コード例 #1
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;
  }