I'm currently making a turtle file. I have to relate values/units based on qudt.org Based on example data shown below:
data = { "objectid_l1": "Bridge_1",
"defid_l1": "Bridge",
"objectid_l2": "Deck_1",
"defid_l2": "Deck",
"variable": "height",
"value": "50.0",
"unit": "M",
}
i made the following code, but the output is not what i want:
from rdflib.namespace import RDF
from rdflib import URIRef, BNode, Literal, Namespace, Graph
EX = Namespace('https://example.com/id/')
UNIT = Namespace('http://qudt.org/2.1/vocab/unit/')
BS = Namespace('https://w3id.org/def/basicsemantics-owl#')
for i in data:
if i['objectid_l1'] != None:
g.add((
EX[i['objectid_l1']],
RDF.type,
EX[i['defid_l1']]
))
g.add((
EX[i['objectid_l1']],
BS['hasPart'],
EX[i['objectid_l2']]
))
g.add((
EX[i['objectid_l1']],
EX[i['variable']],
EX[i['value']]
))
g.add((
EX[i['variable']],
BS['unit'],
UNIT[i['unit']]
))
output:
ex:Bridge_1
a ex:Bridge ;
bs:hasPart ex:Deck_1 ;
ex:height 50.0 .
50.0 bs:unit unit:M .
As output i want that the units indent, the desired output is as follows:
ex:Bridge_1
a ex:Bridge ;
bs:hasPart ex:Deck_1 ;
ex:height [
rdf:value 50.0 ;
bs:unit unit:M ;
];