0

I have a rdf-schema and the triples in the turtle syntax (extract):

@prefix dbr: <http://dbpedia.org/resource/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

#own, TODO change it
@prefix japany: <http://vschuberth.bplaced.net/rdfschema.ttl#> .

japany:import a rdfs:Class.
japany:food a rdfs:Class.
japany:radioactiveIngredients a rdfs:Class.

japany:imports a rdf:Property;
    rdfs:range dbr:PopulatedPlace;
    rdfs:domain japany:import.

japany:exports a rdf:Property;
    rdfs:range dbr:PopulatedPlace;
    rdfs:domain japany:import.

japany:importQuantity a rdf:Property;
    rdfs:range xsd:integer;
    rdfs:domain japany:import.

japany:importValue a rdf:Property;
    rdfs:range xsd:integer;
    rdfs:domain japany:import.

japany:year a rdf:Property;
    rdfs:range xsd:gYear;
    rdfs:domain japany:import.

japany:isPartOf a rdf:Property;
    rdfs:range japany:import;
    rdfs:domain japany:food.

japany:nameOfIng a rdf:Property;
    rdfs:range rdf:Class;
    rdfs:domain japany:radioactiveIngredients.

japany:amount a rdf:Property;
    rdfs:range japany:bqkg;
    rdfs:domain japany:radioactiveIngredients.

japany:nameOfFood a rdf:Property;
    rdfs:range rdf:Class;
    rdfs:domain japany:food.

japany:dateOfSampling a rdf:Property;
    rdfs:range xsd:date;
    rdfs:domain japany:radioactiveIngredients.

japany:isIn a rdf:Property;
    rdfs:range xsd:food;
    rdfs:domain japany:radioactiveIngredients.

<#Import_of_Olivenöl>
japany:imports dbr:Germany;
japany:exports dbr:Japan;
japany:importQuantity 0;
japany:importValue 36;
japany:year "2011"^^xsd:gYear.

<#Olivenöl_Class>
japany:isPartOf <#Import_of_Olivenöl>.

<#Iodine131_in_Olivenöl>
japany:nameOfIng "Iodine131";
japany:amount "< 2,3";
japany:nameOfFood "Olivenöl";
japany:dateOfSampling "15.04.2011"^^xsd:date;
japany:isIn <#Import_of_Olivenöl>.

<#Cesium134_in_Olivenöl>
japany:nameOfIng "Caesium134";
japany:amount "< 1,54";
japany:nameOfFood "Olivenöl";
japany:dateOfSampling "15.04.2011"^^xsd:date;
japany:isIn <#Import_of_Olivenöl>.

<#Cesium137_in_Olivenöl>
japany:nameOfIng "Caesium137";
japany:amount "< 1,95";
japany:nameOfFood "Olivenöl";
japany:dateOfSampling "15.04.2011"^^xsd:date;
japany:isIn <#Import_of_Olivenöl>.

i'm confused how to query through all those entities. they are related to each other. for example: i want to write a query/ queries to get the importValue and importQuantity of each food per year and also list the containing amount of each radioactiveIngredient.

this query will give me incorrect data:

PREFIX japany: <http://vschuberth.bplaced.net/rdfschema.ttl#>


SELECT ?importValue ?importQuantity ?name ?year
WHERE {
  ?trade japany:importValue ?importValue;
         japany:year ?year;
  japany:importQuantity ?importQuantity.
  ?food japany:nameOfFood ?name.

}
ORDER BY ?importQuantity

can anybody help?

Fehler40
  • 125
  • 1
  • 13

1 Answers1

0

A problem is ?food and japany:import are not linked in your query.

Here is a working query :

PREFIX japany: <http://vschuberth.bplaced.net/rdfschema.ttl#>

SELECT ?importValue ?importQuantity ?name ?year
WHERE {
  ?food japany:isPartOf ?import .
  ?import japany:importValue ?importValue ;
                japany:importQuantity ?importQuantity ;
                japany:year ?year .
  ?food japany:nameOfFood ?name.
}
ORDER BY ?importQuantity

But this is creepy :

japany:nameOfFood a rdf:Property;
    rdfs:range rdf:Class.

Why don't you create it as a DatatypeProperty and therefore store a Literal?

Gilles-Antoine Nys
  • 1,481
  • 16
  • 21
  • unfortunately the result is empty...fuseki says there is no data available. do you know why? and thanks, I changed the creepy stuff tordf:DatatypeProperty and rdf:Literal; – Fehler40 Jun 12 '18 at 20:49
  • Perhaps can you try to add "OPTIONAL" filter before each line and see which is empty. OPTIONAL will allow answers that cannot provide a response for each value. – Gilles-Antoine Nys Jun 12 '18 at 21:34
  • @Fehler40 There is no `rdf:DataProperty` ... this is part of OWL, thus, it's `owl:DatatypeProperty` – UninformedUser Jun 13 '18 at 06:39
  • @Gilles-Antoine Nys ...after adding OPTIONAL to each line, only the value of ?name appears, so only the last line seems to work. but i get no data at all if the line "?food japany:isPartOf japany:import" is not optional. – Fehler40 Jun 13 '18 at 07:57
  • I edited the answer. japany:import was bad but ?import seems to be good – Gilles-Antoine Nys Jun 13 '18 at 08:07
  • thanks! everything worked ..found out that I had wrong relations: nameOfFood didn't belong to food. I changed it and with your edited answer everything worked. thanks a lot. – Fehler40 Jun 13 '18 at 12:58