1
votes

I have a python function that defines triples in subject, object and predicates and iterate through them but I need to convert the triples to a RDF URIRef data forma so that I can store it in my RDF store. How can I go about this?

I am using RDFLib for my RDF store, as explained above I am trying to convert a set of data(sensor data to be specific) in a dictionary to RDFLIb URIRef format.

e.g if I have self.triples[self.identifier][prov['subject']]=self.subject.identifier self.triples[self.identifier][rdf['type']]= prov['alternateOf'] and I convert them to URIRef format using RDFLib

as for the store I am using a RDFStore for n3 format

My point here is: RDFLib makes use of Python strings as subjects, predicates, and objects but some operations will not work if they are not properly converted to rdflib.URIRef data format. It is only when they are in the proper format that I can store then in an RDFStore.

1
what store? are you using rdflib?Phil Cooper
You'll need to edit this question to make it clearer. RDF triples are normally defined by subject, predicate and object so it's not clear what the problem is. Please give a clear example of what you want to convert from, and, as Phil says, state which store you're using (or, which RDF syntax variant - RDF/XML, Turtle, etc - you're trying to convert to)Ian Dickinson

1 Answers

1
votes

Short answer to your question of how to convert to a string to a uri:

from rdflib import URIRef
# this cannot be a subject in a triple
uri_str = 'http://stackoverflow.com/questions/11594712'
# this can be a subject (or predicate or object) of a triple
uri_ref = URIRef(uri_str)

Usage with Namespace:

from rdflib import Namespace

ns_str = 'http://example.com/namespace/doc/'
ns = Namespace(ns_str)

uri_str = ns_str+'fragment'

assert URIRef(ns_str+'fragment') == ns.fragment == ns['fragment']