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

项目:neo4j-sparql-extension-yars    文件:Rules.java   
/**
 * Returns a list of rules extracted from the given OWL-2 ontology document.
 * 
 * @param src an ontology document
 * @return a list of rules
 */
public static List<Rule> fromOntology(OWLOntologyDocumentSource src) {
    try {
        // use OWL-API to get a OWLOntology document from source
        OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
        manager.loadOntologyFromOntologyDocument(src);
        Set<OWLOntology> ontologies = manager.getOntologies();
        if (ontologies.isEmpty()) {
            return Collections.EMPTY_LIST;
        } else {
            // use first ontology from given source
            return fromOntology(ontologies.iterator().next());
        }
    } catch (OWLOntologyCreationException ex) {
        throw new IllegalArgumentException(
                "Loading ontology stream failed", ex);
    }
}
项目:neo4j-sparql-extension-yars    文件:Rules.java   
/**
 * Returns a list of rules extracted from the given OWL-2 ontology document.
 * @param in an ontology document as stream
 * @return a list of rules
 */
public static List<Rule> fromOntology(InputStream in) {
    try {
        // use OWL-API to get a OWLOntology document from source
        OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
        manager.loadOntologyFromOntologyDocument(in);
        Set<OWLOntology> ontologies = manager.getOntologies();
        if (ontologies.isEmpty()) {
            return Collections.EMPTY_LIST;
        } else {
            // use first ontology from given source
            return fromOntology(ontologies.iterator().next());
        }
    } catch (OWLOntologyCreationException ex) {
        throw new IllegalArgumentException(
                "Loading ontology stream failed", ex);
    }
}
项目:geoxygene    文件:OwlUtil.java   
/**
 * Open the OWL ontology (from the ontology resources of CartAGen) whose name
 * is passed as parameter.
 * @param name
 * @return
 * @throws OWLOntologyCreationException
 */
public static OWLOntology getOntologyFromName(String name)
    throws OWLOntologyCreationException {
  // create the URI from the name and the CartAGen ontologies folder path
  String uri = FOLDER_PATH + "/" + name + ".owl";
  InputStream stream = OwlUtil.class.getResourceAsStream(uri);
  File file = new File(stream.toString());
  String path = file.getAbsolutePath().substring(0,
      file.getAbsolutePath().lastIndexOf('\\'));
  path = path.replaceAll(new String("\\\\"), new String("//"));
  path = path + "//src/main//resources//ontologies//" + name + ".owl";
  // create the ontology from the URI using an OWLOntologyManager
  OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
  IRI physicalURI = IRI.create(new File(path));
  OWLOntology ontology = manager
      .loadOntologyFromOntologyDocument(physicalURI);

  return ontology;
}
项目:Resource2Vec    文件:R2VManager.java   
/**
 * @param filename
 * @return
 */
