Skip to content

Commit fb46f4e

Browse files
committed
Merge branch 'development'
2 parents 79ee09b + 639064a commit fb46f4e

File tree

21 files changed

+522
-649
lines changed

21 files changed

+522
-649
lines changed

.gitlab-ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ cache:
3636
script:
3737
- 'mvn $MAVEN_CLI_OPTS test'
3838

39-
# Test merge requests using JDK8
40-
test:jdk8:
39+
# Test using JDK17
40+
test:jdk17:
4141
<<: *test
42-
image: maven:3-jdk-8
42+
image: maven:3-eclipse-temurin-17-alpine # Java 17 is the latest LTS at the moment

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8+
## [1.0.0] - 2022-12-08
9+
10+
### Changed
11+
- Updated JUnit from 4.13.2 to 5.9.1 (tests)
12+
- Updated grel-functions-java from v0.7.3 to v0.9.0 (tests)
13+
- Updated jena-arq from 3.17.0 to 4.6.1
14+
- Updated Lombok from 1.18.22 to 1.18.24
15+
- Updated slf4j from 1.7.36 to 2.0.5
16+
- Java language version changed to 11; requires JRE >= 11 to run
17+
- be.ugent.idlab.knows.functions.agent.Agent: deleted methods that were not meant to be in this interface again.
18+
19+
### Fixed
20+
- be.ugent.idlab.knows.functions.agent.AgentTest.testGrelClassesOnClassPathRemoteFnODoc: point remote `grel.ttl` to specific GitHub commit to keep function definitions and implementations in sync.
21+
822
## [0.2.1] - 2022-10-10
923

1024
### Fixed
@@ -63,6 +77,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
6377

6478
## [0.0.1] - 2022-03-25
6579

80+
[1.0.0]: https://github.com/FnOio/function-agent-java/compare/v0.2.1...v1.0.0
6681
[0.2.1]: https://github.com/FnOio/function-agent-java/compare/v0.2.0...v0.2.1
6782
[0.2.0]: https://github.com/FnOio/function-agent-java/compare/v0.1.0...v0.2.0
6883
[0.1.0]: https://github.com/FnOio/function-agent-java/compare/v0.0.4...v0.1.0

pom.xml

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@
66

77
<groupId>be.ugent.idlab.knows</groupId>
88
<artifactId>function-agent-java</artifactId>
9-
<version>0.2.1</version>
9+
<version>1.0.0</version>
1010

1111
<name>function-agent-java</name>
1212
<url>https://fno.io/</url>
1313

1414
<properties>
1515
<commons.version>4.4</commons.version>
16-
<jena.version>3.17.0</jena.version>
17-
<slf4j.version>1.7.36</slf4j.version>
18-
<junit.version>4.13.2</junit.version>
19-
<lombok.version>1.18.22</lombok.version>
20-
<grel.java.version>v0.7.3</grel.java.version>
16+
<jena.version>4.6.1</jena.version>
17+
<slf4j.version>2.0.5</slf4j.version>
18+
<junit.version>5.9.1</junit.version>
19+
<lombok.version>1.18.24</lombok.version>
20+
<grel.java.version>v0.9.0</grel.java.version>
2121
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2222

