Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Commit

Permalink
Speed up related_to query. (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
balhoff authored Nov 29, 2022
1 parent 3ef2932 commit 4c6764a
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/main/scala/org/renci/cam/QueryService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ object QueryService {
val sourceIRI = IRI(solution.getResource(sourceVar).getURI)
val targetIRI = IRI(solution.getResource(targetVar).getURI)
val predicateIRI = IRI(solution.getResource(predicateVar).getURI)
val category = makeBiolinkTerm(IRI(solution.getResource(s"${categoryVar}_first").getURI))
val category = makeBiolinkTerm(
Option(solution.getResource(s"${categoryVar}_first")).map(_.getURI).map(IRI(_)).getOrElse(BiolinkRelatedTo.iri))
val edgeKGID =
DigestUtils.sha1Hex(s"${sourceIRI.value}${predicateIRI.value}${targetIRI.value}".getBytes(StandardCharsets.UTF_8))
val trapiEdge = TRAPIEdge(Some(category), sourceIRI, targetIRI, Some(List(StandardProvenance)))
Expand Down Expand Up @@ -199,9 +200,7 @@ object QueryService {
if (edgeTypes == List(BiolinkRelatedTo)) {
(sparql"""
GRAPH $BiolinkModelGraph {
{ $predVar $BiolinkCategory $categoryVar . }
UNION
{ BIND(${BiolinkRelatedTo.iri} AS $categoryVar) }
$predVar $BiolinkCategory $categoryVar .
FILTER NOT EXISTS {
$predVar $BiolinkCategory $category2Var .
FILTER($categoryVar != $category2Var)
Expand Down

0 comments on commit 4c6764a

Please sign in to comment.