Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Shalsh23 authored Feb 5, 2019
2 parents df3e0a5 + 7968fa5 commit c12ebc9
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 38 deletions.
5 changes: 4 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ resolvers += "Phenoscape Maven repository" at "https://svn.code.sf.net/p/phenosc

javaOptions += "-Xmx100G"

testFrameworks += new TestFramework("utest.runner.Framework")

libraryDependencies ++= {
Seq(
"junit" % "junit" % "4.10" % "test",
Expand All @@ -39,6 +41,7 @@ libraryDependencies ++= {
"org.phenoscape" %% "phenoscape-kb-ingest" % "1.6.1",
"log4j" % "log4j" % "1.2.17",
"org.apache.directory.studio" % "org.apache.commons.codec" % "1.8",
"com.github.pathikrit" %% "better-files" % "3.4.0"
"com.github.pathikrit" %% "better-files" % "3.4.0",
"com.lihaoyi" %% "utest" % "0.6.3" % Test
)
}
28 changes: 11 additions & 17 deletions src/main/scala/org/phenoscape/owl/NegationHierarchyAsserter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import scala.collection.JavaConverters._
import org.phenoscape.scowl._
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._
Expand Down Expand Up @@ -32,36 +31,34 @@ object NegationHierarchyAsserter {
val classTuples = for {
EquivalentClasses(_, expr) <- axioms
// extract named classes and expressions
expressions = expr.collect { case hasPartAxiom@ObjectSomeValuesFrom(`has_part`, _) => hasPartAxiom }
if expressions.nonEmpty
namedClasses = expr.collect { case owlClass: OWLClass => owlClass }
namedClass <- namedClasses
expression <- expressions
namedClasses: Set[OWLClass] = expr.collect { case owlClass: OWLClass => owlClass }
namedClass: OWLClass <- namedClasses
expression: OWLClassExpression <- expr
} yield (expression, namedClass)
// map (class expression -> named classes)
val classMap = buildIndex(classTuples)

// 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(negated) => negated }
if expressions.nonEmpty
namedNegationClasses = expr.collect { case owlClass: OWLClass => owlClass }
expression <- expressions
namedClass <- classMap.getOrElse(expression, Set.empty)
expressionAsNamed = Set(expression).collect { case n: OWLClass => n }
namedClass <- classMap.getOrElse(expression, Set.empty) ++ expressionAsNamed
namedNegationClass <- namedNegationClasses
} yield (namedNegationClass.getIRI, namedClass.getIRI)

val negatesIndex = buildIndex(negatesPairs)
val negatedByIndex = buildReverseIndex(negatesPairs)
val negatedByIndex = buildIndex(negatesPairs.map(_.swap))

val superToSubclassPairs = for {
subClassOfAxiom@SubClassOf(_, subclass@Class(_), superclass@Class(_)) <- axioms
SubClassOf(_, subclass @ Class(_), superclass @ Class(_)) <- axioms
} yield (superclass, subclass)
val subclassesIndex = buildIndex(superToSubclassPairs)

val subclassAxioms = for {
AnnotationAssertion(_, Negates, negater: IRI, negated: IRI) <- axioms
(negater, negated) <- negatesPairs
subClassOfNegatedClass <- subclassesIndex(Class(negated))
superClassOfOntClassIRI <- negatedByIndex(subClassOfNegatedClass.getIRI)
} yield Class(negater) SubClassOf Class(superClassOfOntClassIRI)
Expand All @@ -78,12 +75,9 @@ object NegationHierarchyAsserter {
}

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)) }
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 emptyIndex[A, B]: Map[A, Set[B]] = Map.empty.withDefaultValue(Set.empty)


}
7 changes: 4 additions & 3 deletions src/main/scala/org/phenoscape/owl/build/PhenoscapeKB.scala
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,10 @@ object PhenoscapeKB extends KnowledgeBaseBuilder {
val vocabForNeXML = combine(uberon, pato, bspo, phenoscapeVocab)
val filesToConvert = (FileUtils.listFiles((NEXML / "completed-phenex-files").toJava, Array("xml"), true).asScala ++
FileUtils.listFiles((NEXML / "fin_limb-incomplete-files").toJava, Array("xml"), true).asScala ++
FileUtils.listFiles((NEXML / "Jackson Dissertation Files").toJava, Array("xml"), true).asScala ++
FileUtils.listFiles((NEXML / "teleost-incomplete-files" / "Miniature Monographs").toJava, Array("xml"), true).asScala ++
FileUtils.listFiles((NEXML / "teleost-incomplete-files" / "Miniatures Matrix Files").toJava, Array("xml"), true).asScala ++
FileUtils.listFiles((NEXML / "Jackson_Dissertation_Files").toJava, Array("xml"), true).asScala ++
FileUtils.listFiles((NEXML / "teleost-incomplete-files" / "Miniature_Monographs").toJava, Array("xml"), true).asScala ++
FileUtils.listFiles((NEXML / "teleost-incomplete-files" / "Miniatures_Matrix_Files").toJava, Array("xml"), true).asScala ++
FileUtils.listFiles((NEXML / "teleost-incomplete-files" / "Dillman_Supermatrix_Files").toJava, Array("xml"), true).asScala ++
FileUtils.listFiles((NEXML / "matrix-vs-monograph").toJava, Array("xml"), true).asScala).filterNot(_.getName == "catalog-v001.xml")
val nexmlTBoxAxioms: mutable.Set[OWLAxiom] = mutable.Set()
for (file <- filesToConvert) {
Expand Down
50 changes: 50 additions & 0 deletions src/test/resources/NegationHierarchyAsserterTest.ofn
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,71 @@ Declaration(Class(:A))
Declaration(Class(:B))
Declaration(Class(:C))
Declaration(Class(:D))
Declaration(Class(:HasPartB))
Declaration(Class(:HasPartC))
Declaration(Class(:NotA))
Declaration(Class(:NotB))
Declaration(Class(:NotC))
Declaration(Class(:NotD))
Declaration(Class(:NotHasPartB))
Declaration(Class(:NotHasPartC))
Declaration(ObjectProperty(:has_part))
Declaration(AnnotationProperty(vocab3:negation_of_class))


############################
# Classes
############################

# Class: :B (:B)

EquivalentClasses(:B :D)
SubClassOf(:B :A)

# Class: :C (:C)

SubClassOf(:C :B)

# Class: :D (:D)

SubClassOf(:D :A)

# Class: :HasPartB (:HasPartB)

EquivalentClasses(:HasPartB ObjectSomeValuesFrom(:has_part :B))

# Class: :HasPartC (:HasPartC)

EquivalentClasses(:HasPartC ObjectSomeValuesFrom(:has_part :C))
SubClassOf(:HasPartC :HasPartB)

# Class: :NotA (:NotA)

AnnotationAssertion(vocab3:negation_of_class :NotA :A)
EquivalentClasses(:NotA ObjectComplementOf(:A))

# Class: :NotB (:NotB)

AnnotationAssertion(vocab3:negation_of_class :NotB :B)
EquivalentClasses(:NotB ObjectComplementOf(:B))

# Class: :NotC (:NotC)

AnnotationAssertion(vocab3:negation_of_class :NotC :C)
EquivalentClasses(:NotC ObjectComplementOf(:C))

# Class: :NotD (:NotD)

AnnotationAssertion(vocab3:negation_of_class :NotD :D)
EquivalentClasses(:NotD ObjectComplementOf(:D))

# Class: :NotHasPartB (:NotHasPartB)

EquivalentClasses(:NotHasPartB ObjectComplementOf(ObjectSomeValuesFrom(:has_part :B)))

# Class: :NotHasPartC (:NotHasPartC)

EquivalentClasses(:NotHasPartC ObjectComplementOf(ObjectSomeValuesFrom(:has_part :C)))


)
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,65 @@ package org.phenoscape.owl

import scala.collection.JavaConversions._

import org.junit.Test
import utest._
import org.semanticweb.owlapi.apibinding.OWLManager

import org.phenoscape.scowl._

import junit.framework.Assert

class NegationHierarchyAsserterTest {
object NegationHierarchyAsserterTest extends TestSuite {

val base = "http://owl.phenoscape.org/NegationHierarchyAsserterTest"
val tests = Tests {

@Test
def testHierarchy() {
val base = "http://owl.phenoscape.org/NegationHierarchyAsserterTest"
val manager = OWLManager.createOWLOntologyManager()
val input = getClass().getClassLoader().getResourceAsStream("NegationHierarchyAsserterTest.ofn")
val ontology = manager.loadOntologyFromOntologyDocument(input)
input.close()
Assert.assertTrue(ontology.containsAxiom(Class(s"$base#B") SubClassOf Class(s"$base#A")))
Assert.assertFalse(ontology.containsAxiom(Class(s"$base#NotA") SubClassOf Class(s"$base#NotB")))
Assert.assertTrue(ontology.containsAxiom(Class(s"$base#C") SubClassOf Class(s"$base#B")))
Assert.assertFalse(ontology.containsAxiom(Class(s"$base#NotB") SubClassOf Class(s"$base#NotC")))
Assert.assertTrue(ontology.containsAxiom(Class(s"$base#B") EquivalentTo Class(s"$base#D")))
Assert.assertFalse(ontology.containsAxiom(Class(s"$base#NotB") EquivalentTo Class(s"$base#NotD")))
manager.addAxioms(ontology, NegationHierarchyAsserter.assertNegationHierarchy(ontology.getAxioms().toSet))
Assert.assertTrue(ontology.containsAxiom(Class(s"$base#NotA") SubClassOf Class(s"$base#NotB")))
Assert.assertTrue(ontology.containsAxiom(Class(s"$base#NotB") SubClassOf Class(s"$base#NotC")))
Assert.assertTrue(ontology.containsAxiom(Class(s"$base#NotB") EquivalentTo Class(s"$base#NotD")))
}

'beforeAxioms - {
'test1 - {
assert(ontology.containsAxiom(Class(s"$base#B") SubClassOf Class(s"$base#A")))
}

'test2 - {
assert(!(ontology.containsAxiom(Class(s"$base#NotA") SubClassOf Class(s"$base#NotB"))))
}

'test3 - {
assert(ontology.containsAxiom(Class(s"$base#C") SubClassOf Class(s"$base#B")))
}

'test4 - {
assert(!(ontology.containsAxiom(Class(s"$base#NotB") SubClassOf Class(s"$base#NotC"))))
}

'test5 - {
assert(ontology.containsAxiom(Class(s"$base#B") EquivalentTo Class(s"$base#D")))
}

'test6 - {
assert(!(ontology.containsAxiom(Class(s"$base#NotB") EquivalentTo Class(s"$base#NotD"))))
assert(!ontology.containsAxiom(Class(s"$base#NotHasPartB") SubClassOf Class(s"$base#NotHasPartC")))
}
}

'afterAxioms - {

manager.addAxioms(ontology, NegationHierarchyAsserter.assertNegationHierarchy(ontology.getAxioms().toSet))

'test7 - {
assert(ontology.containsAxiom(Class(s"$base#NotA") SubClassOf Class(s"$base#NotB")))
}

'test8 - {
assert(ontology.containsAxiom(Class(s"$base#NotB") SubClassOf Class(s"$base#NotC")))
}

'test9 - {
assert(ontology.containsAxiom(Class(s"$base#NotB") EquivalentTo Class(s"$base#NotD")))
assert(ontology.containsAxiom(Class(s"$base#NotHasPartB") SubClassOf Class(s"$base#NotHasPartC")))
}
}
}
}

0 comments on commit c12ebc9

Please sign in to comment.