private static OWLOntology getOntology(String filename) {
    File file = new File(filename);

    OWLOntologyManager m = OWLManager.createOWLOntologyManager();

    OWLOntology o;
    try {
        o = m.loadOntologyFromOntologyDocument(IRI.create(file.toURI()));
    } catch (OWLOntologyCreationException e) {
        fail("Cannot load ontology.");
        return null;
    }
    assertNotNull(o);

    return o;
}
项目:owltools    文件:ProvenanceReasonerWrapper.java   
public boolean isEdgeEntailed(OWLEdge e, OWLOntology currentOntology, OWLReasoner reasoner) {
    OWLOntologyManager m = getManager();

    Set<OWLSubClassOfAxiom> scas = currentOntology.getSubClassAxiomsForSubClass(e.c);
    Set<OWLSubClassOfAxiom> rmAxioms = new HashSet<OWLSubClassOfAxiom>();
    for (OWLSubClassOfAxiom sca : scas) {
        if (sca.getSuperClass().equals(e.p)) {
            LOG.info("REMOVING: "+sca);
            rmAxioms.add(sca);
        }
    }
    boolean isEdgeAsserted = rmAxioms.size() > 0;
    if (isEdgeAsserted) {
        m.removeAxioms(currentOntology, rmAxioms);
        reasoner.flush();
    }
    boolean isEntailed;
    isEntailed = reasoner.getSuperClasses(e.c, false).containsEntity(e.p);
    if (isEdgeAsserted) {
        m.addAxioms(currentOntology, rmAxioms);
        reasoner.flush();
    }

    return isEntailed;
}
项目: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;
}
项目:minerva    文件:GafToLegoTranslator.java   
private void addBioEntity(OWLClass pr, OWLOntology lego, Bioentity bioentity) {
    Set<OWLDeclarationAxiom> declarationAxioms = lego.getDeclarationAxioms(pr);
    if (declarationAxioms == null || declarationAxioms.isEmpty()) {
        // add class declaration and add label
        OWLOntologyManager m = lego.getOWLOntologyManager();
        OWLDataFactory f = m.getOWLDataFactory();

        Set<OWLAxiom> axioms = new HashSet<OWLAxiom>();
        axioms.add(f.getOWLDeclarationAxiom(pr));

        String label = bioentity.getSymbol()+" - "+bioentity.getFullName();

        axioms.add(f.getOWLAnnotationAssertionAxiom(f.getRDFSLabel(), pr.getIRI(), f.getOWLLiteral(label)));

        m.addAxioms(lego, axioms);
    }
}
项目:minerva    文件:GafToLegoTranslator.java   
/**
 * Translate the given {@link GafDocument} into an OWL representation of the LEGO model.
 * Additionally minimize the lego model and imports into one ontology module.
 * 
 * @param gaf
 * @return minimized lego ontology
 */
public OWLOntology minimizedTranslate(GafDocument gaf) {
    OWLOntology all = translate(gaf);
    final OWLOntologyManager m = all.getOWLOntologyManager();

    SyntacticLocalityModuleExtractor sme = new SyntacticLocalityModuleExtractor(m, all, ModuleType.BOT);
    Set<OWLEntity> sig = new HashSet<OWLEntity>(all.getIndividualsInSignature());
    Set<OWLAxiom> moduleAxioms = sme.extract(sig);

    try {
        OWLOntology module = m.createOntology(IRI.generateDocumentIRI());
        m.addAxioms(module, moduleAxioms);
        return module;
    } catch (OWLException e) {
        throw new RuntimeException("Could not create minimized lego model.", e);
    }
}
项目:owltools    文件:GMTParser.java   
private void parseRow(String[] row) {
    OWLDataFactory df = graph.getDataFactory();
    OWLOntologyManager mgr = graph.getManager();
    String geneSetId = row[0];
    IRI geneSetIRI = IRI.create(prefix + geneSetId);
    String desc = row[1];
    OWLClass geneSetCls = df.getOWLClass(geneSetIRI);
    OWLAxiom ax = df.getOWLAnnotationAssertionAxiom(df.getRDFSLabel(),geneSetIRI, literal(desc));
    mgr.addAxiom(graph.getSourceOntology(), ax);

    // assume each value is an entity, e.g. gene
    for (int i=2; i < row.length; i++) {
        OWLNamedIndividual individual = df.getOWLNamedIndividual(IRI.create(prefix + row[i]));
        mgr.addAxiom(graph.getSourceOntology(), df.getOWLClassAssertionAxiom(geneSetCls, individual));
    }
}
项目:minerva    文件:BlazegraphMolecularModelManager.java   
/**
 * Save a model to the database.
 * 
 * @param m
 * @param annotations
 * @param metadata
 *
 * @throws OWLOntologyStorageException
 * @throws OWLOntologyCreationException
 * @throws IOException
 * @throws RepositoryException 
 * @throws UnknownIdentifierException 
 */
