一个小型用于自然语言处理交换格式(NIF)的Python库
项目描述
自然语言处理交换格式(NIF) 是一个基于RDF/OWL的格式,旨在实现自然语言处理(NLP)工具、语言资源和注释之间的互操作性。它为诸如命名实体识别或实体链接之类的任务提供了注释文本的标准表示。它被GERBIL用于运行注释者的可重复评估。
此Python库可用于将NIF中的注释语料库进行序列化和反序列化。
文档
支持的NIF版本
NIF 2.1,序列化为rdflib支持的任何格式
概述
本库围绕三个核心类进行设计:* NIFContext 是一个文档(一个字符串);* NIFPhrase 是文档中某段文本(通常是短语)的注释;* NIFCollection 是一组文档,构成一个集合。在NIF中,每个对象都通过URI进行标识,它们的属性和关系通过这些URI之间的RDF三元组进行编码。这个库通过允许您将集合、上下文和短语作为普通的Python对象来操作,抽象掉了编码过程。
快速入门
导入并创建一个集合
from pynif import NIFCollection
collection = 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> a nif: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> a nif: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> a nif: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:taConfidence 9.869993e-01 ;
itsrdf:taIdentRef <http://dbpedia.org/resource/Diego_Maradona> .
<http://freme-project.eu/doc32#offset_23_32> a nif: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:taConfidence 9.804964e-01 .
然后您可以将其解析回
parsed_collection = NIFCollection.loads(generated_nif, format='turtle')
for context in parsed_collection.contexts:
for phrase in context.phrases:
print(phrase)
问题
如果您对这个库有任何问题或疑问,请通过GitHub问题联系我们。
项目详情
下载文件
下载适合您平台的文件。如果您不确定要选择哪个,请了解更多关于安装包的信息。
源代码分发
pynif-0.3.1.tar.gz (17.2 kB 查看哈希)
构建分发
pynif-0.3.1-py2.py3-none-any.whl (19.5 kB 查看哈希)
关闭
pynif-0.3.1.tar.gz的哈希
算法 | 哈希摘要 | |
---|---|---|
SHA256 | de265ea061145e15382e42d2c5d9cd32f1e7d3cd15f57f738f8847681950b365 |
|
MD5 | 47f16c1931a009c09fcc2776f3e29429 |
|
BLAKE2b-256 | e75772f282301bc6c5baf3f0c17f072eecefe332586e70ebfbf781873497ad86 |
关闭
pynif-0.3.1-py2.py3-none-any.whl的哈希
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 090dd7a221bcd45f2f9b5318a8a974cb02e3d8c43a7255121712ed9e44ddb0a9 |
|
MD5 | 9fc1a86044bf7245d69cd22c38d8259f |
|
BLAKE2b-256 | 9d1576aa3003d9b8a10365af8eb41defe13f32af5c3f1c1d25cd2d5f928fcc05 |