Java 类org.semanticweb.owlapi.model.OWLOntologyID 实例源码

项目:uel    文件:UelUI.java   
@Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected,
        boolean cellHasFocus) {

    super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);

    if (value instanceof OWLOntology) {
        OWLOntologyID id = ((OWLOntology) value).getOntologyID();
        if (id.isAnonymous()) {
            this.setText(id.toString());
        } else {
            this.setText(id.getOntologyIRI().get().toString());
        }
    }

    return this;
}
项目:minerva    文件:GafToLegoIndividualTranslator.java   
/**
 * Translate the given {@link GafDocument} into an OWL representation of the LEGO model.
 * 
 * @param gaf
 * @return lego ontology
 * @throws OWLException
 * @throws UnknownIdentifierException 
 */
public OWLOntology translate(GafDocument gaf) throws OWLException, UnknownIdentifierException {
    final OWLOntologyManager m = graph.getManager();
    OWLOntology lego = m.createOntology(IRI.generateDocumentIRI());
    OWLOntology sourceOntology = graph.getSourceOntology();
    OWLOntologyID ontologyID = sourceOntology.getOntologyID();
    if (ontologyID != null) {
        Optional<IRI> ontologyIRI = ontologyID.getOntologyIRI();
        if (ontologyIRI.isPresent()) {
            OWLDataFactory f = m.getOWLDataFactory();
            OWLImportsDeclaration importDeclaration = f.getOWLImportsDeclaration(ontologyIRI.get());
            m.applyChange(new AddImport(lego, importDeclaration ));
        }
    }
    translate(gaf.getGeneAnnotations(), lego);
    return lego;
}
项目:elk-reasoner    文件:TestOWLManager.java   
public static OWLOntologyManager createOWLOntologyManager() {
    OWLOntologyManager man = new OWLOntologyManagerImpl(df,
            new NoOpReadWriteLock());
    man.getOntologyFactories()
            .set(new OWLOntologyFactoryImpl(new OWLOntologyBuilder() {
                private static final long serialVersionUID = -7962454739789851685L;

                @Override
                public OWLOntology createOWLOntology(OWLOntologyManager om,
                        OWLOntologyID id) {
                    return new OWLOntologyImpl(om, id);
                }
            }));
    man.getOntologyParsers().set(MASTER_MANAGER_.getOntologyParsers());
    man.getOntologyStorers().set(MASTER_MANAGER_.getOntologyStorers());
    man.getIRIMappers().set(MASTER_MANAGER_.getIRIMappers());
    return man;
}
项目:owltools    文件:OntologyMetadata.java   
public OntologyMetadata(OWLOntology ont) {
    super();
    OWLOntologyID id = ont.getOntologyID();
    if (id.getOntologyIRI().isPresent())
        ontologyIRI = id.getOntologyIRI().get().toString();
    if (id.getVersionIRI().isPresent())
        versionIRI = id.getVersionIRI().get().toString();
    importDirectives = new HashSet<String>();
    for (OWLImportsDeclaration oid : ont.getImportsDeclarations()) {
        importDirectives.add(oid.getIRI().toString());
    }
    classCount = ont.getClassesInSignature().size();
    namedIndividualCount = ont.getIndividualsInSignature().size();
    axiomCount = ont.getAxiomCount();
    annotations = new HashSet<OntologyAnnotation>();
    for (OWLAnnotation ann : ont.getAnnotations()) {
        annotations.add(new OntologyAnnotation(ann));
    }
}
项目:owltools    文件:OboOntologyReleaseRunner.java   
private String handleVersion(String ontologyId) {
    // TODO add an option to set/overwrite the version manually via command-line
    // TODO re-use/create a method in obo2owl for creating an version IRI
    String version;
    OWLOntology ontology = mooncat.getOntology();
    OWLOntologyID owlOntologyId = ontology.getOntologyID();
    Optional<IRI> versionIRI = owlOntologyId.getVersionIRI();
    if (versionIRI.isPresent() == false) {
        // set a new version IRI using the current date
        version = OntologyVersionTools.format(new Date());
        versionIRI = Optional.of(IRI.create(Obo2OWLConstants.DEFAULT_IRI_PREFIX+ontologyId+"/"+oortConfig.getVersionSubdirectory()+"/"+version+"/"+ontologyId+".owl"));

        OWLOntologyManager m = mooncat.getManager();
        m.applyChange(new SetOntologyID(ontology, new OWLOntologyID(owlOntologyId.getOntologyIRI(), versionIRI)));
    }
    else {
        String versionIRIString = versionIRI.get().toString();
        version = OntologyVersionTools.parseVersion(versionIRIString);
        if (version == null) {
            // use the whole IRI? escape?
            logError("Could not parse a version from ontolgy version IRI: "+versionIRIString);
            version = versionIRIString;
        }
    }
    return version;
}
项目:SciGraph    文件:GraphOwlVisitor.java   
@Override
public Void visit(OWLOntology ontology) {
  this.ontology = Optional.of(ontology);
  this.definingOntology = OwlApiUtils.getIri(ontology);
  Long versionNodeID = null;
  Long ontologyNodeID = null;
  OWLOntologyID id = ontology.getOntologyID();
  if (null == id.getOntologyIRI()) {
    logger.fine("Ignoring null ontology ID for " + ontology.toString());
  } else {
    ontologyNodeID = getOrCreateNode(id.getOntologyIRI().toString(), OwlLabels.OWL_ONTOLOGY);
  }
  if (null != id.getVersionIRI()){
    versionNodeID = getOrCreateNode(id.getVersionIRI().toString(), OwlLabels.OWL_ONTOLOGY);
  }
  if (null != ontologyNodeID && null != versionNodeID) {
    graph.createRelationship(ontologyNodeID, versionNodeID, OwlRelationships.OWL_VERSION_IRI);
  }
  return null;
}
项目:Pellet4Android    文件:OntologyManager.java   
public Map<String, Set<OWLAnnotationValue>> getOntologyAnnotationsOrderedByOntology(
        String annotation) {
    Map<String, Set<OWLAnnotationValue>> annotationValuesByOntologyIri = new HashMap<String, Set<OWLAnnotationValue>>();
    final OWLDataFactory factory = manager.getOWLDataFactory();
    final OWLAnnotationProperty dcProperty = factory
            .getOWLAnnotationProperty(IRI.create(annotation));
    for (OWLOntology ontology : manager.getOntologies()) {

        Set<OWLAnnotationValue> annotationValues = new HashSet<OWLAnnotationValue>();
        for (OWLAnnotation owlAnnotation : ontology.getAnnotations()) {
            if (owlAnnotation.getProperty().equals(dcProperty)) {
                annotationValues.add(owlAnnotation.getValue());
            }
        }

        if (!annotationValues.isEmpty()) {
            final OWLOntologyID ontologyID = ontology.getOntologyID();

            annotationValuesByOntologyIri.put(ontologyID.getOntologyIRI()
                    .toString(), annotationValues);
        }

    }
    return annotationValuesByOntologyIri;
}
项目:binaryowl    文件:OntologyChangeRecordList.java   
public List<OntologyChangeRecordRun> getRuns() {
    List<OntologyChangeRecordRun> result = new ArrayList<OntologyChangeRecordRun>();
    if (!changeRecords.isEmpty()) {
        OWLOntologyID currentRunId = null;
        List<OWLOntologyChangeData> runInfoList = new ArrayList<OWLOntologyChangeData>();
        for(OWLOntologyChangeRecord record : changeRecords) {
            if(currentRunId == null) {
                // First run
                currentRunId = record.getOntologyID();
            }
            else if(!currentRunId.equals(record.getOntologyID())) {
                // Store current run
                result.add(new OntologyChangeRecordRun(currentRunId, new ArrayList<OWLOntologyChangeData>(runInfoList)));
                // Reset for fresh run
                currentRunId = record.getOntologyID();
                runInfoList.clear();
            }
            // Add to current run
            runInfoList.add(record.getData());
        }
        result.add(new OntologyChangeRecordRun(currentRunId, new ArrayList<OWLOntologyChangeData>(runInfoList)));
    }
    return result;
}
项目:uel    文件:UelProtegeStarter.java   
@Override
public OWLOntology createOntology() {
    try {
        return modelManager.createNewOntology(new OWLOntologyID(), null);
    } catch (OWLOntologyCreationException ex) {
        throw new RuntimeException(ex);
    }
}
项目:minerva    文件:CoreMolecularModelManager.java   
/**
 * Executed before the init call {@link #init()}.
 * 
 * @param graph
 * @return IRI, never null
 * @throws OWLOntologyCreationException
 */
