Warm tip: This article is reproduced from stackoverflow.com, please click
rdf rdfs linked-data turtle-rdf triples

How to give a numeric value to an object while writing an rdf triple

发布于 2020-05-03 12:43:01

I am tryin to write an rdf triple for MixedFruitJuice is made of 2 Oranges, 1 Pomegranate and 1 Pineapple.

HereMixedFruitJuice is an instance of class FruitJuiceand Orange Pomegranate and Pineapple are instances of Fruit.

I don't understand how I can give a numeric value to the objects. Like "2" oranges, or "1" Pomegranate.

Questioner
Raghav Rathi
Viewed
38
Ivo Velitchkov 2020-02-16 00:24

There are different ways to achieve this. For example, using OWL, you can apply owl:Restriction to define either an rdfs:subClass or an owl:equivalentClass, depending if you see your recipe as necessary or as necessary and sufficient conditions for a MixedFruitJuice.

I would suggest declaring Orange, Pomegranate and Pineapple as rdfs:subClass of Fruit. This way a concrete juice, if made of concrete fruits according to the recipe, could be MixedFruitJuice. Now, assuming necessary but insufficient conditions (after all they'd also need some shaking), a :MixedFruitJuice can be described as:

:MixedFruitJuice rdf:type owl:Class ;
          rdfs:subClassOf [ owl:intersectionOf ( :Juice
                 [ rdf:type owl:Restriction ;
                 owl:onProperty :hasIngredient ;
                 owl:qualifiedCardinality "1"^^xsd:nonNegativeInteger ;
                 owl:onClass :Pineapple]
                 [ rdf:type owl:Restriction ;
                 owl:onProperty :hasIngredient ;
                 owl:qualifiedCardinality "1"^^xsd:nonNegativeInteger ;
                 owl:onClass :Pomegranate]
                 [ rdf:type owl:Restriction ;
                 owl:onProperty :hasIngredient ;
                 owl:qualifiedCardinality "2"^^xsd:nonNegativeInteger ;
                 owl:onClass :Orange]
                                                          ) ;
                                       rdf:type owl:Class
                                     ] .

Apart from OWL, this can be achieved also with SHACL in some cases, bringing better results.

If you want to keep Orange, Pomegranate and Pineapple as instances and not as subclasses of Fruit, then you may consider using RDF reification or RDF*.

Using reification can create problems and anyway there is a simple way to represent it, using just RDF, which I should've thought of before suggesting OWL. Here it is:

:MixedFruitJuice
  rdf:type :Juice ;
  :isMadeOf [
      rdf:type :Orange ;
      :numberOfUnits "2"^^xsd:decimal ;
    ] ;
  :isMadeOf [
      rdf:type :Pineapple ;
      :numberOfUnits "1"^^xsd:decimal ;
    ] ;
  :isMadeOf [
      rdf:type :Pomegranate ;
      :numberOfUnits "1"^^xsd:decimal ;
    ] ;
.

For :numberOfUnits I could've chosen an xsd:int range but I assume that in juices might require 1.5 apples for example.