HI All,
Here's a little case study in going from a spec to a SPARQL query, and
separately to SQL.
HTH, -- Adrian
Adrian Walker
Reengineering LLC
San Jose, CA, USA
860 830 2085
www.executable-english.com
---------------------SPECIFICATION---------------------
I have a graph where resources have a number of controlled properties.
Call them A thorough F. Some resources may have one property other may
have all 6.
I have a resource with a with properties A, B, and C.
I want to find all resources in the graph where the resource has matching
values but does not have any non specified properties.
So
x with A, B, and C will match
y with A and C will match
z with A, B, C and D will not match
w with A and D will not match.
Any idea how to construct a query that will do this?
------------------------- SPARQL QUERY---------------------
Okay, let me try. I think I've done something similar actually - and ran
into performance problems with those queries using the latest Jena
releases. But that's a different story...
SELECT ?r
WHERE {
# we have a specific resource for which we are looking for matches
BIND(:inputresource AS ?a)
# the input resource has one or more properties
?a :p ?val .
# the matching resource should have at least one of those properties
?r :p ?val .
# but the targeted resource shouldn't have any property that the input
resource doesn't have
FILTER NOT EXISTS {
?r :p ?val2 .
FILTER NOT EXISTS {
?a :p ?val2 .
}
}
}
I think one or both of the FILTER NOT EXISTS may be changed to a MINUS as
well.
---------------------EXECUTABLE ENGLISH --> SQL--------------
some-resource has the property some-property
not : that-resource has a non-matching property
--------------------------------------------------------------
that-resource having that-property matches
some-resource has the property some-property
that-resource has a non-matching property
-------------------------------------------------------------------
that-resource having that-property does not match
some-resource has the property some-property
that-property is a non matching one
---------------------------------------------------------------
that-resource has a non-matching property
this-resource has the property this-property
=================================
x A
x B
x C
y A
y C
z A
z B
z C
z D
w A
w D
this-property is a non matching one
===========================
D
Here is SQL _generated_ from the above.
select tt1.RES , tt1.PROP from
mysql.matchT1 tt1 where tt1.RES not in
(select tt2.RES from mysql.matchT1 tt2 , mysql.matchT2
where mysql.matchT2.PROP = tt2.PROP and tt1.RES = tt2.RES )
On Sat, Mar 4, 2017 at 7:32 AM, Martynas JuseviÄius <***@graphity.org>
wrote:
> > My goal is simply to learn more about graph databases, so I want to
> install and use one. I've installed Fuseki, but I found SPARQL to be overly
> complex compared to other query languages.
>
> It's a little like wanting to use RDBMS but finding SQL overly
> complex. Sure, there is probably some query approach, but you will
> constantly face challenges to try to get it to work. Same for XML and
> XPath, etc.
>
> SPARQL is an industry standard, deal with it. Trying to avoid it will
> lead to a more complex setup than trying to learn and use it. And no
> way it's more complex than SQL.
>