public void saveModel(ModelContainer m,
        Set<OWLAnnotation> annotations, METADATA metadata)
                throws OWLOntologyStorageException, OWLOntologyCreationException,
                IOException, RepositoryException, UnknownIdentifierException {
    IRI modelId = m.getModelId();
    final OWLOntology ont = m.getAboxOntology();
    final OWLOntologyManager manager = ont.getOWLOntologyManager();
    List<OWLOntologyChange> changes = preSaveFileHandler(ont);
    synchronized(ont) {
        try {
            this.writeModelToDatabase(ont, modelId);
            // reset modified flag for abox after successful save
            m.setAboxModified(false);
        } finally {
            if (changes != null) {
                List<OWLOntologyChange> invertedChanges = ReverseChangeGenerator
                        .invertChanges(changes);
                if (invertedChanges != null && !invertedChanges.isEmpty()) {
                    manager.applyChanges(invertedChanges);
                }
            }
        }
    }
}
项目:owltools    文件:AssertInferenceTool.java   
private static List<OWLOntologyChange> handleSupportOntologies(OWLGraphWrapper graph)
{
    OWLOntology ontology = graph.getSourceOntology();
    OWLOntologyManager manager = ontology.getOWLOntologyManager();
    OWLDataFactory factory = manager.getOWLDataFactory();

    List<OWLOntologyChange> removeImportChanges = new ArrayList<OWLOntologyChange>();
    Set<OWLOntology> supportOntologySet = graph.getSupportOntologySet();
    for (OWLOntology support : supportOntologySet) {
        Optional<IRI> supportIRI = support.getOntologyID().getOntologyIRI();
        if(supportIRI.isPresent()) {
            IRI ontologyIRI = supportIRI.get();
            OWLImportsDeclaration importDeclaration = factory.getOWLImportsDeclaration(ontologyIRI);
            ChangeApplied status = manager.applyChange(new AddImport(ontology, importDeclaration));
            if (ChangeApplied.SUCCESSFULLY == status) {
                // the change was successful, create remove import for later
                removeImportChanges.add(new RemoveImport(ontology, importDeclaration));
            }
        }
    }
    return removeImportChanges;
}
项目:pronto    文件:KBStandaloneLoader.java   
private void addAutoGeneratedClassNames(OWLOntologyManager manager,
                                        OWLOntology ontology,
                                        Map<String, OWLClassExpression> nameMap) {

    OWLDataFactory factory = manager.getOWLDataFactory();
    List<OWLOntologyChange> changes = new ArrayList<OWLOntologyChange>();

    for (Map.Entry<String, OWLClassExpression> entry : nameMap.entrySet()) {

        OWLClass subClass = factory.getOWLClass( IRI.create(entry.getKey()) );
        OWLAxiom declAxiom = factory.getOWLEquivalentClassesAxiom( subClass, entry.getValue() );

        changes.addAll( manager.addAxiom( ontology, declAxiom ) );
    }

    manager.applyChanges( changes );
}
项目:pronto    文件:KBEmbeddedLoader.java   
private void addAutoGeneratedClassNames(OWLOntologyManager manager,
                                        OWLOntology ontology,
                                        Map<String, OWLClassExpression> nameMap) {

    OWLDataFactory factory = manager.getOWLDataFactory();
    List<OWLOntologyChange> changes = new ArrayList<OWLOntologyChange>();

    for (Map.Entry<String, OWLClassExpression> entry : nameMap.entrySet()) {

        OWLClass subClass = factory.getOWLClass( IRI.create(entry.getKey()) );
        OWLAxiom declAxiom = factory.getOWLEquivalentClassesAxiom( subClass, entry.getValue() );

        changes.addAll( manager.addAxiom( ontology, declAxiom ) );
    }

    manager.applyChanges( changes );
}
项目:owltools    文件:OWLConverter.java   
/**
 * Add an synonym annotation, plus an annotation on that annotation
 * that specified the type of synonym. The second annotation has the
 * property oio:hasSynonymType.
 *
 * @param ontology the current ontology
 * @param subject the subject of the annotation
 * @param type the IRI of the type of synonym
 * @param property the IRI of the annotation property.
 * @param value the literal value of the synonym
 * @return the synonym annotation axiom
 */