protected IRI getTboxIRI(OWLGraphWrapper graph) throws OWLOntologyCreationException {
    OWLOntology tbox = graph.getSourceOntology();
    OWLOntologyID ontologyID = tbox.getOntologyID();
    if (ontologyID != null) {
        Optional<IRI> ontologyIRI = ontologyID.getOntologyIRI();
        if (ontologyIRI.isPresent()) {
            return ontologyIRI.get();
        }
    }
    throw new OWLOntologyCreationException("No ontology id available for tbox. An ontology IRI is required for the import into the abox.");
}
项目:minerva    文件:CoreMolecularModelManager.java   
/**
 * Export the ABox, will try to set the ontologyID to the given modelId (to
 * ensure import assumptions are met)
 * 
 * @param model
 * @param ontologyFormat
 * @return modelContent
 * @throws OWLOntologyStorageException
 */
public String exportModel(ModelContainer model, OWLDocumentFormat ontologyFormat) throws OWLOntologyStorageException {
    final OWLOntology aBox = model.getAboxOntology();
    final OWLOntologyManager manager = aBox.getOWLOntologyManager();

    // make sure the exported ontology has an ontologyId and that it maps to the modelId
    final IRI expectedABoxIRI = model.getModelId();
    Optional<IRI> currentABoxIRI = aBox.getOntologyID().getOntologyIRI();
    if (currentABoxIRI.isPresent() == false) {
        manager.applyChange(new SetOntologyID(aBox, expectedABoxIRI));
    }
    else {
        if (expectedABoxIRI.equals(currentABoxIRI) == false) {
            OWLOntologyID ontologyID = new OWLOntologyID(Optional.of(expectedABoxIRI), Optional.of(expectedABoxIRI));
            manager.applyChange(new SetOntologyID(aBox, ontologyID));
        }
    }

    // write the model into a buffer
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    if (ontologyFormat != null) {
        manager.saveOntology(aBox, ontologyFormat, outputStream);
    }
    else {
        manager.saveOntology(aBox, outputStream);
    }

    // extract the string from the buffer
    String modelString = outputStream.toString();
    return modelString;
}
项目:owltools    文件:BioChebiGenerator.java   
private void appendOntologyId(OWLOntologyID ontologyID, StringBuilder sb) {
    Optional<IRI> ontologyIRI = ontologyID.getOntologyIRI();
    if (ontologyIRI.isPresent()) {
        sb.append("Ontology(id=").append(ontologyIRI.get());
        Optional<IRI> versionIRI = ontologyID.getVersionIRI();
        if (versionIRI .isPresent()) {
            sb.append(", version=").append(versionIRI.get());
        }
        sb.append(")");

    }
    else {
        sb.append("Ontology with no ID");
    }
}
项目:owltools    文件:EcoTools.java   
/**
 * Create an instance for the given graph and reasoner.
 * 
 * @param graph
 * @param reasoner
 * @param disposeReasoner set to true, if the reasoner should also be disposed
 * @throws UnknownOWLOntologyException
 * @throws OWLOntologyCreationException
 * 
 * @see #dispose()
 */
