Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
dajobe committed Mar 4, 2010
1 parent 2208b53 commit b0c7e32
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
31 changes: 31 additions & 0 deletions sparql/README.md
@@ -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: &lt;http://xmlns.com/foaf/0.1/&gt; SELECT $s $p $o FROM &lt;http://www.dajobe.org/foaf.rdf&gt; 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: &lt;http://xmlns.com/foaf/0.1/&gt; SELECT $nick $name FROM &lt;http://www.dajobe.org/foaf.rdf&gt; 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/
61 changes: 61 additions & 0 deletions sparql/sparql.search.xml
@@ -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: &lt;http://xmlns.com/foaf/0.1/&gt; SELECT $nick $name FROM &lt;http://www.dajobe.org/foaf.rdf&gt; 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>

0 comments on commit b0c7e32

Please sign in to comment.