%META:TOPICPARENT{name="VOSSPARQL"}%
%VOSNAV%
---++ SPARQL Sample Queries using Live Demonstration Data
This page presents examples of querying ODS RDF Graph via SPARQL.
---+++Querying ODS Data via RDF data mapped to SIOC Ontology
Graph IRI format: http://<cname>/dataspace
Examples:
1 Public Demo Server Instance: http://demo.openlinksw.com/dataspace
1 MyOpenLink Services (a demo instance of ODS): http://myopenlink.net/dataspace
---++++Setup Guide
* MyOpenLink.net Service: You can either log on as user: test1, pwd: 1 or create a new account at http://myopenlink.net:8890/ods.
* Live Demo Server: You can either log on as user: demo, pwd: demo or create a new account at: http://demo.openlinksw.com/ods
If you are creating a new account, please perform the following steps:
1 Register under a username of your choosing
1 Create ODS Application instances (aka Data Space Applications) for Briefcase, FeedManager, Mail, Blog, Wiki, Gallery, Bookmarks.
1 Log under new user or use account: test1 and then proceed to the "My Weblog"
1 Create a few sample blog posts
1 Go to the "My Wiki" tab
1 Create a sample Wiki article: Test1Sample, for instance
1 Go to the Wiki Cluster Settings and press `Turn On' to enable Conversations
1 Verify the "Conversation" feature by going to the "Discussions" tab in your ODS home, to see if a newsgroup has been automatically generated for your Wiki article. It should appear as: "oWiki-test1Wiki" assuming this is the name of your Wiki Data Space Instance
1 From the WelcomeVisitors page clicks the Conversations link and sends one reply with body "This is sample reply"
1 Create Data Space instances for the other ODS applications by clicking on the "My...." tabs which indicate each ODS Data Space
1 Proceed to experiment with the SPARQL queries below.
---++++SPARQL Query Interfaces
The SPARQL Sample queries can be executed using Virtuoso's traditional console-based ISQL interface, the Web-based equivalent bundled with the Virtuoso Conductor Admin UI, or by using the iSPARQL Web Query Interface at http://myopenlink.net:8890/sparql_demo/ or exposed via the SPARQL endpoint at: http://myopenlink.net:8890/sparql/ . Of course you can also use the SPARQL Protocol to invoke these queries over HTTP using the SPARQL Query Endpoint at: http://myopenlink.net:8890/sparql/.
*Note*: If you are using SQL-based Data Access methods such as ISQL, ODBC, JDBC, ADO.NET, or XMLA , you must prepend each query with sparql which is the convention required for executing SPARQL via Virtuoso SQL. Also do not forget to terminate your queries with semicolons (;) when using the ISQL interface in console mode.
---++++Query Samples
Note: Default Graph URI value used in the queries below is: http://myopenlink.net/dataspace
* To return a list of all Classes
PREFIX rdf:
PREFIX sioc:
SELECT distinct ?cls
WHERE { ?o rdf:type ?cls }
ORDER BY ?cls
* To return all Spaces
PREFIX sioc:
PREFIX rdf:
SELECT DISTINCT ?space ?name
WHERE
{
?space rdf:type sioc:Space.
optional { ?site sioc:name ?name }
}
* To return a list of Predicates/Properties/Attributes
PREFIX rdf:
PREFIX sioc:
PREFIX dct:
PREFIX dcc:
SELECT distinct ?Predicate
WHERE { ?o ?Predicate ?s . }
ORDER BY ?Predicate
* To list all posts title, author, reply and post date.
PREFIX sioc:
PREFIX rdfs:
PREFIX dct:
PREFIX dcc:
SELECT DISTINCT ?post, ?post_sioc, ?post_author, ?post_title, ?post_date, ?reply
WHERE
{
optional { ?post dct:title ?post_title }.
optional { ?post dcc:created ?post_date}.
optional { ?post sioc:has_creator ?creator}.
optional { ?creator rdfs:label ?post_author}.
optional { ?post sioc:has_reply ?reply }.
optional { ?post rdfs:seeAlso ?post_sioc }.
}
* To list all blog data spaces which belongs to friends of ODS user _test1_
PREFIX sioc:
PREFIX sioct:
PREFIX rdf:
PREFIX foaf:
SELECT ?n, ?knows, ?name
WHERE
{
?po sioc:account_of ?t .
?t rdf:type foaf:Person .
?t foaf:nick ?n filter regex ('test1', ?n) .
?t foaf:knows ?s .
?s foaf:nick ?knows .
?s foaf:holdsAccount ?xx .
?xx sioc:owner_of ?f .
?f a sioct:Weblog .
optional{?f sioc:id ?name}.
}
* To list all posts from ODS user _test1_'s blogs
PREFIX rdf:
PREFIX sioc:
PREFIX dct:
PREFIX dcc:
PREFIX sioct:
SELECT ?post, ?title ?cr ?name
WHERE
{
optional{ ?post dct:title ?title }.
optional{ ?post dcc:created ?cr }.
?post sioc:has_container ?forum .
?forum rdf:type sioct:Weblog .
?forum ?has_member ?member .
?member sioc:id ?name filter regex (?name, 'test1') .
}
* Find all posts from _test1_'s blogs including post timestamps accurate to the second (as opposed to millisecond)
PREFIX rdf:
PREFIX sioc:
PREFIX sioct:
PREFIX xsd:
PREFIX dct:
PREFIX dcc:
SELECT ?title ?cr ?forum
WHERE
{
optional{?post dcc:created ?cr}.
optional{?post dct:title ?title }.
?post sioc:has_container ?forum .
?forum rdf:type sioct:Weblog .
?forum ?has_member ?member .
?member sioc:name "test1" .
filter (xsd:dateTime (?cr) > xsd:dateTime ("2006-05-01T10:56:00Z"))
}
ORDER BY ?cr limit 10
* To find all Data Spaces belonging to ODS member: _test1_
PREFIX rdf:
PREFIX rdfs:
PREFIX sioc:
SELECT DISTINCT ?u ?name ?group
WHERE
{
?x rdf:type sioc:User .
?x sioc:name ?name .
?u sioc:has_member ?x .
{ ?u sioc:id ?group } UNION
{ ?u sioc:description ?group } .
FILTER REGEX(str(?name), "^test1")
}
* To find all Briefcase Data Spaces owned by friends of user _test1_:
PREFIX sioc:
PREFIX sioct:
PREFIX rdf:
PREFIX foaf:
SELECT ?n, ?knows, ?name
WHERE
{
?po sioc:account_of ?t .
?t rdf:type foaf:Person .
?t foaf:nick ?n filter regex ('test1', ?n) .
?t foaf:knows ?s .
?s foaf:nick ?knows .
?s foaf:holdsAccount ?xx .
?xx sioc:owner_of ?f .
?f a sioct:Briefcase.
optional{?f sioc:id ?name}.
}
* To find all ODS Data Spaces belonging to friends of user 'test1':
PREFIX sioc:
PREFIX sioct:
PREFIX rdf:
PREFIX foaf:
SELECT ?n, ?knows, ?name
WHERE
{
?po sioc:account_of ?t .
?t rdf:type foaf:Person .
?t foaf:nick ?n filter regex ('test1', ?n) .
?t foaf:knows ?s .
?s foaf:nick ?knows .
?s foaf:holdsAccount ?xx .
?xx sioc:owner_of ?f .
optional{?f sioc:id ?name}.
}
* To find all Feed subscriptions that have ODS member: 'test1'
PREFIX rdf:
PREFIX sioc:
PREFIX sioct:
SELECT *
WHERE
{
?f rdf:type sioct:SubscriptionList .
optional{?f sioc:has_member ?m}.
?m sioc:id ?name filter regex(?name,'test1')
}
* To find all Feeds entries/posts/items for ODS member: 'test1':
define input:inference "http://myopenlink.net/dataspace"
PREFIX rdf:
PREFIX sioc:
PREFIX dct:
PREFIX sioct:
SELECT ?fname ?post ?title
WHERE
{
?forum rdf:type sioct:SubscriptionList .
?forum sioc:id ?fname .
?forum ?has_member ?member filter regex (?member, "test1").
optional{?forum sioc:parent_of ?parentf }.
optional{?parentf sioc:container_of ?post} .
optional{ ?post dct:title ?title }.
}
* To find all Feed Data Spaces hosted by the MyOpenLink.net service:
PREFIX rdf:
PREFIX sioct:
SELECT *
WHERE { ?f rdf:type sioct:SubscriptionList . }
* To find all Blog Data Spaces hosted by the MyOpenLink.net service:
PREFIX rdf:
PREFIX sioct:
SELECT *
WHERE { ?f rdf:type sioct:Weblog. }
* To find all Wiki Data Spaces hosted by the MyOpenLink.net service:
PREFIX rdf:
PREFIX sioct:
SELECT *
WHERE { ?f rdf:type sioct:Wiki .}
* To find all Wiki Data Spaces and their respective owners:
PREFIX rdf:
PREFIX sioc:
PREFIX sioct:
SELECT *
WHERE
{
?f rdf:type sioct:Wiki .
?f sioc:has_owner ?owner.
?owner sioc:id ?name .
}
* To find all ODS Wiki Data Spaces where instance name contains the string pattern: 'test'
PREFIX rdf:
PREFIX sioc:
PREFIX sioct:
SELECT *
WHERE {
?f rdf:type sioct:Wiki .
?f sioc:id ?s.
FILTER REGEX(str(?s), "^test")
}
* To find all Wiki articles created ODS member: 'test1'
define input:inference "http://myopenlink.net/dataspace"
PREFIX rdf:
PREFIX sioc:
PREFIX sioct:
PREFIX dct:
SELECT *
WHERE
{
?forum rdf:type sioct:Wiki .
?forum sioc:id ?forum_name.
?forum ?has_member ?member .
?member sioc:id "test1" .
?forum sioc:container_of ?post .
optional{?post dct:title ?title}.
}
* To find all the Wiki articles associated with one or more conversations managed by newsgroup: oWiki-test1Wiki.
PREFIX sioc:
PREFIX rdf:
PREFIX dct:
PREFIX dcc:
PREFIX sioct:
SELECT ?title ?created
WHERE
{
graph
{
?forum sioc:id "oWiki-test1WikiEndpoint" .
?forum rdf:type sioct:MessageBoard .
?forum sioc:container_of ?post .
optional { ?post sioc:link ?link } .
optional { ?post dct:title ?title}.
optional { ?post dcc:created ?created }.
}
}
* To find all discussions entries/posts across all conversation enabled ODS Data Spaces:
PREFIX sioc:
PREFIX rdf:
PREFIX dct:
PREFIX dcc:
PREFIX sioct:
SELECT ?title ?created
WHERE {
graph
{
?forum rdf:type sioct:MessageBoard .
?post sioc:has_container ?forum .
optional { ?post sioc:link ?link } .
optional { ?post dct:title ?title}.
optional { ?post dcc:created ?created }.
}
}
ORDER BY DESC (?created)
LIMIT 10
* To find all Photo Gallery Data Spaces hosted by the MyOpenLink.net service:
PREFIX rdf:
PREFIX sioct:
SELECT *
WHERE { ?forum rdf:type sioct:ImageGallery . }
---+++Learn More
* [[ODSSIOCRef][ODS SIOC reference]]
* [[ODSAtomOWLRef][Query ODS Data Spaces using SPARQL and Atom OWL Ontology]]
* [[ODSSKOSRef][Query ODS Data Spaces using SPARQL and SKOS Ontology]]
* [[ODSFOAFRef][Query ODS Data Spaces using SPARQL and FOAF Ontology]]
* [[ODSAnnoteaRef][Query ODS Data Spaces using SPARQL and Annotea Ontology]]
* [[NorthWindREF][Northwind SPARQL Reference]]
* [[SIOCRefTutorial][Query Virtuoso Tutorials using SPARQL]]
* [[SIOCRefDocs][Query Virtuoso Documentation using SPARQL]]
* [[WordPressSIOCRef][WordPress SIOC Reference]]
* [[MediaWikiSIOCRef][MedaWiki SIOC Reference]]
* [[PHPBB3SIOCRef][PHPBB SIOC Reference]]
* [[DrupalSIOCRef][Drupal SIOC Reference]]
CategoryWebSite CategoryVirtuoso CategoryOpenSource CategoryVOS CategorySPARQL CategoryRDF CategoryODS CategorySample CategoryDocumentation
%VOSCOPY%