diff --git a/OWLTools-Core/src/main/java/owltools/mooncat/Mooncat.java b/OWLTools-Core/src/main/java/owltools/mooncat/Mooncat.java index 3bc9d3d07..81502b75f 100644 --- a/OWLTools-Core/src/main/java/owltools/mooncat/Mooncat.java +++ b/OWLTools-Core/src/main/java/owltools/mooncat/Mooncat.java @@ -1188,6 +1188,8 @@ public static void retainAxiomsInPropertySubset(OWLOntology ont, Set ancs = reasoner.getSuperClasses(ax.getSubClass(), false); + //LOG.info(ax + " ANCS="+ancs); + if (ancs.containsEntity( supc)) { + String direct = "indirect"; + if (reasoner.getSuperClasses(ax.getSubClass(), true).containsEntity( supc)) { + direct = "direct"; + } + LOG.info("SCA = "+ax+" D="+direct); + OWLAnnotation ann = df.getOWLAnnotation(anProp, df.getOWLLiteral(direct)); + OWLAxiom newAxiom = changeAxiomAnnotations(ax, Collections.singleton(ann), df); + mgr.addAxiom(ont, newAxiom); + } + else { + // put it back + mgr.addAxiom(ont, ax); + } + } + } + + } + + /** + * Update the given axiom to the new set of axiom annotation. Recreates the + * axiom with the new annotations using the given factory. + * + * @param axiom + * @param annotations + * @param factory + * @return newAxiom + */ + public static OWLAxiom changeAxiomAnnotations(OWLAxiom axiom, Set annotations, OWLDataFactory factory) { + final AxiomAnnotationsChanger changer = new AxiomAnnotationsChanger(annotations, factory); + final OWLAxiom newAxiom = axiom.accept(changer); + return newAxiom; + } + + +} diff --git a/OWLTools-Runner/src/main/java/owltools/cli/CommandRunner.java b/OWLTools-Runner/src/main/java/owltools/cli/CommandRunner.java index 41f44dfd2..b91c44e97 100644 --- a/OWLTools-Runner/src/main/java/owltools/cli/CommandRunner.java +++ b/OWLTools-Runner/src/main/java/owltools/cli/CommandRunner.java @@ -36,8 +36,6 @@ import java.util.Vector; import java.util.stream.Collectors; -import javax.annotation.processing.SupportedOptions; - import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.io.LineIterator; @@ -45,7 +43,6 @@ import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.eclipse.jetty.server.Server; -import org.forester.phylogeny.data.Annotation; import org.geneontology.reasoner.ExpressionMaterializingReasoner; import org.geneontology.reasoner.ExpressionMaterializingReasonerFactory; import org.geneontology.reasoner.OWLExtendedReasoner; @@ -130,6 +127,21 @@ import org.semanticweb.owlapi.vocab.OWL2Datatype; import org.semanticweb.owlapi.vocab.OWLRDFVocabulary; +import com.clarkparsia.owlapi.explanation.DefaultExplanationGenerator; +import com.clarkparsia.owlapi.explanation.ExplanationGenerator; +import com.google.common.base.Optional; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; + +import de.derivo.sparqldlapi.Query; +import de.derivo.sparqldlapi.QueryArgument; +import de.derivo.sparqldlapi.QueryBinding; +import de.derivo.sparqldlapi.QueryEngine; +import de.derivo.sparqldlapi.QueryResult; +import de.derivo.sparqldlapi.exceptions.QueryEngineException; +import de.derivo.sparqldlapi.exceptions.QueryParserException; +import de.derivo.sparqldlapi.types.QueryArgumentType; import owltools.InferenceBuilder.OWLClassFilter; import owltools.RedundantInferences; import owltools.RedundantInferences.RedundantAxiom; @@ -178,6 +190,7 @@ import owltools.mooncat.PropertyViewOntologyBuilder; import owltools.mooncat.ProvenanceReasonerWrapper; import owltools.mooncat.QuerySubsetGenerator; +import owltools.mooncat.RedundantAxiomTagger; import owltools.mooncat.SpeciesMergeUtil; import owltools.mooncat.SpeciesSubsetterUtil; import owltools.mooncat.TransformationUtils; @@ -198,23 +211,6 @@ import uk.ac.manchester.cs.owlapi.modularity.ModuleType; import uk.ac.manchester.cs.owlapi.modularity.SyntacticLocalityModuleExtractor; -import com.clarkparsia.owlapi.explanation.DefaultExplanationGenerator; -import com.clarkparsia.owlapi.explanation.ExplanationGenerator; -import com.google.common.base.Optional; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; -import com.google.common.collect.Sets.SetView; - -import de.derivo.sparqldlapi.Query; -import de.derivo.sparqldlapi.QueryArgument; -import de.derivo.sparqldlapi.QueryBinding; -import de.derivo.sparqldlapi.QueryEngine; -import de.derivo.sparqldlapi.QueryResult; -import de.derivo.sparqldlapi.exceptions.QueryEngineException; -import de.derivo.sparqldlapi.exceptions.QueryParserException; -import de.derivo.sparqldlapi.types.QueryArgumentType; - /** * An instance of this class can execute owltools commands in sequence. * @@ -709,7 +705,7 @@ else if (opts.nextEq("--remove-uninstantiated-classes")) { g.getManager().removeAxioms(g.getSourceOntology(), rmAxioms); } else if (opts.nextEq("--make-subset-by-properties")) { - opts.info("PROPERTY-LIST", + opts.info("[-n] [-f] PROPERTY-LIST", "make an ontology subset that excludes axioms that use properties not in the specified set.\n"+ " Note the ontology should be relaxed e.g. X=A and R some B ==> X SubClassOf A" + " A property list is a space-separated list of object property OBO-IDs, shorthands, URIs, or labels.\n"+ @@ -720,9 +716,11 @@ else if (opts.nextEq("--make-subset-by-properties")) { boolean isSuppressRemoveDangling = false; while (opts.hasOpts()) { if (opts.nextEq("-f|--force")) { + opts.info("", "do not removing dangling"); isForceRemoveDangling = true; } else if (opts.nextEq("-n|--no-remove-dangling")) { + opts.info("", "do not removing dangling"); isSuppressRemoveDangling = true; } else { @@ -3930,7 +3928,7 @@ else if (opts.nextEq("--translate-undeclared-to-classes")) { OWLClass c = g.getDataFactory().getOWLClass((IRI)sub); OWLDeclarationAxiom ax = g.getDataFactory().getOWLDeclarationAxiom(c); g.getManager().addAxiom(g.getSourceOntology(), ax); - } + } } } } @@ -5108,6 +5106,10 @@ public void assertAboxInferences(Opts opts) throws Exception { mgr.addAxioms(g.getSourceOntology(), newAxioms); } + @CLIMethod("--tag-entailed-axioms") + public void tagEntailedAxioms(Opts opts) throws Exception { + RedundantAxiomTagger.tagRedundantAxioms(reasoner); + } @CLIMethod("--assert-inferred-subclass-axioms") public void assertInferredSubClassAxioms(Opts opts) throws Exception { opts.info("[--removeRedundant] [--keepRedundant] [--always-assert-super-classes] [--markIsInferred] [--useIsInferred] [--ignoreNonInferredForRemove] [--allowEquivalencies] [--reportProfile]", diff --git a/OWLTools-Runner/src/test/java/owltools/cli/MockSolrLoadCommandRunnerTest.java b/OWLTools-Runner/src/test/java/owltools/cli/MockSolrLoadCommandRunnerTest.java index e54440521..3812b13e5 100644 --- a/OWLTools-Runner/src/test/java/owltools/cli/MockSolrLoadCommandRunnerTest.java +++ b/OWLTools-Runner/src/test/java/owltools/cli/MockSolrLoadCommandRunnerTest.java @@ -34,4 +34,22 @@ public void testRunner() throws Exception { System.setOut(out); } + @Test + public void testRunnerOboIds() throws Exception { + + PrintStream out = System.out; + System.setOut(new PrintStream(new BufferedOutputStream(new FileOutputStream("target/oboids.json")))); + + String confpath = getResource("ont-config.yaml").getAbsolutePath(); + + init(); + load("obo-ids-test.owl"); + run("--reasoner elk"); + run("--solr-url mock"); + run("--solr-config "+ confpath); + run("--solr-load-ontology"); + System.setOut(out); + System.out.println("Done!"); + } + } diff --git a/OWLTools-Solr/src/main/java/owltools/solrj/loader/MockFlexSolrDocumentLoader.java b/OWLTools-Solr/src/main/java/owltools/solrj/loader/MockFlexSolrDocumentLoader.java index 171348684..19cdfa46e 100644 --- a/OWLTools-Solr/src/main/java/owltools/solrj/loader/MockFlexSolrDocumentLoader.java +++ b/OWLTools-Solr/src/main/java/owltools/solrj/loader/MockFlexSolrDocumentLoader.java @@ -2,6 +2,7 @@ import java.net.MalformedURLException; +import org.apache.log4j.Logger; import org.apache.solr.client.solrj.SolrServer; import org.apache.solr.common.SolrInputDocument; @@ -10,6 +11,8 @@ public class MockFlexSolrDocumentLoader extends FlexSolrDocumentLoader implements MockSolrDocumentLoader { + private static Logger LOG = Logger.getLogger(MockFlexSolrDocumentLoader.class); + public MockFlexSolrDocumentLoader(FlexCollection c) throws MalformedURLException { super((SolrServer)null, c); } @@ -17,6 +20,7 @@ public MockFlexSolrDocumentLoader(FlexCollection c) throws MalformedURLException final MockSolrDocumentCollection documentCollection = new MockSolrDocumentCollection(); @Override public void add(SolrInputDocument doc) { + LOG.info("Adding: "+doc); documentCollection.add(doc); }