protected static OWLAnnotationAssertionAxiom synonym(
        OWLOntology ontology, OWLEntity subject, 
        OWLAnnotationValue type,
        OWLAnnotationProperty property, 
        OWLAnnotationValue value) {
    OWLOntologyManager manager = ontology.getOWLOntologyManager();
    OWLDataFactory dataFactory = manager.getOWLDataFactory();
    OWLAnnotationProperty hasSynonymType =
        dataFactory.getOWLAnnotationProperty(
            format.getIRI("oio:hasSynonymType"));
    OWLAnnotation annotation = 
        dataFactory.getOWLAnnotation(hasSynonymType, type);
    Set<OWLAnnotation> annotations = new HashSet<OWLAnnotation>();
    annotations.add(annotation);
    OWLAnnotationAssertionAxiom axiom =
        dataFactory.getOWLAnnotationAssertionAxiom(
            property, subject.getIRI(), value,
            annotations);
    manager.addAxiom(ontology, axiom);
    return axiom;
}
项目:logmap-matcher    文件:BasicMultiplePartitioning.java   
public OWLOntology loadOWLOntology(String phy_iri_onto) throws OWLOntologyCreationException{        

        try {

            OWLOntologyManager managerOnto;
            managerOnto = SynchronizedOWLManager.createOWLOntologyManager();            
            managerOnto.setSilentMissingImportsHandling(true);                                  
            return managerOnto.loadOntology(IRI.create(phy_iri_onto));


        }
        catch(Exception e){
            System.err.println("Error loading OWL ontology: " + e.getMessage());
            //e.printStackTrace();
            throw new OWLOntologyCreationException();
        }
    }
项目:jcel    文件:ConsoleStarter.java   
/**
 * Classifies a given ontology and checks whether another ontology is
 * entailed by the former.
 *
 * @param premiseFile
 *            ontology file to be classified and used as premise
 * @param conclusionFile
 *            file with the conclusion
 * @throws FileNotFoundException
 *             if the file was not found
 * @throws OWLOntologyCreationException
 *             if the ontology could not be created
 * @throws OWLRendererException
 *             if a renderer error occurs
 * @return <code>true</code> if and only if the premise ontology entails the
 *         conclusion ontology
 */
public boolean checkEntailment(File premiseFile, File conclusionFile)
        throws OWLOntologyCreationException, OWLRendererException, FileNotFoundException {
    Objects.requireNonNull(premiseFile);
    Objects.requireNonNull(conclusionFile);
    logger.fine("starting jcel console ...");

    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();

    logger.fine("loading premise ontology using the OWL API ...");
    OWLOntology premiseOntology = manager.loadOntologyFromOntologyDocument(premiseFile);

    logger.fine("loading conclusion ontology using the OWL API ...");
    OWLOntology conclusionOntology = manager.loadOntologyFromOntologyDocument(conclusionFile);

    logger.fine("starting reasoner ...");
    JcelReasoner reasoner = new JcelReasoner(premiseOntology, false);

    logger.fine("precomputing inferences ...");
    reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY);

    boolean ret = conclusionOntology.getAxioms().stream().allMatch(axiom -> reasoner.isEntailed(axiom));

    logger.fine("jcel console finished.");
    return ret;
}
项目:owltools    文件:AssertInferenceTool.java   
private static void createModule(String moduleName, Set<OWLEntity> signature, OWLOntology ont)
        throws OWLOntologyCreationException, IOException, OWLOntologyStorageException 
{
    // create a new manager avoid unnecessary change events
    final OWLOntologyManager m = OWLManager.createOWLOntologyManager();

    // extract module
    SyntacticLocalityModuleExtractor sme = new SyntacticLocalityModuleExtractor(m, ont, ModuleType.BOT);
    Set<OWLAxiom> moduleAxioms = sme.extract(signature);

    OWLOntology module = m.createOntology(IRI.generateDocumentIRI());
    m.addAxioms(module, moduleAxioms);

    // save module
    OutputStream moduleOutputStream = null;
    try {
        moduleOutputStream = new FileOutputStream(getModuleFile(moduleName));
        m.saveOntology(module, moduleOutputStream);
    }
    finally {
        IOUtils.closeQuietly(moduleOutputStream);
    }
}
项目:elk-reasoner    文件:RetrievingProofsForEntailment.java   
/**
 * @param args
 * @throws OWLOntologyCreationException
 */
