clerezza-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject clerezza-rdf-core git commit: CLEREZZA-1011: Fiexd Handler and added tests, using released dependecies to allow release
Date Fri, 08 Jul 2016 08:51:44 GMT
Repository: clerezza-rdf-core
Updated Branches:
  refs/heads/master 2506180b2 -> 03f02db65


CLEREZZA-1011: Fiexd Handler and added tests, using released dependecies to allow release

Project: http://git-wip-us.apache.org/repos/asf/clerezza-rdf-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/clerezza-rdf-core/commit/03f02db6
Tree: http://git-wip-us.apache.org/repos/asf/clerezza-rdf-core/tree/03f02db6
Diff: http://git-wip-us.apache.org/repos/asf/clerezza-rdf-core/diff/03f02db6

Branch: refs/heads/master
Commit: 03f02db652cf20c03c8fc3786e3ba4655f340951
Parents: 2506180
Author: Reto Gmuer <reto@apache.org>
Authored: Fri Jul 8 08:50:12 2016 +0000
Committer: Reto Gmuer <reto@apache.org>
Committed: Fri Jul 8 08:50:12 2016 +0000

----------------------------------------------------------------------
 impl.sparql/pom.xml                             | 16 +++-
 .../commons/rdf/impl/sparql/SparqlClient.java   | 16 ++--
 .../commons/rdf/impl/sparql/SparqlGraph.java    |  3 +-
 .../commons/rdf/impl/sparql/DadminTest.java     | 94 ++++++++++++++++++++
 .../clerezza/commons/rdf/impl/sparql/dadmin.ttl |  5 ++
 5 files changed, 126 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/clerezza-rdf-core/blob/03f02db6/impl.sparql/pom.xml
----------------------------------------------------------------------
diff --git a/impl.sparql/pom.xml b/impl.sparql/pom.xml
index 2ab62c2..8cde92d 100644
--- a/impl.sparql/pom.xml
+++ b/impl.sparql/pom.xml
@@ -84,12 +84,12 @@
         <dependency>
             <groupId>org.apache.clerezza.commons-rdf</groupId>
             <artifactId>commons-rdf-api</artifactId>
-            <version>0.3-SNAPSHOT</version>
+            <version>0.2</version>
         </dependency>
         <dependency>
             <groupId>org.apache.clerezza.commons-rdf</groupId>
             <artifactId>commons-rdf-impl-utils</artifactId>
-            <version>0.3-SNAPSHOT</version>
+            <version>0.2</version>
         </dependency>
         <dependency>
             <groupId>junit</groupId>
@@ -102,5 +102,17 @@
             <version>1.1.1</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.clerezza</groupId>
+            <artifactId>rdf.core</artifactId>
+            <version>1.0.0</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.clerezza</groupId>
+            <artifactId>rdf.jena.serializer</artifactId>
+            <version>1.1.1</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>    
 </project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/clerezza-rdf-core/blob/03f02db6/impl.sparql/src/main/java/org/apache/clerezza/commons/rdf/impl/sparql/SparqlClient.java
----------------------------------------------------------------------
diff --git a/impl.sparql/src/main/java/org/apache/clerezza/commons/rdf/impl/sparql/SparqlClient.java
b/impl.sparql/src/main/java/org/apache/clerezza/commons/rdf/impl/sparql/SparqlClient.java
index 90a2b96..2745a0e 100644
--- a/impl.sparql/src/main/java/org/apache/clerezza/commons/rdf/impl/sparql/SparqlClient.java
+++ b/impl.sparql/src/main/java/org/apache/clerezza/commons/rdf/impl/sparql/SparqlClient.java
@@ -15,8 +15,11 @@
  */
 package org.apache.clerezza.commons.rdf.impl.sparql;
 
