diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..b8dca7c99 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +FROM maven:alpine + +RUN mkdir /app +WORKDIR /app + +# this trick doesn't seem to work for multi-project repos +#ADD pom.xml /app +#RUN ["/usr/local/bin/mvn-entrypoint.sh", "mvn", "verify", "clean", "--fail-never"] + +ADD OWLTools-Parent/pom.xml /app/OWLTools-Parent/ +WORKDIR /app/OWLTools-Parent +RUN ["/usr/local/bin/mvn-entrypoint.sh", "mvn", "verify", "clean", "--fail-never"] +WORKDIR /app + +ADD . /app +WORKDIR /app/OWLTools-Parent +RUN mvn -DskipTests clean install && cp ../OWLTools-Runner/target/owltools ../OWLTools-Runner/bin/ +ENV PATH="$PATH:/app/OWLTools-Runner/bin/" + +CMD owltools -h diff --git a/OWLTools-Annotation/src/main/java/owltools/gaf/inference/BasicAnnotationPropagator.java b/OWLTools-Annotation/src/main/java/owltools/gaf/inference/BasicAnnotationPropagator.java index 40768b006..f73e8d49c 100644 --- a/OWLTools-Annotation/src/main/java/owltools/gaf/inference/BasicAnnotationPropagator.java +++ b/OWLTools-Annotation/src/main/java/owltools/gaf/inference/BasicAnnotationPropagator.java @@ -380,32 +380,20 @@ protected Map createDefaultAspectMap(OWLGraphWrapper graph) { OWLClass mf = graph.getOWLClassByIdentifier("GO:0003674"); // molecular_function if (mf != null) { - String mfKey = getGoSubOntology(mf, graph); - if (mfKey == null) - throw new RuntimeException("Could not retrieve sub-ontology for GO:0003674 (molecular_function). The value of the OBO-namespace tag does not exist."); - - map.put(mfKey, "F"); + map.put(getGoSubOntology(mf, graph), "F"); } OWLClass bp = graph.getOWLClassByIdentifier("GO:0008150"); // biological_process if (bp != null) { - String bpKey = getGoSubOntology(bp, graph); - if (bpKey == null) - throw new RuntimeException("Could not retrieve sub-ontology for GO:0008150 (biological_process). The value of the OBO-namespace tag does not exist."); - - map.put(bpKey, "P"); + map.put(getGoSubOntology(bp, graph), "P"); } OWLClass cc = graph.getOWLClassByIdentifier("GO:0005575"); // cellular_component if (cc != null) { - String ccKey = getGoSubOntology(cc, graph); - if (ccKey == null) - throw new RuntimeException("Could not retrieve sub-ontology for GO:0005575 (celluar_component). The value of the OBO-namespace tag does not exist."); - - map.put(ccKey, "C"); + map.put(getGoSubOntology(cc, graph), "C"); } - if (map.isEmpty() || map.containsKey(null)) { + if (map.isEmpty()) { // only fail if there are mappings // the test case uses a custom ontology, which has no cc branch throw new RuntimeException("Could not create any valid aspect mappings. Is the correct ontology (GO) loaded?"); diff --git a/OWLTools-Annotation/src/main/java/owltools/gaf/parser/GAFParser.java b/OWLTools-Annotation/src/main/java/owltools/gaf/parser/GAFParser.java index 831e9745a..5dea2c3b0 100644 --- a/OWLTools-Annotation/src/main/java/owltools/gaf/parser/GAFParser.java +++ b/OWLTools-Annotation/src/main/java/owltools/gaf/parser/GAFParser.java @@ -167,7 +167,7 @@ private ReadState loadNext() throws IOException{ return ReadState.next; }else{ fireParsingWarning(error); - LOG.info(error + " : " + this.currentRow); + LOG.warn(error + " : " + this.currentRow); } } return ReadState.success; diff --git a/OWLTools-Annotation/src/test/resources/test_out_dated_iea.gaf b/OWLTools-Annotation/src/test/resources/test_out_dated_iea.gaf index 6e797f003..4d80db2d1 100644 --- a/OWLTools-Annotation/src/test/resources/test_out_dated_iea.gaf +++ b/OWLTools-Annotation/src/test/resources/test_out_dated_iea.gaf @@ -5,4 +5,4 @@ ! NOT a valid submission file!!!!!! ! MGI MGI:1918918 0610007C21Rik GO:0016021 MGI:MGI:1354194 IEA SP_KW:KW-0812 C RIKEN cDNA 0610007C21 gene HSPC013|p18 protein taxon:10090 20101003 UniProtKB VEGA:OTTMUSP00000025430 -MGI MGI:1918919 0610007C21Rik GO:0016021 MGI:MGI:1354194 IEA SP_KW:KW-0812 C RIKEN cDNA 0610007C21 gene HSPC013|p18 protein taxon:10090 20991003 UniProtKB VEGA:OTTMUSP00000025430 +MGI MGI:1918919 0610007C21Rik GO:0016021 MGI:MGI:1354194 IEA SP_KW:KW-0812 C RIKEN cDNA 0610007C21 gene HSPC013|p18 protein taxon:10090 20161003 UniProtKB VEGA:OTTMUSP00000025430 diff --git a/OWLTools-Core/src/main/java/owltools/graph/AxiomAnnotationTools.java b/OWLTools-Core/src/main/java/owltools/graph/AxiomAnnotationTools.java index 913194d0c..b5563483b 100644 --- a/OWLTools-Core/src/main/java/owltools/graph/AxiomAnnotationTools.java +++ b/OWLTools-Core/src/main/java/owltools/graph/AxiomAnnotationTools.java @@ -238,45 +238,6 @@ else if (result.size() == 1) { return result; } - /** - * Append annotations to an existing axiom - * - * @param axiom - * @param annotations - * @param ontology - * @return - */ - public static OWLAxiom appendAxiomAnnotations(OWLAxiom axiom, Set annotations, OWLOntology ontology) { - // filter existing - Set newAnnotations = new HashSet(axiom.getAnnotations()); - newAnnotations.addAll(annotations); - final OWLAxiom newAxiom = changeAxiomAnnotations(axiom, newAnnotations, ontology); - return newAxiom; - } - - /** - * Append xref annotations onto an existing axiom - * - * @param axiom - * @param xrefs - * @param ontology - * @return - */ - public static OWLAxiom appendXrefAnnotations(OWLAxiom axiom, Set xrefs, OWLOntology ontology) { - // filter existing - Set newAnnotations = new HashSet(axiom.getAnnotations()); - final OWLOntologyManager manager = ontology.getOWLOntologyManager(); - final OWLDataFactory factory = manager.getOWLDataFactory(); - - for (String x : xrefs) { - OWLAnnotationProperty p = factory.getOWLAnnotationProperty(IRI.create("http://www.geneontology.org/formats/oboInOwl#hasDbXref")); - OWLLiteral v = factory.getOWLLiteral(x); - newAnnotations.add(factory.getOWLAnnotation(p, v)); - } - final OWLAxiom newAxiom = changeAxiomAnnotations(axiom, newAnnotations, ontology); - return newAxiom; - } - /** * Update the given axiom to a new set of axiom annotation.
diff --git a/OWLTools-Core/src/main/java/owltools/mooncat/AxiomCopier.java b/OWLTools-Core/src/main/java/owltools/mooncat/AxiomCopier.java deleted file mode 100644 index e35a3af17..000000000 --- a/OWLTools-Core/src/main/java/owltools/mooncat/AxiomCopier.java +++ /dev/null @@ -1,445 +0,0 @@ -package owltools.mooncat; - -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.semanticweb.elk.owlapi.ElkReasonerFactory; -import org.semanticweb.owlapi.model.IRI; -import org.semanticweb.owlapi.model.OWLAnnotation; -import org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom; -import org.semanticweb.owlapi.model.OWLAnnotationProperty; -import org.semanticweb.owlapi.model.OWLAnnotationSubject; -import org.semanticweb.owlapi.model.OWLAnnotationValue; -import org.semanticweb.owlapi.model.OWLAxiom; -import org.semanticweb.owlapi.model.OWLClass; -import org.semanticweb.owlapi.model.OWLClassExpression; -import org.semanticweb.owlapi.model.OWLDataFactory; -import org.semanticweb.owlapi.model.OWLEntity; -import org.semanticweb.owlapi.model.OWLEquivalentClassesAxiom; -import org.semanticweb.owlapi.model.OWLLiteral; -import org.semanticweb.owlapi.model.OWLObjectSomeValuesFrom; -import org.semanticweb.owlapi.model.OWLOntology; -import org.semanticweb.owlapi.model.OWLOntologyCreationException; -import org.semanticweb.owlapi.model.OWLOntologyManager; -import org.semanticweb.owlapi.model.OWLSubClassOfAxiom; -import org.semanticweb.owlapi.model.parameters.Imports; -import org.semanticweb.owlapi.reasoner.OWLReasoner; -import org.semanticweb.owlapi.reasoner.OWLReasonerFactory; - -import uk.ac.manchester.cs.owlapi.modularity.ModuleType; -import uk.ac.manchester.cs.owlapi.modularity.SyntacticLocalityModuleExtractor; - -/** - * - * Copies axioms form a source ontology to a target ontology using equivalence axioms from - * a mapping ontology. - * - * Optionally also check to make sure that copying the axioms do not result in incoherencies. - * NOTE: works well with disjoint-sibs, see: https://github.com/monarch-initiative/mondo-build/issues/52 - * - * https://github.com/owlcollab/owltools/issues/230 - * - * @author cjm - * - */ -public class AxiomCopier { - - /** - * If true, copy axiom over even if it exists in target. - * We may want to do this if we want to annotate an axiom with all sources - */ - public boolean isCopyDuplicates = false; - - /** - * If true, check all incoming axioms to ensure they do not cause - * incoherency - */ - public boolean isTestForCoherency = false; - - /** - * We have 2 strategies; see below - */ - public boolean isUseConservative = true; - public OWLReasonerFactory reasonerFactory = new ElkReasonerFactory(); - - - - /** - * Simple IRI-value pairs representing an Annotation minus property - * - * @author cjm - * - */ - class AnnTuple { - IRI iri; - String val; - - - public AnnTuple(IRI iri, String val) { - super(); - this.iri = iri; - this.val = val; - } - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + getOuterType().hashCode(); - result = prime * result + ((iri == null) ? 0 : iri.hashCode()); - result = prime * result + ((val == null) ? 0 : val.hashCode()); - return result; - } - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - AnnTuple other = (AnnTuple) obj; - if (!getOuterType().equals(other.getOuterType())) - return false; - if (iri == null) { - if (other.iri != null) - return false; - } else if (!iri.equals(other.iri)) - return false; - if (val == null) { - if (other.val != null) - return false; - } else if (!val.equals(other.val)) - return false; - return true; - } - private AxiomCopier getOuterType() { - return AxiomCopier.this; - } - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - return "AnnTuple [iri=" + iri + ", val=" + val + "]"; - } - - - - } - - /** - * Makes a copy of axioms in source ontology, ready to be placed in targetOnt. - * - * Note: does not actually place the axioms in targetOnt, but the target ontology - * is used to avoid creating duplicates. Also used to build an exist of classes - * to be used in mapping. - * - * Note for non-logical axioms, when copying annotations we ignore the property - * for the purposes of duplicate checking. Rationale: we may want to block - * copying of an EXACT syn if we have already have the same string with the same class - * for a RELATED syn. - * - * If isTestForCoherency is set, reasoner-based checks are used - * - * @param sourceOnt - ontology to copy axioms from - * @param targetOnt - ontology to copy to (used to check for dupes and build index of classes) - * @param mapOnt - ontology with equivalence axioms - * @return copied and rewritten axioms - * @throws OWLOntologyCreationException - */ - public Set copyAxioms(OWLOntology sourceOnt, OWLOntology targetOnt, OWLOntology mapOnt) throws OWLOntologyCreationException { - - // axioms in targetOnt (minus annotations) - Set axiomsExisting = new HashSet<>(); - - // all simple annotations in T - Set annTuples = new HashSet(); - - // all classes in T - Set classesInTarget = new HashSet<>(); - - // reflexive mappings of classes S->T - Map eqMap = new HashMap<>(); - - OWLDataFactory df = targetOnt.getOWLOntologyManager().getOWLDataFactory(); - - Set targetAxioms = targetOnt.getAxioms(Imports.EXCLUDED); - - // build index of what we have already, to avoid dupes - for (OWLAxiom ax : targetAxioms) { - - // add non-annotation part - axiomsExisting.add(ax.getAxiomWithoutAnnotations()); - - if (ax.isLogicalAxiom()) { - - // add subclasses to index of classes to be mapped to - if (ax instanceof OWLSubClassOfAxiom && - !((OWLSubClassOfAxiom)ax).getSubClass().isAnonymous()) { - classesInTarget.add( ((OWLSubClassOfAxiom)ax).getSubClass().asOWLClass() ); - } - } - else if (ax instanceof OWLAnnotationAssertionAxiom) { - - // keep simple IRI->value index. - // motivation: avoid copying for example X relatedSyn Y if we have X exactSyn Y - OWLAnnotationAssertionAxiom aax = (OWLAnnotationAssertionAxiom)ax; - AnnTuple tup = getAnnTuple(aax); - annTuples.add(tup); - } - } - - // build equivalence map S->T, pointing source classes to target classes - // this map is reflexive - for (OWLAxiom ax : mapOnt.getAxioms(Imports.INCLUDED)) { - if (ax instanceof OWLEquivalentClassesAxiom) { - OWLEquivalentClassesAxiom eca = (OWLEquivalentClassesAxiom)ax; - for (OWLClass c : eca.getNamedClasses()) { - if (classesInTarget.contains(c)) { - for (OWLClass xc : eca.getNamedClasses()) { - eqMap.put(xc, c); - } - continue; - } - } - } - } - - Set axiomsToAdd = new HashSet<>(); - - Set srcAxioms = sourceOnt.getAxioms(Imports.EXCLUDED); - - if (isTestForCoherency) { - Set badAxioms = findIncoherentAxioms(reasonerFactory, sourceOnt, targetOnt, mapOnt); - System.out.println("ORIG:"+srcAxioms.size()); - System.out.println("INCOHERENCY-CAUSING AXIOMS:"+badAxioms.size()); - srcAxioms.removeAll(badAxioms); - System.out.println("NEW:"+srcAxioms.size()); - } - - // get copied axioms - for (OWLAxiom ax : srcAxioms) { - - OWLAxiom coreAxiom = ax.getAxiomWithoutAnnotations(); - OWLClass srcClass = null; - if (ax.isLogicalAxiom()) { - // LOGICAL - - Set sig = ax.getClassesInSignature(); - - if (sig.size() < 2) { - continue; - } - - // of logical axioms, currently only subClassOf axioms (NC->NC) are copied - if (ax instanceof OWLSubClassOfAxiom) { - OWLSubClassOfAxiom sca = (OWLSubClassOfAxiom)ax; - if (!sca.getSubClass().isAnonymous() && !sca.getSuperClass().isAnonymous()) { - srcClass = sca.getSubClass().asOWLClass(); - OWLClass supc = sca.getSuperClass().asOWLClass(); - if (eqMap.containsKey(supc) && eqMap.containsKey(srcClass)) { - - // make a new axiom, including annotation - OWLSubClassOfAxiom newAxiom = df.getOWLSubClassOfAxiom(eqMap.get(srcClass), - eqMap.get(supc), - anns(df, srcClass, false)); - - // add copy to list - if (isCopyDuplicates || - !axiomsExisting.contains(newAxiom.getAxiomWithoutAnnotations())) { - axiomsToAdd.add(newAxiom); - } - } - } - else if (!sca.getSubClass().isAnonymous() && sca.getSuperClass().isAnonymous()) { - // e.g. A SubClassOf R some B - srcClass = sca.getSubClass().asOWLClass(); - OWLClassExpression supx = sca.getSuperClass(); - if (supx instanceof OWLObjectSomeValuesFrom) { - OWLObjectSomeValuesFrom x = (OWLObjectSomeValuesFrom)supx; - if (!x.isAnonymous()) { - OWLClass supc = x.getFiller().asOWLClass(); - if (eqMap.containsKey(supc) && eqMap.containsKey(srcClass)) { - - // make a new axiom, including annotation - OWLSubClassOfAxiom newAxiom = df.getOWLSubClassOfAxiom( - eqMap.get(srcClass), - df.getOWLObjectSomeValuesFrom(x.getProperty(), eqMap.get(supc)), - anns(df, srcClass, false)); - - // add copy to list - if (isCopyDuplicates || - !axiomsExisting.contains(newAxiom.getAxiomWithoutAnnotations())) { - axiomsToAdd.add(newAxiom); - } - } - } - } - } - } - } - else if (ax instanceof OWLAnnotationAssertionAxiom){ - // NON-LOGICAL/ANNOTATION - - OWLAnnotationAssertionAxiom aax = (OWLAnnotationAssertionAxiom)ax; - OWLAnnotationSubject subj = aax.getSubject(); - - // do not copy annotations on blank nodes - if (!(subj instanceof IRI)) { - continue; - } - - srcClass = df.getOWLClass((IRI)subj); - - // only copy if (reflexive) equiv mapping has entry - if (eqMap.containsKey(srcClass)) { - - // OBO convention: xref annotations are treated differently for - // axiom annotations (as are defs) - boolean isXrefAnn = aax.getProperty().getIRI().toString().contains("Synonym"); - - OWLAnnotationAssertionAxiom newAxiom = df.getOWLAnnotationAssertionAxiom(aax.getProperty(), - eqMap.get(srcClass).getIRI(), - aax.getValue(), - anns(df, srcClass, isXrefAnn)); - AnnTuple tup = getAnnTuple(newAxiom); - - boolean isDupe = annTuples.contains(tup) || - axiomsExisting.contains(newAxiom.getAxiomWithoutAnnotations()); - if (isCopyDuplicates || !isDupe) { - axiomsToAdd.add(newAxiom); - } - } - } - else { - //System.out.println("SKIP:"+ax); - - } - } - return axiomsToAdd; - } - - /** - * make annotations to be placed on axiom - * - * @param df - * @param srcClass - * @param isXrefAnn if true use hasDbXref not source - * @return annotations - */ - private Set anns(OWLDataFactory df, OWLClass srcClass, boolean isXrefAnn) { - String iri = srcClass.getIRI().toString(); - iri = iri.replaceAll(".*/", ""); - iri = iri.replaceAll("_", ":"); - String pn = "source"; - if (isXrefAnn) { - pn = "hasDbXref"; - } - OWLAnnotationProperty p = df.getOWLAnnotationProperty(IRI.create("http://www.geneontology.org/formats/oboInOwl#"+pn)); - OWLAnnotation ann = df.getOWLAnnotation(p, df.getOWLLiteral(iri)); - return Collections.singleton(ann); - } - - private AnnTuple getAnnTuple(OWLAnnotationAssertionAxiom aax) { - String v; - OWLAnnotationValue av = aax.getValue(); - if (av instanceof OWLLiteral) { - v = ((OWLLiteral)av).getLiteral(); - } - else { - v = av.toString(); - } - v = v.toLowerCase(); - return new AnnTuple((IRI)aax.getSubject(), v); - } - - /** - * Finds all incoherency-causing axioms in sourceOnt - * - * One of two strategies is used: - * - * strict (default): - * - * combine all axioms, find unsat classes, create a module using SLME BOT from these, - * and treat all axioms in this module as potentially suspect. - * - * conservative: - * - * greedy approach. Keep adding axioms from sourceOntology to a combo ontology, until - * an unsat is found. If this happens, reject the axioms and carry on - * - * note on greedy approach: this is generally less desirable as with a greedy apprpach we may accept a problem - * axiom early and reject ok axioms (based on compatibility with already accepted bad axioms). - * with a strict approach all potentially problematic axioms are treated equally. - * - * - * @param rf - * @param sourceOnt - * @param targetOnt - * @param mapOnt - * @return - * @throws OWLOntologyCreationException - */ - public Set findIncoherentAxioms(OWLReasonerFactory rf, - OWLOntology sourceOnt, OWLOntology targetOnt, OWLOntology mapOnt) throws OWLOntologyCreationException { - - Set badAxioms = new HashSet<>(); - - OWLOntologyManager mgr = targetOnt.getOWLOntologyManager(); - OWLDataFactory df = mgr.getOWLDataFactory(); - - OWLOntology combo = mgr.createOntology(targetOnt.getAxioms(Imports.INCLUDED)); - mgr.addAxioms(combo, mapOnt.getAxioms(Imports.INCLUDED)); - - // TODO: Order these - Set testAxioms = sourceOnt.getAxioms(Imports.INCLUDED); - - OWLReasoner reasoner = rf.createReasoner(combo); - - if (isUseConservative) { - mgr.addAxioms(combo, testAxioms); - reasoner.flush(); - Set unsatisfiableClasses = reasoner.getUnsatisfiableClasses().getEntitiesMinusBottom(); - ModuleType mtype = ModuleType.BOT; - SyntacticLocalityModuleExtractor sme = new SyntacticLocalityModuleExtractor(mgr, combo, mtype); - Set seeds = new HashSet(unsatisfiableClasses); - Set axioms = sme.extract(seeds); - System.out.println("Axiom in unsat module: "+axioms.size()); - for (OWLAxiom ax : testAxioms) { - if (axioms.contains(ax) || - axioms.contains(ax.getAxiomWithoutAnnotations())) { - badAxioms.add(ax); - } - } - System.out.println("Axioms to be filtered: "+axioms.size()); - - } - else { - - for (OWLAxiom ax : testAxioms) { - System.out.println("TESTING: "+ax); - mgr.addAxiom(combo, ax); - reasoner.flush(); - Set unsats = reasoner.getUnsatisfiableClasses().getEntitiesMinusBottom(); - if (unsats.size() > 0) { - badAxioms.add(ax); - mgr.removeAxiom(combo, ax); - } - } - } - - return badAxioms; - - } - - -} diff --git a/OWLTools-Core/src/main/java/owltools/mooncat/EquivalenceSetMergeUtil.java b/OWLTools-Core/src/main/java/owltools/mooncat/EquivalenceSetMergeUtil.java index c9faa9aea..c93f94b6a 100644 --- a/OWLTools-Core/src/main/java/owltools/mooncat/EquivalenceSetMergeUtil.java +++ b/OWLTools-Core/src/main/java/owltools/mooncat/EquivalenceSetMergeUtil.java @@ -17,7 +17,6 @@ import org.semanticweb.owlapi.model.OWLClass; import org.semanticweb.owlapi.model.OWLEntity; import org.semanticweb.owlapi.model.OWLEquivalentClassesAxiom; -import org.semanticweb.owlapi.model.OWLLiteral; import org.semanticweb.owlapi.model.OWLNamedIndividual; import org.semanticweb.owlapi.model.OWLOntology; import org.semanticweb.owlapi.model.OWLOntologyChange; @@ -28,10 +27,8 @@ import org.semanticweb.owlapi.util.OWLEntityRenamer; import owltools.graph.OWLGraphWrapper; -import owltools.io.OWLPrettyPrinter; /** - * Utility for merging cliques of classes inferred to be equivalent * * @author cjm * @@ -48,15 +45,11 @@ public class EquivalenceSetMergeUtil { Map prefixScoreMap = new HashMap(); Map> propertyPrefixScoreMap = new HashMap>(); - boolean isAddEquivalenceAxioms = true; - boolean isRemoveAxiomatizedXRefs = false; - Set noMergePrefixes = new HashSet<>(); - OWLPrettyPrinter owlpp; + boolean isAddEquivalenceAxioms = true; public EquivalenceSetMergeUtil(OWLGraphWrapper g, OWLReasoner r) { graph = g; - owlpp = new OWLPrettyPrinter(g); ont = graph.getSourceOntology(); reasoner = r; } @@ -76,49 +69,17 @@ public void setPrefixScore(String prefix, Double score) { prefixScoreMap.put(prefix, score); } - - /** - * disallow merging of classes from this ontology - * - * E.g. UBERON, MONDO - * - * @param p - */ - public void noMergePrefix(String p) { - noMergePrefixes.add(p); - } - /** - * @param isRemoveAxiomatizedXRefs the isRemoveAxiomatizedXRefs to set - */ - public void setRemoveAxiomatizedXRefs(boolean isRemoveAxiomatizedXRefs) { - this.isRemoveAxiomatizedXRefs = isRemoveAxiomatizedXRefs; - } - - /** - * @param isAddEquivalenceAxioms the isAddEquivalenceAxioms to set - */ - public void setAddEquivalenceAxioms(boolean isAddEquivalenceAxioms) { - this.isAddEquivalenceAxioms = isAddEquivalenceAxioms; - } - - /** - * Merges cliques of classes inferred to be equivalent - * - * * @throws IncoherentOntologyException * */ public void merge() throws IncoherentOntologyException { - Set> nodes = new HashSet>(); Map> nodeByRep = new HashMap>(); - Set badClasses = new HashSet<>(); - Set unsats = reasoner.getUnsatisfiableClasses().getEntitiesMinusBottom(); if (unsats.size() > 0) { throw new IncoherentOntologyException(unsats); @@ -142,17 +103,11 @@ public void merge() throws IncoherentOntologyException { } LOG.info("TOTAL SETS-OF-SETS (redundant): "+nodeByRep.keySet().size()); - OWLAnnotationProperty xrefProperty = graph.getAnnotationProperty(OboFormatTag.TAG_XREF.getTag()); Map e2iri = new HashMap(); Set seenClasses = new HashSet(); - - // new axioms to be added; POST-renaming. - // Note these axioms may contain the IRIs of rewritten axioms (e.g. equivalence) - // We keep these unaltered - Set newAxiomsNoRewrite = new HashSet(); - - // iterate through each clique + Set newAxioms = new HashSet(); + for (Node n : nodes) { boolean isSeen = false; for (OWLEntity c : n.getEntities()) { @@ -165,110 +120,75 @@ public void merge() throws IncoherentOntologyException { if (isSeen) { continue; } - if (true) { - - // get clique leader - OWLEntity cliqueLeader = null; + OWLEntity rep = null; Double best = null; for (OWLEntity c : n.getEntities()) { Double score = getScore(c, prefixScoreMap); LOG.info(c +" SC: "+score); if (best == null || (score != null && score > best)) { - cliqueLeader = c; + rep = c; best = score; } } - LOG.info("Clique leader; BEST: "+best+" FOR: "+n.getEntities()); - + LOG.info("BEST: "+best+" FOR: "+n.getEntities()); for (OWLEntity c : n.getEntities()) { - if (c.equals(cliqueLeader)) + if (c.equals(rep)) continue; - LOG.info(c + " --> "+cliqueLeader); - e2iri.put(c, cliqueLeader.getIRI()); - - for (String p : noMergePrefixes) { - if (hasPrefix(c,p) && hasPrefix(cliqueLeader,p)) { - LOG.error("Illegal merge into "+p+" :: "+owlpp.render(c)+" --> "+ - owlpp.render(cliqueLeader)); - badClasses.add(c.asOWLClass()); - } - } - - // add xrefs + LOG.info(c + " --> "+rep); + e2iri.put(c, rep.getIRI()); if (isAddEquivalenceAxioms) { // if A is equivalent to B we may wish to retain a historical // record of this equivalance - after A is merged into B // (assuming B is the representative), all axioms referencing A // will be gone, so we re-add the original equivalence, - // translating to an obo-style xref - OWLAxiom eca = null; - - // TODO - allow other options - for now make an xref - OWLAnnotationValue value = - graph.getDataFactory().getOWLLiteral(graph.getIdentifier(c)); + // possibly translating to an obo-style xref + OWLAxiom eca; + + if (true) { + // TODO - allow other options - for now make an xref + OWLAnnotationProperty lap = graph.getAnnotationProperty(OboFormatTag.TAG_XREF.getTag()); + OWLAnnotationValue value = + graph.getDataFactory().getOWLLiteral(graph.getIdentifier(c)); + eca = + graph.getDataFactory().getOWLAnnotationAssertionAxiom(lap, rep.getIRI(), value); + } + else { + if (c instanceof OWLClass) { + graph.getDataFactory().getOWLEquivalentClassesAxiom((OWLClass)c, (OWLClass)rep); + } + else { + graph.getDataFactory().getOWLSameIndividualAxiom((OWLNamedIndividual)c, (OWLNamedIndividual)rep); + } + // note: this creates a dangler + // note: if |equivalence set| = n>2, creates n-1 axioms - // We always add to the clique leader - eca = - graph.getDataFactory().getOWLAnnotationAssertionAxiom(xrefProperty, cliqueLeader.getIRI(), value); + } LOG.info("Preserving ECA to represetative: "+eca); - newAxiomsNoRewrite.add(eca); + newAxioms.add(eca); } } } - - // remove any xref between non-dangling classes; - // assumption is that logical axioms connecting classes are complete; - // and also that equivalence xref axioms are added back - if (isRemoveAxiomatizedXRefs) { - Set rmXrefAxioms = new HashSet(); - for (OWLEntity c : n.getEntities()) { - for (OWLAnnotationAssertionAxiom a : graph.getSourceOntology().getAnnotationAssertionAxioms(c.getIRI())) { - if (a.getProperty().equals(xrefProperty)) { - OWLClass d = null; - if (a.getValue() instanceof OWLLiteral) { - d = graph.getOWLClassByIdentifier(((OWLLiteral)(a.getValue())).getLiteral()); - } - else if (a.getValue() instanceof IRI) { - d = graph.getOWLClass( (IRI)(a.getValue())); - } - else { - LOG.error("Can't convert: "+a); - } - if (d != null && - !graph.getSourceOntology().getAnnotationAssertionAxioms(d.getIRI()).isEmpty()) { - LOG.info("removing xref between two non-dangling classes, "+c+" -> "+d); - rmXrefAxioms.add(a); - } - } - } - } - graph.getManager().removeAxioms(ont, rmXrefAxioms); - } - - // Remove annotation assertions for cardinality=1 properties - // unless it is on the clique leader for that property - // (note this may be different than the overall clique leader) + // Merge all properties together + // some properties may be desired to have cardinality = 1 for (OWLAnnotationProperty p : propertyPrefixScoreMap.keySet()) { Map pmap = propertyPrefixScoreMap.get(p); - - // find the clique leader for property p - OWLEntity representativeForProp = null; - Double bestForProp = null; + OWLEntity rep = null; + Double best = null; for (OWLEntity c : n.getEntities()) { String v = graph.getAnnotationValue(c, p); if (v == null || v.equals("")) continue; LOG.info(c + " . "+p+" = "+v); Double score = getScore(c, pmap); - if (bestForProp == null || (score != null && score > bestForProp)) { - representativeForProp = c; - bestForProp = score; + if (best == null || (score != null && score > best)) { + rep = c; + best = score; } } for (OWLEntity c : n.getEntities()) { - if (c.equals(representativeForProp)) + if (c.equals(rep)) continue; Set rmAxioms = new HashSet(); for (OWLAnnotationAssertionAxiom ax : ont.getAnnotationAssertionAxioms(c.getIRI())) { @@ -280,11 +200,6 @@ else if (a.getValue() instanceof IRI) { } } } - - if (!badClasses.isEmpty()) { - LOG.error("The following classes would be merged: "+badClasses); - throw new IncoherentOntologyException(badClasses); - } OWLEntityRenamer oer = new OWLEntityRenamer(graph.getManager(), graph.getAllOntologies()); @@ -293,7 +208,7 @@ else if (a.getValue() instanceof IRI) { graph.getManager().applyChanges(changes); LOG.info("Mapped "+e2iri.size()+" entities!"); - graph.getManager().addAxioms(ont, newAxiomsNoRewrite); + graph.getManager().addAxioms(ont, newAxioms); // remove any reflexive assertions remaining // note: this is incomplete. Need a policy for what to do with equivalence axioms etc. @@ -304,23 +219,14 @@ else if (a.getValue() instanceof IRI) { rmAxioms.add(a); } } - - // sometimes we end up with A=A post-merge; remove these for (OWLEquivalentClassesAxiom a : ont.getAxioms(AxiomType.EQUIVALENT_CLASSES)) { if (a.getClassExpressions().size() < 2) { LOG.info("UNARY: "+a); rmAxioms.add(a); } } - - // not interested in this property - for (OWLAnnotationAssertionAxiom a : ont.getAxioms(AxiomType.ANNOTATION_ASSERTION)) { - if (a.getProperty().getIRI().equals(IRI.create("http://www.geneontology.org/formats/oboInOwl#id"))) { - rmAxioms.add(a); - } - } if (rmAxioms.size() > 0) { - LOG.info("REMOVING AXIOMS: "+rmAxioms.size()); + LOG.info("REMOVING REFLEXIVE AXIOMS: "+rmAxioms.size()); graph.getManager().removeAxioms(ont, rmAxioms); } @@ -346,8 +252,6 @@ private boolean hasPrefix(OWLEntity c, String p) { return false; } - - } diff --git a/OWLTools-Core/src/main/java/owltools/mooncat/Mooncat.java b/OWLTools-Core/src/main/java/owltools/mooncat/Mooncat.java index 3bc9d3d07..d70e11d34 100644 --- a/OWLTools-Core/src/main/java/owltools/mooncat/Mooncat.java +++ b/OWLTools-Core/src/main/java/owltools/mooncat/Mooncat.java @@ -736,20 +736,16 @@ public void removeClassesNotInIDSpace(String idspace, boolean removeDangling) { } public void removeAxiomsAboutIdSpace(String idspace, boolean removeDangling) { - removeAxiomsAboutIdSpace(idspace, removeDangling, true, false); + removeAxiomsAboutIdSpace(idspace, removeDangling, true); } - public void removeAxiomsAboutIdSpace(String idspace, boolean removeDangling, boolean removeAnnotations, boolean isInvert) { + public void removeAxiomsAboutIdSpace(String idspace, boolean removeDangling, boolean removeAnnotations) { LOG.info("Removing classes not in: "+idspace); idspace = idspace.toLowerCase()+":"; Set rmAxioms = new HashSet<>(); int n=0; for (OWLClass c : graph.getSourceOntology().getClassesInSignature()) { String id = graph.getIdentifier(c).toLowerCase(); - boolean isRm = id.startsWith(idspace); - if (isInvert) { - isRm = !isRm; - } - if (isRm) { + if (id.startsWith(idspace)) { n++; rmAxioms.addAll(graph.getSourceOntology().getAxioms(c)); if (removeAnnotations) { diff --git a/OWLTools-Core/src/test/java/owltools/OWLToolsTestBasics.java b/OWLTools-Core/src/test/java/owltools/OWLToolsTestBasics.java index 0ff26b3db..f9c32ddba 100644 --- a/OWLTools-Core/src/test/java/owltools/OWLToolsTestBasics.java +++ b/OWLTools-Core/src/test/java/owltools/OWLToolsTestBasics.java @@ -6,16 +6,11 @@ import java.io.File; import java.io.IOException; import java.io.StringWriter; -import java.util.HashSet; -import java.util.Set; -import org.apache.log4j.Logger; import org.obolibrary.oboformat.model.OBODoc; import org.obolibrary.oboformat.parser.OBOFormatParserException; import org.obolibrary.oboformat.writer.OBOFormatWriter; import org.semanticweb.owlapi.model.IRI; -import org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom; -import org.semanticweb.owlapi.model.OWLAxiom; import org.semanticweb.owlapi.model.OWLOntology; import org.semanticweb.owlapi.model.OWLOntologyCreationException; @@ -23,9 +18,6 @@ import owltools.io.ParserWrapper; public class OWLToolsTestBasics { - - private static Logger LOG = Logger.getLogger(OWLToolsTestBasics.class); - protected static File getResource(String name) { assertNotNull(name); @@ -64,35 +56,4 @@ protected static String renderOBOtoString(OBODoc oboDoc) throws IOException { stream.close(); return out.getBuffer().toString(); } - - private static boolean ignore(OWLAxiom a) { - if (a instanceof OWLAnnotationAssertionAxiom) { - if (((OWLAnnotationAssertionAxiom)a).getProperty().getIRI(). - equals(IRI.create("http://www.geneontology.org/formats/oboInOwl#id"))) { - return true; - } - } - return false; - } - - - protected static int compare(OWLOntology ont1, OWLOntology ont2) { - Set notIn1 = new HashSet<>(); - Set notIn2 = new HashSet<>(); - for (OWLAxiom a1 : ont1.getAxioms()) { - if (!ont2.containsAxiom(a1) && !ignore(a1)) { - LOG.error("ont2 missing "+a1); - notIn2.add(a1); - } - } - - for (OWLAxiom a2 : ont2.getAxioms()) { - if (!ont1.containsAxiom(a2) && !ignore(a2)) { - LOG.error("ont1 missing "+a2); - notIn2.add(a2); - } - } - - return notIn1.size() + notIn2.size(); - } } diff --git a/OWLTools-Core/src/test/java/owltools/mooncat/EquivalenceSetMergeUtilTest.java b/OWLTools-Core/src/test/java/owltools/mooncat/EquivalenceSetMergeUtilTest.java deleted file mode 100644 index 9fbe87370..000000000 --- a/OWLTools-Core/src/test/java/owltools/mooncat/EquivalenceSetMergeUtilTest.java +++ /dev/null @@ -1,60 +0,0 @@ -package owltools.mooncat; - -import static org.junit.Assert.*; - -import java.io.IOException; - -import org.junit.Test; -import org.obolibrary.obo2owl.Obo2OWLConstants.Obo2OWLVocabulary; -import org.obolibrary.oboformat.parser.OBOFormatParser; -import org.semanticweb.elk.owlapi.ElkReasonerFactory; -import org.semanticweb.owlapi.formats.OBODocumentFormat; -import org.semanticweb.owlapi.model.OWLAnnotationProperty; -import org.semanticweb.owlapi.model.OWLDocumentFormat; -import org.semanticweb.owlapi.model.OWLOntology; -import org.semanticweb.owlapi.model.OWLOntologyCreationException; -import org.semanticweb.owlapi.model.OWLOntologyStorageException; -import org.semanticweb.owlapi.reasoner.OWLReasoner; -import org.semanticweb.owlapi.vocab.OWLRDFVocabulary; - -import owltools.OWLToolsTestBasics; -import owltools.graph.OWLGraphWrapper; -import owltools.io.ParserWrapper; - -public class EquivalenceSetMergeUtilTest extends OWLToolsTestBasics { - - @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)); - } - -} diff --git a/OWLTools-Core/src/test/resources/equivalence-set-merge-util-expected.obo b/OWLTools-Core/src/test/resources/equivalence-set-merge-util-expected.obo deleted file mode 100644 index e8fe27a79..000000000 --- a/OWLTools-Core/src/test/resources/equivalence-set-merge-util-expected.obo +++ /dev/null @@ -1,30 +0,0 @@ -ontology: merge-test-out - -[Term] -id: A:1 -name: c1 -def: "b1 def" [] -xref: B:1 -xref: C:1 -xref: EXTERNAL:1 - -[Term] -id: A:2 -name: c2 -def: "b2 def" [] -xref: B:2 -xref: C:2 - -[Term] -id: B:3 -name: c3 -def: "b3 def" [] -xref: C:3 -xref: EXTERNAL:3 - -[Term] -id: D:3 -name: d3 -def: "d3 def" [] -xref: C:3 -xref: EXTERNAL:3 diff --git a/OWLTools-Core/src/test/resources/equivalence-set-merge-util-test.obo b/OWLTools-Core/src/test/resources/equivalence-set-merge-util-test.obo deleted file mode 100644 index 3231b30ea..000000000 --- a/OWLTools-Core/src/test/resources/equivalence-set-merge-util-test.obo +++ /dev/null @@ -1,59 +0,0 @@ -ontology: merge-test - -[Term] -id: A:1 -name: a1 -equivalent_to: B:1 -def: "a1 def" [] -xref: B:1 -xref: B:2 -xref: EXTERNAL:1 - -[Term] -id: B:1 -name: b1 -equivalent_to: C:1 -def: "b1 def" [] -xref: C:1 - -[Term] -id: C:1 -name: c1 -def: "c1 def" [] - -[Term] -id: A:2 -name: a2 -equivalent_to: B:2 -def: "a2 def" [] - -[Term] -id: B:2 -name: b2 -equivalent_to: C:2 -def: "b2 def" [] - -[Term] -id: C:2 -name: c2 -def: "c2 def" [] - -[Term] -id: B:3 -name: b3 -equivalent_to: C:3 -def: "b3 def" [] - -[Term] -id: C:3 -name: c3 -def: "c3 def" [] -xref: C:3 -xref: EXTERNAL:3 - -[Term] -id: D:3 -name: d3 -def: "d3 def" [] -xref: C:3 -xref: EXTERNAL:3 diff --git a/OWLTools-Parent/pom.xml b/OWLTools-Parent/pom.xml index 8c98d11d0..810c0e4c0 100644 --- a/OWLTools-Parent/pom.xml +++ b/OWLTools-Parent/pom.xml @@ -18,7 +18,7 @@ UTF-8 - 4.5.0 + 4.2.6 1.7.10 diff --git a/OWLTools-Runner/bin/owltools.script b/OWLTools-Runner/bin/owltools.script index bd3ba0844..8b0be82b5 100644 --- a/OWLTools-Runner/bin/owltools.script +++ b/OWLTools-Runner/bin/owltools.script @@ -29,6 +29,6 @@ then fi # Run -exec "$JAVA" -Xms2G $JVM_OPTIONS -DentityExmpansionLimit=4086000 -Djava.awt.headless=true -classpath $PATH_TO_SELF owltools.cli.CommandLineInterface "$@" +exec $CMD "$@" exit 1 diff --git a/OWLTools-Runner/src/main/java/owltools/cli/CommandRunner.java b/OWLTools-Runner/src/main/java/owltools/cli/CommandRunner.java index 41f44dfd2..f948cbb56 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; @@ -74,7 +71,6 @@ import org.semanticweb.owlapi.model.AddImport; import org.semanticweb.owlapi.model.AddOntologyAnnotation; import org.semanticweb.owlapi.model.AxiomType; -import org.semanticweb.owlapi.model.HasIRI; import org.semanticweb.owlapi.model.IRI; import org.semanticweb.owlapi.model.OWLAnnotation; import org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom; @@ -167,7 +163,6 @@ import owltools.io.StanzaToOWLConverter; import owltools.io.TableRenderer; import owltools.io.TableToAxiomConverter; -import owltools.mooncat.AxiomCopier; import owltools.mooncat.BridgeExtractor; import owltools.mooncat.Diff; import owltools.mooncat.DiffUtil; @@ -204,7 +199,6 @@ 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; @@ -307,9 +301,6 @@ else if (opts.nextEq("--no-reasoner")) { else if (opts.nextEq("--log-info")) { Logger.getRootLogger().setLevel(Level.INFO); } - else if (opts.nextEq("--log-warning")) { - Logger.getRootLogger().setLevel(Level.WARN); - } else if (opts.nextEq("--log-debug")) { Logger.getRootLogger().setLevel(Level.DEBUG); } @@ -869,58 +860,39 @@ else if (opts.nextEq("--spike-and-reason")) { } OWLPrettyPrinter owlpp = getPrettyPrinter(); - Set sourceOntologyClasses = g.getSourceOntology().getClassesInSignature(Imports.EXCLUDED); - LOG.info("SOURCE ONTOLOGY CLASSES:" +sourceOntologyClasses.size()); - - // create ancestor lookup, pre-spiking + Set cs = g.getSourceOntology().getClassesInSignature(Imports.EXCLUDED); reasoner = createReasoner(g.getSourceOntology(),reasonerName,g.getManager()); + Map> assertedParentMap = new HashMap<>(); - for (OWLClass c : sourceOntologyClasses) { + for (OWLClass c : cs) { assertedParentMap.put(c, reasoner.getSuperClasses(c, false).getFlattened()); } reasoner.dispose(); + LOG.info("CLASSES PRIOR:" +cs.size()); - // spike in support ontologies + // spike for (OWLOntology ont : g.getSupportOntologySet()) { LOG.info("MERGING:" +ont); g.mergeOntology(ont); } g.setSupportOntologySet(new HashSet()); - // perform inference on spiked ontology, determine difference + // test reasoner = createReasoner(g.getSourceOntology(),reasonerName,g.getManager()); int n = 0; - LOG.info("TESTING:" +sourceOntologyClasses.size()); - for (OWLClass c : sourceOntologyClasses) { - - // all ancestors in spiked ontology + LOG.info("TESTING:" +cs.size()); + for (OWLClass c : cs) { Set infParents = new HashSet<>(reasoner.getSuperClasses(c, false).getFlattened()); Set infParentsDirect = new HashSet<>(reasoner.getSuperClasses(c, true).getFlattened()); - // get those unique to spiked ontology infParents.removeAll(assertedParentMap.get(c)); - - for (OWLClass p : infParents) { - - // only report new inferences within source - if (sourceOntologyClasses.contains(p)) { - Set pSubs = reasoner.getSubClasses(p, true).getFlattened(); - boolean isRedundant = false; - for (OWLClass p2 : pSubs) { - if (sourceOntologyClasses.contains(p2) && infParents.contains(p2)) { - isRedundant = true; - break; - } - } - - if (!isRedundant) { - String isDirect = infParentsDirect.contains(p) ? "PARENT" : "ANCESTOR"; - System.out.println(owlpp.render(c)+ - "\t" + isDirect + "\t" + owlpp.render(p)); - n++; - } + if (cs.contains(p)) { + String isDirect = infParentsDirect.contains(p) ? "PARENT" : "ANCESTOR"; + System.out.println("NEW_INFERRED: "+owlpp.render(c)+ + " " + isDirect + " " + owlpp.render(p)); + n++; } } } @@ -1126,7 +1098,6 @@ else if (opts.nextEq("--remove-annotation-assertions")) { boolean isPreserveSynonyms = false; boolean isPreserveRelations = false; boolean isPreserveDeprecations = true; - boolean isPreserveDeprecationAxioms = true; Set preserveAnnotationPropertyIRIs = new HashSet(); while (opts.hasOpts()) { if (opts.nextEq("-l|--preserve-labels")) { @@ -1175,12 +1146,6 @@ else if (opts.nextEq("-p|--preserve-property")) { if (aaa.getProperty().isDeprecated()) { keepAxioms.add(aaa); } - if (isPreserveDeprecationAxioms) { - if (piri.equals(Obo2OWLVocabulary.IRI_OIO_consider.getIRI()) || - piri.equals(Obo2OWLVocabulary.IRI_IAO_0100001.getIRI())) { - keepAxioms.add(aaa); - } - } } if (isPreserveDefinitions) { if (piri.equals(Obo2OWLVocabulary.IRI_IAO_0000115.getIRI())) { @@ -1342,107 +1307,8 @@ else if (opts.nextEq("--rename-entity")) { List changes = oer.changeIRI(IRI.create(opts.nextOpt()),IRI.create(opts.nextOpt())); g.getManager().applyChanges(changes); } - else if (opts.nextEq("--merge-axiom-annotations")) { - opts.info("", "merges logically equivalent axioms making union of all annotations"); - OWLOntology ontology = g.getSourceOntology(); - Set axioms = ontology.getAxioms(Imports.EXCLUDED); - Map> amap = new HashMap<>(); - for (OWLAxiom a : axioms) { - OWLAxiom k = a.getAxiomWithoutAnnotations(); - if (!amap.containsKey(k)) - amap.put(k, new HashSet<>()); - amap.get(k).addAll(a.getAnnotations()); - } - Set newAxioms = new HashSet<>(); - for (OWLAxiom a : amap.keySet()) { - newAxioms.add(a.getAnnotatedAxiom(amap.get(a))); - } - g.getManager().removeAxioms(ontology, axioms); - g.getManager().addAxioms(ontology, newAxioms); - } - else if (opts.nextEq("--interpret-xrefs")) { - opts.info("", "interprets xrefs using logical axioms, adds as annotations on xrefs"); - boolean showOther = false; - while (opts.hasOpts()) { - if (opts.nextEq("--show-others")) { - opts.info("", "if set, who relationship type 'other'"); - showOther = true; - } - else - break; - } - OWLOntology ont = g.getSourceOntology(); - for (OWLClass c : g.getAllOWLClasses()) { - List xrefs = g.getXref(c); - boolean hasWrittenTerm = false; - for (String x : xrefs) { - IRI xiri = g.getIRIByIdentifier(x); - OWLClass xc = g.getDataFactory().getOWLClass(xiri); - - if (xc == null) { - System.err.println("NO CLASS: "+xc); - continue; - } - String rel = null; - if (reasoner.getSuperClasses(c, false).containsEntity(xc)) { - rel = "subClassOf"; - } - else if (reasoner.getSuperClasses(xc, false).containsEntity(c)) { - rel = "superClassOf"; - } - else if (reasoner.getEquivalentClasses(c).contains(xc)) { - rel = "equivalentTo"; - } - else { - if (!showOther) - continue; - rel = "other"; - } - - if (!hasWrittenTerm) { - System.out.println("[Term]"); - System.out.println("id: " + g.getIdentifier(c)+" ! "+g.getLabel(c)); - hasWrittenTerm = true; - } - System.out.println("xref: " + x+" {xref=\"MONDO:"+rel+"\"}"); - } - System.out.println(); - } - } - - else if (opts.nextEq("--add-xref-axiom-annotations")) { - opts.info("-l", "adds xref/provenance annotations to all axioms, excluding labels"); - boolean includeLogical = false; - while (opts.hasOpts()) { - if (opts.nextEq("-l|--logical")) { - opts.info("", "include logical axioms (excluded by default"); - includeLogical = true; - } - else - break; - } - OWLOntology ont = g.getSourceOntology(); - for (OWLClass c : g.getAllOWLClasses()) { - Set xrefs = new HashSet(); - xrefs.add(g.getIdentifier(c)); - Set axioms = new HashSet<>(); - if (includeLogical) - axioms.addAll(ont.getAxioms(c, Imports.EXCLUDED)); - for (OWLAnnotationAssertionAxiom a : ont.getAnnotationAssertionAxioms(c.getIRI())) { - if (a.getProperty().isLabel()) - continue; - axioms.add(a); - } - - Set newAxioms = axioms.stream().map( - a -> AxiomAnnotationTools.appendXrefAnnotations(a, xrefs, ont)).collect(Collectors.toSet()); - g.getManager().removeAxioms(ont, axioms); - g.getManager().addAxioms(ont, newAxioms); - } - } else if (opts.nextEq("--merge-equivalence-sets")) { - opts.info("[-s PREFIX SCORE]* [-l PREFIX SCORE]* [-c PREFIX SCORE]* [-d PREFIX SCORE]* [-P PREFIX] [-x]", - "merges sets of equivalent classes. Prefix-based priorities used to determine representative member"); + opts.info("[-s PREFIX SCORE]* [-l PREFIX SCORE]* [-c PREFIX SCORE]* [-d PREFIX SCORE]*", "merges sets of equivalent classes. Prefix-based priorities used to determine representative member"); EquivalenceSetMergeUtil esmu = new EquivalenceSetMergeUtil(g, reasoner); while (opts.hasOpts()) { if (opts.nextEq("-s")) { @@ -1465,25 +1331,12 @@ else if (opts.nextEq("-d")) { OWLAnnotationProperty p = g.getDataFactory().getOWLAnnotationProperty( Obo2OWLVocabulary.IRI_IAO_0000115.getIRI() ); esmu.setPropertyPrefixScore( p, opts.nextOpt(), Double.parseDouble(opts.nextOpt()) ); } - else if (opts.nextEq("-x")) { - opts.info("", "Removes xrefs between named classes"); - esmu.setRemoveAxiomatizedXRefs(true); - } - else if (opts.nextEq("-P|--preserve")) { - opts.info("PREFIX", "Disallows merging of classes with this prefix"); - esmu.noMergePrefix(opts.nextOpt()); - } else { break; } } esmu.merge(); } - else if (opts.nextEq("--replace-annotations")) { - opts.info("[-p PROP]", "Replace annotation assertions of type PROP for equivalent classes"); - // TODO - - } else if (opts.nextEq("--merge-equivalent-classes")) { opts.info("[-f FROM-URI-PREFIX]* [-t TO-URI-PREFIX] [-a] [-sa]", "merges equivalent classes, from source(s) to target ontology"); List prefixFroms = new Vector(); @@ -1525,9 +1378,7 @@ else if (opts.nextEq("-sa|--prioritize-annotations-from-source")) { // we use equivalence axioms from the full complement of ontologies // TODO - allow arbitrary entities Map binSizeMap = new HashMap(); - int nMatches = 0; - - for (OWLClass e : g.getAllOWLClasses()) { + for (OWLClass e : g.getSourceOntology().getClassesInSignature()) { //LOG.info(" testing "+c+" ECAs: "+g.getSourceOntology().getEquivalentClassesAxioms(c)); // TODO - may be more efficient to invert order of testing String iriStr = e.getIRI().toString(); @@ -1541,7 +1392,6 @@ else if (opts.nextEq("-sa|--prioritize-annotations-from-source")) { if (prefixFroms.size()==0) isMatch = true; if (isMatch) { - nMatches ++; Set ecs = new HashSet(); if (reasoner != null) { ecs = reasoner.getEquivalentClasses(e).getEntities(); @@ -1558,7 +1408,6 @@ else if (opts.nextEq("-sa|--prioritize-annotations-from-source")) { } } int size = ecs.size(); - LOG.debug("Equiv mappings for : "+e+" = "+ecs); if (binSizeMap.containsKey(size)) { binSizeMap.put(size, binSizeMap.get(size) +1); } @@ -1572,7 +1421,6 @@ else if (opts.nextEq("-sa|--prioritize-annotations-from-source")) { // add to mapping. Renaming will happen later e2iri.put(e, d.getIRI()); // TODO one-to-many - LOG.debug("mapping "+e+" -> "+d); // annotation collapsing. In OBO, max cardinality of label, comment and definition is 1 // note that this not guaranteed to work if multiple terms are being merged in @@ -1607,29 +1455,22 @@ else if (opts.nextEq("-sa|--prioritize-annotations-from-source")) { } } } - LOG.info("Num matches = "+nMatches); for (Integer k : binSizeMap.keySet()) { LOG.info(" | Bin( "+k+" classes ) | = "+binSizeMap.get(k)); } g.getManager().removeAxioms(g.getSourceOntology(), rmAxioms); LOG.info("Mapping "+e2iri.size()+" entities"); + // TODO - this is slow List changes = oer.changeIRI(e2iri); g.getManager().applyChanges(changes); LOG.info("Mapped "+e2iri.size()+" entities!"); } else if (opts.nextEq("--rename-entities-via-equivalent-classes")) { - opts.info("[-p PREFIX]", "renames entities in source ontology, using equiv axioms from all"); String prefix = null; - String prefixTo = null; while (opts.hasOpts()) { if (opts.nextEq("-p|--prefix")) { - opts.info("", "prefix to map from (FULL URI)"); prefix = opts.nextOpt(); } - else if (opts.nextEq("-q|--prefix-to")) { - opts.info("", "prefix to map to (FULL URI)"); - prefixTo = opts.nextOpt(); - } else break; } @@ -1659,9 +1500,6 @@ else if (opts.nextEq("-q|--prefix-to")) { } for (OWLClassExpression d : OwlHelper.getEquivalentClasses(c, ont)) { if (d instanceof OWLClass) { - if (prefixTo != null && !d.asOWLClass().getIRI().toString().startsWith(prefixTo)) { - continue; - } e2iri.put(c, d.asOWLClass().getIRI()); LOG.info(" "+c+" ==> "+d ); } @@ -2759,47 +2597,8 @@ else if (opts.nextEq("--annotate-with-reasoner")) { g.setSourceOntology(outputOntology); } } - else if (opts.nextEq("--reason-subontologies")) { - opts.info("", "checks all ontologies in direct imports for incoherency"); - while (opts.hasOpts()) { - if (opts.nextEq("-r")) { - opts.info("REASONERNAME", "selects the reasoner to use"); - reasonerName = opts.nextOpt(); - } - else { - break; - } - } - OWLOntology ont = g.getSourceOntology(); - Set badImports = new HashSet<>(); - for (OWLOntology o : ont.getDirectImports()) { - boolean isIncoherent = false; - OWLReasoner r = createReasoner(o, reasonerName, g.getManager()); - if (!r.isConsistent()) { - LOG.error("INCONSISTENT: "+o); - isIncoherent = true; - } - else { - for (OWLClass c : r.getUnsatisfiableClasses()) { - if (c.isBuiltIn()) - continue; - LOG.error("UNSAT: "+o+" has "+c); - isIncoherent = true; - } - } - if (isIncoherent) { - badImports.add(g.getDataFactory().getOWLImportsDeclaration(o.getOntologyID().getOntologyIRI().get())); - } - } - OWLImportsDeclaration importDeclaration; - for (OWLImportsDeclaration i : badImports) { - LOG.info("REMOVING: "+i); - RemoveImport x = new RemoveImport(ont, i); - g.getManager().applyChange(x); - } - } else if (opts.nextEq("--run-reasoner")) { - opts.info("[-r reasonername] [--assert-implied] [--indirect] [-u] [-m UNSATMODFILE]", "infer new relationships"); + opts.info("[-r reasonername] [--assert-implied] [--indirect] [-u]", "infer new relationships"); boolean isAssertImplied = false; boolean isDirect = true; boolean isShowUnsatisfiable = false; @@ -2834,7 +2633,7 @@ else if (opts.nextEq("-x|--remove-unsatisfiable")) { isShowUnsatisfiable = true; } else if (opts.nextEq("-m|--unsatisfiable-module")) { - opts.info("FILE", "create a module for the unsatisfiable classes."); + opts.info("", "create a module for the unsatisfiable classes."); unsatisfiableModule = opts.nextOpt(); } else if (opts.nextEq("--trace-module-axioms")) { @@ -3035,154 +2834,6 @@ else if (opts.nextEq("--trace-module-axioms")) { } } } - else if (opts.nextEq("--copy-axioms")) { - opts.info("[-m MAPONT] [-s SRCONT] [-n] [-l] [--no-strict]", - "copies axioms from SRC to current (target) ontology"); - AxiomCopier copier = new AxiomCopier(); - OWLOntology mapOnt = null; - OWLOntology targetOnt = g.getSourceOntology(); - OWLOntology sourceOnt = null; - boolean isCopyDuplicates = false; - boolean isTestForCoherency = false; - - boolean isNew = false; - while (opts.hasOpts()) { - if (opts.nextEq("-m|--map-ontology")) { - opts.info("ONTPATH", "REQUIRED"); - mapOnt = pw.parse( opts.nextOpt() ); - } - else if (opts.nextEq("-s|--source-ontology")) { - opts.info("ONTPATH", "REQUIRED"); - sourceOnt = pw.parse( opts.nextOpt() ); - } - else if (opts.nextEq("-n|--new")) { - opts.info("", "if true, place copied axioms in a new ontology"); - isNew = true; - } - else if (opts.nextEq("-l|--logic")) { - opts.info("", "if true, do logical test for coherency on each logical axiom"); - isTestForCoherency = true; - } - else if (opts.nextEq("--no-strict")) { - opts.info( - "", "if set, perform less rigorous filtering. "+ - "use greedy approach, incrementally adding axioms. "+ - "Implies -l"); - isTestForCoherency = true; - copier.isUseConservative = false; - } - else if (opts.nextEq("-d|--copy-duplicates")) { - opts.info("", "if true, copy axioms that already exist"); - isCopyDuplicates = true; - } - else { - break; - } - } - copier.isCopyDuplicates = isCopyDuplicates; - copier.isTestForCoherency = isTestForCoherency; - Set axioms = copier.copyAxioms(sourceOnt, targetOnt, mapOnt); - System.out.println("COPIED AXIOMS: "+axioms.size()); - if (isNew) { - g.setSourceOntology(g.getManager().createOntology()); - } - g.getManager().addAxioms(g.getSourceOntology(), axioms); - } - else if (opts.nextEq("--eval-equiv-axiom")) { - opts.info("[-c CLASSLIST]", "tests the classification power of an existing equivalence "+ - "axiom on an owlclass. Attempts to recapitulate classification of all subclasses with and without axiom. "+ - "measures jaccard similarity of superclass list before and after"); - List clsIds = new ArrayList<>(); - while (opts.hasOpts()) { - if (opts.nextEq("-c|--classes")) { - clsIds = opts.nextList(); - } - else if (opts.nextEq("-r")) { - opts.info("REASONERNAME", "selects the reasoner to use"); - reasonerName = opts.nextOpt(); - } - else { - break; - } - } - OWLOntologyManager mgr = g.getManager(); - OWLOntology ont = g.getSourceOntology(); - OWLPrettyPrinter owlpp = getPrettyPrinter(); - reasoner = createReasoner(ont, reasonerName, mgr); - for (String clsiId :clsIds) { - OWLClass c = g.getOWLClassByIdentifier(clsiId); - System.out.println("EVAL: "+owlpp.render(c)); - - // axioms to recapitulate: test set - Set testAxioms = new HashSet<>(); - Set eqAxioms = new HashSet<>(); - Set moduleClasses = reasoner.getSubClasses(c, false).getFlattened(); - moduleClasses.add(c); - - Map> testSuperClassMap = new HashMap<>(); - for (OWLClass sc : moduleClasses) { - testAxioms.addAll(ont.getSubClassAxiomsForSubClass(sc)); - Set sups = reasoner.getSuperClasses(sc, false).getFlattened(); - - //testSuperClassMap.put(sc, Sets.intersection(sups, moduleClasses)); - testSuperClassMap.put(sc, sups); - } - eqAxioms.addAll(ont.getEquivalentClassesAxioms(c)); - - for (OWLAxiom eqa : eqAxioms) { - System.out.println(" testing power of: "+owlpp.render(eqa)); - } - - mgr.removeAxioms(ont, testAxioms); - String[] states = {"withAxiom", "withoutAxiom"}; - Map>> reinfMap = new HashMap<>(); - for (String state : states) { - reasoner.flush(); - int n = 0; - double jsimTotal = 0.0; - for (OWLClass sc : moduleClasses) { - Set sups = reasoner.getSuperClasses(sc, false).getFlattened(); - //sups = Sets.intersection(sups, moduleClasses); - int numI = Sets.intersection(sups, testSuperClassMap.get(sc)).size(); - int numU = Sets.union(sups, testSuperClassMap.get(sc)).size(); - if (numU>0) { - double jsim = numI / (double)numU; - jsimTotal += jsim; - n++; - //LOG.debug("ANCS); - } - Sets.difference(sups, testSuperClassMap.get(sc)); - if (!reinfMap.containsKey(sc)) { - reinfMap.put(sc, new HashMap<>()); - } - reinfMap.get(sc).put(state, sups); - } - double jsimAvg = jsimTotal / n; - System.out.println(" score "+state+" jaccard sim average="+jsimAvg+" n="+n); - mgr.removeAxioms(ont, eqAxioms); - } - for (OWLClass sc : moduleClasses) { - Set sups1 = reinfMap.get(sc).get(states[0]); - Set sups2 = reinfMap.get(sc).get(states[1]); - if (!sups1.equals(sups2)) { - System.out.println("DIFF FOR: "+owlpp.render(sc)); - Set diff1 = Sets.difference(sups1, sups2); - Set diff2 = Sets.difference(sups2, sups1); - for (OWLClass cd : diff1) { - System.out.println(" "+ states[0]+" : "+owlpp.render(cd)); - } - for (OWLClass cd : diff2) { - System.out.println(" "+ states[1]+" : "+owlpp.render(cd)); - } - } - } - - - // restore - mgr.addAxioms(ont, eqAxioms); - mgr.addAxioms(ont, testAxioms); - } - } else if (opts.nextEq("--stash-subclasses")) { opts.info("[-a][--prefix PREFIX][--ontology RECAP-ONTOLOGY-IRI", "removes all subclasses in current source ontology; after reasoning, try to re-infer these"); @@ -3440,105 +3091,7 @@ else if (opts.nextEq("--obsolete-class")) { System.err.println("TODO"); } - else if (opts.nextEq("--obsolete-replace")) { - opts.info("ID REPLACEMENT-ID", "Add a deprecation axiom"); - OWLObject obsObj = resolveEntity( opts); - OWLObject repl = resolveEntity( opts); - OWLEntityRenamer oer = new OWLEntityRenamer(g.getManager(), g.getAllOntologies()); - Set rmAxioms = new HashSet<>(); - OWLOntology ont = g.getSourceOntology(); - IRI obsObjIRI = ((HasIRI) obsObj).getIRI(); - IRI replIRI = ((HasIRI) repl).getIRI(); - String origLabel = g.getLabel(obsObj); - String label = "obsolete "+origLabel; - for (OWLAnnotationAssertionAxiom a : ont.getAnnotationAssertionAxioms(obsObjIRI)) { - if (a.getProperty().isLabel()) { - rmAxioms.add(a); - } - if (a.getProperty().isComment()) { - rmAxioms.add(a); - } - if (a.getProperty().getIRI().equals(Obo2OWLVocabulary.IRI_IAO_0000115.getIRI())) { - //if (g.getDef(((HasIRI) repl).getIRI()) != null) { - rmAxioms.add(a); - //} - } - } - LOG.info("REMOVING: "+rmAxioms); - g.getManager().removeAxioms(ont, rmAxioms); - - Map e2iri = new HashMap(); - e2iri.put((OWLEntity) obsObj, replIRI); - List changes = oer.changeIRI(e2iri); - g.getManager().applyChanges(changes); - OWLDataFactory df = g.getDataFactory(); - Set newAxioms = new HashSet<>(); - OWLAnnotationProperty synp = df.getOWLAnnotationProperty(Obo2OWLVocabulary.IRI_OIO_hasExactSynonym.getIRI()); - OWLAnnotationProperty xp = df.getOWLAnnotationProperty(Obo2OWLVocabulary.IRI_OIO_hasDbXref.getIRI()); - OWLAnnotation synAnn = df.getOWLAnnotation(xp, df.getOWLLiteral(g.getIdentifier(obsObjIRI))); - Set synAnns = Collections.singleton(synAnn); - newAxioms.add(df.getOWLDeclarationAxiom((OWLClass)obsObj)); - newAxioms.add(df.getOWLAnnotationAssertionAxiom(df.getOWLDeprecated(), obsObjIRI, df.getOWLLiteral(true))); - newAxioms.add(df.getOWLAnnotationAssertionAxiom(df.getRDFSLabel(), obsObjIRI, df.getOWLLiteral(label))); - newAxioms.add(df.getOWLAnnotationAssertionAxiom(synp, replIRI, df.getOWLLiteral(origLabel), synAnns)); - - OWLAnnotationProperty rp = df.getOWLAnnotationProperty(Obo2OWLVocabulary.IRI_IAO_0100001.getIRI()); - newAxioms.add(df.getOWLAnnotationAssertionAxiom(rp, obsObjIRI, - df.getOWLLiteral(g.getIdentifier(repl)))); - - g.getManager().addAxioms(ont, newAxioms); - - } - else if (opts.nextEq("--replace-annotations")) { - opts.info("[-p PROP]", "Replace annotation assertions of type PROP for equivalent classes"); - OWLObject obsObj = resolveEntity( opts); - OWLObject repl = resolveEntity( opts); - OWLEntityRenamer oer = new OWLEntityRenamer(g.getManager(), g.getAllOntologies()); - Set rmAxioms = new HashSet<>(); - OWLOntology ont = g.getSourceOntology(); - IRI obsObjIRI = ((HasIRI) obsObj).getIRI(); - IRI replIRI = ((HasIRI) repl).getIRI(); - String origLabel = g.getLabel(obsObj); - String label = "obsolete "+origLabel; - for (OWLAnnotationAssertionAxiom a : ont.getAnnotationAssertionAxioms(obsObjIRI)) { - if (a.getProperty().isLabel()) { - rmAxioms.add(a); - } - if (a.getProperty().isComment()) { - rmAxioms.add(a); - } - if (a.getProperty().getIRI().equals(Obo2OWLVocabulary.IRI_IAO_0000115.getIRI())) { - //if (g.getDef(((HasIRI) repl).getIRI()) != null) { - rmAxioms.add(a); - //} - } - } - LOG.info("REMOVING: "+rmAxioms); - g.getManager().removeAxioms(ont, rmAxioms); - - Map e2iri = new HashMap(); - e2iri.put((OWLEntity) obsObj, replIRI); - List changes = oer.changeIRI(e2iri); - g.getManager().applyChanges(changes); - OWLDataFactory df = g.getDataFactory(); - Set newAxioms = new HashSet<>(); - OWLAnnotationProperty synp = df.getOWLAnnotationProperty(Obo2OWLVocabulary.IRI_OIO_hasExactSynonym.getIRI()); - OWLAnnotationProperty xp = df.getOWLAnnotationProperty(Obo2OWLVocabulary.IRI_OIO_hasDbXref.getIRI()); - OWLAnnotation synAnn = df.getOWLAnnotation(xp, df.getOWLLiteral(g.getIdentifier(obsObjIRI))); - Set synAnns = Collections.singleton(synAnn); - newAxioms.add(df.getOWLDeclarationAxiom((OWLClass)obsObj)); - newAxioms.add(df.getOWLAnnotationAssertionAxiom(df.getOWLDeprecated(), obsObjIRI, df.getOWLLiteral(true))); - newAxioms.add(df.getOWLAnnotationAssertionAxiom(df.getRDFSLabel(), obsObjIRI, df.getOWLLiteral(label))); - newAxioms.add(df.getOWLAnnotationAssertionAxiom(synp, replIRI, df.getOWLLiteral(origLabel), synAnns)); - - OWLAnnotationProperty rp = df.getOWLAnnotationProperty(Obo2OWLVocabulary.IRI_IAO_0100001.getIRI()); - newAxioms.add(df.getOWLAnnotationAssertionAxiom(rp, obsObjIRI, - df.getOWLLiteral(g.getIdentifier(repl)))); - - g.getManager().addAxioms(ont, newAxioms); - - } - else if (opts.nextEq("-d") || opts.nextEq("--draw")) { + else if (opts.nextEq("-d") || opts.nextEq("--draw")) { opts.info("[-o FILENAME] [-f FMT] LABEL/ID", "generates a file tmp.png made using QuickGO code"); String imgf = "tmp.png"; String fmt = "png"; @@ -3850,26 +3403,20 @@ else if (opts.nextEq("--remove-subset")) { m.removeSubsetClasses(cset, isRemoveDangling); } else if (opts.nextEq("--remove-axioms-about")) { - opts.info("[-v] [-d] IDSPACES", "Removes axioms that are about the specified ID space"); + opts.info("[-d] IDSPACES", "Removes axioms that are about the specified ID space"); boolean isRemoveDangling = true; - boolean isInvert = false; while (opts.hasOpts()) { if (opts.nextEq("-d|--keep-dangling")) { opts.info("", "if specified, dangling axioms (ie pointing to removed classes) are preserved"); isRemoveDangling = false; } - else if (opts.nextEq("-v|--invert")) { - opts.info("", - "invert - remove axioms NOT about"); - isInvert = true; - } else break; } String idspace = opts.nextOpt(); Mooncat m = new Mooncat(g); - m.removeAxiomsAboutIdSpace(idspace, isRemoveDangling, true, isInvert); + m.removeAxiomsAboutIdSpace(idspace, isRemoveDangling); } else if (opts.nextEq("--remove-classes-in-idspace")) { opts.info("[-d] [-s IDSPACE]", "Removes classes in an ID space from ontology"); @@ -3904,22 +3451,12 @@ else if (opts.nextEq("-d|--keep-dangling")) { m.removeSubsetClasses(cset, isRemoveDangling); } else if (opts.nextEq("--extract-subset")) { - opts.info("[-x] SUBSET", "Extract a subset (aka slim) from an ontology, storing subset in place of existing ontology"); - boolean isRemoveDangling = false; - while (opts.hasOpts()) { - if (opts.nextEq("-x|--remove-dangling")) { - opts.info("", - "if specified, dangling axioms (ie pointing to removed classes) are removed"); - isRemoveDangling = true; - } - else - break; - } + opts.info("SUBSET", "Extract a subset (aka slim) from an ontology, storing subset in place of existing ontology"); String subset = opts.nextOpt(); Set cset = g.getOWLClassesInSubset(subset); LOG.info("Removing "+cset.size()+" classes"); Mooncat m = new Mooncat(g); - m.removeSubsetComplementClasses(cset, isRemoveDangling); + m.removeSubsetComplementClasses(cset, false); } else if (opts.nextEq("--translate-undeclared-to-classes")) { for (OWLAnnotationAssertionAxiom a : g.getSourceOntology().getAxioms(AxiomType.ANNOTATION_ASSERTION)) { diff --git a/OWLTools-Runner/src/main/java/owltools/cli/SolrCommandRunner.java b/OWLTools-Runner/src/main/java/owltools/cli/SolrCommandRunner.java index 183aa66bd..c5974bff9 100644 --- a/OWLTools-Runner/src/main/java/owltools/cli/SolrCommandRunner.java +++ b/OWLTools-Runner/src/main/java/owltools/cli/SolrCommandRunner.java @@ -22,9 +22,9 @@ import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; -import org.apache.solr.client.solrj.SolrServer; +import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrServerException; -import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer; +import org.apache.solr.client.solrj.impl.HttpSolrClient; import org.apache.solr.common.SolrException; import org.semanticweb.elk.owlapi.ElkReasonerFactory; import org.semanticweb.owlapi.model.IRI; @@ -73,7 +73,6 @@ import owltools.solrj.loader.MockSolrDocumentLoader; import owltools.solrj.loader.MockFlexSolrDocumentLoader; import owltools.solrj.loader.MockGafSolrDocumentLoader; -import owltools.solrj.loader.MockModelAnnotationSolrDocumentLoader; import owltools.solrj.loader.MockSolrDocumentCollection; import owltools.yaml.golrconfig.ConfigManager; import owltools.yaml.golrconfig.SolrSchemaXMLWriter; @@ -202,24 +201,29 @@ public void setSolrLogFile(Opts opts) { */ @SuppressWarnings("deprecation") @CLIMethod("--solr-purge") - public void purgeSolr(Opts opts) throws Exception { + public void purgeSolr(Opts opts) throws Exception { // Check to see if the global url has been set. String url = sortOutSolrURL(globalSolrURL); // Wipe out the solr index at url. - SolrServer server = new CommonsHttpSolrServer(url); - server.deleteByQuery("*:*"); - server.commit(); - - // Probably worked, so let's destroy the log if there is one. - if( globalSolrLogFile != null && globalSolrLogFile.exists() ){ - boolean yes_p = globalSolrLogFile.delete(); - if( yes_p ){ - LOG.info("Deleted GOlr load log file."); - }else{ - // Nothing there, doing nothing. - } + SolrClient server = new HttpSolrClient(url); + try { + server.deleteByQuery("*:*"); + server.commit(); + + // Probably worked, so let's destroy the log if there is one. + if( globalSolrLogFile != null && globalSolrLogFile.exists() ){ + boolean yes_p = globalSolrLogFile.delete(); + if( yes_p ){ + LOG.info("Deleted GOlr load log file."); + }else{ + // Nothing there, doing nothing. + } + } + } catch (SolrServerException e) { + LOG.info("Purge at: " + url + " failed!"); + e.printStackTrace(); } LOG.info("Purged: " + url); } @@ -312,79 +316,83 @@ else if (opts.nextEq("--allow-null")) { boolean isMock = false; int nClasses = 0; // Actual ontology class loading. - FlexSolrDocumentLoader loader; - if (url.equals("mock")) { - loader = new MockFlexSolrDocumentLoader(flex); - isMock = true; - } - else { - loader = new FlexSolrDocumentLoader(url, flex); - } - - LOG.info("Trying ontology flex load."); - loader.load(); - - // number of docs loaded MUST be equal to or higher than minClasses - // (docs also comprises non-class documents, e.g. ObjectProperties) - if (loader.getCurrentDocNumber() < minClasses) { - LOG.error("Fewer documents loaded than expected: "+loader.getCurrentDocNumber()+" < "+minClasses); - exit(1); - } - - // Load likely successful--log it. - //optionallyLogLoad("ontology", ???); - // TODO: Well, this is a lame second best. - //for( OWLOntology o : g.getAllOntologies() ){ - for( OWLOntology o : g.getManager().getOntologies() ){ - - //optionallyLogLoad("ontology", o.getOntologyID().toString()); - // This is "correct", but I'm only getting one. - String ont_id = "unknown"; - String ont_version = "unknown"; - try { - if (o.getOntologyID() != null) { - Optional optional = o.getOntologyID().getOntologyIRI(); - if (optional.isPresent()) { - ont_id = optional.get().toString(); - } - else { - LOG.info("Failed to get ID of: " + o.toString() + "!"); - } - } - } catch (NullPointerException e) { - LOG.info("Failed to get ID of: " + o.toString() + "!"); - } - - try { - Optional versionIRI = o.getOntologyID().getVersionIRI(); - if (versionIRI.isPresent()){ - ont_version = versionIRI.get().toString(); - Pattern p = Pattern.compile("(\\d{4}-\\d{2}-\\d{2})"); - Matcher m = p.matcher(ont_version); - m.find(); - ont_version = m.group(0); - //ont_version = StringUtils.substringBetween(ont_version, "releases/", "/"); - } - else { - ont_version = null; - } - if( ont_version == null || ont_version.equals("") ){ - // Sane fallback. - LOG.info("Failed to extract version of: " + ont_id + "!"); + try { + FlexSolrDocumentLoader loader; + if (url.equals("mock")) { + loader = new MockFlexSolrDocumentLoader(flex); + isMock = true; + } + else { + loader = new FlexSolrDocumentLoader(url, flex); + } + + LOG.info("Trying ontology flex load."); + loader.load(); + + // number of docs loaded MUST be equal to or higher than minClasses + // (docs also comprises non-class documents, e.g. ObjectProperties) + if (loader.getCurrentDocNumber() < minClasses) { + LOG.error("Fewer documents loaded than expected: "+loader.getCurrentDocNumber()+" < "+minClasses); + exit(1); + } + + // Load likely successful--log it. + //optionallyLogLoad("ontology", ???); + // TODO: Well, this is a lame second best. + //for( OWLOntology o : g.getAllOntologies() ){ + for( OWLOntology o : g.getManager().getOntologies() ){ + + //optionallyLogLoad("ontology", o.getOntologyID().toString()); + // This is "correct", but I'm only getting one. + String ont_id = "unknown"; + String ont_version = "unknown"; + try { + if (o.getOntologyID() != null) { + Optional optional = o.getOntologyID().getOntologyIRI(); + if (optional.isPresent()) { + ont_id = optional.get().toString(); + } + else { + LOG.info("Failed to get ID of: " + o.toString() + "!"); + } + } + } catch (NullPointerException e) { + LOG.info("Failed to get ID of: " + o.toString() + "!"); + } + + try { + Optional versionIRI = o.getOntologyID().getVersionIRI(); + if (versionIRI.isPresent()){ + ont_version = versionIRI.get().toString(); + Pattern p = Pattern.compile("(\\d{4}-\\d{2}-\\d{2})"); + Matcher m = p.matcher(ont_version); + m.find(); + ont_version = m.group(0); + //ont_version = StringUtils.substringBetween(ont_version, "releases/", "/"); + } + else { + ont_version = null; + } + if( ont_version == null || ont_version.equals("") ){ + // Sane fallback. + LOG.info("Failed to extract version of: " + ont_id + "!"); + } + } catch (NullPointerException e) { + LOG.info("Failed to get version of: " + ont_id + "!"); + } catch (IllegalStateException e) { + LOG.info("Failed to get match for version of: " + ont_id + "!"); + } + optionallyLogLoad("ontology", ont_id, ont_version); + + if (isMock) { + showMockDocs((MockSolrDocumentLoader) loader); } - } catch (NullPointerException e) { - LOG.info("Failed to get version of: " + ont_id + "!"); - } catch (IllegalStateException e) { - LOG.info("Failed to get match for version of: " + ont_id + "!"); - } - optionallyLogLoad("ontology", ont_id, ont_version); - - if (isMock) { - showMockDocs((MockSolrDocumentLoader) loader); - } + } + } catch (SolrServerException e) { + LOG.info("Ontology load at: " + url + " failed!"); + e.printStackTrace(); } - } @@ -404,9 +412,14 @@ public void generalLoadOntologySolr(Opts opts) throws Exception { String url = sortOutSolrURL(globalSolrURL); // Actual ontology class loading. - OntologyGeneralSolrDocumentLoader loader = new OntologyGeneralSolrDocumentLoader(url, g); - LOG.info("Trying ontology general load."); - loader.load(); + try { + OntologyGeneralSolrDocumentLoader loader = new OntologyGeneralSolrDocumentLoader(url, g); + LOG.info("Trying ontology general load."); + loader.load(); + } catch (SolrServerException e) { + LOG.info("Ontology load at: " + url + " failed!"); + e.printStackTrace(); + } } /** @@ -507,9 +520,7 @@ public void loadModelAnnotations(Opts opts) throws Exception { Set modelStateFilter = null; boolean removeDeprecatedModels = false; boolean removeTemplateModels = false; - boolean removeUnsatisfiableModels = false; - boolean exitIfUnsatisfiable = true; - boolean exitIfLoadFails = true; + boolean removeUnsatisfiableModels = false; while (opts.hasOpts()) { if (opts.nextEq("--defaultModelStateFilter|--productionModelStateFilter")) { if(modelStateFilter != null) { @@ -539,14 +550,9 @@ else if (opts.nextEq("--includeTemplateModels|--includeTemplate")) { else if (opts.nextEq("--excludeUnsatisfiableModels|--excludeUnsatisfiable")) { removeUnsatisfiableModels = true; } - else if (opts.nextEq("--includeUnsatisfiableModels|--includeUnsatisfiable")) { - removeUnsatisfiableModels = false; - exitIfUnsatisfiable = false; - } - else if (opts.nextEq("--noExitIfLoadFails")) { - opts.info("", "carry on if fail to load any individual model fails. Default is fail fast"); - exitIfLoadFails = false; - } + else if (opts.nextEq("--includeUnsatisfiableModels|--includeUnsatisfiable")) { + removeUnsatisfiableModels = false; + } else break; @@ -555,15 +561,13 @@ else if (opts.nextEq("--noExitIfLoadFails")) { // Check to see if the global url has been set. String url = sortOutSolrURL(globalSolrURL); - // Ensure that legoCatalogs is defined, even is empty. - if( legoCatalogs == null ){ - legoCatalogs = new ArrayList(); - LOG.warn("Missing lego catalogs..."); - } - // Only proceed if our environment was well-defined. - if( legoFiles == null || legoModelPrefix == null || legoFiles.isEmpty() ){ + if( legoCatalogs == null || legoFiles == null || legoModelPrefix == null || + legoCatalogs.isEmpty() || legoFiles.isEmpty() ){ String details = ""; + if (legoCatalogs == null || legoCatalogs.isEmpty()) { + details += "Missing catalog"; + } if (legoFiles == null || legoFiles.isEmpty()) { details += " Missing legoFiles"; } @@ -573,10 +577,10 @@ else if (opts.nextEq("--noExitIfLoadFails")) { LOG.error("Lego environment not well defined--skipping: "+details); exit(-1); }else{ - LOG.warn("Start Loading models, count: "+legoFiles.size()); + LOG.info("Start Loading models, count: "+legoFiles.size()); // Ready the environment for every pass. ParserWrapper pw = new ParserWrapper(); - // Add all of the catalogs; possibly none. + // Add all of the catalogs. for( File legoCatalog : legoCatalogs ){ pw.addIRIMapper(new CatalogXmlIRIMapper(legoCatalog)); } @@ -596,7 +600,7 @@ else if (opts.nextEq("--noExitIfLoadFails")) { continue; } - // Some sanity checks--some of the generated ones are problematic. + // Some sanity checks--some of the genereated ones are problematic. currentReasoner = reasonerFactory.createReasoner(model); boolean consistent = currentReasoner.isConsistent(); if(consistent == false){ @@ -604,33 +608,22 @@ else if (opts.nextEq("--noExitIfLoadFails")) { LOG.warn("Skip since inconsistent: " + fname); continue; } + Set unsatisfiable = currentReasoner.getUnsatisfiableClasses().getEntitiesMinusBottom(); + if (removeUnsatisfiableModels && unsatisfiable.isEmpty() == false) { + LOG.warn("Skip since unsatisfiable: " + fname); + continue; + } ModelAnnotationSolrDocumentLoader loader = null; try { LOG.info("Trying complex annotation load of: " + fname); - boolean isMock = false; String modelUrl = legoModelPrefix + fname; - if (url.equals("mock")) { - loader = new MockModelAnnotationSolrDocumentLoader(url, model, currentReasoner, modelUrl, - modelStateFilter, removeDeprecatedModels, removeTemplateModels); - isMock = true; - } - else { - loader = new ModelAnnotationSolrDocumentLoader(url, model, currentReasoner, modelUrl, - modelStateFilter, removeDeprecatedModels, removeTemplateModels); - } - + loader = new ModelAnnotationSolrDocumentLoader(url, model, currentReasoner, modelUrl, + modelStateFilter, removeDeprecatedModels, removeTemplateModels); loader.load(); - if (isMock) { - showMockDocs((MockModelAnnotationSolrDocumentLoader) loader); - } - } catch (SolrServerException e) { LOG.info("Complex annotation load of " + fname + " at " + url + " failed!"); e.printStackTrace(); - if (exitIfLoadFails) { - System.exit(1); - } } finally { IOUtils.closeQuietly(loader); @@ -725,8 +718,6 @@ public void experimentalLoadComplexAnnotationSolr(Opts opts) throws Exception { continue; } Set unsatisfiable = currentReasoner.getUnsatisfiableClasses().getEntitiesMinusBottom(); - - // TODO - make configurable to allow fail fast if (unsatisfiable.isEmpty() == false) { LOG.info("Skip since unsatisfiable: " + fname); continue; @@ -743,7 +734,6 @@ public void experimentalLoadComplexAnnotationSolr(Opts opts) throws Exception { } catch (SolrServerException e) { LOG.info("Complex annotation load of " + fname + " at " + url + " failed!"); e.printStackTrace(); - System.exit(1); } } finally { // Cleanup reasoner and ontology. @@ -820,7 +810,6 @@ public void loadComplexAnnotationSolr(Opts opts) throws Exception { } catch (SolrServerException e) { LOG.info("Complex annotation load of " + fname + " at " + url + " failed!"); e.printStackTrace(); - System.exit(1); } } finally { // Cleanup reasoner and ontology. @@ -1017,27 +1006,27 @@ public void loadPANTHERGeneralSolr(Opts opts) throws Exception { * @param opts * @throws Exception */ -// @CLIMethod("--solr-load-gpads") -// public void loadGPADsSolr(Opts opts) throws Exception { -// // Check to see if the global url has been set. -// //String url = sortOutSolrURL(globalSolrURL); -// -// List files = opts.nextList(); -// if( files.size() % 2 != 0 ){ -// System.err.println("GPAD format comes in pairs; skipping..."); -// }else{ -// while( ! files.isEmpty() ){ -// String car = files.remove(0); -// String cdr = files.remove(0); -// LOG.info("Parsing GPAD car: " + car); -// LOG.info("Parsing GPAD cdr: " + cdr); -// // TODO: a new buildDocument that takes the two GPAD arguments. -// //GafObjectsBuilder builder = new GafObjectsBuilder(); -// //gafdoc = builder.buildDocument(car, cdr); -// //loadGAFDoc(url, gafdoc); -// } -// } -// } + @CLIMethod("--solr-load-gpads") + public void loadGPADsSolr(Opts opts) throws Exception { + // Check to see if the global url has been set. + //String url = sortOutSolrURL(globalSolrURL); + + List files = opts.nextList(); + if( files.size() % 2 != 0 ){ + System.err.println("GPAD format comes in pairs; skipping..."); + }else{ + while( ! files.isEmpty() ){ + String car = files.remove(0); + String cdr = files.remove(0); + LOG.info("Parsing GPAD car: " + car); + LOG.info("Parsing GPAD cdr: " + cdr); + // TODO: a new buildDocument that takes the two GPAD arguments. + //GafObjectsBuilder builder = new GafObjectsBuilder(); + //gafdoc = builder.buildDocument(car, cdr); + //loadGAFDoc(url, gafdoc); + } + } + } /** * Used for applying the panther trees to the currently data run. @@ -1219,7 +1208,7 @@ private void optionallyLogLoad(String type, String uri, String version){ /* * Wrapper multiple places where there is direct GAF loading. */ - private void loadGAFDoc(String url, GafDocument gafdoc, EcoTools eco, TaxonTools taxo, PANTHERForest pset, String taxonSubsetName, String ecoSubsetName) throws IOException, SolrServerException{ + private void loadGAFDoc(String url, GafDocument gafdoc, EcoTools eco, TaxonTools taxo, PANTHERForest pset, String taxonSubsetName, String ecoSubsetName) throws IOException{ // Seth's head explodes with non-end return! // TODO: Ask Chris if there is any reason to have null on empty GAFs. @@ -1246,9 +1235,20 @@ private void loadGAFDoc(String url, GafDocument gafdoc, EcoTools eco, TaxonTools loader.setTaxonSubsetName(taxonSubsetName); loader.setEcoSubsetName(ecoSubsetName); loader.setGraph(g); - LOG.info("Loading server at: " + url + " with: " + gafdoc.getDocumentPath()); - loader.load(); - + try { + LOG.info("Loading server at: " + url + " with: " + gafdoc.getDocumentPath()); + loader.load(); + } catch (java.lang.NullPointerException e) { // can trigger when the GAF is empty + LOG.warn("Huh...some null pointer exception...good luck! At: " + url + ", " + gafdoc.getDocumentPath()); + //LOG.warn("Message: " + e.getMessage()); + e.printStackTrace(); + } catch (SolrException e) { // can trigger when there is more than one PANTHER tree + LOG.warn("Possible PANTHER error: " + url + " with: " + e.toString()); + e.printStackTrace(); + } catch (SolrServerException e) { + LOG.warn("Something has gone south with Solr: " + url); + e.printStackTrace(); + } if (isMock) { showMockDocs((MockSolrDocumentLoader) loader); } diff --git a/OWLTools-Runner/src/main/resources/log4j.properties b/OWLTools-Runner/src/main/resources/log4j.properties index ee5b40306..6866096ec 100644 --- a/OWLTools-Runner/src/main/resources/log4j.properties +++ b/OWLTools-Runner/src/main/resources/log4j.properties @@ -6,5 +6,5 @@ log4j.logger.owltools.graph.OWLGraphWrapperEdges=ERROR log4j.logger.org.obolibrary.obo2owl=OFF log4j.logger.org.semanticweb.owlapi=error -log4j.rootLogger=WARN, console +log4j.rootLogger=INFO, console diff --git a/OWLTools-Runner/src/test/java/owltools/cli/CommandRunnerMergeEquivSetTest.java b/OWLTools-Runner/src/test/java/owltools/cli/CommandRunnerMergeEquivSetTest.java index 6dda54a61..5ef54e901 100644 --- a/OWLTools-Runner/src/test/java/owltools/cli/CommandRunnerMergeEquivSetTest.java +++ b/OWLTools-Runner/src/test/java/owltools/cli/CommandRunnerMergeEquivSetTest.java @@ -1,11 +1,7 @@ package owltools.cli; -import static org.junit.Assert.*; - import org.junit.Test; -import owltools.mooncat.IncoherentOntologyException; - /** * Tests for {@link CommandRunner}. * @@ -50,57 +46,4 @@ public void testMergeEquivalentIndividuals() throws Exception { } - /** - * Test -P option of MES - * - * This is intended for when we want to prevent merges - * of classes from some ontologies - * - * @throws Exception - */ - @Test - public void testPreserve() throws Exception { - load("merge-equiv-test.obo"); - - boolean ok = false; - run("--reasoner elk"); - // note: ID space is actually "U" in file - try { - run("--merge-equivalence-sets -P ZZ -s ZZ 0 -s MA 10 -s UBERON 5 -s FMA 1"); - run("-o -f obo --no-check target/equiv-set-merged-preserve.obo"); - } - catch (IncoherentOntologyException e) { - // we expect this - ok = true; - } - assertTrue(ok); - - } - - @Test - public void testMergeEquivalentPreserveProvenance() throws Exception { - load("merge-equiv-test.obo"); - - run("--add-xref-axiom-annotations -l"); - run("--reasoner elk"); - // note: ID space is actually "U" in file - run("--merge-equivalence-sets -s MA 1 -s FMA 2 -s U 3 -s HP 1 -s MP 2"); - run("--merge-axiom-annotations"); - run("--interpret-xrefs"); - run("-o -f obo --no-check target/equiv-set-merged-xrefs.obo"); - - } - - @Test - public void testObsoleteReplace() throws Exception { - load("merge-equiv-test.obo"); - - run("--obsolete-replace FMA:1 U:1"); - run("-o -f obo --no-check target/obs-repl.obo"); - - } - - - - } diff --git a/OWLTools-Runner/src/test/resources/merge-equiv-test.obo b/OWLTools-Runner/src/test/resources/merge-equiv-test.obo index dce6ebdb9..3b34bc511 100644 --- a/OWLTools-Runner/src/test/resources/merge-equiv-test.obo +++ b/OWLTools-Runner/src/test/resources/merge-equiv-test.obo @@ -5,7 +5,6 @@ def: "test mp1" [] synonym: "mp syn1" EXACT [] synonym: "mp syn2" EXACT [MP:MP] comment: comment mp1 -is_a: MP:2 intersection_of: PATO:1 intersection_of: r MA:1 @@ -15,7 +14,6 @@ name: hp1 def: "test hp1" [] synonym: "hp syn2" EXACT [HP:HP] comment: comment hp1 -is_a: HP:2 intersection_of: PATO:1 intersection_of: r FMA:1 @@ -25,7 +23,6 @@ name: ma1 comment: ma1 comment synonym: "ma1 syn1" EXACT [] synonym: "ma1 syn2" EXACT [] -is_a: MA:0 [Term] id: FMA:1 @@ -34,7 +31,6 @@ comment: fma1 comment def: "fma1 def" [FMA:FMA] synonym: "fma1 syn1" EXACT [] synonym: "fma1 syn2" EXACT [] -is_a: FMA:0 [Term] id: U:1 @@ -42,38 +38,6 @@ name: u1 def: "u1 def" [U:U] equivalent_to: FMA:1 equivalent_to: MA:1 -is_a: U:0 - -[Term] -id: MA:0 -name: ma0 -comment: ma0 comment -synonym: "ma0 syn1" EXACT [] -synonym: "ma0 syn2" EXACT [] - -[Term] -id: FMA:0 -name: fma0 -comment: fma0 comment -def: "fma0 def" [FMA:FMA] -synonym: "fma0 syn1" EXACT [] -synonym: "fma0 syn2" EXACT [] - -[Term] -id: U:0 -name: u0 -def: "u0 def" [U:U] -equivalent_to: MA:0 -equivalent_to: FMA:0 - -[Term] -id: ZZ:1 -name: zz1 - -[Term] -id: ZZ:2 -name: zz2 -equivalent_to: ZZ:1 diff --git a/OWLTools-Solr/pom.xml b/OWLTools-Solr/pom.xml index 920f0b536..cafebf988 100644 --- a/OWLTools-Solr/pom.xml +++ b/OWLTools-Solr/pom.xml @@ -33,7 +33,7 @@ solr-solrj org.apache.solr - 3.6.0 + 6.5.0 slf4j-api diff --git a/OWLTools-Solr/src/main/java/owltools/solrj/AbstractSolrLoader.java b/OWLTools-Solr/src/main/java/owltools/solrj/AbstractSolrLoader.java index d69321809..36534f7f1 100644 --- a/OWLTools-Solr/src/main/java/owltools/solrj/AbstractSolrLoader.java +++ b/OWLTools-Solr/src/main/java/owltools/solrj/AbstractSolrLoader.java @@ -8,9 +8,9 @@ import org.apache.log4j.Logger; -import org.apache.solr.client.solrj.SolrServer; +import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrServerException; -import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer; +import org.apache.solr.client.solrj.impl.HttpSolrClient; import org.apache.solr.common.SolrInputDocument; import org.semanticweb.owlapi.model.OWLObject; @@ -29,7 +29,9 @@ public abstract class AbstractSolrLoader { private static Logger LOG = Logger.getLogger(AbstractSolrLoader.class); - protected SolrServer server; + // note: SolrServer was deprecated and finally removed in solr6. + // we replace the class usage TODO - change variable name + protected SolrClient server; private Collection docs = new ArrayList(); @@ -47,7 +49,7 @@ public void setGraph(OWLGraphWrapper graph) { this.graph = graph; } - public AbstractSolrLoader(SolrServer server) { + public AbstractSolrLoader(SolrClient server) { super(); this.server = server; } @@ -57,9 +59,10 @@ public AbstractSolrLoader(String url) throws MalformedURLException { } - public static final SolrServer createDefaultServer(String url) throws MalformedURLException { + public static final SolrClient createDefaultServer(String url) throws MalformedURLException { LOG.info("Server at: " + url); - return new CommonsHttpSolrServer(url); + // TODO: https://mycore.atlassian.net/browse/DBT-77 use HttpSolrClient.Builder + return new HttpSolrClient(url); } /** diff --git a/OWLTools-Solr/src/main/java/owltools/solrj/FlexSolrDocumentLoader.java b/OWLTools-Solr/src/main/java/owltools/solrj/FlexSolrDocumentLoader.java index 514ae71ae..9457e9cb9 100644 --- a/OWLTools-Solr/src/main/java/owltools/solrj/FlexSolrDocumentLoader.java +++ b/OWLTools-Solr/src/main/java/owltools/solrj/FlexSolrDocumentLoader.java @@ -4,7 +4,7 @@ import java.net.MalformedURLException; import org.apache.log4j.Logger; -import org.apache.solr.client.solrj.SolrServer; +import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.common.SolrInputDocument; @@ -29,7 +29,7 @@ public FlexSolrDocumentLoader(String url, FlexCollection c) throws MalformedURLE current_doc_number = 0; } - protected FlexSolrDocumentLoader(SolrServer server, FlexCollection c) { + protected FlexSolrDocumentLoader(SolrClient server, FlexCollection c) { super(server); collection = c; current_doc_number = 0; diff --git a/OWLTools-Solr/src/main/java/owltools/solrj/GafSolrDocumentLoader.java b/OWLTools-Solr/src/main/java/owltools/solrj/GafSolrDocumentLoader.java index 8a8021410..8713d9d7a 100644 --- a/OWLTools-Solr/src/main/java/owltools/solrj/GafSolrDocumentLoader.java +++ b/OWLTools-Solr/src/main/java/owltools/solrj/GafSolrDocumentLoader.java @@ -14,7 +14,7 @@ import org.apache.commons.codec.binary.Hex; import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; -import org.apache.solr.client.solrj.SolrServer; +import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.common.SolrInputDocument; import org.semanticweb.owlapi.model.OWLClass; @@ -65,7 +65,7 @@ public GafSolrDocumentLoader(String url) throws MalformedURLException { * @param server * @param triggerLimit */ - protected GafSolrDocumentLoader(SolrServer server, int triggerLimit) { + protected GafSolrDocumentLoader(SolrClient server, int triggerLimit) { super(server); this.doc_limit_trigger = triggerLimit; } diff --git a/OWLTools-Solr/src/main/java/owltools/solrj/ModelAnnotationSolrDocumentLoader.java b/OWLTools-Solr/src/main/java/owltools/solrj/ModelAnnotationSolrDocumentLoader.java index e1eb3d9a0..396cd0ef3 100644 --- a/OWLTools-Solr/src/main/java/owltools/solrj/ModelAnnotationSolrDocumentLoader.java +++ b/OWLTools-Solr/src/main/java/owltools/solrj/ModelAnnotationSolrDocumentLoader.java @@ -13,7 +13,7 @@ import org.apache.commons.lang3.tuple.Pair; import org.apache.log4j.Logger; -import org.apache.solr.client.solrj.SolrServer; +import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.common.SolrInputDocument; import org.obolibrary.obo2owl.Obo2OWLConstants; @@ -92,7 +92,7 @@ public ModelAnnotationSolrDocumentLoader(String golrUrl, OWLOntology model, OWLR this(createDefaultServer(golrUrl), model, r, modelUrl, modelFilter, skipDeprecatedModels, skipTemplateModels); } - public ModelAnnotationSolrDocumentLoader(SolrServer server, OWLOntology model, OWLReasoner r, String modelUrl, + public ModelAnnotationSolrDocumentLoader(SolrClient server, OWLOntology model, OWLReasoner r, String modelUrl, Set modelFilter, boolean skipDeprecatedModels, boolean skipTemplateModels) { super(server); this.model = model; @@ -153,10 +153,6 @@ static Set getAspect(OWLGraphWrapper graph, String aspect) { @Override public void close() throws IOException { graph.close(); - if (reasoner != null) { - reasoner.dispose(); - } - } @Override 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..95933fc47 100644 --- a/OWLTools-Solr/src/main/java/owltools/solrj/loader/MockFlexSolrDocumentLoader.java +++ b/OWLTools-Solr/src/main/java/owltools/solrj/loader/MockFlexSolrDocumentLoader.java @@ -2,8 +2,9 @@ import java.net.MalformedURLException; -import org.apache.solr.client.solrj.SolrServer; import org.apache.solr.common.SolrInputDocument; +import org.apache.solr.client.solrj.SolrClient; + import owltools.flex.FlexCollection; import owltools.solrj.FlexSolrDocumentLoader; @@ -11,7 +12,7 @@ public class MockFlexSolrDocumentLoader extends FlexSolrDocumentLoader implements MockSolrDocumentLoader { public MockFlexSolrDocumentLoader(FlexCollection c) throws MalformedURLException { - super((SolrServer)null, c); + super((SolrClient)null, c); } final MockSolrDocumentCollection documentCollection = new MockSolrDocumentCollection(); diff --git a/OWLTools-Solr/src/main/java/owltools/solrj/loader/MockModelAnnotationSolrDocumentLoader.java b/OWLTools-Solr/src/main/java/owltools/solrj/loader/MockModelAnnotationSolrDocumentLoader.java deleted file mode 100644 index 7916f9dce..000000000 --- a/OWLTools-Solr/src/main/java/owltools/solrj/loader/MockModelAnnotationSolrDocumentLoader.java +++ /dev/null @@ -1,48 +0,0 @@ -package owltools.solrj.loader; - -import java.net.MalformedURLException; -import java.util.Set; - -import org.apache.solr.client.solrj.SolrServer; -import org.apache.solr.common.SolrInputDocument; -import org.semanticweb.owlapi.model.OWLOntology; -import org.semanticweb.owlapi.reasoner.OWLReasoner; - -import owltools.solrj.ModelAnnotationSolrDocumentLoader; - -public class MockModelAnnotationSolrDocumentLoader extends ModelAnnotationSolrDocumentLoader implements MockSolrDocumentLoader { - - - public MockModelAnnotationSolrDocumentLoader(SolrServer server, - OWLOntology model, OWLReasoner r, String modelUrl, - Set modelFilter, boolean skipDeprecatedModels, - boolean skipTemplateModels) { - super(server, model, r, modelUrl, modelFilter, skipDeprecatedModels, - skipTemplateModels); - // TODO Auto-generated constructor stub - } - - public MockModelAnnotationSolrDocumentLoader(String golrUrl, - OWLOntology model, OWLReasoner r, String modelUrl, - Set modelFilter, boolean skipDeprecatedModels, - boolean skipTemplateModels) throws MalformedURLException { - super((SolrServer)null, model, r, modelUrl, modelFilter, skipDeprecatedModels, - skipTemplateModels); - // TODO Auto-generated constructor stub - } - - final MockSolrDocumentCollection documentCollection = new MockSolrDocumentCollection(); - @Override - public void add(SolrInputDocument doc) { - documentCollection.add(doc); - } - - /** - * @return the result - */ - public MockSolrDocumentCollection getDocumentCollection() { - return documentCollection; - } - - -} diff --git a/OWLTools-Solr/src/test/java/owltools/solrj/AllOntologyLoaderIntegrationRunner.java b/OWLTools-Solr/src/test/java/owltools/solrj/AllOntologyLoaderIntegrationRunner.java index d00231f90..a9d056630 100644 --- a/OWLTools-Solr/src/test/java/owltools/solrj/AllOntologyLoaderIntegrationRunner.java +++ b/OWLTools-Solr/src/test/java/owltools/solrj/AllOntologyLoaderIntegrationRunner.java @@ -7,7 +7,7 @@ import java.util.Properties; import org.apache.commons.lang3.time.StopWatch; -import org.apache.solr.client.solrj.SolrServer; +import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.common.SolrInputDocument; import org.junit.AfterClass; @@ -101,7 +101,7 @@ public void testLoadAllOntologies() throws Exception { StopWatch watch = new StopWatch(); watch.start(); - FlexSolrDocumentLoader loader = new FlexSolrDocumentLoader((SolrServer)null, c) { + FlexSolrDocumentLoader loader = new FlexSolrDocumentLoader((SolrClient)null, c) { @Override protected void addToServer(Collection docs) diff --git a/OWLTools-Solr/src/test/java/owltools/solrj/FullTaxonIntegrationRunner.java b/OWLTools-Solr/src/test/java/owltools/solrj/FullTaxonIntegrationRunner.java index e0779fbbe..3767ff700 100644 --- a/OWLTools-Solr/src/test/java/owltools/solrj/FullTaxonIntegrationRunner.java +++ b/OWLTools-Solr/src/test/java/owltools/solrj/FullTaxonIntegrationRunner.java @@ -6,7 +6,7 @@ import java.util.Collection; import java.util.Properties; -import org.apache.solr.client.solrj.SolrServer; +import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.common.SolrInputDocument; import org.junit.AfterClass; @@ -58,7 +58,7 @@ public void testLoadFullTaxon() throws Exception { GafSolrDocumentLoaderIntegrationRunner.gc(); GafSolrDocumentLoaderIntegrationRunner.printMemoryStats(); - FlexSolrDocumentLoader loader = new FlexSolrDocumentLoader((SolrServer)null, c) { + FlexSolrDocumentLoader loader = new FlexSolrDocumentLoader((SolrClient)null, c) { @Override protected void addToServer(Collection docs) diff --git a/OWLTools-Solr/src/test/java/owltools/solrj/GoLoaderIntegrationRunner.java b/OWLTools-Solr/src/test/java/owltools/solrj/GoLoaderIntegrationRunner.java index 997c3b36d..4d845c9c0 100644 --- a/OWLTools-Solr/src/test/java/owltools/solrj/GoLoaderIntegrationRunner.java +++ b/OWLTools-Solr/src/test/java/owltools/solrj/GoLoaderIntegrationRunner.java @@ -7,7 +7,7 @@ import java.util.Properties; import org.apache.commons.lang3.time.StopWatch; -import org.apache.solr.client.solrj.SolrServer; +import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.common.SolrInputDocument; import org.junit.AfterClass; @@ -64,7 +64,7 @@ public void testLoadGoTaxon() throws Exception { GafSolrDocumentLoaderIntegrationRunner.gc(); GafSolrDocumentLoaderIntegrationRunner.printMemoryStats(); - FlexSolrDocumentLoader loader = new FlexSolrDocumentLoader((SolrServer)null, c) { + FlexSolrDocumentLoader loader = new FlexSolrDocumentLoader((SolrClient)null, c) { @Override protected void addToServer(Collection docs) diff --git a/OWLTools-Solr/src/test/java/owltools/solrj/OntologyAndGafLoaderIntegrationRunner.java b/OWLTools-Solr/src/test/java/owltools/solrj/OntologyAndGafLoaderIntegrationRunner.java index 24bea1934..a03661f9b 100644 --- a/OWLTools-Solr/src/test/java/owltools/solrj/OntologyAndGafLoaderIntegrationRunner.java +++ b/OWLTools-Solr/src/test/java/owltools/solrj/OntologyAndGafLoaderIntegrationRunner.java @@ -8,7 +8,7 @@ import java.util.Properties; import org.apache.commons.lang3.time.StopWatch; -import org.apache.solr.client.solrj.SolrServer; +import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.common.SolrInputDocument; import org.junit.AfterClass; @@ -122,7 +122,7 @@ public void testLoadOntologiesAndGaf() throws Exception { final StopWatch ontologyWatch = new StopWatch(); ontologyWatch.start(); - final FlexSolrDocumentLoader ontologyLoader = new FlexSolrDocumentLoader((SolrServer)null, c) { + final FlexSolrDocumentLoader ontologyLoader = new FlexSolrDocumentLoader((SolrClient)null, c) { @Override protected void addToServer(Collection docs) diff --git a/README.md b/README.md index 90cc3c6b8..f7815473e 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,16 @@ [![Build Status](https://travis-ci.org/owlcollab/owltools.svg?branch=master)](https://travis-ci.org/owlcollab/owltools) [![DOI](https://zenodo.org/badge/13996/owlcollab/owltools.svg)](https://zenodo.org/badge/latestdoi/13996/owlcollab/owltools) -For full documentation, +For full documentation, * [see the Wiki](https://github.com/owlcollab/owltools/wiki). * [see the java API docs](https://owlcollab.github.io/owltools) ## OWLTools Build Instructions -The OWLTools use maven as a build tool. +The OWLTools use maven as a build tool. -These instructions assume that a valid maven installation is available. The recommended maven version is 3.0.x, whereby x denotes the latest release for this branch. +These instructions assume that a valid maven installation is available. The recommended maven version is 3.0.x, whereby x denotes the latest release for this branch. Update: OWLTools also requires `git`. Only a proper clone via git, will allow the build to complete. @@ -28,38 +28,21 @@ During the build process, we extract the git version and branch information. The 2a) Run command: `mvn clean install`: This will trigger a complete build of all OWLTools projects and generate the required jars for execution. Remark: As part of the build the tests are executed. Any failed test will stop the build. -2b) Build without test execution (Not Recommended): Run command: mvn clean install -DskipTests - +2b) Build without test execution (Not Recommended): Run command: mvn clean install -Dmaven.test.skip.exec=true + #### Option 2: Eclipse -Requires either: +Requires either: * Eclipse 3.7 * Eclipse 3.6 with installed maven plugin m2e Use the provided Eclipse launch configurations to trigger the build. The configuration are located in the `OWLTools-Parent/eclipse-configs` folder. -## Downloading OWLTools - -This option uses a pre-built JAR and script-wrapper instead of building owltools from the Java source. The JAR is built as part of the continuous building and test of the OWLTools project on a Jenkins server. - -Go to http://build.berkeleybop.org/userContent/owltools/ - -Download [owltools](http://build.berkeleybop.org/userContent/owltools/owltools) - -Note: you may need to make this file executable. Occasionally when downloaded files lose the "executable" permisison. You can do this with `chmod +x owltools`. - -If you add this to your [PATH](https://en.wikipedia.org/wiki/PATH_(variable)), you can run owltools on the command line: - -``` -export PATH=$PATH:directory/to/where/you/downloaded/owltools/ -owltools -h -``` ## Running OWLTools (Unix and MacOS) Running OWLTools requires a successful build, as described in the previous section. - -+ OWLTools Command-Line Tools: The build produces a combined executable bash script and jar, to be found in `OWLTools-Runner/bin` -or in the `OWLTools-Runner/target` directory + ++ OWLTools Command-Line Tools: The executables and the generated jar are both located in `OWLTools-Runner/bin` + OORT: The executables and the generated jar are both located in `OWLTools-Oort/bin`