ODS.VOSODSSparqlSamples

  • Topic
  • Discussion
  • ODS.VOSODSSparqlSamples(Last) -- DAVWikiAdmin? , 2017-06-29 07:32:35 Edit WebDAV System Administrator 2017-06-29 07:32:35

    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
    2. MyOpenLink? Services (a demo instance of ODS): http://myopenlink.net/dataspace

    Setup Guide

    If you are creating a new account, please perform the following steps:

    1. Register under a username of your choosing
    2. Create ODS Application instances (aka Data Space Applications) for Briefcase, FeedManager, Mail, Blog, Wiki, Gallery, Bookmarks.
    3. Log under new user or use account: test1 and then proceed to the "My Weblog"
    4. Create a few sample blog posts
    5. Go to the "My Wiki" tab
    6. Create a sample Wiki article: Test1Sample, for instance
    7. Go to the Wiki Cluster Settings and press `Turn On' to enable Conversations
    8. 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
    9. From the WelcomeVisitors page clicks the Conversations link and sends one reply with body "This is sample reply"
    10. Create Data Space instances for the other ODS applications by clicking on the "My...." tabs which indicate each ODS Data Space
    11. 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: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX sioc: <http://rdfs.org/sioc/ns#> SELECT distinct ?cls WHERE { ?o rdf:type ?cls } LIMIT 10

    • To return all Spaces

      PREFIX sioc: <http://rdfs.org/sioc/ns#> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT * WHERE { ?space rdf:type sioc:Space. optional { ?site sioc:name ?name } } LIMIT 10

    • To return a list of Predicates/Properties/Attributes

      PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX sioc: <http://rdfs.org/sioc/ns#> PREFIX dct: <http://purl.org/dc/elements/1.1/> PREFIX dcc: <http://purl.org/dc/terms/> SELECT distinct ?Predicate WHERE { ?o ?Predicate ?s . } LIMIT 10

    • To list all posts title, author, reply and post date.

      PREFIX sioc: <http://rdfs.org/sioc/ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX dct: <http://purl.org/dc/elements/1.1/> PREFIX dcc: <http://purl.org/dc/terms/> SELECT * 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 }. } LIMIT 10

    • To list all blog data spaces which belongs to friends of ODS user test1

      PREFIX sioc: <http://rdfs.org/sioc/ns#> PREFIX sioct: <http://rdfs.org/sioc/types#> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> 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: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX sioc: <http://rdfs.org/sioc/ns#> PREFIX dct: <http://purl.org/dc/elements/1.1/> PREFIX dcc: <http://purl.org/dc/terms/> PREFIX sioct: <http://rdfs.org/sioc/types#> 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: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX sioc: <http://rdfs.org/sioc/ns#> PREFIX sioct: <http://rdfs.org/sioc/types#> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> PREFIX dct: <http://purl.org/dc/elements/1.1/> PREFIX dcc: <http://purl.org/dc/terms/> 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: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX sioc: <http://rdfs.org/sioc/ns#> 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: <http://rdfs.org/sioc/ns#> PREFIX sioct: <http://rdfs.org/sioc/types#> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> 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: <http://rdfs.org/sioc/ns#> PREFIX sioct: <http://rdfs.org/sioc/types#> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> 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: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX sioc: <http://rdfs.org/sioc/ns#> PREFIX sioct: <http://rdfs.org/sioc/types#> 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: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX sioc: <http://rdfs.org/sioc/ns#> PREFIX dct: <http://purl.org/dc/elements/1.1/> PREFIX sioct: <http://rdfs.org/sioc/types#> 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: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX sioct: <http://rdfs.org/sioc/types#> SELECT * WHERE { ?f rdf:type sioct:SubscriptionList . }

    • To find all Blog Data Spaces hosted by the MyOpenLink.net service:

      PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX sioct: <http://rdfs.org/sioc/types#> SELECT * WHERE { ?f rdf:type sioct:Weblog. }

    • To find all Wiki Data Spaces hosted by the MyOpenLink.net service:

      PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX sioct: <http://rdfs.org/sioc/types#> SELECT * WHERE { ?f rdf:type sioct:Wiki .}

    • To find all Wiki Data Spaces and their respective owners:

      PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX sioc: <http://rdfs.org/sioc/ns#> PREFIX sioct: <http://rdfs.org/sioc/types#> 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: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX sioc: <http://rdfs.org/sioc/ns#> PREFIX sioct: <http://rdfs.org/sioc/types#> 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: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX sioc: <http://rdfs.org/sioc/ns#> PREFIX sioct: <http://rdfs.org/sioc/types#> PREFIX dct: <http://purl.org/dc/elements/1.1/> 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: <http://rdfs.org/sioc/ns#> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX dct: <http://purl.org/dc/elements/1.1/> PREFIX dcc: <http://purl.org/dc/terms/> PREFIX sioct: <http://rdfs.org/sioc/types#> SELECT ?title ?created WHERE { graph <http://myopenlink.net/dataspace> { ?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: <http://rdfs.org/sioc/ns#> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX dct: <http://purl.org/dc/elements/1.1/> PREFIX dcc: <http://purl.org/dc/terms/> PREFIX sioct: <http://rdfs.org/sioc/types#> SELECT ?title ?created WHERE { graph <http://myopenlink.net/dataspace> { ?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: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX sioct: <http://rdfs.org/sioc/types#> SELECT * WHERE { ?forum rdf:type sioct:ImageGallery . }

    Learn More

    CategoryWebSite CategoryVirtuoso CategoryOpenSource CategoryVOS CategorySPARQL CategoryRDF CategoryODS CategoryDocumentation