public EcoTools (OWLGraphWrapper graph, OWLReasoner reasoner, boolean disposeReasoner) throws UnknownOWLOntologyException, OWLOntologyCreationException {

    // This has bitten me, so let's try and bew specific...
    if( reasoner == null ){ throw new Error("No reasoner was specified for use with the EcoTools. Add a reasoner for the command line"); }

    // assume the graph wrapper is more than eco
    // try to find ECO by its purl
    Set<OWLOntology> allOntologies = graph.getAllOntologies();
    OWLOntology eco = null;
    for (OWLOntology owlOntology : allOntologies) {
        OWLOntologyID id = owlOntology.getOntologyID();
        Optional<IRI> ontologyIRI = id.getOntologyIRI();
        if (ontologyIRI.isPresent()) {
            if (ECO_PURL.equals(ontologyIRI.get().toString())) {
                eco = owlOntology;
            }
        }
    }
    if (eco != null) {
        // found eco create new wrapper
        this.eco = new OWLGraphWrapper(eco);
    }
    else {
        // did not find eco, use whole wrapper
        this.eco = graph;
    }

    this.reasoner = reasoner;
    this.disposeReasonerP = disposeReasoner;
}
项目:owltools    文件:EcoMapperFactory.java   
/**
 * Create a {@link TraversingEcoMapper} instance using the given
 * {@link OWLGraphWrapper}. It is assumed that ECO can be retrieved from the
 * graph using its default IRI. The mappings are retrieved using the PURL.
 * <p>
 * Uses the given reasoner in the traversal methods. If disposeReasoner is
 * set to true, dispose also the reasoner, while calling
 * {@link TraversingEcoMapper#dispose()}.
 * 
 * @param all
 *            graph containing all ontologies, including ECO
 * @param reasoner
 *            reasoner capable of traversing ECO
 * @param disposeReasoner
 *            set to true if the reasoner should be disposed, when calling
 *            {@link TraversingEcoMapper#dispose()}
 * @return mapper
 * @throws IOException
 * @throws OWLException
 * @throws IllegalArgumentException
 *             throw when the reasoner is null, or the
 *             {@link OWLGraphWrapper} does not contain ECO.
 * 
 * @see EcoMapper#ECO_PURL_IRI
 * @see EcoMapper#ECO_MAPPING_PURL
 */
