How to write Federated SPARQL request in Protege - sparql

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

Related

sparql query insert data was not save in owl

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...!

Running sparql query for getting float values

Hi Below is my sparql query which I am executing on https://dbpedia.org/sparql. However I am getting an error "Invalid floating point value converting 'United States:'" because of the presence of some characters values in grossincome and If I change my query to str(?grossincome) as ?grossincome1) then it executes correctly. My question is how can I convert all currencies on same scale to avoid this error?
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbp: <http://dbpedia.org/property/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
select distinct (str(?resource) as ?movietitle) (xsd:float(?budget) as ?budget1) (xsd:float(?grossincome) as ?grossincome1) (str(?Country) as ?country1) ?ReleaseDate where {
?movie foaf:name ?resource.
?movie dbo:budget ?budget.
?movie dbp:gross ?grossincome.
?movie dbp:country ?Country.
?movie dbo:releaseDate ?ReleaseDate.
FILTER (lang(?resource) = 'en').
}
The data in DBpedia is not perfect as you already recognized it's quite heterogeneous for the untyped property dbp:gross. Among others, it contains values like BDT 2.52 crores, $34,994,648 USD, AU$178,000, 6892098.0, so it is almost impossible to handle different currencies via a SPARQL query such that it returns the values in the same currency.
I mean, you would have to know all different currencies and formats that occur and then handle each separately. But that's more the task of application logic and not the query itself.
Alternatively, you could try to use the data property http://dbpedia.org/ontology/gross instead, which is supposed to relate to values in $. At least that's what its label "gross ($)" states.

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...