Search in sources :

Example 6 with WorkingMemory

use of org.geneontology.rules.engine.WorkingMemory in project minerva by geneontology.

the class GPADSPARQLTest method testSuppressUberonExtensionsWhenEMAPA.

/**
 * This test needs improvements; the current background axioms used in the tests are resulting in the Uberon inference we're trying to avoid
 *
 * @throws Exception
 */
@Test
public void testSuppressUberonExtensionsWhenEMAPA() throws Exception {
    Model model = ModelFactory.createDefaultModel();
    model.read(this.getClass().getResourceAsStream("/no_uberon_with_emapa.ttl"), "", "ttl");
    Set<Triple> triples = model.listStatements().toList().stream().map(s -> Bridge.tripleFromJena(s.asTriple())).collect(Collectors.toSet());
    WorkingMemory mem = arachne.processTriples(JavaConverters.asScalaSetConverter(triples).asScala());
    Set<GPADData> annotations = exporter.getGPAD(mem, IRI.create("http://test.org"));
    Assert.assertTrue(annotations.stream().anyMatch(a -> a.getAnnotationExtensions().stream().anyMatch(e -> e.getFiller().toString().startsWith("http://purl.obolibrary.org/obo/EMAPA_"))));
    Assert.assertTrue(annotations.stream().noneMatch(a -> a.getAnnotationExtensions().stream().anyMatch(e -> e.getFiller().toString().startsWith("http://purl.obolibrary.org/obo/UBERON_"))));
}
Also used : Triple(org.geneontology.rules.engine.Triple) java.util(java.util) BeforeClass(org.junit.BeforeClass) JenaSystem(org.apache.jena.system.JenaSystem) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLManager(org.semanticweb.owlapi.apibinding.OWLManager) Model(org.apache.jena.rdf.model.Model) WorkingMemory(org.geneontology.rules.engine.WorkingMemory) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) Pair(org.apache.commons.lang3.tuple.Pair) IRI(org.semanticweb.owlapi.model.IRI) Triple(org.geneontology.rules.engine.Triple) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) OWLtoRules(org.geneontology.jena.OWLtoRules) Imports(org.semanticweb.owlapi.model.parameters.Imports) RuleEngine(org.geneontology.rules.engine.RuleEngine) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) Collectors(java.util.stream.Collectors) File(java.io.File) Ignore(org.junit.Ignore) JavaConverters(scala.collection.JavaConverters) DefaultCurieHandler(org.geneontology.minerva.curie.DefaultCurieHandler) Bridge(org.geneontology.rules.util.Bridge) Rule(org.apache.jena.reasoner.rulesys.Rule) ModelFactory(org.apache.jena.rdf.model.ModelFactory) Assert(org.junit.Assert) WorkingMemory(org.geneontology.rules.engine.WorkingMemory) Model(org.apache.jena.rdf.model.Model) Test(org.junit.Test)

Example 7 with WorkingMemory

use of org.geneontology.rules.engine.WorkingMemory in project minerva by geneontology.

the class GPADSPARQLTest method testGPADContainsAcceptedAndCreatedDates.

