Java Code Examples for org.semanticweb.elk.owlapi.ElkReasonerFactory#createReasoner()
The following examples show how to use
org.semanticweb.elk.owlapi.ElkReasonerFactory#createReasoner() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QueryingWithNamedClasses.java From elk-reasoner with Apache License 2.0 | 6 votes |
public QueryingWithNamedClasses() throws OWLOntologyCreationException { // Traditional setup with the OWL-API manager = OWLManager.createOWLOntologyManager(); IRI ontologyIri = IRI.create(EL_ONTOLOGY); ontology = manager.loadOntologyFromOntologyDocument(ontologyIri); System.out.println("Loaded ontology: " + ontology.getOntologyID()); // But we use the Elk reasoner (add it to the classpath) reasonerFactory = new ElkReasonerFactory(); reasoner = reasonerFactory.createReasoner(ontology); // IMPORTANT: Precompute the inferences beforehand, otherwise no results // will be returned reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY); // Ontologies are not easy to query with the full name of concept, so we // keep only the interesting bit ( = shortform) shortFormProvider = new SimpleShortFormProvider(); Set<OWLOntology> importsClosure = ontology.getImportsClosure(); mapper = new BidirectionalShortFormProviderAdapter(manager, importsClosure, shortFormProvider); }
Example 2
Source File: BasicAnnotationPropagator.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
private boolean init() { LOG.info("Start preparing propagation rules"); OWLGraphWrapper graph = getGraph(); ElkReasonerFactory factory = new ElkReasonerFactory(); // assumes that all support ontologies have either been merged into or added as import reasoner = factory.createReasoner(graph.getSourceOntology()); if (reasoner.isConsistent() == false) { LOG.error("The converted annotations and ontology have produced an inconsistent model."); if (throwExceptions) { throw new RuntimeException("The converted annotations and ontology have produced an inconsistent model."); } return false; } propagationRules = createPropagationRules(graph, reasoner); aspectMap = createDefaultAspectMap(graph); LOG.info("Finished preparing propagation rules"); return true; }
Example 3
Source File: MockGafSolrDocumentLoaderTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void test() throws Exception { GafObjectsBuilder b = new GafObjectsBuilder(); final GafDocument gaf = b.buildDocument("src/test/resources/not_bioentity_closure/mini-test.gaf"); ParserWrapper pw = new ParserWrapper(); OWLOntology testOwl = pw.parse(new File("src/test/resources/not_bioentity_closure/mini-test.obo").getCanonicalPath()); final OWLGraphWrapper g = new OWLGraphWrapper(testOwl); OWLOntology slimOWL = pw.parse(TaxonTools.TAXON_PURL); ElkReasonerFactory rf = new ElkReasonerFactory(); MockGafSolrDocumentLoader l = new MockGafSolrDocumentLoader(); OWLReasoner r = null; try { r = rf.createReasoner(slimOWL); l.setGafDocument(gaf); l.setGraph(g); l.setEcoTools(new EcoTools(pw)); l.setTaxonTools(new TaxonTools(r, true)); l.load(); } finally { if (r != null) { r.dispose(); } } List<Map<String, Object>> docs = l.getDocumentCollection().getDocuments(); assertFalse(docs.size() == 0); Gson gson = new GsonBuilder().setPrettyPrinting().create(); for (Map<String, Object> doc : docs) { String json = gson.toJson(doc); System.out.println(json); } }
Example 4
Source File: GafSolrDocumentLoaderIntegrationRunner.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
@BeforeClass public static void setUpBeforeClass() throws Exception { // check runtime for parameters Properties properties = System.getProperties(); gafLocation = properties.getProperty(GafSolrDocumentLoaderIntegrationRunner.class.getSimpleName()+".gaf-folder"); catalogXmlFile = properties.getProperty(GafSolrDocumentLoaderIntegrationRunner.class.getSimpleName()+".catalog-xml"); assertNotNull("Did not find a catalog-xml file.", catalogXmlFile); assertNotNull("Did not find a gaf-folder file.", gafLocation); // setup solr loader loader = new GafSolrDocumentLoader(null, 1000) { @Override protected void addToServer(Collection<SolrInputDocument> docs) throws SolrServerException, IOException { solrCount += docs.size(); GafSolrDocumentLoaderIntegrationRunner.printMemoryStats(); System.out.println("Cache size: "+graph.getCurrentEdgesAdvancedCacheSize()); } }; ParserWrapper pw = new ParserWrapper(); pw.addIRIMapper(new CatalogXmlIRIMapper(catalogXmlFile)); // ontology graph = new OWLGraphWrapper(pw.parse("http://purl.obolibrary.org/obo/go/extensions/go-plus.owl")); graph.mergeOntology(pw.parse("http://purl.obolibrary.org/obo/go/extensions/gorel.owl")); loader.setGraph(graph); // eco EcoTools ecoTools = new EcoTools(pw); loader.setEcoTools(ecoTools); // taxon information OWLOntology taxonOwl = pw.parseOWL(TaxonTools.TAXON_PURL); ElkReasonerFactory factory = new ElkReasonerFactory(); OWLReasoner taxonReasoner = factory.createReasoner(taxonOwl); taxonTools = new TaxonTools(taxonReasoner, true); loader.setTaxonTools(taxonTools); }
Example 5
Source File: GafSolrDocumentLoaderTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
@BeforeClass public static void setUpBeforeClass() throws Exception { loader = new GafSolrDocumentLoader(null, 1000) { @Override protected void addToServer(Collection<SolrInputDocument> docs) throws SolrServerException, IOException { solrCount += docs.size(); } }; ParserWrapper pw = new ParserWrapper(); pw.addIRIMapper(new CatalogXmlIRIMapper("../OWLTools-Annotation/src/test/resources/rules/ontology/extensions/catalog-v001.xml")); // ontology graph = new OWLGraphWrapper(pw.parse("http://purl.obolibrary.org/obo/go.owl")); graph.mergeOntology(pw.parse("http://purl.obolibrary.org/obo/go/extensions/gorel.owl")); graph.mergeOntology(pw.parse(EcoTools.ECO_PURL)); OWLOntology taxonOwl = pw.parseOWL(TaxonTools.TAXON_PURL); graph.mergeOntology(taxonOwl); loader.setGraph(graph); loader.setEcoSubsetName("go_groupings"); // eco EcoTools ecoTools = new EcoTools(pw); loader.setEcoTools(ecoTools); // taxon information ElkReasonerFactory factory = new ElkReasonerFactory(); OWLReasoner taxonReasoner = factory.createReasoner(taxonOwl); taxonTools = new TaxonTools(taxonReasoner, true); loader.setTaxonTools(taxonTools); }
Example 6
Source File: GOReciprocalAnnotationRule.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
public GOReciprocalAnnotationRule(OWLGraphWrapper graph, TraversingEcoMapper eco) { this.graph = graph; evidences = eco.getAllValidEvidenceIds("IPI", true); OWLClass proteinBindingCls = graph.getOWLClassByIdentifier(PROTEIN_BINDING_GO_ID); if (proteinBindingCls == null) { throw new RuntimeException("No class found for identifier: "+PROTEIN_BINDING_GO_ID); } ElkReasonerFactory factory = new ElkReasonerFactory(); OWLReasoner reasoner = null; try { reasoner = factory.createReasoner(graph.getSourceOntology()); proteinBindingClasses = new HashSet<OWLClass>(); proteinBindingClasses.add(proteinBindingCls); Set<OWLClass> subClasses = reasoner.getSubClasses(proteinBindingCls, false).getFlattened(); for (OWLClass cls : subClasses) { if (!cls.isBottomEntity() && !cls.isTopEntity()) { proteinBindingClasses.add(cls); } } } finally { if (reasoner != null) { reasoner.dispose(); } } }
Example 7
Source File: GoMultipleTaxonRule.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
public GoMultipleTaxonRule(OWLGraphWrapper graph) { this.graph = graph; multiOrganismClasses = new HashSet<OWLClass>(); OWLClass mop = graph.getOWLClassByIdentifier(GO_ID_MULTI_ORGANISM_PROCESS); if (mop == null) { throw new RuntimeException("Could not find class for 'multi-organism process' id: "+GO_ID_MULTI_ORGANISM_PROCESS); } multiOrganismClasses.add(mop); ElkReasonerFactory factory = new ElkReasonerFactory(); OWLReasoner reasoner = null; try { reasoner = factory.createReasoner(graph.getSourceOntology()); Set<OWLClass> subClasses = reasoner.getSubClasses(mop, false).getFlattened(); for (OWLClass owlClass : subClasses) { if (owlClass.isBottomEntity() || owlClass.isTopEntity()) { continue; } multiOrganismClasses.add(owlClass); } } finally { if (reasoner != null) { reasoner.dispose(); } } }
Example 8
Source File: BasicAnnotationPropagatorTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void test1() throws Exception { ParserWrapper pw = new ParserWrapper(); OWLGraphWrapper g = pw.parseToOWLGraph(getResourceIRIString("rules/ontology/annotation-propagation-module.obo")); ElkReasonerFactory f = new ElkReasonerFactory(); OWLReasoner reasoner = f.createReasoner(g.getSourceOntology()); assertMapping("GO:0035556", "occurs_in", g, reasoner, 'F', "GO:0005622"); assertMapping("GO:0009881", "part_of", g, reasoner, 'P', "GO:0007165"); Set<OWLClass> closure = BasicAnnotationPropagator.getIsaPartofSuperClassClosure(Collections.singleton(g.getOWLClassByIdentifier("GO:0006415")), g, reasoner); assertTrue(closure.contains(g.getOWLClassByIdentifier("GO:0006412"))); }
Example 9
Source File: SimSpeedTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void load(String idspace) throws OWLOntologyCreationException, OBOFormatParserException, IOException { msg("Loading"); ParserWrapper pw = new ParserWrapper(); ontology = pw.parseOBO("/Users/cjm/repos/phenotype-ontologies/src/ontology/"+idspace+".obo"); reasonerFactory = new ElkReasonerFactory(); reasoner = reasonerFactory.createReasoner(ontology); msg("Loaded. Root = " + reasoner.getRootOntology()); }
Example 10
Source File: EquivalenceSetMergeUtilTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testMerge() throws OWLOntologyCreationException, IOException, IncoherentOntologyException, OWLOntologyStorageException { ParserWrapper pw = new ParserWrapper(); OWLGraphWrapper g = pw.parseToOWLGraph(getResourceIRIString("equivalence-set-merge-util-test.obo")); OWLOntology ont1 = g.getSourceOntology(); ElkReasonerFactory rf = new ElkReasonerFactory(); OWLReasoner reasoner = rf.createReasoner(ont1); EquivalenceSetMergeUtil esmu = new EquivalenceSetMergeUtil(g, reasoner); esmu.setPrefixScore("A", 8.0); esmu.setPrefixScore("B", 6.0); esmu.setPrefixScore("C", 4.0); OWLAnnotationProperty lp = g.getDataFactory().getOWLAnnotationProperty( OWLRDFVocabulary.RDFS_LABEL.getIRI() ); esmu.setPropertyPrefixScore( lp, "C", 5.0); esmu.setPropertyPrefixScore( lp, "B", 4.0); esmu.setPropertyPrefixScore( lp, "A", 3.0); OWLAnnotationProperty dp = g.getDataFactory().getOWLAnnotationProperty( Obo2OWLVocabulary.IRI_IAO_0000115.getIRI() ); esmu.setPropertyPrefixScore( dp, "B", 5.0); esmu.setPropertyPrefixScore( dp, "A", 4.0); esmu.setPropertyPrefixScore( dp, "C", 3.0); esmu.setRemoveAxiomatizedXRefs(true); esmu.merge(); OWLDocumentFormat fmt = new OBODocumentFormat(); pw.saveOWL(g.getSourceOntology(), "target/esmu.owl"); //pw.setCheckOboDoc(false); pw.saveOWL(g.getSourceOntology(), fmt, "target/esmu.obo"); OWLOntology ont2 = pw.parseOWL(getResourceIRIString("equivalence-set-merge-util-expected.obo")); assertEquals(0, compare(ont1, ont2)); }
Example 11
Source File: GCIUtilTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testOrganismPair() throws Exception{ g = getOntologyWrapper("limb_gci.owl"); ElkReasonerFactory rf = new ElkReasonerFactory(); OWLReasoner r = rf.createReasoner(g.getSourceOntology()); try { Set<OWLSubClassOfAxiom> axioms = GCIUtil.getSubClassOfSomeValuesFromAxioms(r); int n = 0; for (OWLSubClassOfAxiom axiom : axioms) { String c = ((OWLClass) axiom.getSubClass()).getIRI().toString(); OWLObjectSomeValuesFrom svf = (OWLObjectSomeValuesFrom) axiom.getSuperClass(); String rel = ((OWLObjectProperty) svf.getProperty()).getIRI().toString(); String p = ((OWLClass) svf.getFiller()).getIRI().toString(); String axstr = c + " " + rel + " " + p; System.out.println(axstr); if ("http://x.org/phalanx-development http://x.org/part-of http://x.org/digit-development".equals(axstr)) { n |= 1; } if ("http://x.org/digit-development http://x.org/part-of http://x.org/autopod-development".equals(axstr)) { n |= 2; } if ("http://x.org/limb-development http://x.org/part-of http://x.org/organism-development".equals(axstr)) { n |= 4; } if ("http://x.org/autopod-development http://x.org/part-of http://x.org/limb-development".equals(axstr)) { n |= 8; } } assertEquals(4, axioms.size()); assertEquals(15, n); } finally { r.dispose(); } }