You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by ss...@apache.org on 2013/07/12 12:07:41 UTC
git commit: added a method to LDPathService that allows running a
program over all resources
Updated Branches:
refs/heads/develop 839c83096 -> 3160eac3f
added a method to LDPathService that allows running a program over all resources
Project: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/commit/3160eac3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/tree/3160eac3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/diff/3160eac3
Branch: refs/heads/develop
Commit: 3160eac3fa8954e0914d6d785f5c089f00174b44
Parents: 839c830
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Fri Jul 12 12:07:33 2013 +0200
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Fri Jul 12 12:07:33 2013 +0200
----------------------------------------------------------------------
.../platform/ldpath/api/LDPathService.java | 13 +++++
.../ldpath/services/LDPathServiceImpl.java | 52 ++++++++++++++++++--
2 files changed, 61 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/3160eac3/platform/marmotta-ldpath/src/main/java/org/apache/marmotta/platform/ldpath/api/LDPathService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-ldpath/src/main/java/org/apache/marmotta/platform/ldpath/api/LDPathService.java b/platform/marmotta-ldpath/src/main/java/org/apache/marmotta/platform/ldpath/api/LDPathService.java
index c258006..8851710 100644
--- a/platform/marmotta-ldpath/src/main/java/org/apache/marmotta/platform/ldpath/api/LDPathService.java
+++ b/platform/marmotta-ldpath/src/main/java/org/apache/marmotta/platform/ldpath/api/LDPathService.java
@@ -24,6 +24,7 @@ import org.apache.marmotta.ldpath.exception.LDPathParseException;
import org.openrdf.model.Value;
import java.util.Collection;
+import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -72,6 +73,18 @@ public interface LDPathService {
*/
public Map<String, Collection<?>> programQuery(Value context, String program) throws LDPathParseException;
+
+ /**
+ * Run a path program over all resources in the triplestore matching the program's filter and return the result for
+ * each respurce. Since this query can potentially return many results and take long, it is recommended to define
+ * appropriate program filters for the query.
+ *
+ * @param program
+ * @return
+ * @throws LDPathParseException
+ */
+ public Map<Value,Map<String,Collection<?>>> programQuery(String program) throws LDPathParseException;
+
/**
* Register a result transformer for a type URI. Use this method in your own projects
* to register custom result transformers.
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/3160eac3/platform/marmotta-ldpath/src/main/java/org/apache/marmotta/platform/ldpath/services/LDPathServiceImpl.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-ldpath/src/main/java/org/apache/marmotta/platform/ldpath/services/LDPathServiceImpl.java b/platform/marmotta-ldpath/src/main/java/org/apache/marmotta/platform/ldpath/services/LDPathServiceImpl.java
index 9e69587..12964db 100644
--- a/platform/marmotta-ldpath/src/main/java/org/apache/marmotta/platform/ldpath/services/LDPathServiceImpl.java
+++ b/platform/marmotta-ldpath/src/main/java/org/apache/marmotta/platform/ldpath/services/LDPathServiceImpl.java
@@ -17,6 +17,9 @@
*/
package org.apache.marmotta.platform.ldpath.services;
+import org.apache.marmotta.commons.sesame.repository.ResourceUtils;
+import org.apache.marmotta.ldpath.model.fields.FieldMapping;
+import org.apache.marmotta.ldpath.model.programs.Program;
import org.apache.marmotta.platform.ldpath.api.LDPathService;
import org.apache.marmotta.platform.ldpath.api.AutoRegisteredLDPathFunction;
import org.apache.marmotta.platform.core.api.triplestore.SesameService;
@@ -41,10 +44,7 @@ import javax.enterprise.inject.Instance;
import javax.inject.Inject;
import java.io.StringReader;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
/**
* Add file description here!
@@ -189,4 +189,48 @@ public class LDPathServiceImpl implements LDPathService {
throw new LDPathParseException("LDPath evaluation failed", e);
}
}
+
+ /**
+ * Run a path program over all resources in the triplestore matching the program's filter and return the result for
+ * each respurce. Since this query can potentially return many results and take long, it is recommended to define
+ * appropriate program filters for the query.
+ *
+ * @param program
+ * @return
+ * @throws org.apache.marmotta.ldpath.exception.LDPathParseException
+ *
+ */
+ @Override
+ public Map<Value, Map<String, Collection<?>>> programQuery(String program) throws LDPathParseException {
+ Map<Value, Map<String, Collection<?>>> result = new HashMap<>();
+ try {
+ RepositoryConnection conn = sesameService.getConnection();
+ try {
+ conn.begin();
+ SesameConnectionBackend backend = SesameConnectionBackend.withConnection(conn);
+ LDPath<Value> ldpath = new LDPath<Value>(backend, config);
+
+ Program<Value> p = ldpath.parseProgram(new StringReader(program));
+
+ // TODO: not very efficient, LDPath should support more efficient listing of resources based on filter
+ for(Value context : ResourceUtils.listResources(conn)) {
+ if(p.getFilter().apply(backend, context, Collections.singleton(context))) {
+
+ Map<String,Collection<?>> binding = new HashMap<String, Collection<?>>();
+
+ for(FieldMapping<?,Value> mapping : p.getFields()) {
+ binding.put(mapping.getFieldName(),mapping.getValues(backend,context));
+ }
+ result.put(context,binding);
+ }
+ }
+ } finally {
+ conn.commit();
+ conn.close();
+ }
+ } catch (RepositoryException e) {
+ throw new LDPathParseException("LDPath evaluation failed", e);
+ }
+ return result;
+ }
}