Updated Branches: refs/heads/develop ad9841782 -> 5fe2a271d
LDPath-Parser now accepts @graph statement (begin of MARMOTTA-215) Project: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/commit/575c30cb Tree: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/tree/575c30cb Diff: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/diff/575c30cb Branch: refs/heads/develop Commit: 575c30cb0e2a160c09fdcb511b4f3e6a96c1a5ec Parents: ad98417 Author: Jakob Frank <[email protected]> Authored: Wed May 8 10:07:38 2013 +0200 Committer: Jakob Frank <[email protected]> Committed: Wed May 8 10:07:38 2013 +0200 ---------------------------------------------------------------------- .../marmotta/ldpath/model/programs/Program.java | 20 +++++++++++++++ .../javacc/at/newmedialab/ldpath/parser/rdfpath.jj | 18 +++++++++++++ .../src/test/resources/parse/program.ldpath | 2 + 3 files changed, 40 insertions(+), 0 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/575c30cb/libraries/ldpath/ldpath-core/src/main/java/org/apache/marmotta/ldpath/model/programs/Program.java ---------------------------------------------------------------------- diff --git a/libraries/ldpath/ldpath-core/src/main/java/org/apache/marmotta/ldpath/model/programs/Program.java b/libraries/ldpath/ldpath-core/src/main/java/org/apache/marmotta/ldpath/model/programs/Program.java index b09d9e9..43930eb 100644 --- a/libraries/ldpath/ldpath-core/src/main/java/org/apache/marmotta/ldpath/model/programs/Program.java +++ b/libraries/ldpath/ldpath-core/src/main/java/org/apache/marmotta/ldpath/model/programs/Program.java @@ -58,6 +58,11 @@ public class Program<Node> implements LDPathConstruct<Node> { * A map mapping from namespace prefix to namespace URI */ private Map<String, String> namespaces; + + /** + * Restrict evaluation of the program to the graphs/contexts + */ + private Set<Node> graphs; /** * An (optional) filter to use for checking which resources should be @@ -78,6 +83,7 @@ public class Program<Node> implements LDPathConstruct<Node> { public Program() { namespaces = new LinkedHashMap<String, String>(); fields = new LinkedHashSet<FieldMapping<?,Node>>(); + graphs = new HashSet<Node>(); } public void addNamespace(String prefix, String uri) { @@ -129,6 +135,20 @@ public class Program<Node> implements LDPathConstruct<Node> { this.namespaces = new LinkedHashMap<String, String>(namespaces); } + public Set<Node> getGraphs() { + return this.graphs; + } + + @SuppressWarnings("unchecked") + public Node[] getGraphArr() { + return (Node[]) this.graphs.toArray(new Object[this.graphs.size()]); + } + + public void setGraphs(Collection<Node> graphs) { + this.graphs.clear(); + this.graphs.addAll(graphs); + } + /** * Executes this Program on the parsed {@link RDFBackend backend}. * @param context The context of the execution http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/575c30cb/libraries/ldpath/ldpath-core/src/main/javacc/at/newmedialab/ldpath/parser/rdfpath.jj ---------------------------------------------------------------------- diff --git a/libraries/ldpath/ldpath-core/src/main/javacc/at/newmedialab/ldpath/parser/rdfpath.jj b/libraries/ldpath/ldpath-core/src/main/javacc/at/newmedialab/ldpath/parser/rdfpath.jj index bf2a24b..83dffae 100644 --- a/libraries/ldpath/ldpath-core/src/main/javacc/at/newmedialab/ldpath/parser/rdfpath.jj +++ b/libraries/ldpath/ldpath-core/src/main/javacc/at/newmedialab/ldpath/parser/rdfpath.jj @@ -47,6 +47,7 @@ import org.apache.marmotta.ldpath.model.transformers.*; import java.util.ArrayList; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -456,6 +457,7 @@ Program Program() : Map<String, String> nss = null; FieldMapping<?,Node> rule; NodeSelector<Node> boostSelector; + LinkedList<Node> graphs; } { ( @@ -468,6 +470,11 @@ Program Program() : )? ( + <K_GRAPH> graphs = UriList() <SCOLON> { + program.setGraphs(graphs); + } )? + + ( <K_FILTER> filter = NodeTest() <SCOLON> { program.setFilter(filter); } @@ -493,6 +500,17 @@ Program Program() : } } +LinkedList<Node> UriList() : { + LinkedList<Node> rest = null; + String uri; } +{ + uri = Uri() ( <COMMA> rest = UriList() )? { + if (rest == null) rest = new LinkedList<Node>(); + rest.addFirst(resolveResource(uri)); + return rest; + } +} + FieldMapping Rule() : { FieldMapping<?,Node> rule; http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/575c30cb/libraries/ldpath/ldpath-core/src/test/resources/parse/program.ldpath ---------------------------------------------------------------------- diff --git a/libraries/ldpath/ldpath-core/src/test/resources/parse/program.ldpath b/libraries/ldpath/ldpath-core/src/test/resources/parse/program.ldpath index 5af4a0e..cb75ce6 100644 --- a/libraries/ldpath/ldpath-core/src/test/resources/parse/program.ldpath +++ b/libraries/ldpath/ldpath-core/src/test/resources/parse/program.ldpath @@ -16,6 +16,8 @@ @prefix test: <http://example.com/>; @prefix foo: <http://foo.com/some/path#> ; +@graph test:context, foo:ctx, test:bar ; + @filter test:type is foo:bar | test:p1 & is-a test:Case ; @boost foo:boost / ^test:boost ;
