用于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对象。
快速启动
- 导入并创建集合
frompynifimportNIFCollectioncollection=NIFCollection(uri="http://freme-project.eu")
- 创建上下文
context=collection.add_context(uri="http://freme-project.eu/doc32",mention="Diego Maradona is from Argentina.")
- 为实体创建条目
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')
- 最后,使用所需的格式获取输出
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.
- 然后可以将其解析回来:
parsed_collection=NIFCollection.loads(generated_nif,format='turtle')forcontextinparsed_collection.contexts:forphraseincontext.phrases:print(phrase)
问题
如果你对这个图书馆有任何问题,请 通过GitHub issue与我们联系。