23-
<!-- we stick to Java 8 because this library is integrated in RMLMapper (https://github.com/RMLio/rmlmapper-java) -->
24-
<maven.compiler.source>8</maven.compiler.source>
25-
<maven.compiler.target>8</maven.compiler.target>
23+
<!-- This is the language level, it is recommended to use the latests LTS JVM to build / run it -->
24+
<maven.compiler.source>11</maven.compiler.source>
25+
<maven.compiler.target>11</maven.compiler.target>
2626
</properties>
2727

2828
<repositories>
@@ -69,8 +69,14 @@
6969

7070
<!-- Unit test framework -->
7171
<dependency>
72-
<groupId>junit</groupId>
73-
<artifactId>junit</artifactId>
72+
<groupId>org.junit.jupiter</groupId>
73+
<artifactId>junit-jupiter-engine</artifactId>
74+
<version>${junit.version}</version>
75+
<scope>test</scope>
76+
</dependency>
77+
<dependency>
78+
<groupId>org.junit.jupiter</groupId>
79+
<artifactId>junit-jupiter-api</artifactId>
7480
<version>${junit.version}</version>
7581
<scope>test</scope>
7682
</dependency>

src/main/java/be/ugent/idlab/knows/functions/agent/Agent.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package be.ugent.idlab.knows.functions.agent;
22

3-
import java.io.IOException;
4-
import java.lang.reflect.Method;
5-
import java.util.List;
6-
73
/**
84
* <p>Copyright 2021 IDLab (Ghent University - imec)</p>
95
*
@@ -28,14 +24,4 @@ public interface Agent {
2824
* @throws Exception Something goes wrong looking up the function or executing it.
2925
*/
3026
Object execute(final String functionId, final Arguments arguments, boolean debug) throws Exception;
31-
32-
void executeToFile(final String functionId, final Arguments arguments, final String fileName) throws Exception;
33-
34-
void executeToFile(final String functionId, final Arguments arguments, final String fileName, boolean debug) throws Exception;
35-
36-
void writeModel(final String filename) throws IOException;
37-
38-
String loadFunction(final Method javaFunction);
39-
40-
List<String> getParameterPredicates(String functionId);
4127
}

src/main/java/be/ugent/idlab/knows/functions/agent/AgentImpl.java

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package be.ugent.idlab.knows.functions.agent;
22

