Different SPARQL query engines give differing results for DESCRIBE Query - sparql

I tried one SPARQL query in two different engines:
Protege 4.3 - SPARQL query tab
Jena 2.11.0
While the query is the same the results returned by these two tools are different.
I tried a DESCRIBE query like the following:
DESCRIBE ?x
WHERE { ?x :someproperty "somevalue"}
Results from protege give me tuples that take ?x as subject/object; while the ones from jena are that take ?x as subject only.
My questions are:
Is the syntax of SPARQL uniform?
If I want DESCRIBE to work as in protege, what should I do in Jena?

To answer your first question yes the SPARQL syntax is uniform since you've used the same query in both tools. However what I think you are actually asking is should the results for the two tools be different or not? i.e. are the semantics of SPARQL uniform
In the case of DESCRIBE then yes the results are explicitly allowed to be different by the SPARQL specification i.e. no the semantics of SPARQL are not uniform but this is only in the case of DESCRIBE.
See Section 16.4 DESCRIBE (Informative) of the SPARQL Specification which states the following:
The query pattern is used to create a result set. The DESCRIBE form
takes each of the resources identified in a solution, together with
any resources directly named by IRI, and assembles a single RDF graph
by taking a "description" which can come from any information
available including the target RDF Dataset. The description is
determined by the query service
The important part of this is the last couple of sentences that say the description is determined by the query service. This means that both Protege's and Jena's answers are correct since they are allowed to choose how they form the description.
Changing Jena DESCRIBE handling
To answer the second part of your question you can change how Jena processes DESCRIBE queries by implementing a custom DescribeHandler and an associated DescribeHandlerFactory. You then need to register your factory like so:
DescribeHandlerRegistry.get().set(new YourDescribeHandlerFactory());

Related

How can I distinguish SQL triples from explicit triples?

I am using Template Driven Extraction to generate an SQL view and RDF triples from the same set of documents. The SQL view is used for quick inspection of the raw data, while the triples are used downstream to feed information to a knowledge graph.
I now need to extract the RDF triples into an external file, and I'm struggling with separating out those triples that back the SQL view. The documentation suggests that I should use fixed subjects or predicates in my Sparql query, which is something I can't do because I don't know either of the two beforehand. I tried filtering out the SQL triples in XQuery, but I could not devise a way to detect whether a certain value returned by sem:sparql or a triple returned by cts:triples was one of SQL's or mine.
Any help on how to get a dump of all non-SQL triples out of MarkLogic would be appreciated.
Thanks,
Hans
Subjects from SQL views are not real sem:iri's (they are sql:rowID's), so you can use the following to exclude them:
FILTER( ISIRI(?subject) )
HTH!
You could try to use the function tde:node-data-extract.
It basically lets you see the results of a document and TDEs.
While it may involve some work doings this with all documents and converting it into RDF again it should be possible.

Getting instance - SPARQL query in Protege

I have an ontology in Protege and want to write some SPARQL queries.
The ontology is set up like this:
Thing > Beverages > Wine > Red_wine
Then I have added different red wines as instances. They also have some object properties like fromCountry, goesWellWith and priceRange
How do I create a SPARQL query for returning for example a red wine from France, that goes well with pork, and priceRange 100-199?
If you want to return certain resources in your knowledge base you need a SELECT query.
As the commenters have stated, it is not possible to answer your question exactly as you didn't provide enough information on how your data is modelled and you are expected to show your own efforts and where they failed.
You can find an detailed overview of SPARQL 1.1 at https://www.w3.org/TR/2013/REC-sparql11-overview-20130321/ or a more approachable tutorial at https://www.w3.org/2009/Talks/0615-qbe/.
As far as I can guess from your question, your query should look similar to this:
SELECT ?wine WHERE
{
?wine a :RedWine;
:goesWellWith :Pork;
:priceRange :PriceRange100To199.
}
Please adapt this query to your exact model and show us your results.
If you mean "just one result" with "a red wine", you can add "LIMIT 1".
You could also model the price range differently, for example by having a minPrice and maxPrice, as this would enable more precise queries using filters.
P.S.: I changed your :Red_wine to :RedWine as camel case is usually used for class URIs.

SPARQL ElementPathBlock

