コード例 #1
0
 // TODO optimize translatin: (e) can be discarded for roles for which there
 // aren't assertions
 private Set<Rule> translation(QLAxiomsTranslator axiomsTranslator) {
   final Set<Rule> result = new HashSet<Rule>();
   for (final OWLClassAssertionAxiom assertion : ontologyNormalization.conceptAssertions())
     result.addAll(axiomsTranslator.assertionTranslation(assertion));
   for (final OWLObjectPropertyAssertionAxiom assertion : ontologyNormalization.roleAssertions())
     result.addAll(axiomsTranslator.assertionTranslation(assertion));
   for (final OWLDataPropertyAssertionAxiom assertion : ontologyNormalization.dataAssertions())
     result.addAll(axiomsTranslator.assertionTranslation(assertion));
   for (final OWLSubClassOfAxiom subsumption : ontologyNormalization.conceptSubsumptions())
     result.addAll(
         axiomsTranslator.subsumptionTranslation(
             subsumption.getSubClass(), subsumption.getSuperClass()));
   for (final OWLSubPropertyAxiom<?> subsumption : ontologyNormalization.roleSubsumptions())
     if (subsumption instanceof OWLSubObjectPropertyOfAxiom) {
       result.addAll(
           axiomsTranslator.subsumptionTranslation(
               subsumption.getSubProperty(), subsumption.getSuperProperty()));
       final OWLSubObjectPropertyOfAxiom axiom = (OWLSubObjectPropertyOfAxiom) subsumption;
       final OWLObjectPropertyExpression ope1 = axiom.getSubProperty();
       final OWLObjectPropertyExpression ope2 = axiom.getSuperProperty();
       final OWLObjectPropertyExpression invOpe1 = ope1.getInverseProperty().getSimplified();
       final OWLObjectPropertyExpression invOpe2 = ope2.getInverseProperty().getSimplified();
       if ((ontologyNormalization.isSuper(some(ope1)) || ontologyNormalization.isSuper(ope1))
           && (ontologyNormalization.isSub(some(ope2)) || ontologyNormalization.isSub(ope2)))
         result.add(
             axiomsTranslator.domainSubsumptionTranslation(
                 axiom.getSubProperty(), axiom.getSuperProperty()));
       if ((ontologyNormalization.isSuper(some(invOpe1)) || ontologyNormalization.isSuper(invOpe1))
           && (ontologyNormalization.isSub(some(invOpe2)) || ontologyNormalization.isSub(invOpe2)))
         result.add(axiomsTranslator.rangeSubsumptionTranslation(invOpe1, invOpe2));
     } else if (subsumption instanceof OWLSubDataPropertyOfAxiom)
       result.addAll(
           axiomsTranslator.subsumptionTranslation(
               subsumption.getSubProperty(), subsumption.getSuperProperty()));
   for (final OWLPropertyExpression ope : ontologyNormalization.getRoles())
     if (ope instanceof OWLObjectPropertyExpression) {
       final OWLObjectProperty p = ((OWLObjectPropertyExpression) ope).getNamedProperty();
       final OWLObjectPropertyExpression invP = p.getInverseProperty();
       if (ontologyNormalization.isSub(some(p)) || ontologyNormalization.isSub(p))
         result.add(axiomsTranslator.domainTranslation(p));
       if (ontologyNormalization.isSub(some(invP)) || ontologyNormalization.isSub(invP))
         result.add(axiomsTranslator.rangeTranslation(p));
     }
   return result;
 }
コード例 #2
0
  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();
  }