+import java.io.BufferedInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.StringWriter;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -95,7 +98,7 @@ public class SparqlClient {
         private final List<Map<String, RDFTerm>> results = new ArrayList<>();
         private boolean readingValue;
         private String lang; //the xml:lang attribute of a literal
-        private String value;
+        private StringWriter valueWriter;
         private Map<String, BlankNode> bNodeMap = new HashMap<>();
         private static final IRI XSD_STRING = new IRI("http://www.w3.org/2001/XMLSchema#string");
         private static final IRI RDF_LANG_STRING = new IRI("http://www.w3.org/1999/02/22-rdf-syntax-ns#langString");
@@ -144,6 +147,7 @@ public class SparqlClient {
                     }
                     lang = atts.getValue("http://www.w3.org/XML/1998/namespace", "lang");
                     readingValue = true;
+                    valueWriter = new StringWriter();
                 }
             }
 
@@ -154,7 +158,7 @@ public class SparqlClient {
         @Override
         public void characters(char[] chars, int start, int length) throws SAXException {
             if (readingValue) {
-                value = new String(chars, start, length);
+                valueWriter.write(chars, start, length);
                 //System.err.println(value + start + ", " + length);
             }
         }
@@ -180,13 +184,15 @@ public class SparqlClient {
                         final Language language = lang == null? null : new Language(lang);;
                         switch (b) {
                             case uri:
-                                rdfTerm = new IRI(value);
+                                rdfTerm = new IRI(valueWriter.toString());
+                                valueWriter = null;
                                 break;
                             case bnode:
-                                rdfTerm = getBNode(value);
+                                rdfTerm = getBNode(valueWriter.toString());
+                                valueWriter = null;
                                 break;
                             case literal:
-                                final String lf = value;
+                                final String lf = valueWriter.toString();
                                 rdfTerm = new AbstractLiteral() {
 
                                     @Override

http://git-wip-us.apache.org/repos/asf/clerezza-rdf-core/blob/03f02db6/impl.sparql/src/main/java/org/apache/clerezza/commons/rdf/impl/sparql/SparqlGraph.java
----------------------------------------------------------------------
diff --git a/impl.sparql/src/main/java/org/apache/clerezza/commons/rdf/impl/sparql/SparqlGraph.java
b/impl.sparql/src/main/java/org/apache/clerezza/commons/rdf/impl/sparql/SparqlGraph.java
index 0df3f14..9874084 100644
--- a/impl.sparql/src/main/java/org/apache/clerezza/commons/rdf/impl/sparql/SparqlGraph.java
+++ b/impl.sparql/src/main/java/org/apache/clerezza/commons/rdf/impl/sparql/SparqlGraph.java
@@ -387,6 +387,7 @@ public class SparqlGraph extends AbstractGraph {
     @Override
     protected int performSize() {
         try {
+            //TODO replace this with count
             return sparqlClient.queryResultSet("SELECT * WHERE { ?s ?p ?o}").size();
         } catch (IOException ex) {
             throw new RuntimeException(ex);
@@ -399,7 +400,7 @@ public class SparqlGraph extends AbstractGraph {
 
     private String asSparqlTerm(Literal literal) {
         //TODO langauge and datatype
-        return "\"" + literal.getLexicalForm() + "\"";
+        return "\"" + literal.getLexicalForm().replace("\n", "\\n").replace("\"", "\\\"")
+ "\"";
     }
 
     private String asSparqlTerm(BlankNode bnode) {

http://git-wip-us.apache.org/repos/asf/clerezza-rdf-core/blob/03f02db6/impl.sparql/src/test/java/org/apache/clerezza/commons/rdf/impl/sparql/DadminTest.java
----------------------------------------------------------------------
diff --git a/impl.sparql/src/test/java/org/apache/clerezza/commons/rdf/impl/sparql/DadminTest.java
b/impl.sparql/src/test/java/org/apache/clerezza/commons/rdf/impl/sparql/DadminTest.java
new file mode 100644
index 0000000..d65a327
--- /dev/null
+++ b/impl.sparql/src/test/java/org/apache/clerezza/commons/rdf/impl/sparql/DadminTest.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2015 The Apache Software Foundation.
+ *
+ * Licensed 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.clerezza.commons.rdf.impl.sparql;
+
+import com.hp.hpl.jena.query.DatasetAccessor;
+import com.hp.hpl.jena.query.DatasetAccessorFactory;
+import java.io.IOException;
+import java.net.ServerSocket;
+import org.apache.jena.fuseki.EmbeddedFusekiServer;
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
+import java.io.InputStream;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+import org.apache.clerezza.commons.rdf.Graph;
+import org.apache.clerezza.commons.rdf.IRI;
+import org.apache.clerezza.commons.rdf.Language;
+import org.apache.clerezza.commons.rdf.Literal;
+import org.apache.clerezza.commons.rdf.RDFTerm;
+import org.apache.clerezza.commons.rdf.Triple;
+import org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl;
+import org.apache.clerezza.rdf.core.serializedform.Serializer;
+import org.apache.clerezza.rdf.core.serializedform.SupportedFormat;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ *
+ * @author reto
+ */
+public class DadminTest {
+
+    final static int serverPort = findFreePort();
+    static EmbeddedFusekiServer server;
+
+    @BeforeClass
+    public static void prepare() throws IOException {
+        final String serviceURI = "http://localhost:" + serverPort + "/ds/data";
+        final DatasetAccessor accessor = DatasetAccessorFactory.createHTTP(serviceURI);
+        final InputStream in = DadminTest.class.getResourceAsStream("dadmin.ttl");
+        final Model m = ModelFactory.createDefaultModel();
+        String base = "http://example.org/";
+        m.read(in, base, "TURTLE");
+        server = EmbeddedFusekiServer.memTDB(serverPort, "/ds");//dataSet.getAbsolutePath());
+        server.start();
+        System.out.println("Started fuseki on port " + serverPort);
+        accessor.putModel(m);
+    }
+
+    @AfterClass
+    public static void cleanup() {
+        server.stop();
+    }
+
+    @Test
+    public void graphSize() {
+        final Graph graph = new SparqlGraph("http://localhost:" + serverPort + "/ds/query");
+        Assert.assertEquals("Graph not of the exepected size", 1, graph.size());
+    }
+
+    @Test
+    public void dump() {
+        final Graph graph = new SparqlGraph("http://localhost:" + serverPort + "/ds/query");
+        Serializer serializer = Serializer.getInstance();
+        serializer.serialize(System.out, graph, SupportedFormat.TURTLE);
+    }
+
+    public static int findFreePort() {
+        int port = 0;
+        try (ServerSocket server = new ServerSocket(0);) {
+            port = server.getLocalPort();
+        } catch (Exception e) {
+            throw new RuntimeException("unable to find a free port");
+        }
+        return port;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/clerezza-rdf-core/blob/03f02db6/impl.sparql/src/test/resources/org/apache/clerezza/commons/rdf/impl/sparql/dadmin.ttl
----------------------------------------------------------------------
diff --git a/impl.sparql/src/test/resources/org/apache/clerezza/commons/rdf/impl/sparql/dadmin.ttl
b/impl.sparql/src/test/resources/org/apache/clerezza/commons/rdf/impl/sparql/dadmin.ttl
new file mode 100644
index 0000000..1213792
--- /dev/null
+++ b/impl.sparql/src/test/resources/org/apache/clerezza/commons/rdf/impl/sparql/dadmin.ttl
@@ -0,0 +1,5 @@
+@prefix rdf:	<http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+@prefix ns1:	<http://schema.org/> .
+
+_:b10521
+	ns1:articleBody	"\n  <li><a href=\"http://data.admin.ch/datasets\" title=\"Available
Data\">Data</a></li>\n  <li><a href=\"http://data.admin.ch/apps\"
title=\"Applications\">Applications</a></li>\n  <li><a href=\"http://data.admin.ch/sparql\"
title=\"SPARQL Endpoint\">SPARQL</a></li>\n  <li><a title=\"About
the Portal\" href=\"http://data.admin.ch/about\">About the Portal</a></li>\n
 <li><a title=\"Contact Us\" href=\"http://data.admin.ch/contact\">Contact</a></li>\n"
.
\ No newline at end of file


Mime
View raw message