Sparql insert query failing - sparql

I am trying to run the below sparql query to insert data to my graph, but it's failing with the error: Error 400: Bad Request.
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX person: <http://example.com/data/person#>
PREFIX contact: <http://example.com/data/contact#>
INSERT
{
person:p4595 contact:email "test1#example.com" ;
contact:mobile "99483-43843" .
person:p6593 contact:email "test2#example.com" ;
contact:mobile "55351-56477" .
}
I have validated all the IRIs and triples are correct. Not sure why the query is failing.
Any help would be much appreciated. Thanks.

The insert syntax is incorrect. You should use either insert data or insert {...} followed by where {} (with empty {}). I have not run the query, but it should be something like this:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX person: <http://example.com/data/person#>
PREFIX contact: <http://example.com/data/contact#>
INSERT DATA
{
person:p4595 contact:email "test1#example.com" ;
contact:mobile "99483-43843" .
person:p6593 contact:email "test2#example.com" ;
contact:mobile "55351-56477" .
}

Related

Display by ObjectProperty in SPARQL

I have a problem in displaying the result using SPARQL in protege.
I have two classes Panne and Solution and an ObjectProperty hasSolution .
I want to display the Panne that has A Solution ex: GODEX hasSolution SOLGODEX.
I tried
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX panne:<http://www.semanticweb.org/rahma/ontologies/2020/pannesOnto.owl#>
SELECT ?Panne ?Solution
WHERE {
?Panne panne:hasSolution ?Solution}
Without knowing your specific ontology structure, the following will likely need some adaptations.
Currently your query selects all subjects and objects involved in a tuple using panne:hasSolution.
If you want to filter down to only those of a specific solution, you have to include that in the query:
SELECT ?Panne
WHERE {
?Panne panne:hasSolution ex:SOLGODEX .
}
If you want all pairs of panne:Panne and panne:Solution, add the respective patterns to select only members ot those classes:
SELECT ?Panne ?Solution
WHERE {
?Panne a panne:Panne .
?Solution a panne:Solution .
?Panne panne:hasSolution ?Solution .
}

How to calculate distance between two points using geosparql

I'm trying to calculate the distance between two points using geosparql. I have objects like the following image (same properties, different values):
And I'm executing that query in sparql:
PREFIX geos: <http://www.opengis.net/ont/geosparql#>
PREFIX geosf: <http://www.opengis.net/def/function/geosparql/>
PREFIX : <http://www.semanticweb.org/frubi/ontologies/2017/10/puntsWIFI#>
SELECT ?distance
WHERE {
?wifipoint1 :hasGeometry ?geo1 .
?geo1 geos:asWKT ?wpoint1 .
FILTER sameterm(?wifipoint1, <http://www.semanticweb.org/frubi/ontologies/2017/10/puntsWIFI#NYWifiFree103>)
?wifipoint2 :hasGeometry ?geo2 .
?geo2 geos:asWKT ?wpoint2 .
FILTER sameterm(?wifipoint2, <http://www.semanticweb.org/frubi/ontologies/2017/10/puntsWIFI#NYWifiFree105>) .
?distance geosf:distance(?wpoint1 ?wpoint2 <http://qudt.org/vocab/unit#Kilometer>)
}
Without adding the distance, I'm able to get the following result:
But at the moment I add the distance I get empty rows. Any idea?
Notes:
I need to calculate the distance between two wifipoints (NYWifiFree103 and NYWifiFree105) which have each one a point.
I'm executing that queries in stardog.
** EDIT **
I simplified the query:
PREFIX geos: <http://www.opengis.net/ont/geosparql#>
PREFIX geof: <http://www.opengis.net/def/function/geosparql/>
PREFIX : <http://www.semanticweb.org/frubi/ontologies/2017/10/puntsWIFI#>
SELECT (geof:distance(?wpoint1, ?wpoint2, <http://qudt.org/vocab/unit#Kilometer>) as ?distance)
WHERE {
?wifipoint1 :hasGeometry ?geo1 .
?geo1 geos:asWKT ?wpoint1 .
FILTER sameterm(?wifipoint1, <http://www.semanticweb.org/frubi/ontologies/2017/10/puntsWIFI#NYWifiFree103>) .
?wifipoint2 :hasGeometry ?geo2 .
?geo2 geos:asWKT ?wpoint2 .
FILTER sameterm(?wifipoint2, <http://www.semanticweb.org/frubi/ontologies/2017/10/puntsWIFI#NYWifiFree105>)
}
When I set in geof:distance two harcoded wktLiteral returns me correct distance, but using Points does not return nothing.
The geof:distance function accepts Geometries as its first two parameters. So with your simplified query, using geof:distance(?geo1, ?geo2, unit:Kilometer) should give you the result you desire. The Stardog Blog has a geospatial primer post that you may find useful.
AKSW is correct, you should use the built in geof:distance function for the calculation.
I have the same problem with GraphDB. instead of distance it returns 2 fields empty and I have already enabled geosparql
Here is my code:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX : <http://www.semanticweb.org/evangelos/ontologies/2019/2/untitled-ontology-2#>
prefix geo: <http://www.opengis.net/ont/geosparql#>
prefix geof: <http://www.opengis.net/def/function/geosparql/>
prefix unit: <http://qudt.org/vocab/unit#>
prefix sf: <http://www.opengis.net/ont/sf#>
prefix test24: <http://www.semanticweb.org/evangelos/ontologies/2019/2/untitled-ontology-2#>
prefix omgeo: <http://www.ontotext.com/owlim/geo#>
SELECT (geof:distance(?point, ?point2, <http://qudt.org/vocab/unit#Kilometer>) as ?distance)
WHERE
{
:MouseioMetaksisSoufliou :hasGPSCoordinates ?geom2.
?geom2 geo:asWKT ?point.
?geom3 geo:asWKT ?point2.
FILTER (?geom2 != ?geom3)
}

Empty TDB2 Query Result

I have a problem with the command line tools of Apache Jena. I want to create a tdb2 database for a big turtle file. For this reason I used the tdb2.loader command as follows:
tdb2.tdbloader --loc ~/indexer ~/indexer/test.ttl
My test.ttl file contains entries of the form:
#prefix bbase: <http://data.bibbase.org/ontology/#> .
#prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
#prefix owl: <http://www.w3.org/2002/07/owl#> .
#prefix dblp: <https://dblp.org/rdf/schema-2017-04-18#>
<https://dblp.org/rec/conf/romoco/Siegwart13>
a dblp:Publication ;
owl:sameAs <http://dx.doi.org/10.1109/RoMoCo.2013.6614591> ;
dblp:authoredBy <https://dblp.org/pers/s/Siegwart:Roland> ;
dblp:bibtexType bbase:Inproceedings ;
dblp:listedOnTocPage <https://dblp.org/db/conf/romoco/romoco2013> ;
dblp:pageNumbers "98" ;
dblp:primaryElectronicEdition <https://doi.org/10.1109/RoMoCo.2013.6614591> ;
dblp:doi "10.1109/RoMoCo.2013.6614591";
dblp:publicationType dblp:Inproceedings ;
dblp:publishedAsPartOf <https://dblp.org/rec/conf/romoco/2013> ;
dblp:publishedInBook "RoMoCo" ;
dblp:title "Design and navigation of wheeled, running, swimming and flying robots." ;
dblp:yearOfPublication "2013" .
...
Now my problem is that if I query the output (tdb2 file), by using the tdb2.tdbquery command, an empty table will be the result. My query searches for all entities having a dblp:doi property and the result should not be an empty table as you can see on the example above. My query file looks als follows:
PREFIX dblp: <https://dblp.org/rdf/schema-2017-04-18#>
SELECT *
WHERE{
?s dblp:doi ?o .
}
And my my tdb2.query command looks as follows:
./tdb2.tdbquery --loc=~/indexer/Data-0001 --query=~/indexer/query.rq
No matter what I'm doing, my result is always:
---------
| s | o |
=========
---------
If I query the .ttl-files directly with the sparql command in the same manner as I use the tdb2.query command, I will get a reasonable result containing some entries.
Unfortunately I cannot find an answer to my question, neither in the Jena documentation nor in this forum. Can someone give me an answer or at least a hint what might go wrong?
Thanks in advance for your help!
Your --loc parameter on the query should be the location where you created the TDB2 database i.e. ~/indexer

How to create an individual of a specific class from SPARQL query using Fuseki?

I am using insert data query to create an individual in this way
PREFIX d: <http://www.owl-ontologies.com/hecproject.owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
INSERT Data
{
d:new2 d:hasUniversityName "Namal" .
d:University a rdfs:Class .
}
I am assuming that d:University is telling the query that created individual new2 is of type University class. When I execute the query it works fine and inserts a record in the dataset and when I execute a general query like this
SELECT ?subject ?predicate ?object
WHERE {
?subject ?predicate ?object
}
then individual is created but when i try to find all individuals of class University i do not find it like that was not created with class University?
You're not assigning the individual d:new2 to the class d:University in your INSERT query. All your query does it to add exactly the two triples
d:new2 d:hasUniversityName "Namal" .
d:University a rdfs:Class .
nothing more, nothing less.
Indeed it's up to you to the triple
d:new2 rdf:type d:University .
that assigns d:new2 to class d:University:
PREFIX d: <http://www.owl-ontologies.com/hecproject.owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
INSERT Data {
d:new2 d:hasUniversityName "Namal" .
d:new2 rdf:type d:University .
d:University a rdfs:Class .
}

Can't execute a specific SPARQL query on DBPedia :/

On this site, for example, take the first SPARQL query and make something very similar:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX p: <http://dbpedia.org/property/>
SELECT *
WHERE {
?name p:name <http://dbpedia.org/resource/Olivier_Theyskens> .
}
Try to execute it: here
And I get no results. However, modify the query to the following:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX p: <http://dbpedia.org/property/>
SELECT *
WHERE {
?name p:name ?otherthing.
}
And I get results, even though they're not the results I want.
Why doesn't the first query work -- what am I doing wrong? :/
In this case, I think it's because you're ordering your query statement backwards.
The DBpedia resource (<http://dbpedia.org/resource/Olivier_Theyskens>) is the Entity or Subject (?s), the property (p:name) is the Attribute or Predicate (?p), and the value of that property (?name) is the Value or Object (?o).
SPARQL expects all statements to be { ?s ?p ?o }, but yours seems to be written as { ?o ?p ?s }...
To sum up, if you try this query --
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX p: <http://dbpedia.org/property/>
SELECT *
WHERE
{
<http://dbpedia.org/resource/Olivier_Theyskens> p:name ?name .
}
-- you'll get the results I think you want.
The problem with your first query is that p:name links to Literal and you try to match a URI.
If you want your first query to work you have to to use the property http://dbpedia.org/ontology/artist that links to the URI and not the literal:
SELECT *
WHERE {
?s <http://dbpedia.org/ontology/artist> <http://dbpedia.org/resource/The_Velvet_Underground> .
}
Notice the different name space for the property <http://dbpedia.org/ontology/artist> this namespace contains ontology instead of property - ontology is the one used for object properties.