### VirtRDF-Label and Faceted Browser rules re. labels for URIs -- The SPARUL statement for loading it into the Quad Store: INSERT INTO WHERE { rdfs:subPropertyOf virtrdf:label . } --Making the rule from the graph: rdfs_rule_set ('facets', 'facets'); -- extend to other rules e.g. virtrdf-label. rdfs_rule_set ('facets', 'virtrdf-label'); ## Google Spreadsheet function http://dbpedia.org/sparql?default-graph-uri=http%3A%2F%2Fdbpedia.org&query=select+%3Fs+%3Fgenre+%3Fdied+%3Fborn+%28bif%3Adatediff%28%27year%27%2Cxsd%3AdateTime%28str%28%3Fborn%29%29%2Cxsd%3AdateTime%28str%28%3Fdied%29%29%29%29+as+%3Fage%0D%0Awhere+%7B+%7B%0D%0Aselect+distinct+%3Fs+%3Fgenre+%3Fdied+%3Fborn+from+%3Chttp%3A%2F%2Fdbpedia.org%3E+where+%0D%0A%7B+%0D%0A++%3Fs+a+%3Chttp%3A%2F%2Fdbpedia.org%2Fontology%2FMusicalArtist%3E+%3B%0D%0A+++++%3Chttp%3A%2F%2Fdbpedia.org%2Fontology%2Fgenre%3E+%3Fgenre%3B%0D%0A+++++%3Chttp%3A%2F%2Fdbpedia.org%2Fontology%2FdeathDate%3E+%3Fdied%3B%0D%0A+++++%3Chttp%3A%2F%2Fdbpedia.org%2Fontology%2FbirthDate%3E+%3Fborn+.%0D%0A%0D%0A++%0D%0A%7D%0D%0A+order+by+desc+%28+%3CLONG%3A%3AIRI_RANK%3E+%28%3Fgenre%29+%29+limit+100+%7D%7D&format=text%2Fcsv&timeout=0&debug=on =ImportHtml("";"table";1) Google HTML Import placehoder: =ImportHtml("http://dbpedia.org/sparql?default-graph-uri=http%3A%2F%2Fdbpedia.org&query=SELECT+DISTINCT+%3Fperson+as+%3Fperson_id+str%28%3Fplabel%29+as+%3Fperson_name+%3Fgenre+as+%3Fgenre_id+str%28%3Fglabel%29+as+%3Fgenre_name+%3Fdied+%3Fborn+%28+%3CLONG%3A%3AIRI_RANK%3E+%28%3Fperson%29+%29+as+%3Frank%0D%0A%28+IF+%28%0D%0A++%28datatype+%28%3Fborn%29+in+%28xsd%3AdateTime%2C+xsd%3Adate%29%29+and%0D%0A++%28datatype+%28%3Fdied%29+in+%28xsd%3AdateTime%2C+xsd%3Adate%29%29%2C%0D%0A++bif%3Adatediff%28%27year%27%2Cxsd%3AdateTime%28str%28%3Fborn%29%29%2Cxsd%3AdateTime%28str%28%3Fdied%29%29%29%2C%0D%0A++%22error%22+%29+%29+as+%3Fage%0D%0AWHERE+%7B+%7B%0D%0ASELECT+DISTINCT+%3Fperson+%3Fplabel+%3Fgenre+%3Fglabel+%3Fdied+%3Fborn+from+%3Chttp%3A%2F%2Fdbpedia.org%3E+WHERE%0D%0A%7B+%0D%0A%3Fperson+a+%3Chttp%3A%2F%2Fdbpedia.org%2Fontology%2FMusicalArtist%3E+%3B%0D%0A+++%3Chttp%3A%2F%2Fdbpedia.org%2Fontology%2Fgenre%3E+%3Fgenre%3B%0D%0A+++%3Chttp%3A%2F%2Fdbpedia.org%2Fontology%2FdeathDate%3E+%3Fdied%3B%0D%0A+++rdfs%3Alabel+%3Fplabel%3B%0D%0A+++%3Chttp%3A%2F%2Fdbpedia.org%2Fontology%2FbirthDate%3E+%3Fborn+.%0D%0A+++%3Fgenre+rdfs%3Alabel+%3Fglabel+.%0D%0A+++filter+%28lang%28%3Fplabel%29+%3D+%22en%22%29%0D%0A+++filter+%28lang%28%3Fglabel%29+%3D+%22en%22%29%0D%0A%0D%0A%7D%0D%0A%0D%0AORDER+BY+DESC+%28+%3CLONG%3A%3AIRI_RANK%3E+%28%3Fperson%29+%29+LIMIT+100++%7D%7D&format=application%2Fvnd.ms-excel&timeout=0&debug=on";"table";1) =ImportHtml("";"table";1) ## FAO Country Listing and CoRefs SELECT DISTINCT ?s1 (sql:GROUP_CONCAT(?coRef, " , ")) AS ?sameAs where { { SELECT DISTINCT * WHERE { ?s1 a ; owl:sameAs ?coRef .} } } ORDER BY DESC ( ( ?s1 ) ) ## SUMO Country Listing & CoRefs SELECT DISTINCT ?s1 AS ?CountryID (sql:GROUP_CONCAT(?coRef, " , ")) AS ?CoReferences where { { SELECT DISTINCT * WHERE { ?s1 a ; owl:sameAs ?coRef .} } } ORDER BY DESC ( ( ?s1 ) ) ## SUMO Country Listing and CoRefs ## Pretty Labels SELECT DISTINCT ?s1 AS ?CountryID, (sql:GROUP_CONCAT(?coRef, " , ")) AS ?CoReference, str(?label) AS ?Name, str(?o) AS ?Comment WHERE { { SELECT DISTINCT * WHERE { ?s1 a ; owl:sameAs ?coRef. OPTIONAL {?s1 rdfs:label ?label}. OPTIONAL {?s1 owl:comment ?o}. } } } ORDER BY DESC ( ( ?s1 ) ) ## SUMO Country Listing and CoRefs ## Pretty Labels ## GeoSpatial Data from FAO SELECT DISTINCT ?s1 AS ?CountryID, ?s AS ?Capital, (sql:GROUP_CONCAT(?coRef, " , ")) AS ?CoReference, str(?label) AS ?Name, str(?o) AS ?Comment, ?lat AS ?Latitude, ?long AS ?Longitude, ?geopoint AS ?Point WHERE { { SELECT DISTINCT * WHERE { ?s1 a ; owl:sameAs ?coRef. OPTIONAL {?s1 rdfs:label ?label}. OPTIONAL {?s1 owl:comment ?o}. ?s ?s1 . ?coRef ?lat. ?coRef ?long. ?coRef geo:geometry ?geopoint. } } } ORDER BY DESC ( ( ?s1 ) ) ## DBpedia Country Listing & CoRefs SELECT DISTINCT ?s1 AS ?CountryID (sql:GROUP_CONCAT(?coRef, " , ")) AS ?CoReferences where { { SELECT DISTINCT * WHERE { ?s1 a ; owl:sameAs ?coRef .} } } ORDER BY DESC ( ( ?s1 ) ) ## Date Arithmetic, Entity Rank, Grouping but no labels select distinct ?person (sql:GROUP_CONCAT(?genre, " , ")) as ?genres ?died ?born ( if ( (datatype (?born) in (xsd:dateTime, xsd:date)) and (datatype (?died) in (xsd:dateTime, xsd:date)), bif:datediff('year',xsd:dateTime(str(?born)),xsd:dateTime(str(?died))), "error" ) ) as ?age where { { select distinct ?person ?genre ?died ?born from where { ?person a ; ?genre; ?died; ?born . } order by desc ( (?person) ) limit 100 }} ## Data Arithmetic, Entity Rank, Grouping, with Pretty Labels SELECT DISTINCT ?person as ?person_id str(?plabel) as ?person_name ?genre as ?genre_id str(?glabel) as ?genre_name ?died ?born ( (?person) ) as ?rank ( IF ( (datatype (?born) in (xsd:dateTime, xsd:date)) and (datatype (?died) in (xsd:dateTime, xsd:date)), bif:datediff('year',xsd:dateTime(str(?born)),xsd:dateTime(str(?died))), "error" ) ) as ?age WHERE { { SELECT DISTINCT ?person ?plabel ?genre ?glabel ?died ?born from WHERE { ?person a ; ?genre; ?died; rdfs:label ?plabel; ?born . ?genre rdfs:label ?glabel . filter (lang(?plabel) = "en") filter (lang(?glabel) = "en") } ORDER BY DESC ( (?person) ) LIMIT 100 }} ## Date Arithmetic, Entity Rank, and Grouping ## Date Arithmetic and Entity Ranking select distinct ?person ?plabel ?genre ?glabel ?died ?born ( (?person) ) as ?rank ( if ( (datatype (?born) in (xsd:dateTime, xsd:date)) and (datatype (?died) in (xsd:dateTime, xsd:date)), bif:datediff('year',xsd:dateTime(str(?born)),xsd:dateTime(str(?died))), "error" ) ) as ?age where { { select distinct ?person ?plabel ?genre ?glabel ?died ?born from where { ?person a ; ?genre; ?died; rdfs:label ?plabel; ?born . ?genre rdfs:label ?glabel . filter (lang(?plabel) = "en") filter (lang(?glabel) = "en") } order by desc ( (?person) ) limit 100 }} ## Date Arithmetic select ?s ?genre ?died ?born (bif:datediff('year',xsd:dateTime(str(?born)),xsd:dateTime(str(?died)))) as ?age where { { select distinct ?s ?genre ?died ?born from where { ?s a ; ?genre; ?died; ?born . } limit 20 }} ## Using SPARQL to add missing isDefinedBy relations to an Ontology. ## Benefit: isDefinedBy relations make Ontologies (TBox) more navigable using follow-your-nose pattern. This also ## makes ABox instance data more discoverable. ## Ontology Document URL: http://www.w3.org/2006/vcard/ns ## Ontology URI: http://www.w3.org/2006/vcard/ns# ## Goal: use SPARQL to generate relations that associate Classes and Properties the Ontology that describes them. ## Steps: use a local Named Graph IRI to host SPARQL Update (SPARUL) the new relations. ## ** Important OWL Reasoning Note ** ## http://open.vocab.org/terms/defines is owl:inverseOf rdfs:isDefinedBy, thus adding this relation to a Named Graph that's used for an inference rule negates the need for creating the actual relations, if you choose to put Virtuoso's reasoner to use. ## Uncomment line below if using Virtuoso and executing SPARQL via iSQL or via an ODBC, JDBC, ADO.NET connection ## SPARQL ## Uncomment line (a SPARQL pragma) below if using Virtuoso and there isn't a local Named Graph holding triples retrieved from the ## Ontology URL ## DEFINE get:soft "add" INSERT INTO {?s rdfs:isDefinedBy . ?s} FROM WHERE { {?s rdfs:subClassOf ?o} UNION {?s rdfs:subPropertyOf ?o} UNION {?s owl:equivalentClass ?o} UNION {?s owl:equivalentProperty ?o} UNION {?s a ?o}} ## Another example using the recorded media Ontology ## Ontology Document URL: http://www.w3.org/ns/ma-ont ## Ontology URI: http://www.w3.org/ns/ma-ont# SPARQL INSERT INTO {?s rdfs:isDefinedBy . ?s} FROM WHERE { {?s rdfs:subClassOf ?o} UNION {?s rdfs:subPropertyOf ?o} UNION {?s owl:equivalentClass ?o} UNION {?s owl:equivalentProperty ?o} UNION {?s a ?o}} ## PA Ontologies cleanup INSERT INTO {?s rdfs:isDefinedBy . ?s} FROM WHERE { {?s rdfs:subClassOf ?o} UNION {?s rdfs:subPropertyOf ?o} UNION {?s owl:equivalentClass ?o} UNION {?s owl:equivalentProperty ?o} UNION {?s a ?o}} INSERT INTO {?s rdfs:isDefinedBy . ?s} FROM WHERE { {?s rdfs:subClassOf ?o} UNION {?s rdfs:subPropertyOf ?o} UNION {?s owl:equivalentClass ?o} UNION {?s owl:equivalentProperty ?o} UNION {?s a ?o}} SPARQL INSERT INTO {?s rdfs:isDefinedBy . ?s} FROM WHERE { {?s rdfs:subClassOf ?o} UNION {?s rdfs:subPropertyOf ?o} UNION {?s owl:equivalentClass ?o} UNION {?s owl:equivalentProperty ?o} UNION {?s a ?o}} INSERT INTO {?s rdfs:isDefinedBy . ?s} FROM WHERE { {?s rdfs:subClassOf ?o} UNION {?s rdfs:subPropertyOf ?o} UNION {?s owl:equivalentClass ?o} UNION {?s owl:equivalentProperty ?o} UNION {?s a ?o}} INSERT INTO {?s rdfs:isDefinedBy . ?s} FROM WHERE { {?s rdfs:subClassOf ?o} UNION {?s rdfs:subPropertyOf ?o} UNION {?s owl:equivalentClass ?o} UNION {?s owl:equivalentProperty ?o} UNION {?s a ?o}} ## Provenance Ontology Cleanup INSERT INTO {?s rdfs:isDefinedBy . ?s} FROM WHERE { {?s rdfs:subClassOf ?o} UNION {?s rdfs:subPropertyOf ?o} UNION {?s owl:equivalentClass ?o} UNION {?s owl:equivalentProperty ?o} UNION {?s a ?o}} ## Web Semantics Ontology INSERT INTO {?s rdfs:isDefinedBy . ?s. a owl:Ontology . ?s } FROM WHERE { {?s rdfs:subClassOf ?o} UNION {?s rdfs:subPropertyOf ?o} UNION {?s owl:equivalentClass ?o} UNION {?s owl:equivalentProperty ?o} UNION {?s a ?o}} ## Wordnet to Schema.org mapping INSERT INTO {?s rdfs:isDefinedBy . ?s. a owl:Ontology . ?s } FROM WHERE { {?s rdfs:subClassOf ?o} UNION {?s rdfs:subPropertyOf ?o} UNION {?s owl:equivalentClass ?o} UNION {?s owl:equivalentProperty ?o} UNION {?s a ?o}} ##Bibo INSERT INTO {?s rdfs:isDefinedBy . ?s. a owl:Ontology . ?s } FROM WHERE { {?s rdfs:subClassOf ?o} UNION {?s rdfs:subPropertyOf ?o} UNION {?s owl:equivalentClass ?o} UNION {?s owl:equivalentProperty ?o} UNION {?s a ?o}} ## VoiD Ontology INSERT INTO { ?s. ?s } FROM WHERE { {?s rdfs:subClassOf ?o} UNION {?s rdfs:subPropertyOf ?o} UNION {?s owl:equivalentClass ?o} UNION {?s owl:equivalentProperty ?o} UNION {?s a ?o}} ### Nepomuk ### Calendar INSERT INTO {?s rdfs:isDefinedBy . ?s. a owl:Ontology . ?s } FROM WHERE { {?s rdfs:subClassOf ?o} UNION {?s rdfs:subPropertyOf ?o} UNION {?s owl:equivalentClass ?o} UNION {?s owl:equivalentProperty ?o} UNION {?s a ?o}} ### Contacts INSERT INTO {?s rdfs:isDefinedBy . ?s. a owl:Ontology . ?s } FROM WHERE { {?s rdfs:subClassOf ?o} UNION {?s rdfs:subPropertyOf ?o} UNION {?s owl:equivalentClass ?o} UNION {?s owl:equivalentProperty ?o} UNION {?s a ?o}} ### Files INSERT INTO {?s rdfs:isDefinedBy . ?s. a owl:Ontology . ?s } FROM WHERE { {?s rdfs:subClassOf ?o} UNION {?s rdfs:subPropertyOf ?o} UNION {?s owl:equivalentClass ?o} UNION {?s owl:equivalentProperty ?o} UNION {?s a ?o}} ### Nepomuk Representational Language Specification INSERT INTO {?s rdfs:isDefinedBy . ?s. a owl:Ontology . ?s } FROM WHERE { {?s rdfs:subClassOf ?o} UNION {?s rdfs:subPropertyOf ?o} UNION {?s owl:equivalentClass ?o} UNION {?s owl:equivalentProperty ?o} UNION {?s a ?o}} ### Personal Information Management INSERT INTO {?s rdfs:isDefinedBy . ?s. a owl:Ontology . ?s } FROM WHERE { {?s rdfs:subClassOf ?o} UNION {?s rdfs:subPropertyOf ?o} UNION {?s owl:equivalentClass ?o} UNION {?s owl:equivalentProperty ?o} UNION {?s a ?o}} ### NLP Analysis from Washington Post Article SELECT DISTINCT * FROM WHERE { {?s rdfs:subClassOf ?o} UNION {?s rdfs:subPropertyOf ?o} UNION {?s owl:equivalentClass ?o} UNION {?s owl:equivalentProperty ?o} UNION {?s a ?o}} ### Network Information Element (NIE) INSERT INTO {?s rdfs:isDefinedBy . ?s. a owl:Ontology . ?s } FROM WHERE { {?s rdfs:subClassOf ?o} UNION {?s rdfs:subPropertyOf ?o} UNION {?s owl:equivalentClass ?o} UNION {?s owl:equivalentProperty ?o} UNION {?s a ?o}} ### Annotation Ontology INSERT INTO {?s rdfs:isDefinedBy . ?s. a owl:Ontology . ?s } FROM WHERE { {?s rdfs:subClassOf ?o} UNION {?s rdfs:subPropertyOf ?o} UNION {?s owl:equivalentClass ?o} UNION {?s owl:equivalentProperty ?o} UNION {?s a ?o}} ## HAO INSERT INTO {?s rdfs:isDefinedBy . ?s. a owl:Ontology . ?s } FROM WHERE { {?s rdfs:subClassOf ?o} UNION {?s rdfs:subPropertyOf ?o} UNION {?s owl:equivalentClass ?o} UNION {?s owl:equivalentProperty ?o} UNION {?s a ?o}} ## RPIs dataset ontology INSERT INTO {?s rdfs:isDefinedBy . ?s. a owl:Ontology . ?s } FROM WHERE { {?s rdfs:subClassOf ?o} UNION {?s rdfs:subPropertyOf ?o} UNION {?s owl:equivalentClass ?o} UNION {?s owl:equivalentProperty ?o} UNION {?s a ?o}} ## Nature.com Ontology INSERT INTO {?s rdfs:isDefinedBy . ?s. a owl:Ontology . ?s } FROM WHERE { {?s rdfs:subClassOf ?o} UNION {?s rdfs:subPropertyOf ?o} UNION {?s owl:equivalentClass ?o} UNION {?s owl:equivalentProperty ?o} UNION {?s a ?o}} ## Vivo Ontology INSERT INTO {?s rdfs:isDefinedBy . ?s. a owl:Ontology . ?s } FROM WHERE { {?s rdfs:subClassOf ?o} UNION {?s rdfs:subPropertyOf ?o} UNION {?s owl:equivalentClass ?o} UNION {?s owl:equivalentProperty ?o} UNION {?s a ?o}} ## Polymer Informatics Ontology INSERT INTO {?s rdfs:isDefinedBy . ?s. a owl:Ontology . ?s } FROM WHERE { {?s rdfs:subClassOf ?o} UNION {?s rdfs:subPropertyOf ?o} UNION {?s owl:equivalentClass ?o} UNION {?s owl:equivalentProperty ?o} UNION {?s a ?o}} ## Stat Ontology from Data.FM ## Doesn't work as it doesn't really have an RDFs or OWL relations INSERT INTO {?s rdfs:isDefinedBy . ?s. a owl:Ontology . ?s } FROM WHERE { {?s rdfs:subClassOf ?o} UNION {?s rdfs:subPropertyOf ?o} UNION {?s owl:equivalentClass ?o} UNION {?s owl:equivalentProperty ?o} UNION {?s a ?o}} ## More co-refs sparql insert into { owl:sameAs . owl:sameAs . owl:sameAs , } ## ## insert into { owl:sameAs , , , , , , } ## PREFIX mu: PREFIX geo: SELECT * WHERE { SERVICE { SELECT ?muOrg ?name ?postcode ?lat ?long WHERE { ?muOrg a . { ?muOrg mu:Sector "Further Education" } UNION { ?muOrg mu:Sector "Higher Education" } . ?muOrg mu:OfficialName ?name . ?muOrg mu:PostCode ?postcode . ?muOrg geo:lat ?lat . ?muOrg geo:lon ?long . } } } PREFIX space: PREFIX rdfs: SELECT ?disc ?label WHERE { SERVICE { SELECT ?disc ?label WHERE { space:discipline ?disc . ?disc rdfs:label ?label } } } --- Data Space Tweak Exercise sparql insert into { owl:equivalentClass . owl:equivalentClass . } -- Verification http://uriburner.com/describe/?url=http%3A%2F%2Fpurl.org%2FNET%2Fbook%2Fvocab%23Book&p=3279&lp=3278&op=3277&prev=&gp=3279 -- Content Negotiation Driven Loading DB.DBA.RDF_LOAD_RDFXML (http_get ('http://purl.org/ontology/mo/', null, 'GET', 'Accept: application/rdf+xml', null, null, 3), 'http://purl.org/ontology/mo/', 'http://purl.org/ontology/mo/'); --- Rules Management -- Remove rdfs_rule_set (rule_name, graph_name, 1) -- Add rdfs_rule_set (rule_name, graph_name) Example: SPARQL load ; -- Remove rdfs_rule_set ('music_ontology', 'http://motools.sourceforge.net/doc/musicontology.n3', 1) -- Add rdfs_rule_set ('music_ontology', 'http://motools.sourceforge.net/doc/musicontology.n3')