Definition of a recursive query in SPARQL - recursion

Can we call the below query a recursive query? if not, what can we call it?
select ?x ?y
where{
?x p1* ?y
}

Yes, property path operators, such as *, offer a limited recursion in SPARQL. However, note that variables are not allowed in property paths, so your query is syntactically invalid.

Related

Unary NOT in SQLite FTS5 MATCH query

The SQLite FTS5 docs say that search queries such as SELECT ... WHERE MATCH '<query1> NOT <query2>' are supported, but it looks like there's no support for the unary NOT operator.
For example, if I want to search for everything that doesn't match <query>, I cannot use MATCH 'NOT <query>'. I would have to use NOT MATCH '<query>', which is a completely different thing (the FTS5 module never gets to see the NOT operator, as it is outside the quotation marks). Only the text inside the quotation marks is the search query.
I need to find a way to use an unary NOT operator inside the search query. I can't use it outside, because I only get to control the search query text, and not the rest of the SQL statement.
A possible approach I've thought of would be to find a search query that matches anything, and do MATCH '<match_anything> NOT <query>'. However, I've found no way to match everything in a search query.
Can you think of a way to have the behaviour of the unary NOT operator inside the search query?
Try this ..
SELECT * FROM docs
WHERE ROWID NOT IN (
SELECT ROWID FROM docs WHERE content MATCH '<query>'
)

How do we apply the ORDER BY and LIMIT,OFFSET Clauses to DAO.fetch(query) in cn1-data-access?

DAO.fetch(query) allows us to get a collection of entities from the sqlite database that meets the query condition. query can be a map or string []. How can we specify ordering with the ORDER BY clause and also how do we apply the LIMIT and OFFSET clauses or do we have to default to db.execute(query)?
Currently ORDER BY, LIMIT, and OFFSET clauses aren't supported. It wouldn't be hard to add. Please file an RFE.
Alternatively it wouldn't be difficult to add this in your own DAO subclass. You can see how fetch(query) is implemented here.

Sqlite FTS, Using OR between match operators

When I execute the following query in a sqlite engine (android or sqlitebrowser) it throws an exception that says unable to use function MATCH in the requested context.
select
a.Body1,
b.Body2
from
tbl1_fts as a,
tbl2_fts as b
where
a.ID = b.ParentID and
(
a.Body1 match('value') or
b.Body2 match('value')
)
-Both tables have fts.
-Using And operator between two matches (instead of OR) runs normally.
How can I fix this or change the query to find rows with above condition?
you can not use OR Operation, just change your Match Keyword.
like
SELECT * FROM docs WHERE docs MATCH 'sqlite OR database';
OR maybe you can use union
SELECT docid FROM docs WHERE docs MATCH 'sqlite AND database'
UNION
SELECT docid FROM docs WHERE docs MATCH 'library';
MATCH as a function would have two parameters:
... WHERE match('value', SomeColumn) ...
However, the usual method of using MATCH is as an operator:
... WHERE SomeColumn MATCH 'value' ...
MATCH has to be used without parentheses.
The AND and OR operators must be in capital letters when used with FTS.

Error creating and viewing graph in Sparql

I am using CREATE GRAPH to create a new graph in sparql. Which gives me success update succeeded. But when i query for all the graphs i cant find it. I am using SELECT and Union to query. I am using Fuseki server.
If you have created the graph but have not yet added any data to it, the query pattern GRAPH ?g {?s ?p ?o} won't match the graph, because ?s ?p ?o can not be bound to anything.
The triplestore you are accessing via Fuseki server presumably does not really support the notion of an 'empty graph' (most triplestores don't, although technically it's allowed by the SPARQL standard). The CREATE operation returns true but effectively does nothing. Only when you start actually adding data to the graph is it really created.

How to list and count the different types of node and edge entities in the graph data using SPARQL query?

I'm looking to provide some summary stats for a data set and I want to list the different types of edge entities and node(vertex) entities in the graph.
For example:
-> In Twitter Social network graph of users and following relationship (Homogeneous graph), there is only one type of vertex entity (user), but in heterogeneous graphs such as ConceptNet data, it will have multiple values.
-> The edge entities can be computed by just counting the different number of predicates I believe using the query :
SELECT DISTINCT (?p AS ?DistinctEdges) { ?s ?p ?o }
But I am not sure how to do so for vertices. The vertex type can be from a subject or object field of the triple and the object in turn can be either a value(literal) or another resource itself.
Please excuse me if I have gone wrong with the vocabulary anywhere. I have just started working on building a semantic web application.
You can use the UNION clause to combine two patterns in conjunction with a FILTER clause using the IsLiteral() function to omit literals e.g.
SELECT DISTINCT ?vertex
WHERE
{
{
?vertex ?p []
}
UNION
{
[] ?p ?vertex
FILTER(!IsLiteral(?vertex))
}
}
The [] is an anonymous variable because you don't care about the some of the positions on either side of the UNION so by giving them an anonymous variable we match any value but don't carry those values out in the query.
The FILTER clause in the RHS of the union is used to filter out objects which are literals. It is not necessary to have this in the LHS because RDF forbids literal subjects so any ?vertex value from the LHS must be a resource i.e. a URI/blank node

Resources