Skip to content

Instantly share code, notes, and snippets.

:.,$s/\(<rdfs:subClassOf.*\n\)\(\( <[^r].*\n\)\{1,99\}\)\(.*rdfs:subClassOf.*\/>\n\)/\1\4\2/c
:.,$s/rdfs:subClassOf rdf:resource="&meta;Function/meta:topClass rdf:resource="\&meta;Function/c
select *
{
?x rdfs:subClassOf meta:Function.
filter not exists
{
?x rdfs:subClassOf ?y.
filter(?y!=meta:Function).
filter not exists {?y a owl:Restriction.}
}
}
select ?pair ?s ?p ?c
{
{select ?s1 ?ps ?s2 {?s1 a owl:Class. ?s2 a owl:Class. ?s1 ?ps ?s2. filter(?ps=skos:closeMatch OR ?ps=skos:broadMatch)}}
bind(replace(replace(replace(concat(?s1,"-",?ps,"-",?s2),"http[^-]*skos/core#","skos/"),"http[^-]*ontology/",""),"/",":") as ?pair).
?s ?p ?c.
filter(?p!=skos:closeMatch AND ?p!=skos:broadMatch).
?c a owl:Class.
filter not exists {?c a owl:Restriction.}
select ?pair as ?Link SAMPLE(str(?sl)) as ?Subjekt SAMPLE(str(?pl)) as ?Praedikat SAMPLE(str(?cl)) as ?Objekt ?s ?p ?c ?g
{
{select ?s1 {GRAPH <http://www.snik.eu/ontology/ciox> { ?s1 a owl:Class.}}}
?s2 a owl:Class.
?s1 ?linkRel ?s2. filter(?linkRel=skos:closeMatch OR ?linkRel=skos:broadMatch OR ?linkRel=skos:broader OR ?linkRel=skos:broader)
bind(replace(str(?linkRel),".*[/#]","") as ?linkRelStr) # don't have labels for SKOS
bind(replace(str(?s1),".*[/#]","") as ?s1Str) # can't sample here
select distinct ?c ?x
{
?c a owl:Class.
?c rdfs:subClassOf* ?x.
filter(?x = meta:EntityType)
#filter(?x = meta:Function OR ?x = meta:Role OR ?x = meta:EntityType)
filter not exists {?c meta:subTopClass ?x.}
}
construct {?c meta:subTopClass ?x}
from <http://www.snik.eu/ontology/meta>
from <http://www.snik.eu/ontology/ob>
from <http://www.snik.eu/ontology/bb>
from <http://www.snik.eu/ontology/he>
{
graph ?g {?c a owl:Class.}
filter(?g!=<http://www.snik.eu/ontology/meta>) # EntityType, Role, Function and Top don't have subTopClass and we trust meta to have all other subtops
?c rdfs:subClassOf* ?x.
select ?pair as ?BB_to_CIOX ?s1Str as ?CIOX ?pl as ?CIOX_relation ?ol as ?CIOX_object
{
{select ?CIOX_Class {GRAPH <http://www.snik.eu/ontology/ciox> { ?CIOX_Class a owl:Class.}}}
{select ?BB_Class {GRAPH <http://www.snik.eu/ontology/bb> { ?BB_Class a owl:Class.}}}
?CIOX_Class ?linkRel ?BB_Class.
filter(?linkRel=skos:exactMatch OR ?linkRel=skos:closeMatch OR ?linkRel=skos:broadMatch OR ?linkRel=skos:broader OR ?linkRel=skos:narrower OR ?linkRel=skos:narrowMatch OR ?linkRel=skos:related OR ?linkRel=skos:relatedMatch)
bind(replace(str(?linkRel),".*[/#]","") as ?linkRelStr) # don't have labels for SKOS
bind(replace(str(?CIOX_Class),".*[/#]","") as ?s1Str) # can't sample here
@KonradHoeffner
KonradHoeffner / select_snik_triplecheckmate_class_table.sparql
Last active December 6, 2016 13:20
select_snik_triplecheckmate_class_table.sparql
# remove leading zeroes and non-numerical characters from hash
# take first 9 numbers so it fits into a 32 bit integer
select distinct (substr(replace(replace(md5(?curi),"[a-f]",""),"^0+",""),1,9) as ?cid) ?curi replace(replace(str(?curi),"^([^/]*/){4}",""),"/",":") as ?cname (substr(replace(replace(md5(sample(?parent)),"[a-f]",""),"^0+",""),1,9) as ?cparent) (count(?child) as ?count_cache) (if(count(?child)=0,1,0) as ?is_leaf)
{
?curi a owl:Class.
OPTIONAL { graph ?g {?curi rdfs:subClassOf ?parent.}}
filter(?g!=<http://snik.eu/ontology/virtual>)
OPTIONAL { {?child rdfs:subClassOf ?curi.} UNION {?child a ?curi.}}
}
select ?class count(?s) as ?count
from <http://www.snik.eu/ontology>
{
graph ?g {?class a owl:Class.}
filter(?g=<http://www.snik.eu/ontology/meta>)
?s rdfs:subClassOf ?class.
} order by desc(?count)