Beispiel #1
0
  public Set<NamingIssue> detectNonExactMatchingDirectChildIssues(OWLOntology ontology) {
    long start = System.currentTimeMillis();

    // get SubClass - SuperClass pairs
    Set<Pair<String, String>> subClassSuperClassPairs = new HashSet<Pair<String, String>>();
    Set<OWLSubClassOfAxiom> axioms = ontology.getAxioms(AxiomType.SUBCLASS_OF);
    for (OWLSubClassOfAxiom ax : axioms) {

      OWLClassExpression subClass = ax.getSubClass();
      OWLClassExpression superClass = ax.getSuperClass();

      if (!subClass.isAnonymous() && !superClass.isAnonymous()) {
        subClassSuperClassPairs.add(
            new Pair<String, String>(
                subClass.asOWLClass().toStringID(), superClass.asOWLClass().toStringID()));
      }
    }

    // compute non matching pairs
    Set<NamingIssue> nonMatchingChildren = computeNonExactMatchingChildren(subClassSuperClassPairs);
    long end = System.currentTimeMillis();
    logger.info("Operation took " + (end - start) + "ms");

    return nonMatchingChildren;
  }
  /**
   * Serializes a batch of triples corresponding to a predicate into one file. Upper bound:
   * TRIPLE_LIMIT_PER_FILE.
   */
  private static int serializeTripleBatch(
      OWLOntology ontology,
      QuestOWLIndividualAxiomIterator iterator,
      String filePrefix,
      String predicateName,
      int fileCount,
      String format)
      throws Exception {
    String fileName = filePrefix + fileCount + ".owl";

    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();

    // Main buffer
    OWLOntology aBox = manager.createOntology(IRI.create(predicateName));

    // Add the signatures
    for (OWLDeclarationAxiom axiom : ontology.getAxioms(AxiomType.DECLARATION)) {
      manager.addAxiom(aBox, axiom);
    }

    int tripleCount = 0;
    while (iterator.hasNext() && (tripleCount < TRIPLE_LIMIT_PER_FILE)) {
      manager.addAxiom(aBox, iterator.next());
      tripleCount++;
    }

    // BufferedOutputStream output = new BufferedOutputStream(new
    // FileOutputStream(outputPath.toFile()));
    // BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(output, "UTF-8"));
    BufferedWriter writer = new BufferedWriter(new FileWriter(fileName));
    manager.saveOntology(aBox, getOntologyFormat(format), new WriterDocumentTarget(writer));

    return tripleCount;
  }
 private void generateChanges() {
   changes = new ArrayList<OWLOntologyChange>();
   for (OWLOntology ont : ontologies) {
     for (OWLClassAxiom ax : ont.getAxioms(AxiomType.DISJOINT_CLASSES)) {
       changes.add(new RemoveAxiom(ont, ax));
     }
   }
 }
 public void visit(OWLOntology ontology) {
   checkOccurrence(ontology.getAnnotations());
   for (AxiomType<?> t : AxiomType.AXIOM_TYPES) {
     for (OWLAxiom ax : ontology.getAxioms(t)) {
       checkOccurrence(ax.getAnnotations());
       ax.accept(this);
     }
   }
   singleAppearance.clear();
 }
 private boolean isAtomic(OWLClassExpression classExpression) {
   if (classExpression.isAnonymous()) {
     return false;
   } else {
     for (OWLOntology ont : ontologies) {
       if (!ont.getAxioms((OWLClass) classExpression, EXCLUDED).isEmpty()) {
         return false;
       }
     }
     return true;
   }
 }
Beispiel #6
0
 public LsignatureExtractorViaInverseRewritingLauncher(
     OWLOntology ontology, LogicFragment fragment) {
   this.ontology = null;
   try {
     manager = ontology.getOWLOntologyManager();
     this.ontology = manager.createOntology();
     manager.addAxioms(this.ontology, ontology.getAxioms());
   } catch (OWLOntologyCreationException e) {
     e.printStackTrace();
   }
   this.fragment = fragment;
 }
Beispiel #7
0
 public LsignatureExtractorLauncher(
     OWLOntology ontology, LogicFragment fragment, boolean integrateRangesFirst) {
   this.ontology = null;
   try {
     OWLOntologyManager manager = ontology.getOWLOntologyManager();
     this.ontology = manager.createOntology();
     manager.addAxioms(this.ontology, ontology.getAxioms());
   } catch (OWLOntologyCreationException e) {
     e.printStackTrace();
   }
   this.fragment = fragment;
   this.integrateRangesFirst = integrateRangesFirst;
 }
  @Override
  public <T> Iterator<T> getInput(Class<T> type) throws IOException {
    // This ontology is already a merged version, no need to iterate over imported ones
    final OWLOntology o = getFromOntoMgr();
    if (type.isAssignableFrom(OWLAxiom.class)) {
      final Iterator<OWLAxiom> iterator = o.getAxioms().iterator();
      return new Iterator<T>() {

        @Override
        public boolean hasNext() {
          return iterator.hasNext();
        }

        @SuppressWarnings("unchecked")
        @Override
        public T next() {
          return (T) iterator.next();
        }

        @Override
        public void remove() {
          // This iterator is read-only
          throw new UnsupportedOperationException("Cannot remove statements from the iterator");
        }
      };
    } else if (type.isAssignableFrom(Statement.class)) {
      final OntModel input = new JenaToOwlConvert().ModelOwlToJenaConvert(o, "RDF/XML");
      final StmtIterator iterator = input.listStatements();
      return new Iterator<T>() {

        @Override
        public boolean hasNext() {
          return iterator.hasNext();
        }

        @SuppressWarnings("unchecked")
        @Override
        public T next() {
          return (T) iterator.next();
        }

        @Override
        public void remove() {
          // This iterator is read-only
          throw new UnsupportedOperationException("Cannot remove statements from the iterator");
        }
      };
    } else {
      throw new UnsupportedOperationException("This provider does not adapt to the given type");
    }
  }
  private OWLOntology reload(
      OWLOntology ontology, OWLOntologyFormat format, OWLOntologyLoaderConfiguration configuration)
      throws IOException, OWLOntologyStorageException, OWLOntologyCreationException {
    OWLOntologyManager man = ontology.getOWLOntologyManager();
    File tempFile = File.createTempFile("Ontology", ".owl");

    man.saveOntology(ontology, format, new FileDocumentTarget(tempFile));

    OWLOntologyManager man2 = getManager(); // OWLManager.createOWLOntologyManager();
    OWLOntology reloaded =
        man2.loadOntologyFromOntologyDocument(new FileDocumentSource(tempFile), configuration);
    man2.removeAxioms(reloaded, new HashSet<OWLAxiom>(reloaded.getAxioms(AxiomType.DECLARATION)));
    return reloaded;
  }
 /**
  * Uses some heuristics to determine if the specified ontology and its imports closure is an OBO
  * ontology.
  *
  * @param ontology The ontology to check
  * @return <code>true</code> if the ontology is an OBO ontology (or could be an OBO ontology)
  *     otherwise false.
  */
 public boolean isOBOOntology(OWLOntology ontology) {
   if (isOBOFormat(ontology)) {
     return true;
   }
   for (AxiomType<?> axiomType : AxiomType.AXIOM_TYPES) {
     for (OWLAxiom ax : ontology.getAxioms(axiomType, true)) {
       if (!isOBOAxiom(ax)) {
         return false;
       }
     }
   }
   for (OWLAnnotationProperty property : ontology.getAnnotationPropertiesInSignature()) {
     if (isOBOEntity(property)) {
       return true;
     }
   }
   return false;
 }
