共指解析包装器

wrapperCoreference的Python项目详细描述


共指解析包装器

共指消解是在文本中查找引用同一实体的所有表达式的任务。对于许多涉及自然语言理解的高层次自然语言理解任务,如文档摘要、问答和信息抽取,这是一个重要的步骤。在

这是一个简单的库,它将两个引用解析模型封装成StanfordNLP包:统计模型和神经模型。这里我们使用SpaCy包加载神经模型(a.k.a,NeuralCoref),使用stanfordnlp包加载统计模型(a.k.a,CoreNLPCoref)。在

要求

pip3 install spacy
pip3 install stanfordnlp
pip3 install wrapperCoreference

StanfordNLP还需要手动下载一个核心模块,请查看here了解更多详细信息。在

^{pr2}$

方法

神经模型的使用示例

fromwrapperCoreferenceimportWrapperCoreferencewc=WrapperCoreference()wc.NeuralCoref(u'My sister has a dog. She loves him.')#output: [{'start': 21, 'end': 24, 'text': 'She', 'resolved': 'My sister'}, {'start': 31, 'end': 34, 'text': 'him', 'resolved': 'a dog'}]

统计模型使用示例

fromwrapperCoreferenceimportWrapperCoreferencewc=WrapperCoreference()wc.setCoreNLP('/tmp/stanford-corenlp-full-2018-10-05')print(wc.CoreNLPCoref(u'My sister has a dog. She loves him.'))#output: [{'start': 31, 'end': 34, 'text': 'him', 'resolved': 'a dog', 'fullInformation': [{'start': 14, 'end': 19, 'text': 'a dog'}]}, {'start' : 21, 'end': 24, 'text': 'She', 'resolved': 'My sister', 'fullInformation': [{'start': 0, 'end': 9, 'text': 'My sister'}]}]

将输出与实体链接相结合

您可以使用nifwrapper库将共指输出与实体链接注释合并。在

fromwrapperCoreferenceimportWrapperCoreferencefromnifwrapperimport*#---- Obtaining coreferenceswc=WrapperCoreference()corefResults=wc.NeuralCoref(u'My sister has a dog. She loves him.')#corefResults = [{'start': 21, 'end': 24, 'text': 'She', 'resolved': 'My sister'}, {'start': 31, 'end': 34, 'text': 'him', 'resolved': 'a dog'}]#---- Obtaining Entity Linking results# inline NIF corpus creationwrp=NIFWrapper()doc=NIFDocument("https://example.org/doc1")#--sent=NIFSentence("https://example.org/doc1#char=0,19")sent.addAttribute("nif:beginIndex","0","xsd:nonNegativeInteger")sent.addAttribute("nif:endIndex","19","xsd:nonNegativeInteger")sent.addAttribute("nif:isString","My sister has a dog.","xsd:string")sent.addAttribute("nif:broaderContext",["https://example.org/doc1"],"URI LIST")#-- a1=NIFAnnotation("https://example.org/doc1#char=14,19","14","19",["https://en.wikipedia.org/wiki/ExambleDogUri"],["dbo:FamilyRelations"])a1.addAttribute("nif:anchorOf","a dog","xsd:string")sent.pushAnnotation(a1)doc.pushSentence(sent)#--sent2=NIFSentence("https://example.org/doc1#char=21,35")sent2.addAttribute("nif:isString","She loves him.","xsd:string")sent2.addAttribute("nif:broaderContext",["https://example.org/doc1"],"URI LIST")sent2.addAttribute("nif:beginIndex","21","xsd:nonNegativeInteger")sent2.addAttribute("nif:endIndex","35","xsd:nonNegativeInteger")doc.pushSentence(sent2)#--wrp.pushDocument(doc)#---- Combining EL annotations with coreferences wrp.extendsDocWithCoref(corefResults,doc.uri)print(wrp.toString())

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
具有泛型的对象的oop Java数组   爪哇丑陋的数字找到第1500名UVA在线评委   SpringJava。lang.IllegalStateException:自动连线批注至少需要一个参数   java为什么我的系统找不到我的属性文件?   java有没有办法让Maven同时构建1.5和1.6字节码JAR?   java通过Sailfin中的header进行操作   使用向量、距离和图形   如果提供的登录信息是错误的,为什么java控件不进入else部分和Toast?   java如何为电子商务安卓应用程序存储产品列表   java保存声音首选项Libgdx Android   java无法在测试单元中调用JpaRepository   java使用批处理更新Cassandra表中的选定列,而不将其他列值设为null   java如何在log4j2中的手动代码配置中向appender添加级别?   从ImageIO返回的java Null。读取(新的ByteArrayInputStream(bs));   java不确定如何防止此Arraylist处于可编辑状态   netbeans中的java更改清单(TrustedLibrary=true属性)   java无法使用RestTemplate和Spring数据REST发布具有关系的新实体