Skip to content

Commit

Permalink
Merge pull request #3007 from HASMAC-AS/GH-3004-rsx-targetshape-perfo…
Browse files Browse the repository at this point in the history
…rmance
  • Loading branch information
hmottestad authored Apr 23, 2021
2 parents ca80fa0 + d91337c commit 0d33b7b
Show file tree
Hide file tree
Showing 120 changed files with 2,307 additions and 597 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
******************************************************************************/
package org.eclipse.rdf4j.sail.shacl.ast;

import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -230,41 +232,16 @@ public SparqlFragment buildSparqlValidNodes_rsx_targetShape(StatementMatcher.Var
StatementMatcher.Variable object,
RdfsSubClassOfReasoner rdfsSubClassOfReasoner, Scope scope) {

boolean isFilterCondition = constraintComponents.stream()
.map(o -> o.buildSparqlValidNodes_rsx_targetShape(subject, object, rdfsSubClassOfReasoner,
List<SparqlFragment> sparqlFragments = constraintComponents.stream()
.map(shape -> shape.buildSparqlValidNodes_rsx_targetShape(subject, object, rdfsSubClassOfReasoner,
Scope.nodeShape))
.map(SparqlFragment::isFilterCondition)
.findFirst()
.orElse(false);

if (isFilterCondition) {
String sparql = constraintComponents.stream()
.map(c -> c.buildSparqlValidNodes_rsx_targetShape(subject, object, rdfsSubClassOfReasoner,
Scope.nodeShape))
.map(SparqlFragment::getFragment)
.collect(Collectors.joining(" ) && ( ", "( ", " )"));

return SparqlFragment.filterCondition(sparql);
.collect(Collectors.toList());

if (SparqlFragment.isFilterCondition(sparqlFragments)) {
return SparqlFragment.and(sparqlFragments);
} else {
String sparql = constraintComponents.stream()
.map(c -> c.buildSparqlValidNodes_rsx_targetShape(subject, object, rdfsSubClassOfReasoner,
Scope.nodeShape))
.map(SparqlFragment::getFragment)
.reduce((a, b) -> a + "\n" + b)
.orElse("");
return SparqlFragment.bgp(sparql);
return SparqlFragment.join(sparqlFragments);
}
}

@Override
public Stream<StatementMatcher> getStatementMatchers_rsx_targetShape(StatementMatcher.Variable subject,
StatementMatcher.Variable object,
RdfsSubClassOfReasoner rdfsSubClassOfReasoner, Scope scope) {

return constraintComponents.stream()
.flatMap(c -> c.getStatementMatchers_rsx_targetShape(subject, object,
rdfsSubClassOfReasoner, Scope.nodeShape));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
******************************************************************************/
package org.eclipse.rdf4j.sail.shacl.ast;

import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.UUID;
Expand Down Expand Up @@ -279,47 +280,17 @@ public SparqlFragment buildSparqlValidNodes_rsx_targetShape(StatementMatcher.Var
StatementMatcher.Variable object,
RdfsSubClassOfReasoner rdfsSubClassOfReasoner, Scope scope) {

StatementMatcher.Variable someObject = new StatementMatcher.Variable(
UUID.randomUUID().toString().replace("-", ""));

boolean isFilterCondition = constraintComponents.stream()
.map(o -> o.buildSparqlValidNodes_rsx_targetShape(object, someObject, rdfsSubClassOfReasoner,
Scope.propertyShape))
.map(SparqlFragment::isFilterCondition)
.findFirst()
.orElse(false);

if (isFilterCondition) {
String sparql = constraintComponents.stream()
.map(c -> c.buildSparqlValidNodes_rsx_targetShape(object, someObject, rdfsSubClassOfReasoner,
Scope.propertyShape))
.map(SparqlFragment::getFragment)
.collect(Collectors.joining(" ) && ( ", "( ", " )"));

return SparqlFragment.filterCondition(sparql);
List<SparqlFragment> sparqlFragments = constraintComponents.stream()
.map(shape -> shape.buildSparqlValidNodes_rsx_targetShape(object,
StatementMatcher.Variable.getRandomInstance(), rdfsSubClassOfReasoner, Scope.propertyShape))
.collect(Collectors.toList());

if (SparqlFragment.isFilterCondition(sparqlFragments)) {
return SparqlFragment.and(sparqlFragments);
} else {
String sparql = constraintComponents.stream()
.map(c -> c.buildSparqlValidNodes_rsx_targetShape(object, someObject, rdfsSubClassOfReasoner,
Scope.propertyShape))
.map(SparqlFragment::getFragment)
.reduce((a, b) -> a + "\n" + b)
.orElse("");
return SparqlFragment.bgp(sparql);
return SparqlFragment.join(sparqlFragments);
}

}

@Override
public Stream<StatementMatcher> getStatementMatchers_rsx_targetShape(StatementMatcher.Variable subject,
StatementMatcher.Variable object,
RdfsSubClassOfReasoner rdfsSubClassOfReasoner, Scope scope) {
StatementMatcher.Variable someObject = new StatementMatcher.Variable(
UUID.randomUUID().toString().replace("-", ""));

return constraintComponents.stream()
.flatMap(c -> c.getStatementMatchers_rsx_targetShape(object, someObject, rdfsSubClassOfReasoner,
Scope.propertyShape));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -264,26 +264,6 @@ List<ConstraintComponent> getConstraintComponents(ShaclProperties properties, Re
properties.getIgnoredProperties()));
}

properties.getOr()
.stream()
.map(or -> new OrConstraintComponent(or, connection, cache, shaclSail))
.forEach(constraintComponent::add);

properties.getXone()
.stream()
.map(xone -> new XoneConstraintComponent(xone, connection, cache, shaclSail))
.forEach(constraintComponent::add);

properties.getAnd()
.stream()
.map(and -> new AndConstraintComponent(and, connection, cache, shaclSail))
.forEach(constraintComponent::add);

properties.getNot()
.stream()
.map(or -> new NotConstraintComponent(or, connection, cache, shaclSail))
.forEach(constraintComponent::add);

properties.getClazz()
.stream()
.map(ClassConstraintComponent::new)
Expand Down Expand Up @@ -338,6 +318,26 @@ List<ConstraintComponent> getConstraintComponents(ShaclProperties properties, Re
.forEach(constraintComponent::add);
}

properties.getOr()
.stream()
.map(or -> new OrConstraintComponent(or, connection, cache, shaclSail))
.forEach(constraintComponent::add);

properties.getXone()
.stream()
.map(xone -> new XoneConstraintComponent(xone, connection, cache, shaclSail))
.forEach(constraintComponent::add);

properties.getAnd()
.stream()
.map(and -> new AndConstraintComponent(and, connection, cache, shaclSail))
.forEach(constraintComponent::add);

properties.getNot()
.stream()
.map(or -> new NotConstraintComponent(or, connection, cache, shaclSail))
.forEach(constraintComponent::add);

return constraintComponent;
}

Expand Down Expand Up @@ -423,17 +423,6 @@ public SparqlFragment buildSparqlValidNodes_rsx_targetShape(StatementMatcher.Var
throw new UnsupportedOperationException(this.getClass().getSimpleName());
}

/**
* For rsx:targetShape
*
* @return
*/
public Stream<StatementMatcher> getStatementMatchers_rsx_targetShape(StatementMatcher.Variable subject,
StatementMatcher.Variable object,
RdfsSubClassOfReasoner rdfsSubClassOfReasoner, Scope scope) {
throw new UnsupportedOperationException(this.getClass().getSimpleName());
}

public static class Factory {

public static List<Shape> getShapes(RepositoryConnection connection, ShaclSail shaclSail) {
Expand Down
Loading

0 comments on commit 0d33b7b

Please sign in to comment.