Beispiel #11
0
  /**
   * <b>Motivation</b>: OWL reasoners do not return superclass expressions If we want to find all
   * class expressions that may hold for a class then we must pre-coordinate all possible
   * expressions within the subset of OWL we care about. <br>
   * This class generates all satisfiable class expressions of the form r some c (for the
   * cross-product of R x C), as well as all class expressions that have been used (which may
   * include nested expressions)
   *
   * <p>The results are stored in queryClassMap
   *
   * @param precomputePropertyClassCombinations
   */
  @Deprecated
  private void generateQueryOntology(boolean precomputePropertyClassCombinations) {
    queryClassMap = new HashMap<OWLClass, OWLClassExpression>();

    getReasoner().flush();

    if (precomputePropertyClassCombinations) {
      LOG.debug("Precomputing all OP x Class combos");
      // cross-product of P x C
      // TODO - reflexivity and local reflexivity?
      for (OWLObjectProperty p : tboxOntology.getObjectPropertiesInSignature(true)) {
        LOG.debug(" materializing P some C for P=:" + p);
        for (OWLClass c : tboxOntology.getClassesInSignature(true)) {
          OWLObjectSomeValuesFrom r = getOWLDataFactory().getOWLObjectSomeValuesFrom(p, c);
          // LOG.debug(" QMAP:"+r);
          addClassExpressionToQueryMap(r);
        }
      }
    }

    // all expressions used in ontology
    for (OWLOntology ont : tboxOntology.getImportsClosure()) {
      LOG.debug("Finding all nested anonymous expressions");
      for (OWLAxiom ax : ont.getAxioms()) {
        // TODO - check if this is the nest closure. ie (r some (r2 some (r3 some ...)))
        for (OWLClassExpression x : ax.getNestedClassExpressions()) {
          if (x.isAnonymous()) {
            // LOG.debug(" QMAP+:"+x);
            addClassExpressionToQueryMap(x);
          }
        }
      }
    }
    if (LOG.isDebugEnabled()) {
      for (OWLOntology ont : collectedAxioms.keySet()) {
        LOG.debug("TOTAL axioms in QMAP: " + collectedAxioms.get(ont).size());
      }
    }
    LOG.debug("Adding collected axioms");
    addCollectedAxioms();
    LOG.debug("Flushing reasoner...");
    reasoner.flush();
    LOG.debug("Flushed reasoner");
  }
