小编Ash*_*ian的帖子

AttributeError:无法从'manage.py'>获取<module'__main__'上的属性

def getNer(text):
    with open('chunker.pkl', 'rb') as pickle_file:
        chunker = pickle.load(pickle_file)
    return chunker.parse(pos_tag(word_tokenize(text)))
Run Code Online (Sandbox Code Playgroud)

运行此功能正常,但是当我在Django项目中包含此功能时,出现以下错误

chunker = pickle.load(pickle_file)
AttributeError: Can't get attribute 'NamedEntityChunker' on <module '__main__' from 'manage.py'>
Run Code Online (Sandbox Code Playgroud)

被腌制的物体是

class NamedEntityChunker(ChunkParserI):
    def __init__(self, train_sents, **kwargs):
        assert isinstance(train_sents, Iterable)

        self.feature_detector = features
        self.tagger = ClassifierBasedTagger(
            train=train_sents,
            feature_detector=features,
            **kwargs)

    def parse(self, tagged_sent):
        chunks = self.tagger.tag(tagged_sent)
        iob_triplets = [(w, t, c) for ((w, t), c) in chunks]
        return conlltags2tree(iob_triplets)
Run Code Online (Sandbox Code Playgroud)

我正在使用最新版本的Django和Python3

python django python-3.6

5
推荐指数
1
解决办法
1205
查看次数

标签 统计

django ×1

python ×1

python-3.6 ×1