001/** 002 * Copyright (C) 2007 - 2016, Jens Lehmann 003 * 004 * This file is part of DL-Learner. 005 * 006 * DL-Learner is free software; you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation; either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * DL-Learner is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 018 */ 019package org.dllearner.utilities; 020 021import fuzzyowl2.*; 022import fuzzyowl2.parser.Parser; 023import org.semanticweb.owlapi.apibinding.OWLManager; 024import org.semanticweb.owlapi.model.*; 025import org.semanticweb.owlapi.search.EntitySearcher; 026import org.semanticweb.owlapi.util.SimpleShortFormProvider; 027import org.semanticweb.owlapi.vocab.OWLFacet; 028 029import java.io.File; 030import java.io.FileOutputStream; 031import java.io.PrintStream; 032import java.util.*; 033 034/** 035 * General class translating from OWL 2 into some fuzzy OWLClassExpression Logic language. 036 * Subclasses of Owl2ToFuzzyDescriptionLogic translate it into specific 037 * languages, such as the language of fuzzyDL, the language of DeLorean... 038 * The user must override most of the following methods: 039 * 040 * <ul> 041 <li>protected String getAtomicConceptName(OWLClass c)</li> 042 <li>protected String getAtomicDataPropertyName(OWLDataProperty p)</li> 043 <li>protected String getAtomicObjectPropertyName(OWLObjectProperty p)</li> 044 <li>protected String getBottomConceptName()</li> 045 <li>protected String getBottomDataPropertyName()</li> 046 <li>protected String getBottomObjectPropertyName()</li> 047 <li>protected String getDataAllValuesFromName(OWLDataPropertyExpression p, OWLDataRange range)</li> 048 <li>protected String getDataExactCardinalityRestrictionName(int card, OWLDataPropertyExpression p)</li> 049 <li>protected String getDataExactCardinalityRestrictionName(int card, OWLDataPropertyExpression p, OWLDataRange range)</li> 050 <li>protected String getDataHasValueName(OWLDataPropertyExpression p, OWLLiteral lit)</li> 051 <li>protected String getDataMaxCardinalityRestrictionName(int card, OWLDataPropertyExpression p)</li> 052 <li>protected String getDataMaxCardinalityRestrictionName(int card, OWLDataPropertyExpression p, OWLDataRange range)</li> 053 <li>protected String getDataMinCardinalityRestrictionName(int card, OWLDataPropertyExpression p)</li> 054 <li>protected String getDataMinCardinalityRestrictionName(int card, OWLDataPropertyExpression p, OWLDataRange range)</li> 055 <li>protected String getDataSomeValuesFromName(OWLDataPropertyExpression p, OWLDataRange range)</li> 056 <li>protected String getIndividualName(OWLIndividual i)</li> 057 <li>protected String getObjectAllValuesFromName(OWLObjectPropertyExpression p, OWLClassExpression c)</li> 058 <li>protected String getObjectComplementOfName(OWLClassExpression c)</li> 059 <li>protected String getObjectExactCardinalityRestrictionName(int card, OWLObjectPropertyExpression p)</li> 060 <li>protected String getObjectExactCardinalityRestrictionName(int card, OWLObjectPropertyExpression p, OWLClassExpression c)</li> 061 <li>protected String getObjectHasSelfName(OWLObjectPropertyExpression p)</li> 062 <li>protected String getObjectHasValueName(OWLObjectPropertyExpression p, OWLIndividual i)</li> 063 <li>protected String getObjectIntersectionOfName(Set<OWLClassExpression> operands)</li> 064 <li>protected String getObjectMaxCardinalityRestrictionName(int card, OWLObjectPropertyExpression p)</li> 065 <li>protected String getObjectMaxCardinalityRestrictionName(int card, OWLObjectPropertyExpression p, OWLClassExpression c)</li> 066 <li>protected String getObjectMinCardinalityRestrictionName(int card, OWLObjectPropertyExpression p)</li> 067 <li>protected String getObjectMinCardinalityRestrictionName(int card, OWLObjectPropertyExpression p, OWLClassExpression c)</li> 068 <li>protected String getObjectOneOfName(Set<OWLIndividual> set)</li> 069 <li>protected String getObjectSomeValuesFromName(OWLObjectPropertyExpression p, OWLClassExpression c)</li> 070 <li>protected String getObjectUnionOfName(Set<OWLClassExpression> operands)</li> 071 <li>protected String getShortName(OWLEntity e)</li> 072 <li>protected String getTopConceptName()</li> 073 <li>protected String getTopDataPropertyName()</li> 074 <li>protected String getTopObjectPropertyName()</li> 075 <li>protected void writeAsymmetricObjectPropertyAxiom(OWLObjectPropertyExpression p)</li> 076 <li>protected void writeChoquetConceptDefinition(String name, ChoquetConcept c)</li> 077 <li>protected void writeConceptAssertionAxiom(OWLIndividual i, OWLClassExpression c, double d)</li> 078 <li>protected void writeConceptDeclaration(OWLClassExpression c)</li> 079 <li>protected void writeDataPropertyAssertionAxiom(OWLIndividual i1, OWLLiteral i2, OWLDataPropertyExpression p, double d)</li> 080 <li>protected void writeDataPropertyDeclaration(OWLDataPropertyExpression dp)</li> 081 <li>protected void writeDataPropertyDomainAxiom(OWLDataPropertyExpression p, OWLClassExpression c)</li> 082 <li>protected void writeDataPropertyRangeAxiom(OWLDataPropertyExpression p, OWLDataRange c)</li> 083 <li>protected void writeDifferentIndividualsAxiom(Set<OWLIndividual> set)</li> 084 <li>protected void writeDisjointClassesAxiom(Set<OWLClassExpression> set)</li> 085 <li>protected void writeDisjointDataPropertiesAxiom(Set<OWLDataPropertyExpression> set)</li> 086 <li>protected void writeDisjointObjectPropertiesAxiom(Set<OWLObjectPropertyExpression> set)</li> 087 <li>protected void writeDisjointUnionAxiom(Set<OWLClassExpression> set)</li> 088 <li>protected void writeEquivalentClassesAxiom(Set<OWLClassExpression> set)</li> 089 <li>protected void writeEquivalentDataPropertiesAxiom(Set<OWLDataPropertyExpression> set)</li> 090 <li>protected void writeEquivalentObjectPropertiesAxiom(Set<OWLObjectPropertyExpression> set)</li> 091 <li>protected void writeFunctionalDataPropertyAxiom(OWLDataPropertyExpression p)</li> 092 <li>protected void writeFunctionalObjectPropertyAxiom(OWLObjectPropertyExpression p)</li> 093 <li>protected void writeFuzzyLogic(FuzzyLogic logic)</li> 094 <li>protected void writeFuzzyNominalConceptDefinition(String name, FuzzyNominalConcept c)</li> 095 <li>protected void writeInverseFunctionalObjectPropertyAxiom(OWLObjectPropertyExpression p)</li> 096 <li>protected void writeInverseObjectPropertiesAxiom(OWLObjectPropertyExpression p1, OWLObjectPropertyExpression p2)</li> 097 <li>protected void writeIrreflexiveObjectPropertyAxiom(OWLObjectPropertyExpression p)</li> 098 <li>protected void writeLeftShoulderFunctionDefinition(String name, LeftShoulderFunction dat)</li> 099 <li>protected void writeLinearFunctionDefinition(String name, LinearFunction dat)</li> 100 <li>protected void writeLinearModifierDefinition(String name, LinearModifier mod)</li> 101 <li>protected void writeModifiedConceptDefinition(String name, ModifiedConcept c)</li> 102 <li>protected void writeModifiedFunctionDefinition(String name, ModifiedFunction dat)</li> 103 <li>protected void writeModifiedPropertyDefinition(String name, ModifiedProperty c)</li> 104 <li>protected void writeNegativeDataPropertyAssertionAxiom(OWLIndividual i1, OWLLiteral i2, OWLDataPropertyExpression p, double d)</li> 105 <li>protected void writeNegativeObjectPropertyAssertionAxiom(OWLIndividual i1, OWLIndividual i2, OWLObjectPropertyExpression p, double d)</li> 106 <li>protected void writeObjectPropertyAssertionAxiom(OWLIndividual i1, OWLIndividual i2, OWLObjectPropertyExpression p, double d)</li> 107 <li>protected void writeObjectPropertyDeclaration(OWLObjectPropertyExpression op)</li> 108 <li>protected void writeObjectPropertyDomainAxiom(OWLObjectPropertyExpression p, OWLClassExpression c)</li> 109 <li>protected void writeObjectPropertyRangeAxiom(OWLObjectPropertyExpression p, OWLClassExpression c)</li> 110 <li>protected void writeOwaConceptDefinition(String name, OwaConcept c)</li> 111 <li>protected void writeQowaConceptDefinition(String name, QowaConcept c)</li> 112 <li>protected void writeQuasiSugenoConceptDefinition(String name, QuasiSugenoConcept c)</li> 113 <li>protected void writeReflexiveObjectPropertyAxiom(OWLObjectPropertyExpression p)</li> 114 <li>protected void writeRightShoulderFunctionDefinition(String name, RightShoulderFunction dat)</li> 115 <li>protected void writeSameIndividualAxiom(Set<OWLIndividual> set)</li> 116 <li>protected void writeSubclassOfAxiom(OWLClassExpression subclass, OWLClassExpression superclass, double d)</li> 117 <li>protected void writeSubDataPropertyOfAxiom(OWLDataPropertyExpression subProperty, OWLDataPropertyExpression superProperty, double d)</li> 118 <li>protected void writeSubObjectPropertyOfAxiom(OWLObjectPropertyExpression subProperty, OWLObjectPropertyExpression superProperty, double d)</li> 119 <li>protected void writeSubPropertyChainOfAxiom(List<OWLObjectPropertyExpression> chain, OWLObjectPropertyExpression superProperty, double d)</li> 120 <li>protected void writeSugenoConceptDefinition(String name, SugenoConcept c)</li> 121 <li>protected void writeSymmetricObjectPropertyAxiom(OWLObjectPropertyExpression p)</li> 122 <li>protected void writeTransitiveObjectPropertyAxiom(OWLObjectPropertyExpression p)</li> 123 <li>protected void writeTrapezoidalFunctionDefinition(String name, TrapezoidalFunction dat)</li> 124 <li>protected void writeTriangularFunctionDefinition(String name, TriangularFunction dat)</li> 125 <li>protected void writeTriangularModifierDefinition(String name, TriangularModifier mod)</li> 126 <li>protected void writeWeightedConceptDefinition(String name, WeightedConcept c)</li> 127 <li>protected void writeWeightedMaxConceptDefinition(String name, WeightedMaxConcept c)</li> 128 <li>protected void writeWeightedMinConceptDefinition(String name, WeightedMinConcept c)</li> 129 <li>protected void writeWeightedSumConceptDefinition(String name, WeightedSumConcept c)</li> 130 * </ul> 131 * 132 * @author Fernando Bobillo 133 */ 134public class FuzzyOwl2 135{ 136 137 protected OWLDataFactory dataFactory; 138 protected Hashtable<String, FuzzyConcept> definedConcepts; 139 protected Hashtable<String, FuzzyProperty> definedProperties; 140 public Hashtable<String, FuzzyDatatype> fuzzyDatatypes; 141 protected Hashtable<String, FuzzyModifier> fuzzyModifiers; 142 protected OWLAnnotationProperty label; 143 protected OWLOntologyManager manager; 144 protected String ontologyPath; 145 protected OWLOntology ontology; 146 protected Set<OWLOntology> ontologies; 147 protected SimpleShortFormProvider pm; 148 149 protected final double NEG_INFINITY = -10000; 150 protected final double POS_INFINITY = 10000; 151 152 /** 153 * Output (file, standard output...) 154 */ 155 protected static PrintStream out = System.out; 156 157 /** 158 * Constructor. 159 * @param input Path of the input ontology. 160 * @param output Path of the output file; null for the standard output. 161 */ 162 public FuzzyOwl2(String input, String output) 163 { 164 definedConcepts = new Hashtable<>(); 165 definedProperties = new Hashtable<>(); 166 fuzzyDatatypes = new Hashtable<>(); 167 fuzzyModifiers = new Hashtable<>(); 168 manager = OWLManager.createOWLOntologyManager(); 169 ontologyPath = input; 170 171 loadOntology(ontologyPath); 172 ontologies = new HashSet<>(); 173 ontologies.add(ontology); 174 175 // Imported ontologies 176 Set<OWLOntology> imports = manager.getImportsClosure(ontology); 177 if (imports != null) 178 ontologies.addAll(imports); 179 180 // If an output file is specified, try to open it. 181 // If not, or if there are problems opening it, we use the standard output. 182 if (output != null) 183 { 184 try { 185 out = new PrintStream(new FileOutputStream(output)); 186 } 187 catch (Exception ex) 188 { 189 printError("Could not load ontology: " + ex.getMessage()); 190 } 191 } 192 193 dataFactory = manager.getOWLDataFactory(); 194 if (ontology.getOntologyID().getOntologyIRI() == null) 195 ontologyPath = ""; 196 else 197 ontologyPath = ontology.getOntologyID().getOntologyIRI().toString(); 198 pm = new SimpleShortFormProvider(); 199 200 label = dataFactory.getOWLAnnotationProperty(IRI.create(ontologyPath + "#" + "fuzzyLabel")); 201 } 202 203 public void setPrintStream(PrintStream ps){ 204 out = ps; 205 } 206 207 protected void loadOntology(String ontologyPath) 208 { 209 try 210 { 211 // Try ontologyPath as the path of a local file 212 File f = new File(ontologyPath); 213 IRI iri = IRI.create(f); 214 ontology = manager.loadOntologyFromOntologyDocument(iri); 215 } 216 catch (Exception e) 217 { 218 // Try ontologyPath as an IRI 219 IRI iri = IRI.create(ontologyPath); 220 try { 221 ontology = manager.loadOntologyFromOntologyDocument(iri); 222 } 223 catch (OWLOntologyCreationException ex) 224 { 225 printError("Could not load ontology: " + ex.getMessage()); 226 } 227 } 228 } 229 230 /** 231 * Prints an error message in the standard output and finishes the execution. 232 * @param s An error message. 233 */ 234 protected static void exit(String s) 235 { 236 System.out.println(s); 237 System.exit(0); 238 } 239 240 /** 241 * Prints a string in the desired PrintStream, unless it contains a null value. 242 */ 243 protected static void print(String s) 244 { 245 if (s != null && !s.contains(" null")) 246 out.println(s); 247 } 248 249 /** 250 * Prints an error string in the standard error. 251 * The parameter could be used in the future to write in the desired PrintStream. 252 */ 253 protected static void printError(String s) 254 { 255 System.err.println(s); 256 } 257 258 /** 259 * @param args Two arguments: the input OWL 2 ontology, and the output fuzzy ontology in fuzzyDL syntax. 260 */ 261 public static void main(String[] args) 262 { 263 String[] returnValue = processParameters(args); 264 FuzzyOwl2 f = new FuzzyOwl2(returnValue[0], returnValue[1]); 265 f.translateOwl2Ontology(); 266 } 267 268 /** 269 * Translates an OWL 2 ontology into a fuzzy one, processing the OWL 2 annotations. 270 */ 271 public void translateOwl2Ontology() 272 { 273 processOntologyAnnotations(); 274 processDatatypeAnnotations(); 275 processConceptAnnotations(); 276 processPropertyAnnotations(); 277 processOntologyAxioms(); 278 } 279 280 /** 281 * Write annotations on the ontology. 282 */ 283 protected void processOntologyAnnotations() 284 { 285 for(OWLOntology o : ontologies) 286 { 287 Set<OWLAnnotation> annotations = o.getAnnotations(); 288 289 for (OWLAnnotation ax : annotations) 290 { 291 if (ax.getProperty().compareTo(label) != 0) 292 continue; 293 294 OWLAnnotationValue value = ax.getValue(); 295 FuzzyLogic logic = Parser.getLogic(value.toString()); 296 writeFuzzyLogic(logic); 297 } 298 } 299 } 300 301 // We annotate left, right, triangular, and trapezoidal functions. 302 private void writeType1Datatypes(Object o, String name) 303 { 304 if (o instanceof LeftShoulderFunction) 305 { 306 LeftShoulderFunction dat = (LeftShoulderFunction) o; 307 double k[] = new double[2]; 308 getK1AndK2(name, k); 309 setK1AndK2(dat, k); 310 fuzzyDatatypes.put(name, dat); 311 writeLeftShoulderFunctionDefinition(name, dat); 312 } 313 else if (o instanceof RightShoulderFunction) 314 { 315 RightShoulderFunction dat = (RightShoulderFunction) o; 316 double k[] = new double[2]; 317 getK1AndK2(name, k); 318 setK1AndK2(dat, k); 319 fuzzyDatatypes.put(name, dat); 320 writeRightShoulderFunctionDefinition(name, dat); 321 } 322 else if (o instanceof TriangularFunction) 323 { 324 TriangularFunction dat = (TriangularFunction) o; 325 double k[] = new double[2]; 326 getK1AndK2(name, k); 327 setK1AndK2(dat, k); 328 fuzzyDatatypes.put(name, dat); 329 writeTriangularFunctionDefinition(name, dat); 330 } 331 else if (o instanceof TrapezoidalFunction) 332 { 333 TrapezoidalFunction dat = (TrapezoidalFunction) o; 334 double k[] = new double[2]; 335 getK1AndK2(name, k); 336 setK1AndK2(dat, k); 337 fuzzyDatatypes.put(name, dat); 338 writeTrapezoidalFunctionDefinition(name, dat); 339 } 340 else if (o instanceof LinearFunction) 341 { 342 LinearFunction dat = (LinearFunction) o; 343 double k[] = new double[2]; 344 getK1AndK2(name, k); 345 setK1AndK2(dat, k); 346 fuzzyDatatypes.put(name, dat); 347 writeLinearFunctionDefinition(name, dat); 348 } 349 } 350 351 // We annotate linear and triangular modifiers. 352 private void writeType2Datatypes(Object o, String name) 353 { 354 if (o instanceof TriangularModifier) 355 { 356 TriangularModifier mod = (TriangularModifier) o; 357 fuzzyModifiers.put(name, mod); 358 writeTriangularModifierDefinition(name, mod); 359 } 360 else if (o instanceof LinearModifier) 361 { 362 LinearModifier mod = (LinearModifier) o; 363 fuzzyModifiers.put(name, mod); 364 writeLinearModifierDefinition(name, mod); 365 } 366 } 367 368 // We annotate modified functions. 369 private void writeType3Datatypes(Object o, String name) 370 { 371 if (o instanceof ModifiedFunction) 372 { 373 ModifiedFunction dat = (ModifiedFunction) o; 374 fuzzyDatatypes.put(name, dat); 375 writeModifiedFunctionDefinition(name, dat); 376 } 377 } 378 379 /** 380 * Write fuzzy datatypes and modifiers definitions, defined with OWL 2 concept annotations. 381 */ 382 protected void processDatatypeAnnotations() 383 { 384 /* 385 * Step 1. We annotate left, right, triangular, trapezoidal, and linear functions. 386 * Step 2. We annotate linear and triangular modifiers. 387 * Step 3. We annotate modified functions. 388 */ 389 for(OWLOntology o : ontologies) 390 { 391 for (OWLDeclarationAxiom ax : o.getAxioms(AxiomType.DECLARATION)) 392 { 393 OWLEntity ent = ax.getEntity(); 394 if (ent.isOWLDatatype()) 395 { 396 OWLDatatype dt = ent.asOWLDatatype(); 397 Collection<OWLAnnotation> annotations = EntitySearcher.getAnnotations(dt, o, label); 398 if (annotations != null) 399 { 400 if (annotations.size() > 1) 401 exit("Error: There are more than" + annotations.size() + " annotations for datatype " + dt + "."); 402 else if (annotations.size() == 1) 403 { 404 Iterator<OWLAnnotation> it = annotations.iterator(); 405 OWLAnnotation next = it.next(); 406 Object ob = Parser.getDatatype(next.getValue().toString()); 407 if (ob != null) 408 writeType1Datatypes(ob, getShortName(dt)); 409 } 410 } 411 } 412 } 413 414 for (OWLDeclarationAxiom ax : o.getAxioms(AxiomType.DECLARATION)) 415 { 416 OWLEntity ent = ax.getEntity(); 417 if (ent.isOWLDatatype()) 418 { 419 OWLDatatype dt = ent.asOWLDatatype(); 420 Collection<OWLAnnotation> annotations = EntitySearcher.getAnnotations(dt, o, label); 421 if (annotations != null) 422 { 423 if (annotations.size() == 1) 424 { 425 Iterator<OWLAnnotation> it = annotations.iterator(); 426 OWLAnnotation next = it.next(); 427 Object ob = Parser.getDatatype(next.getValue().toString()); 428 if (ob != null) 429 writeType2Datatypes(ob, getShortName(dt)); 430 } 431 } 432 } 433 } 434 435 for (OWLDeclarationAxiom ax : o.getAxioms(AxiomType.DECLARATION)) 436 { 437 OWLEntity ent = ax.getEntity(); 438 if (ent.isOWLDatatype()) 439 { 440 OWLDatatype dt = ent.asOWLDatatype(); 441 Collection<OWLAnnotation> annotations = EntitySearcher.getAnnotations(dt, o, label); 442 if (annotations != null) 443 { 444 if (annotations.size() == 1) 445 { 446 Iterator<OWLAnnotation> it = annotations.iterator(); 447 OWLAnnotation next = it.next(); 448 Object ob = Parser.getDatatype(next.getValue().toString()); 449 if (ob != null) 450 writeType3Datatypes(ob, getShortName(dt)); 451 } 452 } 453 } 454 } 455 } 456 } 457 458 /** 459 * Write fuzzy concept definitions, defined with OWL 2 concept annotations. 460 */ 461 protected void processConceptAnnotations() 462 { 463 for(OWLOntology o : ontologies) 464 { 465 for (OWLDeclarationAxiom ax : o.getAxioms(AxiomType.DECLARATION)) 466 { 467 OWLEntity ent = ax.getEntity(); 468 if (ent.isOWLClass()) 469 { 470 OWLClass cls = ent.asOWLClass(); 471 Collection<OWLAnnotation> annotations = EntitySearcher.getAnnotations(cls, o, label); 472 473 if (annotations.size() > 1) 474 exit("Error: There are " + annotations.size() + " class annotations for " + cls + "."); 475 else if (annotations.size() == 1) 476 { 477 String name = getShortName(cls); 478 479 ConceptDefinition c = Parser.getDefinedConcept(annotations.iterator().next().getValue().toString()); 480 if (c != null) 481 { 482 switch (c.getType()) 483 { 484 case MODIFIED_CONCEPT: 485 String modName = c.getFuzzyModifier(); 486 if (fuzzyModifiers.containsKey(modName)) 487 { 488 ModifiedConcept md = new ModifiedConcept(modName, c.getFuzzyConcept()); 489 definedConcepts.put(name, md); 490 writeModifiedConceptDefinition(name, md); 491 } 492 else 493 exit("Error: Fuzzy modifier " + modName + " not defined."); 494 break; 495 496 case FUZZY_NOMINAL: 497 FuzzyNominalConcept nc = new FuzzyNominalConcept(c.getNumber(), c.getIndividual()); 498 definedConcepts.put(name, nc); 499 writeFuzzyNominalConceptDefinition(name, nc); 500 break; 501 502 case WEIGHTED_CONCEPT: 503 WeightedConcept wc = new WeightedConcept(c.getNumber(), c.getFuzzyConcept()); 504 definedConcepts.put(name, wc); 505 writeWeightedConceptDefinition(name, wc); 506 break; 507 508 case WEIGHTED_MAX: 509 List<ConceptDefinition> sourceList = c.getWeightedConcepts(); 510 ArrayList<WeightedConcept> list = new ArrayList<>(); 511 for(ConceptDefinition def : sourceList) 512 list.add(new WeightedConcept(def.getNumber(), def.getFuzzyConcept() ) ); 513 WeightedMaxConcept wmax = new WeightedMaxConcept(list); 514 definedConcepts.put(name, wmax); 515 writeWeightedMaxConceptDefinition(name, wmax); 516 break; 517 518 case WEIGHTED_MIN: 519 sourceList = c.getWeightedConcepts(); 520 list = new ArrayList<>(); 521 for(ConceptDefinition def : sourceList) 522 list.add(new WeightedConcept(def.getNumber(), def.getFuzzyConcept() ) ); 523 WeightedMinConcept wmin = new WeightedMinConcept(list); 524 definedConcepts.put(name, wmin); 525 writeWeightedMinConceptDefinition(name, wmin); 526 break; 527 528 case WEIGHTED_SUM: 529 sourceList = c.getWeightedConcepts(); 530 list = new ArrayList<>(); 531 for(ConceptDefinition def : sourceList) 532 list.add(new WeightedConcept(def.getNumber(), def.getFuzzyConcept() ) ); 533 WeightedSumConcept wsum = new WeightedSumConcept(list); 534 definedConcepts.put(name, wsum); 535 writeWeightedSumConceptDefinition(name, wsum); 536 break; 537 538 case OWA: 539 List<Double> weights = c.getWeights(); 540 List<String> concepts = c.getConcepts(); 541 if (weights.size() != concepts.size()) 542 exit("Error: OWA concept " + name + " has different number of weights and concepts."); 543 else 544 { 545 OwaConcept owa = new OwaConcept(weights, concepts); 546 definedConcepts.put(name, owa); 547 writeOwaConceptDefinition(name, owa); 548 } 549 break; 550 551 case CHOQUET: 552 weights = c.getWeights(); 553 concepts = c.getConcepts(); 554 if (weights.size() != concepts.size()) 555 exit("Error: Choquet concept " + name + " has different number of weights and concepts."); 556 else 557 { 558 ChoquetConcept owa = new ChoquetConcept(weights, concepts); 559 definedConcepts.put(name, owa); 560 writeChoquetConceptDefinition(name, owa); 561 } 562 break; 563 564 case SUGENO: 565 weights = c.getWeights(); 566 concepts = c.getConcepts(); 567 if (weights.size() != concepts.size()) 568 exit("Error: Sugeno concept " + name + " has different number of weights and concepts."); 569 else 570 { 571 SugenoConcept owa = new SugenoConcept(weights, concepts); 572 definedConcepts.put(name, owa); 573 writeSugenoConceptDefinition(name, owa); 574 } 575 break; 576 577 case QUASI_SUGENO: 578 weights = c.getWeights(); 579 concepts = c.getConcepts(); 580 if (weights.size() != concepts.size()) 581 exit("Error: QuasiSugeno concept " + name + " has different number of weights and concepts."); 582 else 583 { 584 QuasiSugenoConcept owa = new QuasiSugenoConcept(weights, concepts); 585 definedConcepts.put(name, owa); 586 writeQuasiSugenoConceptDefinition(name, owa); 587 } 588 break; 589 590 case QUANTIFIER_OWA: 591 String q = c.getQuantifier(); 592 if (!fuzzyDatatypes.containsKey(q)) 593 exit("Error: Quantifier " + q + " not defined."); 594 else // if (fuzzyDatatypes.containsKey(q)) 595 { 596 FuzzyDatatype def = fuzzyDatatypes.get(q); 597 if (!(def instanceof RightShoulderFunction) && !(def instanceof LinearFunction)) 598 exit("Error: Quantifier " + q + " must be a right-shoulder or a linear function."); 599 else { 600 concepts = c.getConcepts(); 601 QowaConcept qowa = new QowaConcept(q, concepts); 602 definedConcepts.put(name, qowa); 603 writeQowaConceptDefinition(name, qowa); 604 } 605 } 606 break; 607 } 608 } 609 } 610 } 611 } 612 } 613 } 614 615 /** 616 * Write fuzzy property definitions, defined with OWL 2 concept annotations. 617 */ 618 protected void processPropertyAnnotations() 619 { 620 for(OWLOntology o : ontologies) 621 { 622 for (OWLDeclarationAxiom ax : o.getAxioms(AxiomType.DECLARATION)) 623 { 624 OWLEntity ent = ax.getEntity(); 625 626 if (ent.isOWLObjectProperty() || ent.isOWLDataProperty()) 627 { 628 OWLProperty prop; 629 if (ent.isOWLObjectProperty() ) 630 prop = ent.asOWLObjectProperty(); 631 else // if (ent.isOWLDataProperty() ) 632 prop = ent.asOWLDataProperty(); 633 634 Collection<OWLAnnotation> annotations = EntitySearcher.getAnnotations(prop, o, label); 635 636 if (annotations.size() > 1) 637 exit("Error: There are " + annotations.size() + " property annotations for " + prop + "."); 638 else if (annotations.size() == 1) 639 { 640 PropertyDefinition pro = Parser.getDefinedProperty(annotations.iterator().next().getValue().toString()); 641 if (pro != null) 642 { 643 if (pro.getType() == PropertyDefinition.PropertyType.MODIFIED_PROPERTY) 644 { 645 String name = getShortName(prop); 646 String modName = pro.getFuzzyModifier(); 647 if (fuzzyModifiers.containsKey(modName)) 648 { 649 ModifiedProperty mp = new ModifiedProperty(modName, pro.getProperty()); 650 definedProperties.put(name, mp); 651 writeModifiedPropertyDefinition(name, mp); 652 } 653 else 654 exit("Error: Fuzzy modifier " + modName + " not defined."); 655 } 656 } 657 } 658 } 659 } 660 } 661 } 662 663 /** 664 * Write the axioms of the OWL 2 ontology. They can have annotations or not. 665 */ 666 protected void processOntologyAxioms() 667 { 668 669 for(OWLOntology o : ontologies) 670 { 671 672 // ****** 673 // TBOx 674 // ****** 675 for (OWLDisjointClassesAxiom ax : o.getAxioms(AxiomType.DISJOINT_CLASSES)) 676 { 677 Set<OWLClassExpression> c = ax.getClassExpressions(); 678 writeDisjointClassesAxiom(c); 679 } 680 681 for (OWLDisjointUnionAxiom ax : o.getAxioms(AxiomType.DISJOINT_UNION)) 682 { 683 Set<OWLClassExpression> c = ax.getClassExpressions(); 684 writeDisjointUnionAxiom(c); 685 } 686 687 for (OWLSubClassOfAxiom ax : o.getAxioms(AxiomType.SUBCLASS_OF)) 688 { 689 OWLClassExpression subclass = ax.getSubClass(); 690 OWLClassExpression superclass = ax.getSuperClass(); 691 double d = getDegree(ax); 692 writeSubclassOfAxiom(subclass, superclass, d); 693 } 694 695 for (OWLEquivalentClassesAxiom ax : o.getAxioms(AxiomType.EQUIVALENT_CLASSES)) 696 { 697 Set<OWLClassExpression> c = ax.getClassExpressions(); 698 writeEquivalentClassesAxiom(c); 699 } 700 701 for (OWLClass c : o.getClassesInSignature()) 702 { 703 if (c.isTopEntity() == false) 704 writeConceptDeclaration(c); 705 } 706 707 708 // ****** 709 // RBOx 710 // ****** 711 712 for (OWLSubObjectPropertyOfAxiom ax : o.getAxioms(AxiomType.SUB_OBJECT_PROPERTY)) 713 { 714 OWLObjectPropertyExpression subProperty = ax.getSubProperty(); 715 OWLObjectPropertyExpression superProperty = ax.getSuperProperty(); 716 double d = getDegree(ax); 717 writeSubObjectPropertyOfAxiom(subProperty, superProperty, d); 718 } 719 720 for (OWLSubDataPropertyOfAxiom ax : o.getAxioms(AxiomType.SUB_DATA_PROPERTY)) 721 { 722 OWLDataPropertyExpression subProperty = ax.getSubProperty(); 723 OWLDataPropertyExpression superProperty = ax.getSuperProperty(); 724 double d = getDegree(ax); 725 writeSubDataPropertyOfAxiom(subProperty, superProperty, d); 726 } 727 728 for (OWLSubPropertyChainOfAxiom ax : o.getAxioms(AxiomType.SUB_PROPERTY_CHAIN_OF)) 729 { 730 List<OWLObjectPropertyExpression> chain = ax.getPropertyChain(); 731 OWLObjectPropertyExpression superProperty = ax.getSuperProperty(); 732 double d = getDegree(ax); 733 writeSubPropertyChainOfAxiom(chain, superProperty, d); 734 } 735 736 for (OWLEquivalentObjectPropertiesAxiom ax : o.getAxioms(AxiomType.EQUIVALENT_OBJECT_PROPERTIES)) 737 { 738 Set<OWLObjectPropertyExpression> set = ax.getProperties(); 739 writeEquivalentObjectPropertiesAxiom(set); 740 } 741 742 for (OWLEquivalentDataPropertiesAxiom ax : o.getAxioms(AxiomType.EQUIVALENT_DATA_PROPERTIES)) 743 { 744 Set<OWLDataPropertyExpression> set = ax.getProperties(); 745 writeEquivalentDataPropertiesAxiom(set); 746 } 747 748 for (OWLTransitiveObjectPropertyAxiom ax : o.getAxioms(AxiomType.TRANSITIVE_OBJECT_PROPERTY)) 749 { 750 OWLObjectPropertyExpression p = ax.getProperty(); 751 writeTransitiveObjectPropertyAxiom(p); 752 } 753 754 for (OWLSymmetricObjectPropertyAxiom ax : o.getAxioms(AxiomType.SYMMETRIC_OBJECT_PROPERTY)) 755 { 756 OWLObjectPropertyExpression p = ax.getProperty(); 757 writeSymmetricObjectPropertyAxiom(p); 758 } 759 760 for (OWLAsymmetricObjectPropertyAxiom ax : o.getAxioms(AxiomType.ASYMMETRIC_OBJECT_PROPERTY)) 761 { 762 OWLObjectPropertyExpression p = ax.getProperty(); 763 writeAsymmetricObjectPropertyAxiom(p); 764 } 765 766 for (OWLReflexiveObjectPropertyAxiom ax : o.getAxioms(AxiomType.REFLEXIVE_OBJECT_PROPERTY)) 767 { 768 OWLObjectPropertyExpression p = ax.getProperty(); 769 writeReflexiveObjectPropertyAxiom(p); 770 } 771 772 for (OWLIrreflexiveObjectPropertyAxiom ax : o.getAxioms(AxiomType.IRREFLEXIVE_OBJECT_PROPERTY)) 773 { 774 OWLObjectPropertyExpression p = ax.getProperty(); 775 writeIrreflexiveObjectPropertyAxiom(p); 776 } 777 778 for (OWLFunctionalObjectPropertyAxiom ax : o.getAxioms(AxiomType.FUNCTIONAL_OBJECT_PROPERTY)) 779 { 780 OWLObjectPropertyExpression p = ax.getProperty(); 781 writeFunctionalObjectPropertyAxiom(p); 782 } 783 784 for (OWLFunctionalDataPropertyAxiom ax : o.getAxioms(AxiomType.FUNCTIONAL_DATA_PROPERTY)) 785 { 786 OWLDataPropertyExpression p = ax.getProperty(); 787 writeFunctionalDataPropertyAxiom(p); 788 } 789 790 for (OWLInverseObjectPropertiesAxiom ax : o.getAxioms(AxiomType.INVERSE_OBJECT_PROPERTIES)) 791 { 792 OWLObjectPropertyExpression p1 = ax.getFirstProperty(); 793 OWLObjectPropertyExpression p2 = ax.getSecondProperty(); 794 writeInverseObjectPropertiesAxiom(p1, p2); 795 } 796 797 for (OWLInverseFunctionalObjectPropertyAxiom ax : o.getAxioms(AxiomType.INVERSE_FUNCTIONAL_OBJECT_PROPERTY)) 798 { 799 OWLObjectPropertyExpression p = ax.getProperty(); 800 writeInverseFunctionalObjectPropertyAxiom(p); 801 } 802 803 for (OWLObjectPropertyDomainAxiom ax : o.getAxioms(AxiomType.OBJECT_PROPERTY_DOMAIN)) 804 { 805 OWLObjectPropertyExpression p = ax.getProperty(); 806 OWLClassExpression c = ax.getDomain(); 807 writeObjectPropertyDomainAxiom(p, c); 808 } 809 810 for (OWLObjectPropertyRangeAxiom ax : o.getAxioms(AxiomType.OBJECT_PROPERTY_RANGE)) 811 { 812 OWLObjectPropertyExpression p = ax.getProperty(); 813 OWLClassExpression c = ax.getRange(); 814 writeObjectPropertyRangeAxiom(p, c); 815 } 816 817 for (OWLDataPropertyDomainAxiom ax : o.getAxioms(AxiomType.DATA_PROPERTY_DOMAIN)) 818 { 819 OWLDataPropertyExpression p = ax.getProperty(); 820 OWLClassExpression c = ax.getDomain(); 821 writeDataPropertyDomainAxiom(p, c); 822 } 823 824 for (OWLDataPropertyRangeAxiom ax : o.getAxioms(AxiomType.DATA_PROPERTY_RANGE)) 825 { 826 OWLDataPropertyExpression p = ax.getProperty(); 827 OWLDataRange range = ax.getRange(); 828 writeDataPropertyRangeAxiom(p, range); 829 } 830 831 for (OWLDisjointObjectPropertiesAxiom ax : o.getAxioms(AxiomType.DISJOINT_OBJECT_PROPERTIES)) 832 { 833 Set<OWLObjectPropertyExpression> properties = ax.getProperties(); 834 writeDisjointObjectPropertiesAxiom(properties); 835 } 836 837 for (OWLDisjointDataPropertiesAxiom ax : o.getAxioms(AxiomType.DISJOINT_DATA_PROPERTIES)) 838 { 839 Set<OWLDataPropertyExpression> properties = ax.getProperties(); 840 writeDisjointDataPropertiesAxiom(properties); 841 } 842 843/* 844 for (OWLDataPropertyExpression dp : o.getDataPropertiesInSignature()) 845 { 846 writeDataPropertyDeclaration(dp); 847 } 848 849 850 for (OWLObjectPropertyExpression op : o.getObjectPropertiesInSignature()) 851 { 852 writeObjectPropertyDeclaration(op); 853 } 854*/ 855 856 // ****** 857 // ABOx 858 // ****** 859 860 for (OWLClassAssertionAxiom ax : o.getAxioms(AxiomType.CLASS_ASSERTION)) 861 { 862 OWLClassExpression c = ax.getClassExpression(); 863 OWLIndividual i = ax.getIndividual(); 864 double d = getDegree(ax); 865 writeConceptAssertionAxiom(i, c, d); 866 } 867 868 for (OWLObjectPropertyAssertionAxiom ax : o.getAxioms(AxiomType.OBJECT_PROPERTY_ASSERTION)) 869 { 870 OWLObjectPropertyExpression p = ax.getProperty(); 871 OWLIndividual i1 = ax.getSubject(); 872 OWLIndividual i2 = ax.getObject(); 873 double d = getDegree(ax); 874 writeObjectPropertyAssertionAxiom(i1, i2, p, d); 875 } 876 877 for (OWLDataPropertyAssertionAxiom ax : o.getAxioms(AxiomType.DATA_PROPERTY_ASSERTION)) 878 { 879 OWLDataPropertyExpression p = ax.getProperty(); 880 OWLIndividual i1 = ax.getSubject(); 881 OWLLiteral i2 = ax.getObject(); 882 double d = getDegree(ax); 883 writeDataPropertyAssertionAxiom(i1, i2, p, d); 884 } 885 886 for (OWLNegativeObjectPropertyAssertionAxiom ax : o.getAxioms(AxiomType.NEGATIVE_OBJECT_PROPERTY_ASSERTION)) 887 { 888 OWLObjectPropertyExpression p = ax.getProperty(); 889 OWLIndividual i1 = ax.getSubject(); 890 OWLIndividual i2 = ax.getObject(); 891 double d = getDegree(ax); 892 writeNegativeObjectPropertyAssertionAxiom(i1, i2, p, d); 893 } 894 895 for (OWLNegativeDataPropertyAssertionAxiom ax : o.getAxioms(AxiomType.NEGATIVE_DATA_PROPERTY_ASSERTION)) 896 { 897 OWLDataPropertyExpression p = ax.getProperty(); 898 OWLIndividual i1 = ax.getSubject(); 899 OWLLiteral i2 = ax.getObject(); 900 double d = getDegree(ax); 901 writeNegativeDataPropertyAssertionAxiom(i1, i2, p, d); 902 } 903 904 for (OWLSameIndividualAxiom ax: o.getAxioms(AxiomType.SAME_INDIVIDUAL)) 905 { 906 Set<OWLIndividual> set = ax.getIndividuals(); 907 writeSameIndividualAxiom(set); 908 } 909 910 for (OWLDifferentIndividualsAxiom ax: o.getAxioms(AxiomType.DIFFERENT_INDIVIDUALS)) 911 { 912 Set<OWLIndividual> set = ax.getIndividuals(); 913 writeDifferentIndividualsAxiom(set); 914 } 915 } 916 } 917 918 /** 919 * Gets a String representation of an OWL 2 class. 920 * 921 * @param c An OWL 2 class. 922 * @return A String representation of c. 923 */ 924 public String getClassName(OWLClassExpression c) 925 { 926 927 switch (c.getClassExpressionType()) 928 { 929 case OWL_CLASS: 930 931 OWLClass d = (OWLClass) c; 932 if (d.isOWLThing()) 933 return getTopConceptName(); 934 else if (d.isOWLNothing()) 935 return getBottomConceptName(); 936 else 937 // Atomic concept 938 return getAtomicConceptName(d); 939 940 case OBJECT_INTERSECTION_OF: 941 942 Set<OWLClassExpression> operands = ((OWLObjectIntersectionOf) c).getOperands(); 943 return getObjectIntersectionOfName(operands); 944 945 case OBJECT_UNION_OF: 946 947 operands = ((OWLObjectUnionOf) c).getOperands(); 948 return getObjectUnionOfName(operands); 949 950 case OBJECT_SOME_VALUES_FROM: 951 952 OWLObjectPropertyExpression p = ((OWLObjectSomeValuesFrom) c).getProperty(); 953 OWLClassExpression e = ((OWLObjectSomeValuesFrom) c).getFiller(); 954 return getObjectSomeValuesFromName(p, e); 955 956 case OBJECT_ALL_VALUES_FROM: 957 958 p = ((OWLObjectAllValuesFrom) c).getProperty(); 959 e = ((OWLObjectAllValuesFrom) c).getFiller(); 960 return getObjectAllValuesFromName(p, e); 961 962 case DATA_SOME_VALUES_FROM: 963 964 OWLDataPropertyExpression dp = ((OWLDataSomeValuesFrom) c).getProperty(); 965 OWLDataRange range = ((OWLDataSomeValuesFrom) c).getFiller(); 966 return getDataSomeValuesFromName(dp, range); 967 968 case DATA_ALL_VALUES_FROM: 969 970 dp = ((OWLDataAllValuesFrom) c).getProperty(); 971 range = ((OWLDataAllValuesFrom) c).getFiller(); 972 return getDataAllValuesFromName(dp, range); 973 974 case OBJECT_COMPLEMENT_OF: 975 976 e = ((OWLObjectComplementOf) c).getOperand(); 977 return getObjectComplementOfName(e); 978 979 case OBJECT_HAS_SELF: 980 981 p = ((OWLObjectHasSelf) c).getProperty(); 982 return getObjectHasSelfName(p); 983 984 case OBJECT_ONE_OF: 985 986 Set<OWLIndividual> set = ((OWLObjectOneOf) c).getIndividuals(); 987 return getObjectOneOfName(set); 988 989 case OBJECT_HAS_VALUE: 990 991 OWLObjectHasValue hasValue = (OWLObjectHasValue) c; 992 OWLIndividual i = hasValue.getFiller(); 993 p = hasValue.getProperty(); 994 return getObjectHasValueName(p, i); 995 996 case DATA_HAS_VALUE: 997 998 OWLDataHasValue dataHasValue = (OWLDataHasValue) c; 999 OWLLiteral lit = dataHasValue.getFiller(); 1000 dp = dataHasValue.getProperty(); 1001 return getDataHasValueName(dp, lit); 1002 1003 case OBJECT_MAX_CARDINALITY: 1004 1005 OWLObjectCardinalityRestriction q = (OWLObjectMaxCardinality) c; 1006 p = q.getProperty(); 1007 int card = q.getCardinality(); 1008 if (q.isQualified()) 1009 return getObjectMaxCardinalityRestrictionName(card, p, q.getFiller()); 1010 else 1011 return getObjectMaxCardinalityRestrictionName(card, p); 1012 1013 case OBJECT_MIN_CARDINALITY: 1014 1015 q = (OWLObjectMinCardinality) c; 1016 p = q.getProperty(); 1017 card = q.getCardinality(); 1018 if (q.isQualified()) 1019 return getObjectMinCardinalityRestrictionName(card, p, q.getFiller()); 1020 else 1021 return getObjectMinCardinalityRestrictionName(card, p); 1022 1023 case OBJECT_EXACT_CARDINALITY: 1024 1025 q = (OWLObjectExactCardinality) c; 1026 p = q.getProperty(); 1027 card = q.getCardinality(); 1028 if (q.isQualified()) 1029 return getObjectExactCardinalityRestrictionName(card, p, q.getFiller()); 1030 else 1031 return getObjectExactCardinalityRestrictionName(card, p); 1032 1033 case DATA_MAX_CARDINALITY: 1034 1035 OWLDataCardinalityRestriction dq = (OWLDataMaxCardinality) c; 1036 dp = dq.getProperty(); 1037 card = dq.getCardinality(); 1038 if (dq.isQualified()) 1039 return getDataMaxCardinalityRestrictionName(card, dp, dq.getFiller()); 1040 else 1041 return getDataMaxCardinalityRestrictionName(card, dp); 1042 1043 case DATA_MIN_CARDINALITY: 1044 1045 dq = (OWLDataMinCardinality) c; 1046 dp = dq.getProperty(); 1047 card = dq.getCardinality(); 1048 if (dq.isQualified()) 1049 return getDataMinCardinalityRestrictionName(card, dp, dq.getFiller()); 1050 else 1051 return getDataMinCardinalityRestrictionName(card, dp); 1052 1053 case DATA_EXACT_CARDINALITY: 1054 1055 dq = (OWLDataExactCardinality) c; 1056 dp = dq.getProperty(); 1057 card = dq.getCardinality(); 1058 if (dq.isQualified()) 1059 return getDataExactCardinalityRestrictionName(card, dp, dq.getFiller()); 1060 else 1061 return getDataExactCardinalityRestrictionName(card, dp); 1062 1063 default: 1064 print("Print class of type " + c.getClassExpressionType()); 1065 return ""; 1066 } 1067 } 1068 1069 /** 1070 * Gets a String representation of an OWL 2 object property. 1071 * 1072 * @param p An OWL 2 object property. 1073 * @return A String representation of p. 1074 */ 1075 public String getObjectPropertyName(OWLObjectPropertyExpression p) 1076 { 1077 if (p.isOWLTopObjectProperty()) 1078 return getTopObjectPropertyName(); 1079 else if (p.isOWLBottomObjectProperty()) 1080 return getBottomObjectPropertyName(); 1081 else 1082 return getAtomicObjectPropertyName(p.asOWLObjectProperty()); 1083 } 1084 1085 /** 1086 * Gets a String representation of an OWL 2 data property. 1087 * 1088 * @param p An OWL 2 data property. 1089 * @return A String representation of p. 1090 */ 1091 public String getDataPropertyName(OWLDataPropertyExpression p) 1092 { 1093 if (p.isOWLTopDataProperty()) 1094 return getTopDataPropertyName(); 1095 else if (p.isOWLBottomDataProperty()) 1096 return getBottomDataPropertyName(); 1097 else 1098 return getAtomicDataPropertyName(p.asOWLDataProperty()); 1099 } 1100 1101 /** 1102 * Returns the degree in the annotation of an axiom. 1103 * @param axiom An OWLAxiom. 1104 * @return The degree in the annotation of an axiom; 1 if it does not exist. 1105 */ 1106 protected double getDegree(OWLAxiom axiom) 1107 { 1108 Set<OWLAnnotation> annotations = axiom.getAnnotations(label); 1109 1110 if (annotations.size() != 1) 1111 { 1112 if (annotations.size() > 1) 1113 print("Error: There are " + annotations.size() + " annotations for axiom " + axiom + "."); 1114 return 1; 1115 } 1116 else 1117 return Parser.getDegree(annotations.iterator().next().getValue().toString()); 1118 } 1119 1120 private void setK1AndK2(FuzzyDatatype dat, double[] k) 1121 { 1122 dat.setMinValue(k[0]); 1123 dat.setMaxValue(k[1]); 1124 } 1125 1126 private void getK1AndK2(String name, double[] k) 1127 { 1128 k[0] = NEG_INFINITY; 1129 k[1] = POS_INFINITY; 1130 1131 for (OWLOntology o : ontologies) 1132 { 1133 Set<OWLDatatypeDefinitionAxiom> set = o.getAxioms(AxiomType.DATATYPE_DEFINITION); 1134 if (set != null) 1135 { 1136 Iterator<OWLDatatypeDefinitionAxiom> it2 = set.iterator(); 1137 1138 String datatypeName = ""; 1139 OWLDatatypeDefinitionAxiom def; 1140 do 1141 { 1142 def = it2.next(); 1143 datatypeName = pm.getShortForm(def.getDatatype()).replace(":", ""); 1144 } while (it2.hasNext() && (datatypeName.compareTo(name) != 0)); 1145 1146 if (datatypeName.compareTo(name) == 0) 1147 { 1148 if (def.getDataRange().getDataRangeType() == DataRangeType.DATA_INTERSECTION_OF) 1149 { 1150 OWLDataIntersectionOf inter = (OWLDataIntersectionOf) def.getDataRange(); 1151 Set<OWLDataRange> operands = inter.getOperands(); 1152 if ((operands != null) && (operands.size() == 2)) 1153 { 1154 Iterator<OWLDataRange> it3 = operands.iterator(); 1155 OWLDataRange r1 = it3.next(); 1156 OWLDataRange r2 = it3.next(); 1157 if ( (r1.getDataRangeType() == DataRangeType.DATATYPE_RESTRICTION) && (r2.getDataRangeType() == DataRangeType.DATATYPE_RESTRICTION) ) 1158 { 1159 OWLDatatypeRestriction rest1 = (OWLDatatypeRestriction) r1; 1160 OWLDatatypeRestriction rest2 = (OWLDatatypeRestriction) r2; 1161 Set<OWLFacetRestriction> set1 = rest1.getFacetRestrictions(); 1162 Set<OWLFacetRestriction> set2 = rest2.getFacetRestrictions(); 1163 if ( (set1 != null) && (set2 != null) && (set1.size() == 1) && (set2.size() == 1) ) 1164 { 1165 OWLFacetRestriction f1 = rest1.getFacetRestrictions().iterator().next(); 1166 OWLFacetRestriction f2 = rest2.getFacetRestrictions().iterator().next(); 1167 if (f1.getFacet() == OWLFacet.MIN_INCLUSIVE) 1168 k[0] = Double.parseDouble(f1.getFacetValue().getLiteral()); 1169 else if (f1.getFacet() == OWLFacet.MAX_INCLUSIVE) 1170 k[1] = Double.parseDouble(f1.getFacetValue().getLiteral()); 1171 if (f2.getFacet() == OWLFacet.MIN_INCLUSIVE) 1172 k[0] = Double.parseDouble(f2.getFacetValue().getLiteral()); 1173 else if (f2.getFacet() == OWLFacet.MAX_INCLUSIVE) 1174 k[1] = Double.parseDouble(f2.getFacetValue().getLiteral()); 1175 } 1176 } 1177 } 1178 } 1179 } 1180 } 1181 } 1182 } 1183 1184 protected static String[] processParameters(String[] args) 1185 { 1186 boolean versionRequested = false; 1187 int numParams = args.length; 1188 String[] returnValue = new String[2]; 1189 1190 if ((args.length >= 1) && args[0].equals("--version")) 1191 { 1192 System.out.println(FuzzyOwl2.class.getSimpleName() + " version: " + 1.0); 1193 versionRequested = true; 1194 numParams--; 1195 } 1196 1197 if (numParams < 1) 1198 exit("Error. Use: java " + FuzzyOwl2.class.getSimpleName() + " <Owl2Ontology> ( <outputFileName> ).\n" + 1199 " Example: java " + FuzzyOwl2.class.getSimpleName() + " c:\\\\fuzzyWine.owl test.txt \n" + 1200 " Example: java " + FuzzyOwl2.class.getSimpleName() + " http://www.co-ode.org/ontologies/pizza/pizza.owl c:\\ont\\test.txt \n"); 1201 else 1202 { 1203 if (versionRequested) 1204 { 1205 returnValue[0] = args[1]; 1206 if (numParams == 2) 1207 returnValue[1] = args[2]; 1208 } 1209 else 1210 { 1211 returnValue[0] = args[0]; 1212 returnValue[1] = args[1]; 1213 } 1214 } 1215 return returnValue; 1216 } 1217 1218 // ****************************************************** 1219 // Methods that should be overwritten by the subclasses. 1220 // ****************************************************** 1221 1222 /** 1223 * Gets the short name (without namespaces) of an OWL 2 entity. 1224 * @param e An OWL 2 entity. 1225 * @return Short name of e. 1226 */ 1227 public String getShortName(OWLEntity e) 1228 { 1229 return pm.getShortForm(e); 1230 } 1231 1232 /** 1233 * Gets a String representation of an OWL 2 individual. 1234 * 1235 * @param i An OWL 2 individual. 1236 * @return A String representation of i. 1237 */ 1238 public String getIndividualName(OWLIndividual i) 1239 { 1240 if (i.isAnonymous()) 1241 { 1242 print("Anonymous individual not supported"); 1243 return null; 1244 } 1245 else 1246 { 1247 String name = getShortName(i.asOWLNamedIndividual()); 1248 print("Print individual " + name); 1249 return name; 1250 } 1251 } 1252 1253 protected String getTopConceptName() 1254 { 1255 print("Print Top concept"); 1256 return ""; 1257 } 1258 1259 protected String getBottomConceptName() 1260 { 1261 print("Print Bottom concept"); 1262 return ""; 1263 } 1264 1265 protected String getAtomicConceptName(OWLClass c) 1266 { 1267 String name = getShortName(c); 1268 print("Print Atomic concept" + name); 1269 return ""; 1270 } 1271 1272 protected String getObjectIntersectionOfName(Set<OWLClassExpression> operands) 1273 { 1274 print("Print ObjectIntersectionOf" + operands); 1275 return ""; 1276 } 1277 1278 protected String getObjectUnionOfName(Set<OWLClassExpression> operands) 1279 { 1280 print("Print ObjectUnionOf" + operands); 1281 return ""; 1282 } 1283 1284 protected String getObjectSomeValuesFromName(OWLObjectPropertyExpression p, OWLClassExpression c) 1285 { 1286 print("Print ObjectSomeValuesFrom(" + p + " " + c + ")"); 1287 return ""; 1288 } 1289 1290 protected String getObjectAllValuesFromName(OWLObjectPropertyExpression p, OWLClassExpression c) 1291 { 1292 print("Print ObjectAllValuesFrom(" + p + " " + c + ")"); 1293 return ""; 1294 } 1295 1296 protected String getDataSomeValuesFromName(OWLDataPropertyExpression p, OWLDataRange range) 1297 { 1298 print("Print DataSomeValuesFrom(" + p + " " + range + ")"); 1299 return ""; 1300 } 1301 1302 protected String getDataAllValuesFromName(OWLDataPropertyExpression p, OWLDataRange range) 1303 { 1304 print("Print DataAllValuesFrom(" + p + " " + range + ")"); 1305 return ""; 1306 } 1307 1308 protected String getObjectComplementOfName(OWLClassExpression c) 1309 { 1310 print("Print ObjectComplement(" + c + ")"); 1311 return ""; 1312 } 1313 1314 protected String getObjectHasSelfName(OWLObjectPropertyExpression p) 1315 { 1316 print("Print ObjectHasSelf(" + p + ")"); 1317 return ""; 1318 } 1319 1320 protected String getObjectOneOfName(Set<OWLIndividual> set) 1321 { 1322 print("Print ObjectOneOf(" + set + ")"); 1323 return ""; 1324 } 1325 1326 protected String getObjectHasValueName(OWLObjectPropertyExpression p, OWLIndividual i) 1327 { 1328 print("Print ObjectHasValue(" + p + " " + i + ")"); 1329 return ""; 1330 } 1331 1332 protected String getDataHasValueName(OWLDataPropertyExpression p, OWLLiteral lit) 1333 { 1334 print("Print DataHasValue(" + p + " " + lit + ")"); 1335 return ""; 1336 } 1337 1338 protected String getObjectMinCardinalityRestrictionName(int card, OWLObjectPropertyExpression p, OWLClassExpression c) 1339 { 1340 print("Print ObjectMinCardinalityRestriction(" + card + " " + p + " " + c + ")"); 1341 return ""; 1342 } 1343 1344 protected String getObjectMinCardinalityRestrictionName(int card, OWLObjectPropertyExpression p) 1345 { 1346 print("Print ObjectMinCardinalityRestriction(" + card + " " + p + " " + ")"); 1347 return ""; 1348 } 1349 1350 protected String getObjectMaxCardinalityRestrictionName(int card, OWLObjectPropertyExpression p, OWLClassExpression c) 1351 { 1352 print("Print ObjectMaxCardinalityRestriction(" + card + " " + p + " " + c + ")"); 1353 return ""; 1354 } 1355 1356 protected String getObjectMaxCardinalityRestrictionName(int card, OWLObjectPropertyExpression p) 1357 { 1358 print("Print ObjectMaxCardinalityRestriction(" + card + " " + p + " " + ")"); 1359 return ""; 1360 } 1361 1362 protected String getObjectExactCardinalityRestrictionName(int card, OWLObjectPropertyExpression p, OWLClassExpression c) 1363 { 1364 print("Print ObjectExactCardinalityRestriction(" + card + " " + p + " " + c + ")"); 1365 return ""; 1366 } 1367 1368 protected String getObjectExactCardinalityRestrictionName(int card, OWLObjectPropertyExpression p) 1369 { 1370 print("Print ObjectExactCardinalityRestriction(" + card + " " + p + " " + ")"); 1371 return ""; 1372 } 1373 1374 protected String getDataMinCardinalityRestrictionName(int card, OWLDataPropertyExpression p, OWLDataRange range) 1375 { 1376 print("Print DataMinCardinalityRestriction(" + card + " " + p + " " + range + ")"); 1377 return ""; 1378 } 1379 1380 protected String getDataMinCardinalityRestrictionName(int card, OWLDataPropertyExpression p) 1381 { 1382 print("Print DataMinCardinalityRestriction(" + card + " " + p + " " + ")"); 1383 return ""; 1384 } 1385 1386 protected String getDataMaxCardinalityRestrictionName(int card, OWLDataPropertyExpression p, OWLDataRange range) 1387 { 1388 print("Print DataMaxCardinalityRestriction(" + card + " " + p + " " + range + ")"); 1389 return ""; 1390 } 1391 1392 protected String getDataMaxCardinalityRestrictionName(int card, OWLDataPropertyExpression p) 1393 { 1394 print("Print DataMaxCardinalityRestriction(" + card + " " + p + " " + ")"); 1395 return ""; 1396 } 1397 1398 protected String getDataExactCardinalityRestrictionName(int card, OWLDataPropertyExpression p, OWLDataRange range) 1399 { 1400 print("Print DataExactCardinalityRestriction(" + card + " " + p + " " + range + ")"); 1401 return ""; 1402 } 1403 1404 protected String getDataExactCardinalityRestrictionName(int card, OWLDataPropertyExpression p) 1405 { 1406 print("Print DataExactCardinalityRestriction(" + card + " " + p + " " + ")"); 1407 return ""; 1408 } 1409 1410 protected String getTopObjectPropertyName() 1411 { 1412 print("Write top object property"); 1413 return ""; 1414 } 1415 1416 protected String getBottomObjectPropertyName() 1417 { 1418 print("Write bottom object property"); 1419 return ""; 1420 } 1421 1422 protected String getAtomicObjectPropertyName(OWLObjectProperty p) 1423 { 1424 print("Write object property + " + getShortName(p) ); 1425 return ""; 1426 } 1427 1428 protected String getTopDataPropertyName() 1429 { 1430 print("Write top object property"); 1431 return ""; 1432 } 1433 1434 protected String getBottomDataPropertyName() 1435 { 1436 print("Write bottom object property"); 1437 return ""; 1438 } 1439 1440 protected String getAtomicDataPropertyName(OWLDataProperty p) 1441 { 1442 print("Write object property + " + getShortName(p) ); 1443 return ""; 1444 } 1445 1446 protected void writeFuzzyLogic(FuzzyLogic logic) 1447 { 1448 print("Write fuzzy logic " + logic); 1449 } 1450 1451 protected void writeConceptDeclaration(OWLClassExpression c) 1452 { 1453 print("Write declaration " + c); 1454 } 1455 1456 protected void writeDataPropertyDeclaration(OWLDataPropertyExpression dp) 1457 { 1458 print("Write declaration " + dp); 1459 } 1460 1461 protected void writeObjectPropertyDeclaration(OWLObjectPropertyExpression op) 1462 { 1463 print("Write declaration " + op); 1464 } 1465 1466 protected void writeConceptAssertionAxiom(OWLIndividual i, OWLClassExpression c, double d) 1467 { 1468 print("Write axiom " + i + " : " + c + " >= " + d); 1469 } 1470 1471 protected void writeObjectPropertyAssertionAxiom(OWLIndividual i1, OWLIndividual i2, OWLObjectPropertyExpression p, double d) 1472 { 1473 print("Write axiom (" + i1 + " , " + i2 + ") : " + p + " >= " + d); 1474 } 1475 1476 protected void writeDataPropertyAssertionAxiom(OWLIndividual i1, OWLLiteral i2, OWLDataPropertyExpression p, double d) 1477 { 1478 print("Write axiom (" + i1 + " , " + i2 + ") : " + p + " >= " + d); 1479 } 1480 1481 protected void writeNegativeObjectPropertyAssertionAxiom(OWLIndividual i1, OWLIndividual i2, OWLObjectPropertyExpression p, double d) 1482 { 1483 print("Write axiom (" + i1 + " , " + i2 + ") : NOT " + p + " >= " + d); 1484 } 1485 1486 protected void writeNegativeDataPropertyAssertionAxiom(OWLIndividual i1, OWLLiteral i2, OWLDataPropertyExpression p, double d) 1487 { 1488 print("Write axiom (" + i1 + " , " + i2 + ") : NOT " + p + " >= " + d); 1489 } 1490 1491 protected void writeSameIndividualAxiom(Set<OWLIndividual> set) 1492 { 1493 print("Write axiom SameIndividual(" + set + ")"); 1494 } 1495 1496 protected void writeDifferentIndividualsAxiom(Set<OWLIndividual> set) 1497 { 1498 print("Write axiom DifferentIndividuals(" + set + ")"); 1499 } 1500 1501 protected void writeDisjointClassesAxiom(Set<OWLClassExpression> set) 1502 { 1503 print("Write axiom DisjointClasses(" + set + ")"); 1504 } 1505 1506 protected void writeDisjointUnionAxiom(Set<OWLClassExpression> set) 1507 { 1508 print("Write axiom DisjointUnion(" + set + ")"); 1509 } 1510 1511 protected void writeSubclassOfAxiom(OWLClassExpression subclass, OWLClassExpression superclass, double d) 1512 { 1513 print("Write axiom SubClassOf(" + subclass + " is subclass of " + superclass + " >= " + d + ")"); 1514 } 1515 1516 protected void writeEquivalentClassesAxiom(Set<OWLClassExpression> set) 1517 { 1518 print("Write axiom EquivalentClasses(" + set + ")"); 1519 } 1520 1521 protected void writeSubObjectPropertyOfAxiom(OWLObjectPropertyExpression subProperty, OWLObjectPropertyExpression superProperty, double d) 1522 { 1523 print("Write axiom SubObjectPropertyOf(" + subProperty + " is subclass of " + superProperty + " >= " + d + ")"); 1524 } 1525 1526 protected void writeSubPropertyChainOfAxiom(List<OWLObjectPropertyExpression> chain, OWLObjectPropertyExpression superProperty, double d) 1527 { 1528 print("Write axiom SubPropertyChainOf(" + chain + " is subclass of " + superProperty + " >= " + d + ")"); 1529 } 1530 1531 protected void writeSubDataPropertyOfAxiom(OWLDataPropertyExpression subProperty, OWLDataPropertyExpression superProperty, double d) 1532 { 1533 print("Write axiom SubDataPropertyOf(" + subProperty + " is subclass of " + superProperty + " >= " + d + ")"); 1534 } 1535 1536 protected void writeEquivalentObjectPropertiesAxiom(Set<OWLObjectPropertyExpression> set) 1537 { 1538 print("Write axiom EquivalentObjectProperties(" + set + ")"); 1539 } 1540 1541 protected void writeEquivalentDataPropertiesAxiom(Set<OWLDataPropertyExpression> set) 1542 { 1543 print("Write axiom EquivalentDataProperties(" + set + ")"); 1544 } 1545 1546 protected void writeTransitiveObjectPropertyAxiom(OWLObjectPropertyExpression p) 1547 { 1548 print("Write axiom TransitiveObjectProperty(" + p + ")"); 1549 } 1550 1551 protected void writeSymmetricObjectPropertyAxiom(OWLObjectPropertyExpression p) 1552 { 1553 print("Write axiom SymmetricObjectProperty(" + p + ")"); 1554 } 1555 1556 protected void writeAsymmetricObjectPropertyAxiom(OWLObjectPropertyExpression p) 1557 { 1558 print("Write axiom AsymmetricObjectProperty(" + p + ")"); 1559 } 1560 1561 protected void writeReflexiveObjectPropertyAxiom(OWLObjectPropertyExpression p) 1562 { 1563 print("Write axiom ReflexiveObjectProperty(" + p + ")"); 1564 } 1565 1566 protected void writeIrreflexiveObjectPropertyAxiom(OWLObjectPropertyExpression p) 1567 { 1568 print("Write axiom IrreflexiveObjectProperty(" + p + ")"); 1569 } 1570 1571 protected void writeFunctionalObjectPropertyAxiom(OWLObjectPropertyExpression p) 1572 { 1573 print("Write axiom FunctionalObjectProperty(" + p + ")"); 1574 } 1575 1576 protected void writeFunctionalDataPropertyAxiom(OWLDataPropertyExpression p) 1577 { 1578 print("Write axiom FunctionalDataProperty(" + p + ")"); 1579 } 1580 1581 protected void writeInverseObjectPropertiesAxiom(OWLObjectPropertyExpression p1, OWLObjectPropertyExpression p2) 1582 { 1583 print("Write axiom (" + p1 + " inverse of " + p2 + ")"); 1584 } 1585 1586 protected void writeInverseFunctionalObjectPropertyAxiom(OWLObjectPropertyExpression p) 1587 { 1588 print("Write axiom InverseFunctionalObjectProperty(" + p + ")"); 1589 } 1590 1591 protected void writeObjectPropertyDomainAxiom(OWLObjectPropertyExpression p, OWLClassExpression c) 1592 { 1593 print("Write axiom domain (" + c + " of object property" + p + ")"); 1594 } 1595 1596 protected void writeObjectPropertyRangeAxiom(OWLObjectPropertyExpression p, OWLClassExpression c) 1597 { 1598 print("Write axiom range (" + c + " of object property" + p + ")"); 1599 } 1600 1601 protected void writeDataPropertyDomainAxiom(OWLDataPropertyExpression p, OWLClassExpression c) 1602 { 1603 print("Write axiom domain (" + c + " of data property" + p + ")"); 1604 } 1605 1606 protected void writeDataPropertyRangeAxiom(OWLDataPropertyExpression p, OWLDataRange c) 1607 { 1608 print("Write axiom range (" + c + " of data property" + p + ")"); 1609 } 1610 1611 protected void writeDisjointObjectPropertiesAxiom(Set<OWLObjectPropertyExpression> set) 1612 { 1613 print("Write axiom (" + set + ")"); 1614 } 1615 1616 protected void writeDisjointDataPropertiesAxiom(Set<OWLDataPropertyExpression> set) 1617 { 1618 print("Write axiom (" + set + ")"); 1619 } 1620 1621 protected void writeTriangularModifierDefinition(String name, TriangularModifier mod) 1622 { 1623 print("Write definition " + name + " = " + mod); 1624 } 1625 1626 protected void writeLinearModifierDefinition(String name, LinearModifier mod) 1627 { 1628 print("Write definition " + name + " = " + mod); 1629 } 1630 1631 protected void writeLeftShoulderFunctionDefinition(String name, LeftShoulderFunction dat) 1632 { 1633 print("Write definition " + name + " = " + dat); 1634 } 1635 1636 protected void writeRightShoulderFunctionDefinition(String name, RightShoulderFunction dat) 1637 { 1638 print("Write definition " + name + " = " + dat); 1639 } 1640 1641 protected void writeLinearFunctionDefinition(String name, LinearFunction dat) 1642 { 1643 print("Write definition " + name + " = " + dat); 1644 } 1645 1646 protected void writeTriangularFunctionDefinition(String name, TriangularFunction dat) 1647 { 1648 print("Write definition " + name + " = " + dat); 1649 } 1650 1651 protected void writeTrapezoidalFunctionDefinition(String name, TrapezoidalFunction dat) 1652 { 1653 print("Write definition " + name + " = " + dat); 1654 } 1655 1656 protected void writeModifiedFunctionDefinition(String name, ModifiedFunction dat) 1657 { 1658 print("Write definition " + name + " = " + dat); 1659 } 1660 1661 protected void writeModifiedPropertyDefinition(String name, ModifiedProperty c) 1662 { 1663 print("Write definition " + name + " = " + c); 1664 } 1665 1666 protected void writeModifiedConceptDefinition(String name, ModifiedConcept c) 1667 { 1668 print("Write definition " + name + " = " + c); 1669 } 1670 1671 protected void writeFuzzyNominalConceptDefinition(String name, FuzzyNominalConcept c) 1672 { 1673 print("Write definition " + name + " = " + c); 1674 } 1675 1676 protected void writeWeightedConceptDefinition(String name, WeightedConcept c) 1677 { 1678 print("Write definition " + name + " = " + c); 1679 } 1680 1681 protected void writeWeightedMaxConceptDefinition(String name, WeightedMaxConcept c) 1682 { 1683 print("Write definition " + name + " = " + c); 1684 } 1685 1686 protected void writeWeightedMinConceptDefinition(String name, WeightedMinConcept c) 1687 { 1688 print("Write definition " + name + " = " + c); 1689 } 1690 1691 protected void writeWeightedSumConceptDefinition(String name, WeightedSumConcept c) 1692 { 1693 print("Write definition " + name + " = " + c); 1694 } 1695 1696 protected void writeOwaConceptDefinition(String name, OwaConcept c) 1697 { 1698 print("Write definition " + name + " = " + c); 1699 } 1700 1701 protected void writeChoquetConceptDefinition(String name, ChoquetConcept c) 1702 { 1703 print("Write definition " + name + " = " + c); 1704 } 1705 1706 protected void writeSugenoConceptDefinition(String name, SugenoConcept c) 1707 { 1708 print("Write definition " + name + " = " + c); 1709 } 1710 1711 protected void writeQuasiSugenoConceptDefinition(String name, QuasiSugenoConcept c) 1712 { 1713 print("Write definition " + name + " = " + c); 1714 } 1715 1716 protected void writeQowaConceptDefinition(String name, QowaConcept c) 1717 { 1718 print("Write definition " + name + " = " + c); 1719 } 1720 1721}