I have 2 questions regarding Sparql:
I have a class and I'm trying to get all instances of a certain class. I'm using Protege. There are 2 instances for the 'Actor' class. How can I write a sparql query to extract only these two values?
Additional to question 1, how can I match only one value. For example how do I modify Question 1's query to match == "Third Party API"?
Related
I have some entities in a specific language and I am trying to retrieve the possible IDs from Wikidata that match those names.
For example, I have some German name, let's say "Ministerium für Auswärtige Angelegenheiten" and I can get the top N candidate IDs that correspond to the name like this:
SELECT ?item
WHERE
{
?item rdfs:label "Ministerium für Auswärtige Angelegenheiten"#de
}
LIMIT 2
and this will give me 2 candidate IDs.
The issue that I have is, if I have a name that contains some inflection, then the exact match won't be in the database and nothing will be returned.
Even in the current example with the name: "Ministerium für Auswärtige Angelegenheiten", if I remove the word "für", I won't get any results returned.
Is there a way to make the search more flexible and return the closest results to the query, even if they are incorrect?
P.S. I am doing it through Python, using the SPARQLWrapper
Not using the WQS SPARQL service, IIANM.
For similar usecases, using the full-text search engine might be workable. Take a look at a search query in the API Sandbox, returning some relevant results.
I am using an IBM wrapper solution around SPARQL to get information from our database. I set a triple variable to act as a filter but it doesnt return an exact match, only a 'contains' match.
More specifically, we are looking at requirements that live in a collection. The SPARQL query returns all requirement objects and the collection that they live in. Each collection has a unique identifier associated with it which is accessed via the predicate 'dcterms:identifier'. The exact line in the SPARQL code which does this is:
?oslc_rm_RequirementCollection1_uri dcterms:identifier ?oslc_rm_RequirementCollection1_identifier
This works as expected. In the output I get a table containing each collection with the list of requirements associated with each one.
The problem arises when I want to look at requirements in only a specific collection. To do this I set the variable oslc_rm_RequirementCollection1_identifier in IBM's wrapper, and it generally works. If I enter '18732' it only shows me requirements from the collection with id 18732. However, this is not an exact match only a contains. For example if I enter '867', I am shown two collections: 867 and 38674.
How can I modify this to exclude 38674 and only show the exact match? I cannot use a string literal because the wrapper does not allow this.
I have a question about SPARQL Query in Protege
I have a built ontology. This ontology includes a subclass called HVAC_CL. HVAC_CL subclass contains an individual called AirCondition_CL. AirCondition_CL as an individual is assigned to a Data property called InstallationPrice. The data property assertion for InstallationPrice is 4000 (as an integer value).
I need a SPARQL Query in Protege to identify the InstallationPrice of the AirCondition_CL individual.
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());
If I have two entities in my model, "People" and "Addresses", and a particular Person has zero or more addresses, accessed via an AddressList navigation property, can I write an OData query that answers the following question:
"Which people have a last name ending in Smith and at least one address?"
It seems to me I can only do one predicate here, e.g.
http://localhost:55100/DemographicsDataService.svc/People?$filter=endswith(LastName,'Smith')
(I'm not yet convinced I can even write a $filter to handle the second predicate.. in which case, assume I'm trying to answer the question, "Last name ending in smith and first name starting with Mary")
You can definitely combine predicates in the $filter. For example:
/People?$filter=endswith(LastName,'Smith') and startswith(FirstName,'Mary')
For details around supported operators and such please see this page: http://www.odata.org/documentation/odata-version-2-0/uri-conventions#FilterSystemQueryOption
Currently OData doesn't have a way to express the question "People which have at least one address".
Depending on your data it might be feasible to download all People fulfilling the first criteria and determine those with address on the client instead.