[#30549] [ANN] Ruby 1.8.6 has been released — "Akinori MUSHA" <knu@...>

 Ruby 1.8.6 をリリースしました。

14 messages 2007/03/12

[#30553] help: lib/shell for ruby 1.9 — keiju@... (Keiju ISHITSUKA)

けいじゅ@いしつかです.

13 messages 2007/03/13
[#30585] Re: help: lib/shell for ruby 1.9 — Yukihiro Matsumoto <matz@...> 2007/03/15

まつもと ゆきひろです

[#30587] Re: help: lib/shell for ruby 1.9 — keiju@... (石塚圭樹) 2007/03/15

けいじゅ@いしつかです.

[#30588] Re: help: lib/shell for ruby 1.9 — Yukihiro Matsumoto <matz@...> 2007/03/15

まつもと ゆきひろです

[ruby-dev:30479] Re: ThreadError on shell.rb

From: "Akira ODA" <oda.org@...>
Date: 2007-03-04 07:21:48 UTC
List: ruby-dev #30479
尾田です。

> ちょっと試しましたが, 再現するのはなかなか難しそうです...
> 実行すると必ず再現します?

いえ、少ないファイル数ならエラーが起きないこともあります。
2,000ファイル以上処理したところでとまったと思ったら、150ファイルほど
でとまる場合もあるようです。

> commands(ARGV)に渡すコマンドは何でしょうか?

自作のPython スクリプトです。で、

% ./bin/dir_filter.rb -f from -t to -- python ./bin/clean_sentence.py
-l list.txt

みたいな感じで走らせてます。一応のせておきます。
# 念のため、今、代わりにgrep を使って実行してみています。

そういえば、前のメールに書くのを忘れてましたが、top で眺めていると実行した
子プロセス(Python)がたまに defunct になってました。あと、関係あるかどうか
分かりませんが、入力、出力のファイルとも NFS でマウントされたファイルです。

import sys
import fileinput

def sentences(fp):
    sentence_id = None
    source = None

    for line in fp:
        if line.startswith('# FILE'): continue
        if line.startswith('# '):
            sentence_id = line[2:].rstrip()
        elif line.startswith('#SRC: '):
            source = line[5:].rstrip()
        elif len(line.strip()) > 0:
            yield sentence_id, source, line.rstrip()

def main(args, list_file):
    duplicate_ids = read_id(list_file)
    for sentence_id, source, tree in sentences(fileinput.input(args)):
        if sentence_id not in duplicate_ids:
            docid, para, sent = sentence_id.split('-')
            print '# %s-%03d-%03d' % (docid, int(para), int(sent))
            print '#SRC: %s' % source
            print tree
            print

def read_id(list_file):
    fp = file(list_file)
    ids = set()
    for line in fp:
        for id in line.rstrip().split('\t')[1:]:
            ids.add(id)
    fp.close()
    return ids

if __name__ == '__main__':
    import optparse
    parser = optparse.OptionParser()
    parser.add_option('--list', '-l', dest='list_file')

    (options, args) = parser.parse_args()

    if not options.list_file:
        parser.print_help()
        sys.exit(1)

    main(args, options.list_file)


-- 
Akira ODA <oda.org@gmail.com>
Junior Research Scientist
Department of Computer Science, New York University.

In This Thread