From fc508e17371ce9b557809af3d01be08e4c149533 Mon Sep 17 00:00:00 2001 From: Shalsh Date: Mon, 19 Nov 2018 17:14:19 -0500 Subject: [PATCH 1/8] Rewrite query to generate expect scores --- src/getscores-genes-corpus.rq | 20 ------------------- .../sparql/get-scores.rq} | 12 +++++------ 2 files changed, 5 insertions(+), 27 deletions(-) delete mode 100644 src/getscores-genes-corpus.rq rename src/{getscores-taxa-corpus.rq => main/sparql/get-scores.rq} (55%) diff --git a/src/getscores-genes-corpus.rq b/src/getscores-genes-corpus.rq deleted file mode 100644 index 202f446..0000000 --- a/src/getscores-genes-corpus.rq +++ /dev/null @@ -1,20 +0,0 @@ -PREFIX obo: -PREFIX ps: -PREFIX rdf: -PREFIX rdfs: -PREFIX owl: -PREFIX owlet: -PREFIX dc: -PREFIX StandardState: - -SELECT ?match ?score ?query ?query_label ?corpusprofile ?corpusprofile_label -FROM -FROM -WHERE -{ -?match ps:combined_score ?score . -?match ps:for_query_profile/^ps:has_phenotypic_profile ?query . -?match ps:for_corpus_profile/^ps:has_phenotypic_profile ?corpusprofile . -?query rdfs:label ?query_label . -?corpusprofile rdfs:label ?corpusprofile_label . -} \ No newline at end of file diff --git a/src/getscores-taxa-corpus.rq b/src/main/sparql/get-scores.rq similarity index 55% rename from src/getscores-taxa-corpus.rq rename to src/main/sparql/get-scores.rq index 87b8b7e..7500438 100644 --- a/src/getscores-taxa-corpus.rq +++ b/src/main/sparql/get-scores.rq @@ -7,14 +7,12 @@ PREFIX owlet: PREFIX dc: PREFIX StandardState: -SELECT ?match ?score ?query ?query_label ?corpusprofile ?corpusprofile_label -FROM -FROM +SELECT ?match ?score ?query ?corpusprofile WHERE { ?match ps:combined_score ?score . -?match ps:for_query_profile/^ps:has_phenotypic_profile ?query . -?match ps:for_corpus_profile/^ps:has_phenotypic_profile ?corpusprofile . -?query rdfs:label ?query_label . -?corpusprofile rdfs:label ?corpusprofile_label . +?match ps:for_query_profile ?query . +?match ps:for_corpus_profile ?corpusprofile . + + } \ No newline at end of file From 500c6ffa7929886a7783c35d035263efd23c0db8 Mon Sep 17 00:00:00 2001 From: Shalsh Date: Fri, 30 Nov 2018 15:52:11 -0500 Subject: [PATCH 2/8] Remove legacy code --- .../scala/org/phenoscape/owl/NegationHierarchyAsserter.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scala/org/phenoscape/owl/NegationHierarchyAsserter.scala b/src/main/scala/org/phenoscape/owl/NegationHierarchyAsserter.scala index 90951aa..9d24864 100644 --- a/src/main/scala/org/phenoscape/owl/NegationHierarchyAsserter.scala +++ b/src/main/scala/org/phenoscape/owl/NegationHierarchyAsserter.scala @@ -8,7 +8,7 @@ import org.semanticweb.owlapi.model.OWLAxiom import org.semanticweb.owlapi.model.OWLClass import org.semanticweb.owlapi.model.OWLSubClassOfAxiom -object NegationHierarchyAsserter extends OWLTask { +object NegationHierarchyAsserter { val Negates = factory.getOWLAnnotationProperty(Vocab.NEGATES) From 080d53b818ea15e57f2285fedf9b5eda85c02a38 Mon Sep 17 00:00:00 2001 From: Shalsh Date: Mon, 3 Dec 2018 12:35:28 -0500 Subject: [PATCH 3/8] Take axioms as input from makefile for absence reasoning logic --- .../owl/NegationHierarchyAsserter.scala | 73 ++++++++++--------- 1 file changed, 40 insertions(+), 33 deletions(-) diff --git a/src/main/scala/org/phenoscape/owl/NegationHierarchyAsserter.scala b/src/main/scala/org/phenoscape/owl/NegationHierarchyAsserter.scala index 9d24864..3531236 100644 --- a/src/main/scala/org/phenoscape/owl/NegationHierarchyAsserter.scala +++ b/src/main/scala/org/phenoscape/owl/NegationHierarchyAsserter.scala @@ -5,47 +5,54 @@ import scala.collection.JavaConverters._ import org.phenoscape.scowl._ import org.semanticweb.owlapi.model.IRI import org.semanticweb.owlapi.model.OWLAxiom +import org.semanticweb.owlapi.apibinding.OWLManager import org.semanticweb.owlapi.model.OWLClass import org.semanticweb.owlapi.model.OWLSubClassOfAxiom object NegationHierarchyAsserter { - val Negates = factory.getOWLAnnotationProperty(Vocab.NEGATES) - - def assertNegationHierarchy(axioms: Set[OWLAxiom]): Set[OWLAxiom] = { - val negatesPairs = for { - AnnotationAssertion(_, Negates, subject: IRI, value: IRI) <- axioms - } yield (subject, value) - val negatesIndex = buildIndex(negatesPairs) - val negatedByIndex = buildReverseIndex(negatesPairs) - val superToSubclassPairs = for { - subClassOfAxiom @ SubClassOf(_, subclass @ Class(_), superclass @ Class(_)) <- axioms - } yield (superclass, subclass) - val subclassesIndex = buildIndex(superToSubclassPairs) - - val subclassAxioms = for { - AnnotationAssertion(_, Negates, negater: IRI, negated: IRI) <- axioms - subClassOfNegatedClass <- subclassesIndex(Class(negated)) - superClassOfOntClassIRI <- negatedByIndex(subClassOfNegatedClass.getIRI) - } yield Class(negater) SubClassOf Class(superClassOfOntClassIRI) - - val equivalentClassAxioms = for { - equivAxiom @ EquivalentClasses(_, _) <- axioms - classes = equivAxiom.getNamedClasses.asScala - if classes.size > 1 - } yield { - val negations = classes.flatMap(c => negatedByIndex(c.getIRI)) - factory.getOWLEquivalentClassesAxiom(negations.map(Class(_)).asJava) + def main(axioms: Set[OWLAxiom]): Unit = { + + val factory = OWLManager.getOWLDataFactory + val Negates = factory.getOWLAnnotationProperty(Vocab.NEGATES) + + def assertNegationHierarchy(): Set[OWLAxiom] = { + + val negatesPairs = for { + AnnotationAssertion(_, Negates, subject: IRI, value: IRI) <- axioms + } yield (subject, value) + val negatesIndex = buildIndex(negatesPairs) + val negatedByIndex = buildReverseIndex(negatesPairs) + val superToSubclassPairs = for { + subClassOfAxiom @ SubClassOf(_, subclass @ Class(_), superclass @ Class(_)) <- axioms + } yield (superclass, subclass) + val subclassesIndex = buildIndex(superToSubclassPairs) + + val subclassAxioms = for { + AnnotationAssertion(_, Negates, negater: IRI, negated: IRI) <- axioms + subClassOfNegatedClass <- subclassesIndex(Class(negated)) + superClassOfOntClassIRI <- negatedByIndex(subClassOfNegatedClass.getIRI) + } yield Class(negater) SubClassOf Class(superClassOfOntClassIRI) + + val equivalentClassAxioms = for { + equivAxiom @ EquivalentClasses(_, _) <- axioms + classes = equivAxiom.getNamedClasses.asScala + if classes.size > 1 + } yield { + val negations = classes.flatMap(c => negatedByIndex(c.getIRI)) + factory.getOWLEquivalentClassesAxiom(negations.map(Class(_)).asJava) + } + subclassAxioms ++ equivalentClassAxioms } - subclassAxioms ++ equivalentClassAxioms - } - def buildIndex[A, B](pairs: Iterable[(A, B)]): Map[A, Set[B]] = - pairs.foldLeft(emptyIndex[A, B]()) { case (index, (a, b)) => index.updated(a, (index(a) + b)) } + def buildIndex[A, B](pairs: Iterable[(A, B)]): Map[A, Set[B]] = + pairs.foldLeft(emptyIndex[A, B]()) { case (index, (a, b)) => index.updated(a, (index(a) + b)) } + + def buildReverseIndex[A, B](pairs: Iterable[(A, B)]): Map[B, Set[A]] = + pairs.foldLeft(emptyIndex[B, A]()) { case (index, (a, b)) => index.updated(b, (index(b) + a)) } - def buildReverseIndex[A, B](pairs: Iterable[(A, B)]): Map[B, Set[A]] = - pairs.foldLeft(emptyIndex[B, A]()) { case (index, (a, b)) => index.updated(b, (index(b) + a)) } + def emptyIndex[A, B](): Map[A, Set[B]] = Map.empty.withDefaultValue(Set.empty) - def emptyIndex[A, B](): Map[A, Set[B]] = Map.empty.withDefaultValue(Set.empty) + } } \ No newline at end of file From 5a79d4de2d14db54a4309588d3ad200780949ecf Mon Sep 17 00:00:00 2001 From: Shalsh Date: Mon, 3 Dec 2018 13:37:09 -0500 Subject: [PATCH 4/8] Modify to take ontology as input directly from commandline --- .../phenoscape/owl/NegationHierarchyAsserter.scala | 14 +++++++++----- .../scala/org/phenoscape/owl/build/Command.scala | 2 ++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/scala/org/phenoscape/owl/NegationHierarchyAsserter.scala b/src/main/scala/org/phenoscape/owl/NegationHierarchyAsserter.scala index 3531236..16b333d 100644 --- a/src/main/scala/org/phenoscape/owl/NegationHierarchyAsserter.scala +++ b/src/main/scala/org/phenoscape/owl/NegationHierarchyAsserter.scala @@ -11,12 +11,16 @@ import org.semanticweb.owlapi.model.OWLSubClassOfAxiom object NegationHierarchyAsserter { - def main(axioms: Set[OWLAxiom]): Unit = { + val factory = OWLManager.getOWLDataFactory + val Negates = factory.getOWLAnnotationProperty(Vocab.NEGATES) - val factory = OWLManager.getOWLDataFactory - val Negates = factory.getOWLAnnotationProperty(Vocab.NEGATES) + def main(args: Array[String]): Unit = { - def assertNegationHierarchy(): Set[OWLAxiom] = { + val axioms = args(0).asInstanceOf[Set[OWLAxiom]] + assertNegationHierarchy(axioms) + } + + def assertNegationHierarchy(axioms: Set[OWLAxiom]): Set[OWLAxiom] = { val negatesPairs = for { AnnotationAssertion(_, Negates, subject: IRI, value: IRI) <- axioms @@ -53,6 +57,6 @@ object NegationHierarchyAsserter { def emptyIndex[A, B](): Map[A, Set[B]] = Map.empty.withDefaultValue(Set.empty) - } + } \ No newline at end of file diff --git a/src/main/scala/org/phenoscape/owl/build/Command.scala b/src/main/scala/org/phenoscape/owl/build/Command.scala index cd038af..ac362e3 100644 --- a/src/main/scala/org/phenoscape/owl/build/Command.scala +++ b/src/main/scala/org/phenoscape/owl/build/Command.scala @@ -1,6 +1,7 @@ package org.phenoscape.owl.build import com.bigdata.rdf.store.DataLoader +import org.phenoscape.owl.NegationHierarchyAsserter object Command extends App { @@ -18,6 +19,7 @@ object Command extends App { case "sparql-construct" => RunSPARQLConstruct.main(commandArgs) case "sparql-update" => RunSPARQLUpdate.main(commandArgs) case "convert-nexml" => ConvertNeXML.main(commandArgs) + case "assert-negation-hierarchy" => NegationHierarchyAsserter.main(commandArgs) case _ => println(""" Valid commands are: From 48896f6b7e31080bc176c20e135c9e0898130207 Mon Sep 17 00:00:00 2001 From: Shalsh Date: Mon, 28 Jan 2019 17:08:17 -0500 Subject: [PATCH 5/8] Extract ontology axioms from file --- .../owl/NegationHierarchyAsserter.scala | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/main/scala/org/phenoscape/owl/NegationHierarchyAsserter.scala b/src/main/scala/org/phenoscape/owl/NegationHierarchyAsserter.scala index 7945329..9d0995a 100644 --- a/src/main/scala/org/phenoscape/owl/NegationHierarchyAsserter.scala +++ b/src/main/scala/org/phenoscape/owl/NegationHierarchyAsserter.scala @@ -1,14 +1,14 @@ package org.phenoscape.owl import scala.collection.JavaConverters._ - import org.phenoscape.scowl._ -import org.semanticweb.owlapi.model.IRI -import org.semanticweb.owlapi.model.OWLAxiom +import org.semanticweb.owlapi.model._ import org.semanticweb.owlapi.apibinding.OWLManager -import org.semanticweb.owlapi.model.OWLClass -import org.semanticweb.owlapi.model.OWLSubClassOfAxiom import org.phenoscape.owl.Vocab.has_part +import java.io.File +import scala.collection.JavaConverters._ +import org.semanticweb.owlapi.model.parameters.Imports + object NegationHierarchyAsserter { @@ -18,7 +18,9 @@ object NegationHierarchyAsserter { def main(args: Array[String]): Unit = { - val axioms = args(0).asInstanceOf[Set[OWLAxiom]] + val manager: OWLOntologyManager = OWLManager.createOWLOntologyManager() + val inputOntology: OWLOntology = manager.loadOntologyFromOntologyDocument(new File(args(0))) + val axioms: Set[OWLAxiom] = inputOntology.getAxioms(Imports.INCLUDED).asScala.toSet assertNegationHierarchy(axioms) } @@ -27,9 +29,9 @@ object NegationHierarchyAsserter { val classTuples = for { EquivalentClasses(_, expr) <- axioms // extract named classes and expressions - expressions = expr.collect{case hasPartAxiom@ObjectSomeValuesFrom(`has_part`, _) => hasPartAxiom} + expressions = expr.collect { case hasPartAxiom@ObjectSomeValuesFrom(`has_part`, _) => hasPartAxiom } if expressions.nonEmpty - namedClasses = expr.collect{case owlClass: OWLClass => owlClass} + namedClasses = expr.collect { case owlClass: OWLClass => owlClass } namedClass <- namedClasses expression <- expressions } yield (expression, namedClass) @@ -39,9 +41,9 @@ object NegationHierarchyAsserter { // create tuples (named class, named negation classes) val negatesPairs = for { EquivalentClasses(_, expr) <- axioms - expressions = expr.collect{case ObjectComplementOf(hasPartAxiom@ObjectSomeValuesFrom(`has_part`, _)) => hasPartAxiom} + expressions = expr.collect { case ObjectComplementOf(hasPartAxiom@ObjectSomeValuesFrom(`has_part`, _)) => hasPartAxiom } if expressions.nonEmpty - namedNegationClasses = expr.collect{case owlClass: OWLClass => owlClass} + namedNegationClasses = expr.collect { case owlClass: OWLClass => owlClass } expression <- expressions namedClass <- classMap.getOrElse(expression, Set.empty) namedNegationClass <- namedNegationClasses @@ -51,7 +53,7 @@ object NegationHierarchyAsserter { val negatedByIndex = buildReverseIndex(negatesPairs) val superToSubclassPairs = for { - subClassOfAxiom @ SubClassOf(_, subclass @ Class(_), superclass @ Class(_)) <- axioms + subClassOfAxiom@SubClassOf(_, subclass@Class(_), superclass@Class(_)) <- axioms } yield (superclass, subclass) val subclassesIndex = buildIndex(superToSubclassPairs) @@ -62,7 +64,7 @@ object NegationHierarchyAsserter { } yield Class(negater) SubClassOf Class(superClassOfOntClassIRI) val equivalentClassAxioms = for { - equivAxiom @ EquivalentClasses(_, _) <- axioms + equivAxiom@EquivalentClasses(_, _) <- axioms classes = equivAxiom.getNamedClasses.asScala if classes.size > 1 } yield { @@ -72,14 +74,13 @@ object NegationHierarchyAsserter { subclassAxioms ++ equivalentClassAxioms } - def buildIndex[A, B](pairs: Iterable[(A, B)]): Map[A, Set[B]] = - pairs.foldLeft(emptyIndex[A, B]()) { case (index, (a, b)) => index.updated(a, (index(a) + b)) } - - def buildReverseIndex[A, B](pairs: Iterable[(A, B)]): Map[B, Set[A]] = - pairs.foldLeft(emptyIndex[B, A]()) { case (index, (a, b)) => index.updated(b, (index(b) + a)) } + def buildIndex[A, B](pairs: Iterable[(A, B)]): Map[A, Set[B]] = + pairs.foldLeft(emptyIndex[A, B]()) { case (index, (a, b)) => index.updated(a, (index(a) + b)) } - def emptyIndex[A, B](): Map[A, Set[B]] = Map.empty.withDefaultValue(Set.empty) + def buildReverseIndex[A, B](pairs: Iterable[(A, B)]): Map[B, Set[A]] = + pairs.foldLeft(emptyIndex[B, A]()) { case (index, (a, b)) => index.updated(b, (index(b) + a)) } + def emptyIndex[A, B](): Map[A, Set[B]] = Map.empty.withDefaultValue(Set.empty) } \ No newline at end of file From f7bac543253c1a03e76a266c7f9c07025b190210 Mon Sep 17 00:00:00 2001 From: Shalsh Date: Mon, 28 Jan 2019 17:10:23 -0500 Subject: [PATCH 6/8] Save negation axioms to file --- .../scala/org/phenoscape/owl/NegationHierarchyAsserter.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/scala/org/phenoscape/owl/NegationHierarchyAsserter.scala b/src/main/scala/org/phenoscape/owl/NegationHierarchyAsserter.scala index 9d0995a..c6d566d 100644 --- a/src/main/scala/org/phenoscape/owl/NegationHierarchyAsserter.scala +++ b/src/main/scala/org/phenoscape/owl/NegationHierarchyAsserter.scala @@ -20,8 +20,8 @@ object NegationHierarchyAsserter { val manager: OWLOntologyManager = OWLManager.createOWLOntologyManager() val inputOntology: OWLOntology = manager.loadOntologyFromOntologyDocument(new File(args(0))) - val axioms: Set[OWLAxiom] = inputOntology.getAxioms(Imports.INCLUDED).asScala.toSet - assertNegationHierarchy(axioms) + val axioms: Set[OWLAxiom] = inputOntology.getAxioms(Imports.INCLUDED).asScala.toSet + val negationAxioms: Set[OWLAxiom] = assertNegationHierarchy(axioms) } def assertNegationHierarchy(axioms: Set[OWLAxiom]): Set[OWLAxiom] = { From bb0942de746ea336fcb61729625fc51ad3e7a650 Mon Sep 17 00:00:00 2001 From: Shalsh Date: Wed, 30 Jan 2019 13:55:47 -0500 Subject: [PATCH 7/8] Save negation ontology to file --- .../scala/org/phenoscape/owl/NegationHierarchyAsserter.scala | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/scala/org/phenoscape/owl/NegationHierarchyAsserter.scala b/src/main/scala/org/phenoscape/owl/NegationHierarchyAsserter.scala index c6d566d..f0c120c 100644 --- a/src/main/scala/org/phenoscape/owl/NegationHierarchyAsserter.scala +++ b/src/main/scala/org/phenoscape/owl/NegationHierarchyAsserter.scala @@ -6,6 +6,7 @@ import org.semanticweb.owlapi.model._ import org.semanticweb.owlapi.apibinding.OWLManager import org.phenoscape.owl.Vocab.has_part import java.io.File +import java.io.FileOutputStream import scala.collection.JavaConverters._ import org.semanticweb.owlapi.model.parameters.Imports @@ -22,6 +23,8 @@ object NegationHierarchyAsserter { val inputOntology: OWLOntology = manager.loadOntologyFromOntologyDocument(new File(args(0))) val axioms: Set[OWLAxiom] = inputOntology.getAxioms(Imports.INCLUDED).asScala.toSet val negationAxioms: Set[OWLAxiom] = assertNegationHierarchy(axioms) + val negationOntology: OWLOntology = manager.createOntology(negationAxioms.asJava) + manager.saveOntology(negationOntology, new FileOutputStream(("negationAxiomsFile"))) } def assertNegationHierarchy(axioms: Set[OWLAxiom]): Set[OWLAxiom] = { From df3e0a56dd74ae62530bb1cf0aa6a0b1eaedd769 Mon Sep 17 00:00:00 2001 From: Shalsh Date: Wed, 30 Jan 2019 16:19:02 -0500 Subject: [PATCH 8/8] Take filename to save negation axioms as input --- .../scala/org/phenoscape/owl/NegationHierarchyAsserter.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scala/org/phenoscape/owl/NegationHierarchyAsserter.scala b/src/main/scala/org/phenoscape/owl/NegationHierarchyAsserter.scala index f0c120c..2b5c086 100644 --- a/src/main/scala/org/phenoscape/owl/NegationHierarchyAsserter.scala +++ b/src/main/scala/org/phenoscape/owl/NegationHierarchyAsserter.scala @@ -24,7 +24,7 @@ object NegationHierarchyAsserter { val axioms: Set[OWLAxiom] = inputOntology.getAxioms(Imports.INCLUDED).asScala.toSet val negationAxioms: Set[OWLAxiom] = assertNegationHierarchy(axioms) val negationOntology: OWLOntology = manager.createOntology(negationAxioms.asJava) - manager.saveOntology(negationOntology, new FileOutputStream(("negationAxiomsFile"))) + manager.saveOntology(negationOntology, new FileOutputStream(args(1))) // negation axioms file } def assertNegationHierarchy(axioms: Set[OWLAxiom]): Set[OWLAxiom] = {