jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [1/6] jena git commit: General tidying up.
Date Tue, 20 Jun 2017 10:44:21 GMT
Repository: jena
Updated Branches:
  refs/heads/master 887def848 -> f89025a83


General tidying up.

Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/bb7af3b4
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/bb7af3b4
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/bb7af3b4

Branch: refs/heads/master
Commit: bb7af3b4d1a7a11c1b48a31917d17c96d1291109
Parents: fbd93e3
Author: Andy Seaborne <andy@apache.org>
Authored: Sat Jun 17 15:41:23 2017 +0100
Committer: Andy Seaborne <andy@apache.org>
Committed: Sat Jun 17 15:41:23 2017 +0100

----------------------------------------------------------------------
 .../org/apache/jena/riot/system/RiotLib.java    |  2 +-
 .../apache/jena/riot/writer/TurtleShell.java    |  2 +-
 .../apache/jena/sparql/util/graph/Findable.java | 19 +++++-
 .../sparql/util/graph/FindableCollection.java   | 68 ++++++++++++++++++++
 .../apache/jena/sparql/util/graph/GNode.java    |  8 ++-
 5 files changed, 94 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/bb7af3b4/jena-arq/src/main/java/org/apache/jena/riot/system/RiotLib.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/system/RiotLib.java b/jena-arq/src/main/java/org/apache/jena/riot/system/RiotLib.java
index e06300e..637a640 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/system/RiotLib.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/system/RiotLib.java
@@ -101,7 +101,7 @@ public class RiotLib
         return fixupPrefixIRI(prefix+":"+localPart);
     }
 
-    /** Convert an prefix name (qname) to an IRI, for when the prerix is nor defined.
+    /** Convert an prefix name (qname) to an IRI, for when the prefix is not defined.
      * @see ARQ#fixupUndefinedPrefixes
      */
     public static String fixupPrefixIRI(String prefixedName) {

http://git-wip-us.apache.org/repos/asf/jena/blob/bb7af3b4/jena-arq/src/main/java/org/apache/jena/riot/writer/TurtleShell.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/writer/TurtleShell.java b/jena-arq/src/main/java/org/apache/jena/riot/writer/TurtleShell.java
index a40cf6d..c820bb8 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/writer/TurtleShell.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/writer/TurtleShell.java
@@ -121,7 +121,7 @@ public abstract class TurtleShell {
         private final Set<Node>             freeBnodes ;  
 
         // The head node in each well-formed list -> list elements
-        private /*final*/ Map<Node, List<Node>> lists ;   
+        private final Map<Node, List<Node>> lists ;   
 
         // List that do not have any incoming triples
         private final Map<Node, List<Node>> freeLists ; 

http://git-wip-us.apache.org/repos/asf/jena/blob/bb7af3b4/jena-arq/src/main/java/org/apache/jena/sparql/util/graph/Findable.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/util/graph/Findable.java b/jena-arq/src/main/java/org/apache/jena/sparql/util/graph/Findable.java
index 95c9435..08275fa 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/util/graph/Findable.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/util/graph/Findable.java
@@ -20,11 +20,26 @@ package org.apache.jena.sparql.util.graph;
 
 import java.util.Iterator ;
 
+import org.apache.jena.atlas.iterator.Iter;
 import org.apache.jena.graph.Node ;
 import org.apache.jena.graph.Triple ;
 
+/** Minimal interface to find by pattern */
 public interface Findable
 {
-    public Iterator<Triple> find(Node s, Node p, Node o) ; 
-    public boolean  contains(Node s, Node p, Node o) ; 
+    /** Return an iterator over all triples matching the {@code (s,p,o)} pattern. 
+     * Each element of {@code (s,p,o)} can be concrete, or the wildcard {@code Node.ANY}.

+     */  
+    public Iterator<Triple> find(Node s, Node p, Node o) ;
+    
+    /** Return whether any triple matches the (s,p,o) pattern. 
+     * Each element of {@code (s,p,o)} can be concrete, or the wildcard {@code Node.ANY}.

+     */  
+    public boolean contains(Node s, Node p, Node o) ;
+    
+    /** Return the number of triples matching the (s,p,o) pattern. 
+     */  
+    public default int count(Node s, Node p, Node o) {
+        return (int)Iter.count(find(s,p,o));
+    }
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/bb7af3b4/jena-arq/src/main/java/org/apache/jena/sparql/util/graph/FindableCollection.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/util/graph/FindableCollection.java
b/jena-arq/src/main/java/org/apache/jena/sparql/util/graph/FindableCollection.java
new file mode 100644
index 0000000..2a85439
--- /dev/null
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/util/graph/FindableCollection.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.jena.sparql.util.graph;
+
+import java.util.*;
+
+import org.apache.jena.atlas.iterator.Iter;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.Triple ;
+
+public class FindableCollection implements Findable
+{
+    private Collection<Triple> triples ;
+
+    public FindableCollection(Collection<Triple> triples) { this.triples = triples
; }
+    
+    @Override
+    public Iterator<Triple> find(Node _s, Node _p, Node _o) {
+        Node s = m(_s) ;
+        Node p = m(_p) ;
+        Node o = m(_o) ;
+        return Iter.filter(triples.iterator(), (t)->matches(t, s, p, o)); 
+    }
+    
+    static Node m(Node n) {
+        return n == Node.ANY ? null : n ; 
+    }
+    
+    // Does concrete t match the pattern (s,p,o)?
+    /*package*/ static boolean matches(Triple t, Node s, Node p, Node o) {
+        if ( s != null && ! Objects.equals(s, t.getSubject()) )
+            return false ;
+        if ( p != null && ! Objects.equals(p, t.getPredicate()) )
+            return false ;
+        if ( o != null && ! Objects.equals(o, t.getObject()) )
+            return false ;
+        return true ;
+    }
+    
+    @Override
+    public boolean contains(Node s, Node p, Node o)
+    {
+        if ( s == Node.ANY ) s = null ;
+        if ( p == Node.ANY ) p = null ;
+        if ( o == Node.ANY ) o = null ;
+        for ( Triple t : triples ) {
+            if ( matches(t, s, p, o) )
+                return true;
+        }
+        return false ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/bb7af3b4/jena-arq/src/main/java/org/apache/jena/sparql/util/graph/GNode.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/util/graph/GNode.java b/jena-arq/src/main/java/org/apache/jena/sparql/util/graph/GNode.java
index d278d47..983f0cd 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/util/graph/GNode.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/util/graph/GNode.java
@@ -18,8 +18,11 @@
 
 package org.apache.jena.sparql.util.graph;
 
+import java.util.Collection;
+
 import org.apache.jena.graph.Graph ;
 import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.Triple;
 import org.apache.jena.sparql.core.BasicPattern ;
 
 
@@ -32,8 +35,11 @@ public class GNode
     { this.findable = new FindableGraph(graph) ; this.node = node ; }
     
     public GNode(BasicPattern triples, Node node)
-    { this.findable = new FindableBasicPattern(triples) ; this.node = node ; }
+    { this.findable = new FindableCollection(triples.getList()) ; this.node = node ; }
     
+    public GNode(Collection<Triple> triples, Node node)
+    { this.findable = new FindableCollection(triples) ; this.node = node ; }
+
     public GNode(GNode other, Node node)
     { this.findable = other.findable ; this.node = node ; }
 


Mime
View raw message