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
feat(api-v2): Make inference optional in Gravsearch #1696
Changes from 9 commits
990fb05
154fb43
fa15b2c
02d4d94
4295d27
98b76d6
79362b9
3572b78
609dd75
a7f3a1c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -573,19 +573,32 @@ case class OrderCriterion(queryVariable: QueryVariable, isAscending: Boolean) ex | |
} | ||
} | ||
|
||
/** | ||
* Represents a FROM clause. | ||
* | ||
* @param namedGraph the named graph to be used in the query. | ||
*/ | ||
case class FromClause(namedGraph: IriRef) extends SparqlGenerator { | ||
override def toSparql: String = s"FROM ${namedGraph.toSparql}\n" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we have a named graph here, shouldn't we use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, this is confusing. For me, any graph in the triplestore that has a name is a "named graph". The pseudo-graph I've clarified this in a7f3a1c. |
||
} | ||
|
||
/** | ||
* Represents a SPARQL CONSTRUCT query. | ||
* | ||
* @param constructClause the CONSTRUCT clause. | ||
* @param fromClause the FROM clause, if any. | ||
* @param whereClause the WHERE clause. | ||
* @param orderBy the variables that the results should be ordered by. | ||
* @param offset if this is a Gravsearch query, represents the OFFSET specified in the query. | ||
* @param querySchema if this is a Gravsearch query, represents the Knora API v2 ontology schema used in the query. | ||
*/ | ||
case class ConstructQuery(constructClause: ConstructClause, whereClause: WhereClause, orderBy: Seq[OrderCriterion] = Seq.empty[OrderCriterion], offset: Long = 0, querySchema: Option[ApiV2Schema] = None) extends SparqlGenerator { | ||
case class ConstructQuery(constructClause: ConstructClause, fromClause: Option[FromClause] = None, whereClause: WhereClause, orderBy: Seq[OrderCriterion] = Seq.empty[OrderCriterion], offset: Long = 0, querySchema: Option[ApiV2Schema] = None) extends SparqlGenerator { | ||
override def toSparql: String = { | ||
val stringBuilder = new StringBuilder | ||
stringBuilder.append(constructClause.toSparql).append(whereClause.toSparql) | ||
|
||
stringBuilder.append(constructClause.toSparql) | ||
.append(fromClause.map(_.toSparql).getOrElse("")) | ||
.append(whereClause.toSparql) | ||
|
||
if (orderBy.nonEmpty) { | ||
stringBuilder.append("ORDER BY ").append(orderBy.map(_.toSparql).mkString(" ")).append("\n") | ||
|
@@ -604,12 +617,13 @@ case class ConstructQuery(constructClause: ConstructClause, whereClause: WhereCl | |
* | ||
* @param variables the variables to be returned by the query. | ||
* @param useDistinct indicates if DISTINCT should be used. | ||
* @param fromClause the FROM clause, if any. | ||
* @param whereClause the WHERE clause. | ||
* @param orderBy the variables that the results should be ordered by. | ||
* @param limit the maximum number of result rows to be returned. | ||
* @param offset the offset to be used (limit of the previous query + 1 to do paging). | ||
*/ | ||
case class SelectQuery(variables: Seq[SelectQueryColumn], useDistinct: Boolean = true, whereClause: WhereClause, groupBy: Seq[QueryVariable] = Seq.empty[QueryVariable], orderBy: Seq[OrderCriterion] = Seq.empty[OrderCriterion], limit: Option[Int] = None, offset: Long = 0) extends SparqlGenerator { | ||
case class SelectQuery(variables: Seq[SelectQueryColumn], useDistinct: Boolean = true, fromClause: Option[FromClause] = None, whereClause: WhereClause, groupBy: Seq[QueryVariable] = Seq.empty[QueryVariable], orderBy: Seq[OrderCriterion] = Seq.empty[OrderCriterion], limit: Option[Int] = None, offset: Long = 0) extends SparqlGenerator { | ||
override def toSparql: String = { | ||
val stringBuilder = new StringBuilder | ||
|
||
|
@@ -620,7 +634,9 @@ case class SelectQuery(variables: Seq[SelectQueryColumn], useDistinct: Boolean = | |
|
||
} | ||
|
||
stringBuilder.append(variables.map(_.toSparql).mkString(" ")).append("\n").append(whereClause.toSparql) | ||
stringBuilder.append(variables.map(_.toSparql).mkString(" ")).append("\n") | ||
.append(fromClause.map(_.toSparql).getOrElse("")) | ||
.append(whereClause.toSparql) | ||
|
||
if (groupBy.nonEmpty) { | ||
stringBuilder.append("GROUP BY ").append(groupBy.map(_.toSparql).mkString(" ")).append("\n") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@benjamingeer question: why are using
lazy val
here in the following three cases? The initialization does not need any evaluation of an expression, it is just a set. In this case, it would not make any difference if the initialization happens immediately or is postponed to the first time the value is accessed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great question! The problem is that
KnoraApiV2ResourceIris
is a static value (it's defined in anobject
rather than in aclass
), which refers to static values in anotherobject
. The order of initialisation of static values in the JVM depends on whichobject
is loaded first by the JVM's class loader at run time. Without thelazy
, ifobject KnoraApi
is initialised beforeobject KnoraApiV2Simple
andobject KnoraApiV2Complex
,KnoraApiV2ResourceIris
will just containnull
values. It took me a little while to figure this out yesterday. A test was failing, and it turned out that it was becauseKnoraApiV2ResourceIris
did not containOntologyConstants.KnoraApiV2Complex.Resource
, because it hadn't been initialised properly.In the earlier code, there was a method, which didn't access those constants until it was called, so it was fine.