Re: How to solve RiotNotFoundException ?
Hi ! I made as I said a little class which solve the errors from the Freebase Turtle. I put this class in attachment, it's certainly not perfect but it seems working. If you have any comments on it I will be happy to listen them. I will send an email too on the Freebase mailing list to list the three errors that I met. Best. Julien. 2014-02-13 17:15 GMT+01:00 Julien Plu julien@redaction-developpez.com: Ok, I will try to create a little class tool which try to do this job, and send a mail to the mailing list to warm them of these issues. Best. Julien. 2014-02-13 15:38 GMT+01:00 Chris_Dollin ehog.he...@gmail.com: On Thursday, February 13, 2014 01:42:33 PM Andy Seaborne wrote: On 13/02/14 12:59, Julien Plu wrote: 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 ? If you look in the Turtle spec, you'll see that (RDF 1.1) lots of characters are legal in prefix names though they may need to be escaped. Check it out. Your higher level decision is whether to correct the intention of the URIs or whether to keep the character published. Feeding all this back to the Freebase people would help. They could fix the data. It's their custom key-escape format http://wiki.freebase.com/wiki/Weblink Quite why it's escaped into their Turtle I don't know. Chris
Re: How to solve RiotNotFoundException ?
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. Best. Julien. 2014-02-13 10:41 GMT+01:00 Andy Seaborne a...@apache.org: 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 a...@apache.org: 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 rve...@dotnetrdf.org: 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@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 :
Re: How to solve RiotNotFoundException ?
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 a...@apache.org: 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 a...@apache.org: 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 rve...@dotnetrdf.org: 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@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
Re: How to solve RiotNotFoundException ?
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 a...@apache.org: 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 a...@apache.org: 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 a...@apache.org: 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 rve...@dotnetrdf.org: 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
Re: How to solve RiotNotFoundException ?
On Thursday, February 13, 2014 01:42:33 PM Andy Seaborne wrote: On 13/02/14 12:59, Julien Plu wrote: 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 ? If you look in the Turtle spec, you'll see that (RDF 1.1) lots of characters are legal in prefix names though they may need to be escaped. Check it out. Your higher level decision is whether to correct the intention of the URIs or whether to keep the character published. Feeding all this back to the Freebase people would help. They could fix the data. It's their custom key-escape format http://wiki.freebase.com/wiki/Weblink Quite why it's escaped into their Turtle I don't know. Chris
Re: How to solve RiotNotFoundException ?
Ok, I will try to create a little class tool which try to do this job, and send a mail to the mailing list to warm them of these issues. Best. Julien. 2014-02-13 15:38 GMT+01:00 Chris_Dollin ehog.he...@gmail.com: On Thursday, February 13, 2014 01:42:33 PM Andy Seaborne wrote: On 13/02/14 12:59, Julien Plu wrote: 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 ? If you look in the Turtle spec, you'll see that (RDF 1.1) lots of characters are legal in prefix names though they may need to be escaped. Check it out. Your higher level decision is whether to correct the intention of the URIs or whether to keep the character published. Feeding all this back to the Freebase people would help. They could fix the data. It's their custom key-escape format http://wiki.freebase.com/wiki/Weblink Quite why it's escaped into their Turtle I don't know. Chris
How to solve RiotNotFoundException ?
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.
Re: How to solve RiotNotFoundException ?
Oops my bad I forgot to convert my String in InputStream :-( Best. Julien. 2014-02-12 13:28 GMT+01:00 Julien Plu julien@redaction-developpez.com: 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.
Re: How to solve RiotNotFoundException ?
On Wednesday, February 12, 2014 01:28:29 PM Julien Plu 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 ? The first argument to model.read is a filename or URL, but you've handed it the complete contents of whatever's given by serviceURL.OpenStream, which looks like Turtle to me. Looks to me that all of your code above could be replaced by Model model = RDFDataMgr.loadModel(https://www.googleapis.com/freebase/v1/rdf/m/020c55;); Chris -- Possibly you're not recalling some of his previous plans. Zoe, /Firefly/ Epimorphics Ltd, http://www.epimorphics.com Registered address: Court Lodge, 105 High Street, Portishead, Bristol BS20 6PT Epimorphics Ltd. is a limited company registered in England (number 7016688)
Re: How to solve RiotNotFoundException ?
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@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.
Re: How to solve RiotNotFoundException ?
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. Julien. 2014-02-12 14:06 GMT+01:00 Rob Vesse rve...@dotnetrdf.org: 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@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.
Re: How to solve RiotNotFoundException ?
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 rve...@dotnetrdf.org: 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@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.