Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

您好,打印台一直输出这个,也不写入knowledge_triple.json是什么原因呢? #17

Open
zhang-zhen-project opened this issue Apr 10, 2023 · 2 comments

Comments

@zhang-zhen-project
Copy link

Start extracting...
Building prefix dict from the default dictionary ...
Loading model from cache C:\Users\z\AppData\Local\Temp\jieba.cache
Loading model cost 0.338 seconds.
Prefix dict has been built successfully.
Process finished with exit code -1073740791 (0xC0000409)

@DeoooChen
Copy link

同问同问

@DeoooChen
Copy link

我刚才看了一下原代码,有一些问题,更改了就可以了。先说明一下,我用的是python3.9 + pyltp0.4.0 + pyltp模型3.4.0。
在./code/core/nlp.py这里:
1. 首先把NLP类里面的default_model_dir进行更改。
改成你下载的pyltp的模型路径,比如我改成了default_model_dir = 'D:/pyltp/ltp_data' 。
2.在init函数里更改“加载ltp模型”的代码。
在运行之前我看了pyltp的源码,发现新版本并没有使用.load()进行模型导入,而是在初始化的时候就用arg0或者model_path参数说明了模型的路径,我的代码修改如下,可以参考。
# 加载ltp模型
# 词性标注模型
self.postagger = Postagger(os.path.join(self.default_model_dir, 'pos.model'))
# postag_flag = self.postagger(model_path=os.path.join(self.default_model_dir, 'pos.model'))
# 命名实体识别模型
self.recognizer = NamedEntityRecognizer(os.path.join(self.default_model_dir, 'ner.model'))
# ner_flag = self.recognizer(model_path=os.path.join(self.default_model_dir, 'ner.model'))
# 依存句法分析模型
self.parser = Parser(os.path.join(self.default_model_dir, 'parser.model'))
# parse_flag = self.parser(model_path=os.path.join(self.default_model_dir, 'parser.model'))
# if postag_flag or ner_flag or parse_flag:
# print('load model failed!')
3.修改parse函数内容。
将:
# for i in range(len(arcs)):
# words[i].head = arcs[i].head
# words[i].dependency = arcs[i].relation
修改成:
for idx, element in enumerate(arcs):
words[idx].head = element[0]
words[idx].dependency = element[1]
因为arcs是一个元素为元组的列表。

改完这些之后我就可以正常运行在命令行得到输出了,同时在./code/data也生成了对应的json文件。祝你好运~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants