sparql query insert data was not save in owl - sparql

I try to add a new user to owl with sparql insert data from a user register. When I check individual instances has showing in browser but when I check in protege, the data was not added or when I restart the program, the data was lossed.
graph2 = graph.get_context(onto)
graph2.update("""
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX gr: <http://www.semanticweb.org/bentofuascarvalho/ontologies/OntoBase#>
INSERT {
gr:""" + username + """ rdf:type gr:Person.
} WHERE {}""")
How to save a new data to synchronize with in Protege and in python?
Thanks...!

Related

How to write Federated SPARQL request in Protege

Can somebody help me please with SPARQL Federated, because I can't understand it syntax.
For example I have my own local ontology (museum domen) and there are some data regarding weather I find this https://dbpedia.org/page/Weather_forecasting.
How can I view information from this ontology (weather and date, for example) and my ontology (excursion and date)?
I tried to create request here https://query.wikidata.org/#SELECT%20DISTINCT%20%3Fitem%20%3FitemLabel%20WHERE%20%7B%0A%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22%5BAUTO_LANGUAGE%5D%22.%20%7D%0A%20%20%7B%0A%20%20%20%20SELECT%20DISTINCT%20%3Fitem%20WHERE%20%7B%0A%20%20%20%20%20%20%3Fitem%20p%3AP4150%20%3Fstatement0.%0A%20%20%20%20%20%20%3Fstatement0%20%28ps%3AP4150%29%20_%3AanyValueP4150.%0A%20%20%20%20%7D%0A%20%20%20%20LIMIT%20100%0A%20%20%7D%0A%7D but it does not work in Protege.
I tried to create request in Protege:
*** PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
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 foaf: <http://www.menthor.net/myontology#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?date ?excursion
FROM <https://dbpedia.org/page/Weather_forecasting>
WHERE <http://www.menthor.net/myontology> foaf: ?excursion .
SERVICE <https://dbpedia.org/page/Weather_forecasting/sparql> {
?date foaf:date ?date . ***
but it does not work again
What prefixes should I have? Can I get data from this link https://dbpedia.org/page/Weather_forecasting in Protege?
enter image description here I can get data from my ontology, but do not understand how to use dbpedia data

Distance, polygon with Sparql

In a project, I use big data which is in sparql.
I cannot calculate the distance and I cannot find all the files (PointofInterrest) that are in a point polygon (to display all the files that are in a region, for example).
I tried with geof: distance but I got this answer:
}
java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: org.openrdf.query.QueryEvaluationException: java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.lang.Exception: task=ChunkTask{query=d6f6b503-fd98-4c2c-891c-afa517fd95e0,bopId=37,partitionId=-1,sinkId=38,altSinkId=null}, cause=java.util.concurrent.ExecutionException: java.lang.UnsupportedOperationException: unknown function: http://www.opengis.net/def/function/geosparql/distance
at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191)
at com.bigdata.rdf.sail.webapp.BigdataServlet.submitApiTask(BigdataServlet.java:294)
I also tried with
bif:st_distance
But I can not. Could you clarify for me please? thank you
PREFIX schema: <http://schema.org/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX ebucore: <http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX geof: <http://www.opengis.net/def/function/geosparql/>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
prefix sf: <http://www.opengis.net/ont/sf>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
prefix ex: <http://example.org/>
PREFIX uom: <http://www.opengis.net/def/uom/OGC/1.0/>
SELECT
(...)
BIND (geof:distance(?lat,?lon, "48.xx"^^xsd:double, "10.xx"^^xsd:double,uom:metre) as ?xr)
}

Querying polymorphism in RDF database using SPARQL

