Reputation: 81
I am trying to convert a csv file into RDF N-triples using RDFLib in python. It seems that subject must be an IRI/blank node and also Predicate must be an IRI. For example,
<http://example.org/show/218> <http://www.w3.org/2000/01/rdf-schema#label> "That Seventies Show" .
I have only static string literal data in csv file and I don't have any IRI. For example,
subject: "Name" predicate: "Id" Object="Location"
.
updated the csv format as below,
Name | Id | Location |
---|---|---|
Jon | 34 | Texas |
Michael | 42 | California |
So, is it possible to use only string literal for subject and predicate ? or How to build the IRI for my data?
Upvotes: 2
Views: 643
Reputation: 1020
You're correct when you state that you must have a URI as the subject. This is a major feature of the technology that allows you to link data together.
You also need to have a namespace for the predicates. This is another feature of the technology that you won't be able to get around.
If you want the name as the subject I would do something like...
subject = rdflib.URIRef('http://ex.com/name')
predicate = rdflib.URIRef('http://ex.com/hasID')
object = rdflib.Literal(id)
graph.add((subject, predicate, object))
where name
and id
are coming from your CSV.
You might want to add an rdfs:label
to the node for parsing/readability. A better option in my opinion is to create a new relation, ex:hasName
and relate the name to the node that way.
Use an existing URI scheme (file://, http://, uuid:, etc) and append something to the end that makes the most sense.
Upvotes: 1