On 12/02/14 13:21, Julien Plu wrote:
Yes I saw my error to lately sorry for disturbing you for nothing :-(

By the way I can't pass immediately the URL to the model because the Turtle
provided by this URI (and all the others from Freebase) have unicode
characters encoded with "\x" so it's not valid Turtle, it's why I try to
translate (or convert) these characher in "\u".

But my method doesn't works, any idea of how to do this in Java ?

Best I can see is to get as string, fixup in Java (string replace), then use a StringReader. It's not too big.

At a wild untested guess, replace all \x with \u00.

You need to tell it the syntax is "TTL" but you'd need to do that anyway because the HTTP response is "Content-Type: text/plain; charset=UTF-8"

  HTTP/1.1 200 OK
  Expires: Wed, 12 Feb 2014 18:50:21 GMT
  Date: Wed, 12 Feb 2014 18:50:21 GMT
  Cache-Control: private, max-age=0, must-revalidate, no-transform
  ETag: "1CZZiDfFArqsKpzUgFQB2V9yilI/MW2d6bfo-oO8n5ovC7d5nFY2_AQ"
  Content-Type: text/plain; charset=UTF-8
  X-Content-Type-Options: nosniff
  X-Frame-Options: SAMEORIGIN
  X-XSS-Protection: 1; mode=block
  Content-Length: 32404
  Server: GSE
  Alternate-Protocol: 443:quic

        Andy


Best.

Julien.


2014-02-12 14:06 GMT+01:00 Rob Vesse <[email protected]>:

You are trying to read from the downloaded contents of the file directly
which is not going to work.  The model.read() API takes in a name of a
file/URI to read or it takes in an InputStream.

Simply pass your input stream directly to the read() call, or even simpler
pass your URI to the read() call and let Jena handle the HTTP request for
you.

Rob

On 12/02/2014 12:28, "Julien Plu" <[email protected]>
wrote:

Hi,

In getting the Turtle RDF from this URI :
https://www.googleapis.com/freebase/v1/rdf/m/020c55

A RiotNotFoundException is thrown :

org.apache.jena.riot.RiotNotFoundException: Not found: @prefix key: <
http://rdf.freebase.com/key/>.
@prefix ns: <http://rdf.freebase.com/ns/>.
@prefix owl: <http://www.w3.org/2002/07/owl#>.
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
.....
.....
at org.apache.jena.riot.RDFDataMgr.open(RDFDataMgr.java:831)
        at org.apache.jena.riot.RDFDataMgr.open(RDFDataMgr.java:813)
        at org.apache.jena.riot.RDFDataMgr.parse(RDFDataMgr.java:684)
        at org.apache.jena.riot.RDFDataMgr.read(RDFDataMgr.java:208)
        at org.apache.jena.riot.RDFDataMgr.read(RDFDataMgr.java:181)
        at org.apache.jena.riot.RDFDataMgr.read(RDFDataMgr.java:119)
        at org.apache.jena.riot.RDFDataMgr.read(RDFDataMgr.java:110)
        at
org.apache.jena.riot.adapters.RDFReaderRIOT.read(RDFReaderRIOT.java:77)
        at com.hp.hpl.jena.rdf.model.impl.ModelCom.read(ModelCom.java:259)
        at freebase.Test.main(Test.java:61)

Here my code :

try {
      URL serviceURL = new URL("
https://www.googleapis.com/freebase/v1/rdf/m/020c55";);
      Model model = ModelFactory.createDefaultModel();
      BufferedReader in = new BufferedReader(new
InputStreamReader(serviceURL.openStream(), "UTF-8"));
      String readline;
      StringBuilder sb = new StringBuilder();
      while ((readline = in.readLine()) != null) {
          sb.append(readline+"\n");
      }
      model.read(sb.toString(), "TTL");
    } catch (Exception ex) {
      ex.printStackTrace();
    }

Any solution to solve this ?

Thanks in advance.

Best.

Julien.







Reply via email to