Skip to content

Commit

Permalink
[Upd] Add support of kbss:iterationCount and kbss:onlyIfTripleCountCh…
Browse files Browse the repository at this point in the history
…anges for Rdf4jUpdateModule
  • Loading branch information
rodionnv committed Jul 20, 2023
1 parent fe3b0b2 commit ffe0f3f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
2 changes: 2 additions & 0 deletions doc/examples/rdf4j-update/rdf4j-update.sms.ttl
Expand Up @@ -50,6 +50,8 @@ INSERT {
}
""" ;
];
kbss:has-max-iteration-count 5 ;
kbss:only-if-triple-count-changes false;
rdf4j:p-rdf4j-server-url "http://localhost:8080/rdf4j-server/" ;
rdf4j:p-rdf4j-repository-name "test-update" ;
.
Expand Down
Expand Up @@ -20,6 +20,7 @@ protected static final Property property(String local )
public static final Property is_parse_text = property("is-parse-text");
public static final Property has_max_iteration_count = property("has-max-iteration-count");
public static final Property has_resource_uri = property("has-resource-uri");
public static final Property only_if_triple_count_changes = property("only-if-triple-count-changes");

/**
returns the URI for this schema
Expand Down
Expand Up @@ -42,6 +42,16 @@ public class Rdf4jUpdateModule extends AbstractModule {
private List<Resource> updateQueries;

private Repository updateRepository;
private int iterationCount;
private boolean onlyIfTripleCountChanges;

public int getIterationCount() {
return iterationCount;
}

public void setIterationCount(int iterationCount) {
this.iterationCount = iterationCount;
}

public String getRdf4jServerURL() {
return rdf4jServerURL;
Expand Down Expand Up @@ -77,7 +87,12 @@ ExecutionContext executeSelf() {

for (Resource updateQueryResource : updateQueries) {
String updateQuery = updateQueryResource.getProperty(SP.text).getLiteral().getString();
makeUpdate(updateQuery, updateConnection);
for(int i = 0;i < iterationCount;i++) {
long oldTriplesCount = updateConnection.size();
makeUpdate(updateQuery, updateConnection);
long newTriplesCount = updateConnection.size();
if(onlyIfTripleCountChanges && (newTriplesCount == oldTriplesCount) )break;
}
}
} catch (RepositoryException e) {
throw new RepositoryAccessException(rdf4jRepositoryName, e);
Expand Down Expand Up @@ -117,8 +132,13 @@ public String getTypeURI() {

@Override
public void loadConfiguration() {
String rdf4jServerURL = getEffectiveValue(P_RDF4J_SERVER_URL).asLiteral().getString();
String rdf4jRepositoryName = getEffectiveValue(P_RDF4J_REPOSITORY_NAME).asLiteral().getString();
rdf4jServerURL = getEffectiveValue(P_RDF4J_SERVER_URL).asLiteral().getString();
rdf4jRepositoryName = getEffectiveValue(P_RDF4J_REPOSITORY_NAME).asLiteral().getString();
iterationCount = getPropertyValue(KBSS_MODULE.has_max_iteration_count,1);
onlyIfTripleCountChanges = getPropertyValue(KBSS_MODULE.only_if_triple_count_changes,false);
LOG.debug("Iteration count={}\nOnlyIf...Changes={}"
,iterationCount
,onlyIfTripleCountChanges);
updateRepository = new SPARQLRepository(rdf4jServerURL + "repositories/" + rdf4jRepositoryName + "/statements");
updateQueries = getResourcesByProperty(SML.updateQuery);
}
Expand Down

0 comments on commit ffe0f3f

Please sign in to comment.