You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@jena.apache.org by GitBox <gi...@apache.org> on 2020/12/01 19:15:04 UTC

[GitHub] [jena] afs opened a new pull request #880: JENA-2006: DatasetGraph prefixes

afs opened a new pull request #880:
URL: https://github.com/apache/jena/pull/880


   Lots of repercussions and lots of checking and tidying while looking at the code areas affected.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org


[GitHub] [jena] afs commented on pull request #880: JENA-2006: DatasetGraph prefixes

Posted by GitBox <gi...@apache.org>.
afs commented on pull request #880:
URL: https://github.com/apache/jena/pull/880#issuecomment-738701352


   Thank you for the reviews. I've fixed the javadoc comments and squashed it down locally to a single commit which, if nothing else, aids reversing this should any problems arise. 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org


[GitHub] [jena] kinow commented on a change in pull request #880: JENA-2006: DatasetGraph prefixes

Posted by GitBox <gi...@apache.org>.
kinow commented on a change in pull request #880:
URL: https://github.com/apache/jena/pull/880#discussion_r535545010



##########
File path: jena-arq/src/main/java/org/apache/jena/riot/system/PrefixLib.java
##########
@@ -80,35 +72,52 @@ public static String abbreviate(PrefixMapI pmap, String uriStr) {
      * Abbreviate a uriStr, return the prefix and local parts.
      * This does not guarantee that the result is suitable for all RDF syntaxes.
      */
-    public static Pair<String, String> abbrev(PrefixMapI prefixes, String uriStr) {
-        for ( PrefixEntry e : prefixes ) {
-            String uriForPrefix = e.getUri();
-            if ( uriStr.startsWith(uriForPrefix) )
-                return Pair.create(e.getPrefix(), uriStr.substring(uriForPrefix.length()));
+    public static Pair<String, String> abbrev(PrefixMap prefixes, String uriStr) {
+        return abbrev(prefixes.getMapping(), uriStr, true);
+    }
+
+    /**
+     * Abbreviate a uriStr, return the prefix and local parts, using a {@code Map} of
+     * prefix string to URI string. This does not guarantee that the result is
+     * suitable for all RDF syntaxes. In addition, perform a fast check for legal
+     * turtle local parts using {@link #isSafeLocalPart}. This covers the majority of
+     * real work cases and allows th code to find a probably-legal abbrev pair if an
+     * illegal one if found. (In practice, illegal local names arise only when one

Review comment:
       s/if/is

##########
File path: jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMap.java
##########
@@ -35,6 +36,24 @@
  * </p>
  */
 public interface PrefixMap {
+    /**
+     * Return the URI for the prefix, or null if there is no entry for this prefix.
+     */
+    public String get(String prefix);
+
+    // Is this a good idea? Leave out until it is justified.

Review comment:
       :+1: 

##########
File path: jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMapNull.java
##########
@@ -18,18 +18,20 @@
 
 package org.apache.jena.riot.system ;
 
+import static org.apache.jena.atlas.lib.Lib.unsupportedMethod;
+
 import java.util.Collections ;
 import java.util.Map ;
 import java.util.function.BiConsumer ;
+import java.util.stream.Stream;
 
 import org.apache.jena.atlas.lib.Pair ;
 import org.apache.jena.shared.PrefixMapping ;
 
-/** Always empty prefix map */
-public class PrefixMapNull implements PrefixMap {
-    public static PrefixMap empty = new PrefixMapNull() ;
+/** Baes of always empty prefix maps {@link PrefixMapSink} and {@link PrefixMapZero}. */

Review comment:
       Base?

##########
File path: jena-arq/src/main/java/org/apache/jena/riot/system/PrefixLib.java
##########
@@ -80,35 +72,52 @@ public static String abbreviate(PrefixMapI pmap, String uriStr) {
      * Abbreviate a uriStr, return the prefix and local parts.
      * This does not guarantee that the result is suitable for all RDF syntaxes.
      */
-    public static Pair<String, String> abbrev(PrefixMapI prefixes, String uriStr) {
-        for ( PrefixEntry e : prefixes ) {
-            String uriForPrefix = e.getUri();
-            if ( uriStr.startsWith(uriForPrefix) )
-                return Pair.create(e.getPrefix(), uriStr.substring(uriForPrefix.length()));
+    public static Pair<String, String> abbrev(PrefixMap prefixes, String uriStr) {
+        return abbrev(prefixes.getMapping(), uriStr, true);
+    }
+
+    /**
+     * Abbreviate a uriStr, return the prefix and local parts, using a {@code Map} of
+     * prefix string to URI string. This does not guarantee that the result is
+     * suitable for all RDF syntaxes. In addition, perform a fast check for legal
+     * turtle local parts using {@link #isSafeLocalPart}. This covers the majority of
+     * real work cases and allows th code to find a probably-legal abbrev pair if an

Review comment:
       s/th/the




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org


[GitHub] [jena] afs commented on pull request #880: JENA-2006: DatasetGraph prefixes

Posted by GitBox <gi...@apache.org>.
afs commented on pull request #880:
URL: https://github.com/apache/jena/pull/880#issuecomment-738826508


   The validation build has passed on my branch-build on travis-ci.org.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org


[GitHub] [jena] rvesse commented on a change in pull request #880: JENA-2006: DatasetGraph prefixes

Posted by GitBox <gi...@apache.org>.
rvesse commented on a change in pull request #880:
URL: https://github.com/apache/jena/pull/880#discussion_r533996839



##########
File path: jena-integration-tests/src/test/java/org/apache/jena/test/integration/TestDatasetPrefixes.java
##########
@@ -0,0 +1,236 @@
+/*
+ * 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.test.integration;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.apache.jena.atlas.lib.Creator;
+import org.apache.jena.query.TxnType;
+import org.apache.jena.riot.system.PrefixMap;
+import org.apache.jena.riot.system.Prefixes;
+import org.apache.jena.shared.JenaException;
+import org.apache.jena.sparql.JenaTransactionException;
+import org.apache.jena.sparql.core.DatasetGraph;
+import org.apache.jena.sparql.core.DatasetGraphFactory;
+import org.apache.jena.sparql.core.DatasetGraphMap;
+import org.apache.jena.sparql.core.DatasetGraphMapLink;
+import org.apache.jena.sparql.graph.GraphFactory;
+import org.apache.jena.system.Txn;
+import org.apache.jena.tdb.TDBFactory;
+import org.apache.jena.tdb.transaction.TDBTransactionException;
+import org.apache.jena.tdb2.DatabaseMgr;
+import org.junit.Assume;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.MethodSorters;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+// Tests go simple -> complex
+// Does not matter ass to their execution, it does help pinpoint what has broken.
+/**
+ * Test of dataset prefixes.
+ * See {@code AbstractTestPrefixMap} for tests of prefix maps in general.
+ */
+
+
+@FixMethodOrder(MethodSorters.JVM)
+@RunWith(Parameterized.class)
+public class TestDatasetPrefixes {
+
+    @Parameters(name = "{index}: {0}")
+    public static Collection<Object[]> data(){
+        Creator<DatasetGraph> c1 = ()->DatasetGraphFactory.createTxnMem();
+        Creator<DatasetGraph> c2 = ()->TDBFactory.createDatasetGraph();
+        Creator<DatasetGraph> c3 = ()->DatabaseMgr.createDatasetGraph();
+        Creator<DatasetGraph> c4 = ()->new DatasetGraphMap();     //DatasetGraphFactory.create();
+        Creator<DatasetGraph> c5 = ()->new DatasetGraphMapLink(GraphFactory.createDefaultGraph()); //DatasetGraphFactory.createGeneral();
+
+        Object[] x1 = { "TIM",  c1 , false, true, true };
+        Object[] x2 = { "TDB1", c2 , true, true, true };
+        Object[] x3 = { "TDB2", c3 , true, true, true };
+        Object[] x4 = { "Map",  c4 , false, false, false };
+        Object[] x5 = { "MapLink", c5 , false, false, false };
+        return Arrays.asList(x1, x2, x3, x4,x5);
+    }
+

Review comment:
       This is a really nice looking new test suite 👍 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org


[GitHub] [jena] afs commented on pull request #880: JENA-2006: DatasetGraph prefixes

Posted by GitBox <gi...@apache.org>.
afs commented on pull request #880:
URL: https://github.com/apache/jena/pull/880#issuecomment-738218203


   > Does this constitute a breaking change (either at the API level or behavioural)?
   
   No.
   
   `Dataset.getPrefixMapping()` has a default method.
   
   `DatasetGraph` does have a new interface method. We could add a default impl but at the moment, it signals "take note" to any downstream implementations I don't know about.
   
   There is no intention to break or change any behaviour where code has not been unwrapping classes and directly getting at the TDB1/TDB2 prefix storage. But that's cheating anyway :-).
   
   It is a big internal change. One reason for putting in right at the start of a version cycle is to give it maximum shakedown and to give downstream systems as much chance as possible to test. I know of very few cases of prefixes not being used as "parse in to set, write out to use".
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org


[GitHub] [jena] afs merged pull request #880: JENA-2006: DatasetGraph prefixes

Posted by GitBox <gi...@apache.org>.
afs merged pull request #880:
URL: https://github.com/apache/jena/pull/880


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org