You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2017/08/24 21:31:27 UTC

[1/8] jena git commit: Typo in comment.

Repository: jena
Updated Branches:
  refs/heads/master 116ffb87c -> 98f711b70


Typo in comment.

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

Branch: refs/heads/master
Commit: 19bbb543a23945ba29035ea76da2d74e58b8df70
Parents: 0f9abc6
Author: Andy Seaborne <an...@apache.org>
Authored: Sat Aug 19 14:56:21 2017 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Sat Aug 19 14:56:21 2017 +0100

----------------------------------------------------------------------
 jena-arq/src/main/java/org/apache/jena/sparql/core/GraphView.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/19bbb543/jena-arq/src/main/java/org/apache/jena/sparql/core/GraphView.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/core/GraphView.java b/jena-arq/src/main/java/org/apache/jena/sparql/core/GraphView.java
index 4c639d0..41a9195 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/core/GraphView.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/GraphView.java
@@ -130,7 +130,7 @@ public class GraphView extends GraphBase implements Sync
         Node g = graphNode(gn) ;
         // Implementations may wish to do better so this is separated out.
         // For example, Iter.distinctAdjacent is a lot cheaper than Iter.distinct
-        // but assumes thing come back in a particular order
+        // but assumes things come back in a particular order
         Iterator<Quad> iterQuads = getDataset().find(g, s, p, o) ;
         Iterator<Triple> iter = GLib.quads2triples(iterQuads) ;
         // Suppress duplicates after projecting to triples.


[3/8] jena git commit: Debug the generated Lucene query string.

Posted by an...@apache.org.
Debug the generated Lucene query string.

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

Branch: refs/heads/master
Commit: 986e2edd6b08d75eef750e288ea7563a19f3c4e1
Parents: d0909c0
Author: Andy Seaborne <an...@apache.org>
Authored: Sat Aug 19 14:57:56 2017 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Sat Aug 19 14:57:56 2017 +0100

----------------------------------------------------------------------
 .../src/main/java/org/apache/jena/query/text/TextIndexLucene.java | 3 +++
 1 file changed, 3 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/986e2edd/jena-text/src/main/java/org/apache/jena/query/text/TextIndexLucene.java