public static void main(String[] args) throws OWLOntologyCreationException {
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();

    // Load your ontology.
    OWLOntology ont = manager.loadOntologyFromOntologyDocument(new File("/path/to/your/ontology/ontology.owl"));

    // Create an instance of ELK
    ElkProverFactory proverFactory = new ElkProverFactory();
    OWLProver prover = proverFactory.createReasoner(ont);       

    // Pre-compute classification
    prover.precomputeInferences(InferenceType.CLASS_HIERARCHY);

    // Pick the entailment for which we are interested in proofs
    OWLAxiom entailment = getEntailment();

    // Get the inferences used to prove the entailment 
    DynamicProof<? extends Inference<OWLAxiom>> proof = prover.getProof(entailment);

    // Now we can recursively request inferences and their premises. Print them to std.out in this example.
    unwindProof(proof, entailment);

    // Terminate the worker threads used by the reasoner.
    prover.dispose();
}
项目:Wolpertinger    文件:WolpertingerTest.java   
/**
   * Atomic clash
   */
  public void testUnsatifiabilityDueToClashInABoxAssertions() {
    OWLDataFactory factory = OWLManager.getOWLDataFactory();
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();

    OWLClassExpression expr1 = factory.getOWLClass(IRI.create(String.format("%s#%s", PREFIX, "A")));
    OWLClassExpression expr2 = factory.getOWLObjectComplementOf(expr1);
    OWLNamedIndividual indiv = factory.getOWLNamedIndividual(IRI.create(String.format("%s#%s", PREFIX, "a")));

    OWLIndividualAxiom fact1 = factory.getOWLClassAssertionAxiom(expr1, indiv);
    OWLIndividualAxiom fact2 = factory.getOWLClassAssertionAxiom(expr2, indiv);

    try {
    OWLOntology ontology = manager.createOntology();
    manager.addAxiom(ontology, fact1);
    manager.addAxiom(ontology, fact2);

    Wolpertinger wolpertinger = new Wolpertinger(ontology);

    assertFalse(wolpertinger.isConsistent());
} catch (OWLOntologyCreationException e) {
    e.printStackTrace();
    fail();
}
  }
