1

pypy を使用して Python コードを高速化したいと考えています。しかし、私はこれらの奇妙な問題を抱えています。

これは、クラスのinitメソッドの私のコードです:

self._parse_function_by_id_prefix = { 
        'T': self._parse_textbound_annotation,
        'M': self._parse_modifier_annotation,
        'A': self._parse_attribute_annotation,
        'N': self._parse_normalization_annotation,
        'R': self._parse_relation_annotation,
        '*': self._parse_equiv_annotation,
        'E': self._parse_event_annotation,
        'F': self._parse_textlevel_annotation,
        '#': self._parse_comment_annotation,
        }`

これは必要に応じて適切な関数を呼び出し、このように定義されています

def _parse_textlevel_annotation(self, _id, data, data_tail, input_file_path):
    _type, ids = data.split(' ')
    ids = ids.split(';')
    return TextLevelAnnotation(_id,_type,ids,data_tail.strip())

def _parse_textbound_annotation(self, _id, data, data_tail, input_file_path):
    _type, spans = self._split_textbound_data(_id, data, input_file_path)
    return TextBoundAnnotation(spans, _id, _type, data_tail, source_id=input_file_path)

「pypy filename」でこれを実行しようとすると、_parse_textbound_annotation の AttributeError が発生し、これだけが発生し、他のエラーは発生しません。通常のコンパイラを使用すると、問題なく動作します。

Traceback (most recent call last):
  File "app_main.py", line 51, in run_toplevel
  File "annotation.py", line 2132, in <module>
    ann = TextAnnotations("/home/hast/Downloads/brat/data/brat_vb/sentiment/test")
  File "annotation.py", line 1059, in __init__
    Annotations.__init__(self, document, read_only)
  File "annotation.py", line 330, in __init__
    'F': self._parse_textlevel_annotation,
AttributeError: 'TextAnnotations' object has no attribute '_parse_textlevel_annotation'

グローバル名が定義されていなかったため、別の奇妙な NameError も発生しましたが、再入力するだけで修正されました。

4

0 に答える 0