You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by wi...@apache.org on 2014/01/20 17:57:28 UTC

[1/4] git commit: MARMOTTA-423: fixed test suite

Updated Branches:
  refs/heads/develop dc950842a -> 4001e928e


MARMOTTA-423: fixed test suite


Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/3a1dcbb7
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/3a1dcbb7
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/3a1dcbb7

Branch: refs/heads/develop
Commit: 3a1dcbb7c4876d46d99a3632ae84b41de578d3ba
Parents: 387e2f3
Author: Sergio Fernández <wi...@apache.org>
Authored: Mon Jan 20 17:06:15 2014 +0100
Committer: Sergio Fernández <wi...@apache.org>
Committed: Mon Jan 20 17:06:15 2014 +0100

----------------------------------------------------------------------
 .../org/apache/marmotta/ldclient/test/freebase/m.07zqbwz.sparql  | 4 ++--
 .../org/apache/marmotta/ldclient/test/freebase/m.0nzm.sparql     | 4 ++--
 .../org/apache/marmotta/ldclient/test/freebase/m.0wqhskn.sparql  | 4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/marmotta/blob/3a1dcbb7/libraries/ldclient/ldclient-provider-freebase/src/test/resources/org/apache/marmotta/ldclient/test/freebase/m.07zqbwz.sparql
----------------------------------------------------------------------
diff --git a/libraries/ldclient/ldclient-provider-freebase/src/test/resources/org/apache/marmotta/ldclient/test/freebase/m.07zqbwz.sparql b/libraries/ldclient/ldclient-provider-freebase/src/test/resources/org/apache/marmotta/ldclient/test/freebase/m.07zqbwz.sparql
index b404068..8f3f336 100644
--- a/libraries/ldclient/ldclient-provider-freebase/src/test/resources/org/apache/marmotta/ldclient/test/freebase/m.07zqbwz.sparql
+++ b/libraries/ldclient/ldclient-provider-freebase/src/test/resources/org/apache/marmotta/ldclient/test/freebase/m.07zqbwz.sparql
@@ -20,7 +20,7 @@ PREFIX ns: <http://rdf.freebase.com/ns/>
 PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
 
 ASK {
-   ns:m.07zqbwz> ns:rdf:type ns:people.person ;
-        rdfs:label: "Sergio Fernández"@en ;
+   ns:m.07zqbwz ns:rdf:type ns:people.person ;
+        rdfs:label "Sergio Fernández"@en ;
         ns:common.topic.official_website <http://www.wikier.org>  .
 }

http://git-wip-us.apache.org/repos/asf/marmotta/blob/3a1dcbb7/libraries/ldclient/ldclient-provider-freebase/src/test/resources/org/apache/marmotta/ldclient/test/freebase/m.0nzm.sparql
----------------------------------------------------------------------
diff --git a/libraries/ldclient/ldclient-provider-freebase/src/test/resources/org/apache/marmotta/ldclient/test/freebase/m.0nzm.sparql b/libraries/ldclient/ldclient-provider-freebase/src/test/resources/org/apache/marmotta/ldclient/test/freebase/m.0nzm.sparql
index fab3d20..e09f8f2 100644
--- a/libraries/ldclient/ldclient-provider-freebase/src/test/resources/org/apache/marmotta/ldclient/test/freebase/m.0nzm.sparql
+++ b/libraries/ldclient/ldclient-provider-freebase/src/test/resources/org/apache/marmotta/ldclient/test/freebase/m.0nzm.sparql
@@ -20,8 +20,8 @@ PREFIX ns: <http://rdf.freebase.com/ns/>
 PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
 
 ASK {
-   ns:m.0nzm> ns:rdf:type ns:business.brand ;
+   ns:m.0nzm ns:rdf:type ns:business.brand ;
         ns:common.topic.alias "ASF"@en;
-        rdfs:label: "Apache Software Foundation"@en ;
+        rdfs:label "Apache Software Foundation"@en ;
         ns:common.topic.official_website <http://www.apache.org/> .
 }

