org.semanticweb.elk.owlapi.ElkReasonerFactory Java Examples
The following examples show how to use
org.semanticweb.elk.owlapi.ElkReasonerFactory.
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: ProvenanceReasonerWrapperTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testReason() throws Exception { ParserWrapper pw = new ParserWrapper(); pw.getManager().getIRIMappers().add(new CatalogXmlIRIMapper(getResource("mooncat/eq-lattice/catalog-v001.xml"))); OWLOntology o = pw.parseOWL(getResourceIRIString("mooncat/eq-lattice/eq-with-imports.owl")); ProvenanceReasonerWrapper pr = new ProvenanceReasonerWrapper(o, new ElkReasonerFactory()); pr.reason(); // OWLEdge [c=<http://example.org/test/BCell-size>, p=<http://example.org/test/ImmuneCell-size>] REQUIRES: [http://example.org/test/auto, http://example.org/test/entity.owl] // OWLEdge [c=<http://example.org/test/Bone-size>, p=<http://example.org/test/Bone-morphology>] REQUIRES: [http://example.org/test/auto, http://example.org/test/quality.owl] assertEquals(143, pr.edges.size()); o.getOWLOntologyManager().saveOntology(o, new FileOutputStream("target/eq-inf.ttl")); }
Example #2
Source File: ReasonerFactory.java From BioSolr with Apache License 2.0 | 6 votes |
/** * Build and return a {@code OWLReasoner} instance for a particular ontology, * as configured. * @param config the configuration for the ontology. * @param ontology the ontology. * @return the configured {@code OWLReasoner} instance, or the HermiT Reasoner * if the configuration value is not recognised. */ public OWLReasoner buildReasoner(OntologyConfiguration config, OWLOntology ontology) { String cfgReasoner = config.getReasoner(); OWLReasoner reasoner; if (HERMIT_REASONER.equalsIgnoreCase(cfgReasoner)) { reasoner = new Reasoner(ontology); } else if (ELK_REASONER.equalsIgnoreCase(cfgReasoner)) { reasoner = new ElkReasonerFactory().createReasoner(ontology); } else { LOGGER.info("Reasoner {} not recognized - using HermiT", cfgReasoner); reasoner = new Reasoner(ontology); } return reasoner; }
Example #3
Source File: ReasonOperationTest.java From robot with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Test reasoning with external ontologies. * * <p>Depending on user option, inferred axioms that refer solely to external ontology classes * (i.e. those in the import chain) should not be asserted * * @throws Exception on any problem */ @Test public void testExternal() throws Exception { OWLOntology importOnt1 = loadOntology("/intersection.omn"); IRI oiri = importOnt1.getOntologyID().getOntologyIRI().orNull(); if (oiri == null) { throw new Exception("Ontology 'intersection.omn' does not have an IRI"); } OWLOntology mainOnt = loadOntology("/simple.owl"); OWLOntologyManager mgr = mainOnt.getOWLOntologyManager(); OWLOntology importOnt = mgr.createOntology(oiri); mgr.addAxioms(importOnt, importOnt1.getAxioms()); OWLImportsDeclaration importsDecl = mgr.getOWLDataFactory().getOWLImportsDeclaration(oiri); AddImport ch = new AddImport(mainOnt, importsDecl); mgr.applyChange(ch); OWLReasonerFactory reasonerFactory = new ElkReasonerFactory(); Map<String, String> opts = new HashMap<>(); opts.put("exclude-external-entities", "true"); ReasonOperation.reason(mainOnt, reasonerFactory, opts); assertFalse(checkContains(mainOnt, "SubClassOf(<http://x.org/XA> <http://x.org/XB>)")); opts.put("exclude-external-entities", "false"); ReasonOperation.reason(mainOnt, reasonerFactory, opts); assertTrue(checkContains(mainOnt, "SubClassOf(<http://x.org/XA> <http://x.org/XB>)")); }
Example #4
Source File: ExtendedReasonerTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testQuery() throws Exception{ g = getOntologyWrapper("extended-reasoner-test.omn"); parser = new ManchesterSyntaxTool(g.getSourceOntology(), g.getSupportOntologySet()); reasoner = new ExpressionMaterializingReasoner(g.getSourceOntology(), new ElkReasonerFactory(), BufferingMode.NON_BUFFERING); reasoner.flush(); IRI piri; piri = IRI.create("http://x.org/part_of"); OWLObjectProperty p = g.getDataFactory().getOWLObjectProperty(piri); findAncestors("digit", p, true, 1); findAncestors("digit", p, false, 2); findAncestors("toe", p, true, 1); findAncestors("toe", p, false, 4); findAncestors("phalanx", p, true, 1); findAncestors("phalanx", p, false, 4); findAncestors("mouse_phalanx", p, true, 2); findAncestors("brachialis", p, true, 1); }
Example #5
Source File: MockFlexSolrDocumentLoaderTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
public List<Map<String, Object>> mockLoad(String path) throws Exception { aconf = new ConfigManager(); aconf.add("src/test/resources/test-ont-config.yaml"); ParserWrapper pw = new ParserWrapper(); OWLOntology testOwl = pw.parse(new File(path).getCanonicalPath()); final OWLGraphWrapper g = new OWLGraphWrapper(testOwl); FlexCollection flex = new FlexCollection(aconf, g); ElkReasonerFactory rf = new ElkReasonerFactory(); MockFlexSolrDocumentLoader l = new MockFlexSolrDocumentLoader(flex); l.load(); List<Map<String, Object>> docs = l.getDocumentCollection().getDocuments(); Gson gson = new GsonBuilder().setPrettyPrinting().create(); for (Map<String, Object> doc : docs) { String json = gson.toJson(doc); System.out.println(json); } return docs; }
Example #6
Source File: MaterializeOperationTest.java From robot with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Test reasoning with imports. * * <p>For motivation, see https://github.com/ontodev/robot/issues/119 * * @throws IOException on file problem * @throws OWLOntologyCreationException on ontology problem * @throws URISyntaxException if URI incorrectly formatted * @throws OntologyLogicException on logic problem */ @Test public void testMaterializeWithImports() throws IOException, OWLOntologyCreationException, OntologyLogicException, URISyntaxException { // TODO: minor, simplify this once // https://github.com/ontodev/robot/issues/121 implemeted File f = new File(getClass().getResource("/import-non-reasoned.owl").toURI()); IOHelper ioh = new IOHelper(); OWLOntology reasoned = ioh.loadOntology(f, true); OWLOntology original = ioh.loadOntology(f, true); OWLReasonerFactory coreReasonerFactory = new ElkReasonerFactory(); Map<String, String> opts = ReasonOperation.getDefaultOptions(); MaterializeOperation.materialize(reasoned, coreReasonerFactory, null, opts); assertIdentical(original, reasoned); }
Example #7
Source File: OwlTestCase.java From SciGraph with Apache License 2.0 | 6 votes |
@Before public void loadOwl() throws Exception { OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); String uri = Resources.getResource("ontologies/cases/" + getTestName() + ".owl").toURI() .toString(); IRI iri = IRI.create(uri); OWLOntology ont = manager.loadOntologyFromOntologyDocument(iri); if (performInference) { ReasonerConfiguration config = new ReasonerConfiguration(); config.setFactory(ElkReasonerFactory.class.getCanonicalName()); config.setAddDirectInferredEdges(true); ReasonerUtil util = new ReasonerUtil(config, manager, ont); util.reason(); } OWLOntologyWalker walker = new OWLOntologyWalker(manager.getOntologies()); GraphOwlVisitor visitor = new GraphOwlVisitor(walker, graph, new ArrayList<MappedProperty>()); walker.walkStructure(visitor); OwlPostprocessor postprocessor = new OwlPostprocessor(graphDb, Collections.<String, String>emptyMap()); postprocessor.processSomeValuesFrom(); drawGraph(); }
Example #8
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 #9
Source File: CommandLineHelper.java From robot with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Given a string of a reasoner name from user input, return the reasoner factory. If the user * input is not valid, throw IllegalArgumentExcepiton. * * @param line the command line to use * @param allowEMR boolean specifying if EMR can be returned * @return OWLReasonerFactory if successful */ public static OWLReasonerFactory getReasonerFactory(CommandLine line, boolean allowEMR) { // ELK is the default reasoner String reasonerName = getDefaultValue(line, "reasoner", "ELK").trim().toLowerCase(); logger.info("Reasoner: " + reasonerName); if (reasonerName.equals("structural")) { return new org.semanticweb.owlapi.reasoner.structural.StructuralReasonerFactory(); } else if (reasonerName.equals("hermit")) { return new org.semanticweb.HermiT.ReasonerFactory(); } else if (reasonerName.equals("jfact")) { return new JFactFactory(); // Reason must change behavior with EMR, so not all commands can use it } else if (reasonerName.equals("emr") && allowEMR) { ElkReasonerFactory innerReasonerFactory = new org.semanticweb.elk.owlapi.ElkReasonerFactory(); return new ExpressionMaterializingReasonerFactory(innerReasonerFactory); } else if (reasonerName.equals("elk")) { return new org.semanticweb.elk.owlapi.ElkReasonerFactory(); } else { throw new IllegalArgumentException(String.format(invalidReasonerError, reasonerName)); } }
Example #10
Source File: TraversingEcoMapperTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
@BeforeClass public static void beforeClass() throws Exception { // Setup environment. ParserWrapper pw = new ParserWrapper(); //NOTE: Yes, the GO here is unnecessary, but we're trying to also catch a certain behavior // where auxilery ontologies are not caught. The best wat to do that here is to load ECO // second and then do the merge. OWLOntology ont_main = pw.parse(getResourceIRIString("go_xp_predictor_test_subset.obo")); OWLOntology ont_scnd = pw.parse(getResourceIRIString("eco.obo")); g = new OWLGraphWrapper(ont_main); g.addSupportOntology(ont_scnd); // NOTE: This step is necessary or things will get ignored! // (This cropped-up in the loader at one point.) for (OWLOntology ont : g.getSupportOntologySet()) g.mergeOntology(ont); OWLReasonerFactory reasonerFactory = new ElkReasonerFactory(); r = reasonerFactory.createReasoner(g.getSourceOntology()); g.setReasoner(r); }
Example #11
Source File: TaxonToolsTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
@BeforeClass public static void beforeClass() throws Exception { // Setup environment. ParserWrapper pw = new ParserWrapper(); //NOTE: Yes, the GO here is unnecessary, but we're trying to also catch a certain behavior // where auxiliary ontologies are not caught. The best way to do that here is to load taxslim // second and then do the merge. OWLOntology ont_main = pw.parse(getResourceIRIString("go_xp_predictor_test_subset.obo")); OWLOntology ont_scnd = pw.parse(getResourceIRIString("taxslim.obo")); g = new OWLGraphWrapper(ont_main); g.addSupportOntology(ont_scnd); // NOTE: This step is necessary or things will get ignored! // (This cropped-up in the loader at one point.) for (OWLOntology ont : g.getSupportOntologySet()) g.mergeOntology(ont); OWLReasonerFactory reasonerFactory = new ElkReasonerFactory(); r = reasonerFactory.createReasoner(g.getSourceOntology()); g.setReasoner(r); }
Example #12
Source File: EcoToolsTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
@BeforeClass public static void beforeClass() throws Exception { // Setup environment. ParserWrapper pw = new ParserWrapper(); //NOTE: Yes, the GO here is unnecessary, but we're trying to also catch a certain behavior // where auxilery ontologies are not caught. The best wat to do that here is to load ECO // second and then do the merge. OWLOntology ont_main = pw.parse(getResourceIRIString("go_xp_predictor_test_subset.obo")); OWLOntology ont_scnd = pw.parse(getResourceIRIString("eco.obo")); g = new OWLGraphWrapper(ont_main); g.addSupportOntology(ont_scnd); // NOTE: This step is necessary or things will get ignored! // (This cropped-up in the loader at one point.) for (OWLOntology ont : g.getSupportOntologySet()) g.mergeOntology(ont); OWLReasonerFactory reasonerFactory = new ElkReasonerFactory(); r = reasonerFactory.createReasoner(g.getSourceOntology()); g.setReasoner(r); }
Example #13
Source File: SpeciesMergeUtilTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testMergeSpecies() throws Exception { ParserWrapper p = new ParserWrapper(); OWLOntology owlOntology = p.parse(getResourceIRIString("speciesMergeTest.obo")); OWLGraphWrapper graph = new OWLGraphWrapper(owlOntology); OWLReasonerFactory rf = new ElkReasonerFactory(); OWLReasoner reasoner = rf.createReasoner(graph.getSourceOntology()); SpeciesMergeUtil smu = new SpeciesMergeUtil(graph); smu.viewProperty = graph.getOWLObjectPropertyByIdentifier("BFO:0000050"); smu.taxClass = graph.getOWLClassByIdentifier("T:1"); smu.reasoner = reasoner; smu.suffix = "coelocanth"; smu.merge(); p.saveOWL(smu.ont, new OBODocumentFormat(), "target/speciesMergeOut.obo"); }
Example #14
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 #15
Source File: RedundantInferencesTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
@BeforeClass public static void setUpBeforeClass() throws Exception { ParserWrapper pw = new ParserWrapper(); graph = pw.parseToOWLGraph(getResourceIRIString("remove-redundant-inferences.obo")); OWLReasonerFactory reasonerFactory = new ElkReasonerFactory(); reasoner = reasonerFactory.createReasoner(graph.getSourceOntology()); }
Example #16
Source File: InferenceBuilder.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static OWLReasonerFactory getFactory(String reasonerName) { if (REASONER_HERMIT.equals(reasonerName)) { return new org.semanticweb.HermiT.ReasonerFactory(); } else if (REASONER_ELK.equals(reasonerName)) { return new ElkReasonerFactory(); } throw new IllegalArgumentException("Unknown reasoner: "+reasonerName); }
Example #17
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 #18
Source File: OwlSimVarianceTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testPValue() throws Exception { ParserWrapper pw = new ParserWrapper(); sourceOntol = pw.parseOBO(getResource("sim/mp-subset-1.obo").getAbsolutePath()); g = new OWLGraphWrapper(sourceOntol); parseAssociations(getResource("sim/mgi-gene2mp-subset-1.tbl"), g); LOG.info("Initialize OwlSim .."); OWLReasoner reasoner = new ElkReasonerFactory().createReasoner(sourceOntol); reasoner.flush(); try { owlsim = owlSimFactory.createOwlSim(sourceOntol); owlsim.createElementAttributeMapFromOntology(); owlsim.computeSystemStats(); } catch (UnknownOWLClassException e) { e.printStackTrace(); } finally { reasoner.dispose(); } // Source sourceOntol and g are used as background knowledge ... OWLSimReferenceBasedStatistics refBasedStats = new OWLSimReferenceBasedStatistics(owlsim, sourceOntol, g); IRI iri = IRI.create("http://purl.obolibrary.org/obo/MGI_101761"); String[] testClasses = new String[] {"MP:0002758", "MP:0002772", "MP:0005448", "MP:0003660"}; Set<OWLClass> testClassesSet = new HashSet<OWLClass>(); for (String testClass : testClasses) { testClassesSet.add(this.getOBOClass(testClass)); } PValue pValue = refBasedStats.getPValue(testClassesSet, iri); LOG.info(pValue.getSimplePValue()); }
Example #19
Source File: OWLGraphWrapperEdgesAdvanced.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
private synchronized ExpressionMaterializingReasoner getMaterializingReasoner() { if (reasoner == null) { reasoner = new ExpressionMaterializingReasoner(getSourceOntology(), new ElkReasonerFactory()); reasoner.materializeExpressions(materializationPropertySet); isSynchronized = true; } else if (isSynchronized == false) { reasoner.materializeExpressions(materializationPropertySet); isSynchronized = true; } return reasoner; }
Example #20
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 #21
Source File: SpeciesMergeUtilTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testMergeFly() throws Exception { ParserWrapper p = new ParserWrapper(); OWLOntology owlOntology = p.parse(getResourceIRIString("interneuron-fly.obo")); Set<OWLClass> clsBefore = owlOntology.getClassesInSignature(); OWLGraphWrapper graph = new OWLGraphWrapper(owlOntology); OWLReasonerFactory rf = new ElkReasonerFactory(); OWLReasoner reasoner = rf.createReasoner(graph.getSourceOntology()); SpeciesMergeUtil smu = new SpeciesMergeUtil(graph); smu.viewProperty = graph.getOWLObjectPropertyByIdentifier("BFO:0000050"); smu.taxClass = graph.getOWLClassByIdentifier("NCBITaxon:7227"); smu.reasoner = reasoner; smu.suffix = "fly"; smu.includedProperties = Collections.singleton(smu.viewProperty); //smu.includedProperties = Collections.singleton(graph.getOWLObjectPropertyByIdentifier("BFO:0000051")); smu.merge(); Set<OWLClass> clsAfter = smu.ont.getClassesInSignature(); LOG.info("Before: "+clsBefore.size()); LOG.info("After: "+clsAfter.size()); assertEquals(100, clsBefore.size()); assertEquals(90, clsAfter.size()); p.saveOWL(smu.ont, new OBODocumentFormat(), "target/flyMergeOut.obo"); }
Example #22
Source File: SimStatsTests.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testStats() throws IOException, OWLOntologyCreationException, MathException, UnknownOWLClassException, OBOFormatParserException { ParserWrapper pw = new ParserWrapper(); sourceOntol = pw.parseOBO(getResource("sim/mp-subset-1.obo").getAbsolutePath()); g = new OWLGraphWrapper(sourceOntol); parseAssociations(getResource("sim/mgi-gene2mp-subset-1.tbl"), g); setOutput("target/basic-owlsim-test.out"); // assume buffering OWLReasoner reasoner = new ElkReasonerFactory().createReasoner(sourceOntol); try { this.createOwlSim(); owlsim.createElementAttributeMapFromOntology(); reasoner.flush(); owlsim.computeSystemStats(); LOG.info("Overall statistical summary for Test:"); LOG.info(owlsim.getSystemStats().toString()); LOG.info("Averaged statistical summary for Individuals in Test:"); // LOG.info(owlsim.getSummaryStatistics(Stat.MEAN).toString()); LOG.info("individuals: "+owlsim.getSummaryStatistics().n.getN()); LOG.info("mean(n/indiv): "+String.format("%1$.5f", owlsim.getSummaryStatistics().n.getMean())); LOG.info("mean(meanIC): "+String.format("%1$.5f", owlsim.getSummaryStatistics().mean.getMean())); LOG.info("mean(maxIC): "+String.format("%1$.5f", owlsim.getSummaryStatistics().max.getMean())); LOG.info("max(maxIC): "+String.format("%1$.5f", owlsim.getSummaryStatistics().max.getMax())); LOG.info("mean(sumIC): "+String.format("%1$.5f", owlsim.getSummaryStatistics().max.getMean())); } finally { reasoner.dispose(); } }
Example #23
Source File: OWLSimTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void setup() throws UnknownOWLClassException { reasoner = new ElkReasonerFactory().createReasoner(sourceOntol); this.createOwlSim(); owlsim.createElementAttributeMapFromOntology(); Properties p = new Properties(); p.setProperty(SimConfigurationProperty.minimumMaxIC.toString(), "0.01"); p.setProperty(SimConfigurationProperty.minimumSimJ.toString(), "0.01"); owlsim.setSimProperties(p); reasoner.flush(); }
Example #24
Source File: BasicOWLSimTestUsingSOS.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testBasicSim() throws IOException, OWLOntologyCreationException, OWLOntologyStorageException, MathException, UnknownOWLClassException { ParserWrapper pw = new ParserWrapper(); sourceOntol = pw.parseOWL(getResourceIRIString("sim/mp-subset-1.obo")); g = new OWLGraphWrapper(sourceOntol); parseAssociations(getResource("sim/mgi-gene2mp-subset-1.tbl"), g); owlpp = new OWLPrettyPrinter(g); // assume buffering OWLReasoner reasoner = new ElkReasonerFactory().createReasoner(sourceOntol); try { owlsim = new SimpleOwlSim(sourceOntol); ((SimpleOwlSim) owlsim).setReasoner(reasoner); LOG.info("Reasoner="+owlsim.getReasoner()); //sos.saveOntology("/tmp/z.owl"); reasoner.flush(); for (OWLNamedIndividual i : sourceOntol.getIndividualsInSignature()) { //System.out.println("COMPARING: "+i); for (OWLNamedIndividual j : sourceOntol.getIndividualsInSignature()) { showSimOld(i,j); } } } finally { reasoner.dispose(); } }
Example #25
Source File: PhenoSimHQETest.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testPhenoSimMouse() throws IOException, OWLOntologyCreationException, OWLOntologyStorageException, MathException { ParserWrapper pw = new ParserWrapper(); sourceOntol = pw.parseOWL(getResourceIRIString("test_phenotype.owl")); g = new OWLGraphWrapper(sourceOntol); owlpp = new OWLPrettyPrinter(g); // assume buffering OWLReasoner reasoner = new ElkReasonerFactory().createReasoner(sourceOntol); try { pproc = new PhenoSimHQEPreProcessor(); pproc.setInputOntology(sourceOntol); pproc.setOutputOntology(sourceOntol); pproc.setReasoner(reasoner); pproc.setOWLPrettyPrinter(owlpp); ((PhenoSimHQEPreProcessor)pproc).defaultLCSElementFrequencyThreshold = 0.7; //sos.setSimPreProcessor(pproc); //sos.preprocess(); pproc.preprocess(); reasoner.flush(); sos = new SimpleOwlSim(sourceOntol); sos.setSimPreProcessor(pproc); sos.createElementAttributeMapFromOntology(); //sos.saveOntology("/tmp/z.owl"); reasoner.flush(); for (OWLNamedIndividual i : sourceOntol.getIndividualsInSignature()) { for (OWLNamedIndividual j : sourceOntol.getIndividualsInSignature()) { showSim(i,j); } } } finally { reasoner.dispose(); } }
Example #26
Source File: PhenoSimHQETest.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testPhenoSim() throws IOException, OWLOntologyCreationException, OWLOntologyStorageException, MathException { ParserWrapper pw = new ParserWrapper(); sourceOntol = pw.parseOWL(getResourceIRIString("q-in-e.omn")); g = new OWLGraphWrapper(sourceOntol); owlpp = new OWLPrettyPrinter(g); // assume buffering OWLReasoner reasoner = new ElkReasonerFactory().createReasoner(sourceOntol); try { pproc = new PhenoSimHQEPreProcessor(); pproc.setInputOntology(sourceOntol); pproc.setOutputOntology(sourceOntol); pproc.setReasoner(reasoner); pproc.setOWLPrettyPrinter(owlpp); ((PhenoSimHQEPreProcessor)pproc).defaultLCSElementFrequencyThreshold = 0.7; //sos.setSimPreProcessor(pproc); //sos.preprocess(); pproc.preprocess(); reasoner.flush(); sos = new SimpleOwlSim(sourceOntol); sos.setSimPreProcessor(pproc); sos.createElementAttributeMapFromOntology(); //sos.saveOntology("/tmp/z.owl"); reasoner.flush(); for (OWLNamedIndividual i : sourceOntol.getIndividualsInSignature()) { for (OWLNamedIndividual j : sourceOntol.getIndividualsInSignature()) { showSim(i,j); } } } finally { reasoner.dispose(); } }
Example #27
Source File: CoannotatedTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Test fetching commonly co-annotated classes in the entire corpus, which * uses the TF-IDF method. * @throws Exception */ @Test public void testGetCoannotatedClassesForAttribute() throws Exception { ParserWrapper pw = new ParserWrapper(); sourceOntol = pw.parseOWL(getResourceIRIString("sim/mp-subset-1.obo")); g = new OWLGraphWrapper(sourceOntol); parseAssociations(getResource("sim/mgi-gene2mp-subset-1.tbl"), g); owlpp = new OWLPrettyPrinter(g); // assume buffering OWLReasoner reasoner = new ElkReasonerFactory().createReasoner(sourceOntol); try { this.createOwlSim(); owlsim.createElementAttributeMapFromOntology(); reasoner.flush(); owlsim.populateFullCoannotationMatrix(); Set<OWLNamedIndividual> inds = sourceOntol.getIndividualsInSignature(); Set<OWLClass> cs = owlsim.getAllAttributeClasses(); LOG.info("Dumping coannotations and scores for all annotated classes"); for (OWLClass c : cs) { List<ClassCount> lcc = owlsim.getCoannotatedClassesForAttribute(c,inds.size()); for (ClassCount cc : lcc) { LOG.info(owlpp.render(c)+owlpp.render(cc.c)+cc.score); } } } finally { reasoner.dispose(); } }
Example #28
Source File: CoannotatedTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Test fetching commonly co-annotated classes in a set of individuals * vs the background (entire) corpus using the TF-IDF method. * @throws Exception * @throws MathException */ @Test public void coAnnotatedTest() throws Exception, MathException { ParserWrapper pw = new ParserWrapper(); sourceOntol = pw.parseOWL(getResourceIRIString("sim/mp-subset-1.obo")); g = new OWLGraphWrapper(sourceOntol); parseAssociations(getResource("sim/mgi-gene2mp-subset-1.tbl"), g); owlpp = new OWLPrettyPrinter(g); // assume buffering OWLReasoner reasoner = new ElkReasonerFactory().createReasoner(sourceOntol); try { this.createOwlSim(); owlsim.createElementAttributeMapFromOntology(); reasoner.flush(); owlsim.populateFullCoannotationMatrix(); Set<OWLNamedIndividual> inds = sourceOntol.getIndividualsInSignature(); for (OWLNamedIndividual i : inds) { //get a random set of other individuals to do the subset List<ClassCount> coaClasses = owlsim.getCoAnnotatedClassesForIndividual(i); LOG.info("Found "+coaClasses.size()+" coannotated classes for "+g.getIdentifier(i)); for (ClassCount cc : coaClasses) { LOG.info(owlpp.render(cc.c)+cc.score); } } } finally { reasoner.dispose(); } }
Example #29
Source File: OldSimpleOwlSim.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void init() { reasonerFactory = new ElkReasonerFactory(); elementToAttributesMap = new HashMap<OWLEntity,Set<OWLClass>>(); attributeToElementsMap = new HashMap<OWLClass,Set<OWLEntity>>(); expressionToClassMap = new HashMap<OWLClassExpression, OWLClass>(); viewClasses = new HashSet<OWLClass>(); sourceViewProperties = new ArrayList<OWLObjectProperty>(); simCache = new HashMap<OWLClassExpressionPair, ScoreAttributePair>(); lcsCache = new HashMap<OWLClassExpressionPair, OWLClass>(); }
Example #30
Source File: EcoTools.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Create a new instance using the ECO graph wrapper. * * @param eco */ public EcoTools(OWLGraphWrapper eco) { this.eco = eco; OWLReasonerFactory factory = new ElkReasonerFactory(); final OWLOntology sourceOntology = eco.getSourceOntology(); reasoner = factory.createReasoner(sourceOntology); disposeReasonerP = true; }