项目:elk-reasoner    文件:OwlApiIncrementalReasoningTestDelegate.java   
@Override
public Collection<OWLAxiom> load() throws Exception {

    final ArrayList<OWLAxiom> changingAxioms = new ArrayList<OWLAxiom>();

    final OWLOntologyManager manager = TestOWLManager
            .createOWLOntologyManager();

    final InputStream stream = getManifest().getInput().getUrl()
            .openStream();
    testOntology_ = manager.loadOntologyFromOntologyDocument(stream);

    for (OWLAxiom axiom : testOntology_.getLogicalAxioms()) {
        if (DYNAMIC_AXIOM_TYPES.contains(axiom.getAxiomType())) {
            changingAxioms.add(axiom);
        }
    }

    return changingAxioms;
}
项目: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;
}
项目:elk-reasoner    文件:OwlInternalProofTest.java   
@Before
public void before() throws Exception {
    Assume.assumeFalse(TestUtils.ignore(manifest_.getInput(),
            ElkTestUtils.TEST_INPUT_LOCATION, IGNORE_LIST));

    final InputStream input = manifest_.getInput().getUrl().openStream();
    OWLOntologyManager manager = TestOWLManager.createOWLOntologyManager();
    OWLOntology ontology = manager.loadOntologyFromOntologyDocument(input);

    this.prover_ = OWLAPITestUtils.createProver(ontology);

    this.query_ = manifest_.getInput().getQuery();

    this.adapter_ = new OwlInternalProof(
            prover_.getDelegate().getInternalReasoner(), query_);
}
项目:elk-reasoner    文件:ProofTest.java   
@Test
public void inconsistentOwlThing() throws Exception {
    OWLOntologyManager owlManager = OWLManager
            .createConcurrentOWLOntologyManager();
    // creating an ontology
    final OWLOntology ontology = owlManager.createOntology();
    OWLClass a = factory.getOWLClass(IRI.create("http://example.org/A"));
    OWLClass b = factory.getOWLClass(IRI.create("http://example.org/B"));
    // top subclass bottom => inconsistent
    owlManager.addAxiom(ontology, factory.getOWLSubClassOfAxiom(
            factory.getOWLThing(), factory.getOWLNothing()));

    final OWLProver prover = OWLAPITestUtils.createProver(ontology);

    ProofTestUtils.provabilityTest(prover,
            factory.getOWLSubClassOfAxiom(a, b));
    ProofTestUtils.provabilityTest(prover,
            factory.getOWLSubClassOfAxiom(
                    factory.getOWLObjectIntersectionOf(a, b),
                    factory.getOWLNothing()));
}
项目:elk-reasoner    文件:ProofTest.java   
@Test
public void inconsistentIndividual() throws Exception {
    OWLOntologyManager owlManager = OWLManager
            .createConcurrentOWLOntologyManager();
    // creating an ontology
    final OWLOntology ontology = owlManager.createOntology();
    OWLNamedIndividual ind = factory
            .getOWLNamedIndividual(IRI.create("http://example.org/i"));
    OWLClass a = factory.getOWLClass(IRI.create("http://example.org/A"));
    OWLClass b = factory.getOWLClass(IRI.create("http://example.org/B"));
    // ind instance of bottom => inconsistent
    owlManager.addAxiom(ontology, factory
            .getOWLClassAssertionAxiom(factory.getOWLNothing(), ind));

    final OWLProver prover = OWLAPITestUtils.createProver(ontology);

    ProofTestUtils.provabilityTest(prover,
            factory.getOWLSubClassOfAxiom(a, b));
    ProofTestUtils.provabilityTest(prover,
            factory.getOWLSubClassOfAxiom(
                    factory.getOWLObjectIntersectionOf(a, b),
                    factory.getOWLNothing()));
}
项目:elk-reasoner    文件:ProofTest.java   
@Test
public void inconsistentClass() throws Exception {
    OWLOntologyManager owlManager = OWLManager
            .createConcurrentOWLOntologyManager();
    // creating an ontology
    final OWLOntology ontology = owlManager.createOntology();
    OWLClass a = factory.getOWLClass(IRI.create("http://example.org/A"));
    OWLClass b = factory.getOWLClass(IRI.create("http://example.org/B"));
    // A subclass of bottom => A is inconsistent
    owlManager.addAxiom(ontology,
            factory.getOWLSubClassOfAxiom(a, factory.getOWLNothing()));

    final OWLProver prover = OWLAPITestUtils.createProver(ontology);

    ProofTestUtils.provabilityTest(prover,
            factory.getOWLSubClassOfAxiom(a, b));
}
项目:owltools    文件:RedundantInferences.java   
/**
 * Remove the redundant and marked as inferred super class assertions for
 * each class in the ontology signature. Uses the reasoner to infer the
 * direct super classes.
 * 
 * @param ontology
 * @param reasoner
 * @return map of class to set of redundant axioms
 */