http://git-wip-us.apache.org/repos/asf/marmotta/blob/3a1dcbb7/libraries/ldclient/ldclient-provider-freebase/src/test/resources/org/apache/marmotta/ldclient/test/freebase/m.0wqhskn.sparql
----------------------------------------------------------------------
diff --git a/libraries/ldclient/ldclient-provider-freebase/src/test/resources/org/apache/marmotta/ldclient/test/freebase/m.0wqhskn.sparql b/libraries/ldclient/ldclient-provider-freebase/src/test/resources/org/apache/marmotta/ldclient/test/freebase/m.0wqhskn.sparql
index d05aac5..8afd1b8 100644
--- a/libraries/ldclient/ldclient-provider-freebase/src/test/resources/org/apache/marmotta/ldclient/test/freebase/m.0wqhskn.sparql
+++ b/libraries/ldclient/ldclient-provider-freebase/src/test/resources/org/apache/marmotta/ldclient/test/freebase/m.0wqhskn.sparql
@@ -20,8 +20,8 @@ PREFIX ns: <http://rdf.freebase.com/ns/>
 PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
 
 ASK {
-   ns:m.0wqhskn> ns:rdf:type ns:computer.software ;
-        rdfs:label: "Apache Marmotta"@en ;
+   ns:m.0wqhskn ns:rdf:type ns:computer.software ;
+        rdfs:label "Apache Marmotta"@en ;
         ns:common.topic.official_website <http://marmotta.apache.org> ;
         ns:common.topic.topic_equivalent_webpage <http://en.wikipedia.org/wiki/Apache_Marmotta> .
 }


[2/4] git commit: MARMOTTA-423: implemented manually freebase turtle pre-parsing in order to fix some errors from its wrong serialization

Posted by wi...@apache.org.
MARMOTTA-423: implemented manually freebase turtle pre-parsing in order to fix some errors from its wrong serialization


Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/8d1946c8
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/8d1946c8
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/8d1946c8

Branch: refs/heads/develop
Commit: 8d1946c84349cf0a6ed74c2afa0f5bd1cf6f00b5
Parents: 3a1dcbb
Author: Sergio Fernández <wi...@apache.org>
Authored: Mon Jan 20 17:10:02 2014 +0100
Committer: Sergio Fernández <wi...@apache.org>
Committed: Mon Jan 20 17:10:02 2014 +0100

----------------------------------------------------------------------
 .../ldclient/ldclient-provider-freebase/pom.xml |  24 ---
 .../vigsterkr/freebase/fix/FreebaseFixit.java   | 190 -------------------
 .../provider/freebase/FreebaseProvider.java     |  47 +++--
 .../test/freebase/TestFreebaseProvider.java     |   4 +-
 4 files changed, 37 insertions(+), 228 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/marmotta/blob/8d1946c8/libraries/ldclient/ldclient-provider-freebase/pom.xml
----------------------------------------------------------------------
diff --git a/libraries/ldclient/ldclient-provider-freebase/pom.xml b/libraries/ldclient/ldclient-provider-freebase/pom.xml
index b1cea46..c233928 100644
--- a/libraries/ldclient/ldclient-provider-freebase/pom.xml
+++ b/libraries/ldclient/ldclient-provider-freebase/pom.xml
@@ -29,29 +29,6 @@
     <name>LDClient Provider: Freebase RDF Access</name>
     <description>Implements patched Linked Data access to Freebase data.</description>
 
-    <build>
-        <plugins>
-            <plugin>
-                <groupId>org.codehaus.mojo</groupId>
-                <artifactId>build-helper-maven-plugin</artifactId>
-                <executions>
-                    <execution>
-                        <id>add-ext</id>
-                        <phase>generate-sources</phase>
-                        <goals>
-                            <goal>add-source</goal>
-                        </goals>
-                        <configuration>
-                            <sources>
-                                <source>src/ext/java</source>
-                            </sources>
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin>
-        </plugins>
-    </build>
-
     <dependencies>
         <dependency>
             <groupId>org.apache.marmotta</groupId>
@@ -61,7 +38,6 @@
             <groupId>org.apache.marmotta</groupId>
             <artifactId>ldclient-core</artifactId>
         </dependency>
