Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use only a single label for readable identifiers, rather than accidentally concatenating. #414

Merged
merged 1 commit into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/main/scala/org/monarchinitiative/dosdp/cli/Generate.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ object Generate {
val knownColumns = dosdp.allVars
for {
readableIdentifiers <- eDOSDP.readableIdentifierProperties
readableIDIndex = ontOpt.map(ont => createReadableIdentifierIndex(readableIdentifiers, eDOSDP, ont)).getOrElse(Map.empty) |+| extraReadableIdentifiers
initialReadableIDIndex = ontOpt.map(ont => createReadableIdentifierIndex(readableIdentifiers, eDOSDP, ont)).getOrElse(Map.empty)
extraReadableIdentifiersInSets = extraReadableIdentifiers.map { case (p, termsToLabel) => p -> termsToLabel.map { case (t, label) => t -> Set(label) } }
readableIDIndex = (initialReadableIDIndex |+| extraReadableIdentifiersInSets).map { case (p, termsToLabels) => p -> termsToLabels.map { case (t, labels) => t -> labels.toSeq.min } }
generatedAxioms <- ZIO.foreach(fillers) { row =>
val (varBindingsItems, localLabelItems) = (for {
vars <- dosdp.vars.toSeq
Expand Down Expand Up @@ -182,12 +184,12 @@ object Generate {
case AnnotationAxioms => (false, true)
}

private def createReadableIdentifierIndex(readableIdentifiers: List[OWLAnnotationProperty], dosdp: ExpandedDOSDP, ont: OWLOntology): Map[IRI, Map[IRI, String]] = {
private def createReadableIdentifierIndex(readableIdentifiers: List[OWLAnnotationProperty], dosdp: ExpandedDOSDP, ont: OWLOntology): Map[IRI, Map[IRI, Set[String]]] = {
val properties = readableIdentifiers.to(Set)
val mappings = for {
AnnotationAssertion(_, prop, subj: IRI, value ^^ _) <- ont.getAxioms(AxiomType.ANNOTATION_ASSERTION, Imports.INCLUDED).asScala
if properties(prop)
} yield Map(prop.getIRI -> Map(subj -> value))
} yield Map(prop.getIRI -> Map(subj -> Set(value)))
mappings.fold(Map.empty)(_ combine _)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ object MultiClausePrintfTest extends DefaultRunnableSpec {

for {
axioms <- Generate.renderPattern(dosdp, OBOPrefixes, List(Map("defined_class" -> "ONT:0000001", "item" -> "ONT:0000002", "axiom_filter" -> "all", "comment_var" -> "My comment1.")), None, outputLogicalAxioms = true, outputAnnotationAxioms = true, None, annotateAxiomSource = false, OboInOwlSource, generateDefinedClass = false, Map.empty)
_ = println(axioms)
} yield assert(axioms)(contains(annotationAxiom1))
},
testM("Annotation should be replaced correctly. Tests the default behaviour (without multiClauses and multiValues).") {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.monarchinitiative.dosdp

import org.monarchinitiative.dosdp.cli.Generate
import org.phenoscape.scowl._
import org.semanticweb.owlapi.apibinding.OWLManager
import org.semanticweb.owlapi.model._
import zio.logging._
import zio.test._

import scala.jdk.CollectionConverters._

object MultipleLabelsTest extends DefaultRunnableSpec {

val term: OWLClass = Class("http://purl.obolibrary.org/obo/ONT_0000001")
val item: OWLClass = Class("http://purl.obolibrary.org/obo/ONT_0000002")
val partOf: OWLObjectProperty = ObjectProperty("http://purl.obolibrary.org/obo/BFO_0000050")
val OboInOwlSource: OWLAnnotationProperty = AnnotationProperty("http://www.geneontology.org/formats/oboInOwl#source")

val dosdp: DOSDP = DOSDP.empty.copy(
pattern_name = Some("test_multiple_labels_pattern"),
classes = Some(Map("thing" -> "owl:Thing")),
vars = Some(Map("item" -> "'thing'")),
name = Some(PrintfAnnotationOBO(None, None, Some("%s item"), Some(List("item")), None)),
)

val ontologyAxioms: Set[OWLAxiom] = Set(AnnotationAssertion(RDFSLabel, item, "label1"), AnnotationAssertion(RDFSLabel, item, "label2"))
val ontology = OWLManager.createOWLOntologyManager().createOntology(ontologyAxioms.asJava)

val annotationAxiom: OWLAnnotationAssertionAxiom = term Annotation(RDFSLabel, "http://purl.obolibrary.org/obo/ONT_0000002 item")
val logicalAxiom: OWLSubClassOfAxiom = term SubClassOf (partOf some item)

def spec = suite("Multiple labels") {
testM("Only one term label should be used for a readable identifier") {
for {
axioms <- Generate.renderPattern(dosdp, OBOPrefixes, List(Map("defined_class" -> "ONT:0000001", "item" -> "ONT:0000002", "axiom_filter" -> "all")), Some(ontology), true, true, None, false, OboInOwlSource, false, Map.empty)
} yield assertTrue(axioms.size == 1) && assertTrue(axioms.exists { case AnnotationAssertion(_, RDFSLabel, iri: IRI, v ^^ _) => term.getIRI == iri && v == "label1 item" })
}
}.provideCustomLayer(Logging.consoleErr())

}