You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by ja...@apache.org on 2013/02/21 12:23:28 UTC
[9/19] MARMOTTA-104: renamed packages in ldpath (resolved)
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5b8766b3/libraries/ldpath/ldpath-core/src/test/java/parse/ParserTest.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-core/src/test/java/parse/ParserTest.java b/libraries/ldpath/ldpath-core/src/test/java/parse/ParserTest.java
deleted file mode 100644
index a048b41..0000000
--- a/libraries/ldpath/ldpath-core/src/test/java/parse/ParserTest.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Copyright (c) 2013 Salzburg Research.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package parse;
-
-import at.newmedialab.ldpath.api.backend.RDFBackend;
-import at.newmedialab.ldpath.api.tests.NodeTest;
-import at.newmedialab.ldpath.api.transformers.NodeTransformer;
-import at.newmedialab.ldpath.model.programs.Program;
-import at.newmedialab.ldpath.parser.ParseException;
-import at.newmedialab.ldpath.parser.RdfPathParser;
-import org.apache.commons.io.IOUtils;
-import org.hamcrest.CoreMatchers;
-import org.junit.Assume;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import java.io.IOException;
-import java.io.StringReader;
-import java.net.URL;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.junit.Assert.*;
-
-
-public class ParserTest {
-
- private static RDFBackend<String> backend;
- private static final String NS_TEST = "http://example.com/";
- private static final String NS_FOO = "http://foo.com/some/path#";
-
- private static final Map<String, String> NAMESPACES;
- static {
- Map<String, String> ns = new HashMap<String, String>();
- ns.put("test", NS_TEST);
- ns.put("foo", NS_FOO);
- NAMESPACES = Collections.unmodifiableMap(ns);
- }
-
- @BeforeClass
- public static void initClass() {
- backend = new EmptyTestingBackend();
- }
-
-
- @Test
- public void testParseProgram() throws IOException {
- RdfPathParser<String> parser = createParser("program.txt");
- try {
- Program<String> program = parser.parseProgram();
- assertNotNull(program.getField("path"));
- assertNotNull(program.getField("lang_test"));
- assertNotNull(program.getField("type_test"));
- assertNotNull(program.getField("int_s"));
- assertNotNull(program.getField("int_p"));
- assertNotNull(program.getField("inverse"));
- assertNotNull(program.getField("config"));
- assertNotNull(program.getBooster());
- assertNotNull(program.getFilter());
-
- } catch (ParseException e) {
- assertFalse(e.getMessage(), true);
- }
- }
-
- @Test
- public void testParseTest() throws IOException {
- RdfPathParser<String> parser = createParser("test.txt");
- try {
- NodeTest<String> test = parser.parseTest(NAMESPACES);
- assertNotNull(test);
- assertNotNull(test.getPathExpression(backend));
- } catch (ParseException e) {
- fail(e.getMessage());
- }
- }
-
- @Test
- public void testParsePrefixes() throws IOException {
- RdfPathParser<String> parser = createParser("namespaces.txt");
- try {
- Map<String, String> prefixes = parser.parsePrefixes();
- assertTrue(prefixes.containsKey("test"));
- assertTrue(prefixes.containsKey("foo"));
- assertEquals(NS_TEST, prefixes.get("test"));
- assertEquals(NS_FOO, prefixes.get("foo"));
- } catch (ParseException e) {
- assertFalse(e.getMessage(), true);
- }
- }
-
-
- private RdfPathParser<String> createParser(String input) throws IOException {
- final URL resource = ParserTest.class.getResource(input);
- Assume.assumeThat("Could not load test input data '" + input + "'", resource, CoreMatchers.notNullValue());
-
- RdfPathParser<String> rdfPathParser = new RdfPathParser<String>(backend,new StringReader(IOUtils.toString(resource)));
- rdfPathParser.registerTransformer(NS_TEST + "type", new NodeTransformer<String, String>() {
- @Override
- public String transform(RDFBackend<String> backend, String node)
- throws IllegalArgumentException {
- return node;
- }
- });
- return rdfPathParser;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5b8766b3/libraries/ldpath/ldpath-functions-collections/pom.xml
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-functions-collections/pom.xml b/libraries/ldpath/ldpath-functions-collections/pom.xml
index b54b847..ccb3b8f 100644
--- a/libraries/ldpath/ldpath-functions-collections/pom.xml
+++ b/libraries/ldpath/ldpath-functions-collections/pom.xml
@@ -82,7 +82,7 @@
<!-- Enable this for including your enhancement chain configuration -->
<!-- <Install-Path>config</Install-Path> -->
<Export-Package>
- at.newmedialab.ldpath.model.*;version=${project.version},
+ org.apache.marmotta.ldpath.model.*;version=${project.version},
</Export-Package>
<_include>src/main/resources/META-INF/MANIFEST.MF</_include>
</instructions>
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5b8766b3/libraries/ldpath/ldpath-functions-collections/src/main/java/at/newmedialab/ldpath/model/functions/coll/AbstractCollFunction.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-functions-collections/src/main/java/at/newmedialab/ldpath/model/functions/coll/AbstractCollFunction.java b/libraries/ldpath/ldpath-functions-collections/src/main/java/at/newmedialab/ldpath/model/functions/coll/AbstractCollFunction.java
deleted file mode 100644
index 5fc0e4a..0000000
--- a/libraries/ldpath/ldpath-functions-collections/src/main/java/at/newmedialab/ldpath/model/functions/coll/AbstractCollFunction.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/**
- * Copyright (C) 2013 Salzburg Research.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package at.newmedialab.ldpath.model.functions.coll;
-
-import at.newmedialab.ldpath.api.backend.RDFBackend;
-import at.newmedialab.ldpath.api.functions.SelectorFunction;
-
-import java.util.Collection;
-
-public abstract class AbstractCollFunction<Node> extends SelectorFunction<Node> {
-
- protected static final String RDF = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
-
- protected int getIndex(RDFBackend<Node> backend, Collection<Node> collection) {
- if (collection.size() != 1) { throw new IllegalArgumentException("index must be a singel integer literal"); }
- return backend.intValue(collection.iterator().next());
- }
-
- protected boolean hasType(RDFBackend<Node> backend, Node node, String type) {
- return backend.listObjects(node, backend.createURI(RDF + "type")).contains(backend.createURI(type));
- }
-
- protected boolean isNil(RDFBackend<Node> backend, Node node) {
- return backend.isURI(node) && backend.stringValue(node).equals(RDF + "nil");
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5b8766b3/libraries/ldpath/ldpath-functions-collections/src/main/java/at/newmedialab/ldpath/model/functions/coll/FlattenFunction.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-functions-collections/src/main/java/at/newmedialab/ldpath/model/functions/coll/FlattenFunction.java b/libraries/ldpath/ldpath-functions-collections/src/main/java/at/newmedialab/ldpath/model/functions/coll/FlattenFunction.java
deleted file mode 100644
index 8050a64..0000000
--- a/libraries/ldpath/ldpath-functions-collections/src/main/java/at/newmedialab/ldpath/model/functions/coll/FlattenFunction.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/**
- * Copyright (C) 2013 Salzburg Research.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package at.newmedialab.ldpath.model.functions.coll;
-
-import at.newmedialab.ldpath.api.backend.RDFBackend;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-
-
-public class FlattenFunction<Node> extends AbstractCollFunction<Node> {
-
-
- @Override
- public Collection<Node> apply(RDFBackend<Node> backend, Node context, Collection<Node>... args) throws IllegalArgumentException {
- if (args.length > 1) {
- throw new IllegalArgumentException(getLocalName() + " must not have more than one parameter");
- }
- final Collection<Node> nodes;
- if (args.length > 0) {
- nodes = args[0];
- } else {
- nodes = Collections.singleton(context);
- }
-
- final List<Node> result = new LinkedList<Node>();
- for (Node node : nodes) {
- if (hasType(backend, node, RDF + "Bag")) {
- flattenContainer(backend, node, result);
- } else if (hasType(backend, node, RDF + "Seq")) {
- flattenContainer(backend, node, result);
- } else if (hasType(backend, node, RDF + "List")) {
- flattenCollection(backend, node, result, new HashSet<Node>());
- } else {
- flattenCollection(backend, node, result, new HashSet<Node>());
- }
- }
-
- return result;
- }
-
- private void flattenCollection(RDFBackend<Node> backend, Node node, Collection<Node> result, Collection<Node> backtrace) {
- if (isNil(backend, node)) {
- return;
- }
-
- // Stop if we detect a cycle.
- if (!backtrace.add(node)) {
- return;
- }
-
- // Add the (all) firsts
- result.addAll(backend.listObjects(node, backend.createURI(RDF + "first")));
-
- // Recursively add the rest
- final Collection<Node> rest = backend.listObjects(node, backend.createURI(RDF + "rest"));
- for (Node r : rest) {
- flattenCollection(backend, r, result, backtrace);
- }
- }
-
- private void flattenContainer(RDFBackend<Node> backend, Node node, Collection<Node> result) {
- for (int i = 1; /* exit via break */; i++) {
- final Collection<Node> objects = backend.listObjects(node, backend.createURI(RDF + "_" + i));
- if (objects.size() > 0) {
- result.addAll(objects);
- } else {
- break;
- }
- }
- }
-
- @Override
- public String getSignature() {
- return "fn:flatten([nodes: NodeList]) :: NodeList";
- }
-
- @Override
- public String getDescription() {
- return "Flattens a rdf-Collection";
- }
-
- @Override
- protected String getLocalName() {
- return "flatten";
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5b8766b3/libraries/ldpath/ldpath-functions-collections/src/main/java/at/newmedialab/ldpath/model/functions/coll/GetFunction.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-functions-collections/src/main/java/at/newmedialab/ldpath/model/functions/coll/GetFunction.java b/libraries/ldpath/ldpath-functions-collections/src/main/java/at/newmedialab/ldpath/model/functions/coll/GetFunction.java
deleted file mode 100644
index ef993d0..0000000
--- a/libraries/ldpath/ldpath-functions-collections/src/main/java/at/newmedialab/ldpath/model/functions/coll/GetFunction.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/**
- * Copyright (C) 2013 Salzburg Research.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package at.newmedialab.ldpath.model.functions.coll;
-
-import at.newmedialab.ldpath.api.backend.RDFBackend;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-
-public class GetFunction<Node> extends AbstractCollFunction<Node> {
-
- @Override
- public Collection<Node> apply(RDFBackend<Node> backend, Node context, Collection<Node>... args) throws IllegalArgumentException {
- final Collection<Node> nodes;
- final int index;
- switch (args.length) {
- case 1:
- nodes = Collections.singleton(context);
- index = getIndex(backend, args[0]);
- break;
- case 2:
- nodes = args[0];
- index = getIndex(backend, args[1]);
- break;
- default:
- throw new IllegalArgumentException(getLocalName() + " must not have more than one or two parameters");
- }
-
- Collection<Node> result = new HashSet<Node>();
- for (Node node : nodes) {
- if (hasType(backend, node, RDF + "Bag")) {
- result.addAll(getFromContainer(backend, node, index));
- } else if (hasType(backend, node, RDF + "Seq")) {
- result.addAll(getFromContainer(backend, node, index));
- } else if (hasType(backend, node, RDF + "List")) {
- result.addAll(getFromCollection(backend, node, index));
- } else {
- result.addAll(getFromCollection(backend, node, index));
- }
- }
- return result;
- }
-
- private Collection<Node> getFromCollection(RDFBackend<Node> backend, Node node, int index) {
- if (index < 0 || isNil(backend, node)) {
- return Collections.emptySet();
- } else if (index == 0) {
- return backend.listObjects(node, backend.createURI(RDF + "first"));
- } else {
- HashSet<Node> result = new HashSet<Node>();
- for (Node n : backend.listObjects(node, backend.createURI(RDF + "rest"))) {
- result.addAll(getFromCollection(backend, n, index - 1));
- }
- return result;
- }
- }
-
- private Collection<Node> getFromContainer(RDFBackend<Node> backend, Node node, int index) {
- return backend.listObjects(node, backend.createURI(RDF + "_" + (index + 1)));
- }
-
- @Override
- public String getSignature() {
- return "fn:get([nodes: NodeList,] n: Integer) :: NodeList";
- }
-
- @Override
- public String getDescription() {
- return "retrieve the nth element from a rdf-Collection (0-based)";
- }
-
- @Override
- protected String getLocalName() {
- return "get";
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5b8766b3/libraries/ldpath/ldpath-functions-collections/src/main/java/at/newmedialab/ldpath/model/functions/coll/SubListFunction.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-functions-collections/src/main/java/at/newmedialab/ldpath/model/functions/coll/SubListFunction.java b/libraries/ldpath/ldpath-functions-collections/src/main/java/at/newmedialab/ldpath/model/functions/coll/SubListFunction.java
deleted file mode 100644
index 0e27333..0000000
--- a/libraries/ldpath/ldpath-functions-collections/src/main/java/at/newmedialab/ldpath/model/functions/coll/SubListFunction.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/**
- * Copyright (C) 2013 Salzburg Research.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package at.newmedialab.ldpath.model.functions.coll;
-
-import at.newmedialab.ldpath.api.backend.RDFBackend;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-
-public class SubListFunction<Node> extends AbstractCollFunction<Node> {
-
- @Override
- public Collection<Node> apply(RDFBackend<Node> backend, Node context, Collection<Node>... args) throws IllegalArgumentException {
- final Collection<Node> nodes;
- final int start, end;
- switch (args.length) {
- case 1:
- nodes = Collections.singleton(context);
- start = getIndex(backend, args[0]);
- end = Integer.MAX_VALUE;
- break;
- case 2:
- if (args[0].size() == 1 && backend.isLiteral(args[0].iterator().next())) {
- nodes = Collections.singleton(context);
- start = getIndex(backend, args[0]);
- end = getIndex(backend, args[1]);
- } else {
- nodes = args[0];
- start = getIndex(backend, args[1]);
- end = Integer.MAX_VALUE;
- }
- break;
- case 3:
- nodes = args[0];
- start = getIndex(backend, args[1]);
- end = getIndex(backend, args[2]);
- break;
- default:
- throw new IllegalArgumentException(getLocalName() + " takes at most 3 arguments");
- }
-
- final List<Node> result = new LinkedList<Node>();
- for (Node node : nodes) {
- if (hasType(backend, node, RDF + "Bag")) {
- result.addAll(subListFromContainer(backend, node, start, end));
- } else if (hasType(backend, node, RDF + "Seq")) {
- result.addAll(subListFromContainer(backend, node, start, end));
- } else if (hasType(backend, node, RDF + "List")) {
- subListFromCollection(backend, node, start, end, result);
- } else {
- subListFromCollection(backend, node, start, end, result);
- }
- }
-
- return result;
- }
-
- private void subListFromCollection(RDFBackend<Node> backend, Node node, int start, int end, List<Node> result) {
- if (isNil(backend, node)) { return; }
-
- if (end > 0) {
- if (start <= 0) {
- result.addAll(backend.listObjects(node, backend.createURI(RDF + "first")));
- }
- for (Node n : backend.listObjects(node, backend.createURI(RDF + "rest"))) {
- subListFromCollection(backend, n, start - 1, end - 1, result);
- }
- }
-
- }
-
- private Collection<? extends Node> subListFromContainer(RDFBackend<Node> backend, Node node, int start, int end) {
- List<Node> result = new LinkedList<Node>();
- for (int i = start; i < end; i++) {
- final Collection<Node> objects = backend.listObjects(node, backend.createURI(RDF + "_" + (i + 1)));
- if (objects.size() > 0) {
- result.addAll(objects);
- } else {
- break;
- }
- }
- return result;
- }
-
- @Override
- public String getSignature() {
- return "fn:subList([nodes: NodeList,] start: Integer [, end: Integer]) :: NodeList";
- }
-
- @Override
- public String getDescription() {
- return "select a range from a rdf-Collection (like substring does for strings, 0-based)";
- }
-
- @Override
- protected String getLocalName() {
- return "subList";
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5b8766b3/libraries/ldpath/ldpath-functions-collections/src/main/java/org/apache/marmotta/ldpath/model/functions/coll/AbstractCollFunction.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-functions-collections/src/main/java/org/apache/marmotta/ldpath/model/functions/coll/AbstractCollFunction.java b/libraries/ldpath/ldpath-functions-collections/src/main/java/org/apache/marmotta/ldpath/model/functions/coll/AbstractCollFunction.java
new file mode 100644
index 0000000..1f3e7d1
--- /dev/null
+++ b/libraries/ldpath/ldpath-functions-collections/src/main/java/org/apache/marmotta/ldpath/model/functions/coll/AbstractCollFunction.java
@@ -0,0 +1,41 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.marmotta.ldpath.model.functions.coll;
+
+
+import java.util.Collection;
+
+import org.apache.marmotta.ldpath.api.backend.RDFBackend;
+import org.apache.marmotta.ldpath.api.functions.SelectorFunction;
+
+public abstract class AbstractCollFunction<Node> extends SelectorFunction<Node> {
+
+ protected static final String RDF = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
+
+ protected int getIndex(RDFBackend<Node> backend, Collection<Node> collection) {
+ if (collection.size() != 1) { throw new IllegalArgumentException("index must be a singel integer literal"); }
+ return backend.intValue(collection.iterator().next());
+ }
+
+ protected boolean hasType(RDFBackend<Node> backend, Node node, String type) {
+ return backend.listObjects(node, backend.createURI(RDF + "type")).contains(backend.createURI(type));
+ }
+
+ protected boolean isNil(RDFBackend<Node> backend, Node node) {
+ return backend.isURI(node) && backend.stringValue(node).equals(RDF + "nil");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5b8766b3/libraries/ldpath/ldpath-functions-collections/src/main/java/org/apache/marmotta/ldpath/model/functions/coll/FlattenFunction.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-functions-collections/src/main/java/org/apache/marmotta/ldpath/model/functions/coll/FlattenFunction.java b/libraries/ldpath/ldpath-functions-collections/src/main/java/org/apache/marmotta/ldpath/model/functions/coll/FlattenFunction.java
new file mode 100644
index 0000000..c1d3bb2
--- /dev/null
+++ b/libraries/ldpath/ldpath-functions-collections/src/main/java/org/apache/marmotta/ldpath/model/functions/coll/FlattenFunction.java
@@ -0,0 +1,105 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.marmotta.ldpath.model.functions.coll;
+
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.marmotta.ldpath.api.backend.RDFBackend;
+
+
+public class FlattenFunction<Node> extends AbstractCollFunction<Node> {
+
+
+ @Override
+ public Collection<Node> apply(RDFBackend<Node> backend, Node context, Collection<Node>... args) throws IllegalArgumentException {
+ if (args.length > 1) {
+ throw new IllegalArgumentException(getLocalName() + " must not have more than one parameter");
+ }
+ final Collection<Node> nodes;
+ if (args.length > 0) {
+ nodes = args[0];
+ } else {
+ nodes = Collections.singleton(context);
+ }
+
+ final List<Node> result = new LinkedList<Node>();
+ for (Node node : nodes) {
+ if (hasType(backend, node, RDF + "Bag")) {
+ flattenContainer(backend, node, result);
+ } else if (hasType(backend, node, RDF + "Seq")) {
+ flattenContainer(backend, node, result);
+ } else if (hasType(backend, node, RDF + "List")) {
+ flattenCollection(backend, node, result, new HashSet<Node>());
+ } else {
+ flattenCollection(backend, node, result, new HashSet<Node>());
+ }
+ }
+
+ return result;
+ }
+
+ private void flattenCollection(RDFBackend<Node> backend, Node node, Collection<Node> result, Collection<Node> backtrace) {
+ if (isNil(backend, node)) {
+ return;
+ }
+
+ // Stop if we detect a cycle.
+ if (!backtrace.add(node)) {
+ return;
+ }
+
+ // Add the (all) firsts
+ result.addAll(backend.listObjects(node, backend.createURI(RDF + "first")));
+
+ // Recursively add the rest
+ final Collection<Node> rest = backend.listObjects(node, backend.createURI(RDF + "rest"));
+ for (Node r : rest) {
+ flattenCollection(backend, r, result, backtrace);
+ }
+ }
+
+ private void flattenContainer(RDFBackend<Node> backend, Node node, Collection<Node> result) {
+ for (int i = 1; /* exit via break */; i++) {
+ final Collection<Node> objects = backend.listObjects(node, backend.createURI(RDF + "_" + i));
+ if (objects.size() > 0) {
+ result.addAll(objects);
+ } else {
+ break;
+ }
+ }
+ }
+
+ @Override
+ public String getSignature() {
+ return "fn:flatten([nodes: NodeList]) :: NodeList";
+ }
+
+ @Override
+ public String getDescription() {
+ return "Flattens a rdf-Collection";
+ }
+
+ @Override
+ protected String getLocalName() {
+ return "flatten";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5b8766b3/libraries/ldpath/ldpath-functions-collections/src/main/java/org/apache/marmotta/ldpath/model/functions/coll/GetFunction.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-functions-collections/src/main/java/org/apache/marmotta/ldpath/model/functions/coll/GetFunction.java b/libraries/ldpath/ldpath-functions-collections/src/main/java/org/apache/marmotta/ldpath/model/functions/coll/GetFunction.java
new file mode 100644
index 0000000..86ec6de
--- /dev/null
+++ b/libraries/ldpath/ldpath-functions-collections/src/main/java/org/apache/marmotta/ldpath/model/functions/coll/GetFunction.java
@@ -0,0 +1,92 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.marmotta.ldpath.model.functions.coll;
+
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+
+import org.apache.marmotta.ldpath.api.backend.RDFBackend;
+
+public class GetFunction<Node> extends AbstractCollFunction<Node> {
+
+ @Override
+ public Collection<Node> apply(RDFBackend<Node> backend, Node context, Collection<Node>... args) throws IllegalArgumentException {
+ final Collection<Node> nodes;
+ final int index;
+ switch (args.length) {
+ case 1:
+ nodes = Collections.singleton(context);
+ index = getIndex(backend, args[0]);
+ break;
+ case 2:
+ nodes = args[0];
+ index = getIndex(backend, args[1]);
+ break;
+ default:
+ throw new IllegalArgumentException(getLocalName() + " must not have more than one or two parameters");
+ }
+
+ Collection<Node> result = new HashSet<Node>();
+ for (Node node : nodes) {
+ if (hasType(backend, node, RDF + "Bag")) {
+ result.addAll(getFromContainer(backend, node, index));
+ } else if (hasType(backend, node, RDF + "Seq")) {
+ result.addAll(getFromContainer(backend, node, index));
+ } else if (hasType(backend, node, RDF + "List")) {
+ result.addAll(getFromCollection(backend, node, index));
+ } else {
+ result.addAll(getFromCollection(backend, node, index));
+ }
+ }
+ return result;
+ }
+
+ private Collection<Node> getFromCollection(RDFBackend<Node> backend, Node node, int index) {
+ if (index < 0 || isNil(backend, node)) {
+ return Collections.emptySet();
+ } else if (index == 0) {
+ return backend.listObjects(node, backend.createURI(RDF + "first"));
+ } else {
+ HashSet<Node> result = new HashSet<Node>();
+ for (Node n : backend.listObjects(node, backend.createURI(RDF + "rest"))) {
+ result.addAll(getFromCollection(backend, n, index - 1));
+ }
+ return result;
+ }
+ }
+
+ private Collection<Node> getFromContainer(RDFBackend<Node> backend, Node node, int index) {
+ return backend.listObjects(node, backend.createURI(RDF + "_" + (index + 1)));
+ }
+
+ @Override
+ public String getSignature() {
+ return "fn:get([nodes: NodeList,] n: Integer) :: NodeList";
+ }
+
+ @Override
+ public String getDescription() {
+ return "retrieve the nth element from a rdf-Collection (0-based)";
+ }
+
+ @Override
+ protected String getLocalName() {
+ return "get";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5b8766b3/libraries/ldpath/ldpath-functions-collections/src/main/java/org/apache/marmotta/ldpath/model/functions/coll/SubListFunction.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-functions-collections/src/main/java/org/apache/marmotta/ldpath/model/functions/coll/SubListFunction.java b/libraries/ldpath/ldpath-functions-collections/src/main/java/org/apache/marmotta/ldpath/model/functions/coll/SubListFunction.java
new file mode 100644
index 0000000..14f5e77
--- /dev/null
+++ b/libraries/ldpath/ldpath-functions-collections/src/main/java/org/apache/marmotta/ldpath/model/functions/coll/SubListFunction.java
@@ -0,0 +1,116 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.marmotta.ldpath.model.functions.coll;
+
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.marmotta.ldpath.api.backend.RDFBackend;
+
+public class SubListFunction<Node> extends AbstractCollFunction<Node> {
+
+ @Override
+ public Collection<Node> apply(RDFBackend<Node> backend, Node context, Collection<Node>... args) throws IllegalArgumentException {
+ final Collection<Node> nodes;
+ final int start, end;
+ switch (args.length) {
+ case 1:
+ nodes = Collections.singleton(context);
+ start = getIndex(backend, args[0]);
+ end = Integer.MAX_VALUE;
+ break;
+ case 2:
+ if (args[0].size() == 1 && backend.isLiteral(args[0].iterator().next())) {
+ nodes = Collections.singleton(context);
+ start = getIndex(backend, args[0]);
+ end = getIndex(backend, args[1]);
+ } else {
+ nodes = args[0];
+ start = getIndex(backend, args[1]);
+ end = Integer.MAX_VALUE;
+ }
+ break;
+ case 3:
+ nodes = args[0];
+ start = getIndex(backend, args[1]);
+ end = getIndex(backend, args[2]);
+ break;
+ default:
+ throw new IllegalArgumentException(getLocalName() + " takes at most 3 arguments");
+ }
+
+ final List<Node> result = new LinkedList<Node>();
+ for (Node node : nodes) {
+ if (hasType(backend, node, RDF + "Bag")) {
+ result.addAll(subListFromContainer(backend, node, start, end));
+ } else if (hasType(backend, node, RDF + "Seq")) {
+ result.addAll(subListFromContainer(backend, node, start, end));
+ } else if (hasType(backend, node, RDF + "List")) {
+ subListFromCollection(backend, node, start, end, result);
+ } else {
+ subListFromCollection(backend, node, start, end, result);
+ }
+ }
+
+ return result;
+ }
+
+ private void subListFromCollection(RDFBackend<Node> backend, Node node, int start, int end, List<Node> result) {
+ if (isNil(backend, node)) { return; }
+
+ if (end > 0) {
+ if (start <= 0) {
+ result.addAll(backend.listObjects(node, backend.createURI(RDF + "first")));
+ }
+ for (Node n : backend.listObjects(node, backend.createURI(RDF + "rest"))) {
+ subListFromCollection(backend, n, start - 1, end - 1, result);
+ }
+ }
+
+ }
+
+ private Collection<? extends Node> subListFromContainer(RDFBackend<Node> backend, Node node, int start, int end) {
+ List<Node> result = new LinkedList<Node>();
+ for (int i = start; i < end; i++) {
+ final Collection<Node> objects = backend.listObjects(node, backend.createURI(RDF + "_" + (i + 1)));
+ if (objects.size() > 0) {
+ result.addAll(objects);
+ } else {
+ break;
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public String getSignature() {
+ return "fn:subList([nodes: NodeList,] start: Integer [, end: Integer]) :: NodeList";
+ }
+
+ @Override
+ public String getDescription() {
+ return "select a range from a rdf-Collection (like substring does for strings, 0-based)";
+ }
+
+ @Override
+ protected String getLocalName() {
+ return "subList";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5b8766b3/libraries/ldpath/ldpath-functions-collections/src/main/resources/META-INF/services/at.newmedialab.ldpath.api.functions.SelectorFunction
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-functions-collections/src/main/resources/META-INF/services/at.newmedialab.ldpath.api.functions.SelectorFunction b/libraries/ldpath/ldpath-functions-collections/src/main/resources/META-INF/services/at.newmedialab.ldpath.api.functions.SelectorFunction
deleted file mode 100644
index 8c0f779..0000000
--- a/libraries/ldpath/ldpath-functions-collections/src/main/resources/META-INF/services/at.newmedialab.ldpath.api.functions.SelectorFunction
+++ /dev/null
@@ -1,3 +0,0 @@
-at.newmedialab.ldpath.model.functions.coll.FlattenFunction
-at.newmedialab.ldpath.model.functions.coll.GetFunction
-at.newmedialab.ldpath.model.functions.coll.SubListFunction
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5b8766b3/libraries/ldpath/ldpath-functions-collections/src/main/resources/META-INF/services/org.apache.marmotta.ldpath.api.functions.SelectorFunction
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-functions-collections/src/main/resources/META-INF/services/org.apache.marmotta.ldpath.api.functions.SelectorFunction b/libraries/ldpath/ldpath-functions-collections/src/main/resources/META-INF/services/org.apache.marmotta.ldpath.api.functions.SelectorFunction
new file mode 100644
index 0000000..2a9cf9f
--- /dev/null
+++ b/libraries/ldpath/ldpath-functions-collections/src/main/resources/META-INF/services/org.apache.marmotta.ldpath.api.functions.SelectorFunction
@@ -0,0 +1,3 @@
+org.apache.marmotta.ldpath.model.functions.coll.FlattenFunction
+org.apache.marmotta.ldpath.model.functions.coll.GetFunction
+org.apache.marmotta.ldpath.model.functions.coll.SubListFunction
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5b8766b3/libraries/ldpath/ldpath-functions-collections/src/test/java/coll/CollectionsTest.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-functions-collections/src/test/java/coll/CollectionsTest.java b/libraries/ldpath/ldpath-functions-collections/src/test/java/coll/CollectionsTest.java
deleted file mode 100644
index 85889ad..0000000
--- a/libraries/ldpath/ldpath-functions-collections/src/test/java/coll/CollectionsTest.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Copyright (c) 2013 Salzburg Research.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package coll;
-
-
-import core.AbstractTestBase;
-import org.hamcrest.CoreMatchers;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameter;
-import org.junit.runners.Parameterized.Parameters;
-import org.openrdf.model.URI;
-import org.openrdf.model.Value;
-import org.openrdf.repository.RepositoryException;
-import org.openrdf.rio.RDFFormat;
-import org.openrdf.rio.RDFParseException;
-
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-
-@RunWith(Parameterized.class)
-public class CollectionsTest extends AbstractTestBase {
-
- private static final int BAG_SIZE = 4;
-
- @Parameters(name = "{0}")
- public static List<String[]> data() {
- return Arrays.asList(
- new String[] { "ex:List" },
- new String[] { "ex:Bag" },
- new String[] { "ex:Seq" }
- );
- }
-
- @Parameter
- public String testContextUri;
-
- private URI uri;
-
- @Before
- public void loadData() throws RepositoryException, RDFParseException, IOException {
- super.loadData("data.n3", RDFFormat.N3);
-
- uri = createURI(testContextUri);
- }
-
- @Test
- public void testFlatten() throws Exception {
- for (String ldPath : Arrays.asList("foo:hasItems / fn:flatten()", "fn:flatten(foo:hasItems)")) {
- final Collection<Value> nodes = evaluateSelector(ldPath, uri);
- Assert.assertEquals(ldPath, BAG_SIZE, nodes.size());
- Assert.assertThat(ldPath, nodes,
- CoreMatchers.<Value> hasItems(createURI("ex:1"), createURI("ex:2"), createURI("ex:3"), createURI("ex:4")));
- }
- }
-
- @Test
- public void testGet() throws Exception {
- for (int i = 0; i < BAG_SIZE + 1; i++) {
- for ( String pattern : Arrays.asList("foo:hasItems / fn:get(\"%d\")", "fn:get(foo:hasItems,\"%d\")")) {
- final String ldPath = String.format(pattern, i);
- final Collection<Value> nodes = evaluateSelector(ldPath, uri);
- if (i < BAG_SIZE) {
- Assert.assertEquals(ldPath, 1, nodes.size());
- Assert.assertThat(ldPath, nodes,
- CoreMatchers.<Value> hasItem(createURI("ex", String.valueOf(i + 1))));
- } else {
- Assert.assertEquals(ldPath, 0, nodes.size());
- }
-
- }
- }
- }
-
- @Test
- public void testSubList() throws Exception {
- for (int i = 0; i <= BAG_SIZE + 1; i++) {
- for (String pattern : Arrays.asList("foo:hasItems / fn:subList(", "fn:subList(foo:hasItems, ")) {
- final String ldPath_1A = String.format("%s\"%d\")", pattern, i);
- final Collection<Value> nodes_1A = evaluateSelector(ldPath_1A, uri);
-
- final int expStart = Math.max(0, Math.min(i, BAG_SIZE));
-
- Assert.assertEquals(ldPath_1A, Math.max(BAG_SIZE - expStart, 0), nodes_1A.size());
- for (int e = expStart; e < BAG_SIZE; e++) {
- Assert.assertThat(ldPath_1A, nodes_1A,
- CoreMatchers.<Value> hasItem(createURI("ex", String.valueOf(e + 1))));
- }
- for (int j = i; j <= BAG_SIZE + 1; j++) {
- final String ldPath_2A = String.format("%s\"%d\", \"%d\")", pattern, i, j);
- final Collection<Value> nodes_2A = evaluateSelector(ldPath_2A, uri);
-
- final int expEnd = Math.max(0, Math.min(j, BAG_SIZE));
-
- Assert.assertEquals(ldPath_2A, expEnd - expStart, nodes_2A.size());
- for (int e = expStart; e < expEnd; e++) {
- Assert.assertThat(ldPath_2A, nodes_2A,
- CoreMatchers.<Value> hasItem(createURI("ex", String.valueOf(e + 1))));
- }
- }
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5b8766b3/libraries/ldpath/ldpath-functions-collections/src/test/java/org/apache/marmotta/ldpath/model/functions/coll/CollectionsTest.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-functions-collections/src/test/java/org/apache/marmotta/ldpath/model/functions/coll/CollectionsTest.java b/libraries/ldpath/ldpath-functions-collections/src/test/java/org/apache/marmotta/ldpath/model/functions/coll/CollectionsTest.java
new file mode 100644
index 0000000..a0124e7
--- /dev/null
+++ b/libraries/ldpath/ldpath-functions-collections/src/test/java/org/apache/marmotta/ldpath/model/functions/coll/CollectionsTest.java
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 2013 Salzburg Research.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.ldpath.model.functions.coll;
+
+
+import org.apache.marmotta.ldpath.test.AbstractTestBase;
+import org.hamcrest.CoreMatchers;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameter;
+import org.junit.runners.Parameterized.Parameters;
+import org.openrdf.model.URI;
+import org.openrdf.model.Value;
+import org.openrdf.repository.RepositoryException;
+import org.openrdf.rio.RDFFormat;
+import org.openrdf.rio.RDFParseException;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+@RunWith(Parameterized.class)
+public class CollectionsTest extends AbstractTestBase {
+
+ private static final int BAG_SIZE = 4;
+
+ @Parameters(name = "{0}")
+ public static List<String[]> data() {
+ return Arrays.asList(
+ new String[] { "ex:List" },
+ new String[] { "ex:Bag" },
+ new String[] { "ex:Seq" }
+ );
+ }
+
+ @Parameter
+ public String testContextUri;
+
+ private URI uri;
+
+ @Before
+ public void loadData() throws RepositoryException, RDFParseException, IOException {
+ super.loadData("data.n3", RDFFormat.N3);
+
+ uri = createURI(testContextUri);
+ }
+
+ @Test
+ public void testFlatten() throws Exception {
+ for (String ldPath : Arrays.asList("foo:hasItems / fn:flatten()", "fn:flatten(foo:hasItems)")) {
+ final Collection<Value> nodes = evaluateSelector(ldPath, uri);
+ Assert.assertEquals(ldPath, BAG_SIZE, nodes.size());
+ Assert.assertThat(ldPath, nodes,
+ CoreMatchers.<Value> hasItems(createURI("ex:1"), createURI("ex:2"), createURI("ex:3"), createURI("ex:4")));
+ }
+ }
+
+ @Test
+ public void testGet() throws Exception {
+ for (int i = 0; i < BAG_SIZE + 1; i++) {
+ for ( String pattern : Arrays.asList("foo:hasItems / fn:get(\"%d\")", "fn:get(foo:hasItems,\"%d\")")) {
+ final String ldPath = String.format(pattern, i);
+ final Collection<Value> nodes = evaluateSelector(ldPath, uri);
+ if (i < BAG_SIZE) {
+ Assert.assertEquals(ldPath, 1, nodes.size());
+ Assert.assertThat(ldPath, nodes,
+ CoreMatchers.<Value> hasItem(createURI("ex", String.valueOf(i + 1))));
+ } else {
+ Assert.assertEquals(ldPath, 0, nodes.size());
+ }
+
+ }
+ }
+ }
+
+ @Test
+ public void testSubList() throws Exception {
+ for (int i = 0; i <= BAG_SIZE + 1; i++) {
+ for (String pattern : Arrays.asList("foo:hasItems / fn:subList(", "fn:subList(foo:hasItems, ")) {
+ final String ldPath_1A = String.format("%s\"%d\")", pattern, i);
+ final Collection<Value> nodes_1A = evaluateSelector(ldPath_1A, uri);
+
+ final int expStart = Math.max(0, Math.min(i, BAG_SIZE));
+
+ Assert.assertEquals(ldPath_1A, Math.max(BAG_SIZE - expStart, 0), nodes_1A.size());
+ for (int e = expStart; e < BAG_SIZE; e++) {
+ Assert.assertThat(ldPath_1A, nodes_1A,
+ CoreMatchers.<Value> hasItem(createURI("ex", String.valueOf(e + 1))));
+ }
+ for (int j = i; j <= BAG_SIZE + 1; j++) {
+ final String ldPath_2A = String.format("%s\"%d\", \"%d\")", pattern, i, j);
+ final Collection<Value> nodes_2A = evaluateSelector(ldPath_2A, uri);
+
+ final int expEnd = Math.max(0, Math.min(j, BAG_SIZE));
+
+ Assert.assertEquals(ldPath_2A, expEnd - expStart, nodes_2A.size());
+ for (int e = expStart; e < expEnd; e++) {
+ Assert.assertThat(ldPath_2A, nodes_2A,
+ CoreMatchers.<Value> hasItem(createURI("ex", String.valueOf(e + 1))));
+ }
+ }
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5b8766b3/libraries/ldpath/ldpath-functions-collections/src/test/resources/coll/data.n3
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-functions-collections/src/test/resources/coll/data.n3 b/libraries/ldpath/ldpath-functions-collections/src/test/resources/coll/data.n3
deleted file mode 100644
index ce78900..0000000
--- a/libraries/ldpath/ldpath-functions-collections/src/test/resources/coll/data.n3
+++ /dev/null
@@ -1,29 +0,0 @@
-@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
-@prefix ex: <http://www.example.com/> .
-@prefix foo: <http://localhost/vcab#> .
-
-ex:Bag a foo:Test;
- foo:hasItems [
- a rdf:Bag;
- rdf:_1 ex:1;
- rdf:_2 ex:2;
- rdf:_3 ex:3;
- rdf:_4 ex:4
- ].
-
-ex:Seq a foo:Test;
- foo:hasItems [
- a rdf:Seq;
- rdf:_1 ex:1;
- rdf:_2 ex:2;
- rdf:_3 ex:3;
- rdf:_4 ex:4
- ].
-
-ex:List a foo:Test;
- foo:hasItems (
- ex:1
- ex:2
- ex:3
- ex:4
- ).
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5b8766b3/libraries/ldpath/ldpath-functions-collections/src/test/resources/org/apache/marmotta/ldpath/model/functions/coll/data.n3
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-functions-collections/src/test/resources/org/apache/marmotta/ldpath/model/functions/coll/data.n3 b/libraries/ldpath/ldpath-functions-collections/src/test/resources/org/apache/marmotta/ldpath/model/functions/coll/data.n3
new file mode 100644
index 0000000..ce78900
--- /dev/null
+++ b/libraries/ldpath/ldpath-functions-collections/src/test/resources/org/apache/marmotta/ldpath/model/functions/coll/data.n3
@@ -0,0 +1,29 @@
+@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+@prefix ex: <http://www.example.com/> .
+@prefix foo: <http://localhost/vcab#> .
+
+ex:Bag a foo:Test;
+ foo:hasItems [
+ a rdf:Bag;
+ rdf:_1 ex:1;
+ rdf:_2 ex:2;
+ rdf:_3 ex:3;
+ rdf:_4 ex:4
+ ].
+
+ex:Seq a foo:Test;
+ foo:hasItems [
+ a rdf:Seq;
+ rdf:_1 ex:1;
+ rdf:_2 ex:2;
+ rdf:_3 ex:3;
+ rdf:_4 ex:4
+ ].
+
+ex:List a foo:Test;
+ foo:hasItems (
+ ex:1
+ ex:2
+ ex:3
+ ex:4
+ ).
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5b8766b3/libraries/ldpath/ldpath-functions-date/pom.xml
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-functions-date/pom.xml b/libraries/ldpath/ldpath-functions-date/pom.xml
index a6ffa25..72cb108 100644
--- a/libraries/ldpath/ldpath-functions-date/pom.xml
+++ b/libraries/ldpath/ldpath-functions-date/pom.xml
@@ -78,7 +78,7 @@
<!-- Enable this for including your enhancement chain configuration -->
<!-- <Install-Path>config</Install-Path> -->
<Export-Package>
- at.newmedialab.ldpath.model.*;version=${project.version},
+ org.apache.marmotta.ldpath.model.*;version=${project.version},
</Export-Package>
<_include>src/main/resources/META-INF/MANIFEST.MF</_include>
</instructions>
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5b8766b3/libraries/ldpath/ldpath-functions-date/src/main/java/at/newmedialab/ldpath/model/functions/date/DateFunction.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-functions-date/src/main/java/at/newmedialab/ldpath/model/functions/date/DateFunction.java b/libraries/ldpath/ldpath-functions-date/src/main/java/at/newmedialab/ldpath/model/functions/date/DateFunction.java
deleted file mode 100644
index 68889d8..0000000
--- a/libraries/ldpath/ldpath-functions-date/src/main/java/at/newmedialab/ldpath/model/functions/date/DateFunction.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/**
- * Copyright (C) 2013 Salzburg Research.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package at.newmedialab.ldpath.model.functions.date;
-
-import at.newmedialab.ldpath.api.functions.SelectorFunction;
-
-public abstract class DateFunction<Node> extends SelectorFunction<Node> {
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5b8766b3/libraries/ldpath/ldpath-functions-date/src/main/java/at/newmedialab/ldpath/model/functions/date/EarliestDateFunction.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-functions-date/src/main/java/at/newmedialab/ldpath/model/functions/date/EarliestDateFunction.java b/libraries/ldpath/ldpath-functions-date/src/main/java/at/newmedialab/ldpath/model/functions/date/EarliestDateFunction.java
deleted file mode 100644
index c51d86d..0000000
--- a/libraries/ldpath/ldpath-functions-date/src/main/java/at/newmedialab/ldpath/model/functions/date/EarliestDateFunction.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/**
- * Copyright (C) 2013 Salzburg Research.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package at.newmedialab.ldpath.model.functions.date;
-
-import at.newmedialab.ldpath.api.backend.RDFBackend;
-import at.newmedialab.ldpath.model.transformers.DateTransformer;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-
-public class EarliestDateFunction<Node> extends DateFunction<Node> {
-
- private final DateTransformer<Node> transformer = new DateTransformer<Node>();
-
- @Override
- public Collection<Node> apply(RDFBackend<Node> backend, Node context,
- Collection<Node>... args) throws IllegalArgumentException {
- if (args.length != 1) {
- throw new IllegalArgumentException("earliest requires exactly one argument");
- }
-
- Node result = null;
- Date earliest = null;
-
- for (Node node : args[0]) {
- try {
- Date d = transformer.transform(backend, node);
- if (earliest == null || d.before(earliest)) {
- earliest = d;
- result = node;
- }
- } catch (IllegalArgumentException e) {
- // Non-Date Literals are just ignored
- }
- }
-
- return result!=null?Collections.singleton(result):Collections.<Node>emptyList();
- }
-
- @Override
- public String getSignature() {
- return "fn:earliest(DateLiteralList): DateLiteral";
- }
-
- @Override
- public String getDescription() {
- return "select the earliest date (min)";
- }
-
- @Override
- public String getLocalName() {
- return "earliest";
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5b8766b3/libraries/ldpath/ldpath-functions-date/src/main/java/at/newmedialab/ldpath/model/functions/date/LatestDateFunction.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-functions-date/src/main/java/at/newmedialab/ldpath/model/functions/date/LatestDateFunction.java b/libraries/ldpath/ldpath-functions-date/src/main/java/at/newmedialab/ldpath/model/functions/date/LatestDateFunction.java
deleted file mode 100644
index 2b269cb..0000000
--- a/libraries/ldpath/ldpath-functions-date/src/main/java/at/newmedialab/ldpath/model/functions/date/LatestDateFunction.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/**
- * Copyright (C) 2013 Salzburg Research.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package at.newmedialab.ldpath.model.functions.date;
-
-import at.newmedialab.ldpath.api.backend.RDFBackend;
-import at.newmedialab.ldpath.model.transformers.DateTransformer;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-
-public class LatestDateFunction<Node> extends DateFunction<Node> {
-
- private final DateTransformer<Node> transformer = new DateTransformer<Node>();
-
- @Override
- public Collection<Node> apply(RDFBackend<Node> backend, Node context,
- Collection<Node>... args) throws IllegalArgumentException {
- if (args.length != 1) {
- throw new IllegalArgumentException("latest requires exactly one argument");
- }
-
- Node result = null;
- Date latest = null;
-
- for (Node node : args[0]) {
- try {
- Date d = transformer.transform(backend, node);
- if (latest == null || d.after(latest)) {
- latest = d;
- result = node;
- }
- } catch (IllegalArgumentException e) {
- // Non-Date Literals are just ignored
- }
- }
-
- return result!=null?Collections.singleton(result):Collections.<Node>emptyList();
- }
-
- @Override
- public String getSignature() {
- return "fn:latest(DateLiteralList): DateLiteral";
- }
-
- @Override
- public String getDescription() {
- return "select the latest date (max)";
- }
-
- @Override
- public String getLocalName() {
- return "latest";
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5b8766b3/libraries/ldpath/ldpath-functions-date/src/main/java/org/apache/marmotta/ldpath/model/functions/date/DateFunction.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-functions-date/src/main/java/org/apache/marmotta/ldpath/model/functions/date/DateFunction.java b/libraries/ldpath/ldpath-functions-date/src/main/java/org/apache/marmotta/ldpath/model/functions/date/DateFunction.java
new file mode 100644
index 0000000..b50d280
--- /dev/null
+++ b/libraries/ldpath/ldpath-functions-date/src/main/java/org/apache/marmotta/ldpath/model/functions/date/DateFunction.java
@@ -0,0 +1,22 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.marmotta.ldpath.model.functions.date;
+
+import org.apache.marmotta.ldpath.api.functions.SelectorFunction;
+
+public abstract class DateFunction<Node> extends SelectorFunction<Node> {
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5b8766b3/libraries/ldpath/ldpath-functions-date/src/main/java/org/apache/marmotta/ldpath/model/functions/date/EarliestDateFunction.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-functions-date/src/main/java/org/apache/marmotta/ldpath/model/functions/date/EarliestDateFunction.java b/libraries/ldpath/ldpath-functions-date/src/main/java/org/apache/marmotta/ldpath/model/functions/date/EarliestDateFunction.java
new file mode 100644
index 0000000..c85af04
--- /dev/null
+++ b/libraries/ldpath/ldpath-functions-date/src/main/java/org/apache/marmotta/ldpath/model/functions/date/EarliestDateFunction.java
@@ -0,0 +1,70 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.marmotta.ldpath.model.functions.date;
+
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+
+import org.apache.marmotta.ldpath.api.backend.RDFBackend;
+import org.apache.marmotta.ldpath.model.transformers.DateTransformer;
+
+public class EarliestDateFunction<Node> extends DateFunction<Node> {
+
+ private final DateTransformer<Node> transformer = new DateTransformer<Node>();
+
+ @Override
+ public Collection<Node> apply(RDFBackend<Node> backend, Node context,
+ Collection<Node>... args) throws IllegalArgumentException {
+ if (args.length != 1) {
+ throw new IllegalArgumentException("earliest requires exactly one argument");
+ }
+
+ Node result = null;
+ Date earliest = null;
+
+ for (Node node : args[0]) {
+ try {
+ Date d = transformer.transform(backend, node);
+ if (earliest == null || d.before(earliest)) {
+ earliest = d;
+ result = node;
+ }
+ } catch (IllegalArgumentException e) {
+ // Non-Date Literals are just ignored
+ }
+ }
+
+ return result!=null?Collections.singleton(result):Collections.<Node>emptyList();
+ }
+
+ @Override
+ public String getSignature() {
+ return "fn:earliest(DateLiteralList): DateLiteral";
+ }
+
+ @Override
+ public String getDescription() {
+ return "select the earliest date (min)";
+ }
+
+ @Override
+ public String getLocalName() {
+ return "earliest";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5b8766b3/libraries/ldpath/ldpath-functions-date/src/main/java/org/apache/marmotta/ldpath/model/functions/date/LatestDateFunction.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-functions-date/src/main/java/org/apache/marmotta/ldpath/model/functions/date/LatestDateFunction.java b/libraries/ldpath/ldpath-functions-date/src/main/java/org/apache/marmotta/ldpath/model/functions/date/LatestDateFunction.java
new file mode 100644
index 0000000..0b3341b
--- /dev/null
+++ b/libraries/ldpath/ldpath-functions-date/src/main/java/org/apache/marmotta/ldpath/model/functions/date/LatestDateFunction.java
@@ -0,0 +1,70 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.marmotta.ldpath.model.functions.date;
+
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+
+import org.apache.marmotta.ldpath.api.backend.RDFBackend;
+import org.apache.marmotta.ldpath.model.transformers.DateTransformer;
+
+public class LatestDateFunction<Node> extends DateFunction<Node> {
+
+ private final DateTransformer<Node> transformer = new DateTransformer<Node>();
+
+ @Override
+ public Collection<Node> apply(RDFBackend<Node> backend, Node context,
+ Collection<Node>... args) throws IllegalArgumentException {
+ if (args.length != 1) {
+ throw new IllegalArgumentException("latest requires exactly one argument");
+ }
+
+ Node result = null;
+ Date latest = null;
+
+ for (Node node : args[0]) {
+ try {
+ Date d = transformer.transform(backend, node);
+ if (latest == null || d.after(latest)) {
+ latest = d;
+ result = node;
+ }
+ } catch (IllegalArgumentException e) {
+ // Non-Date Literals are just ignored
+ }
+ }
+
+ return result!=null?Collections.singleton(result):Collections.<Node>emptyList();
+ }
+
+ @Override
+ public String getSignature() {
+ return "fn:latest(DateLiteralList): DateLiteral";
+ }
+
+ @Override
+ public String getDescription() {
+ return "select the latest date (max)";
+ }
+
+ @Override
+ public String getLocalName() {
+ return "latest";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5b8766b3/libraries/ldpath/ldpath-functions-date/src/main/resources/META-INF/services/at.newmedialab.ldpath.api.functions.SelectorFunction
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-functions-date/src/main/resources/META-INF/services/at.newmedialab.ldpath.api.functions.SelectorFunction b/libraries/ldpath/ldpath-functions-date/src/main/resources/META-INF/services/at.newmedialab.ldpath.api.functions.SelectorFunction
deleted file mode 100644
index 2874864..0000000
--- a/libraries/ldpath/ldpath-functions-date/src/main/resources/META-INF/services/at.newmedialab.ldpath.api.functions.SelectorFunction
+++ /dev/null
@@ -1,2 +0,0 @@
-at.newmedialab.ldpath.model.functions.date.EarliestDateFunction
-at.newmedialab.ldpath.model.functions.date.LatestDateFunction
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5b8766b3/libraries/ldpath/ldpath-functions-date/src/main/resources/META-INF/services/org.apache.marmotta.ldpath.api.functions.SelectorFunction
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-functions-date/src/main/resources/META-INF/services/org.apache.marmotta.ldpath.api.functions.SelectorFunction b/libraries/ldpath/ldpath-functions-date/src/main/resources/META-INF/services/org.apache.marmotta.ldpath.api.functions.SelectorFunction
new file mode 100644
index 0000000..4b41481
--- /dev/null
+++ b/libraries/ldpath/ldpath-functions-date/src/main/resources/META-INF/services/org.apache.marmotta.ldpath.api.functions.SelectorFunction
@@ -0,0 +1,2 @@
+org.apache.marmotta.ldpath.model.functions.date.EarliestDateFunction
+org.apache.marmotta.ldpath.model.functions.date.LatestDateFunction
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5b8766b3/libraries/ldpath/ldpath-functions-date/src/test/java/date/DateFunctionsTest.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-functions-date/src/test/java/date/DateFunctionsTest.java b/libraries/ldpath/ldpath-functions-date/src/test/java/date/DateFunctionsTest.java
deleted file mode 100644
index 9eba72f..0000000
--- a/libraries/ldpath/ldpath-functions-date/src/test/java/date/DateFunctionsTest.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright (c) 2013 Salzburg Research.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package date;
-
-import at.newmedialab.ldpath.model.fields.FieldMapping;
-import at.newmedialab.ldpath.parser.ParseException;
-import at.newmedialab.ldpath.parser.RdfPathParser;
-import at.newmedialab.sesame.commons.util.DateUtils;
-import core.AbstractTestBase;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.openrdf.model.URI;
-import org.openrdf.model.Value;
-import org.openrdf.model.ValueFactory;
-import org.openrdf.repository.RepositoryException;
-import org.openrdf.repository.sail.SailRepositoryConnection;
-import org.openrdf.rio.RDFParseException;
-
-import java.io.IOException;
-import java.util.Collection;
-import java.util.Date;
-import java.util.Random;
-
-public class DateFunctionsTest extends AbstractTestBase {
-
- private Date now;
- private Date first;
- private URI uri;
- private URI prop;
-
- @Before
- public void loadData() throws RepositoryException, RDFParseException, IOException {
- final int delta = 60 * 60 * 24 * 365;
- now = new Date();
- first = new Date(now.getTime() - 1000l * delta);
-
- uri = repository.getValueFactory().createURI(NSS.get("ex") + now.getTime());
- prop = repository.getValueFactory().createURI(NSS.get("foo") + "hasPiH"); // Point in History
-
- final SailRepositoryConnection con = repository.getConnection();
-
- try {
- final ValueFactory vF = con.getValueFactory();
-
- con.add(vF.createStatement(uri, prop, vF.createLiteral(DateUtils.getXMLCalendar(first))));
- con.add(vF.createStatement(uri, prop, vF.createLiteral(DateUtils.getXMLCalendar(now))));
-
- final Random rnd = new Random();
- for (int i = 0; i < 20; i++) {
- Date d = new Date(first.getTime() + rnd.nextInt(delta) * 1000l);
- con.add(vF.createStatement(uri, prop, vF.createLiteral(DateUtils.getXMLCalendar(d))));
- }
-
- con.commit();
- } finally {
- con.close();
- }
- }
-
- @Test
- public void testEarliest() throws ParseException {
- final RdfPathParser<Value> parser = createParserFromString("fn:earliest(<" + prop.stringValue() + ">) :: xsd:dateTime");
- final FieldMapping<Object, Value> rule = parser.parseRule(NSS);
- final Collection<Object> result = rule.getValues(backend, uri);
-
- Assert.assertEquals(1, result.size());
-
- final Object obj = result.iterator().next();
- Assert.assertEquals(first, obj);
- }
-
- @Test
- public void testLatest() throws ParseException {
- final RdfPathParser<Value> parser = createParserFromString("fn:latest(<" + prop.stringValue() + ">) :: xsd:dateTime");
- final FieldMapping<Object, Value> rule = parser.parseRule(NSS);
- final Collection<Object> result = rule.getValues(backend, uri);
-
- Assert.assertEquals(1, result.size());
-
- final Object obj = result.iterator().next();
- Assert.assertEquals(now, obj);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5b8766b3/libraries/ldpath/ldpath-functions-date/src/test/java/org/apache/marmotta/ldpath/model/functions/date/DateFunctionsTest.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-functions-date/src/test/java/org/apache/marmotta/ldpath/model/functions/date/DateFunctionsTest.java b/libraries/ldpath/ldpath-functions-date/src/test/java/org/apache/marmotta/ldpath/model/functions/date/DateFunctionsTest.java
new file mode 100644
index 0000000..67cbef8
--- /dev/null
+++ b/libraries/ldpath/ldpath-functions-date/src/test/java/org/apache/marmotta/ldpath/model/functions/date/DateFunctionsTest.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2013 Salzburg Research.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.ldpath.model.functions.date;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Random;
+
+import org.apache.marmotta.ldpath.model.fields.FieldMapping;
+import org.apache.marmotta.ldpath.parser.ParseException;
+import org.apache.marmotta.ldpath.parser.RdfPathParser;
+import org.apache.marmotta.ldpath.test.AbstractTestBase;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.openrdf.model.URI;
+import org.openrdf.model.Value;
+import org.openrdf.model.ValueFactory;
+import org.openrdf.repository.RepositoryException;
+import org.openrdf.repository.sail.SailRepositoryConnection;
+import org.openrdf.rio.RDFParseException;
+
+import at.newmedialab.sesame.commons.util.DateUtils;
+
+public class DateFunctionsTest extends AbstractTestBase {
+
+ private Date now;
+ private Date first;
+ private URI uri;
+ private URI prop;
+
+ @Before
+ public void loadData() throws RepositoryException, RDFParseException, IOException {
+ final int delta = 60 * 60 * 24 * 365;
+ now = new Date();
+ first = new Date(now.getTime() - 1000l * delta);
+
+ uri = repository.getValueFactory().createURI(NSS.get("ex") + now.getTime());
+ prop = repository.getValueFactory().createURI(NSS.get("foo") + "hasPiH"); // Point in History
+
+ final SailRepositoryConnection con = repository.getConnection();
+
+ try {
+ final ValueFactory vF = con.getValueFactory();
+
+ con.add(vF.createStatement(uri, prop, vF.createLiteral(DateUtils.getXMLCalendar(first))));
+ con.add(vF.createStatement(uri, prop, vF.createLiteral(DateUtils.getXMLCalendar(now))));
+
+ final Random rnd = new Random();
+ for (int i = 0; i < 20; i++) {
+ Date d = new Date(first.getTime() + rnd.nextInt(delta) * 1000l);
+ con.add(vF.createStatement(uri, prop, vF.createLiteral(DateUtils.getXMLCalendar(d))));
+ }
+
+ con.commit();
+ } finally {
+ con.close();
+ }
+ }
+
+ @Test
+ public void testEarliest() throws ParseException {
+ final RdfPathParser<Value> parser = createParserFromString("fn:earliest(<" + prop.stringValue() + ">) :: xsd:dateTime");
+ final FieldMapping<Object, Value> rule = parser.parseRule(NSS);
+ final Collection<Object> result = rule.getValues(backend, uri);
+
+ Assert.assertEquals(1, result.size());
+
+ final Object obj = result.iterator().next();
+ Assert.assertEquals(first, obj);
+ }
+
+ @Test
+ public void testLatest() throws ParseException {
+ final RdfPathParser<Value> parser = createParserFromString("fn:latest(<" + prop.stringValue() + ">) :: xsd:dateTime");
+ final FieldMapping<Object, Value> rule = parser.parseRule(NSS);
+ final Collection<Object> result = rule.getValues(backend, uri);
+
+ Assert.assertEquals(1, result.size());
+
+ final Object obj = result.iterator().next();
+ Assert.assertEquals(now, obj);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5b8766b3/libraries/ldpath/ldpath-functions-html/pom.xml
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-functions-html/pom.xml b/libraries/ldpath/ldpath-functions-html/pom.xml
index e9e0b7f..d0d721b 100644
--- a/libraries/ldpath/ldpath-functions-html/pom.xml
+++ b/libraries/ldpath/ldpath-functions-html/pom.xml
@@ -93,7 +93,7 @@
<!-- Enable this for including your enhancement chain configuration -->
<!-- <Install-Path>config</Install-Path> -->
<Export-Package>
- at.newmedialab.ldpath.model.*;version=${project.version},
+ org.apache.marmotta.ldpath.model.*;version=${project.version},
</Export-Package>
<Import-Package>
!nu.xom.*,!org.dom4j.*,!org.dom4j.io.*,*
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5b8766b3/libraries/ldpath/ldpath-functions-html/src/main/java/at/newmedialab/ldpath/model/functions/CleanHtmlFunction.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-functions-html/src/main/java/at/newmedialab/ldpath/model/functions/CleanHtmlFunction.java b/libraries/ldpath/ldpath-functions-html/src/main/java/at/newmedialab/ldpath/model/functions/CleanHtmlFunction.java
deleted file mode 100644
index cdf8bd5..0000000
--- a/libraries/ldpath/ldpath-functions-html/src/main/java/at/newmedialab/ldpath/model/functions/CleanHtmlFunction.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/**
- * Copyright (C) 2013 Salzburg Research.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package at.newmedialab.ldpath.model.functions;
-
-import at.newmedialab.ldpath.api.backend.RDFBackend;
-import at.newmedialab.ldpath.api.functions.SelectorFunction;
-import at.newmedialab.ldpath.model.transformers.StringTransformer;
-import at.newmedialab.ldpath.util.Collections;
-import org.jsoup.Jsoup;
-import org.jsoup.safety.Whitelist;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * Function to clean up HTML and remove all script and style elements from the content.
- * <p/>
- * Author: Sebastian Schaffert
- */
-public class CleanHtmlFunction<Node> extends SelectorFunction<Node> {
-
- private final StringTransformer<Node> transformer = new StringTransformer<Node>();
-
- private Logger log = LoggerFactory.getLogger(CleanHtmlFunction.class);
-
- public CleanHtmlFunction() {
- }
-
- /**
- * Apply the function to the list of nodes passed as arguments and return the result as type T.
- * Throws IllegalArgumentException if the function cannot be applied to the nodes passed as argument
- * or the number of arguments is not correct.
- *
- * @param args a list of KiWiNodes
- * @return
- */
- @Override
- public Collection<Node> apply(RDFBackend<Node> backend, Node context, Collection<Node>... args) throws IllegalArgumentException {
- Iterator<Node> it;
- if(args.length < 1){
- log.debug("clean HTML from context {}",context);
- it = java.util.Collections.singleton(context).iterator();
- } else {
- log.debug("clean HTML from parameters");
- it = Collections.iterator(args);
- }
- List<Node> result = new ArrayList<Node>();
- while(it.hasNext()) {
- Node node = it.next();
- String cleaned = Jsoup.clean(transformer.transform(backend, node), Whitelist.basic());
- result.add(backend.createLiteral(cleaned));
- }
- return result;
- }
-
- /**
- * Return the name of the NodeFunction for registration in the function registry
- *
- * @return
- * @param backend
- */
- @Override
- public String getLocalName() {
- return "cleanHtml";
- }
-
- /**
- * A string describing the signature of this node function, e.g. "fn:content(uris : Nodes) : Nodes". The
- * syntax for representing the signature can be chosen by the implementer. This method is for informational
- * purposes only.
- *
- * @return
- */
- @Override
- public String getSignature() {
- return "fn:cleanHtml(content: LiteralList) : LiteralList";
- }
-
- /**
- * A short human-readable description of what the node function does.
- *
- * @return
- */
- @Override
- public String getDescription() {
- return "Function to clean up HTML and remove all script and style elements from the content. Can be used in-path, using the current context nodes as argument.";
- }
-}