Mirror of the Rel4tion website/wiki source, view at <http://rel4tion.org>

[[ 🗃 ^yEzqv rel4tion-wiki ]] :: [📥 Inbox] [📤 Outbox] [🐤 Followers] [🤝 Collaborators] [🛠 Commits]

Clone

HTTPS: git clone https://vervis.peers.community/repos/yEzqv

SSH: git clone USERNAME@vervis.peers.community:yEzqv

Branches

Tags

master :: projects / naya /

examples.mdwn

I’m going to try improving Naya and detecting problems by taking the [[sparql-examples]] list and translating the examples one by one to Naya.

2.1

[[!format n3 """ SELECT ?title WHERE { http://example.org/book/book1 http://purl.org/dc/elements/1.1/title ?title . } """]]

2.2

[[!format n3 """ PREFIX foaf: http://xmlns.com/foaf/0.1/ SELECT ?name ?mbox WHERE { ?x foaf:name ?name . ?x foaf:mbox ?mbox } """]]

2.3.1

[[!format n3 """ SELECT ?v WHERE { ?v ?p "cat"@en } """]]

Or:

2.3.2

[[!format n3 """ SELECT ?v WHERE { ?v ?p 42 } """]]

2.3.3

[[!format n3 """ SELECT ?v WHERE { ?v ?p “abc”^^http://example.org/datatype#specialDatatype } """]]

2.4

?

2.5

These are two queries, but they mean exactly the same thing.

[[!format n3 """ PREFIX foaf: http://xmlns.com/foaf/0.1/ SELECT ( CONCAT(?G, " ", ?S) AS ?name ) WHERE { ?P foaf:givenName ?G ; foaf:surname ?S }

PREFIX foaf: http://xmlns.com/foaf/0.1/ SELECT ?name WHERE { ?P foaf:givenName ?G ; foaf:surname ?S BIND(CONCAT(?G, " “, ?S) AS ?name) }”""]]

2.6

[[!format n3 """ PREFIX foaf: http://xmlns.com/foaf/0.1/ PREFIX org: http://example.com/ns#

CONSTRUCT { ?x foaf:name ?name } WHERE { ?x org:employeeName ?name } """]]

3.1

Doing just the first one. The second is the same, but with a case-insensitive regex.

[[!format n3 """ PREFIX dc: http://purl.org/dc/elements/1.1/ SELECT ?title WHERE { ?x dc:title ?title FILTER regex(?title, “^SPARQL”) }

PREFIX dc: http://purl.org/dc/elements/1.1/ SELECT ?title WHERE { ?x dc:title ?title FILTER regex(?title, “web”, “i” ) } """]]

3.2

[[!format n3 """ PREFIX dc: http://purl.org/dc/elements/1.1/ PREFIX ns: http://example.org/ns# SELECT ?title ?price WHERE { ?x ns:price ?price . FILTER (?price < 30.5) ?x dc:title ?title . } """]]

4.2.3

[[!format n3 """ (1 ?x 3 4) :p “w” .

(1 [:p :q] ( 2 ) ) . """]]

This is just syntactic sugar for RDF collections, but these are simply encoded in triples so no new model features are introduced by them.

6.1

[[!format n3 """ PREFIX foaf: http://xmlns.com/foaf/0.1/ SELECT ?name ?mbox WHERE { ?x foaf:name ?name . OPTIONAL { ?x foaf:mbox ?mbox } } """]]

6.2

[[!format n3 """ PREFIX dc: http://purl.org/dc/elements/1.1/ PREFIX ns: http://example.org/ns# SELECT ?title ?price WHERE { ?x dc:title ?title . OPTIONAL { ?x ns:price ?price . FILTER (?price < 30) } } """]]

6.3

[[!format n3 """ PREFIX foaf: http://xmlns.com/foaf/0.1/ SELECT ?name ?mbox ?hpage WHERE { ?x foaf:name ?name . OPTIONAL { ?x foaf:mbox ?mbox } . OPTIONAL { ?x foaf:homepage ?hpage } } """]]

7

[[!format n3 """ PREFIX dc10: http://purl.org/dc/elements/1.0/ PREFIX dc11: http://purl.org/dc/elements/1.1/ SELECT ?title WHERE { { ?book dc10:title ?title } UNION { ?book dc11:title ?title } }

PREFIX dc10: http://purl.org/dc/elements/1.0/ PREFIX dc11: http://purl.org/dc/elements/1.1/ SELECT ?x ?y WHERE { { ?book dc10:title ?x } UNION { ?book dc11:title ?y } }

PREFIX dc10: http://purl.org/dc/elements/1.0/ PREFIX dc11: http://purl.org/dc/elements/1.1/ SELECT ?title ?author WHERE { { ?book dc10:title ?title . ?book dc10:creator ?author } UNION { ?book dc11:title ?title . ?book dc11:creator ?author } } """]]

8.1.1

[[!format n3 """ PREFIX rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns# PREFIX foaf: http://xmlns.com/foaf/0.1/

SELECT ?person WHERE { ?person rdf:type foaf:Person . FILTER NOT EXISTS { ?person foaf:name ?name } } """]]

Discussed in [[design3]].

8.1.2

[[!format n3 """ PREFIX rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns# PREFIX foaf: http://xmlns.com/foaf/0.1/

SELECT ?person WHERE { ?person rdf:type foaf:Person . FILTER EXISTS { ?person foaf:name ?name } } """]]

Discussed in [[design3]].

8.2

[[!format n3 """ PREFIX : http://example/ PREFIX foaf: http://xmlns.com/foaf/0.1/

SELECT DISTINCT ?s WHERE { ?s ?p ?o . MINUS { ?s foaf:givenName “Bob” . } } """]]

“Distinct” is trivial to specify. “Minus” can be modeled using other things in this case, but let’s check the SPARQL spec and see how it works. Hmmm… yes, it looks like I can do the same with other features I already have. I’m adding a distinct flag.

8.3.1

[[!format n3 """ SELECT * { ?s ?p ?o FILTER NOT EXISTS { ?x ?y ?z } }

SELECT * { ?s ?p ?o MINUS { ?x ?y ?z } } """]]

8.3.2

TODO continue here after design 4

[[TODO|TODO/OPEN]] continue here to next example

[See repo JSON]