@Test
@Ignore
public void testGPADContainsAcceptedAndCreatedDates() throws Exception {
    Model model = ModelFactory.createDefaultModel();
    model.read(this.getClass().getResourceAsStream("/created-date-test.ttl"), "", "ttl");
    Set<Triple> triples = model.listStatements().toList().stream().map(s -> Bridge.tripleFromJena(s.asTriple())).collect(Collectors.toSet());
    WorkingMemory mem = arachne.processTriples(JavaConverters.asScalaSetConverter(triples).asScala());
    Set<GPADData> annotations = exporter.getGPAD(mem, IRI.create("http://test.org"));
    IRI gene = IRI.create("http://identifiers.org/wormbase/WBGene00001326");
    Pair<String, String> creationDate = Pair.of("creation-date", "2021-05-13");
    Assert.assertTrue(annotations.stream().anyMatch(a -> a.getObject().equals(gene) && a.getAnnotations().contains(creationDate)));
}
Also used : Triple(org.geneontology.rules.engine.Triple) java.util(java.util) BeforeClass(org.junit.BeforeClass) JenaSystem(org.apache.jena.system.JenaSystem) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLManager(org.semanticweb.owlapi.apibinding.OWLManager) Model(org.apache.jena.rdf.model.Model) WorkingMemory(org.geneontology.rules.engine.WorkingMemory) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) Pair(org.apache.commons.lang3.tuple.Pair) IRI(org.semanticweb.owlapi.model.IRI) Triple(org.geneontology.rules.engine.Triple) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) OWLtoRules(org.geneontology.jena.OWLtoRules) Imports(org.semanticweb.owlapi.model.parameters.Imports) RuleEngine(org.geneontology.rules.engine.RuleEngine) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) Collectors(java.util.stream.Collectors) File(java.io.File) Ignore(org.junit.Ignore) JavaConverters(scala.collection.JavaConverters) DefaultCurieHandler(org.geneontology.minerva.curie.DefaultCurieHandler) Bridge(org.geneontology.rules.util.Bridge) Rule(org.apache.jena.reasoner.rulesys.Rule) ModelFactory(org.apache.jena.rdf.model.ModelFactory) Assert(org.junit.Assert) IRI(org.semanticweb.owlapi.model.IRI) WorkingMemory(org.geneontology.rules.engine.WorkingMemory) Model(org.apache.jena.rdf.model.Model) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with WorkingMemory

use of org.geneontology.rules.engine.WorkingMemory in project minerva by geneontology.

the class GPADSPARQLTest method testGPADOutput.

@Test
public void testGPADOutput() throws Exception {
    Model model = ModelFactory.createDefaultModel();
    model.read(this.getClass().getResourceAsStream("/581e072c00000473.ttl"), "", "ttl");
    Set<Triple> triples = model.listStatements().toList().stream().map(s -> Bridge.tripleFromJena(s.asTriple())).collect(Collectors.toSet());
    WorkingMemory mem = arachne.processTriples(JavaConverters.asScalaSetConverter(triples).asScala());
    String gpad = exporter.exportGPAD(mem, IRI.create("http://test.org"));
    int lines = gpad.split("\n", -1).length;
    // TODO test contents of annotations; dumb test for now
    Assert.assertTrue(gpad.contains("model-state=production"));
    Assert.assertTrue("Should produce annotations", lines > 2);
}
Also used : Triple(org.geneontology.rules.engine.Triple) java.util(java.util) BeforeClass(org.junit.BeforeClass) JenaSystem(org.apache.jena.system.JenaSystem) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLManager(org.semanticweb.owlapi.apibinding.OWLManager) Model(org.apache.jena.rdf.model.Model) WorkingMemory(org.geneontology.rules.engine.WorkingMemory) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) Pair(org.apache.commons.lang3.tuple.Pair) IRI(org.semanticweb.owlapi.model.IRI) Triple(org.geneontology.rules.engine.Triple) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) OWLtoRules(org.geneontology.jena.OWLtoRules) Imports(org.semanticweb.owlapi.model.parameters.Imports) RuleEngine(org.geneontology.rules.engine.RuleEngine) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) Collectors(java.util.stream.Collectors) File(java.io.File) Ignore(org.junit.Ignore) JavaConverters(scala.collection.JavaConverters) DefaultCurieHandler(org.geneontology.minerva.curie.DefaultCurieHandler) Bridge(org.geneontology.rules.util.Bridge) Rule(org.apache.jena.reasoner.rulesys.Rule) ModelFactory(org.apache.jena.rdf.model.ModelFactory) Assert(org.junit.Assert) WorkingMemory(org.geneontology.rules.engine.WorkingMemory) Model(org.apache.jena.rdf.model.Model) Test(org.junit.Test)

