use of org.eclipse.rdf4j.rio.RDFParseException in project opentheso by miledrousset.
the class ReadRdfFileTest method test4.
@Test
public void test4() {
// read the file 'example-data-artists.ttl' as an InputStream.
InputStream is = null;
try {
is = new FileInputStream("test_unesco - Copie.rdf");
} catch (FileNotFoundException ex) {
Logger.getLogger(ReadRdfFileTest.class.getName()).log(Level.SEVERE, null, ex);
}
Model model = null;
try {
model = Rio.parse(is, "", RDFFormat.RDFXML);
} catch (IOException ex) {
Logger.getLogger(ReadRdfFileTest.class.getName()).log(Level.SEVERE, null, ex);
} catch (RDFParseException ex) {
Logger.getLogger(ReadRdfFileTest.class.getName()).log(Level.SEVERE, null, ex);
} catch (UnsupportedRDFormatException ex) {
Logger.getLogger(ReadRdfFileTest.class.getName()).log(Level.SEVERE, null, ex);
}
for (Statement statement : model) {
System.out.println(statement);
}
System.out.println("\n----------------");
for (Statement st : model) {
// we want to see the object values of each statement
Value value = st.getObject();
IRI property = st.getPredicate();
if (property.getLocalName().equals("type"))
System.out.println("\n......\n");
if (property.getLocalName().equals("notation")) {
Literal title = (Literal) value;
System.out.println("notation: " + title.getLabel());
} else if (property.getLocalName().equals("lat")) {
Literal title = (Literal) value;
System.out.println("latitude : " + title.getLabel());
} else if (property.getLocalName().equals("long")) {
Literal title = (Literal) value;
System.out.println("longitude : " + title.getLabel());
} else if (property.getLocalName().equals("created")) {
Literal title = (Literal) value;
System.out.println("created : " + title.getLabel());
} else if (property.getLocalName().equals("modified")) {
Literal title = (Literal) value;
System.out.println("modified : " + title.getLabel());
} else if (value instanceof Literal) {
String pref = "";
if (property.getLocalName().equals("prefLabel"))
pref = " // pref label";
Literal title = (Literal) value;
System.out.println("language: " + title.getLanguage().orElse("unknown"));
System.out.println(" title: " + title.getLabel() + pref);
} else {
System.out.println(" **** " + value + " //// " + property.getLocalName());
if (property.getLocalName().equals("type")) {
System.out.println(" URL: " + st.getSubject());
}
}
}
Rio.write(model, System.out, RDFFormat.RDFXML);
}
use of org.eclipse.rdf4j.rio.RDFParseException in project graal by graphik-team.
the class Producer method run.
@Override
public void run() {
org.eclipse.rdf4j.rio.RDFParser rdfParser = Rio.createParser(format);
if (this.config != null) {
rdfParser.setParserConfig(config);
}
rdfParser.setRDFHandler(new RDFListener(buffer));
try {
rdfParser.parse(this.reader, "");
} catch (RDFParseException e) {
throw new ParseError("An error occured while parsing", e);
} catch (RDFHandlerException e) {
throw new ParseError("An error occured while parsing", e);
} catch (IOException e) {
throw new ParseError("An error occured while parsing", e);
}
buffer.close();
try {
this.reader.close();
} catch (IOException e) {
}
}
use of org.eclipse.rdf4j.rio.RDFParseException in project rdf4j by eclipse.
the class TestTurtleParser method testParseBooleanLiteralWhitespaceSemicolumn.
@Test
public void testParseBooleanLiteralWhitespaceSemicolumn() throws Exception {
String data = "<urn:a> <urn:b> true ; <urn:c> false .";
Reader r = new StringReader(data);
try {
parser.parse(r, baseURI);
assertTrue(statementCollector.getStatements().size() == 2);
} catch (RDFParseException e) {
fail("parse error on correct data: " + e.getMessage());
}
}
use of org.eclipse.rdf4j.rio.RDFParseException in project rdf4j by eclipse.
the class TestTurtleParser method testLineNumberReporting.
@Test
public void testLineNumberReporting() throws Exception {
InputStream in = this.getClass().getResourceAsStream("/test-newlines.ttl");
try {
parser.parse(in, baseURI);
fail("expected to fail parsing input file");
} catch (RDFParseException e) {
// expected
assertFalse(errorCollector.getFatalErrors().isEmpty());
final String error = errorCollector.getFatalErrors().get(0);
// expected to fail at line 9.
assertTrue(error.contains("(9,"));
assertEquals(9, locationListener.getLineNo());
assertEquals(-1, locationListener.getColumnNo());
}
}
use of org.eclipse.rdf4j.rio.RDFParseException in project rdf4j by eclipse.
the class TestTurtleParser method testParseBooleanLiteralComma.
@Test
public void testParseBooleanLiteralComma() throws Exception {
String data = "<urn:a> <urn:b> true, false .";
Reader r = new StringReader(data);
try {
parser.parse(r, baseURI);
assertTrue(statementCollector.getStatements().size() == 2);
} catch (RDFParseException e) {
fail("parse error on correct data: " + e.getMessage());
}
}
Aggregations