Skip to content

Commit

Permalink
[#274] Add loadManualConfiguration and refactor all modules
Browse files Browse the repository at this point in the history
  • Loading branch information
palagdan committed Sep 26, 2024
1 parent 6717114 commit 43c1e82
Show file tree
Hide file tree
Showing 17 changed files with 49 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public abstract class AbstractModule implements Module {
public ExecutionContext execute() {
loadModuleFlags();
loadConfiguration();
loadManualConfiguration();
loadModuleConstraints();
String inputModelFilePath = null;
if (AuditConfig.isEnabled() || isInDebugMode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,7 @@ public void loadConfiguration() {
handler.setValueByProperty(ResourceFactory.createProperty(p.iri()));
}
}

@Override
public void loadManualConfiguration(){}
}
2 changes: 2 additions & 0 deletions s-pipes-core/src/main/java/cz/cvut/spipes/modules/Module.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public interface Module {
*/
void loadConfiguration();

void loadManualConfiguration();

Resource getResource();

void setInputModules(List<Module> inputModules);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ public class ImportE5XModule extends AnnotatedAbstractModule {

// TODO - this parameter id defined with IRI <http://onto.fel.cvut.cz/ontologies/lib/module-param/has-resource-uri> in s-pipes-modules\module.sms.ttl
// TODO - we should be able to annotate directly "StreamResource e5xResource" instead
@Parameter(iri = KBSS_MODULE.has_resource_uri, comment = "Uri of a resource referencing content of an e5x file.")
private String e5xResourceUriStr;

@Parameter(iri = KBSS_MODULE.has_resource_uri, comment = "Uri of a resource referencing content of an e5x file.")
StreamResource e5xResource;

private boolean computeEccairsToAviationSafetyOntologyMapping = true;
Expand Down Expand Up @@ -151,21 +150,4 @@ public String getTypeURI() {
return KBSS_MODULE.uri + "import-e5x";
}

@Override
public void loadConfiguration() {
e5xResourceUriStr = getEffectiveValue(KBSS_MODULE.JENA.has_resource_uri).asLiteral().toString();
e5xResource = getResourceByUri(e5xResourceUriStr);
}

@NotNull
private StreamResource getResourceByUri(@NotNull String e5xResourceUriStr) {

StreamResource res = StreamResourceRegistry.getInstance().getResourceByUrl(e5xResourceUriStr);

if (res == null) {
throw new ResourceNotFoundException("Stream resource " + e5xResourceUriStr + " not found. ");
}
return res;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

@Slf4j
@SPipesModule(label = "temporal v0.1", comment = "Annotate temporal expressions in literals in input model.")
public class SUTimeModule extends AbstractModule {
public class SUTimeModule extends AnnotatedAbstractModule {

public static final String TYPE_URI = KBSS_MODULE.uri + "temporal-v0.1";

Expand All @@ -40,7 +40,6 @@ public class SUTimeModule extends AbstractModule {
@Parameter(iri = DescriptorModel.has_document_date, comment = "Document date format.") // TODO - revise comment
private String documentDate; // TODO support other formats ?


public SUTimeModule() {
}

Expand All @@ -49,17 +48,6 @@ public String getTypeURI() {
return TYPE_URI;
}

@Override
public void loadConfiguration() {

if (this.resource.getProperty(DescriptorModel.JENA.has_document_date) != null) { // TODO set current date if not specified
documentDate = getEffectiveValue(DescriptorModel.JENA.has_document_date).asLiteral().toString();
}

if (this.resource.getProperty(DescriptorModel.JENA.has_rule_file) != null) { //TODO support more rule files
ruleFilePaths.add(Paths.get(getEffectiveValue(DescriptorModel.JENA.has_rule_file).asLiteral().toString()));
}
}

@Override

Expand All @@ -70,12 +58,8 @@ ExecutionContext executeSelf() {
}

private Model analyzeModel(Model m) {



AnnotationPipeline pipeline = loadPipeline();


DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
List<ReifiedStatement> temporalAnnotationStmts = new LinkedList<>();
m.listStatements()
Expand Down Expand Up @@ -199,7 +183,4 @@ private AnnotationPipeline loadPipeline() {
return pipeline;
}




}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import edu.stanford.nlp.time.TimeAnnotator;
import edu.stanford.nlp.time.TimeExpression;
import edu.stanford.nlp.util.CoreMap;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.jena.query.Query;
import org.apache.jena.query.QueryFactory;
Expand All @@ -29,11 +31,15 @@
import java.nio.file.Paths;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;

@Slf4j
@Getter
@Setter
@SPipesModule(label = "temporal-v1", comment = "Module annotates input triples using NLP analysis of time using library SUTime.")
public class SUTimeModuleNew extends AbstractModule {
public class SUTimeModuleNew extends AnnotatedAbstractModule {

private static final String TYPE_URI = KBSS_MODULE.uri + "temporal-v1";
private static final String TYPE_PREFIX = TYPE_URI + "/";
Expand All @@ -49,18 +55,18 @@ public class SUTimeModuleNew extends AbstractModule {
private List<Resource> constructQueries;

@Parameter(iri = SML.replace, comment = "Replace context flag. Default value is false." )
private boolean isReplace;
private boolean isReplace = false;

@Parameter(iri = KBSS_MODULE.is_parse_text,
comment = "Whether the query should be taken from sp:text property instead of from SPIN serialization," +
" default is true.")
private boolean parseText;
private boolean parseText = true;

@Parameter(iri = DescriptorModel.has_rule_file, comment = "Rule file, multivalued.")// TODO - review comment
private List<Path> ruleFilePaths = new LinkedList<>();

@Parameter(iri = DescriptorModel.has_document_date, comment = "Document date format.")// TODO - review comment
private String documentDate; // TODO support other formats ?
private String documentDate = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); // TODO support other formats ?
private AnnotationPipeline pipeline;

public SUTimeModuleNew() {
Expand All @@ -72,30 +78,6 @@ public String getTypeURI() {
return TYPE_URI;
}

public int getPageSize() {
return pageSize;
}

public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}

@Override
public void loadConfiguration() {
if (this.resource.getProperty(DescriptorModel.JENA.has_document_date) != null) { // TODO set current date if not specified
documentDate = getEffectiveValue(DescriptorModel.JENA.has_document_date).asLiteral().toString();
}

if (this.resource.getProperty(DescriptorModel.JENA.has_rule_file) != null) { //TODO support more rule files
ruleFilePaths.add(Paths.get(getEffectiveValue(DescriptorModel.JENA.has_rule_file).asLiteral().toString()));
}
parseText = this.getPropertyValue(KBSS_MODULE.JENA.is_parse_text, true);
pageSize = this.getPropertyValue(P_PAGE_SIZE, DEFAULT_PAGE_SIZE);
constructQueries = getResourcesByProperty(SML.JENA.constructQuery);

isReplace = this.getPropertyValue(SML.JENA.replace, false);
}

@Override
public ExecutionContext executeSelf() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

@Slf4j
@SPipesModule(label = "rdf4j create repository", comment = "Module creates native store rdf4j repository on the given server with the given name.")
public class Rdf4jCreateRepositoryModule extends AbstractModule {
public class Rdf4jCreateRepositoryModule extends AnnotatedAbstractModule {
private static final String TYPE_URI = KBSS_MODULE.uri + "rdf4j-create-repository";
private static final String PROPERTY_PREFIX_URI = KBSS_MODULE.uri + "rdf4j";

Expand All @@ -34,8 +34,9 @@ public class Rdf4jCreateRepositoryModule extends AbstractModule {

@Parameter(iri = PROPERTY_PREFIX_URI + "/" + "p-rdf4j-ignore-if-exists",
comment = "Don't try to create new repository if it already exists (Default value is false)")
private boolean rdf4jIgnoreIfExists;
private boolean rdf4jIgnoreIfExists = false;

@Parameter(iri = PROPERTY_PREFIX_URI + "/" + "p-rdf4j-server-url", comment = "URL of the Rdf4j server")
private RepositoryManager repositoryManager;

public String getRdf4jServerURL() {
Expand Down Expand Up @@ -101,15 +102,7 @@ public String getTypeURI() {
}

@Override
public void loadConfiguration() {
rdf4jServerURL = getEffectiveValue(P_RDF4J_SERVER_URL).asLiteral().getString();
rdf4jRepositoryName = getEffectiveValue(P_RDF4J_REPOSITORY_NAME).asLiteral().getString();
try {
rdf4jIgnoreIfExists = (Objects.equals(getEffectiveValue(P_RDF4J_IGNORE_IF_EXISTS).asLiteral().getString(), "true"));
}
catch (NullPointerException e){
rdf4jIgnoreIfExists = false;
}
public void loadManualConfiguration() {
repositoryManager = new RemoteRepositoryManager(rdf4jServerURL);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"Module deploys content of input execution context into default context of repository (if p-rdf4j-context-iri " +
"is not specified) or concrete context (if p-rdf4j-context-iri is specified)."
)
public class Rdf4jDeployModule extends AbstractModule {
public class Rdf4jDeployModule extends AnnotatedAbstractModule {

private final static String TYPE_URI = KBSS_MODULE.uri + "deploy";
private final static String PROPERTY_PREFIX_URI = KBSS_MODULE.uri + "rdf4j";
Expand All @@ -66,8 +66,8 @@ private static Property getParameter(final String name) {
@Parameter(iri = PROPERTY_PREFIX_URI + "/" + "p-rdf4j-infer-context-iris",
comment = "IRI of contexts is inferred from annotated input triples. Only reified triples that contain triple " +
"?reifiedStatement kbss-module:is-part-of-graph ?graph are processed." +
" Actual triples related to reified statement are not processed/needed.")
private boolean inferContextIRIs;
" Actual triples related to reified statement are not processed/needed. Default is false.")
private boolean inferContextIRIs = false;

static final Property P_RDF4J_REPOSITORY_USERNAME = getParameter("p-rdf4j-secured-username-variable");
@Parameter(iri = PROPERTY_PREFIX_URI + "/" + "p-rdf4j-secured-username-variable", comment = "User name if the repository requires authentication.")
Expand All @@ -89,7 +89,7 @@ public void setRepositoryManager(RepositoryManager repositoryManager) {
@Parameter(iri = PROPERTY_PREFIX_URI + "/" + "p-is-replace", comment =
"Whether data should be replaced (true) / appended (false) into the specified context or repository.\n" +
"Default is false.")
private boolean isReplaceContext;
private boolean isReplaceContext = false;

public String getRdf4jServerURL() {
return rdf4jServerURL;
Expand Down Expand Up @@ -238,19 +238,7 @@ public String getTypeURI() {
}

@Override
public void loadConfiguration() {
rdf4jServerURL = getEffectiveValue(P_RDF4J_SERVER_URL).asLiteral().getString();
rdf4jRepositoryName = getEffectiveValue(P_RDF4J_REPOSITORY_NAME).asLiteral().getString();
if (this.getPropertyValue(P_RDF4J_CONTEXT_IRI) != null) {
rdf4jContextIRI = getEffectiveValue(P_RDF4J_CONTEXT_IRI).asLiteral().getString();
}
isReplaceContext = this.getPropertyValue(P_IS_REPLACE_CONTEXT_IRI, false);
rdf4jSecuredUsernameVariable = Optional.ofNullable(
getEffectiveValue(P_RDF4J_REPOSITORY_USERNAME)).map(n -> n.asLiteral().getString()
).orElse(null);
rdf4jSecuredPasswordVariable = Optional.ofNullable(
getEffectiveValue(P_RDF4J_REPOSITORY_PASSWORD)).map(n -> n.asLiteral().getString()
).orElse(null);
public void loadManualConfiguration() {
if (repositoryManager != null && rdf4jServerURL != null) {
throw new ModuleConfigurationInconsistentException(
"Repository manager is already initialized. Trying to override its configuration from RDF.");
Expand All @@ -263,7 +251,6 @@ public void loadConfiguration() {
remoteRepositoryManager.setUsernameAndPassword(username, password);
}
repository = repositoryManager.getRepository(rdf4jRepositoryName);
inferContextIRIs = getPropertyValue(P_RDF4J_INFER_CONTEXT_IRIS,false);
log.debug("Inferring contexts from annotated input triples.");
}
private static @Nullable String getConfigurationVariable(String variableName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
@SPipesModule(label = "rdf4j update", comment = "Updates sparql endpoint configured in rdf4jServerURL" +
" using specified list updateQueries. The list of queries can be executed multiple times specified by " +
" `has-max-iteration-count` property.")
public class Rdf4jUpdateModule extends AbstractModule {
public class Rdf4jUpdateModule extends AnnotatedAbstractModule {
private static final String TYPE_URI = KBSS_MODULE.uri + "rdf4j-update";
private static final String PROPERTY_PREFIX_URI = KBSS_MODULE.uri + "rdf4j";

Expand All @@ -56,13 +56,13 @@ public class Rdf4jUpdateModule extends AbstractModule {
@Parameter(iri = PROPERTY_PREFIX_URI + "/" + "p-stop-iteration-on-stable-triple-count",
comment = "Stops iteration (i.e. execution of list of queries) if triple count " +
"in the last iteration did not change. Default is false.")
private boolean onlyIfTripleCountChanges;
private boolean onlyIfTripleCountChanges = false;

@Parameter(iri = PROPERTY_PREFIX_URI + "/" + "has-max-iteration-count",
comment = "Limits the number of iterations (i.e. executions of list of queries)" +
" to the specified value. Default value is 1, which means that all" +
" update queries are executed only once.")
private int iterationCount;
private int iterationCount = 1;

private Repository updateRepository;

Expand Down Expand Up @@ -189,11 +189,7 @@ public String getTypeURI() {
}

@Override
public void loadConfiguration() {
rdf4jServerURL = getEffectiveValue(P_RDF4J_SERVER_URL).asLiteral().getString();
rdf4jRepositoryName = getEffectiveValue(P_RDF4J_REPOSITORY_NAME).asLiteral().getString();
iterationCount = getPropertyValue(KBSS_MODULE.JENA.has_max_iteration_count,1);
onlyIfTripleCountChanges = getPropertyValue(P_RDF4J_STOP_ITERATION_ON_STABLE_TRIPLE_COUNT,false);
public void loadManualConfiguration() {
log.debug("Iteration count={}\nOnlyIf...Changes={}"
,iterationCount
,onlyIfTripleCountChanges);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public String getTypeURI() {


@Override
public void loadConfiguration() {
public void loadManualConfiguration() {
super.loadConfiguration();
iterationCount = this.getPropertyValue(KBSS_MODULE.JENA.has_max_iteration_count, 1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,10 @@ protected String substituteQueryMarkers(int currentIteration, String queryStr) {


@Override
public void loadConfiguration() {
public void loadManualConfiguration() {
super.loadConfiguration();
super.loadManualConfiguration();
//iterationCount = this.getPropertyValue(KBSS_MODULE.JENA.s_max_iteration_count, 1);
parseText = this.getPropertyValue(KBSS_MODULE.JENA.is_parse_text, true);
chunkSize = this.getPropertyValue(P_CHUNK_SIZE, DEFAULT_CHUNK_SIZE);
selectQuery = getPropertyValue(SML.JENA.selectQuery).asResource().as(Select.class);
pageSize = this.getPropertyValue(P_PAGE_SIZE, DEFAULT_PAGE_SIZE);
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,9 @@ protected String substituteQueryMarkers(int currentIteration, String queryStr) {


@Override
public void loadConfiguration() {
public void loadManualConfiguration() {
super.loadConfiguration();
//iterationCount = this.getPropertyValue(KBSS_MODULE.JENA.s_max_iteration_count, 1);
parseText = this.getPropertyValue(KBSS_MODULE.JENA.is_parse_text, true);
chunkSize = this.getPropertyValue(P_CHUNK_SIZE, DEFAULT_CHUNK_SIZE);
selectQuery = getPropertyValue(SML.JENA.selectQuery).asResource().as(Select.class);
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,8 @@ protected String substituteQueryMarkers(int currentIteration, String queryStr) {


@Override
public void loadConfiguration() {
public void loadManualConfiguration() {
super.loadConfiguration();
//iterationCount = this.getPropertyValue(KBSS_MODULE.JENA.s_max_iteration_count, 1);
parseText = this.getPropertyValue(KBSS_MODULE.JENA.is_parse_text, true);
pageSize = this.getPropertyValue(P_PAGE_SIZE , DEFAULT_PAGE_SIZE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -380,12 +380,8 @@ public String getTypeURI() {
}

@Override
public void loadConfiguration() {
public void loadManualConfiguration() {
super.loadConfiguration();
marginalConstraint = getEffectiveStringValue(TYPE_PREFIX + "marginal-constraint");
marginalsDefsFileUrl = getEffectiveStringValue(TYPE_PREFIX + "marginals-defs-file-url");
marginalsFileUrl = getEffectiveStringValue(TYPE_PREFIX + "marginals-file-url");
dataServiceUrl = getEffectiveStringValue(TYPE_PREFIX + "data-service-url");
}

private @NotNull
Expand Down
Loading

0 comments on commit 43c1e82

Please sign in to comment.