public static Map<OWLClass, Set<RedundantAxiom>> removeRedundantSubClassAxioms(OWLOntology ontology, OWLReasoner reasoner) {
    Iterable<OWLClass> classes = ontology.getClassesInSignature();
    Map<OWLClass, Set<RedundantAxiom>> axioms = findRedundantSubClassAxioms(classes, ontology, reasoner);
    if (!axioms.isEmpty()) {
        Set<OWLSubClassOfAxiom> allAxioms = new THashSet<OWLSubClassOfAxiom>();
        for(OWLClass cls : axioms.keySet()) {
            for(RedundantAxiom redundantAxiom : axioms.get(cls)) {
                allAxioms.add(redundantAxiom.getAxiom());
            }
        }
        OWLOntologyManager manager = ontology.getOWLOntologyManager();
        manager.removeAxioms(ontology, allAxioms);
        LOG.info("Removed "+axioms.size()+" redundant axioms.");
    }
    return axioms;

}
项目:FAIRsharing-Owl2Neo    文件:Owl2Neo4jLoaderTest.java   
@Before
public void setUp() throws Exception {
    graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(new File(TEST_GRAPH_DB_PATH));
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
    OWLOntology ontology = manager.loadOntologyFromOntologyDocument(file.getFile());
    OWLDataFactory factory = manager.getOWLDataFactory();
    loader = new Owl2Neo4jLoader(graphDb, ontology, factory);
}
项目:OntoBench    文件:OwlApiConfig.java   
@Bean
@Scope(value = WebApplicationContext.SCOPE_REQUEST, proxyMode = ScopedProxyMode.INTERFACES)
public OWLMutableOntology owlOntology(PrefixManager prefixManager) throws OWLOntologyCreationException {
  if (prefixManager.getDefaultPrefix() == null) {
    throw new IllegalStateException("Default ontology prefix must not be null.");
  }

  OWLOntologyManager ontologyManager = OWLManager.createOWLOntologyManager();
  // Cast to a mutable ontology to pass OWLApi's strange checks
  return (OWLMutableOntology) ontologyManager.createOntology(IRI.create(prefixManager.getDefaultPrefix()));
}
项目:BENGAL    文件:StatisticalFunctionalityDetector.java   
public StatisticalFunctionalityDetector(File ontologyFile, double threshold) {
    try {
        OWLOntologyManager man = OWLManager.createOWLOntologyManager();
        ontology = man.loadOntologyFromOntologyDocument(ontologyFile);
        dataFactory = man.getOWLDataFactory();
    } catch (OWLOntologyCreationException e) {
        e.printStackTrace();
    }
    this.threshold = threshold;
}
项目:BENGAL    文件:StatisticalFunctionalityDetector.java   
public StatisticalFunctionalityDetector(InputStream is, double threshold) {
    try {
        OWLOntologyManager man = OWLManager.createOWLOntologyManager();
        ontology = man.loadOntologyFromOntologyDocument(is);
        dataFactory = man.getOWLDataFactory();
    } catch (OWLOntologyCreationException e) {
        e.printStackTrace();
    }
    this.threshold = threshold;
}
项目:rf2-to-owl    文件:TestRenderer.java   
public static void main(String[] args) throws Exception {
        startTime = System.currentTimeMillis();
        OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
        File testOntology = new File("/Users/alo/IdeaProjects/rf2-to-owl/sct.owl");
//        File testOntology = new File("/Users/alo/Downloads/conceptsOwlComplete-cd-alo.xml");
        System.out.println("testOntology: " + testOntology.getName());
        OWLOntology ontology = manager.loadOntologyFromOntologyDocument(testOntology);
        System.out.println("Terminology loaded in: " + (System.currentTimeMillis() - startTime) + " ms.");
        startTime = System.currentTimeMillis();
        PrintWriter writer2 = new PrintWriter("owlRefset-sct-owl.txt", "UTF-8");
        fr.render(ontology,writer2);
        writer2.close();
        System.out.println("OWL Refset created in: " + (System.currentTimeMillis() - startTime) + " ms.");
    }
项目:uel    文件:AlternativeUelStarter.java   
public AlternativeUelStarter(OWLOntologyManager ontologyManager, Set<OWLOntology> ontologies) {
    if (ontologies == null) {
        throw new IllegalArgumentException("Null argument.");
    }
    this.ontologyManager = ontologyManager;
    this.ontologies = ontologies;
}
项目:uel    文件:ProcessorTest.java   
static OWLOntology loadKRSSOntology(String input) throws OWLOntologyCreationException, IOException {
    OWLOntologyManager ontologyManager = OWLManager.createOWLOntologyManager();
    OWLOntology ontology = ontologyManager.createOntology();
    KRSS2OWLParser parser = new KRSS2OWLParser();
    parser.parse(new StreamDocumentSource(new FileInputStream(input)), ontology,
            new OWLOntologyLoaderConfiguration());
    return ontology;
}
项目:owltools    文件:CommandRunner.java   
private OWLReasoner createReasoner(OWLOntology ont, String reasonerName, 
        OWLOntologyManager manager) {
    OWLReasonerFactory reasonerFactory = createReasonerFactory(reasonerName);
    if (reasonerFactory == null) {
        System.out.println("no such reasoner: "+reasonerName);
    }
    else {
        reasoner = reasonerFactory.createReasoner(ont);
        LOG.info("Created reasoner: "+reasoner);
    }
    return reasoner;
}
项目:owltools    文件:OWLConverter.java   
/**
 * Convenience method for adding an annotation assertion to the
 * ontology.
 *
 * @param ontology the current ontology
 * @param subject the subject of the annotation
 * @param property the annotation property
 * @param value the annotation value
 * @return the annotation axiom
 */
