14:- module(trillo_utility_translation, [load_owl/1, load_owl_from_string/1, expand_all_ns/4, expand_all_ns/5, is_axiom/1]). 15 16:- use_module(library(lists),[member/2]). 17:- use_module(library(pengines)). 18 19:- use_module(library(sandbox)). 20 21:- discontiguous(valid_axiom/1). 22:- discontiguous(axiompred/1). 23:- discontiguous(axiom_arguments/2). 24:- discontiguous(expand_axiom/4). 25 26/***************************** 27 MESSAGES 28******************************/ 29:- multifile prolog:message/1. 30 31prologmessage(under_development) --> 32 [ 'NOTE: This function is under development. It may not work properly or may not work at all.' ]. 33 34 35 36builtin_class('http://www.w3.org/2002/07/owl#Thing'). 37builtin_class('http://www.w3.org/2002/07/owl#Nothing'). 38builtin_datatype('http://www.w3.org/2002/07/owl#real'). 39builtin_datatype('http://www.w3.org/2002/07/owl#rational'). 40builtin_datatype('http://www.w3.org/2001/XMLSchema#decimal'). 41builtin_datatype('http://www.w3.org/2001/XMLSchema#integer'). 42builtin_datatype('http://www.w3.org/2001/XMLSchema#nonNegativeInteger'). 43builtin_datatype('http://www.w3.org/2001/XMLSchema#nonPositiveInteger'). 44builtin_datatype('http://www.w3.org/2001/XMLSchema#positiveInteger'). 45builtin_datatype('http://www.w3.org/2001/XMLSchema#negativeInteger'). 46builtin_datatype('http://www.w3.org/2001/XMLSchema#long'). 47builtin_datatype('http://www.w3.org/2001/XMLSchema#int'). 48builtin_datatype('http://www.w3.org/2001/XMLSchema#short'). 49builtin_datatype('http://www.w3.org/2001/XMLSchema#byte'). 50builtin_datatype('http://www.w3.org/2001/XMLSchema#unsignedLong'). 51builtin_datatype('http://www.w3.org/2001/XMLSchema#unsignedInt'). 52builtin_datatype('http://www.w3.org/2001/XMLSchema#unsignedShort'). 53builtin_datatype('http://www.w3.org/2001/XMLSchema#unsignedByte'). 54builtin_datatype('http://www.w3.org/2001/XMLSchema#double'). 55builtin_datatype('http://www.w3.org/2001/XMLSchema#float'). 56builtin_datatype('http://www.w3.org/2001/XMLSchema#string'). 57builtin_datatype('http://www.w3.org/2001/XMLSchema#normalizedString'). 58builtin_datatype('http://www.w3.org/2001/XMLSchema#token'). 59builtin_datatype('http://www.w3.org/2001/XMLSchema#language'). 60builtin_datatype('http://www.w3.org/2001/XMLSchema#Name'). 61builtin_datatype('http://www.w3.org/2001/XMLSchema#NCName'). 62builtin_datatype('http://www.w3.org/2001/XMLSchema#NMTOKEN'). 63builtin_datatype('http://www.w3.org/2001/XMLSchema#boolean'). 64builtin_datatype('http://www.w3.org/2001/XMLSchema#hexBinary'). 65builtin_datatype('http://www.w3.org/2001/XMLSchema#base64Binary'). 66builtin_datatype('http://www.w3.org/2001/XMLSchema#minLength'). 67builtin_datatype('http://www.w3.org/2001/XMLSchema#maxLength'). 68builtin_datatype('http://www.w3.org/2001/XMLSchema#length'). 69builtin_datatype('http://www.w3.org/2001/XMLSchema#dateTime'). 70builtin_datatype('http://www.w3.org/2001/XMLSchema#dateTimeStamp'). 71builtin_datatype('http://www.w3.org/2000/01/rdf-schema#Literal'). 72 73is_class(C) :- get_module(M),M:class(C). 74is_class(C) :- builtin_class(C). 75 76/**************************************** 77 UTILITY 78 ****************************************/ 79set_trdf(Setting,Value):- 80 get_module(M), 81 retractall(M:trdf_setting(Setting,_)), 82 assert(M:trdf_setting(Setting,Value)). 83 84% TODO: hasKey 85 86/**************************************** 87 AXIOMS 88 ****************************************/
94:- meta_predicate entity(). 95 96entity(M:A) :- individual(M:A). 97entity(M:A) :- property(M:A). 98entity(M:A) :- M:class(A). 99entity(M:A) :- M:datatype(A). 100axiom_arguments(entity,[iri]). 101valid_axiom(entity(A)) :- subsumed_by([A],[iri]). 102 103% declarationAxiom(M:individual(A)) :- individual(M:A). 104declarationAxiom(M:namedIndividual(A)) :- M:namedIndividual(A). 105declarationAxiom(M:objectProperty(A)) :- M:objectProperty(A). 106declarationAxiom(M:dataProperty(A)) :- M:dataProperty(A). 107declarationAxiom(M:annotationProperty(A)) :- M:annotationProperty(A). 108declarationAxiom(M:class(A)) :- M:class(A). 109declarationAxiom(M:datatype(A)) :- M:datatype(A). 110% TODO: check. here we treat the ontology declaration as an axiom; 111% this liberal definition of axiom allows us to iterate over axiom/1 112% to find every piece of information in the ontology. 113declarationAxiom(M:ontology(A)) :- M:ontology(A).
thread_local(class/1).119axiompred(class/1). 120axiom_arguments(class,[iri]). 121 122expand_class(M,C,NSList,ExpC) :- 123 expand_iri(M,C,NSList,ExpC), 124 \+ builtin_datatype(ExpC). 125 126valid_axiom(class(A)) :- subsumed_by([A],[iri]). 127expand_axiom(M,class(A),NSList,class(A_full_URL)) :- 128 expand_iri(M,A,NSList,A_full_URL), 129 ( M:addKBName -> add_kb_atoms(M,class,[A_full_URL]) ; true).
thread_local(datatype/1).135axiompred(datatype/1). 136axiom_arguments(datatype,[iri]). 137valid_axiom(datatype(A)) :- subsumed_by([A],[iri]). 138expand_axiom(M,datatype(A),NSList,datatype(A_full_URL)) :- 139 expand_iri(M,A,NSList,A_full_URL), 140 \+ name(A_full_URL,[95, 58, 68, 101, 115, 99, 114, 105, 112, 116, 105, 111, 110|_]), 141 ( M:addKBName -> add_kb_atoms(M,datatype,[A_full_URL]) ; true).
147:- meta_predicate property(). 148 149property(M:A) :- M:dataProperty(A). 150property(M:A) :- M:objectProperty(A). 151property(M:A) :- M:annotationProperty(A). 152axiom_arguments(property,[iri]). 153valid_axiom(property(A)) :- subsumed_by([A],[iri]).
thread_local(objectProperty/1).159axiompred(objectProperty/1). 160axiom_arguments(objectProperty,[iri]). 161 162expand_objectProperty(M,P,NSList,ExpP) :- 163 expand_iri(M,P,NSList,ExpP), 164 ( M:addKBName -> add_kb_atoms(M,objectProperty,[ExpP]) ; true ). 165 166valid_axiom(objectProperty(A)) :- subsumed_by([A],[iri]). 167expand_axiom(M,objectProperty(A),NSList,objectProperty(A_full_URL)) :- 168 expand_iri(M,A,NSList,A_full_URL), 169 ( M:addKBName -> add_kb_atoms(M,objectProperty,[A_full_URL]) ; true).
thread_local(dataProperty/1).175axiompred(dataProperty/1). 176axiom_arguments(dataProperty,[iri]). 177 178expand_dataProperty(M,P,NSList,ExpP) :- 179 expand_iri(M,P,NSList,ExpP), 180 ( M:addKBName -> add_kb_atoms(M,dataProperty,[ExpP]) ; true). 181 182 183valid_axiom(dataProperty(A)) :- subsumed_by([A],[iri]). 184expand_axiom(M,dataProperty(A),NSList,dataProperty(A_full_URL)) :- 185 expand_iri(M,A,NSList,A_full_URL), 186 ( M:addKBName -> add_kb_atoms(M,dataProperty,[A_full_URL]) ; true).
thread_local(annotationProperty/1).192axiompred(annotationProperty/1). 193axiom_arguments(annotationProperty,[iri]). 194 195expand_annotationProperty(M,P,NSList,ExpP) :- 196 expand_iri(M,P,NSList,ExpP), 197 ( M:addKBName -> add_kb_atoms(M,annotationProperty,[ExpP]) ; true ). 198 199expand_annotationSubject(M,P,NSList,ExpP) :- 200 (expand_classExpression(M,P,NSList,ExpP),!) ; 201 (expand_individual(M,P,NSList,ExpP),!) ; 202 (expand_propertyExpression(M,P,NSList,ExpP),!) ; 203 (expand_axiom(M,P,NSList,ExpP),!). 204 205expand_annotationValue(M,P,NSList,ExpP) :- 206 (expand_literal(M,P,NSList,ExpP),!) ; 207 (expand_classExpression(M,P,NSList,ExpP),!) ; 208 (expand_individual(M,P,NSList,ExpP),!) ; 209 (expand_propertyExpression(M,P,NSList,ExpP),!) ; 210 (expand_axiom(M,P,NSList,ExpP),!) . 211 212 213valid_axiom(annotationProperty(A)) :- subsumed_by([A],[iri]). 214expand_axiom(M,annotationProperty(A),NSList,annotationProperty(A_full_URL)) :- 215 expand_iri(M,A,NSList,A_full_URL), 216 ( M:addKBName -> add_kb_atoms(M,annotationProperty,[A_full_URL]) ; true). 217 218expand_axiom(M,annotation(A,B,C),NSList,annotation(A_full_URL,B_full_URL,C_full_URL)) :- 219 ( M:addKBName -> (retractall(M:addKBName), Add=true) ; Add=false ), 220 expand_argument(M,A,NSList,A_full_URL), 221 expand_argument(M,B,NSList,B_full_URL), 222 expand_argument(M,C,NSList,C_full_URL), 223 ( Add=true -> assert(M:addKBName) ; true ).
229:- meta_predicate individual(). 230 231individual(M:A) :- M:anonymousIndividual(A). 232individual(M:A) :- M:namedIndividual(A). 233%individual(A) :- nonvar(A),iri(A),\+property(A),\+class(A),\+ontology(A). % TODO: check: make individuals the default 234axiom_arguments(individual,[iri]). 235valid_axiom(individual(A)) :- subsumed_by([A],[iri]). 236 237expand_individuals(_M,[],_NSList,[]) :- !. 238expand_individuals(M,[H|T],NSList,[ExpH|ExpT]) :- 239 expand_individual(M,H,NSList,ExpH), 240 expand_individuals(M,T,NSList,ExpT). 241 242expand_individual(M,I,NSList,ExpI) :- 243 expand_iri(M,I,NSList,ExpI), 244 \+ builtin_datatype(ExpI), 245 ( M:addKBName -> add_kb_atoms(M,individual,[ExpI]) ; true ).
thread_local(namedIndividual/1).251axiompred(namedIndividual/1). 252axiom_arguments(namedIndividual,[iri]). 253valid_axiom(namedIndividual(A)) :- subsumed_by([A],[iri]). 254expand_axiom(M,namedIndividual(A),NSList,namedIndividual(A_full_URL)) :- 255 expand_iri(M,A,NSList,A_full_URL), 256 ( M:addKBName -> add_kb_atoms(M,individual,[A_full_URL]) ; true).
thread_local(anonymousIndividual/1).263axiompred(anonymousIndividual/1). 264axiom_arguments(anonymousIndividual,[iri]). 265valid_axiom(anonymousIndividual(A)) :- subsumed_by([A],[iri]). 266expand_axiom(M,anonymousIndividual(A),NSList,anonymousIndividual(A_full_URL)) :- 267 expand_iri(M,A,NSList,A_full_URL), 268 ( M:addKBName -> add_kb_atoms(M,individual,[A_full_URL]) ; true).
272:- meta_predicate costruct(). 273 274construct(M:A) :- trillo:axiom(M:A). 275construct(M:A) :- annotation(M:A). 276construct(M:A) :- M:ontology(A). 277axiom_arguments(construct,[iri]). 278valid_axiom(construct(A)) :- subsumed_by([A],[iri]).
283:- multifile trillo:axiom/1. 284 285trilloaxiom(M:A) :- classAxiom(M:A). 286trilloaxiom(M:A) :- propertyAxiom(M:A). 287trilloaxiom(M:hasKey(A,B)) :- M:hasKey(A,B). 288trilloaxiom(M:A) :- fact(M:A). 289trilloaxiom(M:A) :- declarationAxiom(M:A). 290%axiom(annotation(A,B,C)) :- 291% annotation(A,B,C). % CJM-treat annotations as axioms 292axiom_arguments(axiom,[axiom]). 293valid_axiom(axiom(A)) :- subsumed_by([A],[axiom]).
298:- meta_predicate classAxiom(). 299 300classAxiom(M:equivalentClasses(A)) :- M:equivalentClasses(A). 301classAxiom(M:disjointClasses(A)) :- M:disjointClasses(A). 302classAxiom(M:subClassOf(A, B)) :- M:subClassOf(A, B). 303classAxiom(M:disjointUnion(A, B)) :- M:disjointUnion(A, B). 304axiom_arguments(classAxiom,[axiom]). 305valid_axiom(classAxiom(A)) :- subsumed_by([A],[axiom]).
314axiompred(subClassOf/2). 315axiom_arguments(subClassOf,[classExpression, classExpression]). 316valid_axiom(subClassOf(A, B)) :- subsumed_by([A, B],[classExpression, classExpression]). 317expand_axiom(M,subClassOf(A,B),NSList,subClassOf(A_full_URL,B_full_URL)) :- 318 expand_classExpression(M,A,NSList,A_full_URL), 319 expand_classExpression(M,B,NSList,B_full_URL).
thread_local(equivalentClasses/1).326axiompred(equivalentClasses/1). 327axiom_arguments(equivalentClasses,[set(classExpression)]). 328valid_axiom(equivalentClasses(A)) :- subsumed_by([A],[set(classExpression)]). 329expand_axiom(M,equivalentClasses(A),NSList,equivalentClasses(A_full_URL)) :- 330 expand_classExpressions(M,A,NSList,A_full_URL).
thread_local(disjointClasses/1).336axiompred(disjointClasses/1). 337axiom_arguments(disjointClasses,[set(classExpression)]). 338valid_axiom(disjointClasses(A)) :- subsumed_by([A],[set(classExpression)]). 339expand_axiom(M,disjointClasses(A),NSList,disjointClasses(A_full_URL)) :- 340 expand_classExpressions(M,A,NSList,A_full_URL).
thread_local(disjointUnion/2).346axiompred(disjointUnion/2). 347axiom_arguments(disjointUnion,[classExpression,set(classExpression)]). 348valid_axiom(disjointUnion(A,B)) :- subsumed_by([A,B],[classExpression,set(classExpression)]). 349expand_axiom(M,disjointUnion(A,B),NSList,disjointUnion(A_full_URL,B_full_URL)) :- 350 expand_classExpression(M,A,NSList,A_full_URL), 351 expand_classExpressions(M,B,NSList,B_full_URL).
357:- meta_predicate propertyAxiom(). 358 359propertyAxiom(M:symmetricProperty(A)) :- M:symmetricProperty(A). 360propertyAxiom(M:inverseFunctionalProperty(A)) :- M:inverseFunctionalProperty(A). 361propertyAxiom(M:transitiveProperty(A)) :- M:transitiveProperty(A). 362propertyAxiom(M:asymmetricProperty(A)) :- M:asymmetricProperty(A). 363propertyAxiom(M:subPropertyOf(A, B)) :- M:subPropertyOf(A, B). 364propertyAxiom(M:functionalProperty(A)) :- M:functionalProperty(A). 365propertyAxiom(M:irreflexiveProperty(A)) :- M:irreflexiveProperty(A). 366propertyAxiom(M:disjointProperties(A)) :- M:disjointProperties(A). 367propertyAxiom(M:propertyDomain(A, B)) :- M:propertyDomain(A, B). 368propertyAxiom(M:reflexiveProperty(A)) :- M:reflexiveProperty(A). 369propertyAxiom(M:propertyRange(A, B)) :- M:propertyRange(A, B). 370propertyAxiom(M:equivalentProperties(A)) :- M:equivalentProperties(A). 371propertyAxiom(M:inverseProperties(A, B)) :- M:inverseProperties(A, B). 372axiom_arguments(propertyAxiom,[axiom]). 373valid_axiom(propertyAxiom(A)) :- subsumed_by([A],[axiom]).
thread_local(subPropertyOf/2).381axiompred(subPropertyOf/2). 382axiom_arguments(subPropertyOf,[propertyExpression, objectPropertyExpression]). 383valid_axiom(subPropertyOf(A, B)) :- subsumed_by([A, B],[propertyExpression, objectPropertyExpression]). 384%expand_axiom(M,subPropertyOf(A,B),NSList,subPropertyOf(A_full_URL,B_full_URL)) :- %TODO: fix for data properties 385% expand_propertyExpression(M,A,NSList,A_full_URL), 386% expand_objectPropertyExpression(M,B,NSList,B_full_URL).
390subObjectPropertyOf(A, B) :- get_module(M),M:subPropertyOf(A, B),subsumed_by([A, B],[objectPropertyExpressionOrChain, objectPropertyExpression]). 391axiom_arguments(subObjectPropertyOf,[objectPropertyExpressionOrChain, objectPropertyExpression]). 392valid_axiom(subObjectPropertyOf(A, B)) :- subsumed_by([A, B],[objectPropertyExpressionOrChain, objectPropertyExpression]). 393expand_axiom(M,subPropertyOf(A,B),NSList,subPropertyOf(A_full_URL,B_full_URL)) :- 394 expand_objectPropertyExpressionOrChain(M,A,NSList,A_full_URL), 395 expand_objectPropertyExpression(M,B,NSList,B_full_URL). 396 %add_expressivity(M,h).
400subDataPropertyOf(A, B) :- get_module(M),M:subPropertyOf(A, B),subsumed_by([A, B],[dataPropertyExpression, dataPropertyExpression]). 401axiom_arguments(subDataPropertyOf,[dataPropertyExpression, dataPropertyExpression]). 402valid_axiom(subDataPropertyOf(A, B)) :- subsumed_by([A, B],[dataPropertyExpression, dataPropertyExpression]).
406subAnnotationPropertyOf(A, B) :- get_module(M),M:subPropertyOf(A, B),subsumed_by([A, B],[annotationProperty, annotationProperty]). 407axiom_arguments(subAnnotationPropertyOf,[annotationProperty, annotationProperty]). 408valid_axiom(subAnnotationPropertyOf(A, B)) :- subsumed_by([A, B],[annotationProperty, annotationProperty]).
thread_local(equivalentProperties/1).415axiompred(equivalentProperties/1). 416axiom_arguments(equivalentProperties,[set(propertyExpression)]). 417valid_axiom(equivalentProperties(A)) :- subsumed_by([A],[set(propertyExpression)]). 418expand_axiom(M,equivalentProperties(A),NSList,equivalentProperties(A_full_URL)) :- 419 expand_propertyExpressions(M,A,NSList,A_full_URL).
423equivalentObjectProperties(A) :- get_module(M),M:equivalentProperties(A),subsumed_by([A],[set(objectPropertyExpression)]). 424axiom_arguments(equivalentObjectProperties,[set(objectPropertyExpression)]). 425valid_axiom(equivalentObjectProperties(A)) :- subsumed_by([A],[set(objectPropertyExpression)]).
429equivalentDataProperties(A) :- get_module(M),M:equivalentProperties(A),subsumed_by([A],[set(dataPropertyExpression)]). 430axiom_arguments(equivalentDataProperties,[set(dataPropertyExpression)]). 431valid_axiom(equivalentDataProperties(A)) :- subsumed_by([A],[set(dataPropertyExpression)]).
thread_local(disjointProperties/1).438axiompred(disjointProperties/1). 439axiom_arguments(disjointProperties,[set(propertyExpression)]). 440valid_axiom(disjointProperties(A)) :- subsumed_by([A],[set(propertyExpression)]). 441expand_axiom(M,disjointProperties(A),NSList,disjointProperties(A_full_URL)) :- 442 expand_propertyExpressions(M,A,NSList,A_full_URL).
446disjointObjectProperties(A) :- get_module(M),M:disjointProperties(A),subsumed_by([A],[set(objectPropertyExpression)]). 447axiom_arguments(disjointObjectProperties,[set(objectPropertyExpression)]). 448valid_axiom(disjointObjectProperties(A)) :- subsumed_by([A],[set(objectPropertyExpression)]).
452disjointDataProperties(A) :- get_module(M),M:disjointProperties(A),subsumed_by([A],[set(dataPropertyExpression)]). 453axiom_arguments(disjointDataProperties,[set(dataPropertyExpression)]). 454valid_axiom(disjointDataProperties(A)) :- subsumed_by([A],[set(dataPropertyExpression)]).
inverseProperties(partOf,hasPart)
(extensional predicate - can be asserted)
:- thread_local(inverseProperties/2).464axiompred(inverseProperties/2). 465axiom_arguments(inverseProperties,[objectPropertyExpression, objectPropertyExpression]). 466valid_axiom(inverseProperties(A, B)) :- subsumed_by([A, B],[objectPropertyExpression, objectPropertyExpression]). 467expand_axiom(M,inverseProperties(A,B),NSList,inverseProperties(A_full_URL,B_full_URL)) :- 468 expand_objectPropertyExpression(M,A,NSList,A_full_URL), 469 expand_objectPropertyExpression(M,B,NSList,B_full_URL). 470 %add_expressivity(M,i).
477%:- thread_local(propertyDomain/2). 478 479axiompred(propertyDomain/2). 480axiom_arguments(propertyDomain,[propertyExpression, classExpression]). 481valid_axiom(propertyDomain(A, B)) :- subsumed_by([A, B],[propertyExpression, classExpression]). 482expand_axiom(M,propertyDomain(A,B),NSList,propertyDomain(A_full_URL,B_full_URL)) :- 483 expand_propertyExpression(M,A,NSList,A_full_URL), 484 expand_classExpression(M,B,NSList,B_full_URL).
488objectPropertyDomain(A, B) :- get_module(M),M:propertyDomain(A, B),subsumed_by([A, B],[objectPropertyExpression, classExpression]). 489axiom_arguments(objectPropertyDomain,[objectPropertyExpression, classExpression]). 490valid_axiom(objectPropertyDomain(A, B)) :- subsumed_by([A, B],[objectPropertyExpression, classExpression]).
494dataPropertyDomain(A, B) :- get_module(M),M:propertyDomain(A, B),subsumed_by([A, B],[dataPropertyExpression, classExpression]). 495axiom_arguments(dataPropertyDomain,[dataPropertyExpression, classExpression]). 496valid_axiom(dataPropertyDomain(A, B)) :- subsumed_by([A, B],[dataPropertyExpression, classExpression]).
500annotationPropertyDomain(A, B) :- get_module(M),M:propertyDomain(A, B),subsumed_by([A, B],[annotationProperty, iri]). 501axiom_arguments(annotationPropertyDomain,[annotationProperty, iri]). 502valid_axiom(annotationPropertyDomain(A, B)) :- subsumed_by([A, B],[annotationProperty, iri]).
thread_local(propertyRange/2).509axiompred(propertyRange/2). 510axiom_arguments(propertyRange,[propertyExpression, classExpression]). 511valid_axiom(propertyRange(A, B)) :- subsumed_by([A, B],[propertyExpression, classExpression]). 512expand_axiom(M,propertyRange(A,B),NSList,propertyRange(A_full_URL,B_full_URL)) :- 513 expand_iri(M,B,NSList,Datatype), 514 builtin_datatype(Datatype),!, 515 expand_dataRange(M,B,NSList,B_full_URL), 516 expand_dataPropertyExpression(M,A,NSList,A_full_URL). 517expand_axiom(M,propertyRange(A,B),NSList,propertyRange(A_full_URL,B_full_URL)) :- 518 expand_propertyExpression(M,A,NSList,A_full_URL), 519 expand_classExpression(M,B,NSList,B_full_URL).
523objectPropertyRange(A, B) :- propertyRange(A, B),subsumed_by([A, B],[objectPropertyExpression, classExpression]). 524axiom_arguments(objectPropertyRange,[objectPropertyExpression, classExpression]). 525valid_axiom(objectPropertyRange(A, B)) :- subsumed_by([A, B],[objectPropertyExpression, classExpression]).
529dataPropertyRange(A, B) :- get_module(M),M:propertyRange(A, B),subsumed_by([A, B],[dataPropertyExpression, dataRange]). 530axiom_arguments(dataPropertyRange,[objectPropertyExpression, dataRange]). 531valid_axiom(dataPropertyRange(A, B)) :- subsumed_by([A, B],[objectPropertyExpression, dataRange]).
535annotationPropertyRange(A, B) :- get_module(M),M:propertyRange(A, B),subsumed_by([A, B],[annotationProperty, iri]). 536axiom_arguments(annotationPropertyRange,[annotationProperty, iri]). 537valid_axiom(annotationPropertyRange(A, B)) :- subsumed_by([A, B],[annotationProperty, iri]).
thread_local(functionalProperty/1).544axiompred(functionalProperty/1). 545axiom_arguments(functionalProperty,[propertyExpression]). 546valid_axiom(functionalProperty(A)) :- subsumed_by([A],[propertyExpression]). 547expand_axiom(M,functionalProperty(A),NSList,functionalProperty(A_full_URL)) :- 548 expand_propertyExpression(M,A,NSList,A_full_URL). 549 %add_expressivity(M,f).
553functionalObjectProperty(A) :- get_module(M),M:functionalProperty(A),subsumed_by([A],[objectPropertyExpression]). 554axiom_arguments(functionalObjectProperty,[objectPropertyExpression]). 555valid_axiom(functionalObjectProperty(A)) :- subsumed_by([A],[objectPropertyExpression]).
559functionalDataProperty(A) :- get_module(M),M:functionalProperty(A),subsumed_by([A],[dataPropertyExpression]). 560axiom_arguments(functionalDataProperty,[dataPropertyExpression]). 561valid_axiom(functionalDataProperty(A)) :- subsumed_by([A],[dataPropertyExpression]).
thread_local(inverseFunctionalProperty/1).567axiompred(inverseFunctionalProperty/1). 568axiom_arguments(inverseFunctionalProperty,[objectPropertyExpression]). 569valid_axiom(inverseFunctionalProperty(A)) :- subsumed_by([A],[objectPropertyExpression]). 570expand_axiom(M,inverseFunctionalProperty(A),NSList,inverseFunctionalProperty(A_full_URL)) :- 571 expand_objectPropertyExpression(M,A,NSList,A_full_URL). 572 %add_expressivity(M,i), 573 %add_expressivity(M,f).
thread_local(reflexiveProperty/1).579axiompred(reflexiveProperty/1). 580axiom_arguments(reflexiveProperty,[objectPropertyExpression]). 581valid_axiom(reflexiveProperty(A)) :- subsumed_by([A],[objectPropertyExpression]). 582expand_axiom(M,reflexiveProperty(A),NSList,reflexiveProperty(A_full_URL)) :- 583 expand_objectPropertyExpression(M,A,NSList,A_full_URL).
thread_local(irreflexiveProperty/1).589axiompred(irreflexiveProperty/1). 590axiom_arguments(irreflexiveProperty,[objectPropertyExpression]). 591valid_axiom(irreflexiveProperty(A)) :- subsumed_by([A],[objectPropertyExpression]). 592expand_axiom(M,irreflexiveProperty(A),NSList,irreflexiveProperty(A_full_URL)) :- 593 expand_objectPropertyExpression(M,A,NSList,A_full_URL).
thread_local(symmetricProperty/1).599axiompred(symmetricProperty/1). 600axiom_arguments(symmetricProperty,[objectPropertyExpression]). 601valid_axiom(symmetricProperty(A)) :- subsumed_by([A],[objectPropertyExpression]). 602expand_axiom(M,symmetricProperty(A),NSList,symmetricProperty(A_full_URL)) :- 603 expand_objectPropertyExpression(M,A,NSList,A_full_URL).
thread_local(asymmetricProperty/1).609axiompred(asymmetricProperty/1). 610axiom_arguments(asymmetricProperty,[objectPropertyExpression]). 611valid_axiom(asymmetricProperty(A)) :- subsumed_by([A],[objectPropertyExpression]). 612expand_axiom(M,asymmetricProperty(A),NSList,asymmetricProperty(A_full_URL)) :- 613 expand_objectPropertyExpression(M,A,NSList,A_full_URL).
thread_local(transitiveProperty/1).619axiompred(transitiveProperty/1). 620axiom_arguments(transitiveProperty,[objectPropertyExpression]). 621valid_axiom(transitiveProperty(A)) :- subsumed_by([A],[objectPropertyExpression]). 622expand_axiom(M,transitiveProperty(A),NSList,transitiveProperty(A_full_URL)) :- 623 expand_objectPropertyExpression(M,A,NSList,A_full_URL). 624 %add_rule(M,forall_plus_rule), 625 %add_expressivity(M,s).
thread_local(hasKey/2).631axiompred(hasKey/2). 632axiom_arguments(hasKey,[classExpression,propertyExpression]). 633valid_axiom(hasKey(CE,PE)) :- subsumed_by([CE,PE],[classExpression,propertyExpression]). 634expand_axiom(M,hasKey(A,B),NSList,hasKey(A_full_URL,B_full_URL)) :- 635 expand_classExpression(M,A,NSList,A_full_URL), 636 expand_propertyExpression(M,B,NSList,B_full_URL).
643:- meta_predicate fact(). 644 645fact(M:annotationAssertion(A, B, C)) :- M:annotationAssertion(A, B, C). 646fact(M:differentIndividuals(A)) :- M:differentIndividuals(A). 647fact(M:negativePropertyAssertion(A, B, C)) :- M:negativePropertyAssertion(A, B, C). 648fact(M:propertyAssertion(A, B, C)) :- M:propertyAssertion(A, B, C). 649fact(M:sameIndividual(A)) :- M:sameIndividual(A). 650fact(M:classAssertion(A, B)) :- M:classAssertion(A, B). 651axiom_arguments(fact,[axiom]). 652valid_axiom(fact(A)) :- subsumed_by([A],[axiom]).
thread_local(sameIndividual/1).659axiompred(sameIndividual/1). 660axiom_arguments(sameIndividual,[set(individual)]). 661valid_axiom(sameIndividual(A)) :- subsumed_by([A],[set(individual)]). 662expand_axiom(M,sameIndividual(A),NSList,sameIndividual(A_full_URL)) :- 663 expand_individuals(M,A,NSList,A_full_URL).
thread_local(differentIndividuals/1).669axiompred(differentIndividuals/1). 670axiom_arguments(differentIndividuals,[set(individual)]). 671valid_axiom(differentIndividuals(A)) :- subsumed_by([A],[set(individual)]). 672expand_axiom(M,differentIndividuals(A),NSList,differentIndividuals(A_full_URL)) :- 673 expand_individuals(M,A,NSList,A_full_URL).
thread_local(lpIndividuals/1).679axiompred(lpIndividuals/1). 680axiom_arguments(lpIndividuals,[set(individual)]). 681valid_axiom(lpIndividuals(A)) :- subsumed_by([A],[set(individual)]). 682expand_axiom(M,lpIndividuals(A),NSList,lpIndividuals(A_full_URL)) :- 683 expand_individuals(M,A,NSList,A_full_URL).
thread_local(classAssertion/2).689axiompred(classAssertion/2). 690axiom_arguments(classAssertion,[classExpression, individual]). 691valid_axiom(classAssertion(A, B)) :- subsumed_by([A, B],[classExpression, individual]). 692expand_axiom(M,classAssertion(A,B),NSList,B_full_URL) :- 693 expand_iri(M,A,NSList,'http://www.w3.org/2000/01/rdf-schema#Datatype'),!, 694 ( expand_axiom(M,datatype(B),NSList,B_full_URL) -> true ; B_full_URL='none' ). 695expand_axiom(M,classAssertion(A,B),NSList,classAssertion(A_full_URL,B_full_URL)) :- 696 expand_classExpression(M,A,NSList,A_full_URL), 697 expand_individual(M,B,NSList,B_full_URL).
700axiompred(lpClassAssertion/1). 701axiom_arguments(lpClassAssertion,[classExpression]). 702valid_axiom(lpClassAssertion(A)) :- subsumed_by([A],[classExpression]). 703expand_axiom(M,lpClassAssertion(A),NSList,lpClassAssertion(A_full_URL)) :- 704 expand_classExpression(M,A,NSList,A_full_URL).
thread_local(propertyAssertion/3).711axiompred(propertyAssertion/3). 712axiom_arguments(propertyAssertion,[propertyExpression, individual, individual]). 713valid_axiom(propertyAssertion(A, B, C)) :- subsumed_by([A, B, C],[propertyExpression, individual, individual]). 714expand_axiom(M,propertyAssertion(A,B,C),NSList,propertyAssertion(IRI,B_full_URL,C_full_URL)) :- 715 expand_iri(M,A,NSList,IRI), 716 ( IRI='http://www.w3.org/2000/01/rdf-schema#label' ; IRI='http://www.w3.org/2000/01/rdf-schema#comment' ),!, 717 expand_iri(M,B,NSList,B_full_URL), 718 ( expand_iri(M,C,NSList,C_full_URL) ; expand_literal(M,C,NSList,C_full_URL) ), !. 719expand_axiom(M,propertyAssertion(A,B,C),NSList,propertyAssertion(A_full_URL,B_full_URL,C_full_URL)) :- 720 expand_individual(M,C,NSList,C_full_URL),!, 721 expand_individual(M,B,NSList,B_full_URL), 722 expand_objectPropertyExpression(M,A,NSList,A_full_URL). 723expand_axiom(M,propertyAssertion(A,B,C),NSList,propertyAssertion(A_full_URL,B_full_URL,C_full_URL)) :- 724 expand_literal(M,C,NSList,C_full_URL), 725 expand_individual(M,B,NSList,B_full_URL), 726 expand_dataPropertyExpression(M,A,NSList,A_full_URL).
729axiompred(lpPropertyAssertion/1). 730axiom_arguments(lpPropertyAssertion,[propertyExpression]). 731valid_axiom(lpPropertyAssertion(A)) :- subsumed_by([A],[propertyExpression]). 732expand_axiom(M,lpPropertyAssertion(A),NSList,lpPropertyAssertion(A_full_URL)) :- 733 expand_objectPropertyExpression(M,A,NSList,A_full_URL). 734expand_axiom(M,lpPropertyAssertion(A),NSList,lpPropertyAssertion(A_full_URL)) :- 735 expand_dataPropertyExpression(M,A,NSList,A_full_URL).
740objectPropertyAssertion(A, B, C) :- get_module(M),M:propertyAssertion(A, B, C),subsumed_by([A, B, C],[objectPropertyExpression, individual, individual]). 741axiom_arguments(objectPropertyAssertion,[objectPropertyExpression, individual, individual]). 742valid_axiom(objectPropertyAssertion(A, B, C)) :- subsumed_by([A, B, C],[objectPropertyExpression, individual, individual]).
746dataPropertyAssertion(A, B, C) :- get_module(M),M:propertyAssertion(A, B, C),subsumed_by([A, B, C],[dataPropertyExpression, individual, literal]). 747axiom_arguments(dataPropertyAssertion,[objectPropertyExpression, individual, literal]). 748valid_axiom(dataPropertyAssertion(A, B, C)) :- subsumed_by([A, B, C],[dataPropertyExpression, individual, literal]).
thread_local(negativePropertyAssertion/3).755axiompred(negativePropertyAssertion/3). 756axiom_arguments(negativePropertyAssertion,[propertyExpression, individual, individual]). 757valid_axiom(negativePropertyAssertion(A, B, C)) :- subsumed_by([A, B, C],[propertyExpression, individual, individual]). 758expand_axiom(M,negativePropertyAssertion(A,B,C),NSList,negativePropertyAssertion(A_full_URL,B_full_URL,C_full_URL)) :- 759 expand_individual(M,C,NSList,C_full_URL),!, 760 expand_individual(M,B,NSList,B_full_URL), 761 expand_objectPropertyExpression(M,A,NSList,A_full_URL). 762expand_axiom(M,negativePropertyAssertion(A,B,C),NSList,negativePropertyAssertion(A_full_URL,B_full_URL,C_full_URL)) :- 763 expand_literal(M,C,NSList,C_full_URL), 764 expand_individual(M,B,NSList,B_full_URL), 765 expand_dataPropertyExpression(M,A,NSList,A_full_URL).
769negativeObjectPropertyAssertion(A, B, C) :- get_module(M),M:negativePropertyAssertion(A, B, C),subsumed_by([A, B, C],[objectPropertyExpression, individual, individual]). 770axiom_arguments(negativeObjectPropertyAssertion,[objectPropertyExpression, individual, individual]). 771valid_axiom(negativeObjectPropertyAssertion(A, B, C)) :- subsumed_by([A, B, C],[objectPropertyExpression, individual, individual]).
775negativeDataPropertyAssertion(A, B, C) :- get_module(M),M:negativePropertyAssertion(A, B, C),subsumed_by([A, B, C],[dataPropertyExpression, individual, literal]). 776axiom_arguments(negativeDataPropertyAssertion,[dataPropertyExpression, individual, literal]). 777valid_axiom(negativeDataPropertyAssertion(A, B, C)) :- subsumed_by([A, B, C],[dataPropertyExpression, individual, literal]).
thread_local(annotationAssertion/3).783axiompred(annotationAssertion/3). 784axiom_arguments(annotationAssertion,[annotationProperty, annotationSubject, annotationValue]). 785valid_axiom(annotationAssertion(A, B, C)) :- subsumed_by([A, B, C],[annotationProperty, annotationSubject, annotationValue]). 786annotationSubject(_). 787annotationValue(_). 788expand_axiom(M,annotationAssertion(A,B,C),NSList,annotationAssertion(A_full_URL,B_full_URL,C_full_URL)) :- 789 expand_annotationProperty(M,A,NSList,A_full_URL), 790 expand_annotationSubject(M,B,NSList,B_full_URL), 791 expand_annotationValue(M,C,NSList,C_full_URL).
798axiompred(annotation/3). 799 800annotation(M:annotationAnnotation(A, B, C)) :- M:annotationAnnotation(M:A, B, C). 801annotation(M:axiomAnnotation(A, B, C)) :- M:axiomAnnotation(M:A, B, C). 802axiom_arguments(annotation,[iri,annotationProperty,annotationValue]). 803valid_axiom(annotation(A,B,C)) :- subsumed_by([A,B,C],[iri,annotationProperty,annotationValue]). 804expand_axiom(M,annotationAnnotation(A,B,C),NSList,annotationAnnotation(A_full_URL,B_full_URL,C_full_URL)) :- 805 expand_iri(M,A,NSList,A_full_URL), 806 expand_annotationProperty(M,B,NSList,B_full_URL), 807 expand_annotationValue(M,C,NSList,C_full_URL), 808 ( M:addKBName -> add_kb_atoms(M,annotationProperty,[A_full_URL]) ; true ).
811ontologyAnnotation(M:Ontology,AP,AV) :- 812 M:annotation(Ontology,AP,AV), 813 M:ontology(Ontology). 814axiom_arguments(ontologyAnnotation,[ontology, annotationProperty, annotationValue]). 815valid_axiom(ontologyAnnotation(A, B, C)) :- subsumed_by([A, B, C],[ontology, annotationProperty, annotationValue]).
818axiomAnnotation(M:Axiom,AP,AV) :- 819 M:annotation(Axiom,AP,AV), 820 M:axiom(Axiom). 821axiom_arguments(axiomAnnotation,[axiom, annotationProperty, annotationValue]). 822valid_axiom(axiomAnnotation(A, B, C)) :- subsumed_by([A, B, C],[axiom, annotationProperty, annotationValue]).
825annotationAnnotation(M:Annotation,AP,AV) :- 826 M:annotation(Annotation,AP,AV), 827 annotation(M:Annotation). 828axiom_arguments(annotationAnnotation,[annotation, annotationProperty, annotationValue]). 829valid_axiom(annotationAnnotation(A, B, C)) :- subsumed_by([A, B, C],[annotation, annotationProperty, annotationValue]).
thread_local(ontology/1).835expand_ontology(M,A,NSList,A_full_URL) :- 836 expand_iri(M,A,NSList,A_full_URL). 837 838axiompred(ontology/1). 839axiom_arguments(ontology,[iri]). 840valid_axiom(ontology(A)) :- subsumed_by([A],[iri]). 841expand_axiom(M,ontology(A),NSList,ontology(A_full_URL)) :- 842 expand_iri(M,A,NSList,A_full_URL).
846:- meta_predicate ontologyDirective(,). 847 848ontologyDirective(M:A, B) :- M:ontologyImport(A, B). 849ontologyDirective(M:A, B) :- M:ontologyAxiom(A, B). 850ontologyDirective(M:A, B) :- M:ontologyVersionInfo(A, B). 851axiom_arguments(ontologyDirective,[ontology, iri]). 852valid_axiom(ontologyDirective(A, B)) :- subsumed_by([A, B],[ontology, iri]).
subClassOf('http://example.org#a', 'http://example.org#b').
ontologyAxiom('http://example.org#', subClassOf('http://example.org#a','http://example.org#b')).
:- thread_local(ontologyAxiom/2).
864axiompred(ontologyAxiom/2). 865axiom_arguments(ontologyAxiom,[ontology, axiom]). 866valid_axiom(ontologyAxiom(A, B)) :- subsumed_by([A, B],[ontology, axiom]). 867expand_axiom(M,ontologyAxiom(A,B),NSList,ontology(A_full_URL,B_full_URL)) :- 868 expand_ontology(M,A,NSList,A_full_URL), 869 expand_axiom(M,B,NSList,B_full_URL).
thread_local(ontologyImport/2).875axiompred(ontologyImport/2). 876axiom_arguments(ontologyImport,[ontology, iri]). 877valid_axiom(ontologyImport(A, B)) :- subsumed_by([A, B],[ontology, iri]). 878expand_axiom(M,ontologyImport(A,B),NSList,ontology(A_full_URL,B)) :- 879 expand_iri(M,A,NSList,A_full_URL), 880 M:consult(B).
thread_local(ontologyVersionInfo/2).885axiompred(ontologyVersionInfo/2). 886axiom_arguments(ontologyVersionInfo,[ontology, iri]). 887valid_axiom(ontologyVersionInfo(A, B)) :- subsumed_by([A, B],[ontology, iri]). 888 889/**************************************** 890 RESTRICTIONS ON AXIOMS 891 ****************************************/ 892 893% 11.1 894% An object property expression OPE is simple in Ax if, for each object property expression OPE' such that OPE' ->* OPE holds, OPE' is not composite. 895% (The property hierarchy relation ->* is the reflexive-transitive closure of ->) 896%simpleObjectPropertyExpresion(OPE) :- 897% objectPropertyExpression(OPE), 898 899 900/**************************************** 901 EXPRESSIONS 902 ****************************************/ 903 904subsumed_by(X,_) :- var(X),!. 905subsumed_by([],[]) :- !. 906subsumed_by([I|IL],[T|TL]) :- 907 !, 908 subsumed_by(I,T), 909 subsumed_by(IL,TL). 910subsumed_by(L,set(T)):- 911 !, 912 forall(member(I,L), 913 subsumed_by(I,T)). 914subsumed_by(I,T):- 915 !, 916 G=..[T,I], 917 get_module(M), 918 M:G.
TODO: currently underconstrained, any atomic term can be an IRI923iri(IRI) :- atomic(IRI). % 924expand_iri(_M,NS_URL,NSList,Full_URL):- 925 atomic(NS_URL), 926 NS_URL \= literal(_), 927 uri_split(NS_URL,Short_NS,Term, ':'), 928 member((Short_NS=Long_NS),NSList), 929 concat_atom([Long_NS,Term],Full_URL),!. 930 931expand_iri(_M,NS_URL,NSList,Full_URL):- 932 atomic(NS_URL), 933 NS_URL \= literal(_), 934 \+ sub_atom(NS_URL,_,_,_,':'), 935 member(([]=Long_NS),NSList), 936 concat_atom([Long_NS,NS_URL],Full_URL),!. 937 938expand_iri(_M,IRI,_NSList,IRI):- atomic(IRI).
literal(_). % TODO944literal(literal(_)). % TODO 945expand_literal(M,literal(type(Type,Val)),NSList,literal(type(ExpType,Val))) :- 946 expand_datatype(M,Type,NSList,ExpType),!. 947expand_literal(_M,literal(Literal),_NSList,literal(Literal)). 948 949propertyExpression(E) :- objectPropertyExpression(E) ; dataPropertyExpression(E). 950 951expand_propertyExpressions(_M,[],_NSList,[]) :- !. 952expand_propertyExpressions(M,[CE|T],NSList,[ExpCE|ExpT]) :- 953 expand_propertyExpression(M,CE,NSList,ExpCE), 954 expand_propertyExpressions(M,T,NSList,ExpT). 955 956% expand_propertyExpression(M,E,NSList,ExpE):- expand_objectPropertyExpression(M,E,NSList,ExpE) ; expand_dataPropertyExpression(M,E,NSList,ExpE). % TODO: support for datatype to implement 957expand_propertyExpression(M,inverseOf(OP),NSList,inverseOf(ExpOP)) :- !, 958 expand_objectProperty(M,OP,NSList,ExpOP). 959 %add_expressivity(M,i). 960expand_propertyExpression(M,E,NSList,ExpE) :- expand_objectProperty(M,E,NSList,ExpE).
965objectPropertyExpression(E) :- objectProperty(E) ; inverseObjectProperty(E). 966% expand_objectPropertyExpression(M,E,NSList,ExpE) :- expand_objectProperty(M,E,NSList,ExpE) ; expand_inverseObjectProperty(M,E,NSList,ExpE). 967expand_objectPropertyExpression(M,inverseOf(OP),NSList,inverseOf(ExpOP)) :- !,expand_objectProperty(M,OP,NSList,ExpOP). 968 %add_expressivity(M,i). 969expand_objectPropertyExpression(M,E,NSList,ExpE) :- expand_objectProperty(M,E,NSList,ExpE). 970 971% give benefit of doubt; e.g. rdfs:label 972% in the OWL2 spec we have DataProperty := IRI 973% here dataProperty/1 is an asserted fact 974objectPropertyExpression(E) :- nonvar(E),iri(E). 975 976objectPropertyExpressionOrChain(propertyChain(PL)) :- forall(member(P,PL),objectPropertyExpression(P)). 977objectPropertyExpressionOrChain(PE) :- objectPropertyExpression(PE). 978expand_objectPropertyExpressionOrChain(M,propertyChain(PL),NSList,propertyChain(ExpPL)):- !, 979 expand_propertyExpressions(M,PL,NSList,ExpPL). 980 %add_expressivity(M,r). 981expand_objectPropertyExpressionOrChain(M,P,NSList,ExpP):- 982 expand_objectPropertyExpression(M,P,NSList,ExpP). 983 984 985 986inverseObjectProperty(inverseOf(OP)) :- objectProperty(OP). 987expand_inverseObjectProperty(M,inverseOf(OP),NSList,inverseOf(ExpOP)) :- expand_objectProperty(M,OP,NSList,ExpOP). 988 %add_expressivity(M,i). 989 990expand_dataPropertyExpressions(M,DPEs,NSList,ExpDPEs) :- expand_dataPropertyExpression(M,DPEs,NSList,ExpDPEs). 991 992dataPropertyExpression(E) :- dataProperty(E). 993expand_dataPropertyExpression(M,E,NSList,ExpE) :- expand_dataProperty(M,E,NSList,ExpE). 994 995dataPropertyExpression(DPEs) :- 996 ( is_list(DPEs) 997 -> forall(member(DPE,DPEs), 998 dataPropertyExpression(DPE)) 999 ; dataPropertyExpression(DPEs)). 1000 1001expand_dataPropertyExpression(_M,[],_NSList,[]) :- !. 1002expand_dataPropertyExpression(M,[DPE|T],NSList,[ExpDPE|ExpT]) :- 1003 expand_dataPropertyExpression(M,DPE,NSList,ExpDPE), 1004 expand_dataPropertyExpression(M,T,NSList,ExpT). 1005 1006% give benefit of doubt; e.g. rdfs:label 1007% in the OWL2 spec we have DataProperty := IRI 1008% here dataProperty/1 is an asserted fact 1009dataPropertyExpression(E) :- nonvar(E),iri(E). 1010 1011%already declared as entity 1012%datatype(IRI) :- iri(IRI). 1013expand_datatype(M,DT,NSList,ExpDT) :- 1014 expand_iri(M,DT,NSList,ExpDT), 1015 builtin_datatype(ExpDT). 1016 1017expand_dataRanges(_M,[],_NSList,[]) :- !. 1018expand_dataRanges(M,[H|T],NSList,[ExpH|ExpT]) :- 1019 expand_dataRange(M,H,NSList,ExpH), 1020 expand_dataRanges(M,T,NSList,ExpT).
1023dataRange(DR) :- 1024 (datatype(DR) ; 1025 dataIntersectionOf(DR ); 1026 dataUnionOf(DR) ; 1027 dataComplementOf(DR) ; 1028 dataOneOf(DR) ; 1029 datatypeRestriction(DR)),!. 1030expand_dataRange(M,intersectionOf(DRs),NSList,intersectionOf(ExpDRs)) :- !, 1031 expand_dataRanges(M,DRs,NSList,ExpDRs). 1032expand_dataRange(M,unionOf(DRs),NSList,unionOf(ExpDRs)) :- !, 1033 expand_dataRanges(M,DRs,NSList,ExpDRs). 1034expand_dataRange(M,complementOf(DR),NSList,complementOf(ExpDR)) :- !, 1035 expand_dataRange(M,DR,NSList,ExpDR). 1036expand_dataRange(M,oneOf(DRs),NSList,oneOf(ExpDRs)) :- !, 1037 expand_dataRanges(M,DRs,NSList,ExpDRs). 1038expand_dataRange(M,datatypeRestriction(DR,FacetValues),NSList,datatypeRestriction(DRs,FacetValues)):- !, 1039 expand_datatype(M,DR,NSList,DRs), 1040 FacetValues=[_|_]. 1041expand_dataRange(M,literal(DR),NSList,ExpDR):- !, 1042 expand_literal(M,literal(DR),NSList,ExpDR). 1043expand_dataRange(M,DR,NSList,ExpDR) :- 1044 expand_datatype(M,DR,NSList,ExpDR), 1045 ( M:addKBName -> add_kb_atoms(M,datatype,[ExpDR]) ; true ).
Example: classExpression(intersectionOf([car,someValuesFrom(hasColor,blue)])))
Union of:
class/1 | objectIntersectionOf/1 | objectUnionOf/1 | objectComplementOf/1 | objectOneOf/1 | objectSomeValuesFrom/1 | objectAllValuesFrom/1 | objectHasValue/1 | objectHasSelf/1 | objectMinCardinality/1 | objectMaxCardinality/1 | objectExactCardinality/1 | dataSomeValuesFrom/1 | dataAllValuesFrom/1 | dataHasValue/1 | dataMinCardinality/1 | dataMaxCardinality/1 | dataExactCardinality/1
1063expand_classExpressions(_M,[],_NSList,[]) :- !. 1064expand_classExpressions(M,[CE|T],NSList,[ExpCE|ExpT]) :- 1065 expand_classExpression(M,CE,NSList,ExpCE), 1066 expand_classExpressions(M,T,NSList,ExpT). 1067 1068classExpression(CE):- 1069 (iri(CE) ; % NOTE: added to allow cases where class is not imported 1070 class(CE) ; 1071 objectIntersectionOf(CE) ; objectUnionOf(CE) ; objectComplementOf(CE) ; objectOneOf(CE) ; 1072 objectSomeValuesFrom(CE) ; objectAllValuesFrom(CE) ; objectHasValue(CE) ; objectHasSelf(CE) ; 1073 objectMinCardinality(CE) ; objectMaxCardinality(CE) ; objectExactCardinality(CE) ; 1074 dataSomeValuesFrom(CE) ; dataAllValuesFrom(CE) ; dataHasValue(CE) ; 1075 dataMinCardinality(CE) ; dataMaxCardinality(CE) ; dataExactCardinality(CE)),!. 1076/* 1077expand_classExpression(M,CE,NSList,ExpCE):- % TODO: add management datatype 1078 (expand_class(M,CE,NSList,ExpCE) ; % NOTE: added to allow cases where class is not imported 1079 expand_objectIntersectionOf(M,CE,NSList,ExpCE) ; expand_objectUnionOf(M,CE,NSList,ExpCE) ; expand_objectComplementOf(M,CE,NSList,ExpCE) ; expand_objectOneOf(M,CE,NSList,ExpCE) ; 1080 expand_objectSomeValuesFrom(M,CE,NSList,ExpCE) ; expand_objectAllValuesFrom(M,CE,NSList,ExpCE) ; expand_objectHasValue(M,CE,NSList,ExpCE) ; expand_objectHasSelf(M,CE,NSList,ExpCE) ; 1081 expand_objectMinCardinality(M,CE,NSList,ExpCE) ; expand_objectMaxCardinality(M,CE,NSList,ExpCE) ; expand_objectExactCardinality(M,CE,NSList,ExpCE) ; 1082 expand_dataSomeValuesFrom(M,CE,NSList,ExpCE) ; expand_dataAllValuesFrom(M,CE,NSList,ExpCE) ; expand_dataHasValue(M,CE,NSList,ExpCE) ; 1083 expand_dataMinCardinality(M,CE,NSList,ExpCE) ; expand_dataMaxCardinality(M,CE,NSList,ExpCE) ; expand_dataExactCardinality(M,CE,NSList,ExpCE)), 1084 ( M:addKBName -> add_kb_atoms(M,class,[ExpCE]) ; true ). 1085*/ 1086expand_classExpression(M,intersectionOf(CEs),NSList,intersectionOf(ExpCEs)):- !, 1087 expand_classExpressions(M,CEs,NSList,ExpCEs), 1088 ( M:addKBName -> add_kb_atoms(M,class,[intersectionOf(ExpCEs)]) ; true ). 1089expand_classExpression(M,unionOf(CEs),NSList,unionOf(ExpCEs)) :- !, 1090 expand_classExpressions(M,CEs,NSList,ExpCEs), 1091 ( M:addKBName -> add_kb_atoms(M,class,[unionOf(ExpCEs)]) ; true ). 1092 %add_rule(M,or_rule), 1093 %add_expressivity(M,a). 1094expand_classExpression(M,complementOf(CE),NSList,complementOf(ExpCE)) :- !, 1095 expand_classExpression(M,CE,NSList,ExpCE), 1096 ( M:addKBName -> add_kb_atoms(M,class,[complementOf(ExpCE)]) ; true ). 1097 %add_expressivity(M,a). 1098expand_classExpression(M,oneOf(Is),NSList,oneOf(ExpIs)) :- !, % TODO check in trillo 1099 expand_individuals(M,Is,NSList,ExpIs), 1100 ( M:addKBName -> add_kb_atoms(M,class,[oneOf(ExpIs)]) ; true ). 1101 %add_rule(M,o_rule), 1102 %add_expressivity(M,o). 1103expand_classExpression(M,someValuesFrom(OPE,CE),NSList,someValuesFrom(ExpOPE,ExpCE)) :- !, 1104 expand_objectPropertyExpression(M,OPE,NSList,ExpOPE), 1105 expand_classExpression(M,CE,NSList,ExpCE), 1106 ( M:addKBName -> add_kb_atoms(M,class,[someValuesFrom(ExpOPE,ExpCE)]) ; true ). 1107 %add_rule(M,exists_rule). 1108expand_classExpression(M,allValuesFrom(OPE,CE),NSList,allValuesFrom(ExpOPE,ExpCE)) :- !, 1109 expand_objectPropertyExpression(M,OPE,NSList,ExpOPE), 1110 expand_classExpression(M,CE,NSList,ExpCE), 1111 ( M:addKBName -> add_kb_atoms(M,class,[allValuesFrom(ExpOPE,ExpCE)]) ; true ). 1112 %add_rule(M,forall_rule), 1113 %add_expressivity(M,a). 1114expand_classExpression(M,hasValue(OPE,I),NSList,hasValue(ExpOPE,ExpI)) :- !, % TODO: add in trillo 1115 expand_objectPropertyExpression(M,OPE,NSList,ExpOPE), 1116 expand_individual(M,I,NSList,ExpI), 1117 ( M:addKBName -> add_kb_atoms(M,class,[hasValue(ExpOPE,ExpI)]) ; true ). 1118expand_classExpression(M,hasSelf(OPE),NSList,hasSelf(ExpOPE)) :- !, % TODO: add in trillo 1119 expand_objectPropertyExpression(M,OPE,NSList,ExpOPE), 1120 ( M:addKBName -> add_kb_atoms(M,class,[hasSelf(ExpOPE)]) ; true ). 1121expand_classExpression(M,minCardinality(C,OPE,CE),NSList,minCardinality(C,ExpOPE,ExpCE)):- !, 1122 number(C), 1123 C>=0, 1124 expand_objectPropertyExpression(M,OPE,NSList,ExpOPE), 1125 expand_classExpression(M,CE,NSList,ExpCE), 1126 ( M:addKBName -> add_kb_atoms(M,class,[minCardinality(C,ExpOPE,ExpCE)]) ; true ). 1127 %add_rule(M,min_rule), 1128 %add_expressivity(M,q). 1129expand_classExpression(M,minCardinality(C,OPE),NSList,minCardinality(C,ExpOPE)):- !, 1130 number(C), 1131 C>=0, 1132 expand_objectPropertyExpression(M,OPE,NSList,ExpOPE), 1133 ( M:addKBName -> add_kb_atoms(M,class,[minCardinality(C,ExpOPE)]) ; true ). 1134 %add_rule(M,min_rule), 1135 %add_expressivity(M,n). 1136expand_classExpression(M,maxCardinality(C,OPE,CE),NSList,maxCardinality(C,ExpOPE,ExpCE)):- !, 1137 number(C), 1138 C>=0, 1139 expand_objectPropertyExpression(M,OPE,NSList,ExpOPE), 1140 expand_classExpression(M,CE,NSList,ExpCE), 1141 ( M:addKBName -> add_kb_atoms(M,class,[maxCardinality(C,ExpOPE,ExpCE)]) ; true ). 1142 %add_rule(M,max_rule), 1143 %add_expressivity(M,q). 1144expand_classExpression(M,maxCardinality(C,OPE),NSList,maxCardinality(C,ExpOPE)):- !, 1145 number(C), 1146 C>=0, 1147 expand_objectPropertyExpression(M,OPE,NSList,ExpOPE), 1148 ( M:addKBName -> add_kb_atoms(M,class,[maxCardinality(C,ExpOPE)]) ; true ). 1149 %add_rule(M,max_rule), 1150 %add_expressivity(M,n). 1151expand_classExpression(M,exactCardinality(C,OPE,CE),NSList,exactCardinality(C,ExpOPE,ExpCE)):- !, 1152 number(C), 1153 C>=0, 1154 expand_objectPropertyExpression(M,OPE,NSList,ExpOPE), 1155 expand_classExpression(M,CE,NSList,ExpCE), 1156 ( M:addKBName -> add_kb_atoms(M,class,[exactCardinality(C,ExpOPE,ExpCE)]) ; true ). 1157 %add_rule(M,min_rule),add_rule(M,max_rule), 1158 %add_expressivity(M,q). 1159expand_classExpression(M,exactCardinality(C,OPE),NSList,exactCardinality(C,ExpOPE)):- !, 1160 number(C), 1161 C>=0, 1162 expand_objectPropertyExpression(M,OPE,NSList,ExpOPE), 1163 ( M:addKBName -> add_kb_atoms(M,class,[exactCardinality(C,ExpOPE)]) ; true ). 1164 %add_rule(M,min_rule),add_rule(M,max_rule), 1165 %add_expressivity(M,n). 1166expand_classExpression(M,CE,NSList,ExpCE):- 1167 expand_class(M,CE,NSList,ExpCE), 1168 ( M:addKBName -> add_kb_atoms(M,class,[ExpCE]) ; true ).
intersectionOf(ClassExpression:list)
An intersection class expression IntersectionOf( CE1 ... CEn ) contains all individuals that are instances of all class expressions CEi for 1 <= i <= n.
1174objectIntersectionOf(intersectionOf(CEs)) :- 1175 forall(member(CE,CEs), 1176 classExpression(CE)). 1177expand_objectIntersectionOf(M,intersectionOf(CEs),NSList,intersectionOf(ExpCEs)) :- 1178 expand_classExpressions(M,CEs,NSList,ExpCEs).
1182objectUnionOf(unionOf(CEs)) :- 1183 forall(member(CE,CEs), 1184 classExpression(CE)). 1185expand_objectUnionOf(M,unionOf(CEs),NSList,unionOf(ExpCEs)) :- 1186 expand_classExpressions(M,CEs,NSList,ExpCEs).
1190objectComplementOf(complementOf(CE)) :- 1191 classExpression(CE). 1192expand_objectComplementOf(M,complementOf(CE),NSList,complementOf(ExpCE)) :- 1193 expand_classExpression(M,CE,NSList,ExpCE).
1197objectOneOf(oneOf(Is)) :- 1198 is_list(Is). % TODO: check if we need to strengthen this check 1199%objectOneOf(oneOf(Is)) :- 1200% forall(member(I,Is), 1201% individual(I)). 1202expand_objectOneOf(M,oneOf(Is),NSList,oneOf(ExpIs)) :- 1203 expand_individuals(M,Is,NSList,ExpIs).
1207objectSomeValuesFrom(someValuesFrom(OPE,CE)) :- 1208 objectPropertyExpression(OPE), 1209 classExpression(CE). 1210expand_objectSomeValuesFrom(M,someValuesFrom(OPE,CE),NSList,someValuesFrom(ExpOPE,ExpCE)) :- 1211 expand_objectPropertyExpression(M,OPE,NSList,ExpOPE), 1212 expand_classExpression(M,CE,NSList,ExpCE).
1216objectAllValuesFrom(allValuesFrom(OPE,CE)) :- 1217 objectPropertyExpression(OPE), 1218 classExpression(CE). 1219expand_objectAllValuesFrom(M,allValuesFrom(OPE,CE),NSList,allValuesFrom(ExpOPE,ExpCE)) :- 1220 expand_objectPropertyExpression(M,OPE,NSList,ExpOPE), 1221 expand_classExpression(M,CE,NSList,ExpCE).
1225objectHasValue(hasValue(OPE,I)) :- 1226 objectPropertyExpression(OPE), 1227 individual(I). 1228expand_objectHasValue(M,hasValue(OPE,I),NSList,hasValue(ExpOPE,ExpI)) :- 1229 expand_objectPropertyExpression(M,OPE,NSList,ExpOPE), 1230 expand_individual(M,I,NSList,ExpI).
1234objectHasSelf(hasSelf(OPE)) :- 1235 objectPropertyExpression(OPE). 1236expand_objectHasSelf(M,hasSelf(OPE),NSList,hasSelf(ExpOPE)) :- 1237 expand_objectPropertyExpression(M,OPE,NSList,ExpOPE).
1241objectMinCardinality(minCardinality(C,OPE,CE)):- 1242 number(C), 1243 C>=0, 1244 objectPropertyExpression(OPE), 1245 classExpression(CE). 1246objectMinCardinality(minCardinality(C,OPE)):- 1247 number(C), 1248 C>=0, 1249 objectPropertyExpression(OPE). 1250expand_objectMinCardinality(M,minCardinality(C,OPE,CE),NSList,minCardinality(C,ExpOPE,ExpCE)):- 1251 number(C), 1252 C>=0, 1253 expand_objectPropertyExpression(M,OPE,NSList,ExpOPE), 1254 expand_classExpression(M,CE,NSList,ExpCE). 1255expand_objectMinCardinality(M,minCardinality(C,OPE),NSList,minCardinality(C,ExpOPE)):- 1256 number(C), 1257 C>=0, 1258 expand_objectPropertyExpression(M,OPE,NSList,ExpOPE).
1262objectMaxCardinality(maxCardinality(C,OPE,CE)):- 1263 number(C), 1264 C>=0, 1265 objectPropertyExpression(OPE), 1266 classExpression(CE). 1267objectMaxCardinality(maxCardinality(C,OPE)):- 1268 number(C), 1269 C>=0, 1270 objectPropertyExpression(OPE). 1271expand_objectMaxCardinality(M,maxCardinality(C,OPE,CE),NSList,maxCardinality(C,ExpOPE,ExpCE)):- 1272 number(C), 1273 C>=0, 1274 expand_objectPropertyExpression(M,OPE,NSList,ExpOPE), 1275 expand_classExpression(M,CE,NSList,ExpCE). 1276expand_objectMaxCardinality(M,maxCardinality(C,OPE),NSList,maxCardinality(C,ExpOPE)):- 1277 number(C), 1278 C>=0, 1279 expand_objectPropertyExpression(M,OPE,NSList,ExpOPE).
1283objectExactCardinality(exactCardinality(C,OPE,CE)):- 1284 number(C), 1285 C>=0, 1286 objectPropertyExpression(OPE), 1287 classExpression(CE). 1288objectExactCardinality(exactCardinality(C,OPE)):- 1289 number(C), 1290 C>=0, 1291 objectPropertyExpression(OPE). 1292% NON-NORMATIVE: we accept this in order to maximize compatibility with Thea1 1293objectExactCardinality(cardinality(C,OPE)):- 1294 number(C), 1295 C>=0, 1296 objectPropertyExpression(OPE). 1297expand_objectExactCardinality(M,exactCardinality(C,OPE,CE),NSList,exactCardinality(C,ExpOPE,ExpCE)):- 1298 number(C), 1299 C>=0, 1300 expand_objectPropertyExpression(M,OPE,NSList,ExpOPE), 1301 expand_classExpression(M,CE,NSList,ExpCE). 1302expand_objectExactCardinality(M,exactCardinality(C,OPE),NSList,exactCardinality(C,ExpOPE)):- 1303 number(C), 1304 C>=0, 1305 expand_objectPropertyExpression(M,OPE,NSList,ExpOPE).
1309dataIntersectionOf(intersectionOf(DRs)) :- 1310 forall(member(DR,DRs), 1311 dataRange(DR)). 1312expand_dataIntersectionOf(M,intersectionOf(DRs),NSList,intersectionOf(ExpDRs)) :- 1313 expand_dataRanges(M,DRs,NSList,ExpDRs).
1317dataUnionOf(unionOf(DRs)) :- 1318 forall(member(DR,DRs), 1319 dataRange(DR)). 1320expand_dataUnionOf(M,unionOf(DRs),NSList,unionOf(ExpDRs)) :- 1321 expand_dataRanges(M,DRs,NSList,ExpDRs).
1325dataComplementOf(complementOf(DR)) :- 1326 dataRange(DR). 1327expand_dataComplementOf(M,complementOf(DR),NSList,complementOf(ExpDR)) :- 1328 expand_dataRange(M,DR,NSList,ExpDR).
1332dataOneOf(oneOf(DRs)) :- 1333 forall(member(DR,DRs), 1334 dataRange(DR)). 1335expand_dataOneOf(M,oneOf(DRs),NSList,oneOf(ExpDRs)) :- 1336 expand_dataRanges(M,DRs,NSList,ExpDRs).
TODO: multiple args1341datatypeRestriction(datatypeRestriction(DR,FacetValues)):- 1342 datatype(DR), 1343 FacetValues=[_|_]. 1344expand_datatypeRestriction(M,datatypeRestriction(DR,FacetValues),NSList,datatypeRestriction(DRs,FacetValues)):- 1345 expand_datatype(M,DR,NSList,DRs), 1346 FacetValues=[_|_].
1349dataSomeValuesFrom(someValuesFrom(DPE,DR)):- 1350 dataPropertyExpression(DPE), 1351 dataRange(DR). 1352expand_dataSomeValuesFrom(M,someValuesFrom(DPE,DR),NSList,someValuesFrom(ExpDPE,ExpDR)):- 1353 expand_dataRange(M,DR,NSList,ExpDR), 1354 expand_dataPropertyExpression(M,DPE,NSList,ExpDPE).
1357dataAllValuesFrom(allValuesFrom(DPE,DR)):- 1358 dataPropertyExpression(DPE), 1359 dataRange(DR). 1360expand_dataAllValuesFrom(M,allValuesFrom(DPE,DR),NSList,allValuesFrom(ExpDPE,ExpDR)):- 1361 expand_dataRange(M,DR,NSList,ExpDR), 1362 expand_dataPropertyExpression(M,DPE,NSList,ExpDPE).
1366dataHasValue(hasValue(DPE,L)):- 1367 dataPropertyExpression(DPE), 1368 literal(L). 1369expand_dataHasValue(M,hasValue(DPE,L),NSList,hasValue(ExpDPE,ExpL)):- 1370 expand_literal(M,L,NSList,ExpL), 1371 expand_dataPropertyExpression(M,DPE,NSList,ExpDPE).
1375dataMinCardinality(minCardinality(C,DPE,DR)):- 1376 number(C), 1377 C>=0, 1378 dataPropertyExpression(DPE), 1379 dataRange(DR). 1380dataMinCardinality(minCardinality(C,DPE)):- 1381 number(C), 1382 C>=0, 1383 dataPropertyExpression(DPE). 1384expand_dataMinCardinality(M,minCardinality(C,DPE,DR),NSList,minCardinality(C,ExpDPE,ExpDR)):- 1385 number(C), 1386 C>=0, 1387 expand_dataRange(M,DR,NSList,ExpDR), 1388 expand_dataPropertyExpression(M,DPE,NSList,ExpDPE). 1389expand_dataMinCardinality(M,minCardinality(C,DPE),NSList,minCardinality(C,ExpDPE)):- 1390 number(C), 1391 C>=0, 1392 expand_dataPropertyExpression(M,DPE,NSList,ExpDPE).
1397dataMaxCardinality(maxCardinality(C,DPE,DR)):- 1398 number(C), 1399 C>=0, 1400 dataPropertyExpression(DPE), 1401 dataRange(DR). 1402dataMaxCardinality(maxCardinality(C,DPE)):- 1403 number(C), 1404 C>=0, 1405 dataPropertyExpression(DPE). 1406expand_dataMaxCardinality(M,maxCardinality(C,DPE,DR),NSList,maxCardinality(C,ExpDPE,ExpDR)):- 1407 number(C), 1408 C>=0, 1409 expand_dataRange(M,DR,NSList,ExpDR), 1410 expand_dataPropertyExpression(M,DPE,NSList,ExpDPE). 1411expand_dataMaxCardinality(M,maxCardinality(C,DPE),NSList,maxCardinality(C,ExpDPE)):- 1412 number(C), 1413 C>=0, 1414 expand_dataPropertyExpression(M,DPE,NSList,ExpDPE).
1419dataExactCardinality(exactCardinality(C,DPE,DR)):- 1420 number(C), 1421 C>=0, 1422 dataPropertyExpression(DPE), 1423 dataRange(DR). 1424dataExactCardinality(exactCardinality(C,DPE)):- 1425 number(C), 1426 C>=0, 1427 dataPropertyExpression(DPE). 1428% NON-NORMATIVE: we accept this in order to maximize compatibility with Thea1 1429dataExactCardinality(cardinality(C,OPE)):- 1430 number(C), 1431 C>=0, 1432 objectPropertyExpression(OPE). 1433expand_dataExactCardinality(M,exactCardinality(C,DPE,DR),NSList,exactCardinality(C,ExpDPE,ExpDR)):- 1434 number(C), 1435 C>=0, 1436 expand_dataRange(M,DR,NSList,ExpDR), 1437 expand_dataPropertyExpression(M,DPE,NSList,ExpDPE). 1438expand_dataExactCardinality(M,exactCardinality(C,DPE),NSList,exactCardinality(C,ExpDPE)):- 1439 number(C), 1440 C>=0, 1441 expand_dataPropertyExpression(M,DPE,NSList,ExpDPE).
1449is_valid_axiom(Axiom) :- \+ \+ valid_axiom(Axiom). 1450 1451 1452/**************************************** 1453 VIEW PREDICATES 1454 ****************************************/
1458equivalent_to(X,Y) :- equivalentClasses(L),member(X,L),member(Y,L),X\=Y. 1459equivalent_to(X,Y) :- equivalentProperties(L),member(X,L),member(Y,L),X\=Y. 1460 1461disjoint_with(X,Y) :- disjointClasses(L),member(X,L),member(Y,L),X\=Y.
1465anyPropertyAssertion(P,E,V) :- propertyAssertion(P,E,V). 1466anyPropertyAssertion(P,E,V) :- annotationAssertion(P,E,V).
1470labelAnnotation_value(X,Val) :- 1471 anyPropertyAssertion('http://www.w3.org/2000/01/rdf-schema#label', X, literal(type(_,Val))),atom(Val). 1472labelAnnotation_value(X,Val) :- 1473 anyPropertyAssertion('http://www.w3.org/2000/01/rdf-schema#label', X, literal(lang(_,Val))),atom(Val). 1474labelAnnotation_value(X,Val) :- 1475 anyPropertyAssertion('http://www.w3.org/2000/01/rdf-schema#label', X, literal(Val)),atom(Val). 1476 1477/**************************************** 1478 META-PREDICATES 1479 ****************************************/
e.g. axiom_directly_about( subClassOf(X,_), X).
also include property assertions whose second argument is equal to About.
e.g. axiom_directly_about( propertyAssertion(P,X,_), X).
1491axiom_directly_about(Ax,About) :- 1492 trillo:axiom(Ax), 1493 Ax =.. [_,Arg1|_], 1494 ( is_list(Arg1) 1495 -> member(About,Arg1) 1496 ; About=Arg1). 1497axiom_directly_about(Ax,About) :- 1498 Ax=propertyAssertion(_,About,_), 1499 trillo:axiom(Ax). 1500axiom_directly_about(Ax,About) :- 1501 Ax=annotationAssertion(_,About,_), 1502 trillo:axiom(Ax). 1503axiom_directly_about(Ax,About) :- 1504 Ax=classAssertion(_,About), 1505 trillo:axiom(Ax).
1514axiom_directly_references(Ax,Ref) :- 1515 trillo:axiom(Ax), 1516 axiom_or_expression_references(Ax,Ref). 1517 1518axiom_or_expression_references(X,Ref) :- 1519 X =.. [P|Args], 1520 P\=literal, 1521 member(Arg,Args), 1522 ( is_list(Arg) 1523 -> member(Ref,Arg) 1524 ; Ref=Arg). 1525 1526axiom_about(Ax,About) :- 1527 axiom_directly_about(Ax,About). 1528axiom_about(Ax,About) :- 1529 axiom_directly_about(Ax,X), 1530 axiom_about(X,About). 1531 1532axiom_references(Ax,Ref) :- 1533 axiom_directly_references(Ax,Ref). 1534axiom_references(Ax,Ref) :- 1535 axiom_directly_references(Ax,X), 1536 axiom_or_expression_references(X,Ref). 1537 1538axiom_contains_expression(Ax,Ex) :- 1539 axiom_contains_expression(Ax,Ex,_). 1540axiom_contains_expression(Ax,Ex,D) :- 1541 trillo:axiom(Ax), 1542 expression_has_subexpression(Ax,Ex,[],Chain), 1543 length(Chain,D). 1544 1545expression_has_subexpression(Ex,Ex,Accum,Accum). 1546expression_has_subexpression(Ex,SubEx,Accum,Results) :- 1547 Ex =.. [F|Args], 1548 member(A,Args), 1549 expression_has_subexpression(A,SubEx,[F|Accum],Results).
subClassOf(a,intersectionOf([b,someValuesFrom(p,c)]))
then Desc will be a member of [a, b, c, b and p some c, p some c]
1560referenced_description(C) :- 1561 setof(C,referenced_description_1(C),Cs), 1562 member(C,Cs). 1563 1564referenced_description_1(C) :- class(C). 1565referenced_description_1(C) :- 1566 subClassOf(A,B), 1567 ( referenced_description(A,C) 1568 ; referenced_description(B,C)). 1569referenced_description_1(C) :- 1570 equivalentClasses(L), 1571 member(A,L), 1572 referenced_description(A,C). 1573referenced_description_1(C) :- 1574 classAssertion(A,_), 1575 referenced_description(A,C). 1576 1577% TODO - this is incomplete 1578referenced_description(X,X) :- ground(X). 1579referenced_description(someValuesFrom(_,X),Y) :- referenced_description(X,Y). 1580referenced_description(allValuesFrom(_,X),Y) :- referenced_description(X,Y). 1581referenced_description(intersectionOf(L),Y) :- member(X,L),referenced_description(X,Y). 1582referenced_description(unionOf(L),Y) :- member(X,L),referenced_description(X,Y). 1583 1584 1585/**************************************** 1586 UTILITY 1587 ****************************************/ 1588 1589 1590%:- thread_local assert_axiom_hook/1.
this also asserts ontologyAxiom/2, using trdf_setting with current_ontology
1600assert_axiom(M,Axiom) :- 1601 ( M:ns4query(NSList) -> true; NSList = []), 1602 expand_axiom(M,Axiom,NSList,ExpAxiom), 1603 dif(ExpAxiom,'none'), 1604 ( M:ExpAxiom -> true 1605 ; 1606 ( assert(M:), 1607 ( M:trdf_setting(current_ontology,O) 1608 -> assert(M:ontologyAxiom(O,ExpAxiom)) 1609 ; true) 1610 ) 1611 ), !,trillo:update_tabs(M,ExpAxiom). 1612assert_axiom(_M,_Axiom).
1617assert_axiom(M,Axiom,_) :- 1618 M:Axiom, 1619 !. 1620assert_axiom(M,Axiom,O) :- 1621 assert(M:), 1622 assert(M:ontologyAxiom(O,Axiom)), 1623 !.
also removes ontologyAxiom/2 from ALL ontologies
1634retract_axiom(M,Axiom) :-
1635 retractall(M:),
1636 retractall(M:ontologyAxiom(_,Axiom)),
1637 !.1641retract_axiom(M,Axiom,Ontology) :- 1642 \+ var(Ontology), 1643 retractall(M:ontologyAxiom(Ontology,Axiom)), 1644 ( \+ M:ontologyAxiom(_,Axiom) 1645 -> retractall(M:) 1646 ; true), % still exists in other ontology.. 1647 !. 1648 1649 1650retract_all_axioms(M) :- 1651 findall(M:A,trillo:axiom(M:A),Axioms), 1652 maplist(retract,Axioms), 1653 findall(M:ontologyAxiom(O,A),M:ontologyAxiom(O,A),OAxioms), 1654 maplist(retract,OAxioms), 1655 !. 1656 1657 1658utility_translation_init(M) :- 1659 assert(M:annotationProperty('http://www.w3.org/2000/01/rdf-schema#label')), 1660 assert(M:annotationProperty('http://www.w3.org/2000/01/rdf-schema#comment')), 1661 assert(M:annotationProperty('https://sites.google.com/a/unife.it/ml/disponte#probability')), % Retro-compatibility 1662 assert(M:annotationProperty('http://ml.unife.it/disponte#probability')). 1663 1664consult_axioms(File) :- 1665 consult(File). 1666 1667axiom_type(A,T) :- functor(A,T,_). 1668 1669:- use_module(library(debug)). 1670:- use_module(library('semweb/rdf_db')). 1671:- use_module(library('semweb/rdf_edit')). 1672:- use_module(library('semweb/rdfs')). 1673:- use_module(library('url')). 1674:- use_module(library('http/http_open')). 1675:- use_module(library(charsio)). 1676 1677:- thread_local(owl/4). 1678:- thread_local(owl/3). 1679:- thread_local(owl/2). 1680:- dynamic owl/2.
1686:- thread_local(blanknode/3). 1687:- thread_local(outstream/1). 1688 1689:- thread_local(aNN/3). % implements the ANN(X) function. 1690:- thread_local(annotation_r_node/4). % annotation_r_node(S,P,O,Node) 1691:- thread_local(axiom_r_node/4). % axiom_r_node(S,P,O,Node) 1692:- thread_local(owl_repository/2). % implements a simple OWL repository: if URL not found, Ontology is read from a repository (local) RURL 1693 1694 1695% we make this discontiguous so that the code can follow the structure of the document as much as possible 1696 1697:- discontiguous owl_parse_axiom/4. 1698:- discontiguous dothislater/1. 1699 1700% hookable 1701 1702 1703% ----------------------------------------------------------------------- 1704% UTILITY Predicates 1705% -----------------------------------------------------------------------
1713owl_clear_as :- 1714 debug(owl_parser,'Clearing abstract syntax',[]), 1715 forall((axiompred(PredSpec),predspec_head(PredSpec,Head)), 1716 retractall(Head)). 1717 1718predspec_head(Pred/A,Head) :- functor(Head,Pred,A). 1719 1720u_assert(M,Term) :- 1721 call(M:Term), !; assert(M:). 1722 1723 1724convert(T,V,typed_value(T,V)).
1733rdf_2_owl(M,Ont) :- 1734 debug(owl_parser, 'Removing existing owl triples',[]), 1735% retractall(owl(_,_,_,Ont)), 1736 debug(owl_parser,'Copying RDF triples to OWL triples for Ontology ~w',[Ont]), 1737 M:rdf(X,Y,Z), 1738 assert(M:owl(X,Y,Z,Ont)), fail. 1739 1740rdf_2_owl(M,Ont) :- 1741 owl_count(M,Ont,Z), 1742 debug(owl_parser,'Number of owl triples copied: ~w',[Z]).
1748owl_count(M,O,U) :-
1749 findall(1,M:owl(_,_,_,O),X), length(X,U).owl(S,P,O,not_used) after expanding namespaces.
this is required for the triple replacement rules,
which use shortened rdfs/owl namespaces.
(or we could just use the expanded forms here which
may be faster..)
1758expand_and_assert(M,X1,Y1,Z1) :-
1759 expand_ns(X1,X),
1760 expand_ns(Y1,Y),
1761 expand_ns(Z1,Z),!,
1762 retractall(M:owl(X,Y,Z, used1)),
1763 assert(M:owl(X,Y,Z, not_used)).owl(S,P,O)
in Triples has a non-ground variable then this will succeed
non-deterministically. If all variables are ground, then this
will succeed semi-deterministically.1772test_use_owl(_M,[]). 1773test_use_owl(M,[owl(S,P,O)|Rest]) :- 1774 test_use_owl(M,S,P,O), 1775 test_use_owl(M,Rest).
If any of S, P or O is non-ground then this will succeed non-deterministically. If all variables are ground, then this will succeed semi-deterministically.
1784test_use_owl(M,X1,Y1,Z1) :- 1785 expand_ns(X1,X), 1786 expand_ns(Y1,Y), 1787 expand_ns(Z1,Z),!, 1788 M:owl(X,Y,Z, not_used). 1789 1790test_use_owl(M,X1,Y1,Z1,named) :- 1791 expand_ns(X1,X), 1792 expand_ns(Y1,Y), 1793 expand_ns(Z1,Z), 1794 M:owl(X,Y,Z, not_used), 1795 \+ sub_string(X,0,1,_,'_').
1801use_owl(M,Triples) :- 1802 test_use_owl(M,Triples), 1803 use_owl_2(M,Triples). 1804 1805% consume all triples; we have already tested the list and know that all match 1806use_owl_2(_M,[]). 1807use_owl_2(M,[owl(S,P,O)|Triples]) :- 1808 use_owl(M,S,P,O), 1809 use_owl_2(M,Triples). 1810 1811 1812use_owl(M,X1,Y1,Z1) :- 1813 expand_ns(X1,X), 1814 expand_ns(Y1,Y), 1815 expand_ns(Z1,Z), 1816 M:owl(X,Y,Z, not_used), 1817 debug(owl_parser_detail,'using ~w ~w ~w',[X,Y,Z]), 1818 retract(M:owl(X,Y,Z, not_used)), 1819 assert(M:owl(X,Y,Z,used1)). 1820 1821use_owl(M,X1,Y1,Z1,named) :- 1822 expand_ns(X1,X), 1823 expand_ns(Y1,Y), 1824 expand_ns(Z1,Z), 1825 M:owl(X,Y,Z, not_used), 1826 \+ sub_string(X,0,1,_,'_'), 1827 retract(M:owl(X,Y,Z, not_used)), 1828 assert(M:owl(X,Y,Z,used2)). 1829 1830use_owl(M,X1,Y1,Z1,Term) :- 1831 expand_ns(X1,X), 1832 expand_ns(Y1,Y), 1833 expand_ns(Z1,Z), 1834 M:owl(X,Y,Z, not_used), 1835 debug(owl_parser_detail,'using ~w ~w ~w',[X,Y,Z]), 1836 retract(M:owl(X,Y,Z, not_used)), 1837 assert(M:owl(X,Y,Z,used(Term))).
1844use_owl(M,X1,Y1,Z1,named,Term) :-
1845 expand_ns(X1,X),
1846 expand_ns(Y1,Y),
1847 expand_ns(Z1,Z),
1848 M:owl(X,Y,Z, not_used),
1849 \+ sub_string(X,0,1,_,'_'),
1850 retract(M:owl(X,Y,Z, not_used)),
1851 assert(M:owl(X,Y,Z,used(Term))).1858expand_ns(NS_URL, Full_URL) :- 1859 nonvar(NS_URL), 1860 NS_URL \= literal(_), 1861 uri_split(NS_URL,Short_NS,Term, ':'), 1862 rdf_db:ns(Short_NS,Long_NS),!, 1863 concat_atom([Long_NS,Term],Full_URL). 1864 1865expand_ns(URL, URL).
no_base(ShortNs): Use only term!1878collapse_ns(FullURL, NSURL,Char,Options) :- 1879 nonvar(FullURL), 1880 FullURL \= literal(_), 1881 uri_split(FullURL,LongNS, Term, '#'), 1882 concat(LongNS,'#',LongNS1), 1883 rdf_db:ns(ShortNS,LongNS1), 1884 ( member(no_base(ShortNS),Options), ! , NSURL = Term 1885 ; 1886 concat_atom([ShortNS,Char,Term],NSURL) 1887 ),!. 1888% CJM 1889collapse_ns(FullURL, NSURL,_Char,Options) :- 1890 nonvar(FullURL), 1891 \+ FullURL = literal(_), 1892 uri_split(FullURL,LongNS, Term, '#'), 1893 member(no_base(LongNS),Options), 1894 !, 1895 NSURL = Term. 1896 1897 1898collapse_ns(URL, URL,_,_).
concat(Namespace,Split_Char,Term)
1908uri_split(URI,Namespace,Term,Split_Char) :-
1909 sub_atom(URI,Start,_,After,Split_Char),
1910 sub_atom(URI,0,Start,_,Namespace),
1911 Start1 is Start + 1,
1912 sub_atom(URI,Start1,After,_,Term).1917% Appends Node to the InList, and recursively, all other 1918% Nodes that are linked with the Predicate to the Node. The 1919% result is returned to OutList. 1920 1921owl_collect_linked_nodes(Node,Predicate,InList,OutList) :- 1922 get_module(M), 1923 use_owl(M,Node,Predicate,A),!, 1924 owl_collect_linked_nodes(Node,Predicate,InList,List1), 1925 owl_collect_linked_nodes(A,Predicate,List1,OutList). 1926 1927owl_collect_linked_nodes(Node,Predicate,InList,OutList) :- 1928 get_module(M), 1929 use_owl(M,A,Predicate,Node),!, 1930 owl_collect_linked_nodes(Node,Predicate,InList,List1), 1931 owl_collect_linked_nodes(A,Predicate,List1,OutList). 1932 1933owl_collect_linked_nodes(Node,_,List, [Node|List]) :- 1934 \+ memberchk(Node, List),!. 1935 1936owl_collect_linked_nodes(_,_,List, List) :- !. 1937 1938 1939% ---------------------------------------------------------------- 1940% OWL Parser implementation predicates 1941% ----------------------------------------------------------------
blanknode(Node,Description,used) term.
The purpose is to record when a blank node has been used, so
subsequent uses of it will result in structure sharing.1951owl_get_bnode(M,Node,Description) :- 1952 sub_string(Node,0,1,_,'_'),!, 1953 \+ M:blanknode(Node,_,_), 1954 assert(M:blanknode(Node,Description, used)). 1955 1956owl_get_bnode(_,_,_). 1957 1958 1959 1960% ----------------------------------------------------------------------- 1961% Top Level Predicates 1962% ----------------------------------------------------------------------- 1963 1964/* 1965%% owl_parse(+URL, +RDF_Load_Mode, +OWL_Parse_Mode, +ImportFlag:boolean) 1966% 1967% Top level: parse a set of RDF triples and produce an 1968% AS representation of an OWL ontology. 1969% 1970% Calls the rdf_load_stream predicate to parse RDF stream in URL. 1971% If RDF_Load_Mode = complete it first retacts all rdf triples. 1972% If ImportFlag = true it handles owl:import clause at RDF level. 1973% 1974% This implements the mapping defined here: 1975% http://www.w3.org/TR/2008/WD-owl2-mapping-to-rdf-20081202/ 1976owl_parse(URL, RDF_Load_Mode, OWL_Parse_Mode,ImportFlag) :- 1977 ( RDF_Load_Mode=complete 1978 -> rdf_retractall(_,_,_), retractall(rdf_db:rdf_source(_,_,_,_)) 1979 ; true), 1980 ( OWL_Parse_Mode=complete 1981 -> owl_clear_as,retractall(blanknode(_,_,_)), retractall(owl(_,_,_,_)) 1982 ; true), 1983 !, 1984 debug(owl_parser,'Loading stream ~w',[URL]), 1985 owl_canonical_parse_2([URL],URL,ImportFlag,[],ProcessedIRIs), 1986 debug(owl_parser,'rdf_db populated, the following IRIs were processed: ~w',[ProcessedIRIs]), 1987 utility_translation_init, 1988 owl_canonical_parse_3(ProcessedIRIs). 1989 1990 1991%% owl_canonical_parse_2(+IRIs:list,+ParentIRI,+ImportFlag:boolean,+ProcessedURIsIn:list,?ProcessedURIsOut:list) is det 1992% recursively parses all ontologies in IRIs into rdf_db, ensuring none are processed twice. 1993owl_canonical_parse_2([],_,_,Processed,Processed) :- !. 1994 1995owl_canonical_parse_2([IRI|ToProcessRest],Parent,ImportFlag,ProcessedIn,ProcessedOut) :- 1996 member(IRI,ProcessedIn), 1997 !, 1998 owl_canonical_parse_2(ToProcessRest,Parent,ImportFlag,ProcessedIn,ProcessedOut). 1999 2000owl_canonical_parse_2([IRI|ToProcessRest],Parent,ImportFlag,ProcessedIn,ProcessedOut) :- 2001 % Get rdf triples, *Ontology* and Imports 2002 rdf_load_stream(IRI,O,BaseURI,Imports), 2003 ( nonvar(O) 2004 -> Ont = O 2005 ; Ont = Parent), % in the include case we may need to remove the import... 2006 debug(owl_parser,'Commencing rdf_2_owl. Generating owl/4',[]), 2007 rdf_2_owl(BaseURI,Ont), % move the RDF triples into the owl-Ont/4 facts 2008 ( ImportFlag = true 2009 -> owl_canonical_parse_2(Imports,Ont,ImportFlag,[Ont|ProcessedIn],ProcessedIn1) 2010 ; ProcessedIn1=[Ont|ProcessedIn]), 2011 owl_canonical_parse_2(ToProcessRest,Parent,ImportFlag,ProcessedIn1,ProcessedOut). 2012*/
2022owl_canonical_parse_3(_,[]). 2023 2024owl_canonical_parse_3(M,[IRI|Rest]) :- 2025 % Remove any existing not used owl fact 2026 retractall(M:owl(_,_,_,not_used)), 2027 % Copy the owl facts of the IRI document to the 'not_used' 2028 forall(M:owl(S,P,O,IRI),assert(M:owl(S,P,O,not_used))), 2029 2030 debug(owl_parser,'Anon individuals in reification [see table 8]',[]), 2031 2032 collect_r_nodes(M), 2033 2034 % Removed 2035 %forall(M:axiom_r_node(S,P,O,_Node),assert(M:owl(S,P,O,not_used))), 2036 2037 % First parse the Ontology axiom 2038 owl_parse_annotated_axioms(M,ontology/1), 2039 2040 debug(owl_parser,'Replacing patterns [see table 5]',[]),%QUA 2041 % remove triples based on pattern match (Table 5) 2042 ( forall((triple_remove(Pattern,Remove), test_use_owl(M,Pattern)), 2043 forall(member(owl(S,P,O),Remove),use_owl(M,S,P,O,removed))) -> true ; true), 2044 2045 2046 % temporary fix to make up for bug in rdf parsing 2047 % see email to JanW July-1-2009 2048 forall((test_use_owl(M,S,P,BNode), 2049 atom(BNode), 2050 sub_atom(BNode,0,1,_,'_'), 2051 test_use_owl(M,BNode,'http://www.w3.org/1999/02/22-rdf-syntax-ns#datatype',literal(_))), 2052 ( use_owl(M,S,P,BNode,datatype_fix), 2053 use_owl(M,BNode,'http://www.w3.org/1999/02/22-rdf-syntax-ns#datatype',literal(_)), 2054 expand_and_assert(M,S,P,literal('')))), 2055 2056 % replace matched patterns (Table 6) 2057 debug(owl_parser,'Replacing patterns [see table 6]',[]), 2058 ( setof(ReplaceWith, 2059 Pattern^( triple_replace(Pattern,ReplaceWith), % +Triples:list, ?Triples:list 2060 use_owl(M,Pattern), 2061 debug(owl_parser,'Replacing ~w ==> ~w [see table 6]',[Pattern,ReplaceWith])), 2062 ReplacementSetList) 2063 -> forall((member(ReplacementSet,ReplacementSetList),member(owl(S,P,O),ReplacementSet)), 2064 expand_and_assert(M,S,P,O)) 2065 ; debug(owl_parser,'No replacements required',[])), 2066 2067 /* 2068 forall(triple_replace(Pattern,ReplaceWith), 2069 forall(use_owl(M,Pattern), 2070 forall(member(owl(S,P,O),ReplaceWith), 2071 ( expand_and_assert(M,S,P,O), 2072 debug(owl_parser,'Replacing ~w ==> ~w [see table 6]',[Pattern,owl(S,P,O)]))))), 2073 */ 2074 2075 % continue with parsing using the rules... 2076 % Table 8, get the set of RIND - anonymous individuals in reification 2077 findall(X, (member(Y,['owl:Axiom','owl:Annotation', 2078 'owl:AllDisjointClasses','owl:AllDisjointProperties', 2079 'owl:AllDifferent','owl:NegativePropertyAssertion']), 2080 test_use_owl(M,X,'rdf:type',Y) 2081 ), 2082 RIND), 2083 set_trdf(rind,RIND), 2084 2085 % Table 9, row 5 2086 % VV 10/3/2010 get the annotation properties before collecting the annotations. 2087 debug(owl_parser,'asserting annotationProperty/1 for all APs',[]), 2088 forall( test_use_owl(M,D,'rdf:type','owl:AnnotationProperty'), 2089 assert_axiom(M,annotationProperty(D))), 2090 2091 % TODO - make this faster 2092 debug(owl_parser,'Implements function ANN(x) 3.2.2 Table 10.',[]), 2093 findall(_,ann(M,_,_),_), % find all annotations, assert annotation(X,AP,AV) axioms. 2094 2095 debug(owl_parser,'Commencing parse of annotated axioms',[]), 2096 forall((axiompred(PredSpec),\+dothislater(PredSpec),\+omitthis(PredSpec)), 2097 owl_parse_annotated_axioms(M,PredSpec)), 2098 forall((axiompred(PredSpec),dothislater(PredSpec),\+omitthis(PredSpec)), 2099 owl_parse_annotated_axioms(M,PredSpec)), 2100 2101 % annotated complex axioms, s.a., equivalentClasses([a,intersectionOf(..)]) that are 2102 % seen in axiom_r_node as axiom_r_node(a,intersectionOf,_:DescriptionX,_:DescriptionY) 2103 2104 2105 2106 debug(owl_parser_detail,'Commencing parse of unannotated axioms',[]), 2107 forall((axiompred(PredSpec),\+dothislater(PredSpec),\+omitthis(PredSpec)), 2108 owl_parse_nonannotated_axioms(M,PredSpec)), 2109 forall((axiompred(PredSpec),dothislater(PredSpec),\+omitthis(PredSpec)), 2110 owl_parse_nonannotated_axioms(M,PredSpec)),!, 2111 2112 % annotation Assertion 2113 parse_annotation_assertions(M), 2114 forall(owl_parse_compatibility_DL(M,Axiom),assert_axiom(M,Axiom)), 2115 owl_canonical_parse_3(M,Rest). 2116 2117omitthis(ontology/1). 2118 2119 2120owl_parse_annotated_axioms(M,Pred/Arity) :- 2121 debug(owl_parser_detail,'[ann] Parsing all of type: ~w',[Pred]), 2122 functor(Head,Pred,Arity), 2123% forall(owl_parse_axiom(M,Mod:Head), 2124% ( debug(owl_parser_detail,' parsed: [~w] ~w',[Mod,Head]), 2125% assert(Mod:Head))). 2126 forall(owl_parse_axiom(M,Head,true,Annotations), 2127 ( assert_axiom(M,Head), 2128 debug(owl_parser_detail_anns,' parsed: ~w : anns: ~w',[Head,Annotations]), 2129 forall(member(X,Annotations), 2130 forall(M:aNN(X,AP,AV), 2131 assert_axiom(M,annotation(Head,AP,AV)) 2132 ) 2133 ) 2134 ) 2135 ), 2136 debug(owl_parser_detail,'[ann] Done parsing all of type: ~w',[Pred]). 2137 2138owl_parse_nonannotated_axioms(M,Pred/Arity) :- 2139 debug(owl_parser_detail,'[unann] Parsing all of type: ~w',[Pred]), 2140 functor(Head,Pred,Arity), 2141 forall(owl_parse_axiom(M,Head,false,_), 2142 assert_axiom(M,Head) 2143 ).
If owl_repository/2 is defined, then this is used to map URLs prior to loading.
2159rdf_load_stream(URL,Ontology,BaseURI,Imports) :- 2160 owl_repository(URL,RURL), 2161 !, 2162 % note: users responsibility to avoid infinite loops by avoid cycles in repository mappings! 2163 rdf_load_stream(RURL,Ontology,BaseURI,Imports). 2164 2165rdf_load_stream(URL,Ontology,BaseURI,Imports) :- 2166 BaseURI = URL, 2167 ( sub_atom(URL,0,4,_,'http') 2168 -> catch((http_open(URL,RDF_Stream,[]), 2169 rdf_load(RDF_Stream,[if(true),base_uri(BaseURI),blank_nodes(noshare), 2170 result(Action, Triples, MD5),register_namespaces(true)]), 2171 debug(owl_parser,' Loaded ~w stream: ~w Action: ~w Triples:~w MD5: ~w',[URL,RDF_Stream,Action,Triples,MD5]), 2172 close(RDF_Stream)), 2173 Message, 2174 throw(io_error(URL,'rdf_load/2 failed',Message))) % re-throw with more information 2175 ; RDF_Stream = URL, rdf_load(RDF_Stream,[blank_nodes(noshare),if(true),base_uri(BaseURI),register_namespaces(true)]) 2176 ), 2177 % collect all imports directives 2178 ( rdf(Ontology,'http://www.w3.org/1999/02/22-rdf-syntax-ns#type','http://www.w3.org/2002/07/owl#Ontology',BaseURI:_) 2179 -> findall(I,rdf(Ontology,'http://www.w3.org/2002/07/owl#imports',I,BaseURI:_),Imports) 2180 ; Imports = [] 2181 ). 2182 2183 2184 2185% ---------------------------------------------------------------- 2186% 3 Mapping from RDF Graphs to the Structural Specification 2187% ---------------------------------------------------------------- 2188 2189/* 2190 2191 This section specifies the results of steps CP-2.2 and CP-3.3 of the 2192 canonical parsing process from Section 3.6 of the OWL 2 2193 Specification [OWL 2 Specification] on an ontology document D that 2194 can be parsed into an RDF graph G. ... 2195 2196 */ 2197 2198% owl_description_list(+Module,+Node, -List) 2199% 2200% If +Node is defined as rdf:type rdf:List, then List returns 2201% a prolog list of descriptions for this Node. 2202 2203owl_description_list(_M,'http://www.w3.org/1999/02/22-rdf-syntax-ns#nil',[]) :- !. 2204 2205owl_description_list(M,X,[F|R]) :- 2206 % use_owl(M,X,'rdf:type','rdf:List',list), % this is now removed from graph 2207 use_owl(M,X,'rdf:first',Element,first), 2208 owl_description(M,Element,F), 2209 use_owl(M,X,'rdf:rest',Y,rest), 2210 !,owl_description_list(M,Y,R). 2211 2212 2213% owl_individual_list(+Module,+Node, -List) 2214% 2215% If +Node is defined as rdf:type rdf:List, then List returns 2216% a prolog list of individuals for this Node. 2217 2218owl_individual_list(_M,'http://www.w3.org/1999/02/22-rdf-syntax-ns#nil',[]) :- !. 2219 2220owl_individual_list(M,X,[F|R]) :- 2221 % use_owl(M,X,'rdf:type','rdf:List',list), % this is now removed from graph 2222 use_owl(M,X,'rdf:first',F,first), 2223 use_owl(M,X,'rdf:rest',Y,rest), 2224 !,owl_individual_list(M,Y,R). 2225 2226% owl_property_list(+Module,+Node, -List) 2227% 2228% If +Node is defined as rdf:type rdf:List, then List returns 2229% a prolog list of properties for this Node. 2230 2231owl_property_list(_M,'http://www.w3.org/1999/02/22-rdf-syntax-ns#nil',[]) :- !. 2232 2233owl_property_list(M,X,[F|R]) :- 2234 % use_owl(M,X,'rdf:type','rdf:List',list), % this is now removed from graph 2235 use_owl(M,X,'rdf:first',Element,first), 2236 owl_property_expression(M,Element,F), 2237 use_owl(M,X,'rdf:rest',Y,rest), 2238 !,owl_property_list(M,Y,R). 2239 2240% owl_datarange_list(+Module,+Node, -List) 2241% 2242% If +Node is defined as rdf:type rdf:List, then List returns 2243% a prolog list of dataranges for this Node. 2244 2245owl_datarange_list(_,'http://www.w3.org/1999/02/22-rdf-syntax-ns#nil',[]) :- !. 2246 2247owl_datarange_list(M,X,[F|R]) :- 2248 % use_owl(M,X,'rdf:type','rdf:List',list), % this is now removed from graph 2249 use_owl(M,X,'rdf:first',Element,first), 2250 owl_datarange(M,Element,F), 2251 use_owl(M,X,'rdf:rest',Y,rest), 2252 !,owl_datarange_list(M,Y,R). 2253 2254% owl_datatype_restriction_list(+Node, -List) 2255% 2256% If +Node is defined as rdf:type rdf:List, then List returns 2257% a prolog list of datatype restrictions for this Node. 2258 2259owl_datatype_restriction_list('http://www.w3.org/1999/02/22-rdf-syntax-ns#nil',[]) :- !. 2260 2261owl_datatype_restriction_list(X,[facetRestriction(W2,L)|R]) :- 2262 % use_owl(M,X,'rdf:type','rdf:List'), % this is now removed from graph 2263 use_owl(M,X,'rdf:first',Element,first_datatype_restr), 2264 use_owl(M,Element,W,L,datatype_restr), 2265 ( concat_atom([_,W2],'#',W) 2266 -> true 2267 ; W2=W), 2268 use_owl(M,X,'rdf:rest',Y,rest_datatype_restr), 2269 !,owl_datatype_restriction_list(Y,R). 2270 2271 2272% 3.1 Extracting Declarations and the IRIs of the Directly Imported Ontology Documents 2273% This section specifies the result of step CP-2.2 of the canonical parsing process on an RDF graph G 2274 2275 2276% 3.1.2 Parsing of the Ontology Header and Declarations 2277 2278% Table 4. 2279owl_parse_axiom(M,ontology(O),AnnMode,List) :- 2280 test_use_owl(M,O,'rdf:type','owl:Ontology'), 2281 \+ test_use_owl(M,[owl(U,_W,O),owl(U,'rdf:type','owl:Ontology')]), 2282 valid_axiom_annotation_mode(AnnMode,M,O,'rdf:type','owl:Ontology',List), 2283 use_owl(M,O,'rdf:type','owl:Ontology',ontology), 2284 set_trdf(current_ontology,O), 2285 forall(use_owl(M,O,'owl:imports',IRI,ontology_import), assert_axiom(M,ontologyImport(O,IRI))), 2286 forall(use_owl(M,O,'owl:versionInfo',IRI2,ontology_version_info), assert_axiom(M,ontologyVersionInfo(O,IRI2))),!. % Do Once 2287 2288 2289% See table 5. 2290% triple_remove(Pattern:list,Remove:list) 2291% if Pattern is present, remove triples in Remove 2292triple_remove([owl(X,'rdf:type','owl:Ontology')],[owl(X,'rdf:type','owl:Ontology')]). 2293triple_remove([owl(X,'rdf:type','owl:Class'),owl(X,'rdf:type','rdfs:Class')],[owl(X,'rdf:type','rdfs:Class')]). 2294triple_remove([owl(X,'rdf:type','rdfs:Datatype'),owl(X,'rdf:type','rdfs:Class')],[owl(X,'rdf:type','rdfs:Class')]). 2295triple_remove([owl(X,'rdf:type','owl:DataRange'),owl(X,'rdf:type','rdfs:Class')],[owl(X,'rdf:type','rdfs:Class')]). 2296triple_remove([owl(X,'rdf:type','owl:Restriction'),owl(X,'rdf:type','rdfs:Class')],[owl(X,'rdf:type','rdfs:Class')]). 2297triple_remove([owl(X,'rdf:type','owl:Restriction'),owl(X,'rdf:type','owl:Class')],[owl(X,'rdf:type','owl:Class')]). 2298triple_remove([owl(X,'rdf:type','owl:ObjectProperty'),owl(X,'rdf:type','rdf:Property')],[owl(X,'rdf:type','rdf:Property')]). 2299triple_remove([owl(X,'rdf:type','owl:FunctionalProperty'),owl(X,'rdf:type','rdf:Property')],[owl(X,'rdf:type','rdf:Property')]). 2300triple_remove([owl(X,'rdf:type','owl:InverseFunctionalProperty'),owl(X,'rdf:type','rdf:Property')],[owl(X,'rdf:type','rdf:Property')]). 2301triple_remove([owl(X,'rdf:type','owl:TransitiveProperty'),owl(X,'rdf:type','rdf:Property')],[owl(X,'rdf:type','rdf:Property')]). 2302triple_remove([owl(X,'rdf:type','owl:DatatypeProperty'),owl(X,'rdf:type','rdf:Property')],[owl(X,'rdf:type','rdf:Property')]). 2303triple_remove([owl(X,'rdf:type','owl:AnnotationProperty'),owl(X,'rdf:type','rdf:Property')],[owl(X,'rdf:type','rdf:Property')]). 2304triple_remove([owl(X,'rdf:type','owl:OntologyProperty'),owl(X,'rdf:type','rdf:Property')],[owl(X,'rdf:type','rdf:Property')]). 2305triple_remove([owl(X,'rdf:type','rdf:List'),owl(X,'rdf:first',_Y),owl(X,'rdf:rest',_Z)],[owl(X,'rdf:type','rdf:List')]). 2306/* 2307 triple_remove([owl(X,'rdf:type','owl:Thing')],[owl(X,'rdf:type','owl:Thing')]). 2308*/ 2309% See table 6. 2310% http://www.w3.org/TR/2008/WD-owl2-mapping-to-rdf-20081202/ 2311triple_replace([owl(X,'rdf:type','owl:OntologyProperty')],[owl(X,'rdf:type','owl:AnnotationProperty')]). 2312triple_replace([owl(X,'rdf:type','owl:InverseFunctionalProperty')],[owl(X,'rdf:type','owl:ObjectProperty'),owl(X,'rdf:type','owl:InverseFunctionalProperty')]). 2313triple_replace([owl(X,'rdf:type','owl:TransitiveProperty')],[owl(X,'rdf:type','owl:ObjectProperty'),owl(X,'rdf:type','owl:TransitiveProperty')]). 2314triple_replace([owl(X,'rdf:type','owl:SymmetricProperty')],[owl(X,'rdf:type','owl:ObjectProperty'),owl(X,'rdf:type','owl:SymmetricProperty')]). 2315 2316% NOTE: this is not specified in table 6. However, we treat rdfs:Classes as equivalent to owl:Classes 2317triple_replace([owl(X,'rdf:type','rdfs:Class')],[owl(X,'rdf:type','owl:Class')]). 2318 2319% DECLARATIONS 2320% 2321% See table 7. 2322% http://www.w3.org/TR/2008/WD-owl2-mapping-to-rdf-20081202/
2328owl_parse_axiom(M,class(C),AnnMode,List) :- 2329 test_use_owl(M,C,'rdf:type','owl:Class'), 2330 valid_axiom_annotation_mode(AnnMode,M,C,'rdf:type','owl:Class',List), 2331 ( use_owl(M,C,'rdf:type','owl:Class',named,class(C)) -> true ; use_owl(M,C,'rdf:type','rdfs:Class',named,class(C))), 2332 \+ M:class(C). 2333 2334 2335owl_parse_axiom(M,datatype(D), AnnMode, List) :- 2336 test_use_owl(M,D,'rdf:type','rdf:Datatype'), 2337 valid_axiom_annotation_mode(AnnMode,M,D,'rdf:type','rdf:Datatype',List), 2338 use_owl(M,D,'rdf:type','rdf:Datatype',datatype(D)). 2339 2340 2341owl_parse_axiom(M,objectProperty(D), AnnMode, List) :- 2342 test_use_owl(M,D,'rdf:type','owl:ObjectProperty'), 2343 valid_axiom_annotation_mode(AnnMode,M,D,'rdf:type','owl:ObjectProperty',List), 2344 use_owl(M,D,'rdf:type','owl:ObjectProperty',objectProperty(D)), 2345 \+ M:objectProperty(D). 2346 2347 2348% note the difference in names between syntax and rdf 2349owl_parse_axiom(M,dataProperty(D), AnnMode, List) :- 2350 test_use_owl(M,D,'rdf:type','owl:DatatypeProperty'), 2351 valid_axiom_annotation_mode(AnnMode,M,D,'rdf:type','rdf:DatatypeProperty',List), 2352 use_owl(M,D,'rdf:type','owl:DatatypeProperty',dataProperty(D)), 2353 \+ M:dataProperty(D). 2354 2355owl_parse_axiom(M,annotationProperty(D), AnnMode, List) :- 2356 test_use_owl(M,D,'rdf:type','owl:AnnotationProperty'), 2357 valid_axiom_annotation_mode(AnnMode,M,D,'rdf:type','rdf:AnnotationProperty',List), 2358 use_owl(M,D,'rdf:type','owl:AnnotationProperty',annotationProperty(D)), 2359 \+ M:annotationProperty(D). 2360 2361 2362% TODO: check this. do we need to assert individual axioms if all we have is an rdf:type? 2363owl_parse_axiom(M,namedIndividual(D), AnnMode, List) :- 2364 test_use_owl(M,D,'rdf:type','owl:NamedIndividual'), 2365 valid_axiom_annotation_mode(AnnMode,M,D,'rdf:type','rdf:NamedIndividual',List), 2366 use_owl(M,D,'rdf:type','owl:NamedIndividual',namedIndividual(D)). 2367 2368 2369% Table 8. Identifying Anonymous Individuals in Reification 2370% TODO 2371 2372 2373% 3.2 Populating an Ontology 2374 2375 2376% 3.2.1 Analyzing Declarations 2377 2378% 3.2.2 Parsing of Annotations 2379 2380% 2381% ann(+Module,?X, -Extension List) 2382% 2383% Implements function ANN(x) 3.2.2 Table 10 2384% 2385% The annotations in G are parsed next. The function ANN assigns a 2386% set of annotations ANN(x) to each IRI or blank node x. This 2387% function is initialized by setting ANN(x) = a.. for each each IRI 2388% or blank node x. Next, the triple patterns from Table 10 are 2389% matched in G and, for each matched pattern, ANN(x) is extended 2390% with an annotation from the right column. Each time one of these 2391% triple patterns is matched, the matched triples are removed from 2392% G. This process is repeated until no further matches are 2393% possible 2394 2395ann(M,X,Y) :- 2396 ann(M,X,X,Y). 2397 2398 2399 2400ann(M,X,X1, annotation(X1,Y,Z)) :- 2401 M:annotationProperty(Y), 2402 debug(owl_parser_detail,'annotation property: ~w',[Y]), 2403 M:owl(X,Y,Z,not_used), 2404 use_owl(M,X,Y,Z,annotationProperty(Y)), 2405 u_assert(M,aNN(X1,Y,Z)), 2406 ann2(M,X,Y,Z,X1). 2407 2408 2409ann2(M,X,Y,Z,X1) :- 2410 M:annotation_r_node(X,Y,Z,W), 2411 ann(M,W,annotation(X1,Y,Z),Term), 2412 u_assert(M,Term). 2413 2414ann2(M,X,Y,Z,X1) :- 2415 M:axiom_r_node(X,Y,Z,W), 2416 ann(M,W,annotation(X1,Y,Z),Term), 2417 u_assert(M,Term). 2418 2419 2420ann2(_,_,_,_,_). 2421 2422 2423% 3.2.4 Parsing of Expressions 2424 2425is_bnode(C) :- 2426 atom(C), 2427 sub_atom(C,0,1,_,'_'). 2428 2429 2430 % Table 11. Parsing Object Property Expressions 2431owl_property_expression(_M,C,C) :- 2432 \+ is_bnode(C), % better: IRI(C). 2433 % VV added 10/3/2011 2434 C\='http://www.w3.org/1999/02/22-rdf-syntax-ns#first', 2435 C\='http://www.w3.org/1999/02/22-rdf-syntax-ns#rest', 2436 !. 2437 2438owl_property_expression(M,C,D) :- 2439 M:blanknode(C,D,Use), 2440 ( Use = used, 2441 retractall(M:blanknode(C,D,used)), 2442 assert(M:blanknode(C,D,shared)) 2443 ; 2444 true). 2445 2446owl_property_expression(M,P,inverseOf(Q)) :- 2447 use_owl(M,P,'owl:inverseOf',Q,inverseof(P,Q)), 2448 owl_get_bnode(M,P,inverseOf(Q)). 2449 2450 2451% Table 12. Parsing of Data Ranges 2452 2453owl_datarange(_M,D,D) :- 2454 \+ is_bnode(D),!. % better: IRI(C). 2455 2456owl_datarange(M,C,D) :- 2457 M:blanknode(C,D,Use), 2458 ( Use = used, 2459 retractall(M:blanknode(C,D,used)), 2460 assert(M:blanknode(C,D,shared)) 2461 ; 2462 true). 2463 2464owl_datarange(M,D,intersectionOf(L)) :- 2465 use_owl(M,D,'rdf:type','rdfs:Datatype',datarange(D)), 2466 use_owl(M,D,'owl:intersectionOf',Y,datarange(D)), 2467 %print(D-inter-Y),nl, 2468 owl_datarange_list(M,Y,L), 2469 owl_get_bnode(M,D,intersectionOf(L)). 2470 2471owl_datarange(M,D,unionOf(L)) :- 2472 use_owl(M,D,'rdf:type','rdfs:Datatype',datarange(D)), 2473 use_owl(M,D,'owl:unionOf',Y,datarange(D)), 2474 owl_datarange_list(M,Y,L), 2475 owl_get_bnode(M,D,unionOf(L)). 2476 2477 2478owl_datarange(M,D,complementOf(DY)) :- 2479 use_owl(M,D,'rdf:type','rdfs:Datatype',dataRange(D)), 2480 use_owl(M,D,'owl:datatypeComplementOf',Y,datacomplement(D)), 2481 owl_datarange(M,Y,DY), 2482 owl_get_bnode(M,D,complementOf(DY)). 2483 2484% Table 14, case 2 2485 owl_datarange(M,D,complementOf('rdfs:Literal')) :- 2486 use_owl(M,D,'rdf:type','rdfs:DataRange',dataRange(D)), 2487 use_owl(M,D,'owl:oneOf',[],oneOf(D)), 2488 owl_get_bnode(M,D,complementOf('rdfs:Literal')). 2489 2490owl_datarange(M,D,oneOf(L)) :- 2491 use_owl(M,D,'rdf:type','rdfs:Datatype',dataType(D)), 2492 use_owl(M,D,'owl:oneOf',L1,oneOf(D)), 2493 owl_individual_list(M,L1,L), 2494 owl_get_bnode(M,D,oneOf(L)). 2495 2496% Table 14, case 1 2497owl_datarange(M,D,oneOf(L)) :- 2498 use_owl(M,D,'rdf:type','rdfs:DataRange',datarange(D)), 2499 use_owl(M,D,'owl:oneOf',L1,datarange(D)), 2500 owl_individual_list(M,L1,L), 2501 owl_get_bnode(M,D,oneOf(L)). 2502 2503 2504owl_datarange(M,D,datatypeRestriction(DY,L)) :- 2505 use_owl(M,D,'rdf:type','rdfs:Datatype',datarange(D)), 2506 use_owl(M,D,'owl:onDatatype',Y,datarange(D)), 2507 owl_datarange(M,Y,DY), 2508 use_owl(M,D,'owl:withRestrictions',L1,datarange(D)), 2509 owl_datatype_restriction_list(L1,L), 2510 owl_get_bnode(M,D,datatypeRestriction(DY,L)). 2511 2512% Table 13. Parsing of Class Expressions 2513 2514% ---------------------------------------------------------------------- 2515% owl_description(+Module,+Node,-Description). 2516% 2517% It implements OWL AS production rules for Descriptions. 2518% During the construction of the Description any blank node 2519% is recorded for later structure sharing checks. 2520 2521owl_description(_M,C,C) :- 2522 \+ is_bnode(C),!. % better: IRI(C). 2523 2524 2525owl_description(M,C,D) :- 2526 M:blanknode(C,D,Use), 2527 ( Use = used, 2528 retractall(M:blanknode(C,D,used)), 2529 assert(M:blanknode(C,D,shared)) 2530 ; 2531 true),!. 2532 2533% TODO: this leaves behind classAssertions of type owlClass for the bnodes 2534owl_description(M,D,intersectionOf(L)) :- 2535 use_owl(M,D,'owl:intersectionOf',L1,intersectionOf(D)), 2536 owl_description_list(M,L1,L), 2537 \+L = [], 2538 owl_get_bnode(M,D,intersectionOf(L)),!. 2539 2540owl_description(M,D,unionOf(L)) :- 2541 use_owl(M,D,'owl:unionOf',L1,union(D)), 2542 owl_description_list(M,L1,L), 2543 owl_get_bnode(M,D,unionOf(L)),!. 2544 2545 2546owl_description(M,D,complementOf(Descr)) :- 2547 use_owl(M,D,'owl:complementOf',D1,complementOf(D)), 2548 owl_description(M,D1,Descr), 2549 owl_get_bnode(M,D,complementOf(Descr)),!. 2550 2551owl_description(M,D,oneOf(L)) :- 2552 use_owl(M,D,'owl:oneOf',L1,oneOf(D)), 2553 ( use_owl(M,D,'rdf:type','owl:Class',oneOf(D,L)) ; true), 2554 owl_individual_list(M,L1,L), 2555 owl_get_bnode(M,D,oneOf(L)),!. 2556 2557owl_description(M,D,datatypeRestriction(DY,L)) :- 2558 use_owl(M,D,'rdf:type','rdfs:Datatype',datatypeRestr(D)), 2559 use_owl(M,D,'owl:onDatatype',Y,dataType(D)), 2560 owl_datarange(M,Y,DY), 2561 use_owl(M,D,'owl:withRestrictions',L1,withRestrictions(D)), 2562 owl_datatype_restriction_list(L1,L), 2563 owl_get_bnode(M,D,datatypeRestriction(DY,L)). 2564 2565owl_description(M,D,Restriction) :- 2566 owl_restriction(M,D, Restriction), 2567 owl_get_bnode(M,D,Restriction),!. 2568 2569 2570% Table 15 - OWL DL compatibility class expressions 2571% 2572owl_description(M,D,Result) :- 2573 \+ is_bnode(D), % better: IRI(C). 2574 use_owl(M,D,'rdf:type','owl:Class',description(D)), 2575 use_owl(M,D,'owl:unionOf',L,unionOf(L)), 2576 owl_description_list(M,L,DL), 2577 ( DL = [], Result = 'owl:Nothing' ; 2578 DL = [D1], Result = D1), 2579 owl_get_bnode(M,D,Result),!. 2580 2581owl_description(M,D,Result) :- 2582 \+ is_bnode(D), % better: IRI(C). 2583 use_owl(M,D,'rdf:type','owl:Class',dl_compatibility_descr(D)), 2584 use_owl(M,D,'owl:intersectionOf',L,intersectionOf(D)), 2585 owl_description_list(M,L,DL), 2586 ( DL = [], Result = 'owl:Thing' ; 2587 DL = [D1], Result = D1), 2588 owl_get_bnode(M,D,Result),!. 2589 2590owl_description(M,D,Result) :- 2591 \+ is_bnode(D),!, % better: IRI(C). 2592 use_owl(M,D,'rdf:type','owl:Class',dl_compatibility_descr(D)), 2593 use_owl(M,D,'owl:oneOf',[],oneOf(D)), 2594 Result = 'owl:Nothing', 2595 owl_get_bnode(M,D,Result). 2596 2597% support older deprecated versions of OWL2 spec. See for example hydrology.owl 2598onClass(M,E,D) :- use_owl(M,E,'http://www.w3.org/2006/12/owl2#onClass',D,onClass(E)). 2599onClass(M,E,D) :- use_owl(M,E,'owl:onClass',D,onClass(E)). 2600 2601onDataRange(M,E,D) :- use_owl(M,E, 'owl:onDataRange',D,onDatarange(E)). 2602 2603 2604% owl_restriction(+Module,+Element,-Restriction). 2605% 2606% If Element is defined as a owl:Restriction on property P then 2607% Restriction binds to a restriction(Property,Type) term, 2608% according to OWL Abstract syntax specification. 2609 2610owl_restriction(M,Element,Restriction) :- 2611 use_owl(M,Element,'rdf:type','owl:Restriction',restriction(Element)), 2612 ( use_owl(M,Element, 'owl:onProperty',PropertyID,onProperty(Element,PropertyID)) ; 2613 use_owl(M,Element, 'owl:onProperties',PropertyID,onProperties(Element,PropertyID)) 2614 ), 2615 owl_restriction_type(M,Element,PropertyID, Restriction), 2616 debug(owl_parser_detail,'Restriction: ~w',[Restriction]). 2617 2618 2619 2620owl_restriction_type(M,E, P, someValuesFrom(PX, DX)) :- 2621 use_owl(M,E, 'owl:someValuesFrom',D,someValuesFrom(E,P)), 2622 ( owl_description(M,D, DX) ; owl_datarange(M,D,DX)), 2623 ( P = [_|_], owl_property_list(M,P,PX) ; owl_property_expression(M,P, PX)). 2624 2625 2626owl_restriction_type(M,E, P, allValuesFrom(PX,DX)) :- 2627 use_owl(M,E, 'owl:allValuesFrom',D,allValuesFrom(E,P)), 2628 ( owl_description(M,D, DX) ; owl_datarange(M,D,DX)), 2629 ( P = [_|_], owl_property_list(M,P,PX) ; owl_property_expression(M,P, PX)). 2630 2631 2632% changed from thea value-->hasValue 2633owl_restriction_type(M,E, P, hasValue(PX,Value)) :- 2634 use_owl(M,E, 'owl:hasValue',Value,hasValue(E)), 2635 owl_property_expression(M,P, PX). 2636 2637% VV:check if RDF parser returns a triple with O=true for 2638owl_restriction_type(M,E, P, hasSelf(PX)) :- 2639 use_owl(M,E, 'owl:hasSelf', true,hasSelf(E)), 2640 owl_property_expression(M,P, PX). 2641 2642% Support of deprecated translations: 2643% in the OWL2 RDF mapping, unqualified CRs use owl:{min,max}Cardinality 2644% and QCQs use owl:{min,ax}QualifiedCardinality 2645% 2646% however, there appear to be some ontologies; e.g. Hydrology.owl. 2647% that use an older mapping, where the same properties are used 2648% for QCR and unqCR 2649% 2650% it is relatively easy to support this legacy ontologies; however 2651% we must process these BEFORE unqualified cardinality restrictions. 2652 2653owl_restriction_type(M,E, P, exactCardinality(N,PX,DX)) :- 2654 test_use_owl(M,E, 'owl:cardinality',Lit), 2655 onClass(M,E,D), 2656 owl_description(M,D, DX),!, 2657 use_owl(M,E, 'owl:cardinality',Lit,cardinality(E)), 2658 literal_integer(Lit,N), 2659 owl_property_expression(M,P, PX). 2660 2661owl_restriction_type(M,E, P, minCardinality(N,PX,DX)) :- 2662 test_use_owl(M,E, 'owl:minCardinality',Lit), 2663 ( onClass(M,E,D),owl_description(M,D, DX) 2664 ; onDataRange(M,E,D), owl_datarange(M,D,DX)), 2665 !, 2666 % we are sure this is an old-style unqualified CR - now consume triples 2667 use_owl(M,E, 'owl:minCardinality',Lit,minCardinality(E)), 2668 literal_integer(Lit,N), 2669 owl_property_expression(M,P, PX). 2670 2671owl_restriction_type(M,E, P, maxCardinality(N,PX,DX)) :- 2672 test_use_owl(M,E, 'owl:maxCardinality',Lit), 2673 ( onClass(M,E,D),owl_description(M,D, DX) 2674 ; onDataRange(M,E,D), owl_datarange(M,D,DX)), 2675 !, 2676 % we are sure this is an old-style unqualified CR - now consume triples 2677 use_owl(M,E, 'owl:maxCardinality',Lit,maxCard(E)), 2678 literal_integer(Lit,N), 2679 owl_property_expression(M,P, PX). 2680 2681% END OF Support of deprecated translations: 2682 2683% the following are all in the spec: 2684 2685% changed from Thea1->2: cardinality->exactCardinality 2686owl_restriction_type(M,E, P,exactCardinality(N,PX)) :- 2687 use_owl(M,E, 'owl:cardinality',Lit,cardinality(E)), 2688 literal_integer(Lit,N), 2689 owl_property_expression(M,P, PX). 2690 2691owl_restriction_type(M,E, P,exactCardinality(N,PX,DX)) :- 2692 use_owl(M,E, 'owl:qualifiedCardinality',Lit),literal_integer(Lit,N), 2693 ( onClass(M,E,D),owl_description(M,D, DX) ; 2694 onDataRange(M,E,D), owl_datarange(M,D,DX) 2695 ), 2696 owl_property_expression(M,P, PX). 2697 2698 2699owl_restriction_type(M,E, P, minCardinality(N,PX)) :- 2700 use_owl(M,E, 'owl:minCardinality',Lit,cardinality(E)),literal_integer(Lit,N), 2701 owl_property_expression(M,P, PX). 2702 2703owl_restriction_type(M,E, P, minCardinality(N,PX,DX)) :- 2704 use_owl(M,E, 'owl:minQualifiedCardinality',Lit,cardinality(E)),literal_integer(Lit,N), 2705 ( onClass(M,E,D),owl_description(M,D, DX); 2706 onDataRange(M,E,D), owl_datarange(M,D,DX) 2707 ), 2708 owl_property_expression(M,P, PX). 2709 2710 2711owl_restriction_type(M,E, P, maxCardinality(N,PX)) :- 2712 use_owl(M,E, 'owl:maxCardinality',Lit,maxCardinality(E)),literal_integer(Lit,N), 2713 owl_property_expression(M,P, PX). 2714 2715owl_restriction_type(M,E, P, maxCardinality(N,PX,DX)) :- 2716 use_owl(M,E, 'owl:maxQualifiedCardinality',Lit,cardinality(E,Lit)), 2717 literal_integer(Lit,N), 2718 ( onClass(M,E,D),owl_description(M,D, DX); 2719 onDataRange(M,E,D), owl_datarange(M,D,DX)), 2720 owl_property_expression(M,P, PX). 2721 2722 2723% Table 14. Parsing of Data Ranges for Compatibility with OWL DL 2724% Included into owl_datarange clauses above 2725 2726% Table 15. Parsing of Class Expressions for Compatibility with OWL DL 2727% Included into owl_dexcription clauses above 2728 2729% Table 16. Parsing of Axioms without Annotations 2730% Declarations handled previously 2731% CLASS AXIOMS 2732% valid_axiom_annotation_mode: add clauses for the disjoint etc .... 2733 2734collect_r_nodes(M) :- 2735 retractall(M:axiom_r_node(_,_,_,_)), 2736 forall(( test_use_owl(M,Node,'rdf:type','owl:Axiom'), 2737 test_use_owl(M,Node,'owl:annotatedSource',S), 2738 test_use_owl(M,Node,'owl:annotatedProperty',P), 2739 test_use_owl(M,Node,'owl:annotatedTarget',O)), 2740 (assert(M:axiom_r_node(S,P,O,Node)), 2741 assert(M:owl(S,P,O,not_used)), 2742 debug(owl_parser_detail,'~w',[axiom_r_node(S,P,O,Node)]), 2743 use_owl(M,[owl(Node,'rdf:type','owl:Axiom'), 2744 owl(Node,'owl:annotatedSource',S), 2745 owl(Node,'owl:annotatedProperty',P), 2746 owl(Node,'owl:annotatedTarget',O)]))), 2747 2748 retractall(M:annotation_r_node(_,_,_,_)), 2749 forall(( test_use_owl(M,W,'rdf:type','owl:Annotation'), 2750 test_use_owl(M,W,'owl:annotatedSource',S), 2751 test_use_owl(M,W,'owl:annotatedProperty',P), 2752 test_use_owl(M,W,'owl:annotatedTarget',O)), 2753 (assert(M:annotation_r_node(S,P,O,Node)), 2754 debug(owl_parser_detail,'~w',[annotation_r_node(S,P,O,Node)]), 2755 use_owl(M,[owl(W,'rdf:type','owl:Annotation'), 2756 owl(W,'owl:annotatedSource',S), 2757 owl(W,'owl:annotatedProperty',P), 2758 owl(W,'owl:annotatedTarget',O)]))).
2765valid_axiom_annotation_mode(true,M,S,P,O,List) :- 2766 expand_ns(P,PE), 2767 findall(Node,M:axiom_r_node(S,PE,O,Node),List). 2768 2769valid_axiom_annotation_mode(false,_M,_S,_P,_O,[]). 2770 2771 2772owl_parse_axiom(M,subClassOf(DX,DY),AnnMode,List) :- 2773 test_use_owl(M,X,'rdfs:subClassOf',Y), 2774 valid_axiom_annotation_mode(AnnMode,M,X,'rdfs:subClassOf',Y,List), 2775 use_owl(M,X,'rdfs:subClassOf',Y,subclassOf(X,Y)), 2776 owl_description(M,X,DX), 2777 owl_description(M,Y,DY). 2778 2779% Process each equivalentClass pair separately in order to capture 2780% annotations. Block the maximally connected subgraph. 2781% TODO. Process the equivalent(L) axioms to generate maximally connected 2782% equivalentClasses(L) axioms. (but without annotations?) 2783 2784owl_parse_axiom(M,equivalentClasses(DL),AnnMode,List) :- 2785 test_use_owl(M,X,'owl:equivalentClass',Y), 2786 valid_axiom_annotation_mode(AnnMode,M,X,'owl:equivalentClass',Y,List), 2787 use_owl(M,X,'owl:equivalentClass',Y,equivalentClass(X,Y)), 2788 % maximally_connected_subgraph_over('owl:equivalentClass',L), 2789 maplist(owl_description(M),[X,Y],DL), 2790 debug(owl_parser_detail,'equivalentClasses Descs: ~w',[DL]). 2791 2792 2793owl_parse_axiom(M,equivalentClasses([C,intersectionOf(D)]),AnnMode,List) :- 2794 M:class(C), 2795 test_use_owl(M,C,'owl:intersectionOf',D1), 2796 debug(owl_parser,'equivalent collection; intersection for ~w',[C]), 2797 valid_axiom_annotation_mode(AnnMode,M,C,'owl:intersectionOf',D1,List), 2798 owl_description(M,C,intersectionOf(D)). 2799 2800owl_parse_axiom(M,equivalentClasses([C,unionOf(D)]),AnnMode,List) :- 2801 M:class(C), 2802 test_use_owl(M,C,'owl:unionOf',D1), 2803 debug(owl_parser,'equivalent collection; union for ~w',[C]), 2804 valid_axiom_annotation_mode(AnnMode,M,C,'owl:unionOf',D1,List), 2805 owl_description(M,C,unionOf(D)). 2806 2807owl_parse_axiom(M,equivalentClasses([C,oneOf(D)]),AnnMode,List) :- 2808 M:class(C), 2809 test_use_owl(M,C,'owl:oneOf',D1), 2810 debug(owl_parser,'equivalent collection; one of for ~w',[C]), 2811 valid_axiom_annotation_mode(AnnMode,M,C,'owl:oneOf',D1,List), 2812 owl_description(M,C,oneOf(D)). 2813 2814 2815owl_parse_axiom(M,equivalentClasses([C,D])) :- 2816 % TODO: this could be made more efficient by enforcing order of building 2817 ( test_use_owl(M,C,'rdf:type','owl:Class',named) 2818 ; test_use_owl(M,C,'rdf:type','rdfs:Class',named) 2819 ; M:class(C)), 2820 owl_description(M,C,D), 2821 C\=D. 2822 2823% TODO. Process the disjointClasses(L) axioms to generate 2824% larger set of disjoint: ie if N classes are pairwise DisJoint 2825% then we can assert a disjointClasses for all N 2826 2827owl_parse_axiom(M,disjointClasses([DX,DY]),AnnMode,List) :- 2828 test_use_owl(M,X,'owl:disjointWith',Y), 2829 valid_axiom_annotation_mode(AnnMode,M,X,'owl:disjointWith',Y,List), 2830 use_owl(M,X,'owl:disjointWith',Y,disjointWith(X,Y)), 2831 owl_description(M,X,DX), 2832 owl_description(M,Y,DY). 2833 2834% One of the cases where annotations are those of _x and we do not seek 2835% for further annotation axioms. Par. 3.2.5. 2836% Whatever the AnnNode, _x is returned (will be ignored if mode false 2837 2838owl_parse_axiom(M,disjointClasses(L),_AnnMode,[X]) :- 2839 % TODO: X may be referred to in an annotation axiom?? 2840 use_owl(M,X,'rdf:type','owl:AllDisjointClasses',allDisjointClasses(X)), 2841 use_owl(M,X,'owl:members',L1,members(L1)), 2842 owl_description_list(M,L1,L). 2843 2844 2845owl_parse_axiom(M,disjointUnion(DX,DY),AnnMode,List) :- 2846 test_use_owl(M,X,'owl:disjointUnionOf',Y), 2847 valid_axiom_annotation_mode(AnnMode,M,X,'owl:disjointUnionOf',Y,List), 2848 use_owl(M,X,'owl:disjointUnionOf',Y,disjointUnionOf(X,Y)), 2849 owl_description(M,X,DX), 2850 owl_description_list(M,Y,DY). 2851 2852 2853% PROPERTY AXIOMS 2854 2855 2856% introduces bnode 2857owl_parse_axiom(M,subPropertyOf(propertyChain(PL),QX),AnnMode,List) :- 2858 test_use_owl(M,Q,'owl:propertyChainAxiom',L1), 2859 valid_axiom_annotation_mode(AnnMode,M,Q,'owl:propertyChainAxiom',L1,List), 2860 use_owl(M,Q,'owl:propertyChainAxiom',L1,propertyChainAxiom(Q)), 2861 owl_property_list(M,L1,PL), 2862 owl_property_expression(M,Q,QX). 2863 2864owl_parse_axiom(M,subPropertyOf(PX,QX),AnnMode,List) :- 2865 test_use_owl(M,P,'rdfs:subPropertyOf',Q), 2866 valid_axiom_annotation_mode(AnnMode,M,P,'rdfs:subPropertyOf',Q,List), 2867 use_owl(M,P,'rdfs:subPropertyOf',Q,subPropertyOf(P,Q)), 2868 owl_property_expression(M,P,PX), 2869 owl_property_expression(M,Q,QX). 2870 2871 2872% Process each equivalentProperty pair separately in order to capture 2873% annotations. Block the maximally connected subgraph. 2874% TODO. Process the equivalent(L) axioms to generate maximally connected 2875% equivalentProperties(L) axioms. (but without annotations?) 2876 2877owl_parse_axiom(M,equivalentProperties(OPEL),AnnMode,List) :- 2878 test_use_owl(M,X,'owl:equivalentProperty',Y), 2879 valid_axiom_annotation_mode(AnnMode,M,X,'owl:equivalentProperty',Y,List), 2880 use_owl(M,X,'owl:equivalentProperty',Y,equivProperty(X,Y)), 2881 % maximally_connected_subgraph_over('owl:equivalentProperty',L), 2882 maplist(owl_property_expression(M),[X,Y],OPEL). 2883 2884 2885% TODO. Process the disjointProperties(L) axioms to generate 2886% larger set of disjoint: ie if N properties are pairwise DisJoint 2887% then we can assert a disjointClasses for all N 2888 2889owl_parse_axiom(M,disjointProperties([DX,DY]),AnnMode,List) :- 2890 test_use_owl(M,X,'owl:propertyDisjointWith',Y), 2891 valid_axiom_annotation_mode(AnnMode,M,X,'owl:propertyDisjointWith',Y,List), 2892 use_owl(M,X,'owl:propertyDisjointWith',Y,propertyDisjointWith(X,Y)), 2893 owl_description(M,X,DX), 2894 owl_description(M,Y,DY). 2895 2896% One more of the cases where annotations are those of _x and we do not 2897% seek for further annotation axioms. Par. 3.2.5. Whatever the AnnNode, 2898% _x is returned (will be ignored if mode false) 2899 2900owl_parse_axiom(M,disjointProperties(L),_AnnMode,[X]) :- 2901 % TODO: X may be referred to in an annotation axiom?? 2902 use_owl(M,X,'rdf:type','owl:AllDisjointProperties',allDisjointProps(X,L1)), 2903 use_owl(M,X,'owl:members',L1,members(L1)), 2904 L1 = [_,_|_], % length >= 2 2905 owl_property_list(M,L1,L). 2906 2907 2908owl_parse_axiom(M,propertyDomain(PX,CX),AnnMode,List) :- 2909 test_use_owl(M,P,'rdfs:domain',C), 2910 valid_axiom_annotation_mode(AnnMode,M,P,'rdfs:domain',C,List), 2911 use_owl(M,P,'rdfs:domain',C,domain(P,C)), 2912 ( M:annotationProperty(P),CX = C ; 2913 owl_property_expression(M,P,PX), 2914 owl_description(M,C,CX) 2915 ). 2916 2917% We need to distinguish here between object and data property 2918% Currently we first test if the range is a class, this means OPE 2919% otherwise if it is a datarange it means a DPE. 2920% Ideally we should also check possible declarations of OPE or DPE. 2921 2922owl_parse_axiom(M,propertyRange(PX,CX),AnnMode,List) :- 2923 test_use_owl(M,P,'rdfs:range',C), 2924 valid_axiom_annotation_mode(AnnMode,M,P,'rdfs:range',C,List), 2925 use_owl(M,P,'rdfs:range',C,range(P,C)), 2926 ( M:annotationProperty(P) -> PX = P, CX = C ; 2927 owl_property_expression(M,P,PX), 2928 ( owl_description(M,C,CX) -> true ; owl_datarange(M,C,CX)) 2929 ). 2930 2931owl_parse_axiom(M,inverseProperties(PX,QX),AnnMode,List) :- 2932 test_use_owl(M,P,'owl:inverseOf',Q), 2933 valid_axiom_annotation_mode(AnnMode,M,P,'owl:inverseOf',Q,List), 2934 use_owl(M,P,'owl:inverseOf',Q,inverseOf(P,Q)), 2935 owl_property_expression(M,P,PX), 2936 owl_property_expression(M,Q,QX). 2937 2938owl_parse_axiom(M,functionalProperty(P),AnnMode,List) :- 2939 test_use_owl(M,P,'rdf:type','owl:FunctionalProperty'), 2940 valid_axiom_annotation_mode(AnnMode,M,P,'rdf:type','owl:FunctionalProperty',List), 2941 use_owl(M,P,'rdf:type','owl:FunctionalProperty',functionalProperty(P)). 2942 2943owl_parse_axiom(M,inverseFunctionalProperty(P),AnnMode,List) :- 2944 test_use_owl(M,P,'rdf:type','owl:InverseFunctionalProperty'), 2945 valid_axiom_annotation_mode(AnnMode,M,P,'rdf:type','owl:InverseFunctionalProperty',List), 2946 use_owl(M,P,'rdf:type','owl:InverseFunctionalProperty',inverseFunctionalProperty(P)). 2947 2948owl_parse_axiom(M,reflexiveProperty(P),AnnMode,List) :- 2949 test_use_owl(M,P,'rdf:type','owl:ReflexiveProperty'), 2950 valid_axiom_annotation_mode(AnnMode,M,P,'rdf:type','owl:ReflexiveProperty',List), 2951 use_owl(M,P,'rdf:type','owl:ReflexiveProperty',reflexiveProperty(P)). 2952 2953owl_parse_axiom(M,irreflexiveProperty(P),AnnMode,List) :- 2954 test_use_owl(M,P,'rdf:type','owl:IrreflexiveProperty'), 2955 valid_axiom_annotation_mode(AnnMode,M,P,'rdf:type','owl:IrreflexiveProperty',List), 2956 use_owl(M,P,'rdf:type','owl:IrreflexiveProperty',irreflexiveProperty(P)). 2957 2958owl_parse_axiom(M,symmetricProperty(P),AnnMode,List) :- 2959 test_use_owl(M,P,'rdf:type','owl:SymmetricProperty'), 2960 valid_axiom_annotation_mode(AnnMode,M,P,'rdf:type','owl:SymmetricProperty',List), 2961 use_owl(M,P,'rdf:type','owl:SymmetricProperty',symmetricProperty(P)). 2962 2963owl_parse_axiom(M,asymmetricProperty(P),AnnMode,List) :- 2964 test_use_owl(M,P,'rdf:type','owl:AsymmetricProperty'), 2965 valid_axiom_annotation_mode(AnnMode,M,P,'rdf:type','owl:AsymmetricProperty',List), 2966 use_owl(M,P,'rdf:type','owl:AsymmetricProperty',assymetricProperty(P)). 2967 2968owl_parse_axiom(M,transitiveProperty(P),AnnMode,List) :- 2969 test_use_owl(M,P,'rdf:type','owl:TransitiveProperty'), 2970 valid_axiom_annotation_mode(AnnMode,M,P,'rdf:type','owl:TransitiveProperty',List), 2971 use_owl(M,P,'rdf:type','owl:TransitiveProperty',transitiveProperty(P)). 2972 2973owl_parse_axiom(M,hasKey(CX,L),AnnMode,List) :- 2974 test_use_owl(M,C,'owl:hasKey',L1), 2975 valid_axiom_annotation_mode(AnnMode,M,C,'owl:hasKey',L1,List), 2976 use_owl(M,C,'owl:hasKey',L1,hasKey(C)), 2977 owl_description(M,C,CX), 2978 L1 = [_,_|_], % length >= 2 2979 owl_property_list(M,L1,L). 2980 2981% INDIVIDUALS 2982 2983owl_parse_axiom(M,sameIndividual([X,Y]),AnnMode,List) :- 2984 test_use_owl(M,X,'owl:sameAs',Y), 2985 valid_axiom_annotation_mode(AnnMode,M,X,'owl:sameAs',Y,List), 2986 use_owl(M,X,'owl:sameAs',Y,sameAs(X,Y)). 2987 2988owl_parse_axiom(M,differentIndividuals([X,Y]),AnnMode,List) :- 2989 test_use_owl(M,X,'owl:differentFrom',Y), 2990 valid_axiom_annotation_mode(AnnMode,M,X,'owl:differentFrom',Y,List), 2991 use_owl(M,X,'owl:differentFrom',Y,differentFrom(X,Y)). 2992 2993owl_parse_axiom(M,differentIndividuals(L),_AnnMode,[X]) :- 2994 use_owl(M,X,'rdf:type','owl:AllDifferent',allDifferent(L)), 2995 use_owl(M,X,'owl:distinctMembers',L1,distinctMembers(L)), 2996 owl_individual_list(M,L1,L). 2997 2998owl_parse_axiom(M,differentIndividuals(L),_AnnMode,[X]) :- 2999 use_owl(M,X,'rdf:type','owl:AllDifferent',allDifferent(X)), 3000 use_owl(M,X,'owl:members',L1,members(L)), 3001 owl_individual_list(M,L1,L). 3002 3003% make sure this is done before fetching classAssertion/2; 3004% -- the annotationAssertion matching clause should preceded the classAssertion/2 matching clause 3005owl_parse_axiom(M,annotationAssertion('owl:deprecated', X, true),AnnMode,List) :- 3006 test_use_owl(M,X, 'rdf:type', 'owl:DeprecatedClass'), 3007 valid_axiom_annotation_mode(AnnMode,M,X,'rdf:type','owl:DeprecatedClass',List), 3008 use_owl(M,X, 'rdf:type', 'owl:DeprecatedClass',deprecatedClass(X)). 3009 3010% make sure this is done before fetching propertyAssertion/3 3011% this clause should precede it 3012owl_parse_axiom(M,annotationAssertion('owl:deprecated', X, true),AnnMode,List) :- 3013 test_use_owl(M,X, 'rdf:type', 'owl:DeprecatedProperty'), 3014 valid_axiom_annotation_mode(AnnMode,M,X,'rdf:type','owl:DeprecatedProperty',List), 3015 use_owl(M,X, 'rdf:type', 'owl:DeprecatedProperty',deprecatedProperty(X)). 3016 3017% Table 17. Parsing of Annotated Axioms 3018 3019dothislater(annotationAssertion/3). 3020% TODO - only on unnannotated pass? 3021% 3022 3023owl_parse_axiom(M,annotationAssertion(P,A,B),AnnMode,List) :- 3024 M:annotationProperty(P), 3025 test_use_owl(M,A,P,B), % B can be literal or individual 3026 valid_axiom_annotation_mode(AnnMode,M,A,P,B,List), 3027 use_owl(M,A,P,B,annotationProperty(P)). 3028 3029 3030dothislater(classAssertion/2). 3031owl_parse_axiom(M,classAssertion(CX,X),AnnMode,List) :- 3032 test_use_owl(M,X,'rdf:type',C), 3033 C\='http://www.w3.org/2002/07/owl#DeprecatedClass', 3034 % note: some ontologies may include a rdf:type with no 3035 % explicit class declaration. See testfiles/test_undeclared.owl 3036 %class(C), 3037 valid_axiom_annotation_mode(AnnMode,M,X,'rdf:type',C,List), 3038 use_owl(M,X,'rdf:type',C,classAssertion(CX,X)), 3039 % I added this to avoid class assertions for bNodes. Perhaps a better 3040 % way is to simply consume the owl4/ triple at the time of translating 3041 % the description? --CJM 3042 C\='http://www.w3.org/2002/07/owl#Class', 3043 % 3044 C\='http://www.w3.org/1999/02/22-rdf-syntax-ns#Property', 3045 owl_description(M,C,CX). 3046 3047dothislater(propertyAssertion/3). 3048owl_parse_axiom(M,propertyAssertion(PX,A,BX),AnnMode,List) :- 3049 test_use_owl(M,A,P,B), % B can be literal or individual 3050 P\='http://www.w3.org/1999/02/22-rdf-syntax-ns#type', 3051 % note: some ontologies may include a triples with no 3052 % explicit property declaration. See testfiles/test_undeclared.owl 3053 %property(P), 3054 valid_axiom_annotation_mode(AnnMode,M,A,P,B,List), 3055 \+ M:annotationProperty(P), % these triples should have been removed before, during ann parsing 3056 owl_property_expression(M,P,PX), % can also be inverse 3057 % next line added by VV 9/3/2011 for Jochem Liem to support ID-lists as PA objects 3058 ( owl_individual_list(M,B,BX) -> true ; BX = B), 3059 use_owl(M,A,P,B,propertyAssertion(PX,A,BX)). 3060 3061 3062owl_parse_axiom(M,negativePropertyAssertion(PX,A,B),_,X) :- 3063 use_owl(M,X,'rdf:type','owl:NegativePropertyAssertion',negPropertyAssertion(PX,A,B)), 3064 use_owl(M,X,'owl:sourceIndividual',A,negPropertyAssertion(PX,A,B)), 3065 use_owl(M,X,'owl:assertionProperty',P,negPropertyAssertion(PX,A,B)), 3066 use_owl(M,X,'owl:targetValue',B,negPropertyAssertion(PX,A,B)), 3067 owl_property_expression(M,P,PX). 3068 3069 3070% process hooks; SWRL etc 3071 3072% Parsing annotationAssertions 3073% 3074 3075parse_annotation_assertions(M) :- 3076 ( M:trdf_setting(rind,RIND) -> true ; RIND = []),!, 3077 forall((M:aNN(X,AP,AV),findall( aNN(annotation(X,AP,AV),AP1,AV1), 3078 M:aNN(annotation(X,AP,AV),AP1,AV1),ANN), \+member(X,RIND), atomic(X), \+name(X,[95, 58, 68, 101, 115, 99, 114, 105, 112, 116, 105, 111, 110|_])), 3079 ( assert_axiom(M,annotationAssertion(AP,X,AV)), 3080 % VV 10/3/2010 keep annotation/3 3081 % retract(annotation(X,AP,AV)), 3082 forall(member(aNN(_,AP1,AV1),ANN), 3083 assert_axiom(M,annotation(annotationAssertion(AP,X,AV),AP1,AV1)) 3084 ) 3085 ) 3086 ), 3087 % forall(aNN(X,Y,Z),assert(annotation(X,Y,Z))), VV remove 25/1/11 3088 % annotation/3 axioms created already during owl_parse_annotated_axioms/1 3089 retractall(M:aNN(_,_,_)). 3090 3091% Table 18. Parsing of Axioms for Compatibility with OWL DL 3092 3093owl_parse_compatibility_DL(M,equivalentClasses([CEX,complementOf(CEY)])) :- 3094 use_owl(M,X,'owl:complementOf',Y,eq_classes), 3095 owl_description(M,X,CEX), 3096 owl_description(M,Y,CEY). 3097 3098 3099owl_parse_compatibility_DL(M,equivalentClasses([CEX,CEY])) :- 3100 use_owl(M,X,'owl:unionOf',Y,eq_classes), 3101 owl_description(M,X,CEX), 3102 owl_description_list(M,Y,DL), 3103 ( DL = [] -> CEY = 'owl:Nothing' ; (DL=[CEY]->true;CEY = unionOf(DL))). 3104 3105owl_parse_compatibility_DL(M,equivalentClasses([CEX,CEY])) :- 3106 use_owl(M,X,'owl:intersectionOf',Y,eq_classes), 3107 owl_description(M,X,CEX), 3108 owl_description_list(M,Y,DL), 3109 ( DL = [] -> CEY = 'owl:Thing' ; (DL=[CEY]->true;CEY = intersectionOf(DL))). 3110 3111owl_parse_compatibility_DL(M,equivalentClasses([CEX,CEY])) :- 3112 use_owl(M,X,'owl:oneOf',Y,eq_classes), 3113 owl_description(M,X,CEX), 3114 owl_description_list(M,Y,DL), 3115 ( DL = [] -> CEY = 'owl:Nothing' ; CEY = oneOf(DL)). 3116 3117% UTIL
3120maximally_connected_subgraph_over(P,CSet):-
3121 maximally_connected_subgraph_over(P,[],CSetL),
3122 member(CSet,CSetL).3125maximally_connected_subgraph_over(P,Used,[CSet|All]):- 3126 test_use_owl(M,X,P,Y), % seed 3127 \+ member(X,Used), 3128 \+ member(Y,Used), 3129 use_owl(M,X,P,Y,maximally_conected), % seed 3130 !, 3131 extend_set_over(P,[X,Y],CSet), 3132 append(CSet,Used,Used2), 3133 maximally_connected_subgraph_over(P,Used2,All). 3134maximally_connected_subgraph_over(_,_,[]). 3135 3136 3137% det 3138extend_set_over(P,L,L2):- 3139 member(X,L), 3140 test_use_owl(M,X,P,Y), 3141 \+ member(Y,L), 3142 use_owl(M,X,P,Y,extend_set_over), 3143 !,extend_set_over(P,[Y|L],L2). 3144extend_set_over(P,L,L2):- 3145 member(X,L), 3146 test_use_owl(M,Y,P,X), 3147 \+ member(Y,L), 3148 use_owl(M,Y,P,X,extend_set_over), 3149 !,extend_set_over(P,[Y|L],L2). 3150extend_set_over(_,L,L):- !. 3151 3152literal_integer(literal(type,A),N) :- atom_number(A,N). 3153literal_integer(literal(type(_,A)),N) :- atom_number(A,N).
3157time_goal(Goal,Time):- 3158 statistics(cputime,T1), , 3159 statistics(cputime,T2), Time is T2-T1. 3160 3161timed_forall(Cond,Action) :- 3162 forall(Cond, 3163 ( time_goal(Action,Time), 3164 debug(owl2_bench,'Goal: ~w Time:~w',[Action,Time]))).
:- use_module(bio(owl2_from_rdf)). %
The file owl2_from_rdf.plt has some examples */
3179%:- thread_local ns4query/1.
3187load_owl(String):-
3188 get_module(M),
3189 retractall(M:ns4query(_)),
3190 open(String,read,S),
3191 load_owl_from_stream(S),!.3199load_owl_from_string(String):- 3200 open_chars_stream(String,S), 3201 load_owl_from_stream(S). 3202 3203load_owl_from_stream(S):- 3204 get_module(M), 3205 retractall(M:trdf_setting(_,_)), 3206 process_rdf(stream(S), assert_list(M), [namespaces(NSList)]), 3207 close(S), 3208 trillo:add_kb_prefixes(M:NSList), 3209 rdf_2_owl(M,'ont'), 3210 utility_translation_init(M), 3211 owl_canonical_parse_3(M,['ont']), 3212 parse_probabilistic_annotation_assertions(M). 3213 3214% Get the KB's prefixes contained into ns4query 3215:- multifile trillo:kb_prefixes/1. 3216 3217trillokb_prefixes(M:L):- 3218 M:ns4query(L),!. 3219 3220% Adds a list of kb prefixes into ns4query 3221:- multifile trillo:add_kb_prefixes/1. 3222 3223trilloadd_kb_prefixes(_:[]):-!. 3224 3225trilloadd_kb_prefixes(M:[(H=H1)|T]):- 3226 trillo:add_kb_prefix(M:H,H1), 3227 trillo:add_kb_prefixes(M:T). 3228 3229% Adds a prefix into ns4query 3230:- multifile trillo:add_kb_prefix/2. 3231 3232trilloadd_kb_prefix(M:'',B):- !, 3233 trillo:add_kb_prefix(M:[],B). 3234 3235trilloadd_kb_prefix(M:A,B):- 3236 M:ns4query(L),!, 3237 (\+ member((A=_),L) -> 3238 (retract(M:ns4query(L)), 3239 append(L,[(A=B)],NL), 3240 assert(M:ns4query(NL)) 3241 ) 3242 ; 3243 true 3244 ). 3245 3246trilloadd_kb_prefix(M:A,B):- 3247 assert(M:ns4query([(A=B)])). 3248 3249% Removes a prefix from ns4query 3250:- multifile trillo:remove_kb_prefix/2. 3251trilloremove_kb_prefix(M:A,B):- 3252 M:ns4query(L),!, 3253 (member((A=B),L) -> 3254 (retract(M:ns4query(L)), 3255 delete(L,(A=B),NL), 3256 assert(M:ns4query(NL)) 3257 ) 3258 ; 3259 true 3260 ). 3261 3262:- multifile trillo:remove_kb_prefix/1. 3263trilloremove_kb_prefix(M:A):- 3264 M:ns4query(L),!, 3265 (member((A=B),L) *-> 3266 (retract(M:ns4query(L)), 3267 delete(L,(A=B),NL), 3268 assert(M:ns4query(NL)) 3269 ) 3270 ; 3271 (member((B=A),L),! *-> 3272 (retract(M:ns4query(L)), 3273 delete(L,(B=A),NL), 3274 assert(M:ns4query(NL)) 3275 ) 3276 ; 3277 true 3278 ) 3279 ). 3280 3281 3282assert_list(_M,[], _):-!. 3283assert_list(M,[H|T], Source) :- 3284 %H=..[_|Args], 3285 %H1=..[rdf|Args], 3286 assert(M:), 3287 %add_atoms_from_axiom(M,Args), 3288 assert_list(M,T, Source). 3289 3290find_all_probabilistic_annotations(M,An,Ax,PV):- 3291 M:annotation(Ax,An,literal(lang(_Lang, PV))), 3292 atom(PV). 3293 3294find_all_probabilistic_annotations(M,An,Ax,PV):- 3295 M:annotation(Ax,An,literal(type(_Type, PV))), 3296 atom(PV). 3297 3298find_all_probabilistic_annotations(M,An,Ax,PV):- 3299 M:annotation(Ax,An,literal(PV)), 3300 atom(PV). 3301 3302 3303parse_probabilistic_annotation_assertions(M) :- 3304 forall(find_all_probabilistic_annotations(M,An,Ax,PV), 3305 (assert_axiom(M,annotationAssertion(An,Ax,literal(PV)))) 3306 ), 3307 % forall(aNN(X,Y,Z),assert(annotation(X,Y,Z))), VV remove 25/1/11 3308 % annotation/3 axioms created already during owl_parse_annotated_axioms/1 3309 retractall(M:annotation(_,_,_)). 3310 3311/* 3312query_is([Q|_],0,Q):-!. 3313query_is([_|T],N,Q):- 3314 NN is N - 1, 3315 query_is(T,NN,Q). 3316 3317set_new_query([_|T],0,NQ,[NQ|T]):-!. 3318set_new_query([Q|T],N,NQ,[Q|NT]):- 3319 NN is N - 1, 3320 set_new_query(T,NN,NQ,NT). 3321 3322 3323query_expand(CQ):- 3324 CQ =.. [CQP | CQArgs], 3325 member((CQP,PosQ),[(aggregate_all,1), (limit,1)]),!, 3326 query_is(CQArgs,PosQ,Q), 3327 Q =.. [P|Args], 3328 get_module(M), 3329 M:ns4query(NSList),!, 3330 %retract(M:ns4query(NSList)), 3331 expand_all_ns(M,Args,NSList,NewArgs),!, 3332 NQ =.. [P|NewArgs], 3333 set_new_query(CQArgs,PosQ,NQ,CQNewArgs), 3334 NCQ =.. [CQP|CQNewArgs], 3335 call(NCQ). 3336 3337query_expand(Q):- 3338 Q =.. [P|Args], 3339 get_module(M), 3340 M:ns4query(NSList),!, 3341 %retract(M:ns4query(NSList)), 3342 expand_all_ns(M,Args,NSList,NewArgs),!, 3343 NQ =.. [P|NewArgs], 3344 call(NQ). 3345*/ 3346 3347 3348 3349expand_argument(M,literal(P),NSList,ExpP) :- !, 3350 expand_literal(M,literal(P),NSList,ExpP). 3351expand_argument(M,P,NSList,ExpP) :- 3352 (expand_classExpression(M,P,NSList,ExpP) ; 3353 expand_individual(M,P,NSList,ExpP) ; 3354 expand_propertyExpression(M,P,NSList,ExpP) ; 3355 expand_axiom(M,P,NSList,ExpP) ; 3356 expand_annotationProperty(M,P,NSList,ExpP) ; 3357 expand_dataRange(M,P,NSList,ExpP) ; 3358 expand_ontology(M,P,NSList,ExpP) ), !.
3369expand_all_ns(M,Args,NSList,ExpandedArgs):-
3370 expand_all_ns(M,Args,NSList,true,ExpandedArgs).3379expand_all_ns(_M,[],_,_,[]):- !. 3380 3381expand_all_ns(M,[P|T],NSList,AddName,[PNewArgs|NewArgs]):- 3382 is_list(P),!, 3383 expand_all_ns(M,P,NSList,AddName,PNewArgs), 3384 expand_all_ns(M,T,NSList,AddName,NewArgs). 3385 3386expand_all_ns(M,[P|T],NSList,AddName,[NP|NewArgs]):- 3387 expand_argument(M,P,NSList,NP), 3388 expand_all_ns(M,T,NSList,AddName,NewArgs). 3389 3390/* 3391expand_all_ns(M,[P|T],NSList,AddName,[NP|NewArgs]):- 3392 compound(P), 3393 P =.. [N | Args],!, 3394 expand_all_ns(M,Args,NSList,AddName,NewPArgs), 3395 NP =.. [N| NewPArgs], 3396 expand_all_ns(M,T,NSList,AddName,NewArgs). 3397 3398expand_all_ns(M,[H|T],NSList,AddName,[H|NewArgs]):- 3399 check_query_arg(M,H),!, 3400 expand_all_ns(M,T,NSList,AddName,NewArgs). 3401 3402expand_all_ns(M,[H|T],NSList,AddName,[NewArg|NewArgs]):- 3403 expand_ns4query(M,H,NSList,AddName,NewArg), 3404 expand_all_ns(M,T,NSList,AddName,NewArgs). 3405 3406check_query_arg(M,Arg) :- 3407 atomic(Arg),!, 3408 trillo:axiom(M:Ax), 3409 in_axiom(Arg,[Ax]),!, 3410 add_kb_atom(M,Arg). 3411 3412expand_ns4query(M,NS_URL,NSList,AddName, Full_URL):- 3413 nonvar(NS_URL), 3414 NS_URL \= literal(_), 3415 uri_split(NS_URL,Short_NS,Term, ':'), 3416 member((Short_NS=Long_NS),NSList), 3417 concat_atom([Long_NS,Term],Full_URL),!, 3418 ( AddName == true *-> add_kb_atom(M,Full_URL) ; true). 3419 3420expand_ns4query(M,NS_URL,NSList,AddName, Full_URL):- 3421 nonvar(NS_URL), 3422 NS_URL \= literal(_), 3423 \+ sub_atom(NS_URL,_,_,_,':'), 3424 member(([]=Long_NS),NSList), 3425 concat_atom([Long_NS,NS_URL],Full_URL),!, 3426 ( AddName == true *-> add_kb_atom(M,Full_URL) ; true). 3427 3428expand_ns4query(_M,URL,_,_,URL). 3429*/ 3430/* 3431expand_ns4query(_M,URL,_,_,URL):- 3432 var(URL),!. 3433*/ 3434 3435% check whether the given atom is present in an axiom 3436in_axiom(Atom,[Atom|_]):- !. 3437 3438in_axiom(Atom,[literal(_)|T]):-!, 3439 in_axiom(Atom,T). 3440 3441in_axiom(Atom,[Axiom|_]):- 3442 is_list(Axiom), 3443 in_axiom(Atom,Axiom),!. 3444 3445 3446in_axiom(Atom,[Axiom|_]):- 3447 \+ is_list(Axiom), 3448 compound(Axiom), 3449 Axiom=..[_|Args], 3450 in_axiom(Atom,Args),!. 3451 3452in_axiom(Atom,[_|T]):- 3453 in_axiom(Atom,T). 3454 3455% save atoms in kb for checking existence when querying 3456add_atoms_from_axiom(_M,[]):-!. 3457 3458add_atoms_from_axiom(M,[H|T]):- 3459 compound(H), 3460 H =.. ['literal' | _],!, 3461 add_atoms_from_axiom(M,T). 3462 3463add_atoms_from_axiom(M,[H|T]):- 3464 compound(H), 3465 H =.. [_N, Args],!, 3466 ( is_list(Args) -> 3467 add_atoms_from_axiom(M,Args) 3468 ; 3469 add_atoms_from_axiom(M,[Args]) 3470 ), 3471 add_atoms_from_axiom(M,T). 3472 3473add_atoms_from_axiom(M,[H|T]):- 3474 compound(H), 3475 H =.. [_N | Args],!, 3476 add_atoms_from_axiom(M,Args), 3477 add_atoms_from_axiom(M,T). 3478 3479add_atoms_from_axiom(M,[H|T]):- 3480 add_kb_atom(M,H),!, 3481 add_atoms_from_axiom(M,T). 3482 3483 3484add_kb_atom(M,IRI):- 3485 M:kb_atom(L), 3486 ( (member(IRI,L),!) *-> 3487 true 3488 ; 3489 (retract(M:kb_atom(_)), 3490 assert(M:kb_atom([IRI|L])) 3491 ) 3492 ). 3493 3494 3495add_kb_atoms(_M,_Type,[]):-!. 3496 3497add_kb_atoms(M,Type,[H|T]):- 3498 M:kb_atom(KBA0), 3499 L=KBA0.Type, 3500 ( memberchk(H,L) -> 3501 true 3502 ; 3503 ( retractall(M:kb_atom(_)), 3504 KBA=KBA0.put(Type,[H|L]), 3505 assert(M:kb_atom(KBA)) 3506 ) 3507 ), 3508 add_kb_atoms(M,Type,T). 3509 3510% TODO remove this => dataproperty always as dataproperty, object property as property (for retrocompatibility) or objectproperty 3511fix_wrongly_classified_atoms(M):- 3512 M:kb_atom(KBA0), 3513 findall(OP,M:objectProperty(OP),ObjPs), 3514 findall(DP,M:dataProperty(DP),DataPs), 3515 fix_wrongly_classified_properties(ObjPs,objectProperty,KBA0,KBA1), 3516 fix_wrongly_classified_properties(DataPs,dataProperty,KBA1,KBA2), 3517 fix_duplicated_wrongly_classified_properties(KBA2.objectProperty,KBA2.dataProperty,KBA2,KBA), 3518 retractall(M:kb_atom(_)), 3519 assert(M:kb_atom(KBA)). 3520 3521fix_wrongly_classified_properties([],_Type,KBA,KBA). 3522 3523fix_wrongly_classified_properties([H|T],Type,KBA0,KBA):- 3524 RP=KBA0.Type, 3525 ( Type=objectProperty -> OtherType=dataProperty ; OtherType=objectProperty ), 3526 WP=KBA0.OtherType, 3527 ( memberchk(H,RP) -> NRP=RP ; NRP=[H|RP] ), 3528 ( memberchk(H,WP) -> delete(WP,H,NWP) ; NWP=WP ), 3529 KBA1=KBA0.put(Type,NRP), 3530 KBA2=KBA1.put(OtherType,NWP), 3531 fix_wrongly_classified_properties(T,Type,KBA2,KBA). 3532 3533fix_duplicated_wrongly_classified_properties([],_DP,KBA,KBA). 3534 3535fix_duplicated_wrongly_classified_properties([H|T],DP,KBA0,KBA):- 3536 memberchk(H,DP),!, 3537 delete(DP,H,NDP), 3538 KBA1=KBA0.put(dataProperty,NDP), 3539 fix_duplicated_wrongly_classified_properties(T,DP,KBA1,KBA). 3540 3541fix_duplicated_wrongly_classified_properties([_H|T],DP,KBA0,KBA):- 3542 fix_duplicated_wrongly_classified_properties(T,DP,KBA0,KBA). 3543 3544 3545:- multifile trillo:add_axiom/1. 3546trilloadd_axiom(M:Ax):- 3547 assert(M:addKBName), 3548 %init_kb_atom(M), 3549 create_and_assert_axioms(M,Ax), 3550 retractall(M:addKBName), 3551 trillo:update_tabs(M,Ax). 3552 3553:- multifile trillo:add_axioms/1. 3554trilloadd_axioms(_:[]):-!. 3555 3556trilloadd_axioms(M:[H|T]) :- 3557 trillo:add_axiom(M:H), 3558 trillo:add_axioms(M:T). 3559 3560:- multifile trillo:remove_axiom/1. 3561trilloremove_axiom(M:Ax):- 3562 %print_message(warning,under_development), 3563 ( M:ns4query(NSList) -> true; NSList = []), 3564 expand_axiom(M,Ax,NSList,ExpAx), 3565 retract_axiom(M,ExpAx), 3566 retractall(M:owl(ExpAx,'ont')),!, 3567 trillo:reset_query. 3568 3569 3570/* 3571trillo:remove_axiom(M:subClassOf(C,D)):- 3572 print_message(warning,under_development), 3573 ( M:ns4query(NSList) -> true; NSList = []), 3574 expand_axiom(M,subClassOf(C,D),NSList,subClassOf(ExpC,ExpD)), 3575 remove_subClassOf(M,ExpC,ExpD), 3576 retract_axiom(M,subClassOf(ExpC,ExpD)), 3577 retractall(M:owl(subClassOf(ExpC,ExpD),'ont')),!. 3578 3579trillo:remove_axiom(M:Ax):- 3580 print_message(warning,under_development), 3581 ( M:ns4query(NSList) *-> true; NSList = []), 3582 Ax =.. [P|Args], 3583 ( (length(Args,1), Args = [IntArgs], is_list(IntArgs)) -> 3584 ( expand_all_ns(M,IntArgs,NSList,false,ArgsExp), 3585 AxEx =.. [P,ArgsExp] 3586 ) 3587 ; 3588 ( expand_all_ns(M,Args,NSList,false,ArgsExp), 3589 AxEx =.. [P|ArgsExp] 3590 ) 3591 ), 3592 retract_axiom(M,AxEx), 3593 retractall(M:owl(AxEx,'ont')),!. 3594*/ 3595 3596:- multifile trillo:remove_axioms/1. 3597trilloremove_axioms(_:[]):-!. 3598 3599trilloremove_axioms(M:[H|T]) :- 3600 trillo:remove_axiom(M:H), 3601 trillo:remove_axioms(M:T). 3602 3603test_and_assert(M,Ax,O):- 3604 (\+ M:owl(Ax,O) -> 3605 (assert_axiom(M,Ax,O), assert(M:owl(Ax,O))) 3606 ; 3607 true 3608 ). 3609 3610get_module(M):- 3611 pengine_self(Self), 3612 pengine_property(Self,module(M)),!. 3613get_module(M):- !, 3614 prolog_load_context(module,M). 3615 3616parse_rdf_from_owl_rdf_pred(String):- 3617 open_chars_stream(String,S), 3618 load_owl_from_stream(S). 3619 3620/* 3621create_and_assert_axioms(M,Axiom) :- 3622 Axiom=..[P|Args], 3623 ( M:ns4query(NSList) -> true; NSList = []), 3624 ( (length(Args,1), Args = [IntArgs], is_list(IntArgs)) -> 3625 ( expand_all_ns(M,IntArgs,NSList,ArgsExp), 3626 ExpAxiom =.. [P,ArgsExp] 3627 ) 3628 ; 3629 ( expand_axiom(M,Axiom,NSList,ExpAxiom) 3630 %NewtrilloAxiom =.. [P|ArgsExp] 3631 ) 3632 ), 3633 test_and_assert(M,ExpAxiom,'ont'). 3634*/ 3635 3636create_and_assert_axioms(M,Axiom) :- 3637 ( M:ns4query(NSList) -> true; NSList = []), 3638 expand_axiom(M,Axiom,NSList,ExpAxiom), 3639 test_and_assert(M,ExpAxiom,'ont').
3647add_rule(M,max_rule):- !, 3648 M:rules(D,ND), 3649 ( memberchk(max_rule,ND) -> true ; 3650 ( retractall(M:rules(_,_)), 3651 assert(M:rules(D,[max_rule|ND])) 3652 ) 3653 ), !. 3654 3655add_rule(M,or_rule):- !, 3656 M:rules(D,ND), 3657 ( memberchk(or_rule,ND) -> true ; 3658 ( retractall(M:rules(_,_)), 3659 assert(M:rules(D,[or_rule|ND])) 3660 ) 3661 ), !. 3662 3663add_rule(M,Rule):- 3664 M:rules(D,ND), 3665 ( memberchk(Rule,D) -> true ; 3666 ( retractall(M:rules(_,_)), 3667 assert(M:rules([Rule|D],ND)) 3668 ) 3669 ), !.
expressivity(I,R) -> I=1|2|3 (EL|ALC|S)
R=[0|1,0|1,0|1,0|1,0|1|2,0|1] ([H,R,O,I,N|Q,F])
/
3678add_expressivity(M,a):- 3679 M:expressivity(I,R), 3680 ( I > 1 ; ( retractall(M:expressivity(_,_)),assert(M:expressivity(2,R)))), !. 3681 3682add_expressivity(M,s):- 3683 M:expressivity(I,R), 3684 ( I > 2 ; ( retractall(M:expressivity(_,_)),assert(M:expressivity(3,R)))), !. 3685 3686add_expressivity(M,h):- 3687 M:expressivity(I,[H,R,O,I,Res,F]), 3688 ( H=1 ; ( retractall(M:expressivity(_,_)),assert(M:expressivity(I,[1,R,O,I,Res,F])))), !. 3689 3690add_expressivity(M,r):- 3691 M:expressivity(I,[H,R,O,I,Res,F]), 3692 ( R=1 ; ( retractall(M:expressivity(_,_)),assert(M:expressivity(I,[H,1,O,I,Res,F])))), !. 3693 3694add_expressivity(M,o):- 3695 M:expressivity(I,[H,R,O,I,Res,F]), 3696 ( O=1 ; ( retractall(M:expressivity(_,_)),assert(M:expressivity(I,[H,R,1,I,Res,F])))), !. 3697 3698add_expressivity(M,i):- 3699 M:expressivity(I,[H,R,O,I,Res,F]), 3700 ( I=1 ; ( retractall(M:expressivity(_,_)),assert(M:expressivity(I,[H,R,O,1,Res,F])))), !. 3701 3702add_expressivity(M,n):- 3703 M:expressivity(I,[H,R,O,I,Res,F]), 3704 ( Res>0 ; ( retractall(M:expressivity(_,_)),assert(M:expressivity(I,[H,R,O,I,1,F])))), !. 3705 3706add_expressivity(M,q):- 3707 M:expressivity(I,[H,R,O,I,Res,F]), 3708 ( Res>1 ; ( retractall(M:expressivity(_,_)),assert(M:expressivity(I,[H,R,O,I,2,F])))), !. 3709 3710add_expressivity(M,f):- 3711 M:expressivity(I,[H,R,O,I,Res,F]), 3712 ( F=1 ; ( retractall(M:expressivity(_,_)),assert(M:expressivity(I,[H,R,O,I,Res,1])))), !.
3720is_axiom(Axiom) :- 3721 functor(Axiom,Pred,Arity), 3722 axiompred(Pred/Arity),!. 3723 3724clean_up(M):- 3725 rdf_reset_db, 3726 M:(dynamic class/1, datatype/1, objectProperty/1, dataProperty/1, annotationProperty/1), 3727 M:(dynamic namedIndividual/1, anonymousIndividual/1, subClassOf/2, equivalentClasses/1, disjointClasses/1, disjointUnion/2), 3728 M:(dynamic subPropertyOf/2, equivalentProperties/1, disjointProperties/1, inverseProperties/2, propertyDomain/2, propertyRange/2), 3729 M:(dynamic functionalProperty/1, inverseFunctionalProperty/1, reflexiveProperty/1, irreflexiveProperty/1, symmetricProperty/1, asymmetricProperty/1, transitiveProperty/1, hasKey/2), 3730 M:(dynamic sameIndividual/1, differentIndividuals/1, classAssertion/2, propertyAssertion/3, negativePropertyAssertion/3), 3731 M:(dynamic annotationAssertion/3, annotation/3, ontology/1, ontologyAxiom/2, ontologyImport/2, ontologyVersionInfo/2), 3732 M:(dynamic owl/4, owl/3, owl/2, blanknode/3, outstream/1, aNN/3, annotation_r_node/4, axiom_r_node/4, owl_repository/2, trdf_setting/2), 3733 M:(dynamic ns4query/1), 3734 retractall(M:kb_atom([])), 3735 forall(trillo:axiom(M:A),retractall(M:)), 3736 retractall(M:blanknode(_,_,_)), 3737 retractall(M:aNN(_,_,_)), 3738 retractall(M:annotation_r_node(_,_,_)), 3739 retractall(M:axiom_r_node(_,_,_)), 3740 retractall(M:annotation(_,_,_)), 3741 retractall(M:owl(_,_,_)), 3742 retractall(M:owl(_,_,_,_)), 3743 retractall(M:owl(_,_)), 3744 retractall(M:ontologyAxiom(_,_)), 3745 retractall(M:ontologyImport(_,_)), 3746 retractall(M:ontologyVersionInfo(_,_)), 3747 retractall(M:rdf(_,_,_)). 3748 3749set_up(M):- 3750 M:(dynamic class/1, datatype/1, objectProperty/1, dataProperty/1, annotationProperty/1), 3751 M:(dynamic namedIndividual/1, anonymousIndividual/1, subClassOf/2, equivalentClasses/1, disjointClasses/1, disjointUnion/2), 3752 M:(dynamic subPropertyOf/2, equivalentProperties/1, disjointProperties/1, inverseProperties/2, propertyDomain/2, propertyRange/2), 3753 M:(dynamic functionalProperty/1, inverseFunctionalProperty/1, reflexiveProperty/1, irreflexiveProperty/1, symmetricProperty/1, asymmetricProperty/1, transitiveProperty/1, hasKey/2), 3754 M:(dynamic sameIndividual/1, differentIndividuals/1, classAssertion/2, propertyAssertion/3, negativePropertyAssertion/3), 3755 M:(dynamic annotationAssertion/3, annotation/3, ontology/1, ontologyAxiom/2, ontologyImport/2, ontologyVersionInfo/2), 3756 M:(dynamic owl/4, owl/3, owl/2, blanknode/3, outstream/1, aNN/3, annotation_r_node/4, axiom_r_node/4, owl_repository/2, trdf_setting/2), 3757 M:(dynamic ns4query/1, addKBName/0), 3758 M:(dynamic lpClassAssertion/1,lpPropertyAssertion/1,lpIndividuals/1), 3759 retractall(M:addKBName). 3760 %retractall(M:rules(_,_)), 3761 %assert(M:rules([],[])), 3762 %retractall(M:expressivity(_,_)), 3763 %assert(M:expressivity(1,[0,0,0,0,0,0])). 3764 3765set_up_kb_loading(M):- 3766 retractall(M:kb_atom(_)), 3767 init_kb_atom(M), 3768 retractall(M:addKBName), 3769 assert(M:addKBName). 3770 %format("Loading knowledge base...~n",[]), 3771 %statistics(walltime,[_,_]). 3772 3773init_kb_atom(M):- 3774 assert(M:kb_atom(kbatoms{annotationProperty:[],class:[],dataProperty:[],datatype:[],individual:[],objectProperty:[]})). 3775 3776init_kb_atom(M,AnnProps,Classes,DataProps,Datatypes,Inds,ObjectProps):- 3777 assert(M:kb_atom(kbatoms{annotationProperty:AnnProps,class:Classes,dataProperty:DataProps,datatype:Datatypes,individual:Inds,objectProperty:ObjectProps})). 3778 3779init_kb_atom(M,KB):- 3780 assert(M:kb_atom(kbatoms{annotationProperty:KB.annotationProperties,class:KB.classesName,dataProperty:KB.dataProperties,datatype:KB.datatypes,individual:KB.individuals,objectProperty:KB.objectProperties})). 3781 3782:- multifile sandbox:safe_primitive/1. 3783 3784sandbox:safe_primitive(trillo_utility_translation:load_owl(_)). 3785sandbox:safe_primitive(trillo_utility_translation:load_owl_from_string(_)). 3786sandbox:safe_primitive(trillo_utility_translation:expand_all_ns(_,_,_,_)). 3787sandbox:safe_primitive(trillo_utility_translation:expand_all_ns(_,_,_,_,_)). 3788%sandbox:safe_primitive(trillo_utility_translation:query_expand(_)). 3789 3790 3791 3792/* 3793class/1,datatype/1,objectProperty/1,dataProperty/1,annotationProperty/1,namedIndividual/1,anonymousIndividual/1, 3794subClassOf/2,equivalentClasses/1,disjointClasses/1,disjointUnion/2,subPropertyOf/2,equivalentProperties/1, 3795disjointProperties/1,inverseProperties/2,propertyDomain/2,propertyRange/2,functionalProperty/1, 3796inverseFunctionalProperty/1,reflexiveProperty/1,irreflexiveProperty/1,symmetricProperty/1,asymmetricProperty/1, 3797transitiveProperty/1,hasKey/2,sameIndividual/1,differentIndividuals/1,classAssertion/2,propertyAssertion/3, 3798negativePropertyAssertion/3,annotationAssertion/3,annotation/3,ontology/1,ontologyAxiom/2,ontologyImport/2, 3799ontologyVersionInfo/2,owl/4,owl/3,owl/2,blanknode/3,outstream/1,aNN/3,annotation_r_node/4,axiom_r_node/4, 3800owl_repository/2,trdf_setting/2, 3801*/
trillo_utility_translation
This module is base on utility_translation contained in the TRILL package version 6.0.2.
See https://github.com/rzese/trill/blob/master/doc/manual.pdf or http://ds.ing.unife.it/~rzese/software/trill/manual.html for details.