commonsrdf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject [04/33] incubator-commonsrdf git commit: Example : Jena parsers : commons-rdf Graph
Date Mon, 28 Mar 2016 04:55:00 GMT
Example : Jena parsers : commons-rdf Graph


Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/5f8a497e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/5f8a497e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/5f8a497e

Branch: refs/heads/jena
Commit: 5f8a497ea637bdd0326b3b3d7ed8a81826be4792
Parents: 3f532a8
Author: Andy Seaborne <andy@seaborne.org>
Authored: Wed Aug 26 15:58:02 2015 +0100
Committer: Andy Seaborne <andy@seaborne.org>
Committed: Wed Aug 26 15:58:02 2015 +0100

----------------------------------------------------------------------
 D.ttl                                           |  4 ++
 .../java/org/apache/jena/commons/Example1.java  | 37 +++++++++++++
 .../java/org/apache/jena/commons/JCR_Term.java  |  2 +
 .../org/apache/jena/commons/JCR_Triple.java     |  5 ++
 .../java/org/apache/jena/commons/ToGraph.java   | 55 ++++++++++++++++++++
 5 files changed, 103 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/5f8a497e/D.ttl
----------------------------------------------------------------------
diff --git a/D.ttl b/D.ttl
new file mode 100644
index 0000000..d37081c
--- /dev/null
+++ b/D.ttl
@@ -0,0 +1,4 @@
+prefix : <http://example/>
+
+:s :p 123 .
+[ :p1 [ :q "r"@en ] ] .

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/5f8a497e/src/main/java/org/apache/jena/commons/Example1.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/jena/commons/Example1.java b/src/main/java/org/apache/jena/commons/Example1.java
new file mode 100644
index 0000000..36ccbb9
--- /dev/null
+++ b/src/main/java/org/apache/jena/commons/Example1.java
@@ -0,0 +1,37 @@
+/**
+ * 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.commons;
+
+import org.apache.commons.rdf.api.Graph ;
+import org.apache.commons.rdf.api.RDFTermFactory ;
+import org.apache.jena.riot.RDFDataMgr ;
+
+public class Example1 {
+
+    public static void main(String[] args) {
+        RDFTermFactory rft = new RDFTermFactoryJena() ;
+        Graph graph = rft.createGraph() ;
+        ToGraph dest = new ToGraph(graph) ;
+        RDFDataMgr.parse(dest, "D.ttl") ;
+        
+        graph.getTriples().forEach(System.out::println) ;
+    }
+
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/5f8a497e/src/main/java/org/apache/jena/commons/JCR_Term.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/jena/commons/JCR_Term.java b/src/main/java/org/apache/jena/commons/JCR_Term.java
index a07d2d9..f475d3e 100644
--- a/src/main/java/org/apache/jena/commons/JCR_Term.java
+++ b/src/main/java/org/apache/jena/commons/JCR_Term.java
@@ -37,6 +37,8 @@ class JCR_Term implements JenaCommonsRDF {
     }
 
     public String ntriplesString() {
+        if ( node.isBlank() )
+            return "_:C"+node.getBlankNodeLabel() ;
         return FmtUtils.stringForNode(node, empty) ;
     }
     

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/5f8a497e/src/main/java/org/apache/jena/commons/JCR_Triple.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/jena/commons/JCR_Triple.java b/src/main/java/org/apache/jena/commons/JCR_Triple.java
index 2f46653..78463d0 100644
--- a/src/main/java/org/apache/jena/commons/JCR_Triple.java
+++ b/src/main/java/org/apache/jena/commons/JCR_Triple.java
@@ -63,5 +63,10 @@ public class JCR_Triple implements Triple {
             getPredicate().equals(triple.getPredicate()) &&
             getObject().equals(triple.getObject()) ;
     }
+    
+    @Override 
+    public String toString() {
+        return getSubject()+" "+getPredicate()+" "+getObject()+" ." ;
+    }
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/5f8a497e/src/main/java/org/apache/jena/commons/ToGraph.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/jena/commons/ToGraph.java b/src/main/java/org/apache/jena/commons/ToGraph.java
new file mode 100644
index 0000000..618c5e0
--- /dev/null
+++ b/src/main/java/org/apache/jena/commons/ToGraph.java
@@ -0,0 +1,55 @@
+/**
+ * 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.commons;
+
+import org.apache.commons.rdf.api.Graph ;
+import org.apache.jena.riot.system.StreamRDF ;
+
+public class ToGraph implements StreamRDF {
+
+    private Graph graph;
+
+    public ToGraph(Graph graph) {
+        this.graph = graph ;
+    }
+
+    @Override
+    public void start() {}
+
+    @Override
+    public void triple(org.apache.jena.graph.Triple triple) {
+        graph.add(JCR_Factory.fromJena(triple));
+    }
+
+    @Override
+    public void quad(org.apache.jena.sparql.core.Quad quad) {
+        throw new UnsupportedOperationException() ;
+    }
+
+    @Override
+    public void base(String base) {}
+
+    @Override
+    public void prefix(String prefix, String iri) {}
+
+    @Override
+    public void finish() {}
+    
+}
+


Mime
View raw message