public static TraversingEcoMapper createTraversingEcoMapper(OWLGraphWrapper all, OWLReasoner reasoner, boolean disposeReasoner) throws IOException, OWLException {

    // This has bitten me, so let's try and be specific...
    if( reasoner == null )  {
        throw new IllegalArgumentException("No reasoner was specified for use with the EcoTools. Add a reasoner for the command line");
    }

    OWLOntology eco = null;

    // assume the graph wrapper is more than eco
    // try to find ECO by its purl
    Set<OWLOntology> allOntologies = all.getAllOntologies();
    for (OWLOntology owlOntology : allOntologies) {
        OWLOntologyID id = owlOntology.getOntologyID();
        Optional<IRI> ontologyIRI = id.getOntologyIRI();
        if (ontologyIRI.isPresent()) {
            if (EcoMapper.ECO_PURL_IRI.equals(ontologyIRI.get())) {
                eco = owlOntology;
            }
        }
    }
    if (eco == null) {
        throw new IllegalArgumentException("The specified graph did not contain ECO with the IRI: "+EcoMapper.ECO_PURL_IRI);
    }

    OWLGraphWrapper ecoGraph = new OWLGraphWrapper(eco);
    Reader reader = null;
    try {
        reader = createReader(EcoMapper.ECO_MAPPING_PURL);
        EcoMappings<OWLClass> mappings = loadEcoMappings(reader, ecoGraph);
        return new TraversingEcoMapperImpl(mappings, reasoner, disposeReasoner);
    }
    finally {
        IOUtils.closeQuietly(reader);
    }
}
项目:owltools    文件:QuerySubsetGeneratorTest.java   
private OWLGraphWrapper getTargetGraph() throws Exception {
    OWLOntologyManager targetManager = OWLManager.createOWLOntologyManager();
    OWLOntologyID ontologyID  = new OWLOntologyID(Optional.of(IRI.create("http://test.owltools.org/dynamic")), Optional.absent());
    OWLOntology targetOntology = targetManager.createOntology(ontologyID);
    OWLGraphWrapper targetGraph = new OWLGraphWrapper(targetOntology);
    return targetGraph;
}
项目:ISAAC    文件:OWLExporter.java   
/**
 * Instantiates a {@link OWLExporter} from the specified parameters.
 *
 * @param fileOutputStream the file output stream
 * @throws Exception if something goes wrong in constructor
 */
public OWLExporter(OutputStream fileOutputStream) throws Exception {
  dos = new DataOutputStream(new BufferedOutputStream(fileOutputStream));
  if (snomed == null) {
    // Create a new ontology
    snomed =
        manager
            .createOntology(new OWLOntologyID(snomedIRI, snomedVersionIRI));
    format.setParameter("xml:base", snomedNamespace);

    // Obtain SNOMED root concept
    // TODO: this needs to be generalized
    UUID snomedRootUUID = Taxonomies.SNOMED.getUuids()[0];
    ConceptVersionBI snomedRootConcept =
        OTFUtility.getConceptVersion(snomedRootUUID);

    // Add annotation based on root concept
    for (DescriptionVersionBI<?> desc : snomedRootConcept
        .getDescriptionsActive()) {
      if (desc.getText().contains("Release")) {
        manager.applyChange(new AddOntologyAnnotation(snomed, factory
            .getOWLAnnotation(factory
                .getOWLAnnotationProperty(OWLRDFVocabulary.OWL_VERSION_INFO
                    .getIRI()), factory.getOWLLiteral(desc.getText()))));
      }
      if (desc.getText().contains("IHTSDO")) {
        manager.applyChange(new AddOntologyAnnotation(snomed, factory
            .getOWLAnnotation(factory
                .getOWLAnnotationProperty(OWLRDFVocabulary.RDFS_COMMENT
                    .getIRI()), factory.getOWLLiteral(desc.getText()))));
      }
    }
    manager.applyChange(new AddOntologyAnnotation(snomed, factory
        .getOWLAnnotation(factory
            .getOWLAnnotationProperty(OWLRDFVocabulary.RDFS_LABEL.getIRI()),
            factory.getOWLLiteral(snomedOntologyName))));
  }
}
项目:SVoNt    文件:PartitionEL.java   
/**
 * Splits the given ontology into two partitions: The set of OWL EL
 * compliant axioms and the set of axioms which are not compliant with the
 * OWL EL profile. The EL compliant partition is stored in the left part of
 * resulting pair, and the EL non-compliant partition is stored in the right
 * part.
 * 
 * @param sourceOnto
 *            The source ontology to be partitioned.
 * @param compatibilityMode
 *            Specifies the reasoner with which the resulting partition
 *            should be compatible (e.g. Pellet has a different notion of EL
 *            than other reasoners).
 * @return A pair containing two ontologies. The left part is the partition
 *         of the source ontology with all EL-compliant axioms. The right
 *         part is the partition of the source ontology with all
 *         non-EL-compliant axioms. If the source ontology already conforms
 *         to the OWL-EL profile, then the left part of the result contains
 *         the source ontology, and the right part is null.
 * @throws OWLOntologyCreationException
 *             If there is an error loading the source ontology.
 * @throws IllegalAccessException 
 * @throws InstantiationException 
 */
