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

Commit

Permalink
Remove prefixes and embedded IRIs from SPARQL queries (#605)
Browse files Browse the repository at this point in the history
This PR removes prefixes and embedded IRIs from SPARQL queries in QueryService.
  • Loading branch information
gaurav authored Dec 1, 2022
2 parents 05f5394 + 95db8e7 commit dbc7bed
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/main/scala/org/renci/cam/QueryService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ object QueryService extends LazyLogging {

val BiolinkNamedThing: BiolinkClass = BiolinkClass("NamedThing", IRI(s"${BiolinkTerm.namespace}NamedThing"))

/* Hints used to optimize the query (see https://github.com/blazegraph/database/wiki/QueryHints for details). */

val BigDataQueryHintQuery = IRI("http://www.bigdata.com/queryHints#Query")

val BigDataQueryHintFilterExists = IRI("http://www.bigdata.com/queryHints#filterExists")

val BigDataQueryHintPrior = IRI("http://www.bigdata.com/queryHints#Prior")

val BigDataQueryHintRunFirst = IRI("http://www.bigdata.com/queryHints#runFirst")

final case class TRAPIEdgeKey(source_id: String, `type`: Option[BiolinkPredicate], target_id: String)

final case class Triple(subj: IRI, pred: IRI, obj: IRI)
Expand Down Expand Up @@ -474,9 +484,7 @@ object QueryService extends LazyLogging {
val edgePatterns = queryEdgeSparql.fold(sparql"")(_ + _)
val limitSparql = if (limit > 0) sparql" LIMIT $limit" else sparql""
val queryString =
sparql"""PREFIX hint: <http://www.bigdata.com/queryHints#>

SELECT DISTINCT $typeProjections
sparql"""SELECT DISTINCT $typeProjections
(GROUP_CONCAT(DISTINCT ?g; SEPARATOR='|') AS ?graphs)
(GROUP_CONCAT(DISTINCT ?d; SEPARATOR='|') AS ?derivedFrom)
WHERE {
Expand All @@ -488,7 +496,7 @@ object QueryService extends LazyLogging {
$edgePatterns
}
}
hint:Prior hint:runFirst true .
$BigDataQueryHintPrior $BigDataQueryHintRunFirst true .
}
GROUP BY $typeProjections
$limitSparql
Expand Down Expand Up @@ -840,7 +848,7 @@ object QueryService extends LazyLogging {
VALUES ?biolinkPredicate { ${predicates.asValues} }
?predicate $SlotMapping ?biolinkPredicate .
FILTER EXISTS { ?s ?predicate ?o }
<http://www.bigdata.com/queryHints#Query> <http://www.bigdata.com/queryHints#filterExists> "SubQueryLimitOne"
$BigDataQueryHintQuery $BigDataQueryHintFilterExists "SubQueryLimitOne"
}"""
for {
predicates <- SPARQLQueryExecutor.runSelectQueryWithCacheAs[Predicate](queryText.toQuery)
Expand Down

0 comments on commit dbc7bed

Please sign in to comment.