[GitHub] jena pull request: JENA-1147 : Introduce FactoryRDF

2016-03-08 Thread asfgit
Github user asfgit closed the pull request at:

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


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] jena pull request: JENA-1147 : Introduce FactoryRDF

2016-03-07 Thread ajs6f
Github user ajs6f commented on a diff in the pull request:

https://github.com/apache/jena/pull/128#discussion_r55197295
  
--- Diff: 
jena-arq/src/main/java/org/apache/jena/riot/system/FactoryRDFCaching.java ---
@@ -0,0 +1,110 @@
+/*
+ * 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.riot.system;
+
+import java.util.concurrent.ExecutionException ;
+
+import org.apache.jena.ext.com.google.common.cache.Cache ;
+import org.apache.jena.atlas.lib.cache.CacheInfo ;
+import org.apache.jena.datatypes.RDFDatatype ;
+import org.apache.jena.datatypes.xsd.XSDDatatype ;
+import org.apache.jena.ext.com.google.common.cache.CacheBuilder ;
+import org.apache.jena.ext.com.google.common.cache.CacheStats ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.riot.RiotException ;
+import org.apache.jena.riot.lang.LabelToNode ;
+import org.apache.jena.sparql.graph.NodeConst ;
+
+/** Adds some caching of created nodes - the caching is tuned to RIOT 
parser usage */ 
+public class FactoryRDFCaching extends FactoryRDFStd {
+public static final int DftNodeCacheSize = 5000 ; 
+
+// Control the setup - for one thread; start size = 50% of full size, 
no stats
+private final Cache cache ;
+
+public FactoryRDFCaching() {
+this(DftNodeCacheSize) ;
+}
+
+public FactoryRDFCaching(int cacheSize) {
+super() ;
+cache = setCache(cacheSize) ;
+}
+
+private Cache setCache(int cacheSize) {
+return CacheBuilder.newBuilder()
+.maximumSize(cacheSize)
+.initialCapacity(cacheSize/2)
+//.recordStats()
+.concurrencyLevel(1)
+.build() ;
+}
+
+public FactoryRDFCaching(int cacheSize, LabelToNode labelMapping) {
+super(labelMapping) ;
+cache = setCache(cacheSize) ;
+}
+
+@Override
+public Node createURI(String uriStr) {
+try {
+return cache.get(uriStr, ()->RiotLib.createIRIorBNode(uriStr)) 
;
--- End diff --

Ah, cool.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] jena pull request: JENA-1147 : Introduce FactoryRDF

2016-03-07 Thread afs
Github user afs commented on a diff in the pull request:

https://github.com/apache/jena/pull/128#discussion_r55197173
  
--- Diff: 
jena-arq/src/main/java/org/apache/jena/riot/system/FactoryRDFCaching.java ---
@@ -0,0 +1,110 @@
+/*
+ * 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.riot.system;
+
+import java.util.concurrent.ExecutionException ;
+
+import org.apache.jena.ext.com.google.common.cache.Cache ;
+import org.apache.jena.atlas.lib.cache.CacheInfo ;
+import org.apache.jena.datatypes.RDFDatatype ;
+import org.apache.jena.datatypes.xsd.XSDDatatype ;
+import org.apache.jena.ext.com.google.common.cache.CacheBuilder ;
+import org.apache.jena.ext.com.google.common.cache.CacheStats ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.riot.RiotException ;
+import org.apache.jena.riot.lang.LabelToNode ;
+import org.apache.jena.sparql.graph.NodeConst ;
+
+/** Adds some caching of created nodes - the caching is tuned to RIOT 
parser usage */ 
+public class FactoryRDFCaching extends FactoryRDFStd {
+public static final int DftNodeCacheSize = 5000 ; 
+
+// Control the setup - for one thread; start size = 50% of full size, 
no stats
+private final Cache cache ;
+
+public FactoryRDFCaching() {
+this(DftNodeCacheSize) ;
+}
+
+public FactoryRDFCaching(int cacheSize) {
+super() ;
+cache = setCache(cacheSize) ;
+}
+
+private Cache setCache(int cacheSize) {
+return CacheBuilder.newBuilder()
+.maximumSize(cacheSize)
+.initialCapacity(cacheSize/2)
+//.recordStats()
+.concurrencyLevel(1)
+.build() ;
+}
+
+public FactoryRDFCaching(int cacheSize, LabelToNode labelMapping) {
+super(labelMapping) ;
+cache = setCache(cacheSize) ;
+}
+
+@Override
+public Node createURI(String uriStr) {
+try {
+return cache.get(uriStr, ()->RiotLib.createIRIorBNode(uriStr)) 
;
--- End diff --

`NodeFactory` is fundamental and provide exactly the creation operations 
without opinion (maybe you want to create a real URI that looks like 
`<_:label>` e.g. for output.

`RiotLib.createIRIorBNode` understands the `<_:label>` form. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] jena pull request: JENA-1147 : Introduce FactoryRDF

2016-03-07 Thread ajs6f
Github user ajs6f commented on a diff in the pull request:

https://github.com/apache/jena/pull/128#discussion_r55195827
  
--- Diff: 
jena-arq/src/main/java/org/apache/jena/riot/system/FactoryRDFCaching.java ---
@@ -0,0 +1,110 @@
+/*
+ * 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.riot.system;
+
+import java.util.concurrent.ExecutionException ;
+
+import org.apache.jena.ext.com.google.common.cache.Cache ;
+import org.apache.jena.atlas.lib.cache.CacheInfo ;
+import org.apache.jena.datatypes.RDFDatatype ;
+import org.apache.jena.datatypes.xsd.XSDDatatype ;
+import org.apache.jena.ext.com.google.common.cache.CacheBuilder ;
+import org.apache.jena.ext.com.google.common.cache.CacheStats ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.riot.RiotException ;
+import org.apache.jena.riot.lang.LabelToNode ;
+import org.apache.jena.sparql.graph.NodeConst ;
+
+/** Adds some caching of created nodes - the caching is tuned to RIOT 
parser usage */ 
+public class FactoryRDFCaching extends FactoryRDFStd {
+public static final int DftNodeCacheSize = 5000 ; 
+
+// Control the setup - for one thread; start size = 50% of full size, 
no stats
+private final Cache cache ;
+
+public FactoryRDFCaching() {
+this(DftNodeCacheSize) ;
+}
+
+public FactoryRDFCaching(int cacheSize) {
+super() ;
+cache = setCache(cacheSize) ;
+}
+
+private Cache setCache(int cacheSize) {
+return CacheBuilder.newBuilder()
+.maximumSize(cacheSize)
+.initialCapacity(cacheSize/2)
+//.recordStats()
+.concurrencyLevel(1)
+.build() ;
+}
+
+public FactoryRDFCaching(int cacheSize, LabelToNode labelMapping) {
+super(labelMapping) ;
+cache = setCache(cacheSize) ;
+}
+
+@Override
+public Node createURI(String uriStr) {
+try {
+return cache.get(uriStr, ()->RiotLib.createIRIorBNode(uriStr)) 
;
--- End diff --

This may be a dumb question, but why `RiotLib` here, why not `NodeFactory`?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] jena pull request: JENA-1147 : Introduce FactoryRDF

2016-03-07 Thread ajs6f
Github user ajs6f commented on a diff in the pull request:

https://github.com/apache/jena/pull/128#discussion_r55195636
  
--- Diff: 
jena-arq/src/main/java/org/apache/jena/riot/system/FactoryRDF.java ---
@@ -0,0 +1,56 @@
+/*
+ * 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.riot.system;
+
+import org.apache.jena.datatypes.RDFDatatype ;
+import org.apache.jena.graph.Graph ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.Triple ;
+import org.apache.jena.sparql.core.DatasetGraph ;
+import org.apache.jena.sparql.core.Quad ;
+
+/**
+ * Create core RDF objects: {@link Node}s, {@link Triple}s, {@link Quad}s,
+ * {@link Graph}, {@link DatasetGraph}s.
+ * 
+ */
+public interface FactoryRDF {
+// ?? Are these too varied?
+public Graph createGraph() ;
+// ?? Are these too varied?
+public DatasetGraph createDatasetGraph() ;
+public Triple createTriple(Node subject, Node predicate, Node object) ;
+public Quad createQuad(Node graph, Node subject, Node predicate, Node 
object) ;
+public Node createURI(String uriStr) ;
+public Node createTypedLiteral(String lexical, RDFDatatype datatype) ;
+public Node createLangLiteral(String lexical, String langTag) ;
+public Node createStringLiteral(String lexical) ;
+/** Create a blank node */
+public Node createBlankNode() ;
--- End diff --

Do we want something for `BlankNodeId` here?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] jena pull request: JENA-1147 : Introduce FactoryRDF

2016-03-06 Thread afs
GitHub user afs opened a pull request:

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

JENA-1147 : Introduce FactoryRDF 

FactoryRDF is an interface to abstract the creation of nodes, triples and 
quads from constituent elements, e.g. to create a URI Node, the operation takes 
a string for the URI. This allows different policies to be slotted in. This PR 
covers the use of FactoryRDF by ParserProfile.

You can merge this pull request into a Git repository by running:

$ git pull https://github.com/afs/jena master

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/jena/pull/128.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #128


commit 5bc88315ae5ec1c8bb75a794f6f8ca157ebcc6f3
Author: Andy Seaborne 
Date:   2016-03-06T22:56:03Z

Associate a ProgressMonitor with a StreamRDF.

commit ed9f62a0fe3d5616737725fc27205c03859424a6
Author: Andy Seaborne 
Date:   2016-03-06T22:58:26Z

JENA-1147: Introduce FactoryRDF and use in ParserProfile.

commit 1818bb50e6613eb606f6191242becae43099d82a
Author: Andy Seaborne 
Date:   2016-03-06T23:00:36Z

Adjust for FactoryRDF




---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] jena pull request: JENA-1147 : Introduce FactoryRDF

2016-03-06 Thread afs
Github user afs commented on the pull request:

https://github.com/apache/jena/pull/127#issuecomment-193008707
  
This has got messy.  I'll resubmit a cleaned up version.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] jena pull request: JENA-1147 : Introduce FactoryRDF

2016-03-06 Thread afs
Github user afs closed the pull request at:

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


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] jena pull request: JENA-1147 : Introduce FactoryRDF

2016-03-05 Thread afs
GitHub user afs opened a pull request:

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

JENA-1147 : Introduce FactoryRDF

FactoryRDF is an interface to abstract the creation of nodes, triples and 
quads from constituent elements, e.g. to create a URI Node, the operation takes 
a string for the URI. This allows different policies to be slotted in.  This PR 
covers the use of FactoryRDF by ParserProfile. A PR to follow will use a 
caching implementation of FactoryRDF as the default mechanism when parsing.

You can merge this pull request into a Git repository by running:

$ git pull https://github.com/afs/jena master

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/jena/pull/127.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #127


commit a19aa45a1106ae9ece835a9f17a39663f74f4b78
Author: Andy Seaborne 
Date:   2016-03-05T14:28:18Z

Introduce FactoryRDF and use in ParserProfile.




---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---