Beispiel #12
0
  public void mergeOntologies() {
    List<OWLOntologyChange> changes = new ArrayList<OWLOntologyChange>();
    for (OWLOntology ont : ontologies) {
      if (!ont.equals(targetOntology)) {

        // move the axioms
        for (OWLAxiom ax : ont.getAxioms()) {
          changes.add(new AddAxiom(targetOntology, ax));
        }

        // move ontology annotations
        for (OWLAnnotation annot : ont.getAnnotations()) {
          changes.add(new AddOntologyAnnotation(targetOntology, annot));
        }

        if (!targetOntology.getOntologyID().isAnonymous()) {
          // move ontology imports
          for (OWLImportsDeclaration decl : ont.getImportsDeclarations()) {
            if (ontologies.contains(ont.getOWLOntologyManager().getImportedOntology(decl))) {
              continue;
            }
            Optional<IRI> defaultDocumentIRI =
                targetOntology.getOntologyID().getDefaultDocumentIRI();
            if (defaultDocumentIRI.isPresent() && !decl.getIRI().equals(defaultDocumentIRI.get())) {
              changes.add(new AddImport(targetOntology, decl));
            } else {
              logger.warn(
                  "Merge: ignoring import declaration for ontology "
                      + targetOntology.getOntologyID()
                      + " (would result in target ontology importing itself).");
            }
          }
        }
      }
    }
    try {
      owlOntologyManager.applyChanges(changes);
    } catch (OWLOntologyChangeException e) {
      ErrorLogPanel.showErrorDialog(e);
    }
  }
  public void actionPerformed(ActionEvent actionEvent) {
    List<OWLOntologyChange> changes = new ArrayList<OWLOntologyChange>();
    int axiomsRemoved = 0;
    int axiomsAdded = 0;
    int numberOfDisjoints = 0;

    for (OWLOntology ont : getOWLModelManager().getActiveOntologies()) {

      // act on each ontology in turn
      CliqueFinder<OWLClassExpression> merger = new CliqueFinder<OWLClassExpression>();

      Set<OWLDisjointClassesAxiom> oldAxioms = ont.getAxioms(AxiomType.DISJOINT_CLASSES);
      numberOfDisjoints += oldAxioms.size();
      for (OWLDisjointClassesAxiom ax : oldAxioms) {
        merger.add(ax.getClassExpressions());
      }

      for (Set<OWLClassExpression> newAxioms : merger.getResults()) {
        OWLDisjointClassesAxiom newAxiom =
            getOWLModelManager().getOWLDataFactory().getOWLDisjointClassesAxiom(newAxioms);
        if (oldAxioms.contains(newAxiom)) {
          oldAxioms.remove(newAxiom);
        } else {
          changes.add(new AddAxiom(ont, newAxiom));
          axiomsAdded++;
        }
      }

      for (OWLDisjointClassesAxiom oldAxiom : oldAxioms) {
        changes.add(new RemoveAxiom(ont, oldAxiom));
        axiomsRemoved++;
      }
    }
    getOWLModelManager().applyChanges(changes);
    logger.info(
        axiomsRemoved
            + " (of "
            + numberOfDisjoints
            + " total) disjoint class axioms replaced with "
            + axiomsAdded);
  }
 public void storeFromTo(OWLOntology from, HGDBOntology to) {
   final Set<OWLAxiom> axioms = from.getAxioms();
   int i = 0;
   for (OWLAxiom axiom : axioms) {
     to.applyChange(new AddAxiom(to, axiom));
     i++;
     if (i % 5000 == 0) {
       System.out.println("storeFromTo: Axioms: " + i);
     }
   }
   System.out.println("storeFromTo: Axioms: " + i);
   // manager.addAxioms(newOnto, axioms);
   // Add Ontology Annotations
   for (OWLAnnotation a : from.getAnnotations()) {
     to.applyChange(new AddOntologyAnnotation(to, a));
   }
   // Add Import Declarations
   for (OWLImportsDeclaration im : from.getImportsDeclarations()) {
     to.applyChange(new AddImport(to, im));
   }
 }
  private void reload(OWLOntology ontology, OWLOntologyFormat format) throws Exception {
    Set<OWLAxiom> annotationAxioms = new HashSet<OWLAxiom>();
    for (OWLAxiom ax : ontology.getAxioms()) {
      if (ax.isAnnotationAxiom()) {
        annotationAxioms.add(ax);
      }
    }
    OWLOntologyLoaderConfiguration withAnnosConfig = new OWLOntologyLoaderConfiguration();
    OWLOntology reloadedWithAnnoAxioms = reload(ontology, format, withAnnosConfig);
    assertEquals(ontology.getAxioms(), reloadedWithAnnoAxioms.getAxioms());
    //
    OWLOntologyLoaderConfiguration withoutAnnosConfig =
        new OWLOntologyLoaderConfiguration().setLoadAnnotationAxioms(false);
    OWLOntology reloadedWithoutAnnoAxioms = reload(ontology, format, withoutAnnosConfig);
    assertFalse(ontology.getAxioms().equals(reloadedWithoutAnnoAxioms.getAxioms()));

    Set<OWLAxiom> axiomsMinusAnnotationAxioms = new HashSet<OWLAxiom>(ontology.getAxioms());
    axiomsMinusAnnotationAxioms.removeAll(annotationAxioms);
    assertEquals(axiomsMinusAnnotationAxioms, reloadedWithoutAnnoAxioms.getAxioms());
  }