public static Pair<OWLOntology, OWLOntology> partition(OWLOntology sourceOnto, ReasonerCompatibilityMode compatibilityMode)
        throws OWLOntologyCreationException, InstantiationException, IllegalAccessException {

    OWLProfile elProfile = compatibilityMode.getProfileClass().newInstance();

    OWLProfileReport report = elProfile.checkOntology(sourceOnto);

    if (report.isInProfile()) {
        return new ImmutablePair<OWLOntology, OWLOntology>(sourceOnto, null);
    }

    HashSet<OWLAxiom> nonELAxioms = new HashSet<OWLAxiom>();

    Set<OWLProfileViolation> violations = report.getViolations();
    for (OWLProfileViolation violation : violations) {
        nonELAxioms.add(violation.getAxiom());
    }

    OWLOntologyID ontologyID = sourceOnto.getOntologyID();
    IRI ontologyIRI = ontologyID.getOntologyIRI();

    IRI targetELOntologyIRI = IRI.create(ontologyIRI.toString() + "/ELpart");
    IRI targetNonELOntologyIRI = IRI.create(ontologyIRI.toString() + "/nonELpart");

    OWLOntologyManager targetELOntoManager = OWLManager.createOWLOntologyManager();
    targetELOntoManager.addIRIMapper(new NonMappingOntologyIRIMapper());
    OWLOntology targetELOnto = targetELOntoManager.createOntology(new OWLOntologyID(targetELOntologyIRI));

    OWLOntologyManager targetNonELOntoManager = OWLManager.createOWLOntologyManager();
    targetNonELOntoManager.addIRIMapper(new NonMappingOntologyIRIMapper());
    OWLOntology targetNonELOnto = targetNonELOntoManager.createOntology(new OWLOntologyID(targetNonELOntologyIRI));

    Set<OWLAxiom> allAxioms = sourceOnto.getAxioms();
    for (OWLAxiom axiom : allAxioms) {
        if (nonELAxioms.contains(axiom)) {
            targetNonELOntoManager.addAxiom(targetNonELOnto, axiom);
            System.out.println("- " + axiom);
        } else {
            targetELOntoManager.addAxiom(targetELOnto, axiom);
            System.out.println("+ " + axiom);
        }
    }

    return new ImmutablePair<OWLOntology, OWLOntology>(targetELOnto, targetNonELOnto);
}
项目:binaryowl    文件:OntologyChangeDataList.java   
public OntologyChangeDataList(List<OWLOntologyChange> ontologyChanges, OWLOntologyID targetOntology, long timeStamp, BinaryOWLMetadata metadata) {
    List<OWLOntologyChangeData> infoList = new ArrayList<OWLOntologyChangeData>();
    for(OWLOntologyChange change : ontologyChanges) {
        if(change.getOntology().getOntologyID().equals(targetOntology)) {
            infoList.add(change.getChangeData());
        }
    }
    this.timestamp = timeStamp;
    this.metadata = metadata;
    this.list = Collections.unmodifiableList(infoList);
}
项目:minerva    文件:CoreMolecularModelManager.java   
/**
 * Try to load (or replace) a model with the given ontology. It is expected
 * that the content is an A-Box ontology, which imports the T-BOX. Also the
 * ontology ID is used to extract the modelId.<br>
 * <br>
 * This method will currently <b>NOT<b> work due to a bug in the OWL-API.
 * The functional syntax parser does not properly report the exceptions and
 * will return an ontology with an wrong ontology ID!
 * 
 * @param modelData
 * @return modelId
 * @throws OWLOntologyCreationException
 */
