开发者

create rdf files based on SKOS data model in python

I want to create a .rdf file containing data in the form of SKOS model and written in RDF/XML format. I prefer using Python langu开发者_JAVA百科age. Can you suggest any good python libraries? If possible, a simple example would be of great help. thanks


Have a look at 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.


Edited to add: Here is an example producing sample SKOS output:

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'))

Here's the output:

<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>


Maybe these links will help?

  • http://librdf.org/docs/python.html
  • http://infomesh.net/pyrple/
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