protected static OWLAnnotationAssertionAxiom annotate(
        OWLOntology ontology, 
        OWLEntity subject,
        OWLAnnotationProperty property, 
        OWLAnnotationValue value) {
    OWLOntologyManager manager = ontology.getOWLOntologyManager();
    OWLDataFactory dataFactory = manager.getOWLDataFactory();
    OWLAnnotationAssertionAxiom axiom =
        dataFactory.getOWLAnnotationAssertionAxiom(
            property, subject.getIRI(), value);
    manager.addAxiom(ontology, axiom);
    return axiom;
}
项目:minerva    文件:GafToLegoIndividualTranslator.java   
/**
 * Translate the given annotations ({@link GeneAnnotation}) into an OWL representation of the LEGO model.
 * 
 * @param annotations
 * @param lego
 * @throws OWLException 
 * @throws UnknownIdentifierException 
 */
public void translate(Collection<GeneAnnotation> annotations, final OWLOntology lego) throws OWLException, UnknownIdentifierException {
    final OWLOntologyManager m = graph.getManager();

    Set<OWLAxiom> axioms = new HashSet<OWLAxiom>();
    for(GeneAnnotation annotation : annotations) {
        translate(annotation, axioms);
    }
    m.addAxioms(lego, axioms);
}
项目:owltools    文件:Mooncat.java   
/**
 * For every pair X DisjointWith Y, generate an axiom
 * A and Y = Nothing
 * 
 * (may become deprecated after Elk supports disjoints)
 * 
 * @param ont
 * @param manager
 * @param dataFactory
 */
public static void translateDisjointsToEquivalents(OWLOntology ont, OWLOntologyManager manager, OWLDataFactory dataFactory) {
    for (OWLDisjointClassesAxiom dca : ont.getAxioms(AxiomType.DISJOINT_CLASSES, Imports.INCLUDED)) {
        for (OWLClassExpression ce1 : dca.getClassExpressions()) {
            for (OWLClassExpression ce2 : dca.getClassExpressions()) {
                if (ce1.compareTo(ce2) <= 0)
                    continue;
                OWLEquivalentClassesAxiom eca = dataFactory.getOWLEquivalentClassesAxiom(dataFactory.getOWLNothing(),
                        dataFactory.getOWLObjectIntersectionOf(ce1, ce2));
                manager.addAxiom(ont, eca);
                // TODO - remove if requested
            }
        }
    }
}
项目:minerva    文件:GPADSPARQLTest.java   
@BeforeClass
public static void setupRules() throws OWLOntologyCreationException {
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
    OWLOntology ont = manager.loadOntologyFromOntologyDocument(GPADSPARQLTest.class.getResourceAsStream("/ro-merged-2017-10-02.ofn"));
    Set<Rule> rules = new HashSet<>();
    rules.addAll(JavaConverters.setAsJavaSetConverter(OWLtoRules.translate(ont, Imports.INCLUDED, true, true, true, true)).asJava());
    rules.addAll(JavaConverters.setAsJavaSetConverter(OWLtoRules.indirectRules(ont)).asJava());
    arachne = new RuleEngine(Bridge.rulesFromJena(JavaConverters.asScalaSetConverter(rules).asScala()), true);
}
项目:owltools    文件:GetOntologyId.java   
private OWLOntology getOntology() throws Exception{
    if(ontologyLocation.endsWith(".owl")){
        //oborelease.isObo2Owl          
        addProperty("oborelease.isowl", "true");
        OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
        return manager.loadOntologyFromOntologyDocument(new File(ontologyLocation));
    }

    addProperty("oborelease.isobo", "true");

    Obo2Owl obo2owl = new Obo2Owl();

    return obo2owl.convert(ontologyLocation);
}