0

I'm using schema.org to create a RDF/XML file using RDFlib in Python, and am trying to nest elements into a PropertyValue element like so, but it's not working...

g.add((p, n.PropertyValue, (p, n.minValue, Literal(130.15))))

I'm trying to end up with this result...

<schema:PropertyValue>
    <schema:maxValue rdf:datatype="http://www.w3.org/2001/XMLSchema#double">308.0</schema:maxValue>
    <schema:name>Temperature</schema:name>
    <schema:minValue rdf:datatype="http://www.w3.org/2001/XMLSchema#double">130.15</schema:minValue>
</schema:PropertyValue>

How could I do this in RDFlib? Thanks in advance.

MA40
  • 61
  • 1
  • 8
  • your data shows 4 triples which you have to add to the graph separately. So, you have to create the RDF resource and then attach the `rdf:type` triple as well as the 3 other triples for name, min and max value. – UninformedUser May 04 '20 at 09:20
  • Thanks for replying. Could you demonstrate what you mean in code? Sorry, I'm new to RDF – MA40 May 04 '20 at 09:43
  • literally what I said, add a triple for each fact, i.e. one line of code for each triple: `g.add((p, RDF.type, n.PropertyValue))` and `g.add((p, n.minValue, Literal(130.15))` and so on and so furth – UninformedUser May 04 '20 at 09:54
  • I've tried this but how could I provide meaning to the minValue if it is separate from the temperature PropertyValue? – MA40 May 04 '20 at 09:59
  • I do not understand, you have a resource which is of type `PropertyValue` and has min/max value as well as a name, or not? this resource would be `p` in your code. This is exactly what is shown in your expected result and this is what the code will produce. a node whose type is `PropertyValue` with 3 attached edges for min value, max value and name – UninformedUser May 04 '20 at 12:54

1 Answers1

0

As per your data, a Blank Node, [ ], with a name, minValue & maxValue property:

[] a <https://schema.org/PropertyValue> ;
    schema:name "Temperature" ;
    schema:minValue "130.15"^^xsd:double ;
    schema:maxValue "308.0"^^xsd:double ;

Better, use a URI for the PropertyValue thing:

<http://example.org/propval/1>
    a <https://schema.org/PropertyValue> ;
    schema:name "Temperature" ;
    schema:minValue "130.15"^^xsd:double ;
    schema:maxValue "308.0"^^xsd:double ;

Use this RDFlib Python:

SDO = Namespace("https://schema.org/")
g.bind("schema", SDO)

pv = URIRef("http://example.org/propval/1")
g.add((pv, RDF.type, SDO.PropertyValue))
g.add((pv, SDO.name, Literal("Temperature")))
g.add((pv, SDO.minValue, Literal("130.15", datatype=XSD.double)))
g.add((pv, SDO.maxValue, Literal("308.0", datatype=XSD.double)))

Nicholas Car
  • 1,164
  • 4
  • 7