----------------------------------------------------------------------
diff --git a/jena-text/src/main/java/org/apache/jena/query/text/TextIndexLucene.java b/jena-text/src/main/java/org/apache/jena/query/text/TextIndexLucene.java
index 56b906c..54063d8 100644
--- a/jena-text/src/main/java/org/apache/jena/query/text/TextIndexLucene.java
+++ b/jena-text/src/main/java/org/apache/jena/query/text/TextIndexLucene.java
@@ -413,6 +413,9 @@ public class TextIndexLucene implements TextIndex {
         if (graphClause != null)
             queryString = "(" + queryString + ") AND " + graphClause ;
 
+        if ( log.isDebugEnabled())
+            log.debug("Lucene query: {} ({})", queryString,limit) ;
+
         IndexSearcher indexSearcher = new IndexSearcher(indexReader) ;
         Query query = parseQuery(queryString, queryAnalyzer) ;
         if ( limit <= 0 )


[4/8] jena git commit: JENA-1381: Use graph and lang in the cache key.

Posted by an...@apache.org.
JENA-1381: Use graph and lang in the cache key.


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

Branch: refs/heads/master
Commit: ed48b26456f001591be80d565ecdaab23eedc3cf
Parents: 986e2ed
Author: Andy Seaborne <an...@apache.org>
Authored: Sat Aug 19 15:00:26 2017 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Sat Aug 19 15:00:26 2017 +0100

----------------------------------------------------------------------
 .../org/apache/jena/query/text/TextQueryPF.java | 61 ++++++++++++--------
 1 file changed, 38 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/ed48b264/jena-text/src/main/java/org/apache/jena/query/text/TextQueryPF.java
----------------------------------------------------------------------
diff --git a/jena-text/src/main/java/org/apache/jena/query/text/TextQueryPF.java b/jena-text/src/main/java/org/apache/jena/query/text/TextQueryPF.java
index 68026e3..a4279c5 100644
--- a/jena-text/src/main/java/org/apache/jena/query/text/TextQueryPF.java
+++ b/jena-text/src/main/java/org/apache/jena/query/text/TextQueryPF.java
@@ -240,6 +240,36 @@ public class TextQueryPF extends PropertyFunctionBase {
     }
 
     private ListMultimap<String,TextHit> query(Node property, String queryString, String lang, int limit, ExecutionContext execCxt) {
+        String graphURI = chooseGraphURI(execCxt);
+        
+        if ( graphURI == null ) {
+            Explain.explain(execCxt.getContext(), "Text query: "+queryString) ;
+            if ( log.isDebugEnabled())
+                log.debug("Text query: {} ({})", queryString,limit) ;
+        } else {
+            Explain.explain(execCxt.getContext(), "Text query <"+graphURI+">: "+queryString) ;
+            if ( log.isDebugEnabled())
+                log.debug("Text query: {} <{}> ({})", queryString, graphURI, limit) ;
+        }
+        
+        // Cache-key does not matter if lang or graphURI are null
+        String cacheKey = limit + " " + property + " " + queryString + " " + lang + " " + graphURI ;
+        @SuppressWarnings("unchecked")
+        Cache<String,ListMultimap<String,TextHit>> queryCache = 
+            (Cache<String,ListMultimap<String,TextHit>>) execCxt.getContext().get(cacheSymbol);
+        if (queryCache == null) {
+            /* doesn't yet exist, need to create it */
+            queryCache = CacheFactory.createCache(CACHE_SIZE);
+            execCxt.getContext().put(cacheSymbol, queryCache);
+        }
+
+        ListMultimap<String,TextHit> results = queryCache.getOrFill(cacheKey, ()->performQuery(property, queryString, graphURI, lang, limit));
+        // No cache.
+        //ListMultimap<String,TextHit> results = performQuery(property, queryString, graphURI, lang, limit);
+        return results;
+    }
+    
+    private String chooseGraphURI(ExecutionContext execCxt) {
         // use the graph information in the text index if possible
         String graph = null;
         if (textIndex.getDocDef().getGraphField() != null
@@ -252,30 +282,15 @@ public class TextQueryPF extends PropertyFunctionBase {
                     : Quad.defaultGraphNodeGenerated.getURI() ;
             }
         }
-
-        Explain.explain(execCxt.getContext(), "Text query: "+queryString) ;
-        if ( log.isDebugEnabled())
-            log.debug("Text query: {} ({})", queryString,limit) ;
-
-        String cacheKey = limit + " " + property + " " + queryString ;
-        @SuppressWarnings("unchecked")
-        Cache<String,ListMultimap<String,TextHit>> queryCache = 
-            (Cache<String,ListMultimap<String,TextHit>>) execCxt.getContext().get(cacheSymbol);
-        if (queryCache == null) { /* doesn't yet exist, need to create it */
-            queryCache = CacheFactory.createCache(CACHE_SIZE);
-            execCxt.getContext().put(cacheSymbol, queryCache);
+        return graph;
+    }
+    
+    private ListMultimap<String,TextHit> performQuery(Node property, String queryString, String graphURI, String lang, int limit) {
+        List<TextHit> resultList = textIndex.query(property, queryString, graphURI, lang, limit) ;
+        ListMultimap<String,TextHit> results = LinkedListMultimap.create();
+        for (TextHit result : resultList) {
+            results.put(TextQueryFuncs.subjectToString(result.getNode()), result);
         }
-
-        final String queryStr = queryString; // final needed for the lambda function
-        final String graphURI = graph; // final needed for the lambda function
-        ListMultimap<String,TextHit> results = queryCache.getOrFill(cacheKey, () -> {
-            List<TextHit> resultList = textIndex.query(property, queryStr, graphURI, lang, limit) ;
-            ListMultimap<String,TextHit> resultMultimap = LinkedListMultimap.create();
-            for (TextHit result : resultList) {
-                resultMultimap.put(TextQueryFuncs.subjectToString(result.getNode()), result);
-            }
-            return resultMultimap;
-        });
         return results;
     }
     


[8/8] jena git commit: JENA-1381: Merge commit 'refs/pull/274/head' of github.com:apache/jena

Posted by an...@apache.org.
JENA-1381: Merge commit 'refs/pull/274/head' of github.com:apache/jena

This closes #274.


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

Branch: refs/heads/master
Commit: 98f711b70d36b0be2e40076e50161547deed72bd
Parents: 116ffb8 4a3caf0
Author: Andy Seaborne <an...@apache.org>
Authored: Thu Aug 24 22:03:33 2017 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Thu Aug 24 22:03:33 2017 +0100

----------------------------------------------------------------------
 .../org/apache/jena/query/DatasetFactory.java   |  56 +++++----
 .../jena/sparql/core/DatasetGraphFactory.java   |  82 ++++++++-----
 .../jena/sparql/core/DatasetGraphMap.java       |  12 +-
 .../jena/sparql/core/DatasetGraphMapLink.java   |   9 +-
 .../org/apache/jena/sparql/core/GraphView.java  |   5 +-
 .../org/apache/jena/sparql/core/NamedGraph.java |  46 +++++++
 .../jena/sparql/core/NamedGraphWrapper.java     |  44 +++++++
 .../org/apache/jena/query/text/TextHit.java     |   5 +
 .../apache/jena/query/text/TextIndexLucene.java |   3 +
 .../org/apache/jena/query/text/TextQueryPF.java |  70 +++++++----
 .../org/apache/jena/query/text/TS_Text.java     |   1 +
 .../query/text/TestTextGraphIndexExtra.java     | 122 +++++++++++++++++++
 12 files changed, 361 insertions(+), 94 deletions(-)
----------------------------------------------------------------------



[5/8] jena git commit: JENA-1381: Interface NamedGraph

Posted by an...@apache.org.
JENA-1381: Interface NamedGraph


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

Branch: refs/heads/master
Commit: b358603f074d2991e734022abc97e94d83ea77cd
Parents: ed48b26
Author: Andy Seaborne <an...@apache.org>
Authored: Sat Aug 19 17:06:13 2017 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Sat Aug 19 17:44:29 2017 +0100

----------------------------------------------------------------------
 .../org/apache/jena/query/text/TextQueryPF.java | 21 ++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/b358603f/jena-text/src/main/java/org/apache/jena/query/text/TextQueryPF.java
----------------------------------------------------------------------
diff --git a/jena-text/src/main/java/org/apache/jena/query/text/TextQueryPF.java b/jena-text/src/main/java/org/apache/jena/query/text/TextQueryPF.java
index a4279c5..8a684c4 100644
--- a/jena-text/src/main/java/org/apache/jena/query/text/TextQueryPF.java
+++ b/jena-text/src/main/java/org/apache/jena/query/text/TextQueryPF.java
@@ -29,6 +29,7 @@ import org.apache.jena.atlas.lib.CacheFactory ;
 import org.apache.jena.atlas.logging.Log ;
 import org.apache.jena.datatypes.RDFDatatype ;
 import org.apache.jena.datatypes.xsd.XSDDatatype ;
+import org.apache.jena.graph.Graph ;
 import org.apache.jena.graph.Node ;
 import org.apache.jena.ext.com.google.common.collect.LinkedListMultimap;
 import org.apache.jena.ext.com.google.common.collect.ListMultimap;
@@ -271,18 +272,18 @@ public class TextQueryPF extends PropertyFunctionBase {
     
     private String chooseGraphURI(ExecutionContext execCxt) {
         // use the graph information in the text index if possible
-        String graph = null;
-        if (textIndex.getDocDef().getGraphField() != null
-            && execCxt.getActiveGraph() instanceof GraphView) {
-            GraphView activeGraph = (GraphView)execCxt.getActiveGraph() ;
-            if (!Quad.isUnionGraph(activeGraph.getGraphName())) {
-                graph =
-                    activeGraph.getGraphName() != null 
-                    ? TextQueryFuncs.graphNodeToString(activeGraph.getGraphName())
-                    : Quad.defaultGraphNodeGenerated.getURI() ;
+        String graphURI = null;
+        Graph activeGraph = execCxt.getActiveGraph();
+        
+        if (textIndex.getDocDef().getGraphField() != null && activeGraph instanceof NamedGraph) {
+            NamedGraph namedGraph = (NamedGraph)activeGraph ;
+            if (!Quad.isUnionGraph(namedGraph.getGraphName())) {
+                graphURI = namedGraph.getGraphName() != null 
+                        ? TextQueryFuncs.graphNodeToString(namedGraph.getGraphName())
+                        : Quad.defaultGraphNodeGenerated.getURI() ;
             }
         }
-        return graph;
+        return graphURI;
     }
     
     private ListMultimap<String,TextHit> performQuery(Node property, String queryString, String graphURI, String lang, int limit) {


[7/8] jena git commit: JENA-1381: Tests of various database types for text+graph indexing.

Posted by an...@apache.org.
JENA-1381: Tests of various database types for text+graph indexing.


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

Branch: refs/heads/master
Commit: 4a3caf0686c148d38cbc1b794de6b9f326079913
Parents: 03a1c35
Author: Andy Seaborne <an...@apache.org>
Authored: Sat Aug 19 21:01:47 2017 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Sat Aug 19 21:10:27 2017 +0100

----------------------------------------------------------------------
 .../org/apache/jena/query/text/TS_Text.java     |   1 +
 .../query/text/TestTextGraphIndexExtra.java     | 122 +++++++++++++++++++
 2 files changed, 123 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/4a3caf06/jena-text/src/test/java/org/apache/jena/query/text/TS_Text.java
----------------------------------------------------------------------
diff --git a/jena-text/src/test/java/org/apache/jena/query/text/TS_Text.java b/jena-text/src/test/java/org/apache/jena/query/text/TS_Text.java
index 91663f2..7a16cbe 100644
--- a/jena-text/src/test/java/org/apache/jena/query/text/TS_Text.java
+++ b/jena-text/src/test/java/org/apache/jena/query/text/TS_Text.java
@@ -49,6 +49,7 @@ import org.junit.runners.Suite.SuiteClasses;
     , TestDatasetWithAnalyzingQueryParser.class
     , TestDatasetWithComplexPhraseQueryParser.class
     , TestGenericAnalyzerAssembler.class
+    , TestTextGraphIndexExtra.class
 })
 
 public class TS_Text

http://git-wip-us.apache.org/repos/asf/jena/blob/4a3caf06/jena-text/src/test/java/org/apache/jena/query/text/TestTextGraphIndexExtra.java
----------------------------------------------------------------------
diff --git a/jena-text/src/test/java/org/apache/jena/query/text/TestTextGraphIndexExtra.java b/jena-text/src/test/java/org/apache/jena/query/text/TestTextGraphIndexExtra.java
new file mode 100644
index 0000000..2357c6b
--- /dev/null
+++ b/jena-text/src/test/java/org/apache/jena/query/text/TestTextGraphIndexExtra.java
@@ -0,0 +1,122 @@
+/*
+ * 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.query.text;
+
+import org.apache.jena.atlas.lib.StrUtils ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.query.* ;
+import org.apache.jena.query.text.EntityDefinition ;
+import org.apache.jena.query.text.TextDatasetFactory ;
+import org.apache.jena.query.text.TextIndex ;
+import org.apache.jena.query.text.TextIndexConfig ;
+import org.apache.jena.sparql.core.Quad ;
+import org.apache.jena.sparql.sse.SSE ;
+import org.apache.jena.system.Txn ;
+import org.apache.jena.tdb.TDBFactory ;
+import org.apache.jena.vocabulary.RDFS ;
+import org.apache.lucene.store.RAMDirectory ;
+import org.junit.Assert ;
+import org.junit.Test ;
+
+public class TestTextGraphIndexExtra {
+    // JENA-1372
+    // from https://lists.apache.org/thread.html/7c185d3666af3fbf1559b27129b32e2984582413f2331535ee653a83@%3Cusers.jena.apache.org%3E 
+    
+    static Node rdfsLabel     = RDFS.Nodes.label;
+
+    static Dataset textDataset(Dataset dataset) {
+        EntityDefinition entdef = new EntityDefinition("uri", "text", "graph", rdfsLabel);
+        TextIndex textIndex = TextDatasetFactory.createLuceneIndex(new RAMDirectory(), new TextIndexConfig(entdef));
+        return TextDatasetFactory.create(dataset, textIndex, true);
+    }
+    
+    static void populate(Dataset dataset) {
+        Txn.executeWrite(dataset, ()->{
+            Quad q1 = SSE.parseQuad("(<x:/graph1> <x:/thing1> rdfs:label 'test1')");
+            dataset.asDatasetGraph().add(q1);
+            Quad q2 = SSE.parseQuad("(<x:/graph1> <x:/thing2> rdfs:label 'abcd1')");
+            dataset.asDatasetGraph().add(q2);
+            
+            Quad q3 = SSE.parseQuad("(<x:/graph2> <x:/thing3> rdfs:label 'abcd2')");
+            dataset.asDatasetGraph().add(q3);
+        });
+    }
+
+    String textQuery  = StrUtils.strjoinNL
+        ("PREFIX text: <http://jena.apache.org/text#>"
+        ,"SELECT * WHERE {"
+        ,"  graph ?g {"
+        ,"    ?thing text:query 'test1' ."
+        // This would check in the graph the literal is present.
+        // Then test_mem_link_ds returns 1.
+        //,"    ?thing ?p 'test1' ."  
+        ,"  }"
+        ,"}"
+        );
+
+    String textQuery2  = StrUtils.strjoinNL
+        ("PREFIX text: <http://jena.apache.org/text#>"
+        ,"SELECT * WHERE {"
+        ,"  graph ?g {"
+        ,"    ?thing text:query 'test1' ."
+        // This checks in the graph that the literal is present.
+        ,"    ?thing ?p 'test1' ."  
+        ,"  }"
+        ,"}"
+        );
+
+    int sparqlQuery(Dataset dataset, String queryStr) {
+        return Txn.calculateRead(dataset, ()->{
+            QueryExecution qExec = QueryExecutionFactory.create(queryStr, dataset);
+            ResultSet rs = qExec.execSelect();
+            return ResultSetFormatter.consume(rs);
+        });
+    }
+    
+    @Test public void test_mem_copy_ds () {
+        test(DatasetFactory.create(), textQuery, 1);
+        test(DatasetFactory.create(), textQuery2, 1);
+    }
+    
+    @Test public void test_mem_link_ds () {
+        // The general dataset contains graphs as given by linking to the graph object.
+        // It does not provide their name in getGraph() and so the answer is 2 hits,
+        // one for each of <graph1> and <graph2> whereas it is 1 otherwise.
+        test(DatasetFactory.createGeneral(), textQuery, 2);
+        test(DatasetFactory.createGeneral(), textQuery2, 1);
+    }
+
+    @Test public void test_mem_txn_ds () {
+        test(DatasetFactory.createTxnMem(), textQuery, 1);
+        test(DatasetFactory.createTxnMem(), textQuery2, 1);
+    }
+
+    @Test public void test_tdb_ds () {
+        test(TDBFactory.createDataset(), textQuery, 1);
+        test(TDBFactory.createDataset(), textQuery2, 1);
+    }
+
+    private void test(Dataset ds, String queryStr, int expected) {
+        ds = textDataset(ds);
+        populate(ds);
+        int x = sparqlQuery(ds, queryStr);
+        Assert.assertEquals(expected, x);
+    }
+    
+}


[2/8] jena git commit: Add a toString() implementation.

Posted by an...@apache.org.
Add a toString() implementation.

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

Branch: refs/heads/master
Commit: d0909c00b8cc3af2d0b91fe6540e65892a84beb0
Parents: 19bbb54
Author: Andy Seaborne <an...@apache.org>
Authored: Sat Aug 19 14:56:53 2017 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Sat Aug 19 14:56:53 2017 +0100

----------------------------------------------------------------------
 jena-text/src/main/java/org/apache/jena/query/text/TextHit.java | 5 +++++
 1 file changed, 5 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/d0909c00/jena-text/src/main/java/org/apache/jena/query/text/TextHit.java
----------------------------------------------------------------------
diff --git a/jena-text/src/main/java/org/apache/jena/query/text/TextHit.java b/jena-text/src/main/java/org/apache/jena/query/text/TextHit.java
index 75ffce1..a59cf41 100644
--- a/jena-text/src/main/java/org/apache/jena/query/text/TextHit.java
+++ b/jena-text/src/main/java/org/apache/jena/query/text/TextHit.java
@@ -44,4 +44,9 @@ public class TextHit
     public Node getLiteral() {
         return this.literal;
     }
+    
+    @Override
+    public String toString() {
+        return "TextHit[node="+node+" literal="+literal+ " score="+score+"]";
+    }
 }


[6/8] jena git commit: JENA-1381: NamedGraph; use in DatasetGraphMap, GraphView.

Posted by an...@apache.org.
JENA-1381: NamedGraph; use in DatasetGraphMap, GraphView.

Adjust javadoc in DatasetFactory.


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

Branch: refs/heads/master
Commit: 03a1c35abd3c40c05e950c86608d2da668721034
Parents: b358603
Author: Andy Seaborne <an...@apache.org>
Authored: Sat Aug 19 17:56:54 2017 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Sat Aug 19 17:56:54 2017 +0100

----------------------------------------------------------------------
 .../org/apache/jena/query/DatasetFactory.java   | 56 +++++++------
 .../jena/sparql/core/DatasetGraphFactory.java   | 82 ++++++++++++--------
 .../jena/sparql/core/DatasetGraphMap.java       | 12 +--
 .../jena/sparql/core/DatasetGraphMapLink.java   |  9 ++-
 .../org/apache/jena/sparql/core/GraphView.java  |  3 +-
 .../org/apache/jena/sparql/core/NamedGraph.java | 46 +++++++++++
 .../jena/sparql/core/NamedGraphWrapper.java     | 44 +++++++++++
 7 files changed, 186 insertions(+), 66 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/03a1c35a/jena-arq/src/main/java/org/apache/jena/query/DatasetFactory.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/query/DatasetFactory.java b/jena-arq/src/main/java/org/apache/jena/query/DatasetFactory.java
index 84fb9dd..42f960b 100644
--- a/jena-arq/src/main/java/org/apache/jena/query/DatasetFactory.java
+++ b/jena-arq/src/main/java/org/apache/jena/query/DatasetFactory.java
@@ -39,35 +39,22 @@ import org.apache.jena.util.FileManager;
  */
 public class DatasetFactory {
 
-    /** Create an in-memory, non-transactional Dataset.
+    /** Create an in-memory {@link Dataset}.
      * <p>
      * See also {@link #createTxnMem()} for a transactional dataset.
      * <p>
      * This implementation copies models when {@link Dataset#addNamedModel(String, Model)} is called.
+     * <p>
+     * This implementation does not support serialized transactions (it only provides MRSW locking). 
+     * 
+     * @see #createTxnMem
      */
     public static Dataset create() {
         return wrap(DatasetGraphFactory.create()) ;
     }
     
-	/** Create an in-memory, non-transactional Dataset.
-	 * <p>
-	 * See also {@link #createTxnMem()} for a transactional dataset.
-	 * <p>
-	 * Use {@link #createGeneral()} when needing to add graphs with mixed charcateristics, 
-	 * e.g. inference graphs, specific graphs from TDB.
-	 * <p>    
-     * <em>This operation is marked "deprecated" because the general purpose "add named graph of any implementation"
-     * feature will be removed; this feature is now provided by {@link #createGeneral()}.
-     * </em>
-	 * @deprecated Prefer {@link #createGeneral()} or {@link #createTxnMem()} or {@link #create()}
-	 */
-	@Deprecated
-	public static Dataset createMem() {
-		return createGeneral() ;
-	}
-
 	/**
-     * Create an in-memory. transactional Dataset.
+     * Create an in-memory. transactional {@link Dataset}.
      * <p> 
      * This fully supports transactions, including abort to roll-back changes.
      * It provides "autocommit" if operations are performed
@@ -75,7 +62,7 @@ public class DatasetFactory {
      * (the implementation adds a begin/commit around each add or delete
      * so overheads can accumulate).
      * 
-     * @return a transactional, in-memory, modifiable Dataset which
+     * @return a transactional, in-memory, modifiable Dataset
      * 
      */
 	public static Dataset createTxnMem() {
@@ -83,21 +70,44 @@ public class DatasetFactory {
 	}
 
 	/**
-	 * Create a general-purpose Dataset.<br/>
+	 * Create a general-purpose  {@link Dataset}.<br/>
 	 * Any graphs needed are in-memory unless explciitly added with {@link Dataset#addNamedModel}.
 	 * </p>
-	 * This dataset can contain graphs from any source when added via {@link Dataset#addNamedModel}.
+	 * This dataset type can contain graphs from any source when added via {@link Dataset#addNamedModel}.
 	 * These are held as links to the supplied graph and not copied.
 	 * <p> 
-	 * This dataset does not support transactions. 
+	 * <em>This dataset does not support the graph indexing feature of jena-text.</em>
+     * <p>
+	 * This dataset does not support serialized transactions (it only provides MRSW locking). 
 	 * <p>
 	 * 
+	 * @see #createTxnMem
 	 * @return a general-purpose Dataset
 	 */
 	public static Dataset createGeneral() {
 		return wrap(DatasetGraphFactory.createGeneral()); 
 	}
 
+    /** Create an in-memory {@link Dataset}.
+     * <p>
+     * See also {@link #createTxnMem()} for a transactional dataset.
+     * <p>
+     * Use {@link #createGeneral()} when needing to add graphs with mixed characteristics, 
+     * e.g. inference graphs, or specific graphs from TDB.
+     * <p>    
+     * <em>It does not support the graph indexing feature of jena-text.</em>
+     * <p>
+     * <em>This factory operation is marked "deprecated" because the general purpose "add named graph of any implementation"
+     * feature will be removed; this feature is now provided by {@link #createGeneral()}.
+     * </em>
+     * @deprecated Prefer {@link #createTxnMem()} or {@link #create()} or, for special cases, {@link #createGeneral()}.
+     * @see #createTxnMem
+     */
+    @Deprecated
+    public static Dataset createMem() {
+        return createGeneral() ;
+    }
+
     /**
 	 * @param model The model for the default graph
 	 * @return a dataset with the given model as the default graph

http://git-wip-us.apache.org/repos/asf/jena/blob/03a1c35a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphFactory.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphFactory.java b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphFactory.java
index 321055e..68e680f 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphFactory.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphFactory.java
@@ -19,64 +19,78 @@
 package org.apache.jena.sparql.core;
 
 import java.util.Iterator ;
+import java.util.Objects ;
 
 import org.apache.jena.graph.Graph ;
 import org.apache.jena.graph.Node ;
 import org.apache.jena.query.Dataset ;
+import org.apache.jena.rdf.model.Model ;
 import org.apache.jena.sparql.core.mem.DatasetGraphInMemory;
 import org.apache.jena.sparql.graph.GraphFactory ;
 
 public class DatasetGraphFactory
 {
-    /** Create an in-memory {@link DatasetGraph}.
-     * This implementation copies the triples of an added graph into the dataset. 
+    /** Create an in-memory {@link Dataset}.
      * <p>
-     * See also {@link #createTxnMem()}
-     * <br/>
-     * See also {@link #createGeneral()}
+     * See also {@link #createTxnMem()} for a transactional dataset.
+     * <p>
+     * This implementation copies models when {@link Dataset#addNamedModel(String, Model)} is called.
+     * <p>
+     * This implementation does not support serialized transactions (it only provides MRSW locking). 
      * 
      * @see #createTxnMem
-     * @see #createGeneral
      */
-    
     public static DatasetGraph create() {
         return new DatasetGraphMap() ;
     }
 
     /**
-     * Create a general-purpose, non-transactional Dataset.<br/>
+     * Create an in-memory. transactional {@link Dataset}.
+     * <p> 
+     * This fully supports transactions, including abort to roll-back changes.
+     * It provides "autocommit" if operations are performed
+     * outside a transaction but with a performance impact
+     * (the implementation adds a begin/commit around each add or delete
+     * so overheads can accumulate).
      * 
-     * This dataset can contain graphs from any source when added via {@link Dataset#addNamedModel}.
-     * Any graphs needed are in-memory unless explicitly added with {@link DatasetGraph#addGraph}.
+     * @return a transactional, in-memory, modifiable Dataset
+     * 
+     */
+    public static DatasetGraph createTxnMem() { return new DatasetGraphInMemory(); }
+
+    /**
+     * Create a general-purpose  {@link Dataset}.<br/>
+     * Any graphs needed are in-memory unless explciitly added with {@link Dataset#addNamedModel}.
      * </p>
+     * This dataset type can contain graphs from any source when added via {@link Dataset#addNamedModel}.
      * These are held as links to the supplied graph and not copied.
      * <p> 
-     * This dataset does not support transactions. 
+     * <em>This dataset does not support the graph indexing feature of jena-text.</em>
+     * <p>
+     * This dataset does not support serialized transactions (it only provides MRSW locking). 
      * <p>
      * 
-     * @return a general-purpose DatasetGraph
+     * @see #createTxnMem
+     * @return a general-purpose Dataset
      */
     public static DatasetGraph createGeneral() { return new DatasetGraphMapLink(graphMakerMem) ; }
 
-    /**
-     * @return a DatasetGraph which features transactional in-memory operation
-     */
-    public static DatasetGraph createTxnMem() { return new DatasetGraphInMemory(); }
-
-    /** Create an in-memory, non-transactional DatasetGraph.
+    /** Create an in-memory {@link Dataset}.
      * <p>
      * See also {@link #createTxnMem()} for a transactional dataset.
      * <p>
      * Use {@link #createGeneral()} when needing to add graphs with mixed characteristics, 
-     * e.g. inference graphs, specific graphs from TDB.
+     * e.g. inference graphs, or specific graphs from TDB.
      * <p>    
-     * <em>This operation is marked "deprecated" because the general purpose 
-     * "add named graph of any implementation"
+     * <em>It does not support the graph indexing feature of jena-text.</em>
+     * <p>
+     * <em>This factory operation is marked "deprecated" because the general purpose "add named graph of any implementation"
      * feature will be removed; this feature is now provided by {@link #createGeneral()}.
      * </em>
-     * @deprecated Prefer {@link #createGeneral()} or {@link #createTxnMem()}
+     * @deprecated Prefer {@link #createTxnMem()} or {@link #create()} or, for special cases, {@link #createGeneral()}.
+     * @see #createTxnMem
      */
-    @Deprecated
+   @Deprecated
     public static DatasetGraph createMem() { return createGeneral() ; }
     
     /** Create a DatasetGraph based on an existing one;
@@ -89,9 +103,11 @@ public class DatasetGraphFactory
         return cloneStructure(dsg) ;
     }
     
-    /** Clone the structure of a DatasetGraph
+    /** 
+     * Clone the structure of a {@link DatasetGraph}.
      */
     public static DatasetGraph cloneStructure(DatasetGraph dsg) {
+        Objects.requireNonNull(dsg, "DatasetGraph must be provided") ;
         DatasetGraphMapLink dsg2 = new DatasetGraphMapLink(dsg.getDefaultGraph()) ;
         for ( Iterator<Node> names = dsg.listGraphNodes() ; names.hasNext() ; ) {
             Node gn = names.next() ;
@@ -126,15 +142,17 @@ public class DatasetGraphFactory
     /** Interface for making graphs when a dataset needs to add a new graph.
      *  Return null for no graph created.
      */
-    public interface GraphMaker { public Graph create() ; }
+    public interface GraphMaker { public Graph create(Node name) ; }
 
-    /** A graph maker that doesn't make graphs */
-    public static GraphMaker graphMakerNull = () -> null ;
+    /** A graph maker that doesn't make graphs. */
+    public static GraphMaker graphMakerNull = (name) -> null ;
 
-//    /** @deprecated Use graphMakerMem */
-//    @Deprecated 
-//    public static GraphMaker memGraphMaker = () -> GraphFactory.createDefaultGraph() ;
+    /** A graph maker that creates unnamed Jena default graphs */ 
+    /*package*/ static GraphMaker graphMakerMem = (name) -> GraphFactory.createDefaultGraph() ;
     
-    /** A graph maker that create Jena default graphs */ 
-    public static GraphMaker graphMakerMem = () -> GraphFactory.createDefaultGraph() ;
+    /** A graph maker that create {@link NamedGraph}s around a Jena default graphs */ 
+    public static GraphMaker graphMakerNamedGraphMem = (name) -> {
+        Graph g = GraphFactory.createDefaultGraph() ;
+        return new NamedGraphWrapper(name, g);
+    };
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/03a1c35a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphMap.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphMap.java b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphMap.java
index dc06ca7..24d3e04 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphMap.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphMap.java
@@ -52,17 +52,17 @@ public class DatasetGraphMap extends DatasetGraphTriplesQuads
     /**  DatasetGraphMap defaulting to storage in memory.
      */
     public DatasetGraphMap() {
-        this(DatasetGraphFactory.graphMakerMem) ; 
+        this(DatasetGraphFactory.graphMakerNamedGraphMem) ; 
     }
     
     /**  DatasetGraphMap with a specific policy for graph creation.
      *   This allows control over the storage. 
      */
     public DatasetGraphMap(GraphMaker graphMaker) {
-        this(graphMaker.create(), graphMaker) ;
+        this(graphMaker.create(null), graphMaker) ;
     }
     
-    public DatasetGraphMap(Graph defaultGraph, GraphMaker graphMaker) {
+    private DatasetGraphMap(Graph defaultGraph, GraphMaker graphMaker) {
         this.defaultGraph = defaultGraph ;
         this.graphMaker = graphMaker ;
     }
@@ -144,7 +144,7 @@ public class DatasetGraphMap extends DatasetGraphTriplesQuads
         // Not a special case.
         Graph g = graphs.get(graphNode);
         if ( g == null ) {
-            g = getGraphCreate();
+            g = getGraphCreate(graphNode);
             if ( g != null )
                 graphs.put(graphNode, g);
         }
@@ -155,8 +155,8 @@ public class DatasetGraphMap extends DatasetGraphTriplesQuads
      * Return null for "nothing created as a graph".
      * Sub classes can reimplement this.  
      */
-    protected Graph getGraphCreate() { 
-        Graph g = graphMaker.create() ;
+    protected Graph getGraphCreate(Node graphNode) { 
+        Graph g = graphMaker.create(graphNode) ;
         if ( g == null )
             throw new ARQException("Can't make new graphs") ;
         return g ;

http://git-wip-us.apache.org/repos/asf/jena/blob/03a1c35a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphMapLink.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphMapLink.java b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphMapLink.java
index 345efc0..c6d455b 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphMapLink.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphMapLink.java
@@ -106,7 +106,7 @@ public class DatasetGraphMapLink extends DatasetGraphCollection
      * DatasetFactory.createGeneral.
      */
     /*package*/ DatasetGraphMapLink(GraphMaker graphMaker) {
-        this(graphMaker.create(), graphMaker) ;
+        this(graphMaker.create(null), graphMaker) ;
     }
 
     /** A {@code DatasetGraph} that uses the given graph for the default graph
@@ -146,6 +146,7 @@ public class DatasetGraphMapLink extends DatasetGraphCollection
 
     @Override
     public Graph getGraph(Node graphNode) {
+        // Same as DatasetMap.getGraph but we inherit differently.
         if ( Quad.isUnionGraph(graphNode) ) 
             return new GraphUnionRead(this) ;
         if ( Quad.isDefaultGraph(graphNode))
@@ -153,7 +154,7 @@ public class DatasetGraphMapLink extends DatasetGraphCollection
         // Not a special case.
         Graph g = graphs.get(graphNode);
         if ( g == null ) {
-            g = getGraphCreate();
+            g = getGraphCreate(graphNode);
             if ( g != null )
                 graphs.put(graphNode, g);
         }
@@ -163,8 +164,8 @@ public class DatasetGraphMapLink extends DatasetGraphCollection
     /** Called from getGraph when a nonexistent graph is asked for.
      * Return null for "nothing created as a graph"
      */
-    protected Graph getGraphCreate() { 
-        return graphMaker.create() ;
+    protected Graph getGraphCreate(Node graphNode) { 
+        return graphMaker.create(graphNode) ;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/jena/blob/03a1c35a/jena-arq/src/main/java/org/apache/jena/sparql/core/GraphView.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/core/GraphView.java b/jena-arq/src/main/java/org/apache/jena/sparql/core/GraphView.java
index 41a9195..ab20c0c 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/core/GraphView.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/GraphView.java
@@ -44,7 +44,7 @@ import org.apache.jena.util.iterator.WrappedIterator ;
  *  @see GraphUnionRead
  */ 
 
-public class GraphView extends GraphBase implements Sync
+public class GraphView extends GraphBase implements NamedGraph, Sync
 {
     // Beware this implements union graph - implementations may wish
     // to do better so see protected method below.
@@ -80,6 +80,7 @@ public class GraphView extends GraphBase implements Sync
      * Return the graph name for this graph in the dataset it is a view of.
      * Returns {@code null} for the default graph.
      */
+    @Override
     public Node getGraphName() {
         return (gn == Quad.defaultGraphNodeGenerated) ? null : gn ;
     }

http://git-wip-us.apache.org/repos/asf/jena/blob/03a1c35a/jena-arq/src/main/java/org/apache/jena/sparql/core/NamedGraph.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/core/NamedGraph.java b/jena-arq/src/main/java/org/apache/jena/sparql/core/NamedGraph.java
new file mode 100644
index 0000000..77db174
--- /dev/null
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/NamedGraph.java
@@ -0,0 +1,46 @@
+/*
+ * 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.core;
+
+import org.apache.jena.graph.Graph ;
+import org.apache.jena.graph.Node ;
+
+/**
+ * A graph with an associated name.
+ * <p>
+ * Sometimes there is an associated name with a graph, where it lives on the web,
+ * or the name in a dataset.
+ * <p>
+ * This interface is for graph that have one associated name.
+ * What "associated" means is left open.  
+ * 
+ * @see GraphView
+ * @see NamedGraphWrapper
+ */
+
+public interface NamedGraph extends Graph {
+    /**
+     * Return the graph name for this graph.
+     * Blank nodes can be used.
+     * <p>
+     * A named graph of "null" is discouraged - use {@link Quad#defaultGraphIRI} 
+     * for a default graph in the context of use.
+     */
+    public Node getGraphName();
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/03a1c35a/jena-arq/src/main/java/org/apache/jena/sparql/core/NamedGraphWrapper.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/core/NamedGraphWrapper.java b/jena-arq/src/main/java/org/apache/jena/sparql/core/NamedGraphWrapper.java
new file mode 100644
index 0000000..7b826c6
--- /dev/null
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/NamedGraphWrapper.java
@@ -0,0 +1,44 @@
+/*
+ * 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.core;
+
+import org.apache.jena.graph.Graph ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.sparql.graph.GraphWrapper ;
+
+/**
+ * Add a name to a graph.
+ * 
+ * @see GraphView
+ */
+
+public class NamedGraphWrapper extends GraphWrapper implements NamedGraph {
+
+    private final Node graphName ;
+
+    public NamedGraphWrapper(Node graphName, Graph graph) {
+        super(graph) ;
+        this.graphName = graphName;
+    }
+
+    @Override
+    public Node getGraphName() {
+        return graphName ;
+    }
+}