Skip to content
Permalink
Browse files

fix(api-v1): Optimise link value queries for Fuseki (DSP-1243) (#1791)

  • Loading branch information
benjamingeer committed Jan 22, 2021
1 parent 6f14aee commit b1e1b9eeb73d7aaa0a46fc3060fd64e4d550c09f
@@ -136,11 +136,11 @@ object StandoffTagUtilV2 {
standoffPropertyEntities(standoffTagPropIri).entityInfoContent.predicates

// check if a cardinality exists for the current attribute
if (classSpecificProps.get(standoffTagPropIri).isEmpty) {
if (!classSpecificProps.contains(standoffTagPropIri)) {
throw BadRequestException(s"no cardinality defined for attr '${attr.key}'")
}

if (propPredicates.get(OntologyConstants.KnoraBase.ObjectDatatypeConstraint.toSmartIri).isDefined) {
if (propPredicates.contains(OntologyConstants.KnoraBase.ObjectDatatypeConstraint.toSmartIri)) {
// property is a data type property

val propDatatypeConstraint = propPredicates(OntologyConstants.KnoraBase.ObjectDatatypeConstraint.toSmartIri)
@@ -45,44 +45,37 @@ SELECT ?linkValue ?directLinkExists ?targetResourceClass ?objPred ?objObj
FROM <http://www.ontotext.com/explicit>
}
WHERE {
BIND(IRI("@subjectIri") AS ?subject)
BIND(IRI("@predicateIri") AS ?predicate)
BIND(IRI("@{predicateIri}Value") AS ?predicateForLinkValue)

@maybeObjectIri match {
case Some(objectIri) => {

BIND(IRI("@objectIri") AS ?object)
BIND(IRI("@linkValueIri") AS ?linkValue)

}
<@linkValueIri> rdf:type knora-base:LinkValue .

case None => {}
FILTER NOT EXISTS {
<@linkValueIri> knora-base:isDeleted true .
}

BIND(IRI("@linkValueIri") AS ?linkValue)
OPTIONAL {
@maybeObjectIri match {
case Some(objectIri) => {
<@objectIri> rdf:type ?targetResourceClass .
}

?subject ?predicateForLinkValue ?linkValue .
?linkValue rdf:type knora-base:LinkValue ;
rdf:subject ?subject ;
rdf:predicate ?predicate ;
rdf:object ?object ;
knora-base:isDeleted false .
case None => {
<@subjectIri> <@predicateIri> ?object .
?object rdf:type ?targetResourceClass .
}
}

OPTIONAL {
?subject ?predicate ?object .
?object rdf:type ?targetResourceClass .
BIND(true AS ?directLinkExists)
}

{
?linkValue ?objPred ?objObj .
<@linkValueIri> ?objPred ?objObj .
}
UNION
{
@* Return the project of the resource that contains the value. *@

?subject ?predicateForLinkValue ?linkValue . @* TODO: Why do we need this here? (Issue 235) *@
?subject knora-base:attachedToProject ?resourceProject .
<@subjectIri> knora-base:attachedToProject ?resourceProject .

BIND(knora-base:attachedToProject AS ?objPred)
BIND(?resourceProject AS ?objObj)
@@ -47,23 +47,22 @@ SELECT ?linkValue ?directLinkExists ?targetResourceClass ?objPred ?objObj
FROM <http://www.ontotext.com/explicit>
}
WHERE {
BIND(IRI("@subjectIri") AS ?subject)
BIND(IRI("@predicateIri") AS ?predicate)
BIND(IRI("@{predicateIri}Value") AS ?predicateForLinkValue)
BIND(IRI("@objectIri") AS ?object)
<@subjectIri> <@{predicateIri}Value> ?linkValue .

?subject ?predicateForLinkValue ?linkValue .
?linkValue rdf:type knora-base:LinkValue ;
@if(!includeDeleted) {
knora-base:isDeleted false ;
rdf:subject <@subjectIri> ;
rdf:predicate <@predicateIri> ;
rdf:object <@objectIri> .

@if(!includeDeleted) {
FILTER NOT EXISTS {
?linkValue knora-base:isDeleted true ;
}
rdf:subject ?subject ;
rdf:predicate ?predicate ;
rdf:object ?object .
}

OPTIONAL {
?subject ?predicate ?object .
?object rdf:type ?targetResourceClass .
<@subjectIri> <@predicateIri> <@objectIri> .
<@objectIri> rdf:type ?targetResourceClass .
BIND(true AS ?directLinkExists)
}

@@ -76,8 +75,7 @@ WHERE {
{
@* Return the project of the resource that contains the value. *@

?subject ?predicateForLinkValue ?linkValue . @* TODO: Why do we need this here? (Issue 235) *@
?subject knora-base:attachedToProject ?resourceProject .
<@subjectIri> knora-base:attachedToProject ?resourceProject .

BIND(knora-base:attachedToProject AS ?objPred)
BIND(?resourceProject AS ?objObj)
@@ -113,6 +113,7 @@ scala_test(
"//webapi:test_library",
"@maven//:org_scala_lang_modules_scala_xml_2_12",
"@maven//:org_xmlunit_xmlunit_core",
"@maven//:com_jsuereth_scala_arm_2_12",
] + BASE_TEST_DEPENDENCIES_WITH_JSON,
)

0 comments on commit b1e1b9e

Please sign in to comment.