SPARQL Tutorial
Headline
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
prefix omn: <http://open-multinet.info/ontology/omn#>
prefix omn-resource: <http://open-multinet.info/ontology/omn-resource#>
prefix omn-domain-nfv: <http://open-multinet.info/ontology/omn-domain-nfv#>
prefix omn-lifecycle: <http://open-multinet.info/ontology/omn-lifecycle#>
prefix time: <http://www.w3.org/2006/time#>
prefix isco: <http://www.gt-arc.com/isco/ontologies/2017/10/sample-lifecycle-offering-1#>
SELECT ?subject ?object
WHERE { ?subject rdf:SubClass omn-domain-nfv:Parameter }
SELECT ?subject ?object
WHERE { ?subject rdfs:subClassOf ?object }
1. Return Instances
?s rdf:type omn:Service .
2. Return subclasses, recursive subclasses
SELECT ?s
WHERE {
?s rdfs:subClassOf* omn:Service .
}
?s rdfs:subClassOf* omn:Service .
3. etc
SELECT ?subject ?object
WHERE { ?subject a omn-lifecycle:State }
SELECT ?domain ?range
WHERE {
omn-resource:hasInterface rdfs:domain ?domain ;
rdfs:range ?range .
}
4. isco example
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
prefix omn: <http://open-multinet.info/ontology/omn#>
prefix omn-resource: <http://open-multinet.info/ontology/omn-resource#>
prefix omn-domain-nfv: <http://open-multinet.info/ontology/omn-domain-nfv#>
prefix omn-lifecycle: <http://open-multinet.info/ontology/omn-lifecycle#>
prefix time: <http://www.w3.org/2006/time#>
prefix isco: <http://www.gt-arc.com/isco/ontologies/2017/10/isco-sample-1#>
SELECT ?subject ?object
WHERE { ?subject omn:hasReservation isco:life3}
5. find subject with value
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?subject ?object
WHERE {
?subject ?p ?o .
filter( str(?o) = "60" )
}
6. Search class by label (must be manually defined)
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
prefix omn: <http://open-multinet.info/ontology/omn#>
prefix omn-resource: <http://open-multinet.info/ontology/omn-resource#>
prefix omn-domain-nfv: <http://open-multinet.info/ontology/omn-domain-nfv#>
prefix omn-lifecycle: <http://open-multinet.info/ontology/omn-lifecycle#>
prefix time: <http://www.w3.org/2006/time#>
prefix policy: <http://www.gt-arc-com/network/management/ontologies/2017/9/policy-information-base#>
SELECT ?s ?p ?o ?classLabel
WHERE {
?s rdfs:subClassOf* policy:QosClass .
?s ?p ?o .
?s rdfs:label ?classLabel .
FILTER regex(?classLabel, "Class0", "i")
SELECT ?g ?s ?p ?o ?about
WHERE {
?s rdfs:range omn:Resource .
?s ?p ?o .
FILTER regex(str(?p), "type", "i")
}
7. Sparql function
7.1 Regex
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?name
WHERE { ?x foaf:name ?name
FILTER regex(?name, "^ali", "i") }
Protege Bug