Skip to content

Commit

Permalink
[#258] Refactor @parameter to include iri instead of (urlPrefix, name)
Browse files Browse the repository at this point in the history
  • Loading branch information
blcham committed Sep 13, 2024
1 parent c08f264 commit f3b022c
Show file tree
Hide file tree
Showing 50 changed files with 317 additions and 261 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package cz.cvut.spipes.constants;

import org.apache.jena.rdf.model.Property;
import org.apache.jena.rdf.model.ResourceFactory;

import static org.apache.jena.rdf.model.ResourceFactory.createProperty;

public class KBSS_MODULE {

Expand All @@ -10,17 +11,25 @@ public class KBSS_MODULE {
*/
public static final String uri = "http://onto.fel.cvut.cz/ontologies/lib/module/";

protected static final Property property(String local )
{ return ResourceFactory.createProperty( uri, local ); }

public static final Property has_input_graph_constraint = property("has-input-graph-constraint");
public static final Property has_output_graph_constraint = property("has-output-graph-constraint");
public static final Property has_target_module_flag = property("has-target-module-flag");
public static final Property has_debug_mode_flag = property("has-debug-mode-flag");
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 String has_input_graph_constraint = uri + "has-input-graph-constraint";
public static final String has_output_graph_constraint = uri + "has-output-graph-constraint";
public static final String has_target_module_flag = uri + "has-target-module-flag";
public static final String has_debug_mode_flag = uri + "has-debug-mode-flag";
public static final String is_parse_text = uri + "is-parse-text";
public static final String has_max_iteration_count = uri + "has-max-iteration-count";
public static final String has_resource_uri = uri + "has-resource-uri";

// states that reified statement belongs to specific named graph identified by uri
public static final Property is_part_of_graph = property("is-part-of-graph");
public static final String is_part_of_graph = uri + "is-part-of-graph";

public static class JENA {
public static final Property has_input_graph_constraint = createProperty(KBSS_MODULE.has_input_graph_constraint);
public static final Property has_output_graph_constraint = createProperty(KBSS_MODULE.has_output_graph_constraint);
public static final Property has_target_module_flag = createProperty(KBSS_MODULE.has_target_module_flag);
public static final Property has_debug_mode_flag = createProperty(KBSS_MODULE.has_debug_mode_flag);
public static final Property is_parse_text = createProperty(KBSS_MODULE.is_parse_text);
public static final Property has_max_iteration_count = createProperty(KBSS_MODULE.has_max_iteration_count);
public static final Property has_resource_uri = createProperty(KBSS_MODULE.has_resource_uri);
public static final Property is_part_of_graph = createProperty(KBSS_MODULE.is_part_of_graph);
}
}
29 changes: 17 additions & 12 deletions s-pipes-core/src/main/java/cz/cvut/spipes/constants/SM.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package cz.cvut.spipes.constants;

import org.apache.jena.rdf.model.Property;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.rdf.model.ResourceFactory;

import static org.apache.jena.rdf.model.ResourceFactory.createProperty;
import static org.apache.jena.rdf.model.ResourceFactory.createResource;

public class SM {

Expand All @@ -11,18 +12,22 @@ public class SM {
*/
public static final String uri = "http://topbraid.org/sparqlmotion#";

protected static final Resource resource(String local )
{ return ResourceFactory.createResource( uri + local ); }
public static final String next = uri + "next";
public static final String outputVariable = uri + "outputVariable";
public static final String returnModule = uri + "returnModule";

protected static final Property property(String local )
{ return ResourceFactory.createProperty( uri, local ); }
public static final String Function = uri + "Function";
public static final String Module = uri + "Module";
public static final String Modules = uri + "Modules";


public static final Property next = property("next");
public static final Property outputVariable = property("outputVariable");
public static final Property returnModule = property("returnModule");
public static class JENA {
public static final Property next = createProperty(SM.next);
public static final Property outputVariable = createProperty(SM.outputVariable);
public static final Property returnModule = createProperty(SM.returnModule);

public static final Resource Function = resource("Function");
public static final Resource Module = resource("Module");
public static final Resource Modules = resource("Modules");
public static final org.apache.jena.rdf.model.Resource Function = createResource(SM.Function);
public static final org.apache.jena.rdf.model.Resource Module = createResource(SM.Module);
public static final org.apache.jena.rdf.model.Resource Modules = createResource(SM.Modules);
}
}
77 changes: 48 additions & 29 deletions s-pipes-core/src/main/java/cz/cvut/spipes/constants/SML.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import org.apache.jena.rdf.model.Property;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.rdf.model.ResourceFactory;

import static org.apache.jena.rdf.model.ResourceFactory.createProperty;
import static org.apache.jena.rdf.model.ResourceFactory.createResource;

public class SML {

Expand All @@ -11,32 +13,49 @@ public class SML {
*/
public static final String uri = "http://topbraid.org/sparqlmotionlib#";

protected static final org.apache.jena.rdf.model.Resource resource(String local )
{ return ResourceFactory.createResource( uri + local ); }

protected static final Property property(String local )
{ return ResourceFactory.createProperty( uri, local ); }

public static final Property replace = property( "replace");
public static final Property constructQuery = property("constructQuery");
public static final Property value = property("value");
public static final Property selectQuery = property("selectQuery");
public static final Property updateQuery = property("updateQuery");
public static final Property sourceFilePath = property("sourceFilePath");
public static final Property url = property("url");
public static final Property targetFilePath = property("targetFilePath");
public static final Property baseURI = property("baseURI");
public static final Property serialization = property("serialization");
public static final Property ignoreImports = property("ignoreImports");

public static final Resource ApplyConstruct = resource("ApplyConstruct");
public static final Resource ExportToRDFFile = resource("ExportToRDFFile");
public static final Resource ImportRDFFromWorkspace = resource("ImportRDFFromWorkspace");
public static final Resource ImportFileFromURL = resource("ImportFileFromURL");
public static final Resource BindWithConstant = resource("BindWithConstant");
public static final Resource BindBySelect = resource("BindBySelect");
public static final Resource Merge = resource("Merge");
public static final Resource ReturnRDF = resource("ReturnRDF");

public static final Resource JSONLD = resource("JSONLD");
public static final String replace = uri + "replace";
public static final String constructQuery = uri + "constructQuery";
public static final String value = uri + "value";
public static final String selectQuery = uri + "selectQuery";
public static final String updateQuery = uri + "updateQuery";
public static final String sourceFilePath = uri + "sourceFilePath";
public static final String url = uri + "url";
public static final String targetFilePath = uri + "targetFilePath";
public static final String baseURI = uri + "baseURI";
public static final String serialization = uri + "serialization";
public static final String ignoreImports = uri + "ignoreImports";

public static final String ApplyConstruct = uri + "ApplyConstruct";
public static final String ExportToRDFFile = uri + "ExportToRDFFile";
public static final String ImportRDFFromWorkspace = uri + "ImportRDFFromWorkspace";
public static final String ImportFileFromURL = uri + "ImportFileFromURL";
public static final String BindWithConstant = uri + "BindWithConstant";
public static final String BindBySelect = uri + "BindBySelect";
public static final String Merge = uri + "Merge";
public static final String ReturnRDF = uri + "ReturnRDF";
public static final String JSONLD = uri + "JSONLD";

public static class JENA {
public static final Property replace = createProperty(SML.replace);
public static final Property constructQuery = createProperty(SML.constructQuery);
public static final Property value = createProperty(SML.value);
public static final Property selectQuery = createProperty(SML.selectQuery);
public static final Property updateQuery = createProperty(SML.updateQuery);
public static final Property sourceFilePath = createProperty(SML.sourceFilePath);
public static final Property url = createProperty(SML.url);
public static final Property targetFilePath = createProperty(SML.targetFilePath);
public static final Property baseURI = createProperty(SML.baseURI);
public static final Property serialization = createProperty(SML.serialization);
public static final Property ignoreImports = createProperty(SML.ignoreImports);

public static final Resource ApplyConstruct = createResource("ApplyConstruct");
public static final Resource ExportToRDFFile = createResource("ExportToRDFFile");
public static final Resource ImportRDFFromWorkspace = createResource("ImportRDFFromWorkspace");
public static final Resource ImportFileFromURL = createResource("ImportFileFromURL");
public static final Resource BindWithConstant = createResource("BindWithConstant");
public static final Resource BindBySelect = createResource("BindBySelect");
public static final Resource Merge = createResource("Merge");
public static final Resource ReturnRDF = createResource("ReturnRDF");
public static final Resource JSONLD = createResource("JSONLD");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@
import cz.cvut.spipes.function.ARQFunction;
import cz.cvut.spipes.modules.Module;
import cz.cvut.spipes.util.JenaPipelineUtils;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.lang.reflect.Modifier;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.Resource;
Expand All @@ -28,6 +19,16 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.lang.reflect.Modifier;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

public class PipelineFactory {

private static final Logger log = LoggerFactory.getLogger(PipelineFactory.class);
Expand Down Expand Up @@ -166,7 +167,7 @@ private static Map<Resource, Module> loadAllModules(@NotNull Model configModel)
Resource res = e.getKey();

// set up input modules
res.listProperties(SM.next).toList().stream()
res.listProperties(SM.JENA.next).toList().stream()
.map(st -> {
Module m = res2ModuleMap.get(st.getObject().asResource());
if (m == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,13 @@ protected String saveFullModelToTemporaryFile(OntModel model) {
}

private void loadModuleConstraints() {
inputConstraintQueries = getResourcesByProperty(KBSS_MODULE.has_input_graph_constraint);
outputConstraintQueries = getResourcesByProperty(KBSS_MODULE.has_output_graph_constraint);
inputConstraintQueries = getResourcesByProperty(KBSS_MODULE.JENA.has_input_graph_constraint);
outputConstraintQueries = getResourcesByProperty(KBSS_MODULE.JENA.has_output_graph_constraint);
}

private void loadModuleFlags() {
isTargetModule = getPropertyValue(KBSS_MODULE.has_debug_mode_flag, false);
isInDebugMode = getPropertyValue(KBSS_MODULE.has_debug_mode_flag, false);
isTargetModule = getPropertyValue(KBSS_MODULE.JENA.has_debug_mode_flag, false);
isInDebugMode = getPropertyValue(KBSS_MODULE.JENA.has_debug_mode_flag, false);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package cz.cvut.spipes.modules;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cz.cvut.spipes.modules.handlers.*;
import org.apache.jena.rdf.model.ResourceFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* The `AnnotatedAbstractModule` class extends the `AbstractModule` class and provides
* an implementation for loading the module's configuration using {@link Parameter} annotation.
Expand All @@ -35,10 +35,10 @@ public void loadConfiguration() {
final Parameter p = f.getAnnotation(Parameter.class);
if ( p == null ) {
continue;
} else if (vars.containsKey(p.name())) {
throw new RuntimeException(String.format("Two parameters are named the same %s, except prefix", p.name()));
} else if (vars.containsKey(p.iri())) {
throw new RuntimeException(String.format("Two parameters have same iri %s", p.iri()));
} else {
vars.put(p.name(), f);
vars.put(p.iri(), f);
}

log.trace("Processing parameter {} ", f.getName());
Expand All @@ -51,7 +51,7 @@ public void loadConfiguration() {
}
HandlerRegistry handlerRegistry = HandlerRegistry.getInstance();
Handler<?> handler = handlerRegistry.getHandler(f.getType(), resource, executionContext, setter);
handler.setValueByProperty(ResourceFactory.createProperty(p.urlPrefix()+p.name()));
handler.setValueByProperty(ResourceFactory.createProperty(p.iri()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,23 @@ public class ApplyConstructModule extends AnnotatedAbstractModule {

private static final Logger log = LoggerFactory.getLogger(ApplyConstructModule.class);


//sml:constructQuery
@Parameter(urlPrefix = SML.uri, name = "constructQuery")
@Parameter(iri = SML.constructQuery)
private List<Resource> constructQueries;

//sml:replace
@Parameter(urlPrefix = SML.uri, name = "replace")
@Parameter(iri = SML.replace)
private boolean isReplace = false;

//kbss:parseText
/**
* Whether the query should be taken from sp:text property instead of from SPIN serialization
*/
@Parameter(urlPrefix = KBSS_MODULE.uri, name = "is-parse-text")
@Parameter(iri = KBSS_MODULE.is_parse_text)
private boolean parseText = false;


//kbss:iterationCount
/**
* Maximal number of iterations of the whole rule set. 0 means 0 iterations. The actual number of iterations can be smaller,
Expand All @@ -59,7 +61,7 @@ public class ApplyConstructModule extends AnnotatedAbstractModule {
* <p>
* Within each iteration, all queries are evaluated on the same model.
*/
@Parameter(urlPrefix = KBSS_MODULE.uri, name = "has-max-iteration-count")
@Parameter(iri = KBSS_MODULE.has_max_iteration_count)
private int iterationCount = 1;

public ApplyConstructModule() {
Expand Down Expand Up @@ -166,7 +168,7 @@ public ExecutionContext executeSelf() {

@Override
public String getTypeURI() {
return SML.ApplyConstruct.getURI();
return SML.ApplyConstruct;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,21 @@
import cz.cvut.spipes.engine.ExecutionContextFactory;
import cz.cvut.spipes.engine.VariablesBinding;
import cz.cvut.spipes.util.QueryUtils;
import org.apache.jena.query.Query;
import org.apache.jena.query.QueryExecution;
import org.apache.jena.query.QueryExecutionFactory;
import org.apache.jena.query.QuerySolution;
import org.apache.jena.query.ResultSet;
import org.apache.jena.query.*;
import org.apache.jena.rdf.model.ModelFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.topbraid.spin.arq.ARQFactory;
import org.topbraid.spin.model.Select;

public class BindBySelectModule extends AnnotatedAbstractModule {

private static final Logger log = LoggerFactory.getLogger(BindBySelectModule.class);

@Parameter(urlPrefix = SML.uri, name = "selectQuery")
@Parameter(iri = SML.selectQuery)
private Select selectQuery;

//sml:replace
@Parameter(urlPrefix = SML.uri, name = "replace")
@Parameter(iri = SML.replace)
private boolean isReplace = false;

@Override
Expand Down Expand Up @@ -60,7 +55,7 @@ public ExecutionContext executeSelf() {

@Override
public String getTypeURI() {
return SML.BindBySelect.getURI();
return SML.BindBySelect;
}

public Select getSelectQuery() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public class BindRDFContentHashModule extends AnnotatedAbstractModule {

private static final Logger log = LoggerFactory.getLogger(BindRDFContentHashModule.class);
@Parameter(urlPrefix = SM.uri, name="outputVariable")
@Parameter(iri = SM.outputVariable)
String outputVariable;

@Override
Expand Down
Loading

0 comments on commit f3b022c

Please sign in to comment.