Executing the following SparQL query for example will cause a empty query result in MarkLogic:
SELECT *
WHERE { ?s ?p ?o .
FILTER ( 805964266*1719307142*805964270 )
}
Expected query result:
The all data in the database.
Alternatives:
Executing the SparQL query in Query Console and with Java Client API will both get empty query result.
This query can return the expected query result in Apache Jena and RDF4j.
Can someone give me an answer or a hint about it?
I believe the issue is that the expression: 805964266*1719307142*805964270 is producing a decimal overflow. If you execute that expression by itself as XQuery it produces the following error:
[1.0-ml] XDMP-DECOVRFLW: (err:FOAR0002) 805964266 * 1719307142 * 805964270 -- Decimal overflow
If you explicitly evaluate those numbers as xs:double values, then it will compute a value and the applied FILTER produces the expected results:
PREFIX xs: <http://www.w3.org/2001/XMLSchema#>
SELECT *
WHERE { ?s ?p ?o .
FILTER ( xs:double(805964266)*xs:double(1719307142)*xs:double(805964270) )
}
For additional information about XDMP-DECOVERFLW, refer to this knowledgebase article:
https://help.marklogic.com/knowledgebase/article/View/163/0/decimal-division-error-xdmp-decovrflw
Related
I'm new to SPARQL hope someone could help me.
The problem is that if I run the following query on dbpedia sparql:
SELECT DISTINCT ?class WHERE {
?s a ?class.
}
it returns:
result query
I would like to remove the results that has this two prefix: "http://www.w3.org/2002/07/owl" and "http://www.w3.org/2000/01/rdf-schema", now the query is:
SELECT DISTINCT ?class WHERE {
?s a ?class.
FILTER ( !strstarts(str(?class), "http://www.w3.org/2002/07/owl") ).
FILTER ( !strstarts(str(?class), "http://www.w3.org/2000/01/rdf-schema") ).}
but it returns only one result:
http://www.w3.org/1999/02/22-rdf-syntax-ns#Property
If I execute the same query on istat sparql these queries work fine.
So the question is, why on dbpedia my queries does not work as expected?
Thanks
My query in Virtuoso SPARQL Query Editor is as follows which resuted it 74
SELECT (COUNT (*) AS ?count) WHERE {?s ?p <http://dbpedia.org/resource/Machine_learning> .}
I used the same query in SPARQLWrapper as follows which gave me the count as 1195.
from SPARQLWrapper import SPARQLWrapper, JSON
sparqlw = SPARQLWrapper("http://dbpedia.org/sparql")
dbpedia_uri = "http://dbpedia.org/resource/Machine_learning"
sparqlw.setQuery(f"SELECT (COUNT (*) AS ?count) WHERE {{?s ?p <{dbpedia_uri}> .}}")
sparqlw.setReturnFormat(JSON)
results = sparqlw.query().convert()
results_df = pd.io.json.json_normalize(results['results']['bindings'])
print(results_df)
I re-checked the following details.
both are using http://dbpedia.org/ version
my f-string is equivalent to the query
Therefore, I am very confused why this big change of the results happen.
I am happy to provide more details if needed.
I guess I am stuck at the basics with SPARQL. Can someone help ?
I simply wnat to filter all subjects containing "Mountain" of an RDS database.
Prefix lgdr:<http://linkedgeodata.org/triplify/> Prefix lgdo:<http://linkedgeodata.org/ontology/>
Select * where {
?s ?p ?o .
filter (contains(?s, "Mountain"))
} Limit 1000
The query leads to an error:
Virtuoso 22023 Error SL001: The SPARQL 1.1 function CONTAINS() needs a string value as first argument
You can get it to "work" using:
Prefix lgdr:<http://linkedgeodata.org/triplify/> Prefix lgdo:<http://linkedgeodata.org/ontology/>
Select * where {
?s ?p ?o .
filter (contains(str(?s), "Mountain"))
} Limit 1000
Note the additional str in the query.
However, that results in
Virtuoso S1T00 Error SR171: Transaction timed out
and I am not sure how to deal with that.
But in principle in works: When you use
Limit 1
you get
s p o
http://linkedgeodata.org/ontology/MountainRescue http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://www.w3.org/2002/07/owl#Class
I need to find all triples on DBpedia where http://dbpedia.org/resource/Benin is a subject or object. This query gives me the output that I want in a format that works the best for me (just three variables and no blank spaces):
PREFIX : <http://dbpedia.org/resource/>
SELECT * WHERE {
?s ?p ?o
FILTER (?s=:Benin OR ?o=:Benin)
}
I get similar results if I have this query:
PREFIX : <http://dbpedia.org/resource/>
SELECT * WHERE {
{:Benin ?p ?o}
UNION
{?s ?p :Benin}
}
However, the formatting of the latter is off. It first gives me p and o output leaving s blank and then s and p leaving o blank. Also, the first query takes more time to execute. I will be grateful for an explanation of the mechanics of how the two queries work and why there is a difference in the output.
However, the formatting of the latter is off
That's because both queries have different result sets together with SELECT *. The union joins the tuples, but since some tuples are missing parts, you get skewed output.
You can resolve the problem by explicitly listing and selecting the variables:
PREFIX : <http://dbpedia.org/resource/>
SELECT ?s ?p ?o WHERE {
{
?s ?p ?o
FILTER (?s=:Benin)
}
UNION
{
?s ?p ?o .
FILTER (?o=:Benin)
}
}
Note that this is still much faster on dbpedia than the OR filter.
The union will return duplicates when a tuple matches both filter expressions (i.e. :Benin ?p :Benin).
SELECT DISTINCT would remedy that at additional cost and since it looks like the problem is non-existent, I omitted it for improved performance.
Also, the first query takes more time to execute.
That's hard to say without the result of an EXPLAIN(), but my first guess would be that the equality filter is using the index, while the OR filter is using a full table scan. Virtuoso does not seem to generate good query plans for nested filters.
Try this --
PREFIX : <http://dbpedia.org/resource/>
DESCRIBE :Benin
-- or just --
DESCRIBE <http://dbpedia.org/resource/Benin>
You can get the output in various other serializations, including N-triples.
I want to select a triple using SPARQL. To do it, i'm using following query:
SELECT count (*)
WHERE {?s ?p ?o}
FILTER (?s=http://kjkhlsa.net && ?p=http://lkasdjlkjas.com && ?o=Test)
As answer i get fully wrong triple :( subject ist not equal to "http://kjkhlsa.net", predicate is not equal to "http://lkasdjlkjas.com" and object ist also not equal to "Test". Can someone explain me, what I'm doing wrong :(
edit1:
I have put the query into php file:
$inst_query = 'SELECT * { <http://kjkhlsa.net> <http://lkasdjlkjas.com> "Test"}';
echo $inst_query;
The answer from the echo was "SELECT * { "Test"}". Then i tried it with WHERE:
$inst_query = 'SELECT * WHERE { <http://kjkhlsa.net> <http://lkasdjlkjas.com> "Test"}';
echo $inst_query;
Here was the answer "SELECT * WHERE { "Test"}"...so, i'm missing the URIs, but this seems for me as php issue and not sparql problem.
edit2:
I've put the query into SPARQL Query editor and i get the response "no result"....but I'm sure, that i have this triple.
In its current form the question is not very clear (see my comment above).
Since you are essentially trying to get triples matching a pattern, it is more efficient to use a graph pattern instead of FILTER. Many SPARQL implementations first match candidate triples by graph patterns and only then apply the FILTER expression. In essence, with a ?s ?p ?o graph pattern, you're doing a linear scan over all your triples.
So, here's something that should work, using graph patterns instead of FILTER.
SELECT * { <http://kjkhlsa.net> <http://lkasdjlkjas.com> "Test" }
Notes: I didn't include COUNT(*) which is not standard SPARQL. <> around URIs. "" around literal.
Try to use this :
SELECT count (*) as ?count
WHERE {
?s ?p ?o
FILTER (?s=<http://kjkhlsa.net> && ?p=<http://lkasdjlkjas.com> && ?o=Test)
}
The following query uses the count function to count the number of distinct URI(s) returned to the ?s variable.
SELECT ?s (COUNT (DISTINCT ?s) as ?count)
WHERE {?s ?p ?o}
FILTER (?o="Test")