Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 27DDA200CC2 for ; Tue, 20 Jun 2017 12:44:26 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 26389160BE1; Tue, 20 Jun 2017 10:44:26 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 4E12F160BD3 for ; Tue, 20 Jun 2017 12:44:25 +0200 (CEST) Received: (qmail 34844 invoked by uid 500); 20 Jun 2017 10:44:24 -0000 Mailing-List: contact commits-help@jena.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jena.apache.org Delivered-To: mailing list commits@jena.apache.org Received: (qmail 34825 invoked by uid 99); 20 Jun 2017 10:44:24 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 20 Jun 2017 10:44:24 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 25564E0A38; Tue, 20 Jun 2017 10:44:21 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: andy@apache.org To: commits@jena.apache.org Date: Tue, 20 Jun 2017 10:44:21 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/6] jena git commit: General tidying up. archived-at: Tue, 20 Jun 2017 10:44:26 -0000 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 Authored: Sat Jun 17 15:41:23 2017 +0100 Committer: Andy Seaborne 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 freeBnodes ; // The head node in each well-formed list -> list elements - private /*final*/ Map> lists ; + private final Map> lists ; // List that do not have any incoming triples private final Map> 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 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 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 triples ; + + public FindableCollection(Collection triples) { this.triples = triples ; } + + @Override + public Iterator 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 triples, Node node) + { this.findable = new FindableCollection(triples) ; this.node = node ; } + public GNode(GNode other, Node node) { this.findable = other.findable ; this.node = node ; }