ResourceTopicPortals

From SPARQL Working Group
Revision as of 08:48, 25 May 2009 by KjetilK (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


Topic-centric portals and multimedia systems

Background

Computas AS has developed two systems for customers that uses SPARQL/Update. The first is a system that uses SKOS thesauri to organize web resources. The portal, which is available to the public through several Norwegian libraries, helps the users find resources based on freetext search, facetted search and navigation through a topic structure. Any relation between topics are allow, not just hierarchal.

The next system, reuses much of the codebase of the former, but is based on an OWL ontology, to display material on multimedia terminals. In both cases, the administration interface uses SPARQL/Update to interact with the data, which is in a quad store.

The queries

I've taken excerpts from the logs of both systems. Most of the queries are real in the sense that they are used in a live system. Some queries are tests from a development system, but the query has a counterpart in the deployed system. So, this gives a pretty good view of how SPARQL/Update is actually used. Most of these queries have been written by Magnus Haraldsen Amundsen.

Insert a literal

This inserts a literal, but first it makes sure that there is nothing is allready there.

PREFIX sub: <http://xmlns.computas.com/sublima#>
DELETE FROM GRAPH <http://msone.computas.no/graphs/infobox/ontology_mediasone> 
  { <http://www.computas.com/mediasone-ontologi#Home> ?p ?o . }
WHERE {<http://www.computas.com/mediasone-ontologi#Home> ?p ?o .}
INSERT DATA INTO <http://msone.computas.no/graphs/infobox/ontology_mediasone> {
  <http://www.computas.com/mediasone-ontologi#Home> sub:infobox """Hjem kj\u00E6re hjem!"""@no .
}

Insert some basic data

Create a graph and add some basic data about it and the archive contained in it.

CREATE GRAPH <http://msone.computas.no/graphs/instance/hamsun>
INSERT INTO GRAPH <http://msone.computas.no/graphs> 
{
  <http://msone.computas.no/graphs/instance/hamsun> a <http://www.computas.com/mediasone#Archive> ;
  rdfs:label "Hamsun" .
  <http://msone.computas.no/graphs/instance/hamsun> a <http://msone.computas.no/graphs#InstanceGraph> .
}

Update data about an admin

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX sioc: <http://rdfs.org/sioc/ns#>
DELETE FROM <http://msone.computas.no/graphs>
{
  <http://localhost:8180/sublima-webapp-1.0-SNAPSHOT/role/Administrator> ?o ?p .
}
WHERE {
  <http://localhost:8180/sublima-webapp-1.0-SNAPSHOT/role/Administrator> ?o ?p .
}
INSERT DATA INTO <http://msone.computas.no/graphs>
{
  <http://localhost:8180/sublima-webapp-1.0-SNAPSHOT/role/Administrator> a sioc:Role ;
                                           rdfs:label "Administrator"@no .
}

Add timestamp

INSERT INTO <http://msone.computas.no/graphs/ontology/mediasone> {
  <http://msone.computas.no/graphs/ontology/mediasone> <http://purl.org/dc/terms/dateAccepted>     
                            "2009-05-04T13:22:34"^^<http://www.w3.org/2001/XMLSchema#dateTime>
} 

Remove timestamp

DELETE FROM <http://msone.computas.no/graphs/vocab/mediasone> 
{  
  <http://msone.computas.no/graphs/vocab/mediasone> <http://purl.org/dc/terms/dateAccepted> ?o 
} 
WHERE 
{ 
  <http://msone.computas.no/graphs/vocab/mediasone> <http://purl.org/dc/terms/dateAccepted> ?o 
}

Add some data about a Work

PREFIX dct: <http://purl.org/dc/terms/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX mv: <http://www.computas.com/mediasone#>
DELETE FROM GRAPH <http://msone.computas.no/graphs/instance/hamsun> {
  <http://msonetest.computas.no:8180/mediasone/track/om-a-avfinne-seg-med-forholdene-i-norge-og-om-norsk-arbeiderdiktning> ?p ?o .
  ?s <http://purl.org/dc/terms/modified> ?o2 .
}
WHERE { 
  <http://msonetest.computas.no:8180/mediasone/track/om-a-avfinne-seg-med-forholdene-i-norge-og-om-norsk-arbeiderdiktning> ?p ?o .
  ?s <http://purl.org/dc/terms/modified> ?o2 .
}
INSERT INTO GRAPH <http://msone.computas.no/graphs/instance/hamsun> 
{
  <http://msone.computas.no/graphs/instance/hamsun> <http://purl.org/dc/terms/modified> "2009-05-11T15:37:42"^^<http://www.w3.org/2001/XMLSchema#dateTime> .
  <http://msonetest.computas.no:8180/mediasone/track/om-a-avfinne-seg-med-forholdene-i-norge-og-om-norsk-arbeiderdiktning> dct:description """Intervju i NRK"""@en .
  <http://msonetest.computas.no:8180/mediasone/track/om-a-avfinne-seg-med-forholdene-i-norge-og-om-norsk-arbeiderdiktning> dct:source <http://msone.computas.no/graphs/instance/hamsun> .
  <http://msonetest.computas.no:8180/mediasone/track/om-a-avfinne-seg-med-forholdene-i-norge-og-om-norsk-arbeiderdiktning> dct:title """Om \u00E5 avfinne seg med forholdene i Norge og om norsk arbeiderdiktning."""@en .
  <http://msonetest.computas.no:8180/mediasone/track/om-a-avfinne-seg-med-forholdene-i-norge-og-om-norsk-arbeiderdiktning> mv:streamURL <http://www.example.org/media/tema/hamsun/lyd/nrk/nrk_om_aa_avfinne_seg.ogg> .
  <http://msonetest.computas.no:8180/mediasone/track/om-a-avfinne-seg-med-forholdene-i-norge-og-om-norsk-arbeiderdiktning> rdf:type <http://musicbrainz.org/mm/mm-2.1#Track> .
  <http://msonetest.computas.no:8180/mediasone/track/om-a-avfinne-seg-med-forholdene-i-norge-og-om-norsk-arbeiderdiktning> rdf:type <http://creativecommons.org/ns#Work> .
}

