Skip to content

Instantly share code, notes, and snippets.

View gatemezing's full-sized avatar

Ghislain gatemezing

View GitHub Profile
@gatemezing
gatemezing / EntityByClasses
Created April 28, 2014 14:55
SPARQL query of entities per classes
## Query classes with their entities
SELECT DISTINCT ?class (COUNT(DISTINCT ?x) as ?entities)
where {?x a ?class. ?class a owl:Class. filter (?class != owl:Thing)} GROUP BY ?class HAVING (COUNT(?x)) ORDER BY DESC(?entities)
@gatemezing
gatemezing / listProperties
Last active August 29, 2015 14:01
This query returns all the properties in an endpoint ordered DESC by label
## listing al the properties in an endpoint
select distinct ?s ?label where { {?s a owl:ObjectProperty; rdfs:label ?label} union {?s a owl:DatatypeProperty; rdfs:label ?label} union {?s a rdf:Property; rdfs:label ?label} }order by desc(?label)
@gatemezing
gatemezing / resourceWithDate
Last active August 29, 2015 14:02
List of resources with date in SPARQL
select distinct ?resource ?date where {{?resource ?p ?date. ?p a owl:DatatypeProperty; rdfs:range ?range. filter (?range= xsd:date || ?range= xsd:dateTime )} union {?resource ?p ?o. ?p a rdf:Property; rdfs:range ?range. filter (?range= xsd:date || ?range= xsd:dateTime)}} limit 1000
###equivalent ASK query ######
ASK where {{ ?p a owl:DatatypeProperty; rdfs:range ?range. filter (?range= xsd:date || ?range= xsd:dateTime )} union { ?p a rdf:Property; rdfs:range ?range. filter (?range= xsd:date || ?range= xsd:dateTime)}}
@gatemezing
gatemezing / NumberOfDatasetPerVocabs
Created July 2, 2014 08:25
A query in LOV to get all the vocabs with the number of datasets using them. Link of the result at http://goo.gl/tkY4RN.
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
PREFIX voaf:<http://purl.org/vocommons/voaf#>
SELECT ?vocabURI (count(?dataset) as ?numberDataset)
WHERE{
?vocabURI a voaf:Vocabulary .
?vocabURI voaf:usageInDataset ?usage.
?usage voaf:inDataset ?dataset.
?dataset rdfs:label ?datasetLabel.
@gatemezing
gatemezing / countingGeonamesFeatures
Last active August 29, 2015 14:04
A Query to count geonames features in the wild.
## 1- version for virtuoso endpoints
PREFIX geo-ont: <http://www.geonames.org/ontology#>
SELECT DISTINCT count(?s)
WHERE {
?s a geo-ont:Feature.
filter (contains(str(?s), "sws.geonames.org"))
}
@gatemezing
gatemezing / geonamesPoints
Created August 5, 2014 13:58
Query to create a graph with wkt points in factforge/sparql
PREFIX gn: <http://www.geonames.org/ontology#>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX gsp: <http://www.opengis.net/ont/geosparql#>
CONSTRUCT {
?s a gn:Feature ; gn:countryCode ?code .
?s gn:name ?name ; gn:featureCode ?fcode ; gn:featureClass ?class .
?s rdfs:isDefinedBy ?def.
?s geo:lat ?lat.
@gatemezing
gatemezing / metadataBano2RDF
Created August 22, 2014 12:59
Exemple metadata BANO2RDF
#metadata###
##cas données de la région 01 ##
@prefix dcat: <http://www.w3.org/ns/dcat#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix dcterms: <http://purl.org/dc/terms/> .
<http://www.openstreetmap.fr/bano/data/> a dcat:Catalog ;
dcterms:title "Données des adresses du projet Bano en RDF"@fr ;
@gatemezing
gatemezing / Route2RDF
Created September 15, 2014 17:13
SPARQL query to convert "ROUTE" fro,m BDTOPO into RDF using Datalit CONSTRUCT module
## Q1: Converting PATH (route file) into RDF
## using CONSTRUCT query
PREFIX topo: <http://data.ign.fr/def/topo#>
prefix geom: <http://data.ign.fr/def/geometrie#>
prefix ignfr: <http://data.ign.fr/id/ignf/systCoord/>
prefix gsp: <http://www.opengis.net/ont/geosparql#>
prefix skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
@gatemezing
gatemezing / factforge boundingbox
Created October 10, 2014 08:46
Factforge bounding box use case - Eurecom and Eiffel Tower
# Second level administrative units in France
# in FactForge between Eurecom and Eiffel Tower total 36
# using omgeo:within ( )
PREFIX omgeo: <http://www.ontotext.com/owlim/geo#>
PREFIX geo-ont: <http://www.geonames.org/ontology#>
SELECT DISTINCT ?link ?m
WHERE {
?link geo-ont:name ?m.
?link geo-ont:featureCode geo-ont:A.ADM2 .
@gatemezing
gatemezing / convertIAB++Taxonomy
Created November 7, 2014 14:26
A CONSTRUCT query to transform IAB++ taxonomy in CSV in a vocabulary using Datalift platform. This assumes you have loaded the csv file and already transformed in raw RDF.
PREFIX dcterms: <http://purl.org/dc/terms/>
CONSTRUCT {
?classURI a owl:Class, rdfs:Class.
?classURI rdfs:label ?level1label.
?level2URI a owl:Class, rdfs:Class; rdfs:subClassOf ?classURI;
rdfs:label ?level2label.
?level3URI a owl:Class, rdfs:Class; rdfs:subClassOf ?level2URI;
rdfs:label ?level3label.
?level4URI a owl:Class, rdfs:Class; rdfs:subClassOf ?level3URI;
rdfs:label ?level4label.