diff --git a/OWLTools-Core/src/main/java/owltools/graph/OWLGraphWrapperEdgesAdvanced.java b/OWLTools-Core/src/main/java/owltools/graph/OWLGraphWrapperEdgesAdvanced.java index 1751dcf37..340ab1e0a 100644 --- a/OWLTools-Core/src/main/java/owltools/graph/OWLGraphWrapperEdgesAdvanced.java +++ b/OWLTools-Core/src/main/java/owltools/graph/OWLGraphWrapperEdgesAdvanced.java @@ -680,12 +680,13 @@ else if (obj instanceof OWLObjectProperty) { } return relation_map; } - + private void addIdLabelClosure(OWLClass c, boolean reflexive, - final Set props, final Map relation_map) { + final Set props, final Map relation_map) { addPropertiesForMaterialization(props); ExpressionMaterializingReasoner materializingReasoner = getMaterializingReasoner(); Set classExpressions = materializingReasoner.getSuperClassExpressions(c, false); + OWLEntity owlThing = this.getManager().getOWLDataFactory().getOWLThing(); // remove owl:Thing - although logically valid, it is not of use to the consumer diff --git a/OWLTools-Core/src/main/java/owltools/graph/OWLGraphWrapperExtended.java b/OWLTools-Core/src/main/java/owltools/graph/OWLGraphWrapperExtended.java index 403b79bb5..94889cce7 100644 --- a/OWLTools-Core/src/main/java/owltools/graph/OWLGraphWrapperExtended.java +++ b/OWLTools-Core/src/main/java/owltools/graph/OWLGraphWrapperExtended.java @@ -221,6 +221,7 @@ public String getAnnotationValue(OWLObject c, OWLAnnotationProperty lap) { else { return null; } + for (OWLAnnotation a : anns) { if (a.getValue() instanceof OWLLiteral) { OWLLiteral val = (OWLLiteral) a.getValue(); @@ -623,7 +624,6 @@ public OWLAnnotationProperty getAnnotationProperty(String tag){ */ public String getNamespace(OWLObject c) { OWLAnnotationProperty lap = getAnnotationProperty(OboFormatTag.TAG_NAMESPACE.getTag()); - return getAnnotationValue(c, lap); } @@ -933,7 +933,7 @@ public String getIdentifier(IRI iriId) { } // In the case where the input class does not have oboInOwl#id, we return its original URL. - LOG.warn("Unable to retrieve the value of oboInOw#id as the identifier for " + iriId + "; we will use an original iri as the identifier."); + // LOG.warn("Unable to retrieve the value of oboInOw#id as the identifier for " + iriId + "; we will use an original iri as the identifier."); return (String) SerializationUtils.clone(iriId.toString()); } diff --git a/OWLTools-Core/src/test/java/owltools/graph/OWLGraphWrapperExtendedTest.java b/OWLTools-Core/src/test/java/owltools/graph/OWLGraphWrapperExtendedTest.java index d4107732d..7b1dc62b6 100644 --- a/OWLTools-Core/src/test/java/owltools/graph/OWLGraphWrapperExtendedTest.java +++ b/OWLTools-Core/src/test/java/owltools/graph/OWLGraphWrapperExtendedTest.java @@ -44,6 +44,7 @@ public void testGetIdentifier() throws Exception { String id2 = wrapper.getIdentifier(IRI.create("http://purl.obolibrary.org/obo/GO_0000002")); String id3 = wrapper.getIdentifier(IRI.create("http://example.com/X_005")); String id4 = wrapper.getIdentifier(IRI.create("http://example.com/X_010")); + String id5 = wrapper.getIdentifier(IRI.create("http://purl.obolibrary.org/obo/GR_protein_Q6K4D1")); assertEquals(id1, "GO:0000001"); assertEquals(id2, "GO:0000002"); diff --git a/OWLTools-Runner/.settings/org.eclipse.jdt.core.prefs b/OWLTools-Runner/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 714351aec..000000000 --- a/OWLTools-Runner/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,5 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 -org.eclipse.jdt.core.compiler.compliance=1.8 -org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.source=1.8 diff --git a/OWLTools-Runner/src/main/java/owltools/cli/SolrCommandRunner.java b/OWLTools-Runner/src/main/java/owltools/cli/SolrCommandRunner.java index b032b2c6d..fceca405a 100644 --- a/OWLTools-Runner/src/main/java/owltools/cli/SolrCommandRunner.java +++ b/OWLTools-Runner/src/main/java/owltools/cli/SolrCommandRunner.java @@ -593,8 +593,6 @@ private void loadEachModelAnnotation(ParserWrapper pwr, File legoFile, String ur boolean exitIfUnsatisfiable, boolean exitIfLoadFails) throws IOException { String fname = legoFile.getName(); OWLReasoner currentReasoner = null; - OWLOntologyManager manager = pwr.getManager(); - OWLOntology model = null; ModelAnnotationSolrDocumentLoader loader = null; @@ -609,20 +607,24 @@ private void loadEachModelAnnotation(ParserWrapper pwr, File legoFile, String ur } /** - * DEEP-COPIES OWLOntology instance. + * DEEP-COPIES ALL OWLOntology instances in the manager of the model. * Note that most serialization libraries such as Kryo or Cloner DO NOT work for * copying OWLOntology or reasoner instance. In other words, deep-copying ontology * should be done via "copyOntology" method. This allows preventing memory leaks, i.e., * running reasoners affects the model (OWLOntology instance) but the changes only happen * over copied instance, which can be safely disposed without blowing out of memory. + * See also: https://github.com/owlcollab/owltools/issues/253#issuecomment-388415035 */ OWLOntologyManager tempOWLManager = OWLManager.createOWLOntologyManager(); - OWLOntology tModel = tempOWLManager.copyOntology(model, OntologyCopy.DEEP); + for(OWLOntology o: model.getOWLOntologyManager().getOntologies()) + tempOWLManager.copyOntology(o, OntologyCopy.DEEP); + + OWLOntology dcpModel = tempOWLManager.getOntology(model.getOntologyID()); // Some sanity checks--some of the generated ones are problematic. // We need a consistent ontology for the closure calculations! OWLReasonerFactory reasonerFactory = new ElkReasonerFactory(); - currentReasoner = reasonerFactory.createReasoner(tModel); + currentReasoner = reasonerFactory.createReasoner(dcpModel); boolean consistent = currentReasoner.isConsistent(); if(consistent == false){ LOG.warn("Skip since inconsistent: " + fname); @@ -634,12 +636,12 @@ private void loadEachModelAnnotation(ParserWrapper pwr, File legoFile, String ur String modelUrl = legoModelPrefix + fname; if (url.equals("mock")) { - loader = new MockModelAnnotationSolrDocumentLoader(url, tModel, currentReasoner, modelUrl, + loader = new MockModelAnnotationSolrDocumentLoader(url, dcpModel, currentReasoner, modelUrl, modelStateFilter, removeDeprecatedModels, removeTemplateModels); isMock = true; } else { - loader = new ModelAnnotationSolrDocumentLoader(url, tModel, currentReasoner, modelUrl, + loader = new ModelAnnotationSolrDocumentLoader(url, dcpModel, currentReasoner, modelUrl, modelStateFilter, removeDeprecatedModels, removeTemplateModels); } @@ -650,7 +652,7 @@ private void loadEachModelAnnotation(ParserWrapper pwr, File legoFile, String ur } currentReasoner.dispose(); - tempOWLManager.removeOntology(tModel); + tempOWLManager.removeOntology(dcpModel); } catch (Exception e) { LOG.info("Complex annotation load of " + fname + " at " + url + " failed!"); e.printStackTrace(); @@ -658,11 +660,10 @@ private void loadEachModelAnnotation(ParserWrapper pwr, File legoFile, String ur if (exitIfLoadFails) System.exit(1); } finally { - manager.removeOntology(model); if (loader != null) { + LOG.info("Finalizing the current loader..."); loader.close(); loader = null; - LOG.info("Closing the current loader..."); } } } diff --git a/OWLTools-Solr/.settings/org.eclipse.jdt.core.prefs b/OWLTools-Solr/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 714351aec..000000000 --- a/OWLTools-Solr/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,5 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 -org.eclipse.jdt.core.compiler.compliance=1.8 -org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.source=1.8 diff --git a/OWLTools-Solr/src/main/java/owltools/solrj/ModelAnnotationSolrDocumentLoader.java b/OWLTools-Solr/src/main/java/owltools/solrj/ModelAnnotationSolrDocumentLoader.java index ea416485f..9a0b0952b 100644 --- a/OWLTools-Solr/src/main/java/owltools/solrj/ModelAnnotationSolrDocumentLoader.java +++ b/OWLTools-Solr/src/main/java/owltools/solrj/ModelAnnotationSolrDocumentLoader.java @@ -87,12 +87,12 @@ public class ModelAnnotationSolrDocumentLoader extends AbstractSolrLoader implem private boolean skipDeprecatedModels; private boolean skipTemplateModels; - public ModelAnnotationSolrDocumentLoader(String golrUrl, OWLOntology model, OWLReasoner r, String modelUrl, + public ModelAnnotationSolrDocumentLoader(String golrUrl, OWLOntology model, OWLReasoner r, String modelUrl, Set modelFilter, boolean skipDeprecatedModels, boolean skipTemplateModels) throws MalformedURLException { this(createDefaultServer(golrUrl), model, r, modelUrl, modelFilter, skipDeprecatedModels, skipTemplateModels); } - - public ModelAnnotationSolrDocumentLoader(SolrServer server, OWLOntology model, OWLReasoner r, String modelUrl, + + public ModelAnnotationSolrDocumentLoader(SolrServer server, OWLOntology model, OWLReasoner r, String modelUrl, Set modelFilter, boolean skipDeprecatedModels, boolean skipTemplateModels) { super(server); this.model = model; @@ -106,12 +106,12 @@ public ModelAnnotationSolrDocumentLoader(SolrServer server, OWLOntology model, O OWLDataFactory df = graph.getDataFactory(); partOf = OBOUpperVocabulary.BFO_part_of.getObjectProperty(df); occursIn = OBOUpperVocabulary.BFO_occurs_in.getObjectProperty(df); - + defaultClosureRelations = new ArrayList(1); defaultClosureRelations.add(graph.getIdentifier(partOf)); - + enabledBy = OBOUpperVocabulary.GOREL_enabled_by.getObjectProperty(df); - + title = df.getOWLAnnotationProperty(IRI.create("http://purl.org/dc/elements/1.1/title")); source = df.getOWLAnnotationProperty(IRI.create("http://purl.org/dc/elements/1.1/source")); contributor = df.getOWLAnnotationProperty(IRI.create("http://purl.org/dc/elements/1.1/contributor")); @@ -123,29 +123,31 @@ public ModelAnnotationSolrDocumentLoader(SolrServer server, OWLOntology model, O layoutHintX = df.getOWLAnnotationProperty(IRI.create("http://geneontology.org/lego/hint/layout/x")); layoutHintY = df.getOWLAnnotationProperty(IRI.create("http://geneontology.org/lego/hint/layout/y")); templatestate = df.getOWLAnnotationProperty(IRI.create("http://geneontology.org/lego/templatestate")); - + displayLabelProp = df.getRDFSLabel(); shortIdProp = df.getOWLAnnotationProperty(IRI.create(Obo2OWLConstants.OIOVOCAB_IRI_PREFIX+"id")); - jsonProp = df.getOWLAnnotationProperty(IRI.create("http://geneontology.org/lego/json-model")); - + bpSet = getAspect(graph, "biological_process"); } - static Set getAspect(OWLGraphWrapper graph, String aspect) { + Set getAspect(OWLGraphWrapper graph, String aspect) { Set result = new HashSet(); + + // Literally computing all subclasses of the root class labeled with "biological process" + OWLClass c = model.getOWLOntologyManager().getOWLDataFactory().getOWLClass(IRI.create("http://purl.obolibrary.org/obo/GO_0008150")); + Set subClassBPSet = reasoner.getSubClasses(c, false).getFlattened(); + for(OWLClass cls : graph.getAllOWLClasses()) { - if (cls.isBuiltIn()) { + if (cls.isBuiltIn()) continue; - } + String id = graph.getIdentifier(cls); - if (id.startsWith("GO:") == false) { + if (id.startsWith("GO:") == false) continue; - } - String namespace = graph.getNamespace(cls); - if (namespace != null && namespace.equals(aspect)) { + + if (subClassBPSet.contains(cls)) result.add(cls); - } } return result; } @@ -166,7 +168,7 @@ public void close() throws IOException { public void load() throws SolrServerException, IOException { LOG.info("Loading complex annotation document..."); final OWLShuntGraph shuntGraph = createShuntGraph(graph); - + String modelId = null; String modelDate = null; String title = null; @@ -217,7 +219,7 @@ else if (p.isDeprecated()) { // fallback modelId = model.getOntologyID().getOntologyIRI().get().toString(); } - + if (requiredModelStates != null && state != null) { boolean contains = requiredModelStates.contains(state); if (contains == false) { @@ -249,6 +251,7 @@ else if (p.isDeprecated()) { final Set mfAnnotations = getAnnotations(null, mfNamed); Map>> processes = findProcesses(mfNamed); Map>> locations = findLocations(mfNamed); + for(OWLClass gpType : gpTypes) { for(OWLClass mfType : mfTypes) { if (processes.isEmpty() == false) { diff --git a/OWLTools-Solr/src/main/java/owltools/solrj/loader/MockModelAnnotationSolrDocumentLoader.java b/OWLTools-Solr/src/main/java/owltools/solrj/loader/MockModelAnnotationSolrDocumentLoader.java index 7916f9dce..adb6a8ef4 100644 --- a/OWLTools-Solr/src/main/java/owltools/solrj/loader/MockModelAnnotationSolrDocumentLoader.java +++ b/OWLTools-Solr/src/main/java/owltools/solrj/loader/MockModelAnnotationSolrDocumentLoader.java @@ -5,6 +5,7 @@ import org.apache.solr.client.solrj.SolrServer; import org.apache.solr.common.SolrInputDocument; +import org.semanticweb.owlapi.model.OWLClass; import org.semanticweb.owlapi.model.OWLOntology; import org.semanticweb.owlapi.reasoner.OWLReasoner; @@ -17,8 +18,7 @@ public MockModelAnnotationSolrDocumentLoader(SolrServer server, OWLOntology model, OWLReasoner r, String modelUrl, Set modelFilter, boolean skipDeprecatedModels, boolean skipTemplateModels) { - super(server, model, r, modelUrl, modelFilter, skipDeprecatedModels, - skipTemplateModels); + super(server, model, r, modelUrl, modelFilter, skipDeprecatedModels, skipTemplateModels); // TODO Auto-generated constructor stub } @@ -26,8 +26,7 @@ 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); + super((SolrServer)null, model, r, modelUrl, modelFilter, skipDeprecatedModels, skipTemplateModels); // TODO Auto-generated constructor stub }