Delete related concepts

PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
DELETE FROM <http://smil.sublima.computas.com:8180/smil/> 
{ 
   ?s ?p <http://smil.sublima.computas.com:8180/smil/topic/betennelse-i-nedre-bihuler> . 
} 
WHERE { 
  ?s a skos:Concept . 
  ?s ?p <http://smil.sublima.computas.com:8180/smil/topic/betennelse-i-nedre-bihuler> . 
}


Insert new concept

but first ensure that there is nothing in the quad store from earlier.

PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX wdr: <http://www.w3.org/2007/05/powder#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
DELETE FROM GRAPH <http://smil.sublima.computas.com:8180/smil/> {    
  <http://smil.sublima.computas.com:8180/smil/topic/betennelse-i-nedre-bihuler> ?p ?o . 
}
WHERE { 
  <http://smil.sublima.computas.com:8180/smil/topic/betennelse-i-nedre-bihuler> ?p ?o . 
}
INSERT INTO GRAPH <http://smil.sublima.computas.com:8180/smil/> {
  <http://smil.sublima.computas.com:8180/smil/topic/betennelse-i-nedre-bihuler> <http://www.w3.org/2004/02/skos/core#broader> <http://smil.sublima.computas.com:8180/smil/topic/topic000173> .
  <http://smil.sublima.computas.com:8180/smil/topic/betennelse-i-nedre-bihuler> rdf:type <http://www.w3.org/2004/02/skos/core#Concept> .
  <http://smil.sublima.computas.com:8180/smil/topic/betennelse-i-nedre-bihuler> skos:altLabel """vondt i ansiktet"""@no .
  <http://smil.sublima.computas.com:8180/smil/topic/betennelse-i-nedre-bihuler> skos:definition """Kan v\u00E6re \u00E5rsaken hvis man har vondt midt i ansiktet."""@no .
  <http://smil.sublima.computas.com:8180/smil/topic/betennelse-i-nedre-bihuler> skos:note """"""@no .
  <http://smil.sublima.computas.com:8180/smil/topic/betennelse-i-nedre-bihuler> skos:prefLabel """Betennelse i nedre bihuler"""@no .
  <http://smil.sublima.computas.com:8180/smil/topic/betennelse-i-nedre-bihuler> wdr:describedBy <http://sublima.computas.com/status/nytt_forslag> .
}

Merge two concepts

This is done in three queries, first insert the new one.

PREFIX wdr:             <http://www.w3.org/2007/05/powder#>
PREFIX skos:            <http://www.w3.org/2004/02/skos/core#>
INSERT INTO <http://smil.sublima.computas.com:8180/smil/>
{
  <http://smil.sublima.computas.com:8180/smil/topic/akupunktur-og-alternativ-medisin> a skos:Concept ;
                                                 skos:prefLabel "Akupunktur og alternativ medisin"@no;
                      wdr:describedBy <http://sublima.computas.com/status/godkjent_av_administrator> .
}

Then inherit the properties of one of the old ones.

PREFIX owl: <http://www.w3.org/2002/07/owl#>
INSERT INTO <http://smil.sublima.computas.com:8180/smil/> {    
  <http://smil.sublima.computas.com:8180/smil/topic/akupunktur-og-alternativ-medisin> ?p ?o }
WHERE { 
  OPTIONAL {
     <http://smil.sublima.computas.com:8180/smil/topic/topic00013> ?p ?o . 
     ?p a owl:ObjectProperty . 
  }
  OPTIONAL {
     <http://smil.sublima.computas.com:8180/smil/topic/topic00013> ?p ?o . 
     ?p a owl:SymmetricProperty . 
  } 
}

Finally set the status of the old one:

PREFIX wdr: <http://www.w3.org/2007/05/powder#>
PREFIX status: <http://sublima.computas.com/status/>
MODIFY <http://smil.sublima.computas.com:8180/smil/>
DELETE { <http://smil.sublima.computas.com:8180/smil/topic/topic00013> wdr:describedBy ?status . }
INSERT { <http://smil.sublima.computas.com:8180/smil/topic/topic00013> wdr:describedBy status:inaktiv . }
WHERE { <http://smil.sublima.computas.com:8180/smil/topic/topic00013> wdr:describedBy ?status . }

Create relation

This creates a new type of relation that can be used between topics:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
DELETE FROM GRAPH <http://smil.sublima.computas.com:8180/smil/> {  
  <http://smil.sublima.computas.com:8180/smil/topicrelations/forarsaker> ?p ?o . 
}
WHERE { 
  <http://smil.sublima.computas.com:8180/smil/topicrelations/forarsaker> ?p ?o . 
}
INSERT INTO GRAPH <http://smil.sublima.computas.com:8180/smil/> {
  <http://smil.sublima.computas.com:8180/smil/topicrelations/forarsaker> a <http://www.w3.org/2002/07/owl#ObjectProperty> .
  <http://smil.sublima.computas.com:8180/smil/topicrelations/forarsaker> rdfs:label """for\u00E5rsaker"""@no .
  <http://smil.sublima.computas.com:8180/smil/topicrelations/forarsaker> rdfs:subPropertyOf <http://www.w3.org/2004/02/skos/core#semanticRelation> .
}

Mass editing

This use case is an important use case, as URIs are often not very cool, and change, but in ways that makes it possible to change many URIs using a regular expression. This results in a list of resources that where the URIs change. One of the queries to change the URI of one resource is:


MODIFY <http://smil.sublima.computas.com:8180/smil/>
DELETE { <http://www.radiumhospitalet.no/Norsk/Pasienter_og_parorende/Diagnose_og_behandling/Hormonbehandling/> ?p ?o }
INSERT { <http://www.rikshospitalet.no/Norsk/Pasienter_og_parorende/Diagnose_og_behandling/Hormonbehandling/> ?p ?o }
WHERE { <http://www.radiumhospitalet.no/Norsk/Pasienter_og_parorende/Diagnose_og_behandling/Hormonbehandling/> ?p ?o }

It would be nice to be able to update many such URIs without iterating over them as is currently done.


Add a new user

Very similar to other queries, it adds a new user, but makes sure there isn't anything there from earlier:


PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX wdr: <http://www.w3.org/2007/05/powder#>
PREFIX sioc: <http://rdfs.org/sioc/ns#>
DELETE FROM GRAPH <http://smil.sublima.computas.com:8180/smil/> { 
  <http://smil.sublima.computas.com:8180/smil/user/mailtolarshvermannsenno> ?p ?o . 
}
WHERE { 
  <http://smil.sublima.computas.com:8180/smil/user/mailtolarshvermannsenno> ?p ?o . 
}
INSERT INTO GRAPH <http://smil.sublima.computas.com:8180/smil/> {
  <http://smil.sublima.computas.com:8180/smil/user/mailtolarshvermannsenno> rdf:type <http://rdfs.org/sioc/ns#User> .
  <http://smil.sublima.computas.com:8180/smil/user/mailtolarshvermannsenno> rdfs:label """Lars Hvermannsen"""@no .
  <http://smil.sublima.computas.com:8180/smil/user/mailtolarshvermannsenno> sioc:email <mailto:lars@hvermannsen.no> .
  <http://smil.sublima.computas.com:8180/smil/user/mailtolarshvermannsenno> sioc:has_function <http://smil.sublima.computas.com:8180/smil/role/Administrator> .
  <http://smil.sublima.computas.com:8180/smil/user/mailtolarshvermannsenno> wdr:describedBy <http://sublima.computas.com/status/inaktiv> .
}

Move data between graphs

We do also have a query that move data between graphs, updateing a timestamp, filtering on a list of certain subjects.

INSERT INTO GRAPH <http://msone.computas.no/graphs/instance/dummy1>
{
  ?s ?p ?o .
  ?s ?p3 ?o1 .
  ?s1 ?p1 ?s .
  ?o ?p2 ?o2 .
  ?s <http://xmlns.computas.com/sublima#importDate> """20-04-2009""" .
  ?s1 <http://xmlns.computas.com/sublima#importDate> """20-04-2009""" .
  ?o <http://xmlns.computas.com/sublima#importDate> """20-04-2009""" .
}
WHERE
{ 
  GRAPH  <http://msone.computas.no/graphs/temp/dummy1>
  {
    ?s ?p ?o .
    OPTIONAL {?s1 ?p1 ?s}
    OPTIONAL {?o ?p2 ?o2}
    OPTIONAL {?s ?p3 ?o1}
    FILTER (?s in (
      <file:/c:/tmp/mp3/Mediesone.wmv>))
  }
}