-
         <dependency>
             <groupId>org.openrdf.sesame</groupId>
             <artifactId>sesame-rio-turtle</artifactId>

http://git-wip-us.apache.org/repos/asf/marmotta/blob/8d1946c8/libraries/ldclient/ldclient-provider-freebase/src/ext/java/com/github/vigsterkr/freebase/fix/FreebaseFixit.java
----------------------------------------------------------------------
diff --git a/libraries/ldclient/ldclient-provider-freebase/src/ext/java/com/github/vigsterkr/freebase/fix/FreebaseFixit.java b/libraries/ldclient/ldclient-provider-freebase/src/ext/java/com/github/vigsterkr/freebase/fix/FreebaseFixit.java
deleted file mode 100644
index 166ff46..0000000
--- a/libraries/ldclient/ldclient-provider-freebase/src/ext/java/com/github/vigsterkr/freebase/fix/FreebaseFixit.java
+++ /dev/null
@@ -1,190 +0,0 @@
-/**
- Copyright (c) 2014, Viktor Gal
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice, this
- list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- The views and conclusions contained in the software and documentation are those
- of the authors and should not be interpreted as representing official policies,
- either expressed or implied, of the FreeBSD Project.
- */
-
-package com.github.vigsterkr.freebase.fix;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.*;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-public class FreebaseFixit {
-
-    private static Logger log = LoggerFactory.getLogger(FreebaseFixit.class);
-
-    private final long line = 0;
-
-    /* patterns */
-    private final static String FREEBASE_ESCAPE_CHAR = Pattern.quote("$");
-
-    private final static Pattern freebaseEscape =
-            Pattern.compile(FREEBASE_ESCAPE_CHAR + "([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})");
-
-    private final static Pattern tripletPattern =
-            Pattern.compile("^(\\S+)\\s+(\\S+)\\s+(.*)$");
-
-    private final static Pattern nullChar = Pattern.compile("\\x00");
-
-    private final static Pattern URIPattern = Pattern.compile("^<(.*)>$");
-
-    private final static Pattern lePattern = Pattern.compile("<");
-    private final static Pattern gePattern = Pattern.compile(">");
-
-    private final static Pattern trailingDotPattern = Pattern.compile("\\s+\\.$");
-
-    private static String fixEscaping(String input) {
-        Matcher m = freebaseEscape.matcher(input);
-        return m.replaceAll("%$1%$2");
-    }
-
-    private static String removeNullChar(String input) {
-        Matcher m = nullChar.matcher(input);
-        return m.replaceAll("");
-    }
-
-    private static List<String> splitToTriplet(String input) {
-        Matcher m = tripletPattern.matcher(input);
-        List<String> triplet = new ArrayList<String>();
-        if (m.matches()) {
-            triplet.add(m.group(1));
-            triplet.add(m.group(2));
-            triplet.add(m.group(3));
-        }
-
-        return triplet;
-    }
-
-    private static boolean isLiteral(String s) {
-        if (s.startsWith("\""))
-            return true;
-        return false;
-    }
-
-    private static String fixURI(String uri) {
-        Matcher m = URIPattern.matcher(uri);
-        if (m.matches()) {
-            String fixedURI = lePattern.matcher(m.group(1)).replaceAll("%3C");
-            fixedURI = gePattern.matcher(fixedURI).replaceAll("%3E");
-            return String.format("<%s>", fixedURI);
-        }
-
-        return uri;
-    }
-
-    public static String fixSubject(String subj) {
-        String fixedSubject = fixEscaping(subj);
-
-        return fixedSubject;
-    }
-
-    public static String fixPredicate(String pred) {
-        String fixedPredicate = fixEscaping(pred);
-
-        return fixedPredicate;
-    }
-
-    public static String fixObject(String obj) {
-        String fixedObject = obj;
-
-        fixedObject = fixURI(fixedObject);
-
-        if (isLiteral(fixedObject)) {
-            fixedObject = removeNullChar(fixedObject);
-        }
-
-        return fixedObject;
-    }
-
-    private static String cleanObject(String obj) {
-        String cleanObj = obj.trim();
-        cleanObj = trailingDotPattern.matcher(cleanObj).replaceAll("");
-
-        return cleanObj;
-    }
-
-    public static String fixTriplet(String tripletLine) throws Exception {
-        List<String> triplet = splitToTriplet(tripletLine);
-        if (triplet.isEmpty())
-            throw new Exception("Failed to parse empty line");
-
-        String subject = triplet.get(0);
-        String predicate = triplet.get(1);
-        String object = triplet.get(2);
-
-		/* fix subject */
-        subject = fixSubject(subject);
-
-		/* fix predicate */
-        predicate = fixPredicate(predicate);
-
-		/* fix object */
-        if (!object.endsWith("."))
-            throw new Exception("Object doesn't end with dot");
-
-        object = cleanObject(object);
-        if (object.length() == 0)
-            throw new Exception("Unexpected empty object");
-
-        object = fixObject(object);
-
-        return String.format("%s %s %s .", subject, predicate, object);
-    }
-
-    public static void fix(BufferedReader br) {
-        fix(br, System.out);
-    }
-
-    public static void fix(BufferedReader br, PrintStream out) {
-        try {
-            String input;
-            while ((input = br.readLine()) != null) {
-                try {
-                    out.println(fixTriplet(input));
-                } catch (Exception e) {
-                    log.error(e.getMessage());
-                }
-            }
-        } catch (IOException io) {
-            io.printStackTrace();
-        }
-    }
-
-    public static void main(String[] args) {
-        BufferedReader br =
-                new BufferedReader(new InputStreamReader(System.in));
-
-        FreebaseFixit fbFix = new FreebaseFixit();
-        fbFix.fix(br);
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/marmotta/blob/8d1946c8/libraries/ldclient/ldclient-provider-freebase/src/main/java/org/apache/marmotta/ldclient/provider/freebase/FreebaseProvider.java
----------------------------------------------------------------------
diff --git a/libraries/ldclient/ldclient-provider-freebase/src/main/java/org/apache/marmotta/ldclient/provider/freebase/FreebaseProvider.java b/libraries/ldclient/ldclient-provider-freebase/src/main/java/org/apache/marmotta/ldclient/provider/freebase/FreebaseProvider.java
index ee82d39..ccd0159 100644
--- a/libraries/ldclient/ldclient-provider-freebase/src/main/java/org/apache/marmotta/ldclient/provider/freebase/FreebaseProvider.java
+++ b/libraries/ldclient/ldclient-provider-freebase/src/main/java/org/apache/marmotta/ldclient/provider/freebase/FreebaseProvider.java
@@ -20,7 +20,6 @@ package org.apache.marmotta.ldclient.provider.freebase;
 import com.google.common.base.Preconditions;
 
 import javolution.util.function.Predicate;
-import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.marmotta.commons.sesame.model.ModelCommons;
 import org.apache.marmotta.ldclient.api.endpoint.Endpoint;
@@ -32,7 +31,6 @@ import org.openrdf.rio.RDFFormat;
 import org.openrdf.rio.RDFParseException;
 import org.openrdf.rio.Rio;
 
-import com.github.vigsterkr.freebase.fix.FreebaseFixit;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -57,7 +55,7 @@ public class FreebaseProvider extends AbstractHttpProvider {
     public static final RDFFormat DEFAULT_RDF_FORMAT = RDFFormat.TURTLE;
     public static final String DEFAULT_ENCODING = "UTF-8";
     private static final Pattern CHARSET_PATTERN = Pattern.compile("(?i)\\bcharset=\\s*\"?([^\\s;\"]*)");
-    private static final  Pattern FREEBASE_LITERAL_PATTERN = Pattern.compile("^\\s+[a-z]+:[a-z]+(?:\\.[a-z]+)*\\s+\"(.*)\"(?:@[a-z]+)?;$");
+    private static final  Pattern FREEBASE_LITERAL_PATTERN = Pattern.compile("^\\s+([a-z]+:[a-z]+(?:\\.[a-z]+)*)\\s+\"(.*)\"(@[a-z]+)?(;|\\.)$");
 
     /**
      * Return the name of this data provider. To be used e.g. in the configuration and in log messages.
@@ -142,22 +140,49 @@ public class FreebaseProvider extends AbstractHttpProvider {
             if (m.matches()) {
                 //literal found
                 try {
-                    String literal = m.group(2);
-                    log.info("Original literal: {}", literal);
-                    String fixed = FreebaseFixit.fixObject(literal);
-                    log.info("Fixed literal: {}", literal);
-                    sb.append("    " + m.group(1) + "    \"" + fixed + "\"" + m.group(3) + " ; \n");
+                    final String literal = m.group(2);
+                    final String fixed = fixLiteral(literal);
+                    //log.debug("literal: --{}--{}", literal, fixed);
+                    String triple = m.group(1) + "    \"" + fixed + "\"";
+                    if (m.group(3) != null) {
+                        triple += m.group(3);
+                    }
+                    log.debug("new triple: {}", triple);
+                    sb.append("    " + triple + m.group(4));
+                    sb.append(("\n"));
                 } catch (Exception e) {
                     log.error("Error fixing line, so triple ignored: {}", e.getMessage());
-                    log.debug("error on line: {}", line);
+                    log.error("error on line: {}", line);
+                    if (line.endsWith(".")) {
+                        sb.append((".\n"));
+                    }
                 }
             } else {
                 //not a triple with a literal as object, so pass-through
                 sb.append(line);
+                sb.append(("\n"));
             }
-            sb.append(("\n"));
         }
         return new ByteArrayInputStream(sb.toString().getBytes());
     }
 
-}
+    private String fixLiteral(String literal) throws UnsupportedEncodingException {
+
+        //non-escaped quotes
+        literal = literal.replaceAll("\"", "\\\"");
+
+        //wrong encoding
+        if (literal.contains("\\x")) {
+            //TODO: find a way to re-code properly the literal
+            //http://www.ic.unicamp.br/~stolfi/EXPORT/www/ISO-8859-1-Encoding.html
+            literal = literal.replaceAll("\\\\xe1", "á");
+            literal = literal.replaceAll("\\\\xe9", "é");
+            literal = literal.replaceAll("\\\\xed", "í");
+            literal = literal.replaceAll("\\\\xf3", "ó");
+            literal = literal.replaceAll("\\\\xfa", "ú");
+        }
+
+        return literal;
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/marmotta/blob/8d1946c8/libraries/ldclient/ldclient-provider-freebase/src/test/java/org/apache/marmotta/ldclient/test/freebase/TestFreebaseProvider.java
----------------------------------------------------------------------
diff --git a/libraries/ldclient/ldclient-provider-freebase/src/test/java/org/apache/marmotta/ldclient/test/freebase/TestFreebaseProvider.java b/libraries/ldclient/ldclient-provider-freebase/src/test/java/org/apache/marmotta/ldclient/test/freebase/TestFreebaseProvider.java
index 9a339c7..46fc5ae 100644
--- a/libraries/ldclient/ldclient-provider-freebase/src/test/java/org/apache/marmotta/ldclient/test/freebase/TestFreebaseProvider.java
+++ b/libraries/ldclient/ldclient-provider-freebase/src/test/java/org/apache/marmotta/ldclient/test/freebase/TestFreebaseProvider.java
@@ -23,14 +23,12 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * Test if the FreebaseProvider is working properly.
+ * Test the Freebase LDClient Provider.
  *
  * @author Sergio Fernández
  */
 public class TestFreebaseProvider extends ProviderTestBase {
 
-    private static Logger log = LoggerFactory.getLogger(TestFreebaseProvider.class);
-
     private static final String ASF = "http://rdf.freebase.com/ns/m.0nzm";
     private static final String MARMOTTA = "http://rdf.freebase.com/ns/m.0wqhskn";
     private static final String SERGIO = "http://rdf.freebase.com/ns/m.07zqbwz";


[3/4] git commit: MARMOTTA-423: some more small fixes to what a fucking serialization

Posted by wi...@apache.org.
MARMOTTA-423: some more small fixes to what a fucking serialization


Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/68dcda20
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/68dcda20
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/68dcda20

Branch: refs/heads/develop
Commit: 68dcda20d8e6a1c116b5463c5c1f8a3b489cad1e
Parents: 8d1946c
Author: Sergio Fernández <wi...@apache.org>
Authored: Mon Jan 20 17:57:02 2014 +0100
Committer: Sergio Fernández <wi...@apache.org>
Committed: Mon Jan 20 17:57:02 2014 +0100

----------------------------------------------------------------------
 .../provider/freebase/FreebaseProvider.java     | 47 +++++++++++++++-----
 1 file changed, 36 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/marmotta/blob/68dcda20/libraries/ldclient/ldclient-provider-freebase/src/main/java/org/apache/marmotta/ldclient/provider/freebase/FreebaseProvider.java
----------------------------------------------------------------------
diff --git a/libraries/ldclient/ldclient-provider-freebase/src/main/java/org/apache/marmotta/ldclient/provider/freebase/FreebaseProvider.java b/libraries/ldclient/ldclient-provider-freebase/src/main/java/org/apache/marmotta/ldclient/provider/freebase/FreebaseProvider.java
index ccd0159..97ea6c7 100644
--- a/libraries/ldclient/ldclient-provider-freebase/src/main/java/org/apache/marmotta/ldclient/provider/freebase/FreebaseProvider.java
+++ b/libraries/ldclient/ldclient-provider-freebase/src/main/java/org/apache/marmotta/ldclient/provider/freebase/FreebaseProvider.java
@@ -20,6 +20,7 @@ package org.apache.marmotta.ldclient.provider.freebase;
 import com.google.common.base.Preconditions;
 
 import javolution.util.function.Predicate;
+import org.apache.commons.lang3.StringEscapeUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.marmotta.commons.sesame.model.ModelCommons;
 import org.apache.marmotta.ldclient.api.endpoint.Endpoint;
@@ -35,6 +36,8 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.*;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.Collections;
 import java.util.List;
 import java.util.regex.Matcher;
@@ -56,6 +59,7 @@ public class FreebaseProvider extends AbstractHttpProvider {
     public static final String DEFAULT_ENCODING = "UTF-8";
     private static final Pattern CHARSET_PATTERN = Pattern.compile("(?i)\\bcharset=\\s*\"?([^\\s;\"]*)");
     private static final  Pattern FREEBASE_LITERAL_PATTERN = Pattern.compile("^\\s+([a-z]+:[a-z]+(?:\\.[a-z]+)*)\\s+\"(.*)\"(@[a-z]+)?(;|\\.)$");
+    private static final  Pattern FREEBASE_RESOURCE_PATTERN = Pattern.compile("^\\s+([a-z]+:[a-z]+(?:\\.[a-z]+)*)\\s+([a-z]+:.*(\\..*))(;|\\.)$");
 
     /**
      * Return the name of this data provider. To be used e.g. in the configuration and in log messages.
@@ -126,7 +130,8 @@ public class FreebaseProvider extends AbstractHttpProvider {
     }
 
     /**
-     * Fixes Freebase deficiencies on Turtle serialization
+     * Fixes Freebase deficiencies on Turtle serialization, doing
+     * some dirty things they may be semantically wrong.
      *
      * @param is stream with the raw data
      * @return fixed stream
@@ -136,19 +141,20 @@ public class FreebaseProvider extends AbstractHttpProvider {
         StringBuffer sb = new StringBuffer();
         String line;
         while ((line = br.readLine()) != null) {
-            Matcher m = FREEBASE_LITERAL_PATTERN.matcher(line);
-            if (m.matches()) {
+            Matcher literalMatcher = FREEBASE_LITERAL_PATTERN.matcher(line);
+            Matcher resourceMatcher = FREEBASE_RESOURCE_PATTERN.matcher(line);
+            if (literalMatcher.matches()) {
                 //literal found
                 try {
-                    final String literal = m.group(2);
+                    final String literal = literalMatcher.group(2);
                     final String fixed = fixLiteral(literal);
                     //log.debug("literal: --{}--{}", literal, fixed);
-                    String triple = m.group(1) + "    \"" + fixed + "\"";
-                    if (m.group(3) != null) {
-                        triple += m.group(3);
+                    String triple = literalMatcher.group(1) + "    \"" + fixed + "\"";
+                    if (literalMatcher.group(3) != null) {
+                        triple += literalMatcher.group(3);
                     }
                     log.debug("new triple: {}", triple);
-                    sb.append("    " + triple + m.group(4));
+                    sb.append("    " + triple + literalMatcher.group(4));
                     sb.append(("\n"));
                 } catch (Exception e) {
                     log.error("Error fixing line, so triple ignored: {}", e.getMessage());
@@ -157,8 +163,19 @@ public class FreebaseProvider extends AbstractHttpProvider {
                         sb.append((".\n"));
                     }
                 }
+            } else if (resourceMatcher.matches()) {
+                if (resourceMatcher.group(2).contains("$")) {
+                    //awaiting for https://openrdf.atlassian.net/browse/SES-2000
+                    if (line.endsWith(".")) {
+                        sb.append((".\n"));
+                    }
+                } else {
+                    //fine, so pass-through
+                    sb.append(line);
+                    sb.append(("\n"));
+                }
             } else {
-                //not a triple with a literal as object, so pass-through
+                //something else, so pass-through
                 sb.append(line);
                 sb.append(("\n"));
             }
@@ -169,17 +186,25 @@ public class FreebaseProvider extends AbstractHttpProvider {
     private String fixLiteral(String literal) throws UnsupportedEncodingException {
 
         //non-escaped quotes
-        literal = literal.replaceAll("\"", "\\\"");
+        literal = literal.replaceAll("\"", "'");
 
-        //wrong encoding
+        //wrong charset
         if (literal.contains("\\x")) {
             //TODO: find a way to re-code properly the literal
             //http://www.ic.unicamp.br/~stolfi/EXPORT/www/ISO-8859-1-Encoding.html
             literal = literal.replaceAll("\\\\xe1", "á");
+            literal = literal.replaceAll("\\\\xe3", "ã");
+            literal = literal.replaceAll("\\\\xe7", "ç");
             literal = literal.replaceAll("\\\\xe9", "é");
             literal = literal.replaceAll("\\\\xed", "í");
             literal = literal.replaceAll("\\\\xf3", "ó");
             literal = literal.replaceAll("\\\\xfa", "ú");
+            literal = literal.replaceAll("\\\\x", ""); //FIXME: wrong, wrong, wrong!
+        }
+
+        //wrong unicode encoding
+        if (literal.contains("\\u")) {
+            literal = StringEscapeUtils.unescapeJava(literal);
         }
 
         return literal;


[4/4] git commit: Merge branch 'develop' of https://git-wip-us.apache.org/repos/asf/marmotta into develop

Posted by wi...@apache.org.
Merge branch 'develop' of https://git-wip-us.apache.org/repos/asf/marmotta into develop


Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/4001e928
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/4001e928
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/4001e928

Branch: refs/heads/develop
Commit: 4001e928edfa36918e9790c7ebed082b1cac936d
Parents: 68dcda2 dc95084
Author: Sergio Fernández <wi...@apache.org>
Authored: Mon Jan 20 17:57:07 2014 +0100
Committer: Sergio Fernández <wi...@apache.org>
Committed: Mon Jan 20 17:57:07 2014 +0100

----------------------------------------------------------------------
 launchers/marmotta-webapp/pom.xml               |  29 ++++
 .../persistence/KiWiSparqlConnection.java       |  12 --
 .../backends/marmotta-backend-titan/pom.xml     | 173 +++++++++++++++++++
 .../backend/titan/TitanLoggingModule.java       |  81 +++++++++
 .../backend/titan/TitanStoreProvider.java       | 122 +++++++++++++
 .../src/main/resources/META-INF/beans.xml       |  28 +++
 .../main/resources/config-defaults.properties   |  57 ++++++
 .../resources/config-descriptions.properties    | 154 +++++++++++++++++
 .../src/main/resources/kiwi-module.properties   |  38 ++++
 .../src/main/resources/web/admin/about.html     |  36 ++++
 .../main/resources/web/admin/configuration.html |  54 ++++++
 platform/backends/pom.xml                       |   1 +
 12 files changed, 773 insertions(+), 12 deletions(-)
----------------------------------------------------------------------