From f7d454e05754d19d7e21ca35417509b3ac11b745 Mon Sep 17 00:00:00 2001 From: Jim Balhoff Date: Wed, 1 Dec 2021 14:24:45 -0500 Subject: [PATCH 1/2] Minor cleanup and warnings fixes. --- .../org/phenoscape/kb/AnatomicalEntity.scala | 18 +-- src/main/scala/org/phenoscape/kb/App.scala | 2 +- .../phenoscape/kb/CharacterDescription.scala | 110 ++++++++++-------- .../scala/org/phenoscape/kb/EQForGene.scala | 43 +++---- src/main/scala/org/phenoscape/kb/Gene.scala | 5 +- .../kb/GeneExpressionAnnotation.scala | 6 +- .../kb/GenePhenotypeAnnotation.scala | 4 +- src/main/scala/org/phenoscape/kb/Graph.scala | 13 +-- src/main/scala/org/phenoscape/kb/KB.scala | 33 ++---- .../scala/org/phenoscape/kb/OWLFormats.scala | 8 +- .../org/phenoscape/kb/PhenexDataSet.scala | 10 +- .../scala/org/phenoscape/kb/Phenotype.scala | 2 +- .../kb/PresenceAbsenceOfStructure.scala | 24 ++-- .../scala/org/phenoscape/kb/ResultCount.scala | 10 +- .../scala/org/phenoscape/kb/Similarity.scala | 20 +--- src/main/scala/org/phenoscape/kb/Study.scala | 2 +- src/main/scala/org/phenoscape/kb/Taxon.scala | 48 +++----- src/main/scala/org/phenoscape/kb/Term.scala | 6 +- .../kb/queries/DirectPhenotypesForTaxon.scala | 2 +- .../kb/queries/GeneAffectingPhenotype.scala | 2 +- .../queries/StudiesRelevantToPhenotype.scala | 2 +- .../kb/queries/TaxaWithPhenotype.scala | 2 +- .../kb/queries/TaxonAnnotations.scala | 2 +- .../kb/queries/TaxonPhenotypes.scala | 2 +- .../kb/util/SPARQLEntityChecker.scala | 2 +- ...ala => SPARQLInterpolatorBlazegraph.scala} | 4 +- .../scala/org/phenoscape/kb/util/Util.scala | 7 -- 27 files changed, 162 insertions(+), 227 deletions(-) rename src/main/scala/org/phenoscape/kb/util/{SPARQLInterpolatorOWLAPI.scala => SPARQLInterpolatorBlazegraph.scala} (71%) diff --git a/src/main/scala/org/phenoscape/kb/AnatomicalEntity.scala b/src/main/scala/org/phenoscape/kb/AnatomicalEntity.scala index e239bd00..c752d783 100644 --- a/src/main/scala/org/phenoscape/kb/AnatomicalEntity.scala +++ b/src/main/scala/org/phenoscape/kb/AnatomicalEntity.scala @@ -4,12 +4,11 @@ import akka.http.scaladsl.marshalling.{Marshaller, ToEntityMarshaller} import akka.http.scaladsl.model.MediaTypes import org.apache.jena.query.{QueryFactory, QuerySolution} import org.phenoscape.kb.KBVocab.{rdfsSubClassOf, _} -import org.phenoscape.kb.Similarity.rdfsSubClassOf import org.phenoscape.owl.Vocab._ import org.phenoscape.scowl._ import org.phenoscape.sparql.SPARQLInterpolation._ import org.phenoscape.sparql.SPARQLInterpolationOWL._ -import org.phenoscape.kb.util.SPARQLInterpolatorOWLAPI._ +import org.phenoscape.kb.util.SPARQLInterpolatorBlazegraph._ import org.phenoscape.owl.{NamedRestrictionGenerator, Vocab} import org.semanticweb.owlapi.model.IRI import spray.json.DefaultJsonProtocol._ @@ -71,7 +70,7 @@ object AnatomicalEntity { } // Output a boolean matrix as CSV - def matrixRendererFromMapOfMaps[A](dependencyMatrix: DependencyMatrix[A]) = { + def matrixRendererFromMapOfMaps[A](dependencyMatrix: DependencyMatrix[A]): String = { val mapOfMaps = dependencyMatrix.map val orderedKeys = dependencyMatrix.orderedKeys @@ -79,17 +78,13 @@ object AnatomicalEntity { val matrix = for (x <- orderedKeys) yield { val row = s"$x" - val values = for (y <- orderedKeys) yield mapOfMaps(x)(y) match { - case true => 1 - case false => 0 - } + val values = for (y <- orderedKeys) yield (if (mapOfMaps(x)(y)) 1 else 0) s"$row,${values.mkString(",")}" } s"$headers\n${matrix.mkString("\n")}\n" } def presenceAbsenceDependencyMatrix(iris: List[IRI]): Future[DependencyMatrix[IRI]] = { - import org.phenoscape.kb.util.Util.TraversableOps import org.phenoscape.kb.util.Util.MapOps val query = queryImpliesPresenceOfMulti(iris) for { @@ -123,21 +118,16 @@ object AnatomicalEntity { """ private def queryImpliesPresenceOfMulti(terms: Iterable[IRI]): QueryText = { - import scalaz._ - import Scalaz._ val valuesList = terms.map(t => sparql" $t ").fold(sparql"")(_ + _) sparql""" SELECT DISTINCT ?x ?y FROM $KBClosureGraph FROM $KBMainGraph FROM $KBRedundantRelationGraph - WHERE { - VALUES ?x { $valuesList } + VALUES ?x { $valuesList } VALUES ?y { $valuesList } - ?x $rdfsSubClassOf | $IMPLIES_PRESENCE_OF ?y . - FILTER(?x != ?y) } """ diff --git a/src/main/scala/org/phenoscape/kb/App.scala b/src/main/scala/org/phenoscape/kb/App.scala index a77ec8ac..b9c5c001 100644 --- a/src/main/scala/org/phenoscape/kb/App.scala +++ b/src/main/scala/org/phenoscape/kb/App.scala @@ -20,7 +20,7 @@ import org.phenoscape.owlet.SPARQLComposer._ import org.phenoscape.sparql.FromQuerySolution import org.semanticweb.owlapi.model.IRI -import scala.collection.JavaConverters._ +import scala.jdk.CollectionConverters._ import scala.concurrent.Future import scala.concurrent.duration._ import scala.language.postfixOps diff --git a/src/main/scala/org/phenoscape/kb/CharacterDescription.scala b/src/main/scala/org/phenoscape/kb/CharacterDescription.scala index 819aa4f8..f29f6971 100644 --- a/src/main/scala/org/phenoscape/kb/CharacterDescription.scala +++ b/src/main/scala/org/phenoscape/kb/CharacterDescription.scala @@ -19,9 +19,12 @@ import org.phenoscape.owlet.SPARQLComposer._ import org.semanticweb.owlapi.model.{IRI, OWLClassExpression} import spray.json.DefaultJsonProtocol._ import spray.json._ +import org.phenoscape.kb.KBVocab.KBMainGraph -import scala.collection.JavaConverters._ +import scala.jdk.CollectionConverters._ import scala.concurrent.Future +import org.phenoscape.sparql.SPARQLInterpolation._ +import org.phenoscape.sparql.SPARQLInterpolationOWL._ object CharacterDescription { @@ -58,12 +61,16 @@ object CharacterDescription { App.executeSPARQLQuery(buildCharacterDescriptionQuery(iri), fromQuerySolution(iri)).map(_.headOption) def annotatedCharacterDescriptionWithAnnotation(iri: IRI): Future[Option[AnnotatedCharacterDescription]] = { - val query = select_distinct('state, 'description, 'matrix, 'matrix_label) where bgp( - t('state, describes_phenotype, iri), - t('state, dcDescription, 'description), - t('matrix, has_character / may_have_state_value, 'state), - t('matrix, rdfsLabel, 'matrix_label) - ) + val query = + sparql""" + SELECT DISTINCT ?state ?description ?matrix ?matrix_label + WHERE { + ?state $describes_phenotype $iri . + ?state $dcDescription ?description . + ?matrix $has_character/$may_have_state_value ?state . + ?matrix $rdfsLabel ?matrix_label . + } + """.toQuery val result = App.executeSPARQLQuery( query, result => @@ -84,34 +91,41 @@ object CharacterDescription { result.flatMap(Future.sequence(_)).map(_.headOption) } - def buildBasicQuery(entity: OWLClassExpression = owlThing, - taxon: OWLClassExpression = owlThing, - publications: Iterable[IRI] = Nil): Query = { - val entityPatterns = - if (entity == owlThing) Nil + def buildWhereClause(entity: OWLClassExpression = owlThing, + taxon: OWLClassExpression = owlThing, + publications: Iterable[IRI] = Nil): QueryText = { + val entityPattern = + if (entity == owlThing) sparql"" + else sparql""" + ?phenotype $ps_entity_term|$ps_related_entity_term ?entity . + ?entity $rdfsSubClassOf ${entity.asOMN} + """ + val taxonPattern = + if (taxon == owlThing) sparql"" else - t('phenotype, ps_entity_term | ps_related_entity_term, 'entity) :: t('entity, - rdfsSubClassOf, - entity.asOMN) :: Nil - val taxonPatterns = - if (taxon == owlThing) Nil - else - t('taxon, exhibits_state, 'state) :: t('taxon, rdfsSubClassOf, taxon.asOMN) :: Nil - val filters = - if (publications.isEmpty) Nil - else - new ElementFilter( - new E_OneOf(new ExprVar('matrix), - new ExprList(publications.map(new NodeValueNode(_)).toBuffer[Expr].asJava))) :: Nil - select_distinct() from "http://kb.phenoscape.org/" where (bgp( - t('state, dcDescription, 'state_desc) :: - t('state, describes_phenotype, 'phenotype) :: - t('matrix, has_character / may_have_state_value, 'state) :: - t('matrix, rdfsLabel, 'matrix_label) :: - entityPatterns ++ - taxonPatterns: _* - ) :: - filters: _*) + sparql""" + ?taxon $exhibits_state ?state . + ?taxon $rdfsSubClassOf ${taxon.asOMN} . + """ + val publicationsFilter = + if (publications.isEmpty) sparql"" + else { + val pubsList = publications.map(p => sparql"$p").reduceOption((l, r) => sparql"$l, $r").getOrElse(sparql"") + sparql""" + FILTER(?matrix IN ($pubsList)) + """ + } + sparql""" + WHERE { + ?state $dcDescription ?state_desc . + ?state $describes_phenotype ?phenotype . + ?matrix $has_character/$may_have_state_value ?state . + ?matrix $rdfsLabel ?matrix_label . + $entityPattern + $taxonPattern + $publicationsFilter + } + """ } def buildQuery(entity: OWLClassExpression = owlThing, @@ -119,24 +133,26 @@ object CharacterDescription { publications: Iterable[IRI] = Nil, limit: Int = 20, offset: Int = 0): Query = { - val query = buildBasicQuery(entity, taxon, publications) - query.addResultVar('state) - query.addResultVar('state_desc) - query.addResultVar('matrix) - query.addResultVar('matrix_label) - query.setOffset(offset) - query.setLimit(limit) - query.addOrderBy('state_desc) - query.addOrderBy('state) - query + val whereClause = buildWhereClause(entity, taxon, publications) + sparql""" + SELECT DISTINCT ?state ?state_desc ?matrix ?matrix_label + FROM $KBMainGraph + $whereClause + ORDER BY ?state_desc ?state + LIMIT $limit + OFFSET $offset + """.toQuery } def buildTotalQuery(entity: OWLClassExpression = owlThing, taxon: OWLClassExpression = owlThing, publications: Iterable[IRI] = Nil): Query = { - val query = buildBasicQuery(entity, taxon, publications) - query.getProject.add(Var.alloc("count"), query.allocAggregate(new AggCountVarDistinct(new ExprVar("state")))) - query + val whereClause = buildWhereClause(entity, taxon, publications) + sparql""" + SELECT (COUNT(DISTINCT(?state) AS ?count) + FROM $KBMainGraph + $whereClause + """.toQuery } def buildVariationProfileTotalQuery(taxa: Seq[IRI]): Query = { diff --git a/src/main/scala/org/phenoscape/kb/EQForGene.scala b/src/main/scala/org/phenoscape/kb/EQForGene.scala index 4576ea46..043ea889 100644 --- a/src/main/scala/org/phenoscape/kb/EQForGene.scala +++ b/src/main/scala/org/phenoscape/kb/EQForGene.scala @@ -1,31 +1,19 @@ package org.phenoscape.kb -import scala.collection.JavaConverters._ -import scala.concurrent.ExecutionContext.Implicits.global -import scala.concurrent.Future -import scala.concurrent.duration._ -import scala.language.postfixOps - +import akka.util.Timeout import org.apache.jena.query.Query -import org.phenoscape.owl.NamedRestrictionGenerator -import org.phenoscape.owl.Vocab._ import org.phenoscape.kb.KBVocab._ -import org.phenoscape.owlet.SPARQLComposer._ -import org.phenoscape.scowl._ - +import org.phenoscape.owl.Vocab._ import org.phenoscape.sparql.SPARQLInterpolation._ -import org.phenoscape.kb.util.SPARQLInterpolatorOWLAPI._ -import org.phenoscape.sparql.SPARQLInterpolationOWL._ -import org.phenoscape.sparql.SPARQLInterpolation.QueryText - -import org.semanticweb.owlapi.apibinding.OWLManager import org.semanticweb.owlapi.model.IRI - -import com.google.common.collect.HashMultiset - -import akka.util.Timeout -import spray.json._ +import org.phenoscape.sparql.SPARQLInterpolationOWL._ import spray.json.DefaultJsonProtocol._ +import spray.json._ + +import scala.concurrent.ExecutionContext.Implicits.global +import scala.concurrent.Future +import scala.concurrent.duration._ +import scala.language.postfixOps object EQForGene { @@ -56,10 +44,15 @@ object EQForGene { App.executeSPARQLQuery(annotationsQuery(geneID), _.getResource("association").getURI) def annotationsQuery(geneIRI: IRI): Query = - select_distinct('association) from "http://kb.phenoscape.org/" where bgp( - t('association, rdfType, association), - t('association, associationHasPredicate, has_phenotype), - t('association, associationHasSubject, geneIRI)) + sparql""" + SELECT DISTINCT ?association + FROM $KBMainGraph + WHERE { + ?association $rdfType $association . + ?association $associationHasPredicate $has_phenotype . + ?association $associationHasSubject $geneIRI . + } + """.toQuery def qualitiesForAnnotation(annotationID: String): Future[Iterable[String]] = App.executeSPARQLQuery(annotationSuperQualityQuery(annotationID), _.getResource("quality").getURI) diff --git a/src/main/scala/org/phenoscape/kb/Gene.scala b/src/main/scala/org/phenoscape/kb/Gene.scala index c675896d..3139cdcc 100644 --- a/src/main/scala/org/phenoscape/kb/Gene.scala +++ b/src/main/scala/org/phenoscape/kb/Gene.scala @@ -2,7 +2,6 @@ package org.phenoscape.kb import akka.http.scaladsl.marshalling.{Marshaller, ToEntityMarshaller} import akka.http.scaladsl.model.MediaTypes -import org.apache.jena.graph.NodeFactory import org.apache.jena.query.{Query, QuerySolution} import org.apache.jena.rdf.model.{Model, Property, Resource, ResourceFactory} import org.apache.jena.sparql.core.Var @@ -25,10 +24,10 @@ import spray.json.DefaultJsonProtocol._ import spray.json._ import org.phenoscape.sparql.SPARQLInterpolation.{QueryText, _} import org.phenoscape.sparql.SPARQLInterpolationOWL._ -import org.phenoscape.kb.util.SPARQLInterpolatorOWLAPI._ +import org.phenoscape.kb.util.SPARQLInterpolatorBlazegraph._ import org.phenoscape.owl.Vocab.{AnnotatedPhenotype, GeneExpression, associated_with_gene, associated_with_taxon, dcSource, has_part, in_taxon, inheres_in, occurs_in, part_of, rdfType, towards} -import scala.collection.JavaConverters._ +import scala.jdk.CollectionConverters._ import scala.concurrent.Future import scala.language.implicitConversions diff --git a/src/main/scala/org/phenoscape/kb/GeneExpressionAnnotation.scala b/src/main/scala/org/phenoscape/kb/GeneExpressionAnnotation.scala index 0d73f265..9e53317b 100644 --- a/src/main/scala/org/phenoscape/kb/GeneExpressionAnnotation.scala +++ b/src/main/scala/org/phenoscape/kb/GeneExpressionAnnotation.scala @@ -5,13 +5,13 @@ import akka.http.scaladsl.model.MediaTypes import akka.util.Timeout import org.apache.jena.query.{Query, QuerySolution} import org.apache.jena.sparql.core.Var -import org.apache.jena.sparql.expr.{E_NotOneOf, Expr, ExprList, ExprVar} import org.apache.jena.sparql.expr.aggregate.AggCountDistinct import org.apache.jena.sparql.expr.nodevalue.NodeValueNode +import org.apache.jena.sparql.expr.{E_NotOneOf, Expr, ExprList, ExprVar} import org.apache.jena.sparql.syntax.{ElementFilter, ElementSubQuery} +import org.phenoscape.kb.JSONResultItem.JSONResultItemsMarshaller import org.phenoscape.kb.KBVocab.{rdfsLabel, rdfsSubClassOf, _} import org.phenoscape.kb.Main.system.dispatcher -import org.phenoscape.kb.JSONResultItem.JSONResultItemsMarshaller import org.phenoscape.owl.Vocab._ import org.phenoscape.owlet.OwletManchesterSyntaxDataType.SerializableClassExpression import org.phenoscape.owlet.SPARQLComposer._ @@ -20,9 +20,9 @@ import org.semanticweb.owlapi.model.{IRI, OWLClassExpression} import spray.json.DefaultJsonProtocol._ import spray.json._ -import scala.collection.JavaConverters._ import scala.concurrent.Future import scala.concurrent.duration._ +import scala.jdk.CollectionConverters._ import scala.language.postfixOps case class GeneExpressionAnnotation(gene: MinimalTerm, location: MinimalTerm, source: Option[IRI]) diff --git a/src/main/scala/org/phenoscape/kb/GenePhenotypeAnnotation.scala b/src/main/scala/org/phenoscape/kb/GenePhenotypeAnnotation.scala index f4ec1c29..f08057bd 100644 --- a/src/main/scala/org/phenoscape/kb/GenePhenotypeAnnotation.scala +++ b/src/main/scala/org/phenoscape/kb/GenePhenotypeAnnotation.scala @@ -9,9 +9,9 @@ import org.apache.jena.sparql.expr._ import org.apache.jena.sparql.expr.aggregate.AggCountDistinct import org.apache.jena.sparql.expr.nodevalue.NodeValueNode import org.apache.jena.sparql.syntax.{ElementFilter, ElementSubQuery} +import org.phenoscape.kb.JSONResultItem.JSONResultItemsMarshaller import org.phenoscape.kb.KBVocab.{rdfsLabel, rdfsSubClassOf, _} import org.phenoscape.kb.Main.system.dispatcher -import org.phenoscape.kb.JSONResultItem.JSONResultItemsMarshaller import org.phenoscape.owl.Vocab._ import org.phenoscape.owlet.OwletManchesterSyntaxDataType.SerializableClassExpression import org.phenoscape.owlet.SPARQLComposer._ @@ -20,8 +20,8 @@ import org.semanticweb.owlapi.model.{IRI, OWLClassExpression} import spray.json.DefaultJsonProtocol._ import spray.json._ -import scala.collection.JavaConverters._ import scala.concurrent.Future +import scala.jdk.CollectionConverters._ import scala.language.postfixOps case class GenePhenotypeAnnotation(gene: MinimalTerm, phenotype: MinimalTerm, source: Option[IRI]) diff --git a/src/main/scala/org/phenoscape/kb/Graph.scala b/src/main/scala/org/phenoscape/kb/Graph.scala index 34e37eb4..ab5d0bf8 100644 --- a/src/main/scala/org/phenoscape/kb/Graph.scala +++ b/src/main/scala/org/phenoscape/kb/Graph.scala @@ -8,17 +8,11 @@ import org.semanticweb.owlapi.model.IRI import org.phenoscape.kb.KBVocab.{rdfsLabel, rdfsSubClassOf, _} import org.phenoscape.owl.Vocab.rdfType import org.phenoscape.kb.Main.system.dispatcher -import org.phenoscape.owl.NamedRestrictionGenerator -import org.phenoscape.owlet.SPARQLComposer._ import org.phenoscape.sparql.SPARQLInterpolation._ -import org.phenoscape.sparql.SPARQLInterpolation.QueryText -import org.phenoscape.kb.util.SPARQLInterpolatorOWLAPI._ -import org.phenoscape.scowl import org.phenoscape.sparql.SPARQLInterpolationOWL._ import scala.concurrent.Future import scala.language.postfixOps -import java.net.{URLDecoder, URLEncoder} object Graph { @@ -148,15 +142,14 @@ object Graph { val termSubsumerSeq = for { pairs <- futurePairs } yield { - val termSubsumerPairs = pairs.map(p => (p._1 -> (p._2, p._3))) - termSubsumerPairs.map { case (term, (relation, subsumer)) => + val termSubsumerPairs = pairs.map(p => p._1 -> (p._2, p._3)) + termSubsumerPairs.flatMap { case (term, (relation, subsumer)) => val virtualTermIRI = relation match { case "http://www.w3.org/2000/01/rdf-schema#subClassOf" => IRI.create(subsumer) case _ => RelationalTerm(IRI.create(relation), IRI.create(subsumer)).iri - } Map(IRI.create(term) -> virtualTermIRI) - }.flatten + } } termSubsumerSeq } diff --git a/src/main/scala/org/phenoscape/kb/KB.scala b/src/main/scala/org/phenoscape/kb/KB.scala index 8d6c3f78..ea563654 100644 --- a/src/main/scala/org/phenoscape/kb/KB.scala +++ b/src/main/scala/org/phenoscape/kb/KB.scala @@ -1,40 +1,29 @@ package org.phenoscape.kb -import scala.concurrent.Future - +import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._ +import akka.http.scaladsl.marshalling.{Marshaller, ToEntityMarshaller} import org.apache.jena.datatypes.xsd.XSDDatatype -import org.apache.jena.query.QueryFactory import org.apache.jena.sparql.core.Var -import org.apache.jena.sparql.expr.E_Exists -import org.apache.jena.sparql.expr.E_NotExists -import org.apache.jena.sparql.expr.ExprVar +import org.apache.jena.sparql.expr.{E_NotExists, ExprVar} import org.apache.jena.sparql.expr.aggregate.AggCountVarDistinct -import org.apache.jena.sparql.syntax.Element -import org.apache.jena.sparql.syntax.ElementFilter -import org.apache.jena.sparql.syntax.ElementGroup +import org.apache.jena.sparql.syntax.{Element, ElementFilter, ElementGroup} +import org.apache.jena.vocabulary.DCTerms import org.phenoscape.kb.KBVocab._ import org.phenoscape.kb.Main.system.dispatcher import org.phenoscape.owl.Vocab._ import org.phenoscape.owlet.SPARQLComposer._ - -import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._ -import akka.http.scaladsl.marshalling.Marshaller -import akka.http.scaladsl.marshalling.ToEntityMarshaller -import spray.json._ -import spray.json.DefaultJsonProtocol._ -import java.util.Date -import org.phenoscape.kb.util.SPARQLInterpolatorOWLAPI._ import org.phenoscape.sparql.SPARQLInterpolation._ import org.phenoscape.sparql.SPARQLInterpolationOWL._ -import org.phenoscape.sparql.SPARQLInterpolation.QueryText -import org.openrdf.model.vocabulary.DCTERMS -import org.apache.jena.vocabulary.DCTerms -import org.semanticweb.owlapi.model.IRI +import org.semanticweb.owlapi.model.{IRI, OWLObjectProperty} +import spray.json.DefaultJsonProtocol._ +import spray.json._ + import java.time.Instant +import scala.concurrent.Future object KB { - val rdfsLabel = org.phenoscape.kb.KBVocab.rdfsLabel + val rdfsLabel: OWLObjectProperty = org.phenoscape.kb.KBVocab.rdfsLabel def annotationSummary: Future[KBAnnotationSummary] = { val matrices = annotatedMatrixCount diff --git a/src/main/scala/org/phenoscape/kb/OWLFormats.scala b/src/main/scala/org/phenoscape/kb/OWLFormats.scala index d311e79c..4ca4c866 100644 --- a/src/main/scala/org/phenoscape/kb/OWLFormats.scala +++ b/src/main/scala/org/phenoscape/kb/OWLFormats.scala @@ -1,13 +1,11 @@ package org.phenoscape.kb +import akka.http.scaladsl.marshalling.{Marshaller, ToEntityMarshaller} +import akka.http.scaladsl.model.MediaTypes +import akka.http.scaladsl.unmarshalling.Unmarshaller import org.phenoscape.owlet.ManchesterSyntaxClassExpressionParser import org.phenoscape.owlet.OwletManchesterSyntaxDataType.SerializableClassExpression import org.semanticweb.owlapi.model.OWLClassExpression - -import akka.http.scaladsl.marshalling.Marshaller -import akka.http.scaladsl.marshalling.ToEntityMarshaller -import akka.http.scaladsl.model.MediaTypes -import akka.http.scaladsl.unmarshalling.Unmarshaller import scalaz._ object OWLFormats { diff --git a/src/main/scala/org/phenoscape/kb/PhenexDataSet.scala b/src/main/scala/org/phenoscape/kb/PhenexDataSet.scala index 41da8b81..bc041765 100644 --- a/src/main/scala/org/phenoscape/kb/PhenexDataSet.scala +++ b/src/main/scala/org/phenoscape/kb/PhenexDataSet.scala @@ -1,14 +1,12 @@ package org.phenoscape.kb -import java.io.StringWriter -import java.util.UUID - +import akka.http.scaladsl.marshalling.{Marshaller, ToEntityMarshaller} +import akka.http.scaladsl.model.MediaTypes import org.phenoscape.io.NeXMLWriter import org.phenoscape.model.DataSet -import akka.http.scaladsl.marshalling.Marshaller -import akka.http.scaladsl.marshalling.ToEntityMarshaller -import akka.http.scaladsl.model.MediaTypes +import java.io.StringWriter +import java.util.UUID object PhenexDataSet { diff --git a/src/main/scala/org/phenoscape/kb/Phenotype.scala b/src/main/scala/org/phenoscape/kb/Phenotype.scala index 857f9190..528d5646 100644 --- a/src/main/scala/org/phenoscape/kb/Phenotype.scala +++ b/src/main/scala/org/phenoscape/kb/Phenotype.scala @@ -20,7 +20,7 @@ import scala.language.postfixOps object Phenotype { - implicit val timeout = Timeout(10 minutes) + private implicit val timeout = Timeout(10 minutes) def info(phenotype: IRI, annotatedStatesOnly: Boolean): Future[Phenotype] = { val eqsFuture = eqForPhenotype(phenotype) diff --git a/src/main/scala/org/phenoscape/kb/PresenceAbsenceOfStructure.scala b/src/main/scala/org/phenoscape/kb/PresenceAbsenceOfStructure.scala index f6251b80..6e848a11 100644 --- a/src/main/scala/org/phenoscape/kb/PresenceAbsenceOfStructure.scala +++ b/src/main/scala/org/phenoscape/kb/PresenceAbsenceOfStructure.scala @@ -1,44 +1,38 @@ package org.phenoscape.kb -import java.net.URI -import java.text.SimpleDateFormat -import java.util.Calendar import org.apache.jena.query.{Query, QuerySolution} import org.apache.jena.rdf.model.{Property, ResourceFactory} import org.apache.jena.sparql.core.Var +import org.apache.jena.sparql.expr.ExprVar import org.apache.jena.sparql.expr.aggregate.{AggCountDistinct, AggCountVarDistinct} -import org.apache.jena.sparql.expr.nodevalue.NodeValueNode -import org.apache.jena.sparql.expr.{E_OneOf, Expr, ExprList, ExprVar} -import org.apache.jena.sparql.syntax.{ElementFilter, ElementSubQuery} +import org.apache.jena.sparql.syntax.ElementSubQuery import org.apache.log4j.Logger import org.obo.datamodel.impl.OBOClassImpl import org.phenoscape.io.NeXMLUtil -import org.phenoscape.kb.KBVocab.{owlNothing, rdfsLabel, rdfsSubClassOf} +import org.phenoscape.kb.KBVocab.{KBMainGraph, rdfsLabel, rdfsSubClassOf} import org.phenoscape.kb.Main.system.dispatcher import org.phenoscape.model.MultipleState.MODE import org.phenoscape.model.{Character, DataSet, MultipleState, State, Taxon => MatrixTaxon} import org.phenoscape.owl.NamedRestrictionGenerator +import org.phenoscape.owl.Vocab.{ABSENCE_OF, IMPLIES_PRESENCE_OF, dcDescription, describes_phenotype, exhibits_state, has_absence_of, has_character, has_presence_of, may_have_state_value, part_of} import org.phenoscape.owlet.OwletManchesterSyntaxDataType.SerializableClassExpression import org.phenoscape.owlet.SPARQLComposer._ import org.phenoscape.scowl._ -import org.semanticweb.owlapi.model.{IRI, OWLClassExpression, OWLEntity} -import uk.ac.manchester.cs.owl.owlapi.OWLClassImpl import org.phenoscape.sparql.SPARQLInterpolation._ import org.phenoscape.sparql.SPARQLInterpolationOWL._ -import org.phenoscape.kb.util.SPARQLInterpolatorOWLAPI._ -import org.phenoscape.kb.KBVocab.KBMainGraph -import org.phenoscape.owl.Vocab.{ABSENCE_OF, IMPLIES_PRESENCE_OF, dcDescription, describes_phenotype, exhibits_state, has_absence_of, has_character, has_presence_of, may_have_state_value, part_of} +import org.semanticweb.owlapi.model.{IRI, OWLClassExpression, OWLEntity} import scalaz.NonEmptyList -import scala.collection.JavaConverters._ +import java.net.URI +import java.text.SimpleDateFormat +import java.util.Calendar import scala.collection.mutable import scala.concurrent.Future +import scala.jdk.CollectionConverters._ import scala.language.{implicitConversions, postfixOps} object PresenceAbsenceOfStructure { - val implies_presence_of_some = NamedRestrictionGenerator.getClassRelationIRI(IMPLIES_PRESENCE_OF.getIRI) - implicit def owlEntityToJenaProperty(prop: OWLEntity): Property = ResourceFactory.createProperty(prop.getIRI.toString) def statesEntailingAbsence(taxon: IRI, diff --git a/src/main/scala/org/phenoscape/kb/ResultCount.scala b/src/main/scala/org/phenoscape/kb/ResultCount.scala index e4a83639..46b6485c 100644 --- a/src/main/scala/org/phenoscape/kb/ResultCount.scala +++ b/src/main/scala/org/phenoscape/kb/ResultCount.scala @@ -1,14 +1,10 @@ package org.phenoscape.kb -import org.apache.jena.query.ResultSet - -import akka.http.scaladsl.marshalling.Marshaller -import akka.http.scaladsl.marshalling.ToEntityMarshaller - import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport.sprayJsonMarshaller - -import spray.json._ +import akka.http.scaladsl.marshalling.{Marshaller, ToEntityMarshaller} +import org.apache.jena.query.ResultSet import spray.json.DefaultJsonProtocol._ +import spray.json._ object ResultCount { diff --git a/src/main/scala/org/phenoscape/kb/Similarity.scala b/src/main/scala/org/phenoscape/kb/Similarity.scala index a5b7578e..736cc1a6 100644 --- a/src/main/scala/org/phenoscape/kb/Similarity.scala +++ b/src/main/scala/org/phenoscape/kb/Similarity.scala @@ -1,38 +1,28 @@ package org.phenoscape.kb -import akka.http.scaladsl.marshalling.{Marshaller, ToEntityMarshaller, ToResponseMarshallable} +import akka.http.scaladsl.marshalling.{Marshaller, ToEntityMarshaller} import akka.http.scaladsl.model.MediaTypes import org.apache.jena.graph.{NodeFactory, Node_Variable} -import org.apache.jena.query.{Query, QueryFactory, QuerySolution} -import org.apache.jena.sparql.core.Var -import org.apache.jena.sparql.expr.{E_NotOneOf, Expr, ExprList, ExprVar} -import org.apache.jena.sparql.path.Path -import org.apache.jena.sparql.expr.aggregate.AggCountVarDistinct -import org.apache.jena.sparql.expr.nodevalue.NodeValueNode +import org.apache.jena.query.{Query, QuerySolution} import org.apache.jena.sparql.path.Path import org.apache.jena.sparql.syntax._ import org.phenoscape.kb.Graph.getTermSubsumerPairs +import org.phenoscape.kb.JSONResultItem.JSONResultItemsMarshaller import org.phenoscape.kb.KBVocab._ import org.phenoscape.kb.Main.system.dispatcher -import org.phenoscape.kb.JSONResultItem.JSONResultItemsMarshaller -import org.phenoscape.owl.{NamedRestrictionGenerator, Vocab} +import org.phenoscape.owl.Vocab import org.phenoscape.owl.Vocab._ import org.phenoscape.owlet.SPARQLComposer._ import org.phenoscape.scowl._ +import org.phenoscape.sparql.FromQuerySolutionOWL._ import org.phenoscape.sparql.SPARQLInterpolation._ import org.phenoscape.sparql.SPARQLInterpolationOWL._ -import org.phenoscape.kb.util.SPARQLInterpolatorOWLAPI._ -import org.phenoscape.sparql.FromQuerySolutionOWL._ -import org.phenoscape.owlet.SPARQLComposer import org.semanticweb.owlapi.model.{IRI, OWLClass, OWLNamedIndividual} import spray.json.DefaultJsonProtocol._ import spray.json._ -import scala.collection.JavaConverters._ -import scala.collection.mutable import scala.concurrent.Future import scala.language.postfixOps -import scala.collection.immutable.ListMap object Similarity { diff --git a/src/main/scala/org/phenoscape/kb/Study.scala b/src/main/scala/org/phenoscape/kb/Study.scala index d4d6ef6c..019431fb 100644 --- a/src/main/scala/org/phenoscape/kb/Study.scala +++ b/src/main/scala/org/phenoscape/kb/Study.scala @@ -4,7 +4,7 @@ import java.util.UUID import akka.http.scaladsl.marshalling.{Marshaller, ToEntityMarshaller} import akka.http.scaladsl.model.MediaTypes -import scala.collection.JavaConverters._ +import scala.jdk.CollectionConverters._ import scala.concurrent.Future import scala.language.implicitConversions import scala.xml.Elem diff --git a/src/main/scala/org/phenoscape/kb/Taxon.scala b/src/main/scala/org/phenoscape/kb/Taxon.scala index fb62b3d1..798bf9be 100644 --- a/src/main/scala/org/phenoscape/kb/Taxon.scala +++ b/src/main/scala/org/phenoscape/kb/Taxon.scala @@ -1,48 +1,36 @@ package org.phenoscape.kb -import scala.collection.JavaConverters._ -import scala.concurrent.Future -import scala.language.postfixOps +import akka.http.scaladsl.marshalling.{Marshaller, ToEntityMarshaller} +import akka.http.scaladsl.model.MediaTypes import org.apache.jena.graph.NodeFactory -import org.apache.jena.query.Query -import org.apache.jena.query.QuerySolution -import org.apache.jena.rdf.model.Model -import org.apache.jena.rdf.model.Resource -import org.apache.jena.rdf.model.ResourceFactory +import org.apache.jena.query.{Query, QuerySolution} +import org.apache.jena.rdf.model.{Model, Resource, ResourceFactory} import org.apache.jena.sparql.core.Var -import org.apache.jena.sparql.expr.{E_Coalesce, Expr, ExprList, ExprVar} -import org.apache.jena.sparql.path.{P_Link, P_OneOrMore1} -import org.apache.jena.sparql.expr.aggregate.AggCountDistinct -import org.apache.jena.sparql.expr.aggregate.AggCountVarDistinct +import org.apache.jena.sparql.expr.aggregate.{AggCountDistinct, AggCountVarDistinct} import org.apache.jena.sparql.expr.nodevalue.NodeValueString -import org.apache.jena.sparql.syntax.ElementBind -import org.apache.jena.sparql.syntax.ElementNamedGraph -import org.apache.jena.sparql.syntax.ElementSubQuery +import org.apache.jena.sparql.expr.{E_Coalesce, Expr, ExprList, ExprVar} +import org.apache.jena.sparql.syntax.{ElementBind, ElementNamedGraph, ElementSubQuery} import org.apache.jena.vocabulary.RDFS import org.phenoscape.kb.Facets.Facet -import org.phenoscape.kb.KBVocab._ -import org.phenoscape.kb.KBVocab.rdfsLabel -import org.phenoscape.kb.KBVocab.rdfsSubClassOf -import org.phenoscape.kb.Main.system.dispatcher import org.phenoscape.kb.JSONResultItem.JSONResultItemsMarshaller -import org.phenoscape.kb.queries.DirectPhenotypesForTaxon -import org.phenoscape.kb.queries.TaxaWithPhenotype +import org.phenoscape.kb.KBVocab.{rdfsLabel, rdfsSubClassOf, _} +import org.phenoscape.kb.Main.system.dispatcher +import org.phenoscape.kb.queries.QueryUtil.{PhenotypicQuality, QualitySpec} +import org.phenoscape.kb.queries.{DirectPhenotypesForTaxon, TaxaWithPhenotype} import org.phenoscape.owl.Vocab import org.phenoscape.owl.Vocab._ import org.phenoscape.owlet.OwletManchesterSyntaxDataType.SerializableClassExpression import org.phenoscape.owlet.SPARQLComposer._ import org.phenoscape.scowl._ -import org.phenoscape.sparql.SPARQLInterpolation.{QueryText, _} +import org.phenoscape.sparql.SPARQLInterpolation._ import org.phenoscape.sparql.SPARQLInterpolationOWL._ -import org.phenoscape.kb.util.SPARQLInterpolatorOWLAPI._ -import org.semanticweb.owlapi.model.{IRI, OWLClassExpression, OWLEntity, OWLObject} -import org.semanticweb.owlapi.model.OWLClassExpression -import akka.http.scaladsl.marshalling.Marshaller -import akka.http.scaladsl.marshalling.ToEntityMarshaller -import akka.http.scaladsl.model.MediaTypes -import org.phenoscape.kb.queries.QueryUtil.{PhenotypicQuality, QualitySpec} -import spray.json._ +import org.semanticweb.owlapi.model.{IRI, OWLClassExpression} import spray.json.DefaultJsonProtocol._ +import spray.json._ + +import scala.concurrent.Future +import scala.jdk.CollectionConverters._ +import scala.language.postfixOps object Taxon { diff --git a/src/main/scala/org/phenoscape/kb/Term.scala b/src/main/scala/org/phenoscape/kb/Term.scala index fc25b371..d1f4ac4f 100644 --- a/src/main/scala/org/phenoscape/kb/Term.scala +++ b/src/main/scala/org/phenoscape/kb/Term.scala @@ -1,6 +1,5 @@ package org.phenoscape.kb -import java.util.regex.Pattern import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._ import akka.http.scaladsl.marshalling.{Marshaller, ToEntityMarshaller} import akka.http.scaladsl.model.MediaTypes @@ -10,14 +9,12 @@ import org.apache.jena.query.{Query, QueryFactory, QuerySolution} import org.apache.jena.sparql.core.Var import org.apache.jena.sparql.expr._ import org.apache.jena.sparql.expr.aggregate.AggMin -import org.apache.jena.sparql.expr.nodevalue.NodeValueNode import org.apache.jena.sparql.path.{P_Link, P_OneOrMore1} import org.apache.jena.sparql.syntax.{Element, ElementFilter, ElementGroup, ElementUnion} import org.phenoscape.kb.KBVocab.{rdfsLabel, rdfsSubClassOf, _} import org.phenoscape.kb.Main.system.dispatcher import org.phenoscape.kb.ingest.util.ExpressionUtil import org.phenoscape.kb.util.SPARQLEntityChecker -import org.phenoscape.kb.util.SPARQLInterpolatorOWLAPI._ import org.phenoscape.owl.NamedRestrictionGenerator import org.phenoscape.owl.Vocab._ import org.phenoscape.owl.util.ExpressionsUtil @@ -35,7 +32,8 @@ import spray.json.DefaultJsonProtocol._ import spray.json._ import java.net.{URLDecoder, URLEncoder} -import scala.collection.JavaConverters._ +import java.util.regex.Pattern +import scala.jdk.CollectionConverters._ import scala.collection.mutable import scala.concurrent.Future import scala.language.postfixOps diff --git a/src/main/scala/org/phenoscape/kb/queries/DirectPhenotypesForTaxon.scala b/src/main/scala/org/phenoscape/kb/queries/DirectPhenotypesForTaxon.scala index 4a8349e2..d9aa7fde 100644 --- a/src/main/scala/org/phenoscape/kb/queries/DirectPhenotypesForTaxon.scala +++ b/src/main/scala/org/phenoscape/kb/queries/DirectPhenotypesForTaxon.scala @@ -8,7 +8,7 @@ import org.phenoscape.kb.util.BlazegraphNamedSubquery import org.phenoscape.sparql.SPARQLInterpolationOWL._ import org.phenoscape.owl.Vocab._ import org.phenoscape.sparql.SPARQLInterpolation.{QueryText, _} -import org.phenoscape.kb.util.SPARQLInterpolatorOWLAPI._ +import org.phenoscape.kb.util.SPARQLInterpolatorBlazegraph._ import org.semanticweb.owlapi.model.IRI import scalaz.Scalaz._ import scalaz._ diff --git a/src/main/scala/org/phenoscape/kb/queries/GeneAffectingPhenotype.scala b/src/main/scala/org/phenoscape/kb/queries/GeneAffectingPhenotype.scala index e045fc9b..ed1f8f19 100644 --- a/src/main/scala/org/phenoscape/kb/queries/GeneAffectingPhenotype.scala +++ b/src/main/scala/org/phenoscape/kb/queries/GeneAffectingPhenotype.scala @@ -4,7 +4,7 @@ import org.phenoscape.kb.AnatomicalEntity import org.phenoscape.kb.KBVocab.{rdfsSubClassOf, _} import org.phenoscape.kb.Main.system.dispatcher import org.phenoscape.kb.util.BlazegraphNamedSubquery -import org.phenoscape.kb.util.SPARQLInterpolatorOWLAPI._ +import org.phenoscape.kb.util.SPARQLInterpolatorBlazegraph._ import org.phenoscape.sparql.SPARQLInterpolationOWL._ import org.phenoscape.owl.NamedRestrictionGenerator import org.phenoscape.owl.Vocab._ diff --git a/src/main/scala/org/phenoscape/kb/queries/StudiesRelevantToPhenotype.scala b/src/main/scala/org/phenoscape/kb/queries/StudiesRelevantToPhenotype.scala index 761e8696..612ccafe 100644 --- a/src/main/scala/org/phenoscape/kb/queries/StudiesRelevantToPhenotype.scala +++ b/src/main/scala/org/phenoscape/kb/queries/StudiesRelevantToPhenotype.scala @@ -5,7 +5,7 @@ import org.phenoscape.kb.KBVocab.{rdfsLabel, rdfsSubClassOf, _} import org.phenoscape.kb.Main.system.dispatcher import org.phenoscape.kb.queries.QueryUtil.QualitySpec import org.phenoscape.kb.util.BlazegraphNamedSubquery -import org.phenoscape.kb.util.SPARQLInterpolatorOWLAPI._ +import org.phenoscape.kb.util.SPARQLInterpolatorBlazegraph._ import org.phenoscape.sparql.SPARQLInterpolationOWL._ import org.phenoscape.owl.Vocab._ import org.phenoscape.sparql.SPARQLInterpolation.{QueryText, _} diff --git a/src/main/scala/org/phenoscape/kb/queries/TaxaWithPhenotype.scala b/src/main/scala/org/phenoscape/kb/queries/TaxaWithPhenotype.scala index a38fad36..d22e8eec 100644 --- a/src/main/scala/org/phenoscape/kb/queries/TaxaWithPhenotype.scala +++ b/src/main/scala/org/phenoscape/kb/queries/TaxaWithPhenotype.scala @@ -6,7 +6,7 @@ import org.phenoscape.kb.KBVocab.{rdfsSubClassOf, _} import org.phenoscape.kb.Main.system.dispatcher import org.phenoscape.kb.queries.QueryUtil.{InferredAbsence, InferredPresence, PhenotypicQuality, QualitySpec} import org.phenoscape.kb.util.BlazegraphNamedSubquery -import org.phenoscape.kb.util.SPARQLInterpolatorOWLAPI._ +import org.phenoscape.kb.util.SPARQLInterpolatorBlazegraph._ import org.phenoscape.sparql.SPARQLInterpolationOWL._ import org.phenoscape.owl.NamedRestrictionGenerator import org.phenoscape.owl.Vocab._ diff --git a/src/main/scala/org/phenoscape/kb/queries/TaxonAnnotations.scala b/src/main/scala/org/phenoscape/kb/queries/TaxonAnnotations.scala index 29e85a41..eb062c88 100644 --- a/src/main/scala/org/phenoscape/kb/queries/TaxonAnnotations.scala +++ b/src/main/scala/org/phenoscape/kb/queries/TaxonAnnotations.scala @@ -5,7 +5,7 @@ import org.phenoscape.kb.KBVocab.{rdfsSubClassOf, _} import org.phenoscape.kb.Main.system.dispatcher import org.phenoscape.kb.queries.QueryUtil.QualitySpec import org.phenoscape.kb.util.BlazegraphNamedSubquery -import org.phenoscape.kb.util.SPARQLInterpolatorOWLAPI._ +import org.phenoscape.kb.util.SPARQLInterpolatorBlazegraph._ import org.phenoscape.owl.Vocab._ import org.phenoscape.scowl._ import org.phenoscape.sparql.SPARQLInterpolation.{QueryText, _} diff --git a/src/main/scala/org/phenoscape/kb/queries/TaxonPhenotypes.scala b/src/main/scala/org/phenoscape/kb/queries/TaxonPhenotypes.scala index 5cd58bf7..2bdd4556 100644 --- a/src/main/scala/org/phenoscape/kb/queries/TaxonPhenotypes.scala +++ b/src/main/scala/org/phenoscape/kb/queries/TaxonPhenotypes.scala @@ -5,7 +5,7 @@ import org.phenoscape.kb.KBVocab.{rdfsSubClassOf, _} import org.phenoscape.kb.Main.system.dispatcher import org.phenoscape.kb.queries.QueryUtil.QualitySpec import org.phenoscape.kb.util.BlazegraphNamedSubquery -import org.phenoscape.kb.util.SPARQLInterpolatorOWLAPI._ +import org.phenoscape.kb.util.SPARQLInterpolatorBlazegraph._ import org.phenoscape.owl.Vocab._ import org.phenoscape.scowl._ import org.phenoscape.sparql.SPARQLInterpolation.{QueryText, _} diff --git a/src/main/scala/org/phenoscape/kb/util/SPARQLEntityChecker.scala b/src/main/scala/org/phenoscape/kb/util/SPARQLEntityChecker.scala index ab6bb50d..0e8f789f 100644 --- a/src/main/scala/org/phenoscape/kb/util/SPARQLEntityChecker.scala +++ b/src/main/scala/org/phenoscape/kb/util/SPARQLEntityChecker.scala @@ -10,7 +10,7 @@ import org.apache.jena.sparql.syntax.ElementGroup import org.apache.jena.vocabulary.RDF import org.apache.jena.vocabulary.RDFS import org.phenoscape.kb.KBVocab.KBMainGraph -import org.phenoscape.kb.util.SPARQLInterpolatorOWLAPI._ +import org.phenoscape.kb.util.SPARQLInterpolatorBlazegraph._ import org.phenoscape.sparql.SPARQLInterpolation._ import org.phenoscape.sparql.SPARQLInterpolationOWL._ import org.semanticweb.owlapi.apibinding.OWLManager diff --git a/src/main/scala/org/phenoscape/kb/util/SPARQLInterpolatorOWLAPI.scala b/src/main/scala/org/phenoscape/kb/util/SPARQLInterpolatorBlazegraph.scala similarity index 71% rename from src/main/scala/org/phenoscape/kb/util/SPARQLInterpolatorOWLAPI.scala rename to src/main/scala/org/phenoscape/kb/util/SPARQLInterpolatorBlazegraph.scala index 763ac215..d42437aa 100644 --- a/src/main/scala/org/phenoscape/kb/util/SPARQLInterpolatorOWLAPI.scala +++ b/src/main/scala/org/phenoscape/kb/util/SPARQLInterpolatorBlazegraph.scala @@ -4,9 +4,9 @@ import contextual._ import org.phenoscape.sparql.SPARQLInterpolation.SPARQLInterpolator.SPARQLContext import org.phenoscape.sparql.SPARQLInterpolation._ -object SPARQLInterpolatorOWLAPI { +object SPARQLInterpolatorBlazegraph { - implicit val embedSubqueryReferenceInSPARQL = + implicit val embedSubqueryReferenceInSPARQL: SPARQLEmbedder[BlazegraphNamedSubquery] = SPARQLInterpolator.embed[BlazegraphNamedSubquery](Case(SPARQLContext, SPARQLContext)(q => s"INCLUDE %${q.ids.min}")) } diff --git a/src/main/scala/org/phenoscape/kb/util/Util.scala b/src/main/scala/org/phenoscape/kb/util/Util.scala index b748ce56..790c274e 100644 --- a/src/main/scala/org/phenoscape/kb/util/Util.scala +++ b/src/main/scala/org/phenoscape/kb/util/Util.scala @@ -2,13 +2,6 @@ package org.phenoscape.kb.util object Util { - implicit class TraversableOps[A](self: Traversable[A]) { - - def groupMap[K, B](key: A => K)(f: A => B): Map[K, Set[B]] = - self.groupBy(key).map { case (k, vs) => k -> vs.map(f).toSet } - - } - implicit class MapOps[K, V](self: Map[K, V]) { /** From a4aaaa3bac4a166d99074049d531c64fb9c0ce89 Mon Sep 17 00:00:00 2001 From: Jim Balhoff Date: Wed, 1 Dec 2021 15:02:10 -0500 Subject: [PATCH 2/2] Restore definition. --- .../kb/PresenceAbsenceOfStructure.scala | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/scala/org/phenoscape/kb/PresenceAbsenceOfStructure.scala b/src/main/scala/org/phenoscape/kb/PresenceAbsenceOfStructure.scala index 6e848a11..9b32a320 100644 --- a/src/main/scala/org/phenoscape/kb/PresenceAbsenceOfStructure.scala +++ b/src/main/scala/org/phenoscape/kb/PresenceAbsenceOfStructure.scala @@ -9,12 +9,12 @@ import org.apache.jena.sparql.syntax.ElementSubQuery import org.apache.log4j.Logger import org.obo.datamodel.impl.OBOClassImpl import org.phenoscape.io.NeXMLUtil -import org.phenoscape.kb.KBVocab.{KBMainGraph, rdfsLabel, rdfsSubClassOf} +import org.phenoscape.kb.KBVocab.{rdfsLabel, rdfsSubClassOf, KBMainGraph} import org.phenoscape.kb.Main.system.dispatcher import org.phenoscape.model.MultipleState.MODE import org.phenoscape.model.{Character, DataSet, MultipleState, State, Taxon => MatrixTaxon} import org.phenoscape.owl.NamedRestrictionGenerator -import org.phenoscape.owl.Vocab.{ABSENCE_OF, IMPLIES_PRESENCE_OF, dcDescription, describes_phenotype, exhibits_state, has_absence_of, has_character, has_presence_of, may_have_state_value, part_of} +import org.phenoscape.owl.Vocab.{dcDescription, describes_phenotype, exhibits_state, has_absence_of, has_character, has_presence_of, may_have_state_value, part_of, ABSENCE_OF, IMPLIES_PRESENCE_OF} import org.phenoscape.owlet.OwletManchesterSyntaxDataType.SerializableClassExpression import org.phenoscape.owlet.SPARQLComposer._ import org.phenoscape.scowl._ @@ -33,6 +33,8 @@ import scala.language.{implicitConversions, postfixOps} object PresenceAbsenceOfStructure { + val implies_presence_of_some = NamedRestrictionGenerator.getClassRelationIRI(IMPLIES_PRESENCE_OF.getIRI) + implicit def owlEntityToJenaProperty(prop: OWLEntity): Property = ResourceFactory.createProperty(prop.getIRI.toString) def statesEntailingAbsence(taxon: IRI, @@ -173,19 +175,19 @@ object PresenceAbsenceOfStructure { taxonClass: Option[OWLClassExpression], taxonList: Option[NonEmptyList[IRI]]): Query = { val entityExpressionQueryOpt = entityClass.map(cls => sparql" ?entity $rdfsSubClassOf ${cls.asOMN} . ") - val entityValuesOpt = entityList.flatMap(list => list.map(iri => sparql" $iri ").list.reduceLeftOption(_ + _)).map { - iris => + val entityValuesOpt = + entityList.flatMap(list => list.map(iri => sparql" $iri ").list.reduceLeftOption(_ + _)).map { iris => sparql"VALUES ?entity { $iris }" - } + } val entityQuery = (entityExpressionQueryOpt, entityValuesOpt) match { case (Some(expressionQuery), Some(entityValues)) => sparql"{ $expressionQuery } UNION { $entityValues } " case _ => entityExpressionQueryOpt.orElse(entityValuesOpt).getOrElse(sparql"") } val taxonExpressionQueryOpt = taxonClass.map(cls => sparql" ?taxon $rdfsSubClassOf ${cls.asOMN} . ") - val taxonValuesOpt = taxonList.flatMap(list => list.map(iri => sparql" $iri ").list.reduceLeftOption(_ + _)).map { - iris => + val taxonValuesOpt = + taxonList.flatMap(list => list.map(iri => sparql" $iri ").list.reduceLeftOption(_ + _)).map { iris => sparql"VALUES ?taxon { $iris }" - } + } val taxonQuery = (taxonExpressionQueryOpt, taxonValuesOpt) match { case (Some(expressionQuery), Some(taxonValues)) => sparql"{ $expressionQuery } UNION { $taxonValues } " case _ => taxonExpressionQueryOpt.orElse(taxonValuesOpt).getOrElse(sparql"")