Example 9 with WorkingMemory

use of org.geneontology.rules.engine.WorkingMemory in project minerva by geneontology.

the class CoreMolecularModelManager method createCanonicalInferredModel.

public WorkingMemory createCanonicalInferredModel(IRI modelId) {
    // swap out any non-canonical types
    OWLOntology source_abox = getModelAbox(modelId);
    OWLOntologyManager aman = OWLManager.createOWLOntologyManager();
    OWLDataFactory df = aman.getOWLDataFactory();
    OWLAnnotationProperty canonical_record = df.getOWLAnnotationProperty(IRI.create("http://geneontology.org/lego/canonical_record"));
    OWLReasonerFactory reasonerFactory = new StructuralReasonerFactory();
    try {
        OWLOntology abox = aman.copyOntology(source_abox, OntologyCopy.DEEP);
        OWLReasoner abox_reasoner = reasonerFactory.createReasoner(abox);
        // convert to canonical wherever possible
        abox.getIndividualsInSignature().forEach(i -> {
            Set<OWLClass> types = abox_reasoner.getTypes(i, true).getFlattened();
            for (OWLClass type : types) {
                Collection<OWLAnnotation> canons = EntitySearcher.getAnnotationObjects(type, tbox, canonical_record);
                // more correct to create new instances for each
                if (canons != null && canons.size() > 0) {
                    for (OWLAnnotation canon : canons) {
                        if (canon.getValue().asIRI().isPresent()) {
                            OWLClass canonical = df.getOWLClass(canon.getValue().asIRI().get());
                            // direct swap
                            // remove the old one
                            OWLClassAssertionAxiom original = df.getOWLClassAssertionAxiom(type, i);
                            aman.removeAxiom(abox, original);
                            // add the new one
                            OWLClassAssertionAxiom canonical_type = df.getOWLClassAssertionAxiom(canonical, i);
                            aman.addAxiom(abox, canonical_type);
                        }
                    }
                }
            }
        });
        WorkingMemory inferred = createInferredModel(abox, modelId);
        abox_reasoner.dispose();
        aman.removeOntology(abox);
        return inferred;
    } catch (OWLOntologyCreationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return createInferredModel(source_abox, modelId);
    }
}
Also used : WorkingMemory(org.geneontology.rules.engine.WorkingMemory) OWLReasoner(org.semanticweb.owlapi.reasoner.OWLReasoner) StructuralReasonerFactory(org.semanticweb.owlapi.reasoner.structural.StructuralReasonerFactory) OWLReasonerFactory(org.semanticweb.owlapi.reasoner.OWLReasonerFactory)

Aggregations

WorkingMemory (org.geneontology.rules.engine.WorkingMemory)9 java.util (java.util)7 Collectors (java.util.stream.Collectors)7 Pair (org.apache.commons.lang3.tuple.Pair)7 Model (org.apache.jena.rdf.model.Model)7 ModelFactory (org.apache.jena.rdf.model.ModelFactory)7 Bridge (org.geneontology.rules.util.Bridge)7 IRI (org.semanticweb.owlapi.model.IRI)7 JavaConverters (scala.collection.JavaConverters)7 File (java.io.File)6 FileUtils (org.apache.commons.io.FileUtils)6 Rule (org.apache.jena.reasoner.rulesys.Rule)6 JenaSystem (org.apache.jena.system.JenaSystem)6 OWLtoRules (org.geneontology.jena.OWLtoRules)6 DefaultCurieHandler (org.geneontology.minerva.curie.DefaultCurieHandler)6 RuleEngine (org.geneontology.rules.engine.RuleEngine)6 Triple (org.geneontology.rules.engine.Triple)6 Assert (org.junit.Assert)6 BeforeClass (org.junit.BeforeClass)6 Ignore (org.junit.Ignore)6