我想创建一个包含 SKOS 模型形式的数据并以 RDF/XML 格式编写的 .rdf 文件。我更喜欢使用 Python 语言。你能推荐任何好的 python 库吗?如果可能的话,一个简单的例子会有很大的帮助。 谢谢
请您参考如下方法:
看看RDFLib :
RDFLib is a Python library for working with RDF, a simple yet powerful language for representing information.
The library contains parsers and serializers for RDF/XML, N3, NTriples, Turtle, TriX and RDFa. The library presents a Graph interface which can be backed by any one of a number of store implementations, including, memory, MySQL, Redland, SQLite, Sleepycat, ZODB and SQLObject.
编辑添加:这是生成示例 SKOS 输出的示例:
from rdflib import Graph, Literal, Namespace, RDF, URIRef
graph = Graph()
skos = Namespace('http://www.w3.org/2004/02/skos/core#')
graph.bind('skos', skos)
graph.add((URIRef('URI'), RDF['type'], skos['Concept']))
graph.add((URIRef('URI'), skos['prefLabel'], Literal('Temp', lang='en')))
graph.add((URIRef('URI'), skos['related'], URIRef('URI-Related')))
print(graph.serialize(format='pretty-xml'))
这是输出:
<rdf:RDF
xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'
xmlns:skos='http://www.w3.org/2004/02/skos/core#'
>
<skos:Concept rdf:about="URI">
<skos:related rdf:resource="URI-Related"/>
<skos:prefLabel xml:lang="en">Temp</skos:prefLabel>
</skos:Concept>
</rdf:RDF>