33
import be.ugent.idlab.knows.functions.agent.dataType.DataTypeConverter;
4+
import be.ugent.idlab.knows.functions.agent.dataType.DataTypeConverterException;
45
import be.ugent.idlab.knows.functions.agent.dataType.DataTypeConverterProvider;
56
import be.ugent.idlab.knows.functions.agent.exception.MissingRDFSeqIndexException;
67
import be.ugent.idlab.knows.functions.agent.functionIntantiation.Instantiator;
@@ -40,6 +41,9 @@ public class AgentImpl implements Agent {
4041
private final Map<String, Function> functionId2Function;
4142
private final Instantiator instantiator;
4243

44+
// pattern for finding rdf:_nnn parameters
45+
final private Pattern seq_pattern = Pattern.compile(RDF +"_\\d+");
46+
4347
public AgentImpl(final Map<String, Function> functionId2Function, final Instantiator instantiator) {
4448
this.functionId2Function = functionId2Function;
4549
this.instantiator = instantiator;
@@ -70,24 +74,25 @@ public Object execute(String functionId, Arguments arguments, boolean debug) thr
7074
// find the corresponding function
7175
final Function function = functionId2Function.get(functionId);
7276

73-
if (Objects.isNull(function)) {
77+
if (function == null) {
7478
throw new FunctionNotFoundException("Function with id " + functionId + " not found");
7579
}
7680

77-
Method method = null;
78-
// get the method if the function is not a composition
79-
// when moved to if-statement after parameter loading, tests fail (not sure why)
80-
if (!function.isComposite()) {
81-
method = instantiator.getMethod(functionId);
82-
if(method == null){
83-
throw new MethodNotFoundException("No method found for function " + functionId);
81+
if (function.isComposite()) {
82+
List<Object> values = getParameterValues(functionId, arguments, function);
83+
return instantiator.getCompositeMethod(functionId, debug).apply(this, values.toArray());
84+
} else {
85+
Method method = instantiator.getMethod(functionId);
86+
if (method != null) {
87+
List<Object> values = getParameterValues(functionId, arguments, function);
88+
return method.invoke(null, values.toArray());
89+
} else {
90+
throw new MethodNotFoundException("No method found for function " + function.getId() + " (" + function.getName() + ')');
8491
}
8592
}
93+
}
8694

87-
// pattern for finding rdf:_nnn parameters
88-
Pattern pattern = Pattern.compile(RDF +"_\\d+");
89-
90-
// "fill in" the argument parameters
95+
private List<Object> getParameterValues(String functionId, Arguments arguments, Function function) throws MissingRDFSeqIndexException, DataTypeConverterException {
9196
final List<Object> valuesInOrder = new ArrayList<>(arguments.size());
9297
for (Parameter argumentParameter : function.getArgumentParameters()) {
9398
logger.debug("finding value for parameter {}", argumentParameter.getId());
@@ -98,7 +103,7 @@ public Object execute(String functionId, Arguments arguments, boolean debug) thr
98103
logger.debug("found sequential parameter (_nnn), looking for values");
99104
// get the highest available sequence index
100105
Optional<Integer> optionalInteger = arguments.getArgumentNames().stream()
101-
.filter(name -> pattern.matcher(name).matches())
106+
.filter(name -> seq_pattern.matcher(name).matches())
102107
.map(i -> Integer.parseInt(i.substring(RDF.toString().length()+1)))
103108
.max(Integer::compareTo);
104109

@@ -133,22 +138,14 @@ public Object execute(String functionId, Arguments arguments, boolean debug) thr
133138
}
134139
}
135140
}
136-
137-
// now execute the method
138-
if (!function.isComposite()) {
139-
return method.invoke(null, valuesInOrder.toArray());
140-
}
141-
// if the function is a composition, there is no specific method associated with.
142-
return instantiator.getCompositeMethod(functionId, debug).apply(this, valuesInOrder.toArray());
141+
return valuesInOrder;
143142
}
144143

145-
@Override
146-
public void executeToFile(String functionId, Arguments arguments, String fileName) throws Exception {
144+
void executeToFile(String functionId, Arguments arguments, String fileName) throws Exception {
147145
this.executeToFile(functionId, arguments, fileName, false);
148146
}
149147

150-
@Override
151-
public void executeToFile(String functionId, Arguments arguments, String fileName, boolean debug) throws Exception {
148+
void executeToFile(String functionId, Arguments arguments, String fileName, boolean debug) throws Exception {
152149
constructResult(functionId, arguments, fileName, debug);
153150
}
154151

@@ -188,8 +185,7 @@ private void printModel(Model model, String filename) throws IOException {
188185
}
189186
}
190187

191-
@Override
192-
public String loadFunction(Method javaFunction) {
188+
String loadFunction(Method javaFunction) {
193189
DataTypeConverterProvider dataTypeConverterProvider = new DataTypeConverterProvider();
194190
if (!Modifier.isStatic(javaFunction.getModifiers())) {
195191
throw new UnsupportedOperationException("Java function needs to be static");
@@ -241,13 +237,11 @@ private FunctionMapping loadFunctionMapping(Method javaFunction, String function
241237
return new FunctionMapping(functionId, methodMapping, implementation);
242238
}
243239

244-
@Override
245-
public List<String> getParameterPredicates(String functionId) {
240+
List<String> getParameterPredicates(String functionId) {
246241
return this.functionId2Function.get(functionId).getArgumentParameters().stream().map(Parameter::getId).collect(Collectors.toList());
247242
}
248243

249-
@Override
250-
public void writeModel(String filename) throws IOException {
244+
void writeModel(String filename) throws IOException {
251245
Model model = ModelFactory.createDefaultModel();
252246
for (Function function : this.functionId2Function.values()) {
253247
DescriptionGenerator.addFunctionToModel(model, function);

src/main/java/be/ugent/idlab/knows/functions/agent/Arguments.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,12 @@ public Set<String> getArgumentNames() {
5858
@Override
5959
public String toString() {
6060
final StringBuilder str = new StringBuilder();
61-
nameToValueMap.entries().forEach(entry -> {
62-
str
63-
.append("('")
64-
.append(entry.getKey())
65-
.append("' -> '")
66-
.append(entry.getValue().toString())
67-
.append("')");
68-
});
61+
nameToValueMap.entries().forEach(entry -> str
62+
.append("('")
63+
.append(entry.getKey())
64+
.append("' -> '")
65+
.append(entry.getValue().toString())
66+
.append("')"));
6967
return str.toString();
7068
}
7169
}

0 commit comments

Comments
 (0)