1

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?

  • no, you have to create IRIs - I mean, how difficult is it to just declare any namespace for your data and use it in combination with the values. I also don't get the format of your CSV. Usually, the header of the CSV makes the schema of the ontology. The other rows make the RDF triples then. – UninformedUser Jul 17 '21 at 08:43
  • I have updated the csv format. So, do you mean I can use any general IRI as namespace? I don't have any generalized URI for my data. – swathi selvaraju Jul 19 '21 at 11:48

1 Answers1

0

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.

tldr

Use an existing URI scheme (file://, http://, uuid:, etc) and append something to the end that makes the most sense.

Thomas
  • 720
  • 9
  • 22
  • Thanks. As I don't have any specific URI scheme for my data, can I use generalized one like http://www.w3.org/2001/XMLSchema/ – swathi selvaraju Jul 20 '21 at 09:14
  • Sure that would work-but if you're sharing the data with anyone they might be confused. `file://data.csv#Jon`, `file://data.csv#Michael` might not be a terrible convention. – Thomas Jul 20 '21 at 16:50