コード例 #1
0
  public Map<String, OWLIndividual> returnSitesInOntology() {
    // map that contains the correspondance between the names of the sites
    // and their OWLIndividual representations.
    Map<String, OWLIndividual> returnMap = new HashMap<>();
    List<OWLIndividual> returnList = new ArrayList<>();
    OWLAnnotationProperty hasNameAnnotationProperty =
        OWLFactory.getOWLAnnotationProperty(":individualName", topIxPrefixManager);

    OWLClassExpression tempSiteClassExpression =
        OWLFactory.getOWLClass(":Site", topIxPrefixManager);
    for (OWLClassAssertionAxiom tempClassAssAx :
        topIxOnt.getClassAssertionAxioms(tempSiteClassExpression)) {
      returnList.add(tempClassAssAx.getIndividual());

      Set<OWLAnnotationAssertionAxiom> tempSiteAnnotationsSet =
          topIxOnt.getAnnotationAssertionAxioms(
              tempClassAssAx.getIndividual().asOWLNamedIndividual().getIRI());
      for (OWLAnnotationAssertionAxiom tempAnnotationAssertionAxiom : tempSiteAnnotationsSet) {
        if (tempAnnotationAssertionAxiom.getProperty().equals(hasNameAnnotationProperty)) {
          String tempString = tempAnnotationAssertionAxiom.getValue().toString();
          logger.info(tempString);
          tempString =
              tempString.substring(tempString.indexOf('"') + 1, tempString.indexOf('^') - 1);
          logger.info(tempString);
          logger.info(tempClassAssAx.getIndividual().toString());
          returnMap.put(tempString, tempClassAssAx.getIndividual());
        }
      }
    }
    return returnMap;
  }
コード例 #2
0
  public Set<OWLAxiom> write(OWLIndividual individual) {
    Set<OWLAxiom> axioms = new HashSet<OWLAxiom>();
    axioms.addAll(writeEntityStart(INDIVIDUAL, individual));
    if (!isFiltered(AxiomType.CLASS_ASSERTION)) {
      for (OWLOntology ontology : getOntologies()) {
        SectionMap expressions = new SectionMap();
        for (OWLClassAssertionAxiom ax : ontology.getClassAssertionAxioms(individual)) {
          if (isDisplayed(ax)) {
            expressions.add(ax.getClassExpression(), ax);
            axioms.add(ax);
          }
        }
        writeSection(TYPES, expressions, ",", true, ontology);
      }
    }
    for (OWLOntology ontology : getOntologies()) {

      List<OWLPropertyAssertionAxiom<?, ?>> assertions =
          new ArrayList<OWLPropertyAssertionAxiom<?, ?>>();
      assertions.addAll(ontology.getObjectPropertyAssertionAxioms(individual));
      assertions.addAll(ontology.getNegativeObjectPropertyAssertionAxioms(individual));
      assertions.addAll(ontology.getDataPropertyAssertionAxioms(individual));
      assertions.addAll(ontology.getNegativeDataPropertyAssertionAxioms(individual));

      if (!assertions.isEmpty()) {
        fireSectionRenderingPrepared(FACTS.toString());
        writeSection(FACTS);
        writeSpace();
        writeOntologiesList(ontology);
        incrementTab(1);
        writeNewLine();
        fireSectionRenderingStarted(FACTS.toString());

        for (Iterator<OWLPropertyAssertionAxiom<?, ?>> it = assertions.iterator(); it.hasNext(); ) {
          OWLPropertyAssertionAxiom<?, ?> ax = it.next();
          fireSectionItemPrepared(FACTS.toString());
          Set<OWLAnnotation> annos = ax.getAnnotations();
          if (!annos.isEmpty()) {
            writeAnnotations(annos);
            pushTab(getIndent() + 1);
          }

          if (ax instanceof OWLNegativeDataPropertyAssertionAxiom
              || ax instanceof OWLNegativeObjectPropertyAssertionAxiom) {
            write(NOT);
            writeSpace();
          }
          ax.getProperty().accept(this);
          writeSpace();
          writeSpace();
          ax.getObject().accept(this);
          if (!annos.isEmpty()) {
            popTab();
          }
          fireSectionItemFinished(FACTS.toString());
          if (it.hasNext()) {
            write(",");
            writeNewLine();
          }
        }
        popTab();
        writeNewLine();
        writeNewLine();
      }
    }

    if (!isFiltered(AxiomType.SAME_INDIVIDUAL)) {
      for (OWLOntology ontology : getOntologies()) {
        Set<OWLIndividual> inds = new TreeSet<OWLIndividual>();
        for (OWLSameIndividualAxiom ax : ontology.getSameIndividualAxioms(individual)) {
          if (isDisplayed(ax)) {
            inds.addAll(ax.getIndividuals());
            axioms.add(ax);
          }
        }
        inds.remove(individual);
        writeSection(SAME_AS, inds, ",", true, ontology);
      }
    }
    if (!isFiltered(AxiomType.DIFFERENT_INDIVIDUALS)) {
      for (OWLOntology ontology : getOntologies()) {
        Set<OWLIndividual> inds = new TreeSet<OWLIndividual>();
        Set<OWLDifferentIndividualsAxiom> nary = new TreeSet<OWLDifferentIndividualsAxiom>();
        for (OWLDifferentIndividualsAxiom ax : ontology.getDifferentIndividualAxioms(individual)) {
          if (ax.getIndividuals().size() == 2 && isDisplayed(ax)) {
            inds.addAll(ax.getIndividuals());
            axioms.add(ax);
          } else {
            nary.add(ax);
          }
        }
        inds.remove(individual);
        writeSection(DIFFERENT_FROM, inds, ",", true, ontology);
        if (renderExtensions) {
          for (OWLDifferentIndividualsAxiom ax : nary) {
            writeSection(DIFFERENT_INDIVIDUALS, ax.getIndividuals(), ", ", false, ontology);
          }
        }
      }
    }
    writeEntitySectionEnd(INDIVIDUAL.toString());
    return axioms;
  }
コード例 #3
0
  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;
  }