Beispiel #16
0
  private String parseWithOWLAPI(
      URL ontologyURL,
      boolean useOWLAPI,
      boolean considerImportedOntologies,
      boolean considerImportedClosure,
      boolean useReasoner)
      throws OWLOntologyCreationException, OWLOntologyStorageException, URISyntaxException {
    String result = "";

    if (useOWLAPI) {
      OWLOntologyManager manager = OWLManager.createOWLOntologyManager();

      OWLOntology ontology = manager.loadOntology(IRI.create(ontologyURL.toString()));

      if (considerImportedClosure || considerImportedOntologies) {
        Set<OWLOntology> setOfImportedOntologies = new HashSet<OWLOntology>();
        if (considerImportedOntologies) {
          setOfImportedOntologies.addAll(ontology.getDirectImports());
        } else {
          setOfImportedOntologies.addAll(ontology.getImportsClosure());
        }
        for (OWLOntology importedOntology : setOfImportedOntologies) {
          manager.addAxioms(ontology, importedOntology.getAxioms());
        }
      }

      if (useReasoner) {
        ontology = parseWithReasoner(manager, ontology);
      }

      StringDocumentTarget parsedOntology = new StringDocumentTarget();

      manager.saveOntology(ontology, new RDFXMLOntologyFormat(), parsedOntology);
      result = parsedOntology.toString();
    }

    return result;
  }
 public Set<OWLAxiom> write(OWLDataProperty property) {
   Set<OWLAxiom> axioms = new HashSet<OWLAxiom>();
   axioms.addAll(writeEntityStart(DATA_PROPERTY, property));
   if (!isFiltered(AxiomType.FUNCTIONAL_DATA_PROPERTY)) {
     for (OWLOntology ontology : getOntologies()) {
       SectionMap characteristics = new SectionMap();
       for (OWLAxiom ax : ontology.getFunctionalDataPropertyAxioms(property)) {
         if (isDisplayed(ax)) {
           characteristics.add(FUNCTIONAL.toString(), ax);
           axioms.add(ax);
         }
       }
       writeSection(CHARACTERISTICS, characteristics, ",", true, ontology);
     }
   }
   if (!isFiltered(AxiomType.DATA_PROPERTY_DOMAIN)) {
     for (OWLOntology ontology : getOntologies()) {
       SectionMap domains = new SectionMap();
       for (OWLDataPropertyDomainAxiom ax : ontology.getDataPropertyDomainAxioms(property)) {
         if (isDisplayed(ax)) {
           domains.add(ax.getDomain(), ax);
           axioms.add(ax);
         }
       }
       writeSection(DOMAIN, domains, ",", true, ontology);
     }
   }
   if (!isFiltered(AxiomType.DATA_PROPERTY_RANGE)) {
     for (OWLOntology ontology : getOntologies()) {
       SectionMap ranges = new SectionMap();
       for (OWLDataPropertyRangeAxiom ax : ontology.getDataPropertyRangeAxioms(property)) {
         if (isDisplayed(ax)) {
           ranges.add(ax.getRange(), ax);
           axioms.add(ax);
         }
       }
       writeSection(RANGE, ranges, ",", true, ontology);
     }
   }
   if (!isFiltered(AxiomType.SUB_DATA_PROPERTY)) {
     for (OWLOntology ontology : getOntologies()) {
       SectionMap supers = new SectionMap();
       for (OWLSubDataPropertyOfAxiom ax :
           ontology.getDataSubPropertyAxiomsForSubProperty(property)) {
         if (isDisplayed(ax)) {
           supers.add(ax.getSuperProperty(), ax);
           axioms.add(ax);
         }
       }
       writeSection(SUB_PROPERTY_OF, supers, ",", true, ontology);
     }
   }
   if (!isFiltered(AxiomType.EQUIVALENT_DATA_PROPERTIES)) {
     for (OWLOntology ontology : getOntologies()) {
       SectionMap props = new SectionMap();
       for (OWLEquivalentDataPropertiesAxiom ax :
           ontology.getEquivalentDataPropertiesAxioms(property)) {
         if (isDisplayed(ax) && ax.getProperties().size() == 2) {
           props.add(ax.getPropertiesMinus(property).iterator().next(), ax);
           axioms.add(ax);
         }
       }
       writeSection(EQUIVALENT_TO, props, ",", true, ontology);
     }
   }
   if (!isFiltered(AxiomType.DISJOINT_DATA_PROPERTIES)) {
     for (OWLOntology ontology : getOntologies()) {
       SectionMap props = new SectionMap();
       for (OWLDisjointDataPropertiesAxiom ax :
           ontology.getDisjointDataPropertiesAxioms(property)) {
         if (ax.getProperties().size() == 2 && isDisplayed(ax)) {
           props.add(ax.getPropertiesMinus(property).iterator().next(), ax);
           axioms.add(ax);
         }
       }
       props.remove(property);
       writeSection(DISJOINT_WITH, props, ",", true, ontology);
     }
   }
   if (!isFiltered(AxiomType.SWRL_RULE)) {
     for (OWLOntology ontology : getOntologies()) {
       Set<OWLAxiom> rules = new HashSet<OWLAxiom>();
       for (SWRLRule rule : ontology.getAxioms(AxiomType.SWRL_RULE)) {
         if (isDisplayed(rule)) {
           for (SWRLAtom atom : rule.getHead()) {
             if (atom.getPredicate().equals(property)) {
               writeSection(RULE, rules, "", true, ontology);
               break;
             }
           }
         }
       }
     }
   }
   writeEntitySectionEnd(DATA_PROPERTY.toString());
   return axioms;
 }
  public Set<OWLAxiom> write(OWLObjectPropertyExpression property) {
    Set<OWLAxiom> axioms = new HashSet<OWLAxiom>();
    axioms.addAll(writeEntityStart(OBJECT_PROPERTY, property));
    if (!isFiltered(AxiomType.SUB_OBJECT_PROPERTY)) {
      for (OWLOntology ontology : getOntologies()) {
        SectionMap properties = new SectionMap();
        for (OWLSubObjectPropertyOfAxiom ax :
            ontology.getObjectSubPropertyAxiomsForSubProperty(property)) {
          if (isDisplayed(ax)) {
            properties.add(ax.getSuperProperty(), ax);
            axioms.add(ax);
          }
        }
        writeSection(SUB_PROPERTY_OF, properties, ",", true, ontology);
      }
      if (renderExtensions) {
        for (OWLOntology ontology : getOntologies()) {
          SectionMap properties = new SectionMap();
          for (OWLSubObjectPropertyOfAxiom ax :
              ontology.getObjectSubPropertyAxiomsForSuperProperty(property)) {
            if (isDisplayed(ax)) {
              properties.add(ax.getSubProperty(), ax);
              axioms.add(ax);
            }
          }
          writeSection(SUPER_PROPERTY_OF, properties, ",", true, ontology);
        }
      }
    }
    if (!isFiltered(AxiomType.EQUIVALENT_OBJECT_PROPERTIES)) {
      for (OWLOntology ontology : getOntologies()) {
        SectionMap properties = new SectionMap();
        for (OWLEquivalentObjectPropertiesAxiom ax :
            ontology.getEquivalentObjectPropertiesAxioms(property)) {
          if (isDisplayed(ax) && ax.getProperties().size() == 2) {
            Set<OWLObjectPropertyExpression> props = ax.getPropertiesMinus(property);
            properties.add(props.iterator().next(), ax);
            axioms.add(ax);
          }
        }
        writeSection(EQUIVALENT_TO, properties, ",", true, ontology);
      }
    }
    if (!isFiltered(AxiomType.DISJOINT_OBJECT_PROPERTIES)) {
      for (OWLOntology ontology : getOntologies()) {
        SectionMap properties = new SectionMap();
        for (OWLDisjointObjectPropertiesAxiom ax :
            ontology.getDisjointObjectPropertiesAxioms(property)) {
          if (ax.getProperties().size() == 2 && isDisplayed(ax)) {
            Set<OWLObjectPropertyExpression> props = ax.getPropertiesMinus(property);
            properties.add(props.iterator().next(), ax);
            axioms.add(ax);
          }
        }
        writeSection(DISJOINT_WITH, properties, ",", true, ontology);
      }
    }
    if (!isFiltered(AxiomType.SUB_PROPERTY_CHAIN_OF)) {
      for (OWLOntology ontology : getOntologies()) {
        for (OWLSubPropertyChainOfAxiom ax : ontology.getAxioms(AxiomType.SUB_PROPERTY_CHAIN_OF)) {
          if (ax.getSuperProperty().equals(property)) {
            if (isDisplayed(ax)) {
              SectionMap map = new SectionMap();
              map.add(ax.getPropertyChain(), ax);
              writeSection(SUB_PROPERTY_CHAIN, map, " o ", false, ontology);
              axioms.add(ax);
            }
          }
        }
      }
    }

    for (OWLOntology ontology : getOntologies()) {
      SectionMap characteristics = new SectionMap();
      if (!isFiltered(AxiomType.FUNCTIONAL_OBJECT_PROPERTY)) {
        for (OWLFunctionalObjectPropertyAxiom ax :
            ontology.getFunctionalObjectPropertyAxioms(property)) {
          if (isDisplayed(ax)) {
            characteristics.add(FUNCTIONAL.toString(), ax);
            axioms.add(ax);
          }
        }
      }

      if (!isFiltered(AxiomType.INVERSE_FUNCTIONAL_OBJECT_PROPERTY)) {
        for (OWLAxiom ax : ontology.getInverseFunctionalObjectPropertyAxioms(property)) {
          if (isDisplayed(ax)) {
            characteristics.add(INVERSE_FUNCTIONAL.toString(), ax);
            axioms.add(ax);
          }
        }
      }
      if (!isFiltered(AxiomType.SYMMETRIC_OBJECT_PROPERTY)) {
        for (OWLAxiom ax : ontology.getSymmetricObjectPropertyAxioms(property)) {
          if (isDisplayed(ax)) {
            characteristics.add(SYMMETRIC.toString(), ax);
            axioms.add(ax);
          }
        }
      }
      if (!isFiltered(AxiomType.TRANSITIVE_OBJECT_PROPERTY)) {
        for (OWLAxiom ax : ontology.getTransitiveObjectPropertyAxioms(property)) {
          if (isDisplayed(ax)) {
            characteristics.add(TRANSITIVE.toString(), ax);
            axioms.add(ax);
          }
        }
      }
      if (!isFiltered(AxiomType.REFLEXIVE_OBJECT_PROPERTY)) {
        for (OWLAxiom ax : ontology.getReflexiveObjectPropertyAxioms(property)) {
          if (isDisplayed(ax)) {
            characteristics.add(REFLEXIVE.toString(), ax);
            axioms.add(ax);
          }
        }
      }
      if (!isFiltered(AxiomType.IRREFLEXIVE_OBJECT_PROPERTY)) {
        for (OWLAxiom ax : ontology.getIrreflexiveObjectPropertyAxioms(property)) {
          if (isDisplayed(ax)) {
            characteristics.add(IRREFLEXIVE.toString(), ax);
            axioms.add(ax);
          }
        }
      }
      if (!isFiltered(AxiomType.ASYMMETRIC_OBJECT_PROPERTY)) {
        for (OWLAxiom ax : ontology.getAsymmetricObjectPropertyAxioms(property)) {
          if (isDisplayed(ax)) {
            characteristics.add(ASYMMETRIC.toString(), ax);
            axioms.add(ax);
          }
        }
      }
      writeSection(CHARACTERISTICS, characteristics, ",", true, ontology);
    }

    if (!isFiltered(AxiomType.OBJECT_PROPERTY_DOMAIN)) {
      for (OWLOntology ontology : getOntologies()) {
        SectionMap expressions = new SectionMap();
        for (OWLObjectPropertyDomainAxiom ax : ontology.getObjectPropertyDomainAxioms(property)) {
          if (isDisplayed(ax)) {
            expressions.add(ax.getDomain(), ax);
            axioms.add(ax);
          }
        }
        writeSection(DOMAIN, expressions, ",", true, ontology);
      }
    }
    if (!isFiltered(AxiomType.OBJECT_PROPERTY_RANGE)) {
      for (OWLOntology ontology : getOntologies()) {
        SectionMap expressions = new SectionMap();
        for (OWLObjectPropertyRangeAxiom ax : ontology.getObjectPropertyRangeAxioms(property)) {
          if (isDisplayed(ax)) {
            expressions.add(ax.getRange(), ax);
            axioms.add(ax);
          }
        }
        writeSection(RANGE, expressions, ",", true, ontology);
      }
    }
    if (!isFiltered(AxiomType.INVERSE_OBJECT_PROPERTIES)) {
      for (OWLOntology ontology : getOntologies()) {
        Set<OWLObjectPropertyExpression> properties = new TreeSet<OWLObjectPropertyExpression>();
        for (OWLInverseObjectPropertiesAxiom ax :
            ontology.getInverseObjectPropertyAxioms(property)) {
          if (isDisplayed(ax)) {
            if (ax.getFirstProperty().equals(property)) {
              properties.add(ax.getSecondProperty());
            } else {
              properties.add(ax.getFirstProperty());
            }
            axioms.add(ax);
          }
        }
        writeSection(INVERSE_OF, properties, ",", true, ontology);
      }
    }

    if (!isFiltered(AxiomType.SWRL_RULE)) {
      for (OWLOntology ontology : getOntologies()) {
        Set<OWLAxiom> rules = new HashSet<OWLAxiom>();
        for (SWRLRule rule : ontology.getAxioms(AxiomType.SWRL_RULE)) {
          if (isDisplayed(rule)) {
            for (SWRLAtom atom : rule.getHead()) {
              if (atom.getPredicate().equals(property)) {
                rules.add(rule);
                // XXX attempted patching
                writeSection(RULE, rules, ",", true, ontology);
                break;
              }
            }
          }
        }
      }
    }
    writeEntitySectionEnd(OBJECT_PROPERTY.toString());
    return axioms;
  }
  public Set<OWLAxiom> write(OWLClass cls) {
    Set<OWLAxiom> axioms = new HashSet<OWLAxiom>();
    axioms.addAll(writeEntityStart(CLASS, cls));

    if (!isFiltered(AxiomType.EQUIVALENT_CLASSES)) {
      for (OWLOntology ontology : getOntologies()) {
        SectionMap equivalentClasses = new SectionMap();
        for (OWLEquivalentClassesAxiom ax : ontology.getEquivalentClassesAxioms(cls)) {
          if (ax.getClassExpressions().size() == 2) {
            if (isDisplayed(ax)) {
              for (OWLClassExpression equivCls : ax.getClassExpressionsMinus(cls)) {
                equivalentClasses.add(equivCls, ax);
              }
              axioms.add(ax);
            }
          }
        }
        equivalentClasses.remove(cls);
        writeSection(EQUIVALENT_TO, equivalentClasses, ",", true, ontology);
      }
    }

    if (!isFiltered(AxiomType.SUBCLASS_OF)) {
      for (OWLOntology ontology : getOntologies()) {
        SectionMap superclasses = new SectionMap();
        for (OWLSubClassOfAxiom ax : ontology.getSubClassAxiomsForSubClass(cls)) {
          if (isDisplayed(ax)) {
            superclasses.add(ax.getSuperClass(), ax);
            axioms.add(ax);
          }
        }
        writeSection(SUBCLASS_OF, superclasses, ",", true, ontology);
      }
      if (renderExtensions) {
        for (OWLOntology ont : getOntologies()) {
          SectionMap subClasses = new SectionMap();
          for (OWLSubClassOfAxiom ax : ont.getSubClassAxiomsForSuperClass(cls)) {
            if (isDisplayed(ax)) {
              subClasses.add(ax.getSubClass(), ax);
              axioms.add(ax);
            }
          }
          writeSection(SUPERCLASS_OF, subClasses, ",", true, ont);
        }
      }
    }
    if (!isFiltered(AxiomType.DISJOINT_CLASSES)) {
      for (OWLOntology ontology : getOntologies()) {
        Set<OWLAxiom> pairwiseDisjointClassesAxioms = new HashSet<OWLAxiom>();
        SectionMap disjointClasses = new SectionMap();
        for (OWLDisjointClassesAxiom ax : ontology.getDisjointClassesAxioms(cls)) {
          if (isDisplayed(ax)) {
            if (ax.getClassExpressions().size() == 2) {
              pairwiseDisjointClassesAxioms.add(ax);
              OWLClassExpression disjointWith = ax.getClassExpressionsMinus(cls).iterator().next();
              disjointClasses.add(disjointWith, ax);
            }
            axioms.add(ax);
          }
        }
        writeSection(DISJOINT_WITH, disjointClasses, ", ", false, ontology);
        if (renderExtensions) {
          // Handling of nary in frame style
          for (OWLDisjointClassesAxiom ax : ontology.getDisjointClassesAxioms(cls)) {
            if (isDisplayed(ax)) {
              if (ax.getClassExpressions().size() > 2) {
                Set<OWLClassExpression> allDisjointClasses =
                    new TreeSet<OWLClassExpression>(ax.getClassExpressions());
                allDisjointClasses.remove(cls);
                axioms.add(ax);
                writeSection(DISJOINT_CLASSES, allDisjointClasses, ", ", false, ontology);
              }
            }
          }
        }
      }
    }
    if (!isFiltered(AxiomType.HAS_KEY)) {
      for (OWLOntology ontology : getOntologies()) {
        for (OWLHasKeyAxiom ax : ontology.getHasKeyAxioms(cls)) {
          if (isDisplayed(ax)) {
            SectionMap map = new SectionMap();
            map.add(ax.getPropertyExpressions(), ax);
            writeSection(HAS_KEY, map, ", ", true, ontology);
          }
        }
      }
    }
    if (!isFiltered(AxiomType.CLASS_ASSERTION)) {
      for (OWLOntology ontology : getOntologies()) {
        SectionMap individuals = new SectionMap();
        for (OWLClassAssertionAxiom ax : ontology.getClassAssertionAxioms(cls)) {
          if (isDisplayed(ax)) {
            if (renderExtensions || ax.getIndividual().isAnonymous()) {
              individuals.add(ax.getIndividual(), ax);
              axioms.add(ax);
            }
          }
        }
        writeSection(INDIVIDUALS, individuals, ",", true, ontology);
      }
    }
    if (!isFiltered(AxiomType.SWRL_RULE)) {
      for (OWLOntology ontology : getOntologies()) {
        Set<OWLAxiom> rules = new HashSet<OWLAxiom>();
        for (SWRLRule rule : ontology.getAxioms(AxiomType.SWRL_RULE)) {
          if (isDisplayed(rule)) {
            for (SWRLAtom atom : rule.getHead()) {
              if (atom.getPredicate().equals(cls)) {
                writeSection(RULE, rules, ", ", true, ontology);
                break;
              }
            }
          }
        }
      }
    }
    writeEntitySectionEnd(CLASS.toString());
    return axioms;
  }
  public void writeOntology() throws OWLRendererException {
    if (ontologies.size() != 1) {
      throw new OWLRuntimeException("Can only render one ontology");
    }
    OWLOntology ontology = getOntologies().iterator().next();
    writePrefixMap();
    writeNewLine();
    writeOntologyHeader(ontology);

    for (OWLAnnotationProperty prop : ontology.getAnnotationPropertiesInSignature()) {
      write(prop);
    }
    for (OWLDatatype datatype : ontology.getDatatypesInSignature()) {
      write(datatype);
    }
    for (OWLObjectProperty prop : ontology.getObjectPropertiesInSignature()) {
      write(prop);
      OWLObjectPropertyExpression invProp = prop.getInverseProperty();
      if (!ontology.getAxioms(invProp).isEmpty()) {
        write(invProp);
      }
    }
    for (OWLDataProperty prop : ontology.getDataPropertiesInSignature()) {
      write(prop);
    }
    for (OWLClass cls : ontology.getClassesInSignature()) {
      write(cls);
    }
    for (OWLNamedIndividual ind : ontology.getIndividualsInSignature()) {
      write(ind);
    }
    for (OWLAnonymousIndividual ind : ontology.getReferencedAnonymousIndividuals()) {
      write(ind);
    }
    // Nary disjoint classes axioms
    event = new RendererEvent(this, ontology);
    for (OWLDisjointClassesAxiom ax : ontology.getAxioms(AxiomType.DISJOINT_CLASSES)) {
      if (ax.getClassExpressions().size() > 2) {
        SectionMap map = new SectionMap();
        map.add(ax.getClassExpressions(), ax);
        writeSection(DISJOINT_CLASSES, map, ",", false, ontology);
      }
    }
    // Nary equivalent classes axioms
    for (OWLEquivalentClassesAxiom ax : ontology.getAxioms(AxiomType.EQUIVALENT_CLASSES)) {
      if (ax.getClassExpressions().size() > 2) {
        SectionMap map = new SectionMap();
        map.add(ax.getClassExpressions(), ax);
        writeSection(EQUIVALENT_CLASSES, map, ",", false, ontology);
      }
    }
    // Nary disjoint properties
    for (OWLDisjointObjectPropertiesAxiom ax :
        ontology.getAxioms(AxiomType.DISJOINT_OBJECT_PROPERTIES)) {
      if (ax.getProperties().size() > 2) {
        SectionMap map = new SectionMap();
        map.add(ax.getProperties(), ax);
        writeSection(DISJOINT_PROPERTIES, map, ",", false, ontology);
      }
    }
    // Nary equivlant properties
    for (OWLEquivalentObjectPropertiesAxiom ax :
        ontology.getAxioms(AxiomType.EQUIVALENT_OBJECT_PROPERTIES)) {
      if (ax.getProperties().size() > 2) {
        SectionMap map = new SectionMap();
        map.add(ax.getProperties(), ax);
        writeSection(EQUIVALENT_PROPERTIES, map, ",", false, ontology);
      }
    }
    // Nary disjoint properties
    for (OWLDisjointDataPropertiesAxiom ax :
        ontology.getAxioms(AxiomType.DISJOINT_DATA_PROPERTIES)) {
      if (ax.getProperties().size() > 2) {
        SectionMap map = new SectionMap();
        map.add(ax.getProperties(), ax);
        writeSection(DISJOINT_PROPERTIES, map, ",", false, ontology);
      }
    }
    // Nary equivalent properties
    for (OWLEquivalentDataPropertiesAxiom ax :
        ontology.getAxioms(AxiomType.EQUIVALENT_DATA_PROPERTIES)) {
      if (ax.getProperties().size() > 2) {
        SectionMap map = new SectionMap();
        map.add(ax.getProperties(), ax);
        writeSection(EQUIVALENT_PROPERTIES, map, ",", false, ontology);
      }
    }
    // Nary different individuals
    for (OWLDifferentIndividualsAxiom ax : ontology.getAxioms(AxiomType.DIFFERENT_INDIVIDUALS)) {
      if (ax.getIndividuals().size() > 2) {
        SectionMap map = new SectionMap();
        map.add(ax.getIndividuals(), ax);
        writeSection(DIFFERENT_INDIVIDUALS, map, ",", false, ontology);
      }
    }
    for (SWRLRule rule : ontology.getAxioms(AxiomType.SWRL_RULE)) {
      writeSection(RULE, Collections.singleton(rule), ", ", false);
    }
    flush();
  }
  public void execute() throws Exception {
    int rowCount = 0;
    try {

      String fileLoction =
          propertiesUtil.getPropertyValue(
              propertiesFileLocations, COSMICFUSIONEXPORT_TSV_FILE_LOCATION);
      File file = new File(fileLoction);
      logger.info("[01234] Processing File " + file.getName() + " ...... ");

      CSVReader reader = new CSVReader(new FileReader(file), '\t');
      JsonArray jsonArr = new JsonArray();
      String[] record;
      while ((record = reader.readNext()) != null) {

        if (rowCount != 0) {
          Complete_Fusion_Export cfe = factory.createComplete_Fusion_Export(CFE + rowCount);
          JsonObject jsonObject = new JsonObject();

          String fusion_IdValue = record[10] == null ? EMPTY_STRING : record[10];
          cfe.addFusion_Id(getFusionId(fusion_IdValue));
          jsonObject.addProperty(FUSION_ID, fusion_IdValue);

          String fusionTypeValue = record[12] == null ? EMPTY_STRING : record[12];
          cfe.addFusion_Type(fusionTypeValue);
          jsonObject.addProperty(FUSION_TYPE, fusionTypeValue);

          String histology_Subtype_1Value = record[9] == null ? EMPTY_STRING : record[9];
          cfe.addHistology_Subtype_1(histology_Subtype_1Value);
          jsonObject.addProperty(HISTOLOGY_SUBTYPE_1, histology_Subtype_1Value);

          String histology_Subtype_3Value = record[11] == null ? EMPTY_STRING : record[11];
          cfe.addHistology_Subtype_3(histology_Subtype_3Value);
          jsonObject.addProperty(HISTOLOGY_SUBTYPE_3, histology_Subtype_3Value);

          String primarySiteValue = record[2] == null ? EMPTY_STRING : record[2];
          cfe.addPrimary_Site(primarySiteValue);
          jsonObject.addProperty(PRIMARY_SITE, primarySiteValue);

          String pubmedPMIDValue = record[13] == null ? EMPTY_STRING : record[13];
          cfe.addPubmed_PMID(pubmedPMIDValue);
          jsonObject.addProperty(PUBMED_PMID, pubmedPMIDValue);

          String site_Subtype_1Value = record[3];
          cfe.addSite_Subtype_1(site_Subtype_1Value);
          jsonObject.addProperty(SITE_SUBTYPE_1_VALUE, site_Subtype_1Value);

          String site_Subtype_3Value = record[5];
          cfe.addSite_Subtype_3(site_Subtype_3Value);
          jsonObject.addProperty(SITE_SUBTYPE_3_VALUE, site_Subtype_3Value);

          String translocationName = record[11] == null ? EMPTY_STRING : record[11];
          cfe.addTranslocation_Name(translocationName);
          jsonObject.addProperty(TRANSLOCATION_NAME, translocationName);

          jsonArr.add(jsonObject);

          // TODO Uncomment before the .jar generation
          //					 owlOntologyManager.saveOntology(cfe.getOwlOntology(),
          //					 new FileOutputStream(new
          //					 File(propertiesUtil.getPropertyValue(propertiesFileLocations,
          //							 COSMICFUSIONEXPORT_RDF_FILE_LOCATION))));

          // TODO Use the code below to create samples.
          //					if (rowCount == 100) {
          File jsonSampleFile =
              new File(
                  propertiesUtil.getPropertyValue(
                      propertiesFileLocations, COSMICFUSIONEXPORT_JSON_FILE_LOCATION));
          FileUtils.writeStringToFile(jsonSampleFile, jsonArr.toString());
          owlOntologyManager.saveOntology(
              cfe.getOwlOntology(),
              new FileOutputStream(
                  new File(
                      propertiesUtil.getPropertyValue(
                          propertiesFileLocations, COSMICFUSIONEXPORT_RDF_FILE_LOCATION))));

          //						break;
          //					}
        }

        rowCount++;
      }
    } catch (Exception e) {
      logger.error("[01234] Error! " + e.getMessage());
      throw new RuntimeException(e.getMessage(), e);
    } finally {
      logger.info("[01234] Axioms size: " + onto.getAxioms().size());
      logger.info("[01234] Records: " + rowCount);
      logger.info("[01234] Process of CompleteFusionExportConverterImpl finished!");
    }
  }