public ModelContainer importModel(String modelData) throws OWLOntologyCreationException {
    // load data from String
    final OWLOntologyManager manager = graph.getManager();
    final OWLOntologyDocumentSource documentSource = new StringDocumentSource(modelData);
    OWLOntology modelOntology;
    final Set<OWLParserFactory> originalFactories = removeOBOParserFactories(manager);
    try {
        modelOntology = manager.loadOntologyFromOntologyDocument(documentSource);
    }
    catch (OWLOntologyAlreadyExistsException e) {
        // exception is thrown if there is an ontology with the same ID already in memory 
        OWLOntologyID id = e.getOntologyID();
        IRI existingModelId = id.getOntologyIRI().orNull();

        // remove the existing memory model
        unlinkModel(existingModelId);

        // try loading the import version (again)
        modelOntology = manager.loadOntologyFromOntologyDocument(documentSource);
    }
    finally {
        resetOBOParserFactories(manager, originalFactories);
    }

    // try to extract modelId
    IRI modelId = null;
    Optional<IRI> ontologyIRI = modelOntology.getOntologyID().getOntologyIRI();
    if (ontologyIRI.isPresent()) {
        modelId = ontologyIRI.get();
    }
    if (modelId == null) {
        throw new OWLOntologyCreationException("Could not extract the modelId from the given model");
    }
    // paranoia check
    ModelContainer existingModel = modelMap.get(modelId);
    if (existingModel != null) {
        unlinkModel(modelId);
    }

    // add to internal model
    ModelContainer newModel = addModel(modelId, modelOntology);

    // update imports
    updateImports(newModel);

    return newModel;
}
项目:owltools    文件:CommandRunner.java   
private void catOntologies(Opts opts) throws OWLOntologyCreationException, IOException {
     opts.info("[-r|--ref-ont ONT] [-i|--use-imports]", "Catenate ontologies taking only referenced subsets of supporting onts.\n"+
             "        See Mooncat docs");
     Mooncat m = new Mooncat(g);
     ParserWrapper pw = new ParserWrapper();
     String newURI = null;
     while (opts.hasOpts()) {
         //String opt = opts.nextOpt();
         if (opts.nextEq("-r") || opts.nextEq("--ref-ont")) {
             LOG.error("DEPRECATED - list all ref ontologies on main command line");
             String f = opts.nextOpt();
             m.addReferencedOntology(pw.parseOWL(f));
         }
         else if (opts.nextEq("-s") || opts.nextEq("--src-ont")) {
             m.setOntology(pw.parseOWL(opts.nextOpt()));
         }
         else if (opts.nextEq("-p") || opts.nextEq("--prefix")) {
             m.addSourceOntologyPrefix(opts.nextOpt());
         }
         else if (opts.nextEq("-i") || opts.nextEq("--use-imports")) {
             System.out.println("using everything in imports closure");
             g.addSupportOntologiesFromImportsClosure();
         }
         else if (opts.nextEq("-n") || opts.nextEq("--new-uri")) {
             System.out.println("new URI for merged ontology");
             newURI = opts.nextOpt();
         }
         else {
             break;
             //opts.fail();
         }
     }
     //if (m.getReferencedOntologies().size() == 0) {
     // m.setReferencedOntologies(g.getSupportOntologySet());
     //}
     //g.useImportClosureForQueries();
     //for (OWLAxiom ax : m.getClosureAxiomsOfExternalReferencedEntities()) {
     // System.out.println("M_AX:"+ax);
     //}

     m.mergeOntologies();
     m.removeDanglingAxioms();
     if (newURI != null) {
         SetOntologyID soi = new SetOntologyID(g.getSourceOntology(),
                 new OWLOntologyID(Optional.of(IRI.create(newURI)), Optional.<IRI>absent()));
         g.getManager().applyChange(soi);
         /*
HashSet<OWLOntology> cpOnts = new HashSet<OWLOntology>();
LOG.info("srcOnt annots:"+g.getSourceOntology().getAnnotations().size());
cpOnts.add(g.getSourceOntology());
OWLOntology newOnt = g.getManager().createOntology(IRI.create(newURI), cpOnts);
LOG.info("newOnt annots:"+newOnt.getAnnotations().size());

//g.getDataFactory().getOWLOn
g.setSourceOntology(newOnt);
          */
     }
 }
