
be.ugent.rml.functions.FunctionModel Maven / Gradle / Ivy
package be.ugent.rml.functions;
import be.ugent.rml.term.Term;
import net.minidev.json.parser.JSONParser;
import net.minidev.json.parser.ParseException;
import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Value;
import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.time.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
/**
* Function Model
*
* @author bjdmeest
*/
public class FunctionModel {
private final List parameters; // parameters urls
private final List outputs; // output types
private Term URI;
private Method method;
protected Logger logger = LoggerFactory.getLogger(this.getClass());
public FunctionModel(Term URI, Method m, List parameters, List outputs) {
this.URI = URI;
this.method = m;
this.parameters = parameters;
this.outputs = outputs;
}
public Object execute(Map args) {
Object[] parameters = this.getParameters(args);
try {
return this.method.invoke(null, parameters);
// ArrayList result = this.toValue(object, this.getDataType(args));
} catch (IllegalAccessException | InvocationTargetException e) {
// Nothing to do?
e.printStackTrace(); // maybe this? :p
}
return null;
}
public Term getURI() {
return URI;
}
private ArrayList toValue(Object result, IRI type) {
SimpleValueFactory vf = SimpleValueFactory.getInstance();
ArrayList values = new ArrayList<>();
if (!(result instanceof Collection>)) {
ArrayList
© 2015 - 2025 Weber Informatics LLC | Privacy Policy