用于nlp交换格式(nif)的小型python库

pynif的Python项目详细描述


NLP Interchange Format (NIF)是 基于rdf/owl的格式,旨在实现 自然语言处理(NLP)工具、语言资源和 注解。它为 任务,如Named Entity Recognition 或者Entity Linking。它 由GERBIL使用以运行 注释器的可重复评估。

此python库可用于序列化和反序列化注释 NIF的下士。

支持的NIF版本

nif 2.1,在any of the formats supported by rdflib中序列化

概述

这个库围绕三个核心类:*aNIFContext 是文档(字符串);*aNIFPhrase是 文档中的文本片段(通常是短语;*aNIFCollection 是一组文档,构成一个集合。在nif中,每个 这些对象由uri标识,它们的属性和关系 由这些uri之间的rdf三元组编码。这个图书馆摘要 通过让您操作集合、上下文和 短语为普通的python对象。

快速启动

  1. 导入并创建集合
frompynifimportNIFCollectioncollection=NIFCollection(uri="http://freme-project.eu")
  1. 创建上下文
context=collection.add_context(uri="http://freme-project.eu/doc32",mention="Diego Maradona is from Argentina.")
  1. 为实体创建条目
context.add_phrase(beginIndex=0,endIndex=14,taClassRef=['http://dbpedia.org/ontology/SportsManager','http://dbpedia.org/ontology/Person','http://nerd.eurecom.fr/ontology#Person'],score=0.9869992701528016,annotator='http://freme-project.eu/tools/freme-ner',taIdentRef='http://dbpedia.org/resource/Diego_Maradona',taMsClassRef='http://dbpedia.org/ontology/SoccerManager')context.add_phrase(beginIndex=23,endIndex=32,taClassRef=['http://dbpedia.org/ontology/PopulatedPlace','http://nerd.eurecom.fr/ontology#Location','http://dbpedia.org/ontology/Place'],score=0.9804963628413852,annotator='http://freme-project.eu/tools/freme-ner',taMsClassRef='http://dbpedia.org/resource/Argentina')
  1. 最后,使用所需的格式获取输出
generated_nif=collection.dumps(format='turtle')print(generated_nif)

您将获得作为字符串的nif表示:

<http://freme-project.eu>anif:ContextCollection;nif:hasContext<http://freme-project.eu/doc32>;ns1:conformsTo<http://persistence.uni-leipzig.org/nlp2rdf/ontologies/nif-core/2.1>.<http://freme-project.eu/doc32>anif:Context,nif:OffsetBasedString;nif:beginIndex"0"^^xsd:nonNegativeInteger;nif:endIndex"33"^^xsd:nonNegativeInteger;nif:isString"Diego Maradona is from Argentina.".<http://freme-project.eu/doc32#offset_0_14>anif:OffsetBasedString,nif:Phrase;nif:anchorOf"Diego Maradona";nif:beginIndex"0"^^xsd:nonNegativeInteger;nif:endIndex"14"^^xsd:nonNegativeInteger;nif:referenceContext<http://freme-project.eu/doc32>;nif:taMsClassRef<http://dbpedia.org/ontology/SoccerManager>;itsrdf:taAnnotatorsRef<http://freme-project.eu/tools/freme-ner>;itsrdf:taClassRef<http://dbpedia.org/ontology/Person>,<http://dbpedia.org/ontology/SportsManager>,<http://nerd.eurecom.fr/ontology#Person>;itsrdf:taConfidence9.869993e-01;itsrdf:taIdentRef<http://dbpedia.org/resource/Diego_Maradona>.<http://freme-project.eu/doc32#offset_23_32>anif:OffsetBasedString,nif:Phrase;nif:anchorOf"Argentina";nif:beginIndex"23"^^xsd:nonNegativeInteger;nif:endIndex"32"^^xsd:nonNegativeInteger;nif:referenceContext<http://freme-project.eu/doc32>;nif:taMsClassRef<http://dbpedia.org/resource/Argentina>;itsrdf:taAnnotatorsRef<http://freme-project.eu/tools/freme-ner>;itsrdf:taClassRef<http://dbpedia.org/ontology/Place>,<http://dbpedia.org/ontology/PopulatedPlace>,<http://nerd.eurecom.fr/ontology#Location>;itsrdf:taConfidence9.804964e-01.
  1. 然后可以将其解析回来:
parsed_collection=NIFCollection.loads(generated_nif,format='turtle')forcontextinparsed_collection.contexts:forphraseincontext.phrases:print(phrase)

问题

如果你对这个图书馆有任何问题,请 通过GitHub issue与我们联系。

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

推荐PyPI第三方库


热门话题
java构造函数SimpleCommandBus()不可见   Java字符串和返回   java不能在类中使用上下文?   使用Java为SOAP定制DataHandler   java“访问被拒绝”在编译servlet时   java嵌入Jetty,在给定时间后终止请求   java如何使用预先指定的URL限制AWS S3 bucket中对象的上传大小?   java理解Azure文件存储:未知hostException   java将对象作为参数传递是否会产生与将其存储在字段中相同级别的耦合?   https告诉java客户端代码接受自签名证书   Java中的简单*权威DNS服务器*   Java解压缩字节数组错误数据检查   当我用SpringDoc和接口描述API规范时,java Spring控制器验证似乎不起作用   在Java中使用PHash(OpenCV)   Kotlin中的java简单继承示例   java Infinispan:ISPN004016:服务器不再位于群集中(127.0.0.1:11222),正在从池中删除   2行滑动菜单安卓本机JAVA   使用日期选择器时Android Studio中的java 4错误   java在<之间删除内容!和/>