项目:owltools    文件:BioChebiGenerator.java   
/**
 * Create the GCIs for BioChEBI. Add the axioms into the given ontology.
 * 
 * @param ontology
 * @param ignoredClasses
 */
public void expand(OWLOntology ontology, Set<OWLClass> ignoredClasses) {
    final OWLOntologyManager manager = ontology.getOWLOntologyManager();
    final OWLDataFactory factory = manager.getOWLDataFactory();

    // scan axioms
    Set<OWLSubClassOfAxiom> axioms = ontology.getAxioms(AxiomType.SUBCLASS_OF, Imports.INCLUDED);
    for (OWLSubClassOfAxiom axiom : axioms) {
        OWLClassExpression superCE = axiom.getSuperClass();
        OWLClassExpression subCE = axiom.getSubClass();
        if (subCE.isAnonymous()) {
            // sub class needs to be an named OWLClass
            continue;
        }

        if (superCE instanceof OWLObjectSomeValuesFrom == false) {
            continue;
        }
        OWLObjectSomeValuesFrom some = (OWLObjectSomeValuesFrom) superCE;

        OWLObjectPropertyExpression expression = some.getProperty();
        if (expression.isAnonymous()) {
            // object property expression needs to be a named OWLObjectProperty 
            continue;
        }

        OWLObjectProperty p = (OWLObjectProperty) expression;

        Set<OWLObjectProperty> expansions = expansionMap.get(p);
        if (expansions == null) {
            continue;
        }

        // get content for GCI
        OWLClassExpression y = some.getFiller();
        OWLClass x = subCE.asOWLClass();
        if (ignoredClasses.contains(x)) {
            continue;
        }
        for (OWLObjectProperty createProperty : expansions) {
            OWLClassExpression ce1 = factory.getOWLObjectSomeValuesFrom(createProperty, x);
            OWLClassExpression ce2 = factory.getOWLObjectSomeValuesFrom(createProperty, y);
            OWLEquivalentClassesAxiom eq = factory.getOWLEquivalentClassesAxiom(ce1, ce2);
            manager.addAxiom(ontology, eq);
        }
    }

    Set<OWLOntology> imports = ontology.getImports();
    StringBuilder sb = new StringBuilder();
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    sb.append("Generated on ").append(dateFormat.format(new Date())).append(" using the following import chain:");
    for (OWLOntology owlOntology : imports) {
        OWLOntologyID ontologyID = owlOntology.getOntologyID();
        sb.append(" ");
        appendOntologyId(ontologyID, sb);
    }
    addComment(sb.toString(), ontology);
}
项目:owltools    文件:ImportClosureSlurper.java   
public void save(File baseFolder, BufferedWriter w) throws IOException, OWLOntologyStorageException {
    w.write("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n");
    w.write("<catalog prefer=\"public\" xmlns=\"urn:oasis:names:tc:entity:xmlns:xml:catalog\">\n");

    for (OWLOntology ont : ontology.getImportsClosure()) {
        validateImports(ont);

        OWLOntologyID ontologyID = ont.getOntologyID();
        IRI actualIRI = null;
        Optional<IRI> optional = ontologyID.getOntologyIRI();
        if (optional.isPresent()) {
            actualIRI = optional.get();
        }

        // Not really sure why this is here, but apparently we can get
        // an ontology without an IRI, in which case we'll generate one
        // that is 'sort of' unique (only fails if two different machines run
        // this tool at the exact same time).
        //
        if (actualIRI == null) {
            IRI generatedIRI = IRI.generateDocumentIRI();
            actualIRI = generatedIRI;
        }
        // Always write the actualIRI
        String actualLocalFile = createLocalFileName(actualIRI);
        IRI outputStream = IRI.create(new File(baseFolder, actualLocalFile));
        ont.getOWLOntologyManager().saveOntology(ont, outputStream);

        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("name: "+ actualIRI +" local: "+actualLocalFile);
        }
        w.write("  <uri name=\""+ actualIRI  +"\" uri=\""+ actualLocalFile +"\"/>\n");

        //
        // In case there is a difference between the source document IRI
        // and the IRI of the resolved target (e.g., there is an HTTP
        // redirect from a legacy IRI to a newer IRI), then write an entry
        // in the catalog that points the legacy IRI to the newer, canonical one.
        // Examples of this include:
        //  http://purl.obolibrary.org/obo/so.owl
        // which redirects to:
        //  http://purl.obolibrary.org/obo/so-xp.obo.owl
        //

        IRI             documentIRI = ont.getOWLOntologyManager().getOntologyDocumentIRI(ont);
        if (documentIRI != actualIRI) {
            String sourceLocalFile = createLocalFileName(actualIRI);
            if (LOGGER.isInfoEnabled()) {
                LOGGER.info("alias: "+ documentIRI + " ==> " + actualIRI + " local: "+ sourceLocalFile);
            }
            w.write("  <uri name=\""+ documentIRI +"\" uri=\""+ sourceLocalFile +"\"/>\n");
        }
    }
    w.write("</catalog>\n");
    w.flush();
}
项目:binaryowl    文件:BinaryOWLOntologyDocumentHandlerAdapter.java   
@Override
public void handleOntologyID(OWLOntologyID ontologyID) throws E {
}
项目:binaryowl    文件:BinaryOWLV1DocumentBodySerializer.java   
public <E extends Throwable> void read(DataInputStream dis, BinaryOWLOntologyDocumentHandler<E> handler, OWLDataFactory df) throws IOException, BinaryOWLParseException, UnloadableImportException, E {

        BinaryOWLInputStream inputStream = new BinaryOWLInputStream(dis, df, VERSION);

        // Metadata
        BinaryOWLMetadataChunk chunk = new BinaryOWLMetadataChunk(inputStream);
        BinaryOWLMetadata metadata = chunk.getMetadata();
        handler.handleDocumentMetaData(metadata);

        handler.handleBeginInitialDocumentBlock();

        // Ontology ID
        BinaryOWLOntologyID serializer = new BinaryOWLOntologyID(inputStream);
        OWLOntologyID ontologyID = serializer.getOntologyID();
        handler.handleOntologyID(ontologyID);

        // Imported ontologies
        BinaryOWLImportsDeclarationSet importsDeclarationSet = new BinaryOWLImportsDeclarationSet(inputStream);
        Set<OWLImportsDeclaration> importsDeclarations = importsDeclarationSet.getImportsDeclarations();
        handler.handleImportsDeclarations(importsDeclarations);

        // IRI Table
        IRILookupTable iriLookupTable = new IRILookupTable(dis);

        // Used to be literal table
        // Skip 1 byte - the interning marker
        inputStream.skip(1);


        LookupTable lookupTable = new LookupTable(iriLookupTable);


        BinaryOWLInputStream lookupTableStream = new BinaryOWLInputStream(dis, lookupTable, df, VERSION);

        // Ontology Annotations
        Set<OWLAnnotation> annotations = lookupTableStream.readOWLObjects();
        handler.handleOntologyAnnotations(annotations);

        // Axiom tables - axioms by type
        for (int i = 0; i < AxiomType.AXIOM_TYPES.size(); i++) {
            Set<OWLAxiom> axiomsOfType = lookupTableStream.readOWLObjects();
            handler.handleAxioms(axiomsOfType);
        }

        handler.handleEndInitialDocumentBlock();
        handler.handleBeginDocumentChangesBlock();
        BinaryOWLInputStream changesInputStream = new BinaryOWLInputStream(dis, df, VERSION);
        // Read any changes that have been appended to the end of the file - no look up table for this
        readOntologyChanges(changesInputStream, handler);
        handler.handleEndDocumentChangesBlock();
        handler.handleEndDocument();
    }
