Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues #205, #206 and #216 #210

Merged
merged 14 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,9 @@ private void generateRdfForAllModules() throws MalformedURLException, ClassNotFo
for (Class<?> moduleClass : moduleClasses) {
getLog().info("Creating RDF for module '" + moduleClass.getCanonicalName() + "'");
var moduleAnnotation = readModuleAnnotationFromClass(moduleClass);
var extendedModuleAnnotation = readExtendedModuleAnnotationFromClass(moduleClass);
var constraints = readConstraintsFromClass(moduleClass);
writeConstraintsToModel(model, constraints, moduleAnnotation);
writeConstraintsToModel(model, constraints, moduleAnnotation, extendedModuleAnnotation);
}

getLog().info("--------------------------------------");
Expand All @@ -154,14 +155,27 @@ private void generateRdfForAllModules() throws MalformedURLException, ClassNotFo
getLog().info("======================================");
}

private SPipesModule readExtendedModuleAnnotationFromClass(Class<?> moduleClass) {

SPipesModule ret = null;
Class cls = moduleClass.getSuperclass();
while(ret == null && cls != null) {
ret = readModuleAnnotationFromClass(cls);
cls = cls.getSuperclass();
}

return ret;
}

private void generateRdfForModule() throws MojoExecutionException {
try {
Set<Class<?>> moduleClasses = readAllModuleClasses(this.project);
var model = readModelFromDefaultFile();
for (Class<?> moduleClass : moduleClasses) {
var moduleAnnotation = readModuleAnnotationFromClass(moduleClass);
var extendedModuleAnnotation = readExtendedModuleAnnotationFromClass(moduleClass);
var constraints = readConstraintsFromClass(moduleClass);
writeConstraintsToModel(model, constraints, moduleAnnotation);
writeConstraintsToModel(model, constraints, moduleAnnotation, extendedModuleAnnotation);
}

var ontologyPath = modulePackageName.replaceAll("[.]", "/") + "/" + ontologyFilename;
Expand Down Expand Up @@ -269,25 +283,27 @@ private Model readModelFromDefaultFile() {

private void writeConstraintsToModel(Model baseRdfModel,
List<cz.cvut.spipes.modules.Parameter> constraintAnnotations,
SPipesModule moduleAnnotation) {
SPipesModule moduleAnnotation,
SPipesModule extendedModuleAnnotation) {
final var root = ResourceFactory.createResource(KBSS_MODULE.uri + moduleAnnotation.label().replaceAll(" ", "-").toLowerCase()); //todo can be added to the annotation
// set extended uri
Optional.ofNullable(extendedModuleAnnotation)
.map(a -> ResourceFactory.createResource(
KBSS_MODULE.uri + a.label().replaceAll(" ", "-").toLowerCase()) //todo can be added to the annotation
).ifPresent(r -> baseRdfModel.add(root, RDFS.subClassOf, r));

baseRdfModel.add(root, RDF.type, SM.Module);
baseRdfModel.add(root, RDFS.comment, moduleAnnotation.comment());
baseRdfModel.add(root, RDFS.label, moduleAnnotation.label());
final var statements = baseRdfModel.listStatements(null, RDF.type, SM.Module);
while (statements.hasNext()) {
final var statement = statements.next();
final var subject = statement.getSubject();
for (var annotation : constraintAnnotations) {
final var modelConstraint = ResourceFactory.createResource();
baseRdfModel.add(modelConstraint, RDF.type, SPL.Argument);
baseRdfModel.add(modelConstraint, SPL.predicate, annotation.urlPrefix() + annotation.name());
baseRdfModel.add(modelConstraint, RDFS.comment, "Automatically generated field: " + annotation.name());
baseRdfModel.add(subject, SPIN.constraint, modelConstraint);

getLog().debug("Added model constraint based on annotation: " +
"(name = " + annotation.name() + ", urlPrefix = " + annotation.urlPrefix() + ")");
}
for (var annotation : constraintAnnotations) {
final var modelConstraint = ResourceFactory.createResource();
baseRdfModel.add(modelConstraint, RDF.type, SPL.Argument);
baseRdfModel.add(modelConstraint, SPL.predicate, ResourceFactory.createResource(annotation.urlPrefix() + annotation.name()));
baseRdfModel.add(modelConstraint, RDFS.comment, "Automatically generated field: " + annotation.name());
baseRdfModel.add(root, SPIN.constraint, modelConstraint);

getLog().debug("Added model constraint based on annotation: " +
"(name = " + annotation.name() + ", urlPrefix = " + annotation.urlPrefix() + ")");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import cz.cvut.kbss.jopa.model.descriptors.EntityDescriptor;
import cz.cvut.spipes.constants.KBSS_MODULE;
import cz.cvut.spipes.engine.ExecutionContext;
import cz.cvut.spipes.modules.annotations.SPipesModule;
import eu.trentorise.opendata.jackan.CkanClient;
import eu.trentorise.opendata.jackan.exceptions.CkanException;
import eu.trentorise.opendata.jackan.model.CkanCatalog;
Expand All @@ -26,6 +27,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@SPipesModule(label = "ckan2rdf-v1", comment = "Convert ckan to rdf.")
public class Ckan2RdfModule extends AnnotatedAbstractModule {

public static final String TYPE_URI = KBSS_MODULE.uri + "ckan2rdf-v1";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import cz.cvut.spipes.engine.ExecutionContextFactory;
import java.time.Instant;
import java.util.Calendar;

import cz.cvut.spipes.modules.annotations.SPipesModule;
import org.apache.commons.io.IOUtils;
import org.apache.jena.query.ParameterizedSparqlString;
import org.apache.jena.query.Query;
Expand All @@ -18,6 +20,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@SPipesModule(label = "sparqlEndpointDatasetExplorer-v1", comment = "TODO")
public class SparqlEndpointDatasetExplorerModule extends AnnotatedAbstractModule {

public static final String TYPE_URI = KBSS_MODULE.uri + "sparqlEndpointDatasetExplorer-v1";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import java.util.ArrayList;
import java.util.List;
import java.util.TimeZone;

import cz.cvut.spipes.modules.annotations.SPipesModule;
import org.apache.jena.query.QueryExecution;
import org.apache.jena.query.QueryExecutionFactory;
import org.apache.jena.query.QueryFactory;
Expand All @@ -24,6 +26,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@SPipesModule(label = "dataset discovery v1", comment =
"Discovers dataset based on keyword userInput in repository linked.opendata.cz-federated-descriptor-faceted-search " +
"hosted at http://onto.fel.cvut.cz/rdf4j-server.")
public class DatasetDiscoveryModule extends AbstractModule {

private static final Logger LOG = LoggerFactory.getLogger(DatasetDiscoveryModule.class);
Expand All @@ -34,6 +39,7 @@ public class DatasetDiscoveryModule extends AbstractModule {
* URL of the Sesame server.
*/
private static final Property P_USER_INPUT = getParameter("prp-user-input");
@Parameter(urlPrefix = TYPE_URI + "/", name = "prp-user-inpu")
blcham marked this conversation as resolved.
Show resolved Hide resolved
private String userInput;

private static Property getParameter(final String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import cz.cvut.spipes.engine.ExecutionContext;
import java.io.IOException;
import java.util.Collections;
import java.util.Optional;

import cz.cvut.spipes.modules.annotations.SPipesModule;
import org.apache.jena.query.Query;
import org.apache.jena.query.QueryExecution;
import org.apache.jena.query.QueryExecutionFactory;
Expand All @@ -19,21 +22,27 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@SPipesModule(label = "get dataset descriptors v1", comment = "Retrieve dataset descriptor for dataset with dataset-iri in endpoint-url.")
public class GetDatasetDescriptorsModule extends AbstractModule {

private static final Logger LOG = LoggerFactory.getLogger(GetDatasetDescriptorsModule.class);

private static final String TYPE_URI = KBSS_MODULE.uri + "get-dataset-descriptors-v1";
private static final String PARAM_URI = TYPE_URI + "/";

/**
* URL of the Sesame server.
*/
private static final Property P_DATASET_IRI = getParameter("p-dataset-iri");
private static final Property P_ENDPOINT_URL = getParameter("endpoint-url");

@Parameter(urlPrefix = PARAM_URI, name = "dataset-iri")
private String prpDatasetIri;

/**
* URL of the SPARQL endpoint.
*/
@Parameter(urlPrefix = PARAM_URI, name = "endpoint-url")
private String endpointUrl = "http://onto.fel.cvut.cz/rdf4j-server/repositories/descriptors-metadata";

private static Property getParameter(final String name) {
Expand Down Expand Up @@ -95,5 +104,6 @@ public String getTypeURI() {
@Override
public void loadConfiguration() {
prpDatasetIri = this.getStringPropertyValue(P_DATASET_IRI);
endpointUrl = Optional.ofNullable(this.getStringPropertyValue(P_ENDPOINT_URL)).orElse(endpointUrl);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import cz.cvut.spipes.engine.ExecutionContext;
import cz.cvut.spipes.engine.ExecutionContextFactory;
import cz.cvut.spipes.exception.ResourceNotFoundException;
import cz.cvut.spipes.modules.annotations.SPipesModule;
import cz.cvut.spipes.modules.eccairs.EccairsAccessFactory;
import cz.cvut.spipes.modules.eccairs.JopaPersistenceUtils;
import cz.cvut.spipes.modules.eccairs.SesameDataDao;
Expand All @@ -34,10 +35,15 @@
import java.net.URI;
import java.util.Arrays;

@SPipesModule(label = "import-e5x", comment = "Convert e5x xml files to rdf.")
public class ImportE5XModule extends AbstractModule {

private static final Logger LOG = LoggerFactory.getLogger(ImportE5XModule.class);

// 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
@Parameter(name = "has-resource-uri")
private String e5xResourceUriStr;

StreamResource e5xResource;

private boolean computeEccairsToAviationSafetyOntologyMapping = true;
Expand Down Expand Up @@ -145,7 +151,7 @@ public String getTypeURI() {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import cz.cvut.spipes.constants.KBSS_MODULE;
import cz.cvut.spipes.constants.SML;
import cz.cvut.spipes.engine.ExecutionContext;
import cz.cvut.spipes.modules.annotations.SPipesModule;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.jena.rdf.model.*;
import org.apache.jena.vocabulary.RDF;
Expand All @@ -21,6 +22,7 @@
/**
* Compute form:has-origin-path and form:has-origin-path-id properties.
*/
@SPipesModule(label = "construct form metadata", comment = "Compute form:has-origin-path and form:has-origin-path-id properties.")
blcham marked this conversation as resolved.
Show resolved Hide resolved
public class ConstructFormMetadataModule extends AnnotatedAbstractModule {

private static final Logger LOG = LoggerFactory.getLogger(ConstructFormMetadataModule.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import cz.cvut.spipes.engine.ExecutionContext;
import cz.cvut.spipes.form.JenaFormUtils;
import cz.cvut.spipes.form.JopaPersistenceUtils;
import cz.cvut.spipes.modules.annotations.SPipesModule;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.Resource;
Expand All @@ -25,6 +26,10 @@
* For input Q&A models constructs textual view of specified questions. Each textual view represent the question
* and its sub-questions recursively.
*/
@SPipesModule(label = "construct textual view", comment =
blcham marked this conversation as resolved.
Show resolved Hide resolved
"For input Q&A models constructs textual view of specified questions. Each textual" +
" view represent the question and its sub-questions recursively."
)
public class ConstructTextualViewModule extends AnnotatedAbstractModule {

private static final Logger LOG = LoggerFactory.getLogger(ConstructTextualViewModule.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import cz.cvut.spipes.constants.SML;
import cz.cvut.spipes.engine.ExecutionContext;
import cz.cvut.spipes.form.JenaFormUtils;
import cz.cvut.spipes.modules.annotations.SPipesModule;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.Resource;
Expand All @@ -19,6 +20,10 @@
* Inputs are forms using Q&A model. Possible values of questions are added to questions that does not have
* any value attached and contains possible value query.
*/
@SPipesModule(label = "fetch possible values", comment =
blcham marked this conversation as resolved.
Show resolved Hide resolved
"Fetches possible values for answers of questions. Inputs are forms using Q&A model. Possible values of " +
"questions are added to questions that does not have any value attached and contains possible value query."
)
public class FetchPossibleValuesModule extends AnnotatedAbstractModule {

private static final Logger LOG = LoggerFactory.getLogger(FetchPossibleValuesModule.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import cz.cvut.spipes.constants.SML;
import cz.cvut.spipes.engine.ExecutionContext;
import cz.cvut.spipes.form.JenaFormUtils;
import cz.cvut.spipes.modules.annotations.SPipesModule;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
Expand All @@ -20,6 +21,11 @@
* question origin combined with executionId. New question instances are created using questionInstanceTemplate
* which defaults to "doc:question-{_questionOriginHash}-{_executionId}".
*/
@SPipesModule(label = "merge form metadata", comment =
blcham marked this conversation as resolved.
Show resolved Hide resolved
"Merges form metadata. Inputs are sample form and Q&A model. Questions from both models are remapped to new" +
"IRIs based on question origin combined with executionId. New question instances are created using" +
"questionInstanceTemplate which defaults to \"doc:question-{_questionOriginHash}-{_executionId}\"."
)
public class MergeFormMetadataModule extends AnnotatedAbstractModule {

private static final Logger LOG = LoggerFactory.getLogger(MergeFormMetadataModule.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import cz.cvut.spipes.constants.KBSS_MODULE;
import cz.cvut.spipes.engine.ExecutionContext;
import cz.cvut.spipes.modules.annotations.SPipesModule;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@SPipesModule(label = "identity", comment = "Implements a no-op.")
public class IdentityModule extends AnnotatedAbstractModule {

private static final Logger LOG = LoggerFactory.getLogger(IdentityModule.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import cz.cvut.spipes.constants.KBSS_MODULE;
import cz.cvut.spipes.engine.ExecutionContext;
import cz.cvut.spipes.engine.ExecutionContextFactory;
import cz.cvut.spipes.modules.annotations.SPipesModule;
import cz.cvut.spipes.sutime.AnnforModel;
import cz.cvut.spipes.sutime.DescriptorModel;
import edu.stanford.nlp.ling.CoreAnnotations;
Expand All @@ -27,13 +28,17 @@
import java.nio.file.Paths;


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

private static final Logger LOG = LoggerFactory.getLogger(SUTimeModule.class);

public static final String TYPE_URI = KBSS_MODULE.getURI() + "temporal-v0.1";

@Parameter(urlPrefix = DescriptorModel.prefix, name = "has-document-date")
private List<Path> ruleFilePaths = new LinkedList<>();

@Parameter(urlPrefix = DescriptorModel.prefix, name = "has-rule-file")
private String documentDate; // TODO support other formats ?


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import cz.cvut.spipes.constants.KBSS_MODULE;
import cz.cvut.spipes.constants.SML;
import cz.cvut.spipes.engine.ExecutionContext;
import cz.cvut.spipes.modules.annotations.SPipesModule;
import cz.cvut.spipes.sutime.AnnforModel;
import cz.cvut.spipes.sutime.DescriptorModel;
import cz.cvut.spipes.util.JenaUtils;
Expand Down Expand Up @@ -33,6 +34,7 @@
import java.util.*;


@SPipesModule(label = "temporal-v1", comment = "Annotate temporal expressions in literals in input model.")
public class SUTimeModuleNew extends AbstractModule {

private static final Logger LOG = LoggerFactory.getLogger(SUTimeModuleNew.class);
Expand All @@ -43,16 +45,24 @@ public class SUTimeModuleNew extends AbstractModule {
private static final String LIMIT_OFFSET_CLAUSE_MARKER_NAME = "LIMIT_OFFSET";
private static final Property P_PAGE_SIZE = ResourceFactory.createProperty(TYPE_PREFIX + "page-size");
private Integer pageSize = DEFAULT_PAGE_SIZE;

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

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

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

@Parameter(urlPrefix = DescriptorModel.prefix, name = "has-document-date")
private List<Path> ruleFilePaths = new LinkedList<>();
@Parameter(urlPrefix = DescriptorModel.prefix, name = "has-rule-file")
private String documentDate; // TODO support other formats ?
private AnnotationPipeline pipeline;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class DescriptorModel {
/**
* The namespace of the vocabulary as a string
*/
private static final String prefix = "http://onto.fel.cvut.cz/ontologies/dataset-descriptor/temporal-v1/";
public static final String prefix = "http://onto.fel.cvut.cz/ontologies/dataset-descriptor/temporal-v1/";

protected static final Resource resource(String local )
{ return ResourceFactory.createResource( prefix + local ); }
Expand Down
Loading