[GitHub] jena issue #299: Turtle Star

2018-06-11 Thread hartig
Github user hartig commented on the issue:

https://github.com/apache/jena/pull/299
  
Agreed. 


---


[GitHub] jena pull request #431: JENA-1559: Alternative PrefixMapping implementation;...

2018-06-11 Thread rvesse
Github user rvesse commented on a diff in the pull request:

https://github.com/apache/jena/pull/431#discussion_r194338879
  
--- Diff: 
jena-arq/src/main/java/org/apache/jena/sparql/graph/PrefixMappingBase.java ---
@@ -0,0 +1,277 @@
+/*
+ * 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.graph;
+
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Optional;
+import java.util.StringJoiner;
+import java.util.function.BiConsumer;
+
+import org.apache.jena.ext.xerces.util.XMLChar;
+import org.apache.jena.shared.PrefixMapping;
+import org.apache.jena.util.SplitIRI;
+
+/**
+ * Framework for implementing {@link PrefixMapping}. It is stateless 
(unlike
+ * {@code PrefixMappingImpl}) and implements the contract of {@link 
PrefixMapping},
+ * providing the key algorithm and delegating storage to the subclasses.
+ * 
+ * Reverse mapping, looking up a URI to find a prefix is complex. There 
may be several
+ * possibilities. Applications should not reliy on every implementat being 
consistent,
+ * espeically when writing data when there has to be a choice on on prefix 
to use to
+ * shorten a URI.
+ * 
+ */
+public abstract class PrefixMappingBase implements PrefixMapping {
+/* Reverse mappings.
+ * The strict contract of PrefixMapping requires a separate 
reversemapping to be storoed and manipuated
+ * which in turn adds complexity to the storage implementations.
+ * However, applications removing prefixes is unusual so we end up 
with a lot of complexity with little value.
+ * 
+ * Beware of the details of removing a mapping when there is another 
to the same URI.
+ * If we had:
+ * 
+ *  Add (pref1, U)
+ *  Add (pref2, U)
+ * 
+ * so that {@code U} reverse maps ({@link #getNsURIPrefix}) to {@code 
pref2} (it was
+ * done second) then
+ * 
+ *  Remove (pref2)
+ * 
+ * it causes {@code U} to reverse map to {@code pref1}.
+ * 
+ * This feature is quite a burden on implementations and should be 
regarded as "legacy" -
+ * an implementation may not support this complex effect.
+ * 
+ * PrefixMappingMem does.
+ * Database backed ones typically don't.
+ */
+
+protected PrefixMappingBase() {}
+
+// The storage operations of an implementation.
+
+/** Add prefix */
+abstract protected void add(String prefix, String uri);
+
+/** Remove prefix. */
+abstract protected void remove(String prefix);
+
+/** Clear all mappings */
+abstract protected void clear();
+
+abstract protected boolean isEmpty();
+
+abstract protected int size();
+
+/** Return the URI that the prefix maps to. */ 
+abstract protected String prefixToUri(String prefix);
+
+/** Return a prefix that maps to the URI.
+ * There may be several; the answer is any one of them. 
+ */ 
+abstract protected String uriToPrefix(String uri);
+
+/** Return as a map. This map is only used within this class.
+ * It can be as efficient as possible.
+ * It will not be modifed.
+ * It wil not be retuned to a caller of {@code PrefixMappingBase}.
+ */
+abstract protected Map asMap();
+
+/** 
+ * Return as a map. The map return is not connected to the prefix 
mapping implementation,
+ * does not reflect subsequent prefix mapping changes.
+ */
+abstract protected Map asMapCopy();
+
+/** Apply the {@link BiConsumer} to each (prefix, uri) pair. */
+abstract protected void apply(BiConsumer action);
+
+/**
+ * This part of the subclass API and may be overriden if an 
implementation can do
+ * better This general implementation is based on asMap() which may be 
a copy or may
+ * be 

[GitHub] jena pull request #431: JENA-1559: Alternative PrefixMapping implementation;...

2018-06-11 Thread rvesse
Github user rvesse commented on a diff in the pull request:

https://github.com/apache/jena/pull/431#discussion_r194338271
  
--- Diff: 
jena-arq/src/main/java/org/apache/jena/sparql/graph/PrefixMappingBase.java ---
@@ -0,0 +1,277 @@
+/*
+ * 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.graph;
+
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Optional;
+import java.util.StringJoiner;
+import java.util.function.BiConsumer;
+
+import org.apache.jena.ext.xerces.util.XMLChar;
+import org.apache.jena.shared.PrefixMapping;
+import org.apache.jena.util.SplitIRI;
+
+/**
+ * Framework for implementing {@link PrefixMapping}. It is stateless 
(unlike
+ * {@code PrefixMappingImpl}) and implements the contract of {@link 
PrefixMapping},
+ * providing the key algorithm and delegating storage to the subclasses.
+ * 
+ * Reverse mapping, looking up a URI to find a prefix is complex. There 
may be several
+ * possibilities. Applications should not reliy on every implementat being 
consistent,
--- End diff --

Typos

- `implementat` this line
- `espeically` on the following line


---


[jira] [Commented] (JENA-1559) Avoid unnecessary prefix loading in GraphPrefixesProjection

2018-06-11 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/JENA-1559?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16507836#comment-16507836
 ] 

ASF GitHub Bot commented on JENA-1559:
--

Github user rvesse commented on a diff in the pull request:

https://github.com/apache/jena/pull/431#discussion_r194338271
  
--- Diff: 
jena-arq/src/main/java/org/apache/jena/sparql/graph/PrefixMappingBase.java ---
@@ -0,0 +1,277 @@
+/*
+ * 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.graph;
+
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Optional;
+import java.util.StringJoiner;
+import java.util.function.BiConsumer;
+
+import org.apache.jena.ext.xerces.util.XMLChar;
+import org.apache.jena.shared.PrefixMapping;
+import org.apache.jena.util.SplitIRI;
+
+/**
+ * Framework for implementing {@link PrefixMapping}. It is stateless 
(unlike
+ * {@code PrefixMappingImpl}) and implements the contract of {@link 
PrefixMapping},
+ * providing the key algorithm and delegating storage to the subclasses.
+ * 
+ * Reverse mapping, looking up a URI to find a prefix is complex. There 
may be several
+ * possibilities. Applications should not reliy on every implementat being 
consistent,
--- End diff --

Typos

- `implementat` this line
- `espeically` on the following line


> Avoid unnecessary prefix loading in GraphPrefixesProjection 
> 
>
> Key: JENA-1559
> URL: https://issues.apache.org/jira/browse/JENA-1559
> Project: Apache Jena
>  Issue Type: Task
>Affects Versions: Jena 3.7.0
>Reporter: Andy Seaborne
>Assignee: Andy Seaborne
>Priority: Major
>
> {{GraphPrefixesProjection}} loads all prefixes from the database (JENA-81). 
> It was done that way because {{PrefixMappingImpl}} has internal 
> datastructures that are not passing through lookup misses. 
> Load as needed and rework the way the prefix implementation to cleanly 
> separate algorithms from storage.
> Leave {{PrefixMappingImpl}} untouched - its name and details are too 
> well-known.
>  
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (JENA-1559) Avoid unnecessary prefix loading in GraphPrefixesProjection

2018-06-11 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/JENA-1559?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16507839#comment-16507839
 ] 

ASF GitHub Bot commented on JENA-1559:
--

Github user rvesse commented on a diff in the pull request:

https://github.com/apache/jena/pull/431#discussion_r194339397
  
--- Diff: 
jena-arq/src/main/java/org/apache/jena/sparql/graph/PrefixMappingOver.java ---
@@ -0,0 +1,97 @@
+/*
+ * 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.graph;
+
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Objects;
+import java.util.function.BiConsumer;
+
+import org.apache.jena.iri.IRI;
+import org.apache.jena.riot.system.PrefixMap;
+
+public class PrefixMappingOver extends PrefixMappingBase {
--- End diff --

Would `PrefixMappingDecorator` be a more descriptive name?


> Avoid unnecessary prefix loading in GraphPrefixesProjection 
> 
>
> Key: JENA-1559
> URL: https://issues.apache.org/jira/browse/JENA-1559
> Project: Apache Jena
>  Issue Type: Task
>Affects Versions: Jena 3.7.0
>Reporter: Andy Seaborne
>Assignee: Andy Seaborne
>Priority: Major
>
> {{GraphPrefixesProjection}} loads all prefixes from the database (JENA-81). 
> It was done that way because {{PrefixMappingImpl}} has internal 
> datastructures that are not passing through lookup misses. 
> Load as needed and rework the way the prefix implementation to cleanly 
> separate algorithms from storage.
> Leave {{PrefixMappingImpl}} untouched - its name and details are too 
> well-known.
>  
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (JENA-1559) Avoid unnecessary prefix loading in GraphPrefixesProjection

2018-06-11 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/JENA-1559?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16507837#comment-16507837
 ] 

ASF GitHub Bot commented on JENA-1559:
--

Github user rvesse commented on a diff in the pull request:

https://github.com/apache/jena/pull/431#discussion_r194338419
  
--- Diff: 
jena-arq/src/main/java/org/apache/jena/sparql/graph/PrefixMappingBase.java ---
@@ -0,0 +1,277 @@
+/*
+ * 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.graph;
+
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Optional;
+import java.util.StringJoiner;
+import java.util.function.BiConsumer;
+
+import org.apache.jena.ext.xerces.util.XMLChar;
+import org.apache.jena.shared.PrefixMapping;
+import org.apache.jena.util.SplitIRI;
+
+/**
+ * Framework for implementing {@link PrefixMapping}. It is stateless 
(unlike
+ * {@code PrefixMappingImpl}) and implements the contract of {@link 
PrefixMapping},
+ * providing the key algorithm and delegating storage to the subclasses.
+ * 
+ * Reverse mapping, looking up a URI to find a prefix is complex. There 
may be several
+ * possibilities. Applications should not reliy on every implementat being 
consistent,
+ * espeically when writing data when there has to be a choice on on prefix 
to use to
+ * shorten a URI.
+ * 
+ */
+public abstract class PrefixMappingBase implements PrefixMapping {
+/* Reverse mappings.
+ * The strict contract of PrefixMapping requires a separate 
reversemapping to be storoed and manipuated
--- End diff --

Typos:

- Missing space in `reverse mapping`
- `storoed`
- `manipuated`


> Avoid unnecessary prefix loading in GraphPrefixesProjection 
> 
>
> Key: JENA-1559
> URL: https://issues.apache.org/jira/browse/JENA-1559
> Project: Apache Jena
>  Issue Type: Task
>Affects Versions: Jena 3.7.0
>Reporter: Andy Seaborne
>Assignee: Andy Seaborne
>Priority: Major
>
> {{GraphPrefixesProjection}} loads all prefixes from the database (JENA-81). 
> It was done that way because {{PrefixMappingImpl}} has internal 
> datastructures that are not passing through lookup misses. 
> Load as needed and rework the way the prefix implementation to cleanly 
> separate algorithms from storage.
> Leave {{PrefixMappingImpl}} untouched - its name and details are too 
> well-known.
>  
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[GitHub] jena pull request #431: JENA-1559: Alternative PrefixMapping implementation;...

2018-06-11 Thread rvesse
Github user rvesse commented on a diff in the pull request:

https://github.com/apache/jena/pull/431#discussion_r194339397
  
--- Diff: 
jena-arq/src/main/java/org/apache/jena/sparql/graph/PrefixMappingOver.java ---
@@ -0,0 +1,97 @@
+/*
+ * 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.graph;
+
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Objects;
+import java.util.function.BiConsumer;
+
+import org.apache.jena.iri.IRI;
+import org.apache.jena.riot.system.PrefixMap;
+
+public class PrefixMappingOver extends PrefixMappingBase {
--- End diff --

Would `PrefixMappingDecorator` be a more descriptive name?


---


[jira] [Commented] (JENA-1559) Avoid unnecessary prefix loading in GraphPrefixesProjection

2018-06-11 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/JENA-1559?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16507838#comment-16507838
 ] 

ASF GitHub Bot commented on JENA-1559:
--

Github user rvesse commented on a diff in the pull request:

https://github.com/apache/jena/pull/431#discussion_r194338879
  
--- Diff: 
jena-arq/src/main/java/org/apache/jena/sparql/graph/PrefixMappingBase.java ---
@@ -0,0 +1,277 @@
+/*
+ * 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.graph;
+
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Optional;
+import java.util.StringJoiner;
+import java.util.function.BiConsumer;
+
+import org.apache.jena.ext.xerces.util.XMLChar;
+import org.apache.jena.shared.PrefixMapping;
+import org.apache.jena.util.SplitIRI;
+
+/**
+ * Framework for implementing {@link PrefixMapping}. It is stateless 
(unlike
+ * {@code PrefixMappingImpl}) and implements the contract of {@link 
PrefixMapping},
+ * providing the key algorithm and delegating storage to the subclasses.
+ * 
+ * Reverse mapping, looking up a URI to find a prefix is complex. There 
may be several
+ * possibilities. Applications should not reliy on every implementat being 
consistent,
+ * espeically when writing data when there has to be a choice on on prefix 
to use to
+ * shorten a URI.
+ * 
+ */
+public abstract class PrefixMappingBase implements PrefixMapping {
+/* Reverse mappings.
+ * The strict contract of PrefixMapping requires a separate 
reversemapping to be storoed and manipuated
+ * which in turn adds complexity to the storage implementations.
+ * However, applications removing prefixes is unusual so we end up 
with a lot of complexity with little value.
+ * 
+ * Beware of the details of removing a mapping when there is another 
to the same URI.
+ * If we had:
+ * 
+ *  Add (pref1, U)
+ *  Add (pref2, U)
+ * 
+ * so that {@code U} reverse maps ({@link #getNsURIPrefix}) to {@code 
pref2} (it was
+ * done second) then
+ * 
+ *  Remove (pref2)
+ * 
+ * it causes {@code U} to reverse map to {@code pref1}.
+ * 
+ * This feature is quite a burden on implementations and should be 
regarded as "legacy" -
+ * an implementation may not support this complex effect.
+ * 
+ * PrefixMappingMem does.
+ * Database backed ones typically don't.
+ */
+
+protected PrefixMappingBase() {}
+
+// The storage operations of an implementation.
+
+/** Add prefix */
+abstract protected void add(String prefix, String uri);
+
+/** Remove prefix. */
+abstract protected void remove(String prefix);
+
+/** Clear all mappings */
+abstract protected void clear();
+
+abstract protected boolean isEmpty();
+
+abstract protected int size();
+
+/** Return the URI that the prefix maps to. */ 
+abstract protected String prefixToUri(String prefix);
+
+/** Return a prefix that maps to the URI.
+ * There may be several; the answer is any one of them. 
+ */ 
+abstract protected String uriToPrefix(String uri);
+
+/** Return as a map. This map is only used within this class.
+ * It can be as efficient as possible.
+ * It will not be modifed.
+ * It wil not be retuned to a caller of {@code PrefixMappingBase}.
+ */
+abstract protected Map asMap();
+
+/** 
+ * Return as a map. The map return is not connected to the prefix 
mapping implementation,
+ * does not reflect subsequent prefix mapping changes.
+ */
+abstract protected Map asMapCopy();
+
+/** Apply the {@link BiConsumer} to each (prefix, uri) pair. */
+abstract protected vo

[GitHub] jena pull request #431: JENA-1559: Alternative PrefixMapping implementation;...

2018-06-11 Thread rvesse
Github user rvesse commented on a diff in the pull request:

https://github.com/apache/jena/pull/431#discussion_r194338419
  
--- Diff: 
jena-arq/src/main/java/org/apache/jena/sparql/graph/PrefixMappingBase.java ---
@@ -0,0 +1,277 @@
+/*
+ * 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.graph;
+
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Optional;
+import java.util.StringJoiner;
+import java.util.function.BiConsumer;
+
+import org.apache.jena.ext.xerces.util.XMLChar;
+import org.apache.jena.shared.PrefixMapping;
+import org.apache.jena.util.SplitIRI;
+
+/**
+ * Framework for implementing {@link PrefixMapping}. It is stateless 
(unlike
+ * {@code PrefixMappingImpl}) and implements the contract of {@link 
PrefixMapping},
+ * providing the key algorithm and delegating storage to the subclasses.
+ * 
+ * Reverse mapping, looking up a URI to find a prefix is complex. There 
may be several
+ * possibilities. Applications should not reliy on every implementat being 
consistent,
+ * espeically when writing data when there has to be a choice on on prefix 
to use to
+ * shorten a URI.
+ * 
+ */
+public abstract class PrefixMappingBase implements PrefixMapping {
+/* Reverse mappings.
+ * The strict contract of PrefixMapping requires a separate 
reversemapping to be storoed and manipuated
--- End diff --

Typos:

- Missing space in `reverse mapping`
- `storoed`
- `manipuated`


---


[GitHub] jena pull request #433: JENA-1561: Enable TDB2 in Fuseki UI and on the comma...

2018-06-11 Thread rvesse
Github user rvesse commented on a diff in the pull request:

https://github.com/apache/jena/pull/433#discussion_r194342614
  
--- Diff: 
jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/mgt/ActionDatasets.java
 ---
@@ -351,15 +356,13 @@ private static void assemblerFromForm(HttpAction 
action, StreamRDF dest) {
 FusekiSystem.addGlobals(params); 
 
 //action.log.info(format("[%d] Create database : name = %s, type = 
%s", action.id, dbName, dbType )) ;
-if ( ! dbType.equals(tDatabasetTDB) && ! 
dbType.equals(tDatabasetMem) )
-ServletOps.errorBadRequest(format("dbType can be only '%s' or 
'%s'", tDatabasetTDB, tDatabasetMem)) ;
 
-String template = null ;
-if ( dbType.equalsIgnoreCase(tDatabasetTDB))
-template = 
TemplateFunctions.templateFile(Template.templateTDBFN, params, Lang.TTL) ;
-if ( dbType.equalsIgnoreCase(tDatabasetMem))
-template = 
TemplateFunctions.templateFile(Template.templateMemFN, params, Lang.TTL) ;
-RDFParser.create().source(new 
StringReader(template)).base("http://base/";).lang(Lang.TTL).parse(dest);
+String template = 
dbTypeToTemplate.get(dbType.toLowerCase(Locale.ROOT));
+if ( template == null )
+ServletOps.errorBadRequest(format("dbType can be only '%s' 
or '%s'", tDatabaseTDB, tDatabaseMem)) ;
--- End diff --

This PR now allows three possibilities so the error message is now 
inaccurate


---


[jira] [Commented] (JENA-1561) Enable TDB2 in the Fuseki UI and on the Fuseki command line.

2018-06-11 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/JENA-1561?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16507847#comment-16507847
 ] 

ASF GitHub Bot commented on JENA-1561:
--

Github user rvesse commented on a diff in the pull request:

https://github.com/apache/jena/pull/433#discussion_r194342614
  
--- Diff: 
jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/mgt/ActionDatasets.java
 ---
@@ -351,15 +356,13 @@ private static void assemblerFromForm(HttpAction 
action, StreamRDF dest) {
 FusekiSystem.addGlobals(params); 
 
 //action.log.info(format("[%d] Create database : name = %s, type = 
%s", action.id, dbName, dbType )) ;
-if ( ! dbType.equals(tDatabasetTDB) && ! 
dbType.equals(tDatabasetMem) )
-ServletOps.errorBadRequest(format("dbType can be only '%s' or 
'%s'", tDatabasetTDB, tDatabasetMem)) ;
 
-String template = null ;
-if ( dbType.equalsIgnoreCase(tDatabasetTDB))
-template = 
TemplateFunctions.templateFile(Template.templateTDBFN, params, Lang.TTL) ;
-if ( dbType.equalsIgnoreCase(tDatabasetMem))
-template = 
TemplateFunctions.templateFile(Template.templateMemFN, params, Lang.TTL) ;
-RDFParser.create().source(new 
StringReader(template)).base("http://base/";).lang(Lang.TTL).parse(dest);
+String template = 
dbTypeToTemplate.get(dbType.toLowerCase(Locale.ROOT));
+if ( template == null )
+ServletOps.errorBadRequest(format("dbType can be only '%s' 
or '%s'", tDatabaseTDB, tDatabaseMem)) ;
--- End diff --

This PR now allows three possibilities so the error message is now 
inaccurate


> Enable TDB2 in the Fuseki UI and on the Fuseki command line.
> 
>
> Key: JENA-1561
> URL: https://issues.apache.org/jira/browse/JENA-1561
> Project: Apache Jena
>  Issue Type: New Feature
>  Components: Fuseki
>Affects Versions: Jena 3.7.0
>Reporter: Andy Seaborne
>Assignee: Andy Seaborne
>Priority: Major
> Fix For: Jena 3.8.0
>
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[GitHub] jena pull request #299: Turtle Star

2018-06-11 Thread asfgit
Github user asfgit closed the pull request at:

https://github.com/apache/jena/pull/299


---


[GitHub] jena pull request #431: JENA-1559: Alternative PrefixMapping implementation;...

2018-06-11 Thread ajs6f
Github user ajs6f commented on a diff in the pull request:

https://github.com/apache/jena/pull/431#discussion_r194364163
  
--- Diff: 
jena-arq/src/main/java/org/apache/jena/sparql/graph/PrefixMappingOver.java ---
@@ -0,0 +1,97 @@
+/*
+ * 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.graph;
+
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Objects;
+import java.util.function.BiConsumer;
+
+import org.apache.jena.iri.IRI;
+import org.apache.jena.riot.system.PrefixMap;
+
+public class PrefixMappingOver extends PrefixMappingBase {
--- End diff --

+1


---


[jira] [Commented] (JENA-1559) Avoid unnecessary prefix loading in GraphPrefixesProjection

2018-06-11 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/JENA-1559?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16507906#comment-16507906
 ] 

ASF GitHub Bot commented on JENA-1559:
--

Github user ajs6f commented on a diff in the pull request:

https://github.com/apache/jena/pull/431#discussion_r194364163
  
--- Diff: 
jena-arq/src/main/java/org/apache/jena/sparql/graph/PrefixMappingOver.java ---
@@ -0,0 +1,97 @@
+/*
+ * 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.graph;
+
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Objects;
+import java.util.function.BiConsumer;
+
+import org.apache.jena.iri.IRI;
+import org.apache.jena.riot.system.PrefixMap;
+
+public class PrefixMappingOver extends PrefixMappingBase {
--- End diff --

+1


> Avoid unnecessary prefix loading in GraphPrefixesProjection 
> 
>
> Key: JENA-1559
> URL: https://issues.apache.org/jira/browse/JENA-1559
> Project: Apache Jena
>  Issue Type: Task
>Affects Versions: Jena 3.7.0
>Reporter: Andy Seaborne
>Assignee: Andy Seaborne
>Priority: Major
>
> {{GraphPrefixesProjection}} loads all prefixes from the database (JENA-81). 
> It was done that way because {{PrefixMappingImpl}} has internal 
> datastructures that are not passing through lookup misses. 
> Load as needed and rework the way the prefix implementation to cleanly 
> separate algorithms from storage.
> Leave {{PrefixMappingImpl}} untouched - its name and details are too 
> well-known.
>  
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[GitHub] jena pull request #434: JENA-1562: Fix for Graph.size() for TDB2 graphs

2018-06-11 Thread afs
Github user afs commented on a diff in the pull request:

https://github.com/apache/jena/pull/434#discussion_r194395266
  
--- Diff: jena-arq/src/main/java/org/apache/jena/sparql/core/GraphView.java 
---
@@ -165,6 +165,9 @@ public void performDelete( Triple t ) {
 Node o = t.getObject() ;
 dsg.delete(g, s, p, o) ;
 }
+
+// Subclasses may wish to provide graphBaseSize otherwise GraphBase 
uses find()  
--- End diff --

Done.


---


[jira] [Commented] (JENA-1562) TDB2 Graph.size() is much slower than TDB1.

2018-06-11 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/JENA-1562?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16507993#comment-16507993
 ] 

ASF GitHub Bot commented on JENA-1562:
--

Github user afs commented on a diff in the pull request:

https://github.com/apache/jena/pull/434#discussion_r194395266
  
--- Diff: jena-arq/src/main/java/org/apache/jena/sparql/core/GraphView.java 
---
@@ -165,6 +165,9 @@ public void performDelete( Triple t ) {
 Node o = t.getObject() ;
 dsg.delete(g, s, p, o) ;
 }
+
+// Subclasses may wish to provide graphBaseSize otherwise GraphBase 
uses find()  
--- End diff --

Done.


> TDB2 Graph.size() is much slower than TDB1.
> ---
>
> Key: JENA-1562
> URL: https://issues.apache.org/jira/browse/JENA-1562
> Project: Apache Jena
>  Issue Type: Bug
>Affects Versions: Jena 3.7.0
>Reporter: Andy Seaborne
>Assignee: Andy Seaborne
>Priority: Major
> Fix For: Jena 3.8.0
>
>
> TDB2 {{Graph.size()}} is much slower than TDB1.
> TDB2 {{Graph.size()}} relies on {{GraphBase.size}}, which uses 
> {{graph.find(ANY,ANY,ANY)}} which creates nodes and triples unnecessarily for 
> the count.
> TDB1 has code to use the primary tupleindex size() operation and it 50x 
> faster on 5m triples in the default graph.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[GitHub] jena pull request #434: JENA-1562: Fix for Graph.size() for TDB2 graphs

2018-06-11 Thread afs
Github user afs commented on a diff in the pull request:

https://github.com/apache/jena/pull/434#discussion_r194396180
  
--- Diff: 
jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/store/GraphViewSwitchable.java
 ---
@@ -79,16 +83,34 @@ public TransactionHandler getTransactionHandler() {
 /** Return the {@code DatasetGraphSwitchable} we are viewing. */
 @Override
 public DatasetGraphSwitchable getDataset() {
-return getx() ;
+return getx();
 }
 
 /** Return the {@code Graph} from the underlying switchable.
  *  Do not hold onto this reference across switches. 
  */
 public Graph getGraph() {
-return getx().getGraph(getGraphName()) ;
+return getx().getGraph(getGraphName());
 }
 
+// Super uses find. Override to call GraphTDB.size()
+@Override
+protected int graphBaseSize() {
+if ( isDefaultGraph() )
+return getDSG().getDefaultGraphTDB().size();
+return getDSG().getGraphTDB(getGraphName()).size();
+}
+
+private DatasetGraphTDB getDSG() {
+return ((DatasetGraphTDB)(getx().get()));
+}
+
+private static Function, Tuple> 
project4TupleTo3Tuple = item -> {
--- End diff --

Don't understand.  It is used in the method above and pulled out for 
clarity. It makes the handling of union graph clearer IMO with a named function 
at that point, not inline code.


---


[jira] [Commented] (JENA-1562) TDB2 Graph.size() is much slower than TDB1.

2018-06-11 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/JENA-1562?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16508004#comment-16508004
 ] 

ASF GitHub Bot commented on JENA-1562:
--

Github user afs commented on a diff in the pull request:

https://github.com/apache/jena/pull/434#discussion_r194396180
  
--- Diff: 
jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/store/GraphViewSwitchable.java
 ---
@@ -79,16 +83,34 @@ public TransactionHandler getTransactionHandler() {
 /** Return the {@code DatasetGraphSwitchable} we are viewing. */
 @Override
 public DatasetGraphSwitchable getDataset() {
-return getx() ;
+return getx();
 }
 
 /** Return the {@code Graph} from the underlying switchable.
  *  Do not hold onto this reference across switches. 
  */
 public Graph getGraph() {
-return getx().getGraph(getGraphName()) ;
+return getx().getGraph(getGraphName());
 }
 
+// Super uses find. Override to call GraphTDB.size()
+@Override
+protected int graphBaseSize() {
+if ( isDefaultGraph() )
+return getDSG().getDefaultGraphTDB().size();
+return getDSG().getGraphTDB(getGraphName()).size();
+}
+
+private DatasetGraphTDB getDSG() {
+return ((DatasetGraphTDB)(getx().get()));
+}
+
+private static Function, Tuple> 
project4TupleTo3Tuple = item -> {
--- End diff --

Don't understand.  It is used in the method above and pulled out for 
clarity. It makes the handling of union graph clearer IMO with a named function 
at that point, not inline code.


> TDB2 Graph.size() is much slower than TDB1.
> ---
>
> Key: JENA-1562
> URL: https://issues.apache.org/jira/browse/JENA-1562
> Project: Apache Jena
>  Issue Type: Bug
>Affects Versions: Jena 3.7.0
>Reporter: Andy Seaborne
>Assignee: Andy Seaborne
>Priority: Major
> Fix For: Jena 3.8.0
>
>
> TDB2 {{Graph.size()}} is much slower than TDB1.
> TDB2 {{Graph.size()}} relies on {{GraphBase.size}}, which uses 
> {{graph.find(ANY,ANY,ANY)}} which creates nodes and triples unnecessarily for 
> the count.
> TDB1 has code to use the primary tupleindex size() operation and it 50x 
> faster on 5m triples in the default graph.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[GitHub] jena pull request #431: JENA-1559: Alternative PrefixMapping implementation;...

2018-06-11 Thread afs
Github user afs commented on a diff in the pull request:

https://github.com/apache/jena/pull/431#discussion_r194398068
  
--- Diff: 
jena-arq/src/main/java/org/apache/jena/sparql/graph/PrefixMappingOver.java ---
@@ -0,0 +1,97 @@
+/*
+ * 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.graph;
+
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Objects;
+import java.util.function.BiConsumer;
+
+import org.apache.jena.iri.IRI;
+import org.apache.jena.riot.system.PrefixMap;
+
+public class PrefixMappingOver extends PrefixMappingBase {
--- End diff --

Its real name is `PrefixMappingOverPrefixMap` ... seemed a bit long and 
confusing.

It does not seem to be a decorator.  Would "Adapter" be OK?



---


[jira] [Commented] (JENA-1559) Avoid unnecessary prefix loading in GraphPrefixesProjection

2018-06-11 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/JENA-1559?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16508013#comment-16508013
 ] 

ASF GitHub Bot commented on JENA-1559:
--

Github user afs commented on a diff in the pull request:

https://github.com/apache/jena/pull/431#discussion_r194398068
  
--- Diff: 
jena-arq/src/main/java/org/apache/jena/sparql/graph/PrefixMappingOver.java ---
@@ -0,0 +1,97 @@
+/*
+ * 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.graph;
+
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Objects;
+import java.util.function.BiConsumer;
+
+import org.apache.jena.iri.IRI;
+import org.apache.jena.riot.system.PrefixMap;
+
+public class PrefixMappingOver extends PrefixMappingBase {
--- End diff --

Its real name is `PrefixMappingOverPrefixMap` ... seemed a bit long and 
confusing.

It does not seem to be a decorator.  Would "Adapter" be OK?



> Avoid unnecessary prefix loading in GraphPrefixesProjection 
> 
>
> Key: JENA-1559
> URL: https://issues.apache.org/jira/browse/JENA-1559
> Project: Apache Jena
>  Issue Type: Task
>Affects Versions: Jena 3.7.0
>Reporter: Andy Seaborne
>Assignee: Andy Seaborne
>Priority: Major
>
> {{GraphPrefixesProjection}} loads all prefixes from the database (JENA-81). 
> It was done that way because {{PrefixMappingImpl}} has internal 
> datastructures that are not passing through lookup misses. 
> Load as needed and rework the way the prefix implementation to cleanly 
> separate algorithms from storage.
> Leave {{PrefixMappingImpl}} untouched - its name and details are too 
> well-known.
>  
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[GitHub] jena pull request #434: JENA-1562: Fix for Graph.size() for TDB2 graphs

2018-06-11 Thread ajs6f
Github user ajs6f commented on a diff in the pull request:

https://github.com/apache/jena/pull/434#discussion_r194398578
  
--- Diff: 
jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/store/GraphViewSwitchable.java
 ---
@@ -79,16 +83,34 @@ public TransactionHandler getTransactionHandler() {
 /** Return the {@code DatasetGraphSwitchable} we are viewing. */
 @Override
 public DatasetGraphSwitchable getDataset() {
-return getx() ;
+return getx();
 }
 
 /** Return the {@code Graph} from the underlying switchable.
  *  Do not hold onto this reference across switches. 
  */
 public Graph getGraph() {
-return getx().getGraph(getGraphName()) ;
+return getx().getGraph(getGraphName());
 }
 
+// Super uses find. Override to call GraphTDB.size()
+@Override
+protected int graphBaseSize() {
+if ( isDefaultGraph() )
+return getDSG().getDefaultGraphTDB().size();
+return getDSG().getGraphTDB(getGraphName()).size();
+}
+
+private DatasetGraphTDB getDSG() {
+return ((DatasetGraphTDB)(getx().get()));
+}
+
+private static Function, Tuple> 
project4TupleTo3Tuple = item -> {
--- End diff --

I'm totally confused. The method above reads:
```
private DatasetGraphTDB getDSG() {
return ((DatasetGraphTDB)(getx().get()));
}
```
Where is `project4TupleTo3Tuple` used there?


---


[GitHub] jena pull request #431: JENA-1559: Alternative PrefixMapping implementation;...

2018-06-11 Thread ajs6f
Github user ajs6f commented on a diff in the pull request:

https://github.com/apache/jena/pull/431#discussion_r194399107
  
--- Diff: 
jena-arq/src/main/java/org/apache/jena/sparql/graph/PrefixMappingOver.java ---
@@ -0,0 +1,97 @@
+/*
+ * 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.graph;
+
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Objects;
+import java.util.function.BiConsumer;
+
+import org.apache.jena.iri.IRI;
+import org.apache.jena.riot.system.PrefixMap;
+
+public class PrefixMappingOver extends PrefixMappingBase {
--- End diff --

Can't speak for @rvesse, but "Adaptor" is even better to my eye.


---


[jira] [Commented] (JENA-1562) TDB2 Graph.size() is much slower than TDB1.

2018-06-11 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/JENA-1562?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16508016#comment-16508016
 ] 

ASF GitHub Bot commented on JENA-1562:
--

Github user ajs6f commented on a diff in the pull request:

https://github.com/apache/jena/pull/434#discussion_r194398578
  
--- Diff: 
jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/store/GraphViewSwitchable.java
 ---
@@ -79,16 +83,34 @@ public TransactionHandler getTransactionHandler() {
 /** Return the {@code DatasetGraphSwitchable} we are viewing. */
 @Override
 public DatasetGraphSwitchable getDataset() {
-return getx() ;
+return getx();
 }
 
 /** Return the {@code Graph} from the underlying switchable.
  *  Do not hold onto this reference across switches. 
  */
 public Graph getGraph() {
-return getx().getGraph(getGraphName()) ;
+return getx().getGraph(getGraphName());
 }
 
+// Super uses find. Override to call GraphTDB.size()
+@Override
+protected int graphBaseSize() {
+if ( isDefaultGraph() )
+return getDSG().getDefaultGraphTDB().size();
+return getDSG().getGraphTDB(getGraphName()).size();
+}
+
+private DatasetGraphTDB getDSG() {
+return ((DatasetGraphTDB)(getx().get()));
+}
+
+private static Function, Tuple> 
project4TupleTo3Tuple = item -> {
--- End diff --

I'm totally confused. The method above reads:
```
private DatasetGraphTDB getDSG() {
return ((DatasetGraphTDB)(getx().get()));
}
```
Where is `project4TupleTo3Tuple` used there?


> TDB2 Graph.size() is much slower than TDB1.
> ---
>
> Key: JENA-1562
> URL: https://issues.apache.org/jira/browse/JENA-1562
> Project: Apache Jena
>  Issue Type: Bug
>Affects Versions: Jena 3.7.0
>Reporter: Andy Seaborne
>Assignee: Andy Seaborne
>Priority: Major
> Fix For: Jena 3.8.0
>
>
> TDB2 {{Graph.size()}} is much slower than TDB1.
> TDB2 {{Graph.size()}} relies on {{GraphBase.size}}, which uses 
> {{graph.find(ANY,ANY,ANY)}} which creates nodes and triples unnecessarily for 
> the count.
> TDB1 has code to use the primary tupleindex size() operation and it 50x 
> faster on 5m triples in the default graph.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (JENA-1559) Avoid unnecessary prefix loading in GraphPrefixesProjection

2018-06-11 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/JENA-1559?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16508025#comment-16508025
 ] 

ASF GitHub Bot commented on JENA-1559:
--

Github user ajs6f commented on a diff in the pull request:

https://github.com/apache/jena/pull/431#discussion_r194399107
  
--- Diff: 
jena-arq/src/main/java/org/apache/jena/sparql/graph/PrefixMappingOver.java ---
@@ -0,0 +1,97 @@
+/*
+ * 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.graph;
+
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Objects;
+import java.util.function.BiConsumer;
+
+import org.apache.jena.iri.IRI;
+import org.apache.jena.riot.system.PrefixMap;
+
+public class PrefixMappingOver extends PrefixMappingBase {
--- End diff --

Can't speak for @rvesse, but "Adaptor" is even better to my eye.


> Avoid unnecessary prefix loading in GraphPrefixesProjection 
> 
>
> Key: JENA-1559
> URL: https://issues.apache.org/jira/browse/JENA-1559
> Project: Apache Jena
>  Issue Type: Task
>Affects Versions: Jena 3.7.0
>Reporter: Andy Seaborne
>Assignee: Andy Seaborne
>Priority: Major
>
> {{GraphPrefixesProjection}} loads all prefixes from the database (JENA-81). 
> It was done that way because {{PrefixMappingImpl}} has internal 
> datastructures that are not passing through lookup misses. 
> Load as needed and rework the way the prefix implementation to cleanly 
> separate algorithms from storage.
> Leave {{PrefixMappingImpl}} untouched - its name and details are too 
> well-known.
>  
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[GitHub] jena pull request #433: JENA-1561: Enable TDB2 in Fuseki UI and on the comma...

2018-06-11 Thread afs
Github user afs commented on a diff in the pull request:

https://github.com/apache/jena/pull/433#discussion_r194399246
  
--- Diff: 
jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/mgt/ActionDatasets.java
 ---
@@ -351,15 +356,13 @@ private static void assemblerFromForm(HttpAction 
action, StreamRDF dest) {
 FusekiSystem.addGlobals(params); 
 
 //action.log.info(format("[%d] Create database : name = %s, type = 
%s", action.id, dbName, dbType )) ;
-if ( ! dbType.equals(tDatabasetTDB) && ! 
dbType.equals(tDatabasetMem) )
-ServletOps.errorBadRequest(format("dbType can be only '%s' or 
'%s'", tDatabasetTDB, tDatabasetMem)) ;
 
-String template = null ;
-if ( dbType.equalsIgnoreCase(tDatabasetTDB))
-template = 
TemplateFunctions.templateFile(Template.templateTDBFN, params, Lang.TTL) ;
-if ( dbType.equalsIgnoreCase(tDatabasetMem))
-template = 
TemplateFunctions.templateFile(Template.templateMemFN, params, Lang.TTL) ;
-RDFParser.create().source(new 
StringReader(template)).base("http://base/";).lang(Lang.TTL).parse(dest);
+String template = 
dbTypeToTemplate.get(dbType.toLowerCase(Locale.ROOT));
+if ( template == null )
+ServletOps.errorBadRequest(format("dbType can be only '%s' 
or '%s'", tDatabaseTDB, tDatabaseMem)) ;
--- End diff --

Good point! Done.


---


[jira] [Commented] (JENA-1561) Enable TDB2 in the Fuseki UI and on the Fuseki command line.

2018-06-11 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/JENA-1561?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16508027#comment-16508027
 ] 

ASF GitHub Bot commented on JENA-1561:
--

Github user afs commented on a diff in the pull request:

https://github.com/apache/jena/pull/433#discussion_r194399246
  
--- Diff: 
jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/mgt/ActionDatasets.java
 ---
@@ -351,15 +356,13 @@ private static void assemblerFromForm(HttpAction 
action, StreamRDF dest) {
 FusekiSystem.addGlobals(params); 
 
 //action.log.info(format("[%d] Create database : name = %s, type = 
%s", action.id, dbName, dbType )) ;
-if ( ! dbType.equals(tDatabasetTDB) && ! 
dbType.equals(tDatabasetMem) )
-ServletOps.errorBadRequest(format("dbType can be only '%s' or 
'%s'", tDatabasetTDB, tDatabasetMem)) ;
 
-String template = null ;
-if ( dbType.equalsIgnoreCase(tDatabasetTDB))
-template = 
TemplateFunctions.templateFile(Template.templateTDBFN, params, Lang.TTL) ;
-if ( dbType.equalsIgnoreCase(tDatabasetMem))
-template = 
TemplateFunctions.templateFile(Template.templateMemFN, params, Lang.TTL) ;
-RDFParser.create().source(new 
StringReader(template)).base("http://base/";).lang(Lang.TTL).parse(dest);
+String template = 
dbTypeToTemplate.get(dbType.toLowerCase(Locale.ROOT));
+if ( template == null )
+ServletOps.errorBadRequest(format("dbType can be only '%s' 
or '%s'", tDatabaseTDB, tDatabaseMem)) ;
--- End diff --

Good point! Done.


> Enable TDB2 in the Fuseki UI and on the Fuseki command line.
> 
>
> Key: JENA-1561
> URL: https://issues.apache.org/jira/browse/JENA-1561
> Project: Apache Jena
>  Issue Type: New Feature
>  Components: Fuseki
>Affects Versions: Jena 3.7.0
>Reporter: Andy Seaborne
>Assignee: Andy Seaborne
>Priority: Major
> Fix For: Jena 3.8.0
>
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[GitHub] jena pull request #431: JENA-1559: Alternative PrefixMapping implementation;...

2018-06-11 Thread afs
Github user afs commented on a diff in the pull request:

https://github.com/apache/jena/pull/431#discussion_r194405024
  
--- Diff: 
jena-arq/src/main/java/org/apache/jena/sparql/graph/PrefixMappingBase.java ---
@@ -0,0 +1,277 @@
+/*
+ * 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.graph;
+
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Optional;
+import java.util.StringJoiner;
+import java.util.function.BiConsumer;
+
+import org.apache.jena.ext.xerces.util.XMLChar;
+import org.apache.jena.shared.PrefixMapping;
+import org.apache.jena.util.SplitIRI;
+
+/**
+ * Framework for implementing {@link PrefixMapping}. It is stateless 
(unlike
+ * {@code PrefixMappingImpl}) and implements the contract of {@link 
PrefixMapping},
+ * providing the key algorithm and delegating storage to the subclasses.
+ * 
+ * Reverse mapping, looking up a URI to find a prefix is complex. There 
may be several
+ * possibilities. Applications should not reliy on every implementat being 
consistent,
+ * espeically when writing data when there has to be a choice on on prefix 
to use to
+ * shorten a URI.
+ * 
+ */
+public abstract class PrefixMappingBase implements PrefixMapping {
+/* Reverse mappings.
+ * The strict contract of PrefixMapping requires a separate 
reversemapping to be storoed and manipuated
+ * which in turn adds complexity to the storage implementations.
+ * However, applications removing prefixes is unusual so we end up 
with a lot of complexity with little value.
+ * 
+ * Beware of the details of removing a mapping when there is another 
to the same URI.
+ * If we had:
+ * 
+ *  Add (pref1, U)
+ *  Add (pref2, U)
+ * 
+ * so that {@code U} reverse maps ({@link #getNsURIPrefix}) to {@code 
pref2} (it was
+ * done second) then
+ * 
+ *  Remove (pref2)
+ * 
+ * it causes {@code U} to reverse map to {@code pref1}.
+ * 
+ * This feature is quite a burden on implementations and should be 
regarded as "legacy" -
+ * an implementation may not support this complex effect.
+ * 
+ * PrefixMappingMem does.
+ * Database backed ones typically don't.
+ */
+
+protected PrefixMappingBase() {}
+
+// The storage operations of an implementation.
+
+/** Add prefix */
+abstract protected void add(String prefix, String uri);
+
+/** Remove prefix. */
+abstract protected void remove(String prefix);
+
+/** Clear all mappings */
+abstract protected void clear();
+
+abstract protected boolean isEmpty();
+
+abstract protected int size();
+
+/** Return the URI that the prefix maps to. */ 
+abstract protected String prefixToUri(String prefix);
+
+/** Return a prefix that maps to the URI.
+ * There may be several; the answer is any one of them. 
+ */ 
+abstract protected String uriToPrefix(String uri);
+
+/** Return as a map. This map is only used within this class.
+ * It can be as efficient as possible.
+ * It will not be modifed.
+ * It wil not be retuned to a caller of {@code PrefixMappingBase}.
+ */
+abstract protected Map asMap();
+
+/** 
+ * Return as a map. The map return is not connected to the prefix 
mapping implementation,
+ * does not reflect subsequent prefix mapping changes.
+ */
+abstract protected Map asMapCopy();
+
+/** Apply the {@link BiConsumer} to each (prefix, uri) pair. */
+abstract protected void apply(BiConsumer action);
+
+/**
+ * This part of the subclass API and may be overriden if an 
implementation can do
+ * better This general implementation is based on asMap() which may be 
a copy or may
+ * be a v

[jira] [Commented] (JENA-1559) Avoid unnecessary prefix loading in GraphPrefixesProjection

2018-06-11 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/JENA-1559?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16508058#comment-16508058
 ] 

ASF GitHub Bot commented on JENA-1559:
--

Github user afs commented on a diff in the pull request:

https://github.com/apache/jena/pull/431#discussion_r194405024
  
--- Diff: 
jena-arq/src/main/java/org/apache/jena/sparql/graph/PrefixMappingBase.java ---
@@ -0,0 +1,277 @@
+/*
+ * 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.graph;
+
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Optional;
+import java.util.StringJoiner;
+import java.util.function.BiConsumer;
+
+import org.apache.jena.ext.xerces.util.XMLChar;
+import org.apache.jena.shared.PrefixMapping;
+import org.apache.jena.util.SplitIRI;
+
+/**
+ * Framework for implementing {@link PrefixMapping}. It is stateless 
(unlike
+ * {@code PrefixMappingImpl}) and implements the contract of {@link 
PrefixMapping},
+ * providing the key algorithm and delegating storage to the subclasses.
+ * 
+ * Reverse mapping, looking up a URI to find a prefix is complex. There 
may be several
+ * possibilities. Applications should not reliy on every implementat being 
consistent,
+ * espeically when writing data when there has to be a choice on on prefix 
to use to
+ * shorten a URI.
+ * 
+ */
+public abstract class PrefixMappingBase implements PrefixMapping {
+/* Reverse mappings.
+ * The strict contract of PrefixMapping requires a separate 
reversemapping to be storoed and manipuated
+ * which in turn adds complexity to the storage implementations.
+ * However, applications removing prefixes is unusual so we end up 
with a lot of complexity with little value.
+ * 
+ * Beware of the details of removing a mapping when there is another 
to the same URI.
+ * If we had:
+ * 
+ *  Add (pref1, U)
+ *  Add (pref2, U)
+ * 
+ * so that {@code U} reverse maps ({@link #getNsURIPrefix}) to {@code 
pref2} (it was
+ * done second) then
+ * 
+ *  Remove (pref2)
+ * 
+ * it causes {@code U} to reverse map to {@code pref1}.
+ * 
+ * This feature is quite a burden on implementations and should be 
regarded as "legacy" -
+ * an implementation may not support this complex effect.
+ * 
+ * PrefixMappingMem does.
+ * Database backed ones typically don't.
+ */
+
+protected PrefixMappingBase() {}
+
+// The storage operations of an implementation.
+
+/** Add prefix */
+abstract protected void add(String prefix, String uri);
+
+/** Remove prefix. */
+abstract protected void remove(String prefix);
+
+/** Clear all mappings */
+abstract protected void clear();
+
+abstract protected boolean isEmpty();
+
+abstract protected int size();
+
+/** Return the URI that the prefix maps to. */ 
+abstract protected String prefixToUri(String prefix);
+
+/** Return a prefix that maps to the URI.
+ * There may be several; the answer is any one of them. 
+ */ 
+abstract protected String uriToPrefix(String uri);
+
+/** Return as a map. This map is only used within this class.
+ * It can be as efficient as possible.
+ * It will not be modifed.
+ * It wil not be retuned to a caller of {@code PrefixMappingBase}.
+ */
+abstract protected Map asMap();
+
+/** 
+ * Return as a map. The map return is not connected to the prefix 
mapping implementation,
+ * does not reflect subsequent prefix mapping changes.
+ */
+abstract protected Map asMapCopy();
+
+/** Apply the {@link BiConsumer} to each (prefix, uri) pair. */
+abstract protected void 

[GitHub] jena pull request #434: JENA-1562: Fix for Graph.size() for TDB2 graphs

2018-06-11 Thread afs
Github user afs commented on a diff in the pull request:

https://github.com/apache/jena/pull/434#discussion_r194408181
  
--- Diff: 
jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/store/GraphViewSwitchable.java
 ---
@@ -79,16 +83,34 @@ public TransactionHandler getTransactionHandler() {
 /** Return the {@code DatasetGraphSwitchable} we are viewing. */
 @Override
 public DatasetGraphSwitchable getDataset() {
-return getx() ;
+return getx();
 }
 
 /** Return the {@code Graph} from the underlying switchable.
  *  Do not hold onto this reference across switches. 
  */
 public Graph getGraph() {
-return getx().getGraph(getGraphName()) ;
+return getx().getGraph(getGraphName());
 }
 
+// Super uses find. Override to call GraphTDB.size()
+@Override
+protected int graphBaseSize() {
+if ( isDefaultGraph() )
+return getDSG().getDefaultGraphTDB().size();
+return getDSG().getGraphTDB(getGraphName()).size();
+}
+
+private DatasetGraphTDB getDSG() {
+return ((DatasetGraphTDB)(getx().get()));
+}
+
+private static Function, Tuple> 
project4TupleTo3Tuple = item -> {
--- End diff --

OK - got it - it's a stray from GraphTDB. This one can be cleaned out.


---


[jira] [Commented] (JENA-1562) TDB2 Graph.size() is much slower than TDB1.

2018-06-11 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/JENA-1562?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16508073#comment-16508073
 ] 

ASF GitHub Bot commented on JENA-1562:
--

Github user afs commented on a diff in the pull request:

https://github.com/apache/jena/pull/434#discussion_r194408181
  
--- Diff: 
jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/store/GraphViewSwitchable.java
 ---
@@ -79,16 +83,34 @@ public TransactionHandler getTransactionHandler() {
 /** Return the {@code DatasetGraphSwitchable} we are viewing. */
 @Override
 public DatasetGraphSwitchable getDataset() {
-return getx() ;
+return getx();
 }
 
 /** Return the {@code Graph} from the underlying switchable.
  *  Do not hold onto this reference across switches. 
  */
 public Graph getGraph() {
-return getx().getGraph(getGraphName()) ;
+return getx().getGraph(getGraphName());
 }
 
+// Super uses find. Override to call GraphTDB.size()
+@Override
+protected int graphBaseSize() {
+if ( isDefaultGraph() )
+return getDSG().getDefaultGraphTDB().size();
+return getDSG().getGraphTDB(getGraphName()).size();
+}
+
+private DatasetGraphTDB getDSG() {
+return ((DatasetGraphTDB)(getx().get()));
+}
+
+private static Function, Tuple> 
project4TupleTo3Tuple = item -> {
--- End diff --

OK - got it - it's a stray from GraphTDB. This one can be cleaned out.


> TDB2 Graph.size() is much slower than TDB1.
> ---
>
> Key: JENA-1562
> URL: https://issues.apache.org/jira/browse/JENA-1562
> Project: Apache Jena
>  Issue Type: Bug
>Affects Versions: Jena 3.7.0
>Reporter: Andy Seaborne
>Assignee: Andy Seaborne
>Priority: Major
> Fix For: Jena 3.8.0
>
>
> TDB2 {{Graph.size()}} is much slower than TDB1.
> TDB2 {{Graph.size()}} relies on {{GraphBase.size}}, which uses 
> {{graph.find(ANY,ANY,ANY)}} which creates nodes and triples unnecessarily for 
> the count.
> TDB1 has code to use the primary tupleindex size() operation and it 50x 
> faster on 5m triples in the default graph.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (JENA-1560) Prefix utilities to prune prefixes to those needed by the data.

2018-06-11 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/JENA-1560?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16508871#comment-16508871
 ] 

ASF GitHub Bot commented on JENA-1560:
--

Github user ajs6f commented on a diff in the pull request:

https://github.com/apache/jena/pull/432#discussion_r194564937
  
--- Diff: 
jena-core/src/main/java/org/apache/jena/util/PrefixMappingUtils.java ---
@@ -0,0 +1,362 @@
+/*
+ * 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.util;
+
+import java.util.* ;
+import java.util.function.Consumer ;
+import java.util.stream.Collectors ;
+
+import org.apache.jena.atlas.lib.SetUtils ;
+import org.apache.jena.atlas.lib.Trie ;
+import org.apache.jena.graph.Graph ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.Triple ;
+import org.apache.jena.graph.impl.WrappedGraph;
+import org.apache.jena.rdf.model.Model ;
+import org.apache.jena.shared.PrefixMapping ;
+import org.apache.jena.shared.impl.PrefixMappingImpl ;
+
+public class PrefixMappingUtils {
+/**
+ * Return a read-only graph that has the same data (RDF triples) as 
the one given, but has a
+ * prefix mapping that only includes "in use " prefixes.
--- End diff --

Might want to put a link here to `calcInUsePrefixMapping` below just in 
case someone wants to the precise meaning of "in use". 


> Prefix utilities to prune prefixes to those needed by the data.
> ---
>
> Key: JENA-1560
> URL: https://issues.apache.org/jira/browse/JENA-1560
> Project: Apache Jena
>  Issue Type: New Feature
>  Components: Core
>Affects Versions: Jena 3.7.0
>Reporter: Andy Seaborne
>Assignee: Andy Seaborne
>Priority: Minor
>
> Sometimes, prefixes are no longer needed by the data. They still clutter-up 
> output. 
> In long lived (persistent), the effect can build up to the point where 
> several 10s of prefixes are present but not used.
> Some utilities to prune the unused prefixes would be useful.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[GitHub] jena pull request #432: JENA-1560: PrefixMappingUtils

2018-06-11 Thread ajs6f
Github user ajs6f commented on a diff in the pull request:

https://github.com/apache/jena/pull/432#discussion_r194568224
  
--- Diff: 
jena-core/src/main/java/org/apache/jena/util/PrefixMappingUtils.java ---
@@ -0,0 +1,362 @@
+/*
+ * 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.util;
+
+import java.util.* ;
+import java.util.function.Consumer ;
+import java.util.stream.Collectors ;
+
+import org.apache.jena.atlas.lib.SetUtils ;
+import org.apache.jena.atlas.lib.Trie ;
+import org.apache.jena.graph.Graph ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.Triple ;
+import org.apache.jena.graph.impl.WrappedGraph;
+import org.apache.jena.rdf.model.Model ;
+import org.apache.jena.shared.PrefixMapping ;
+import org.apache.jena.shared.impl.PrefixMappingImpl ;
+
+public class PrefixMappingUtils {
+/**
+ * Return a read-only graph that has the same data (RDF triples) as 
the one given, but has a
+ * prefix mapping that only includes "in use " prefixes.
+ * 
+ * The prefix mappings of the two graphs are not connected. 
+ * Later changes to the prefix mapping of the original graph are not 
reflected in the returned graph.
+ * Modifications to the triples conatained in the underlying graph are 
reflected.   
+ */
+public static Graph graphInUsePrefixMapping(Graph graph) {
+final PrefixMapping prefixMapping = calcInUsePrefixMapping(graph) ;
+prefixMapping.lock() ;
+Graph graph2 = new WrappedGraph(graph) {
+@Override
+public void performAdd(Triple triple)
+{ throw new UnsupportedOperationException() ; }
+
+@Override
+public void performDelete(Triple triple)
+{ throw new UnsupportedOperationException() ; }
+
+@Override
+public PrefixMapping getPrefixMapping() {
+return prefixMapping ;
+}
+} ;
+return graph2 ;
+}
+
+/**
+ * Analyse the graph to see which prefixes of the graph are in use.
+ * 
+ * In the case of overlapping prefixes (where one prefix declaration 
is has an initial
+ * URI string which matches another prefix declaration), all are 
included, though
+ * they may not be used when printing (that depends on the output 
process). In effect,
+ * this process has "false positives".
+ * 
+ * This function does not calculate new prefixes.
+ * 
+ * @see #calcInUsePrefixMappingTTL(Graph)
+ */
+public static PrefixMapping calcInUsePrefixMapping(Graph graph) {
+PrefixMapping prefixMapping = graph.getPrefixMapping() ;
+if ( prefixMapping == null )
+return null ;
+return calcInUsePrefixMapping(graph, prefixMapping) ;
+}
+
+/**
+ * Analyse the graph to see which prefixes of the given {@link 
PrefixMapping} are in
+ * use.
+ * 
+ * In the case of overlapping prefixes (where one prefix declaration 
is has an initial
+ * URI string which matches another prefix declaration), all are 
included, though
+ * they may not be used when printing (that depends on the output 
process). In effect,
+ * this process has "false positives".
+ * 
+ * This function does not calculate new prefixes.
+ * 
+ * @see #calcInUsePrefixMappingTTL(Graph, PrefixMapping)
+ */
+public static PrefixMapping calcInUsePrefixMapping(Graph graph, 
PrefixMapping prefixMapping) {
+
+/* Method:
+ * 
+ * For each URI in the data, look it up in the trie.
+ * to see if has a declared prefix.
+ * 
+ * Exit early if every prefix is accounted for. 
+ */
+   
+// Map prefix to URI.
+  

[GitHub] jena pull request #432: JENA-1560: PrefixMappingUtils

2018-06-11 Thread ajs6f
Github user ajs6f commented on a diff in the pull request:

https://github.com/apache/jena/pull/432#discussion_r194564937
  
--- Diff: 
jena-core/src/main/java/org/apache/jena/util/PrefixMappingUtils.java ---
@@ -0,0 +1,362 @@
+/*
+ * 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.util;
+
+import java.util.* ;
+import java.util.function.Consumer ;
+import java.util.stream.Collectors ;
+
+import org.apache.jena.atlas.lib.SetUtils ;
+import org.apache.jena.atlas.lib.Trie ;
+import org.apache.jena.graph.Graph ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.Triple ;
+import org.apache.jena.graph.impl.WrappedGraph;
+import org.apache.jena.rdf.model.Model ;
+import org.apache.jena.shared.PrefixMapping ;
+import org.apache.jena.shared.impl.PrefixMappingImpl ;
+
+public class PrefixMappingUtils {
+/**
+ * Return a read-only graph that has the same data (RDF triples) as 
the one given, but has a
+ * prefix mapping that only includes "in use " prefixes.
--- End diff --

Might want to put a link here to `calcInUsePrefixMapping` below just in 
case someone wants to the precise meaning of "in use". 


---


[jira] [Commented] (JENA-1560) Prefix utilities to prune prefixes to those needed by the data.

2018-06-11 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/JENA-1560?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16508872#comment-16508872
 ] 

ASF GitHub Bot commented on JENA-1560:
--

Github user ajs6f commented on a diff in the pull request:

https://github.com/apache/jena/pull/432#discussion_r194566823
  
--- Diff: 
jena-core/src/main/java/org/apache/jena/util/PrefixMappingUtils.java ---
@@ -0,0 +1,362 @@
+/*
+ * 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.util;
+
+import java.util.* ;
+import java.util.function.Consumer ;
+import java.util.stream.Collectors ;
+
+import org.apache.jena.atlas.lib.SetUtils ;
+import org.apache.jena.atlas.lib.Trie ;
+import org.apache.jena.graph.Graph ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.Triple ;
+import org.apache.jena.graph.impl.WrappedGraph;
+import org.apache.jena.rdf.model.Model ;
+import org.apache.jena.shared.PrefixMapping ;
+import org.apache.jena.shared.impl.PrefixMappingImpl ;
+
+public class PrefixMappingUtils {
+/**
+ * Return a read-only graph that has the same data (RDF triples) as 
the one given, but has a
+ * prefix mapping that only includes "in use " prefixes.
+ * 
+ * The prefix mappings of the two graphs are not connected. 
+ * Later changes to the prefix mapping of the original graph are not 
reflected in the returned graph.
+ * Modifications to the triples conatained in the underlying graph are 
reflected.   
+ */
+public static Graph graphInUsePrefixMapping(Graph graph) {
+final PrefixMapping prefixMapping = calcInUsePrefixMapping(graph) ;
+prefixMapping.lock() ;
+Graph graph2 = new WrappedGraph(graph) {
+@Override
+public void performAdd(Triple triple)
+{ throw new UnsupportedOperationException() ; }
+
+@Override
+public void performDelete(Triple triple)
+{ throw new UnsupportedOperationException() ; }
+
+@Override
+public PrefixMapping getPrefixMapping() {
+return prefixMapping ;
+}
+} ;
+return graph2 ;
+}
+
+/**
+ * Analyse the graph to see which prefixes of the graph are in use.
+ * 
+ * In the case of overlapping prefixes (where one prefix declaration 
is has an initial
+ * URI string which matches another prefix declaration), all are 
included, though
+ * they may not be used when printing (that depends on the output 
process). In effect,
+ * this process has "false positives".
+ * 
+ * This function does not calculate new prefixes.
+ * 
+ * @see #calcInUsePrefixMappingTTL(Graph)
+ */
+public static PrefixMapping calcInUsePrefixMapping(Graph graph) {
+PrefixMapping prefixMapping = graph.getPrefixMapping() ;
+if ( prefixMapping == null )
+return null ;
+return calcInUsePrefixMapping(graph, prefixMapping) ;
+}
+
+/**
+ * Analyse the graph to see which prefixes of the given {@link 
PrefixMapping} are in
+ * use.
+ * 
+ * In the case of overlapping prefixes (where one prefix declaration 
is has an initial
+ * URI string which matches another prefix declaration), all are 
included, though
+ * they may not be used when printing (that depends on the output 
process). In effect,
+ * this process has "false positives".
+ * 
+ * This function does not calculate new prefixes.
+ * 
+ * @see #calcInUsePrefixMappingTTL(Graph, PrefixMapping)
+ */
+public static PrefixMapping calcInUsePrefixMapping(Graph graph, 
PrefixMapping prefixMapping) {
+
+/* Method:
+ * 
+ * 

[jira] [Commented] (JENA-1560) Prefix utilities to prune prefixes to those needed by the data.

2018-06-11 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/JENA-1560?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16508873#comment-16508873
 ] 

ASF GitHub Bot commented on JENA-1560:
--

Github user ajs6f commented on a diff in the pull request:

https://github.com/apache/jena/pull/432#discussion_r194567840
  
--- Diff: 
jena-core/src/main/java/org/apache/jena/util/PrefixMappingUtils.java ---
@@ -0,0 +1,362 @@
+/*
+ * 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.util;
+
+import java.util.* ;
+import java.util.function.Consumer ;
+import java.util.stream.Collectors ;
+
+import org.apache.jena.atlas.lib.SetUtils ;
+import org.apache.jena.atlas.lib.Trie ;
+import org.apache.jena.graph.Graph ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.Triple ;
+import org.apache.jena.graph.impl.WrappedGraph;
+import org.apache.jena.rdf.model.Model ;
+import org.apache.jena.shared.PrefixMapping ;
+import org.apache.jena.shared.impl.PrefixMappingImpl ;
+
+public class PrefixMappingUtils {
+/**
+ * Return a read-only graph that has the same data (RDF triples) as 
the one given, but has a
+ * prefix mapping that only includes "in use " prefixes.
+ * 
+ * The prefix mappings of the two graphs are not connected. 
+ * Later changes to the prefix mapping of the original graph are not 
reflected in the returned graph.
+ * Modifications to the triples conatained in the underlying graph are 
reflected.   
+ */
+public static Graph graphInUsePrefixMapping(Graph graph) {
+final PrefixMapping prefixMapping = calcInUsePrefixMapping(graph) ;
+prefixMapping.lock() ;
+Graph graph2 = new WrappedGraph(graph) {
+@Override
+public void performAdd(Triple triple)
+{ throw new UnsupportedOperationException() ; }
+
+@Override
+public void performDelete(Triple triple)
+{ throw new UnsupportedOperationException() ; }
+
+@Override
+public PrefixMapping getPrefixMapping() {
+return prefixMapping ;
+}
+} ;
+return graph2 ;
+}
+
+/**
+ * Analyse the graph to see which prefixes of the graph are in use.
+ * 
+ * In the case of overlapping prefixes (where one prefix declaration 
is has an initial
+ * URI string which matches another prefix declaration), all are 
included, though
+ * they may not be used when printing (that depends on the output 
process). In effect,
+ * this process has "false positives".
+ * 
+ * This function does not calculate new prefixes.
+ * 
+ * @see #calcInUsePrefixMappingTTL(Graph)
+ */
+public static PrefixMapping calcInUsePrefixMapping(Graph graph) {
+PrefixMapping prefixMapping = graph.getPrefixMapping() ;
+if ( prefixMapping == null )
+return null ;
+return calcInUsePrefixMapping(graph, prefixMapping) ;
+}
+
+/**
+ * Analyse the graph to see which prefixes of the given {@link 
PrefixMapping} are in
+ * use.
+ * 
+ * In the case of overlapping prefixes (where one prefix declaration 
is has an initial
+ * URI string which matches another prefix declaration), all are 
included, though
+ * they may not be used when printing (that depends on the output 
process). In effect,
+ * this process has "false positives".
+ * 
+ * This function does not calculate new prefixes.
+ * 
+ * @see #calcInUsePrefixMappingTTL(Graph, PrefixMapping)
+ */
+public static PrefixMapping calcInUsePrefixMapping(Graph graph, 
PrefixMapping prefixMapping) {
+
+/* Method:
+ * 
+ * 

[GitHub] jena pull request #432: JENA-1560: PrefixMappingUtils

2018-06-11 Thread ajs6f
Github user ajs6f commented on a diff in the pull request:

https://github.com/apache/jena/pull/432#discussion_r194564667
  
--- Diff: 
jena-core/src/main/java/org/apache/jena/util/PrefixMappingUtils.java ---
@@ -0,0 +1,362 @@
+/*
+ * 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.util;
+
+import java.util.* ;
+import java.util.function.Consumer ;
+import java.util.stream.Collectors ;
+
+import org.apache.jena.atlas.lib.SetUtils ;
+import org.apache.jena.atlas.lib.Trie ;
+import org.apache.jena.graph.Graph ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.Triple ;
+import org.apache.jena.graph.impl.WrappedGraph;
+import org.apache.jena.rdf.model.Model ;
+import org.apache.jena.shared.PrefixMapping ;
+import org.apache.jena.shared.impl.PrefixMappingImpl ;
+
+public class PrefixMappingUtils {
+/**
+ * Return a read-only graph that has the same data (RDF triples) as 
the one given, but has a
+ * prefix mapping that only includes "in use " prefixes.
+ * 
+ * The prefix mappings of the two graphs are not connected. 
+ * Later changes to the prefix mapping of the original graph are not 
reflected in the returned graph.
+ * Modifications to the triples conatained in the underlying graph are 
reflected.   
--- End diff --

Typo "conatained" => "contained"


---


[jira] [Commented] (JENA-1560) Prefix utilities to prune prefixes to those needed by the data.

2018-06-11 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/JENA-1560?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16508870#comment-16508870
 ] 

ASF GitHub Bot commented on JENA-1560:
--

Github user ajs6f commented on a diff in the pull request:

https://github.com/apache/jena/pull/432#discussion_r194564667
  
--- Diff: 
jena-core/src/main/java/org/apache/jena/util/PrefixMappingUtils.java ---
@@ -0,0 +1,362 @@
+/*
+ * 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.util;
+
+import java.util.* ;
+import java.util.function.Consumer ;
+import java.util.stream.Collectors ;
+
+import org.apache.jena.atlas.lib.SetUtils ;
+import org.apache.jena.atlas.lib.Trie ;
+import org.apache.jena.graph.Graph ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.Triple ;
+import org.apache.jena.graph.impl.WrappedGraph;
+import org.apache.jena.rdf.model.Model ;
+import org.apache.jena.shared.PrefixMapping ;
+import org.apache.jena.shared.impl.PrefixMappingImpl ;
+
+public class PrefixMappingUtils {
+/**
+ * Return a read-only graph that has the same data (RDF triples) as 
the one given, but has a
+ * prefix mapping that only includes "in use " prefixes.
+ * 
+ * The prefix mappings of the two graphs are not connected. 
+ * Later changes to the prefix mapping of the original graph are not 
reflected in the returned graph.
+ * Modifications to the triples conatained in the underlying graph are 
reflected.   
--- End diff --

Typo "conatained" => "contained"


> Prefix utilities to prune prefixes to those needed by the data.
> ---
>
> Key: JENA-1560
> URL: https://issues.apache.org/jira/browse/JENA-1560
> Project: Apache Jena
>  Issue Type: New Feature
>  Components: Core
>Affects Versions: Jena 3.7.0
>Reporter: Andy Seaborne
>Assignee: Andy Seaborne
>Priority: Minor
>
> Sometimes, prefixes are no longer needed by the data. They still clutter-up 
> output. 
> In long lived (persistent), the effect can build up to the point where 
> several 10s of prefixes are present but not used.
> Some utilities to prune the unused prefixes would be useful.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[GitHub] jena pull request #432: JENA-1560: PrefixMappingUtils

2018-06-11 Thread ajs6f
Github user ajs6f commented on a diff in the pull request:

https://github.com/apache/jena/pull/432#discussion_r194566823
  
--- Diff: 
jena-core/src/main/java/org/apache/jena/util/PrefixMappingUtils.java ---
@@ -0,0 +1,362 @@
+/*
+ * 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.util;
+
+import java.util.* ;
+import java.util.function.Consumer ;
+import java.util.stream.Collectors ;
+
+import org.apache.jena.atlas.lib.SetUtils ;
+import org.apache.jena.atlas.lib.Trie ;
+import org.apache.jena.graph.Graph ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.Triple ;
+import org.apache.jena.graph.impl.WrappedGraph;
+import org.apache.jena.rdf.model.Model ;
+import org.apache.jena.shared.PrefixMapping ;
+import org.apache.jena.shared.impl.PrefixMappingImpl ;
+
+public class PrefixMappingUtils {
+/**
+ * Return a read-only graph that has the same data (RDF triples) as 
the one given, but has a
+ * prefix mapping that only includes "in use " prefixes.
+ * 
+ * The prefix mappings of the two graphs are not connected. 
+ * Later changes to the prefix mapping of the original graph are not 
reflected in the returned graph.
+ * Modifications to the triples conatained in the underlying graph are 
reflected.   
+ */
+public static Graph graphInUsePrefixMapping(Graph graph) {
+final PrefixMapping prefixMapping = calcInUsePrefixMapping(graph) ;
+prefixMapping.lock() ;
+Graph graph2 = new WrappedGraph(graph) {
+@Override
+public void performAdd(Triple triple)
+{ throw new UnsupportedOperationException() ; }
+
+@Override
+public void performDelete(Triple triple)
+{ throw new UnsupportedOperationException() ; }
+
+@Override
+public PrefixMapping getPrefixMapping() {
+return prefixMapping ;
+}
+} ;
+return graph2 ;
+}
+
+/**
+ * Analyse the graph to see which prefixes of the graph are in use.
+ * 
+ * In the case of overlapping prefixes (where one prefix declaration 
is has an initial
+ * URI string which matches another prefix declaration), all are 
included, though
+ * they may not be used when printing (that depends on the output 
process). In effect,
+ * this process has "false positives".
+ * 
+ * This function does not calculate new prefixes.
+ * 
+ * @see #calcInUsePrefixMappingTTL(Graph)
+ */
+public static PrefixMapping calcInUsePrefixMapping(Graph graph) {
+PrefixMapping prefixMapping = graph.getPrefixMapping() ;
+if ( prefixMapping == null )
+return null ;
+return calcInUsePrefixMapping(graph, prefixMapping) ;
+}
+
+/**
+ * Analyse the graph to see which prefixes of the given {@link 
PrefixMapping} are in
+ * use.
+ * 
+ * In the case of overlapping prefixes (where one prefix declaration 
is has an initial
+ * URI string which matches another prefix declaration), all are 
included, though
+ * they may not be used when printing (that depends on the output 
process). In effect,
+ * this process has "false positives".
+ * 
+ * This function does not calculate new prefixes.
+ * 
+ * @see #calcInUsePrefixMappingTTL(Graph, PrefixMapping)
+ */
+public static PrefixMapping calcInUsePrefixMapping(Graph graph, 
PrefixMapping prefixMapping) {
+
+/* Method:
+ * 
+ * For each URI in the data, look it up in the trie.
+ * to see if has a declared prefix.
+ * 
+ * Exit early if every prefix is accounted for. 
+ */
+   
+// Map prefix to URI.
+  

[jira] [Commented] (JENA-1560) Prefix utilities to prune prefixes to those needed by the data.

2018-06-11 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/JENA-1560?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16508874#comment-16508874
 ] 

ASF GitHub Bot commented on JENA-1560:
--

Github user ajs6f commented on a diff in the pull request:

https://github.com/apache/jena/pull/432#discussion_r194568224
  
--- Diff: 
jena-core/src/main/java/org/apache/jena/util/PrefixMappingUtils.java ---
@@ -0,0 +1,362 @@
+/*
+ * 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.util;
+
+import java.util.* ;
+import java.util.function.Consumer ;
+import java.util.stream.Collectors ;
+
+import org.apache.jena.atlas.lib.SetUtils ;
+import org.apache.jena.atlas.lib.Trie ;
+import org.apache.jena.graph.Graph ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.Triple ;
+import org.apache.jena.graph.impl.WrappedGraph;
+import org.apache.jena.rdf.model.Model ;
+import org.apache.jena.shared.PrefixMapping ;
+import org.apache.jena.shared.impl.PrefixMappingImpl ;
+
+public class PrefixMappingUtils {
+/**
+ * Return a read-only graph that has the same data (RDF triples) as 
the one given, but has a
+ * prefix mapping that only includes "in use " prefixes.
+ * 
+ * The prefix mappings of the two graphs are not connected. 
+ * Later changes to the prefix mapping of the original graph are not 
reflected in the returned graph.
+ * Modifications to the triples conatained in the underlying graph are 
reflected.   
+ */
+public static Graph graphInUsePrefixMapping(Graph graph) {
+final PrefixMapping prefixMapping = calcInUsePrefixMapping(graph) ;
+prefixMapping.lock() ;
+Graph graph2 = new WrappedGraph(graph) {
+@Override
+public void performAdd(Triple triple)
+{ throw new UnsupportedOperationException() ; }
+
+@Override
+public void performDelete(Triple triple)
+{ throw new UnsupportedOperationException() ; }
+
+@Override
+public PrefixMapping getPrefixMapping() {
+return prefixMapping ;
+}
+} ;
+return graph2 ;
+}
+
+/**
+ * Analyse the graph to see which prefixes of the graph are in use.
+ * 
+ * In the case of overlapping prefixes (where one prefix declaration 
is has an initial
+ * URI string which matches another prefix declaration), all are 
included, though
+ * they may not be used when printing (that depends on the output 
process). In effect,
+ * this process has "false positives".
+ * 
+ * This function does not calculate new prefixes.
+ * 
+ * @see #calcInUsePrefixMappingTTL(Graph)
+ */
+public static PrefixMapping calcInUsePrefixMapping(Graph graph) {
+PrefixMapping prefixMapping = graph.getPrefixMapping() ;
+if ( prefixMapping == null )
+return null ;
+return calcInUsePrefixMapping(graph, prefixMapping) ;
+}
+
+/**
+ * Analyse the graph to see which prefixes of the given {@link 
PrefixMapping} are in
+ * use.
+ * 
+ * In the case of overlapping prefixes (where one prefix declaration 
is has an initial
+ * URI string which matches another prefix declaration), all are 
included, though
+ * they may not be used when printing (that depends on the output 
process). In effect,
+ * this process has "false positives".
+ * 
+ * This function does not calculate new prefixes.
+ * 
+ * @see #calcInUsePrefixMappingTTL(Graph, PrefixMapping)
+ */
+public static PrefixMapping calcInUsePrefixMapping(Graph graph, 
PrefixMapping prefixMapping) {
+
+/* Method:
+ * 
+ * 

[GitHub] jena pull request #432: JENA-1560: PrefixMappingUtils

2018-06-11 Thread ajs6f
Github user ajs6f commented on a diff in the pull request:

https://github.com/apache/jena/pull/432#discussion_r194567840
  
--- Diff: 
jena-core/src/main/java/org/apache/jena/util/PrefixMappingUtils.java ---
@@ -0,0 +1,362 @@
+/*
+ * 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.util;
+
+import java.util.* ;
+import java.util.function.Consumer ;
+import java.util.stream.Collectors ;
+
+import org.apache.jena.atlas.lib.SetUtils ;
+import org.apache.jena.atlas.lib.Trie ;
+import org.apache.jena.graph.Graph ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.Triple ;
+import org.apache.jena.graph.impl.WrappedGraph;
+import org.apache.jena.rdf.model.Model ;
+import org.apache.jena.shared.PrefixMapping ;
+import org.apache.jena.shared.impl.PrefixMappingImpl ;
+
+public class PrefixMappingUtils {
+/**
+ * Return a read-only graph that has the same data (RDF triples) as 
the one given, but has a
+ * prefix mapping that only includes "in use " prefixes.
+ * 
+ * The prefix mappings of the two graphs are not connected. 
+ * Later changes to the prefix mapping of the original graph are not 
reflected in the returned graph.
+ * Modifications to the triples conatained in the underlying graph are 
reflected.   
+ */
+public static Graph graphInUsePrefixMapping(Graph graph) {
+final PrefixMapping prefixMapping = calcInUsePrefixMapping(graph) ;
+prefixMapping.lock() ;
+Graph graph2 = new WrappedGraph(graph) {
+@Override
+public void performAdd(Triple triple)
+{ throw new UnsupportedOperationException() ; }
+
+@Override
+public void performDelete(Triple triple)
+{ throw new UnsupportedOperationException() ; }
+
+@Override
+public PrefixMapping getPrefixMapping() {
+return prefixMapping ;
+}
+} ;
+return graph2 ;
+}
+
+/**
+ * Analyse the graph to see which prefixes of the graph are in use.
+ * 
+ * In the case of overlapping prefixes (where one prefix declaration 
is has an initial
+ * URI string which matches another prefix declaration), all are 
included, though
+ * they may not be used when printing (that depends on the output 
process). In effect,
+ * this process has "false positives".
+ * 
+ * This function does not calculate new prefixes.
+ * 
+ * @see #calcInUsePrefixMappingTTL(Graph)
+ */
+public static PrefixMapping calcInUsePrefixMapping(Graph graph) {
+PrefixMapping prefixMapping = graph.getPrefixMapping() ;
+if ( prefixMapping == null )
+return null ;
+return calcInUsePrefixMapping(graph, prefixMapping) ;
+}
+
+/**
+ * Analyse the graph to see which prefixes of the given {@link 
PrefixMapping} are in
+ * use.
+ * 
+ * In the case of overlapping prefixes (where one prefix declaration 
is has an initial
+ * URI string which matches another prefix declaration), all are 
included, though
+ * they may not be used when printing (that depends on the output 
process). In effect,
+ * this process has "false positives".
+ * 
+ * This function does not calculate new prefixes.
+ * 
+ * @see #calcInUsePrefixMappingTTL(Graph, PrefixMapping)
+ */
+public static PrefixMapping calcInUsePrefixMapping(Graph graph, 
PrefixMapping prefixMapping) {
+
+/* Method:
+ * 
+ * For each URI in the data, look it up in the trie.
+ * to see if has a declared prefix.
+ * 
+ * Exit early if every prefix is accounted for. 
+ */
+   
+// Map prefix to URI.
+