generic sparql queries - geovistory/lod4hss-harvest GitHub Wiki

Get frequency of instances of owl classes

PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT  (STR(?eff) as ?str_eff) (GROUP_CONCAT(?label; SEPARATOR = ' / ')  as ?cct_label)  ?class
WHERE {
{
    SELECT (COUNT(*) as ?eff) ?class ?label
WHERE {
  ?inst a ?class.
  ### comment next line to have all classes
  ?class a owl:Class.
      OPTIONAL { ?class rdfs:label ?label}

}
GROUP BY ?class ?label

}
FILTER(strlen(?label))
   
}
GROUP BY ?class ?eff
ORDER BY DESC(?eff)

Get frequency of properties

PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT DISTINCT ?property ?label (COUNT(*) as ?eff)
WHERE {
  ?s ?property ?o.
  OPTIONAL { ?property rdfs:label ?label}
}
GROUP BY ?property ?label
ORDER BY DESC(?eff)

Get URI providers and their frequency

PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT (count(*) as ?eff) ?hostname WHERE {
  #?s <https://ontome.net/property/1943> ?p
  ?sub owl:sameAs ?uri .
  # filter(contains(str(?uri),"idref"))
  bind(strbefore(strafter(str(?uri),"//"),"/") as ?hostname)
}  group by ?hostname
order by desc(?eff)
limit 10

Exemples d'URI

PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?sub ?subLabel ?uri WHERE {
  ?sub owl:sameAs ?uri ;
       rdfs:label ?subLabel
   filter(contains(str(?subLabel),"Kepl"))
  # filter(contains(str(?uri),"idref"))
  }  
limit 10

Properties of an entity, including literal datatype

Outgoing triples of Ship Voyage from Texel to Jakarta, including literal data type of literals:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xml: <http://www.w3.org/XML/1998/namespace>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX time: <http://www.w3.org/2006/time#>
PREFIX ontome: <https://ontome.net/ontology/>
PREFIX geov: <http://geovistory.org/resource/>

SELECT ?subject ?predicate ?object ?dt
WHERE {
  geov:i151089 ?predicate ?object .
  BIND (datatype(?object) AS ?dt)
}
LIMIT 10

Frequency of incoming properties of an entity

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xml: <http://www.w3.org/XML/1998/namespace>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX time: <http://www.w3.org/2006/time#>
PREFIX ontome: <https://ontome.net/ontology/>
PREFIX geov: <http://geovistory.org/resource/>

SELECT ?predicate (count(distinct ?subject) as ?count) 
WHERE {
 ?subject ?predicate geov:i209502 .
}
GROUP BY ?predicate 
LIMIT 100

First 10 incoming properties of an entity

PREFIX geov: <http://geovistory.org/resource/>

SELECT ?subject ?predicate
WHERE {
?subject ?predicate geov:i196955 .
}
LIMIT 10	

Example literal of type langString 

Outgoing triples of the OntoME property 1354. The object of rdfs:label is a literal of type rdf:langString.

PREFIX ontome: <https://ontome.net/ontology/>

SELECT ?predicate ?object ?dt
WHERE {
  ontome:p1354 ?predicate ?object .
  BIND (datatype(?object) AS ?dt)
}
LIMIT 10

Example literal of type xsd:string

Outgoing triples of the Appellation in a Language i182675. The objects of ontome:p1113 and rdfs:label are a literals of type xsd:string.

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX ontome: <https://ontome.net/ontology/>
PREFIX geov: <http://geovistory.org/resource/>

SELECT ?predicate ?object ?dt
WHERE {
  geov:i182675 ?predicate ?object .
  BIND (datatype(?object) AS ?dt)
}
LIMIT 10

Example literal of type geo:wktLiteral

Outgoing triples of a Presence. The object of ontome:p148 is a literal of type geo:wktLiteral

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xml: <http://www.w3.org/XML/1998/namespace>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX time: <http://www.w3.org/2006/time#>
PREFIX ontome: <https://ontome.net/ontology/>
PREFIX geov: <http://geovistory.org/resource/>

SELECT ?predicate ?object ?dt
WHERE {
  geov:i253594 ?predicate ?object .
  BIND (datatype(?object) AS ?dt)
}
LIMIT 10

Example literals of type time:*

Outgoing triples of DateTimeDescription geov:i271905. See the objects and their data types:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xml: <http://www.w3.org/XML/1998/namespace>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX time: <http://www.w3.org/2006/time#>
PREFIX ontome: <https://ontome.net/ontology/>
PREFIX geov: <http://geovistory.org/resource/>

SELECT ?subject ?predicate ?object ?dt
WHERE {
  geov:i271905 ?predicate ?object .
  BIND (datatype(?object) AS ?dt)
}
LIMIT 10