I have a question about polymorphism in RDF schema.
I created a class "MobilePhone":
#prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
#prefix schema: <http://schema.org/> .
#prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
#prefix my: <http://localhost/> .
my:MobilePhone rdf:type rdfs:Class .
my:MobilePhone rdfs:subClassOf schema:Product .
my:MobilePhone rdfs:label "MobilePhone" .
Then I executed two queries:
PREFIX : <http://schema.org/>
PREFIX my: <http://localhost/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?instance
WHERE {
?instance a my:MobilePhone .
}
and
PREFIX : <http://schema.org/>
PREFIX my: <http://localhost/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?instance
WHERE {
?instance a :Product .
}
I expected the second query to retrieve all Products. Even "MobilePhone" products. But that didn't happen. I had to use:
PREFIX : <http://schema.org/>
PREFIX my: <http://localhost/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?instance
WHERE {
?class rdfs:subClassOf* :Product .
?instance rdf:type ?class .
}
Does anyone know if it is possible to update my schema so the first query for searching all Products would work?
It is possible to update your data (not your schema [or ontology]) to deliver the desired result, by "forward chaining" -- i.e., by explicitly including statements that each entity which is a my:MobilePhone is also a :Product.
It's also possible to use "backward chaining" to deliver the desired result; the specifics of this will vary with your triple/quad store and other software. (My employer's solution, Virtuoso, uses a DEFINE input:inference pragma to activate an inference rule set for each query.)
Both of these may be considered as "inferencing" or "reasoning", though common usage generally applies these terms only to the dynamic action -- which happens with every query in "backward chaining", and once, pre-query, typically during data load, in "forward chaining".

SPARQL query not retrieving the individuals in protege 5.0

i am working on protege 5.0 tool i downloaded the ontologies i.e doid.owl and cpr.owl which is freely downloadable from the web then i merged them. and i tried querying the ontologies using a SPARQL query the basic "select *" query is working but for retrieving the individuals, i have a query which is not working.. since cpr.owl is the benchmark i merged the ontology into that
the query is:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rs:<http://purl.obolibrary.org/obo/doid.owl>
PREFIX ab: <http://purl.org/cpr/0.9>
SELECT ?name ?age ?address
WHERE
{ ?person ab:hasDisease "heart_cancer";
ab:Name ?name ;
ab:Age ?age ;
ab:Address ?address. }

What is wrong with my SPARQL query and how can I fix it?

I am learning how to create SPARQL queries. Currently, I am using Dbpedia datasets.
I tried to query about "What are the airports that are in Canada" with the following query:
PREFIX owl: <http://www.w3.org/2002/07/owl#>
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#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX : <http://dbpedia.org/resource/>
PREFIX dbpedia2: <http://dbpedia.org/property/>
PREFIX dbpedia: <http://dbpedia.org/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT ?name ?country WHERE {
?name rdf:type <http://dbpedia.org/ontology/Airport>;
?name rdf:type <http://dbpedia.org/ontology/Country>
}
LIMIT 20
I am still confused about building SPARQL queries especially with resources and RDF graphs.
What I need is what is the mistake with the above query?
Thanks
The query you are looking for is something like:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
SELECT DISTINCT ?airport ?label WHERE {
?airport rdf:type <http://dbpedia.org/ontology/Airport>;
rdfs:label ?label;
dbpedia-owl:location <http://dbpedia.org/resource/Canada> .
}
This query however doesn't return much results and you would be better of with something like:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
SELECT DISTINCT ?airport ?label WHERE {
?airport rdf:type <http://dbpedia.org/class/yago/AirportsInOntario> ;
rdfs:label ?label .
}
There are various things wrong in your initial query that imply that you should get a better understanding of SPARQL. You need to revise the way you construct the triple patterns. I recommend you to have a look at the following tutorial:
http://www.cambridgesemantics.com/2008/09/sparql-by-example/
Also you will find exploratory SPARQL queries tremendously helpful:
exploratory SPARQL queries?
Your query is currently asking for objects (resources) that have type Airport AND have type Country. Needless to say, there are no results.
You query is also asking for ?country which is completely undefined.
See msalvadores' answer for a correct example...