共指解析包装器

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第三方库


热门话题
java使用字符而不是字符串的意义   部分匹配长度字符串相似性的java正则表达式   java获取构造函数错误(错误:“(”或“[”)   java@Value注释无法正常工作SpringBoot   java hasKey在响应中没有看到字段   java JavaFX,没有JFXButtons和所有   在Log4j2中,是否可以根据键从记录器中筛选出某些键值对?   如何使用Java中Kafka的消息,从特定偏移量开始   java在单击后存储动态按钮的值   java Android编码:ViewRootImpl$CalledFromErrorThreadException。[Noob]   通过FileChooser保存pdf格式会提示在java中出现第二个对话框   用于空文件的java Spring集成文件标记   java我们应该如何编写get方法,以便私有字段不会超出其预期范围?   java Eclipse产品问题,Juno RequireHandle:org。日食e4。果心服务