Ok I found, it was the " characters. But now there is another bad syntax which is for example :
ns:type.object.key ns:authority.nndb.854$002F000160374; so problem come from the "$002F" which means certainly "/", by what is-it possible to replace this ? Have I to recreate all the URI myself ? Thanks. 2014-02-13 12:23 GMT+01:00 Andy Seaborne <[email protected]>: > On 13/02/14 10:29, Julien Plu wrote: > >> Thanks for the Java hints ! >> >> The line which goes wrong is : >> >> ns:common.topic.description "\u05e0\u05e2\u05de\u05d9 >> \u05de\u05dc\u05d0\u05e0\u05d9 \u05d4\u05d0\u05e8\u05d9\u05e1 >> \u05d4\u05d9\u05d0 \u05e9\u05d7\u05e7\u05e0\u05d9\u05ea >> \u05e7\u05d5\u05dc\u05e0\u05d5\u05e2 \u05d0\u05e0\u05d2\u05dc\ >> u05d9\u05d4, >> \u05de\u05d5\u05db\u05e8\u05ea \u05d1\u05d6\u05db\u05d5\u05ea >> \u05ea\u05e4\u05e7\u05d9\u05d3\u05d4 \u05db\u05d8\u05d9\u05d4 >> \u05d3\u05d0\u05dc\u05de\u05d4 \u05d1\u05e1\u05d3\u05e8\u05ea >> \u05e1\u05e8\u05d8\u05d9 "\[[u]]05e9\u05d5\u05d3\u05d3\u05d9 >> \u05d4\u05e7\u05d0\u05e8\u05d9\u05d1\u05d9\u05d9\u05dd"."@iw; >> >> I highlighted in blue surrounded by two brackets the character which throw >> the exception. >> > > Step 1: Decide what the problem is. > > If you don't understand the syntax error, take the output and chop it down > to a simple test case. > > Step 2: Fix it! > > Having found out why the syntax is broken, add code to fix it. > > Andy > > > >> Best. >> >> Julien. >> >> >> 2014-02-13 10:41 GMT+01:00 Andy Seaborne <[email protected]>: >> >> On 13/02/14 09:10, Julien Plu wrote: >>> >>> I changed a bit my code to add your advice but I still have an error : >>>> >>>> org.apache.jena.riot.RiotException: [line: 39, col: 467] Unknown char: >>>> \(92;0x005C) >>>> >>>> >>> Problem with the conversion. >>> >>> Print out the converted string to see what the problem is. >>> >>> >>> >>> Here the new code : >>>> >>>> try { >>>> URL serviceURL = new URL(" >>>> https://www.googleapis.com/freebase/v1/rdf/m/020c55"); >>>> URLConnection connection = serviceURL.openConnection(); >>>> Model model = ModelFactory.createDefaultModel(); >>>> BufferedReader bf = new BufferedReader(new >>>> InputStreamReader(connection.getInputStream())); >>>> String readline; >>>> StringBuilder sb = new StringBuilder(); >>>> while ((readline = bf.readLine()) != null) { >>>> sb.append(readline.replaceAll("\\\\x", "\\\\u00")+"\n"); >>>> } >>>> InputStream in = new ByteArrayInputStream(sb. >>>> toString().getBytes()); >>>> >>>> >>> BAD >>> >>> Never use getBytes() for web data. >>> >>> 1/ Use a StringReader >>> 2/ If you must convert to bytes, set the charset to be "UTF-8" (or >>> ideally >>> the charset for the ressponse). >>> >>> >>> model.read(in, null, "TTL"); >>> >>>> } catch (Exception ex) { >>>> ex.printStackTrace(); >>>> } >>>> >>>> Best >>>> >>>> Julien. >>>> >>>> >>>> 2014-02-12 19:58 GMT+01:00 Andy Seaborne <[email protected]>: >>>> >>>> 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" <julien.plu@redaction- >>>>>>> developpez.com >>>>>>> >>>>>>>> >>>>>>>> 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. >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>> >>>>> >>>> >>> >> >
