コード例 #1
0
 public void writeOntologyHeader(OWLOntology ontology) {
   event = new RendererEvent(this, ontology);
   fireFrameRenderingPrepared(ONTOLOGY.toString());
   write(ONTOLOGY.toString());
   write(":");
   writeSpace();
   if (!ontology.isAnonymous()) {
     int indent = getIndent();
     writeFullURI(ontology.getOntologyID().getOntologyIRI().toString());
     writeNewLine();
     pushTab(indent);
     if (ontology.getOntologyID().getVersionIRI() != null) {
       writeFullURI(ontology.getOntologyID().getVersionIRI().toString());
     }
     popTab();
   }
   fireFrameRenderingStarted(ONTOLOGY.toString());
   writeNewLine();
   for (OWLImportsDeclaration decl : ontology.getImportsDeclarations()) {
     fireSectionItemPrepared(IMPORT.toString());
     write(IMPORT.toString());
     write(":");
     writeSpace();
     fireSectionRenderingStarted(IMPORT.toString());
     writeFullURI(decl.getURI().toString());
     writeNewLine();
     fireSectionRenderingFinished(IMPORT.toString());
   }
   writeNewLine();
   writeSection(ANNOTATIONS, ontology.getAnnotations(), ",", true);
   fireFrameRenderingFinished(ONTOLOGY.toString());
 }
コード例 #2
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);
    }
  }
コード例 #3
0
  protected OWLOntology getOntologyAsOWLOntology(
      OWLOntologyID ontologyId, boolean merge, IRI universalPrefix) {
    // if (merge) throw new UnsupportedOperationException("Merge not implemented yet for
    // OWLOntology.");

    // Remove the check below. It might be an unmanaged dependency (TODO remove from collector and
    // reintroduce check?).
    // if (!hasOntology(ontologyIri)) return null;
    OWLOntology o;
    o = ontologyProvider.getStoredOntology(ontologyId, OWLOntology.class, merge);

    if (merge) {
      final Set<OWLOntology> set = new HashSet<OWLOntology>();
      log.debug("Merging {} with its imports, if any.", o);
      set.add(o);
      // Actually, if the provider already performed the merge, this won't happen
      for (OWLOntology impo : o.getImportsClosure()) {
        log.debug("Imported ontology {} will be merged with {}.", impo, o);
        set.add(impo);
      }
      OWLOntologySetProvider provider =
          new OWLOntologySetProvider() {
            @Override
            public Set<OWLOntology> getOntologies() {
              return set;
            }
          };
      OWLOntologyMerger merger = new OWLOntologyMerger(provider);
      try {
        o =
            merger.createMergedOntology(
                OWLManager.createOWLOntologyManager(), ontologyId.getOntologyIRI());
      } catch (OWLOntologyCreationException e) {
        log.error("Failed to merge imports for ontology " + ontologyId, e);
        // do not reassign the root ontology
      }
    } else {
      // Rewrite import statements
      List<OWLOntologyChange> changes = new ArrayList<OWLOntologyChange>();
      OWLDataFactory df = OWLManager.getOWLDataFactory();

      /*
       * TODO manage import rewrites better once the container ID is fully configurable (i.e. instead of
       * going upOne() add "session" or "ontology" if needed). But only do this if we keep considering
       * imported ontologies as *not* managed.
       */
      for (OWLImportsDeclaration oldImp : o.getImportsDeclarations()) {
        changes.add(new RemoveImport(o, oldImp));
        String s = oldImp.getIRI().toString();
        // FIXME Ugly way to check, but we'll get through with it
        if (s.contains("::")) s = s.substring(s.indexOf("::") + 2, s.length());
        boolean managed = managedOntologies.contains(oldImp.getIRI());
        // For space, always go up at least one

        String tid = getID();
        if (backwardPathLength > 0) tid = tid.split("/")[0];

        IRI target =
            IRI.create(
                (managed
                        ? universalPrefix + "/" + tid + "/"
                        : URIUtils.upOne(universalPrefix) + "/")
                    + s);
        changes.add(new AddImport(o, df.getOWLImportsDeclaration(target)));
      }
      o.getOWLOntologyManager().applyChanges(changes);
    }

    return o;
  }
コード例 #4
0
 /** @param axiom the axiom */
 public void visit(OWLImportsDeclaration axiom) {
   write("ImportsDeclaration");
   axiom.getIRI().accept(this);
 }