Beispiel #22
0
  public Set<NamingIssue> detectNonMatchingChildIssues(OWLOntology ontology, boolean directChild) {
    long start = System.currentTimeMillis();

    // get SubClass - SuperClass pairs
    Set<NamingIssue> nonMatchingChildren = new HashSet<NamingIssue>();
    if (directChild) {
      Set<OWLSubClassOfAxiom> axioms = ontology.getAxioms(AxiomType.SUBCLASS_OF);
      for (OWLSubClassOfAxiom ax : axioms) {

        OWLClassExpression subClass = ax.getSubClass();
        OWLClassExpression superClass = ax.getSuperClass();

        if (!subClass.isAnonymous() && !superClass.isAnonymous()) {
          String subClassURI = subClass.asOWLClass().toStringID();
          String superClassURI = superClass.asOWLClass().toStringID();

          if (ignoreSingleTokenSubClasses && !singleToken(subClassURI)) {
            String subClassHead = getHeadNoun(subClassURI);
            String superClassHead = getHeadNoun(superClassURI);

            boolean matching =
                subClassHead.equals(superClassHead) || isHypernymOf(superClassHead, subClassHead);

            if (!matching) {
              String newClassURI = buildNewURI(subClassURI, superClassHead);
              nonMatchingChildren.add(
                  new NamingIssue(
                      subClassURI,
                      superClassURI,
                      new RenamingInstruction(subClassURI, newClassURI)));
            }
          }
        }
      }
    } else {
      OWLReasonerFactory reasonerFactory = PelletReasonerFactory.getInstance();
      OWLReasoner reasoner = reasonerFactory.createNonBufferingReasoner(ontology);

      Set<OWLClass> classes = ontology.getClassesInSignature();

      for (OWLClass cls : classes) {
        Set<OWLClass> superClasses = reasoner.getSuperClasses(cls, false).getFlattened();
        superClasses.remove(OWL_THING);
        for (OWLClass superClass : superClasses) {
          String subClassURI = cls.asOWLClass().toStringID();
          String superClassURI = superClass.asOWLClass().toStringID();

          if (ignoreSingleTokenSubClasses && !singleToken(subClassURI)) {
            String subClassHead = getHeadNoun(subClassURI);
            String superClassHead = getHeadNoun(superClassURI);

            boolean matching =
                subClassHead.equals(superClassHead) || isHypernymOf(superClassHead, subClassHead);

            if (!matching) {
              String newClassURI = buildNewURI(subClassURI, superClassHead);
              nonMatchingChildren.add(
                  new NamingIssue(
                      subClassURI,
                      superClassURI,
                      new RenamingInstruction(subClassURI, newClassURI)));
            }
          }
        }
      }
    }

    long end = System.currentTimeMillis();
    logger.info("Operation took " + (end - start) + "ms");

    return nonMatchingChildren;
  }
 @Override
 public void visit(OWLOntology ontology) {
   process(ontology.getAxioms());
 }