项目:binaryowl    文件:OntologyChangeRecordRun.java   
public OntologyChangeRecordRun(OWLOntologyID ontologyID, List<OWLOntologyChangeData> records) {
    this.ontologyID = ontologyID;
    this.records = new ArrayList<OWLOntologyChangeData>(records);
}
项目:binaryowl    文件:OntologyChangeRecordRun.java   
public OWLOntologyID getOntologyID() {
    return ontologyID;
}
项目:binaryowl    文件:SetOntologyIDDataSerializer.java   
@Override
public void write(SetOntologyIDData recordData, BinaryOWLOutputStream outputStream) throws IOException {
    OWLOntologyID id = recordData.getNewId();
    BinaryOWLOntologyID serializer = new BinaryOWLOntologyID(id);
    serializer.write(outputStream);
}
项目:binaryowl    文件:BinaryOWLOntologyID.java   
public BinaryOWLOntologyID(OWLOntologyID ontologyID) {
    this.ontologyID = ontologyID;
}
项目:binaryowl    文件:BinaryOWLOntologyID.java   
public OWLOntologyID getOntologyID() {
    return ontologyID;
}
项目:binaryowl    文件:BinaryOWLOntologyDocumentHandler.java   
void handleOntologyID(OWLOntologyID ontologyID) throws E;
项目:binaryowl    文件:HasOntologyID.java   
OWLOntologyID getOntologyID();