SWAT4LS2012 Tutorial

From NCBO Wiki
Jump to navigation Jump to search

Tutorial documentation to be added here.

Example queries
--> Slide 27
-- Select count of all terms from ABA. Result is 913 rows returned.
PREFIX owl:  <http://www.w3.org/2002/07/owl#>
SELECT (count(*) as ?c)
FROM <http://bioportal.bioontology.org/ontologies/ABA>
WHERE {
  ?s a owl:Class .
       }
 
-- Select count of all terms from ABA and HP. Result is 10855 rows returned.
PREFIX owl:  <http://www.w3.org/2002/07/owl#>
SELECT (count(*) as ?c)
FROM <http://bioportal.bioontology.org/ontologies/ABA>
FROM <http://bioportal.bioontology.org/ontologies/HP>
WHERE {
  ?s a owl:Class .
       }

-- Select all distinct triples that have the specified URI as a subject
PREFIX owl:  <http://www.w3.org/2002/07/owl#>
SELECT DISTINCT *
WHERE {
  <http://purl.obolibrary.org/obo/BFO_0000001> ?p ?o .
       }


--> Slide 29
-- Select the URI and preferred name from ABA (OWL format) and HP (OBO format) using the "globals" graph
PREFIX owl:  <http://www.w3.org/2002/07/owl#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT DISTINCT ?termURI ?prefLabel
 FROM <http://bioportal.bioontology.org/ontologies/ABA>
 FROM <http://bioportal.bioontology.org/ontologies/HP>
 FROM <http://bioportal.bioontology.org/ontologies/globals> 
WHERE {
      ?termURI a owl:Class;
      skos:prefLabel ?prefLabel .
} 
LIMIT 20 //limit added for demo query


--> Slide 30
-- Select all ontology graphs
PREFIX meta: <http://bioportal.bioontology.org/metadata/def/>
SELECT DISTINCT ?graph 
WHERE {
    [] meta:hasDataGraph ?graph 
}
ORDER BY ?graph

--> No slide
-- Select the count of all graphs
PREFIX meta: <http://bioportal.bioontology.org/metadata/def/> 
SELECT (COUNT(?graph) as ?c)
WHERE { 
    [] meta:hasDataGraph ?graph
}


--> Slide 31
-- Describe SNOMEDCT
DESCRIBE <http://bioportal.bioontology.org/ontologies/46896>


--> Slide 32
-- Select all ontologies updated since some DATE
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX meta: <http://bioportal.bioontology.org/metadata/def/>
PREFIX omv: <http://omv.ontoware.org/2005/05/ontology#>

SELECT ?version ?name ?creation WHERE { 
       ?version a omv:Ontology .
       ?version  omv:name ?name .
       ?version meta:timestampCreation ?creation .
       FILTER (xsd:dateTime(?creation) > "2012-10-01T00:00:00"^^xsd:dateTime)
} ORDER BY ?name


--> Slide 33
-- Select the latest versions of all ontologies
PREFIX meta: <http://bioportal.bioontology.org/metadata/def/> 
PREFIX omv: <http://omv.ontoware.org/2005/05/ontology#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT ?ont ?name ?acr ?creationDate ?contactName ?terms
WHERE { 
   ?ont a omv:Ontology;
       omv:acronym ?acr;
       omv:name ?name;
       meta:timestampCreation ?creationDate .
       OPTIONAL { ?ont meta:hasContactName ?contactName . }
       OPTIONAL { ?ont omv:numberOfClasses ?terms . }
} ORDER BY DESC(xsd:dateTime(?creationDate))


--> No slide 
-- List unique graphs and their metadata
PREFIX meta: <http://bioportal.bioontology.org/metadata/def/> 
PREFIX omv: <http://omv.ontoware.org/2005/05/ontology#>
SELECT ?ont ?name ?acronym
WHERE { 
  ?ont meta:hasDataGraph ?graph .
	?ont a omv:Ontology .
	?ont omv:name ?name .
	?ont omv:acronym ?acronym .
}
ORDER BY ?acronym
LIMIT 10 //limit added for demo


--> No slide
-- Download an ontology
CONSTRUCT { ?s ?p ?o } WHERE {
  GRAPH <http://bioportal.bioontology.org/ontologies/1580> {
   ?s ?p ?o .
  }
}


--> Slide 34 
-- Select all graphs that contain a term URI
PREFIX owl:  <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT DISTINCT ?graph WHERE {
GRAPH ?graph {
       <http://mouse.brain-map.org/atlas/index.html#RHP> a owl:Class .
   }
}