Beispiel #24
0
  public OWLOntology findLsignature(
      OWLOntology ontology, LogicFragment fragment, Statistics stats) {
    Timer t = new Timer();
    this.stats = stats;
    Logger_MORe.logInfo("extracting " + fragment.toString() + "-signature");
    OWLOntology ret = null;
    OWLOntologyManager manager = ontology.getOWLOntologyManager();
    try {
      ret = manager.createOntology();
      manager.addAxioms(ret, ontology.getAxioms());
    } catch (OWLOntologyCreationException e) {
      e.printStackTrace();
    }
    lSignatureClasses = new HashSet<OWLClass>();
    lSignatureOther = new HashSet<OWLEntity>();
    compSignatureClasses = new HashSet<OWLClass>();
    compSignatureOther = new HashSet<OWLEntity>();

    LsignatureExtractorLauncher elkSignatureExtractorLauncher = null;
    LsignatureExtractorLauncher elkSignatureExtractorIntegratingRangesLauncher = null;
    LsignatureExtractorViaInverseRewritingLauncher elkSignatureExtractorRewritingInversesLauncher =
        null;

    ForkJoinPool executor = new ForkJoinPool();
    elkSignatureExtractorLauncher =
        new LsignatureExtractorLauncher(ontology, LogicFragment.ELK, false);
    executor.execute(elkSignatureExtractorLauncher);

    if (ret != null) {
      // otherwise we have nowhere to return the axioms in the normalised ontologies necessary to
      // really classify all the extra classses in the lSignature
      if (rewriteInverses) {
        elkSignatureExtractorRewritingInversesLauncher =
            new LsignatureExtractorViaInverseRewritingLauncher(ontology, LogicFragment.ELK);
        executor.execute(elkSignatureExtractorRewritingInversesLauncher);
      }
      if (integrateRanges) {
        elkSignatureExtractorIntegratingRangesLauncher =
            new LsignatureExtractorLauncher(ontology, LogicFragment.ELK, true);
        executor.execute(elkSignatureExtractorIntegratingRangesLauncher);
      }

      // check the output of the normal ELKsignature and cancel the other threads if the lSig is the
      // whole signature
      initialiseLsignature((LsignatureExtractor) elkSignatureExtractorLauncher.join());

      if (compSignatureClasses.isEmpty())
        cancelTasks(
            elkSignatureExtractorIntegratingRangesLauncher,
            elkSignatureExtractorRewritingInversesLauncher);
      else {
        if (elkSignatureExtractorRewritingInversesLauncher != null
            && extendLsignature(
                    (LsignatureExtractor) elkSignatureExtractorRewritingInversesLauncher.join())
                > 0) {
          manager.addAxioms(
              ret,
              ((LsignatureExtractorViaInverseRewritingLauncher)
                      elkSignatureExtractorRewritingInversesLauncher)
                  .getOntology()
                  .getAxioms());
        }
        if (compSignatureClasses.isEmpty())
          cancelTasks(elkSignatureExtractorRewritingInversesLauncher);
        else if (elkSignatureExtractorIntegratingRangesLauncher != null
            && extendLsignature(
                    (LsignatureExtractor) elkSignatureExtractorIntegratingRangesLauncher.join())
                > 0) {
          manager.addAxioms(
              ret,
              ((LsignatureExtractorLauncher) elkSignatureExtractorIntegratingRangesLauncher)
                  .getOntology()
                  .getAxioms());
        }
      }
      stats.updateLsignatureSize(lSignatureClasses.size(), true);
    } else {
      ret = ontology;
      initialiseLsignature((LsignatureExtractor) elkSignatureExtractorLauncher.join());
    }

    Logger_MORe.logInfo(lSignatureClasses.size() + "classes in lSignature");
    Logger_MORe.logDebug(lSignatureClasses.toString());
    Logger_MORe.logInfo(compSignatureClasses.size() + "classes in compSignature");

    // might be a good idea to try to isolate extra axioms in the normalisation/rewriting - is this
    // possible/worth the effort?
    // check the order in which we try to extend the lSignature with each of the rewritten
    // ontologies and consider if one may be better that the other
    Logger_MORe.logDebug(t.duration() + "s to find Lsignature");

    return ret;
  }
 @Override
 protected Set<? extends OWLAxiom> getObjects(OWLOntology ont) {
   return ont.getAxioms(axiomType);
 }