In am trying to retrieve the triples of a SPARQL expression involved in the OPTIONAL and NON OPTIONAL part of the query, separately.
I used the API ARQ Jena visitor but neither ElementPathBlock nor ElementGroup nor ElementOptional are enough. ElementPathBlock retrieves all the triples, and ElementGroup retrieves the groups of triples (enclosed by {}), and ElementOptional the optional Elements.
Could you help me please?
Thanks for your answer. I found the solution. I was using the ElementWalker as you suggested. However, ElementWalker is not useful (or I could not find the good way) for the traversal of a SPARQL query as usual, I means left-to-right and top-down traversal. I had to write my own method for the traversal of a SPARQL using instanceof, and each type of SPARQL expression: ElementPathBlock, ElementOptional, etc, and recursion. In this way, I was able to extract the optional part (and mandatory part) of the query, as well as union and minus, etc.

Display all fields in Wikidata Query Service

Wikidata provides query browser at https://query.wikidata.org
I want to display films all fields. I tried with using * but its not working. Does anybody know how to display all fields of the data for Films?
To work with SPARQL is necessary to understand some concepts, as #AKSW said in the comments of the question. If you don't understand the meaning of ?film ?p ?o. This is called triple¹ and is composed by subject-predicate-object. E. g., in the case of the films, it could be: x is a film. This is what you are querying in the Wikidata Query Service (WDQS) when you use ?film wdt:P31 wd:Q11424.
I think it isn't possible to display all the property-values of an item. In addition it probably could cause a timeout because there is many statements of many items.
If you want to check the property-values of all the films in Wikidata I think an option might be you write or find a script to extract the items with P31-Q11424 (instance of films). For that, the accessing data section could be useful (e. g. with pywikibot you could query and extract what you want).
If you are interested in SPARQL and WDQS I recommend you to read some help resources:
Wikidata Query Service Help, specifically the SPARQL tutorial.
Query examples (read another queries is how I began to learn).
SPARQL 1.1 Query Language specification.
RDF Dump Format (because read about the ontology of Wikidata could help to understand the concepts).
Edit
When I answer it I wrote triplestore and linked it to its respective page in the Wikipedia in English, but after the comment of #AKSW I consider I was wrong because the triplestore is the concept which is used to refer to the storage and retrieval of triple or semantic triple, "a set of three entities that codifies a statement about semantic data in the form of subject–predicate–object expressions" (from Semantic triple page in Wikipedia in English).

SPARQL - learning by example

In short, if someone instructs me, "Get a list of databases which include Oracle, Mysql, DB2, MSSQL, etc.," how can I actually establish which fields and information I need to create the query? I downloaded DBpedia and grepped the triples, e.g.,
$ `grep 'Oracle' * | grep 'Database'
article_categories_en.nt:<http://dbpedia.org/resource/Oracle_Database> <http://purl.org/dc/terms/subject> <http://dbpedia.org/resource/Category:Relational_database_management_systems> .`
How do I create a SPARQL query from that initial question?
Using that snippet above, I know Oracle is a company and one of its products is an RDBMS by the same name. I tried the lookup tool and searching the web but did not get far enough with this and need some direction.
In this particular case, I'd start by visiting the DBpedia page corresponding to one of the things that you know you'd like in your result. A good instance is http://dbpedia.org/page/MySQL. On that page, you can start to look for properties that might help you find other related systems. One property listed on the page is
dbpedia-owl:genre dbpedia:Relational_database_management_system
Then I'd go the DBpedia SPARQL endpoint and try searching for other things that have this same property and value. In this case, I can run the following query:
SELECT * WHERE {
?rdbms dbpedia-owl:genre dbpedia:Relational_database_management_system .
}
SPARQL results
The results are pretty promising; there are 38 results. The first few are:
rdbms
http://dbpedia.org/resource/MySQL_Cluster
http://dbpedia.org/resource/MSQL
http://dbpedia.org/resource/OpenEdge_Advanced_Business_Language
http://dbpedia.org/resource/Adaptive_Server_Enterprise
…
In general, I find it much easier to locate an instance of the sort of thing that I'm looking for in Wikipedia, then visit the corresponding DBpedia page and look at the properties, and then formulate some exploratory queries based on that.