forked from yql/yql-tables
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import from http://triplr.org/sparyql/ and http://github.com/dajobe/s…
- Loading branch information
Showing
2 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
SPARYQL | ||
------- | ||
|
||
SPARQL + YQL = SPARYQL | ||
|
||
Try these queries in the [YQL Console][1] | ||
|
||
1. Example 1: get all triples from a FOAF file | ||
<pre><code> | ||
use "http://triplr.org/sparyql/sparql.xml" as sparql; | ||
select * from sparql where query="PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT $s $p $o FROM <http://www.dajobe.org/foaf.rdf> WHERE { $s $p $o } LIMIT 10" | ||
and service="http://sparql.org/sparql" | ||
</code></pre> | ||
|
||
2. Example 2: get friend's nick and names from a FOAF file | ||
<pre><code> | ||
use "http://triplr.org/sparyql/sparql.xml" as sparql; | ||
select * from sparql where query="PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT $nick $name FROM <http://www.dajobe.org/foaf.rdf> WHERE { $x a foaf:Person . $x foaf:nick $nick . $x foaf:name $name }" | ||
and service="http://sparql.org/sparql" | ||
</code></pre> | ||
|
||
3. Example 3 - select just one field: value of object triple | ||
<pre><code> | ||
use "http://triplr.org/sparyql/sparql.xml" as sparql; | ||
select result.o.value from sparql where query="PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT $s $p $o FROM <http://www.dajobe.org/foaf.rdf> WHERE { $s $p $o } LIMIT 10" | ||
and service="http://sparql.org/sparql" | ||
</code></pre> | ||
|
||
*** | ||
|
||
[1]: http://developer.yahoo.com/yql/console/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd" | ||
securityLevel="any" | ||
https="false" | ||
> | ||
<!-- http://developer.yahoo.com/yql/guide/yql-opentables-reference.html --> | ||
<meta> | ||
<author>Dave Beckett</author> | ||
<documentationURL>http://triplr.org/sparyql/</documentationURL> | ||
<sampleQuery>select * from {table} where query="SPARQL QUERY" and service="SPARQL ENDPOINT URL" e.g. | ||
select * from {table} where query="PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT $nick $name FROM <http://www.dajobe.org/foaf.rdf> WHERE { $x a foaf:Person . $x foaf:nick $nick . $x foaf:name $name }" and service="http://sparql.org/sparql" | ||
</sampleQuery> | ||
</meta> | ||
<bindings> | ||
<select produces="XML"> | ||
<!-- | ||
SPARQL Protocol http://www.w3.org/TR/rdf-sparql-protocol/ | ||
HTTP binding: | ||
{ endpoint} ?query={query} & default-graph-uri={uri} | ||
Requires/assumes application/sparql-results+xml response. | ||
--> | ||
<inputs> | ||
<key id='query' type='xs:string' paramType='variable' required='true' /> | ||
<key id='service' type='xs:uri' paramType='variable' required='true' /> | ||
</inputs> | ||
|
||
<execute> | ||
<![CDATA[ | ||
url = unescape(service) + "?query=" + escape(query); | ||
var resp = y.rest(url).accept("application/sparql-results+xml").get(); | ||
var data = resp.response; | ||
default xml namespace = ''; | ||
var sparqlns = new Namespace('http://www.w3.org/2005/sparql-results#'); | ||
var xdata = <sparql>{data}</sparql>; | ||
var results = <sparql> | ||
<query>{query}</query> | ||
</sparql>; | ||
for each (var result in xdata.sparqlns::sparql.sparqlns::results.elements()) { | ||
var row = <result/>; | ||
for each (var binding in result.elements()) { | ||
var b = <{binding.@name}/>; | ||
for each (var e in binding.elements()) { | ||
b.appendChild(<type>{e.localName()}</type>); | ||
b.appendChild(<value>{e.text()}</value>); | ||
} | ||
row.appendChild(b); | ||
} | ||
results.sparql += row; | ||
} | ||
response.object = results; | ||
]]> | ||
</execute> | ||
</select> | ||
</bindings> | ||
|
||
</table> |