private Model loadModel(String fileName) throws Exception { URL modelURL = this.getClass().getResource(TESTCASES_DIR + fileName); assertNotNull("Test file not found: " + fileName, modelURL); Model model = createEmptyModel(); Optional<RDFFormat> rdfFormat = Rio.getParserFormatForFileName(fileName); assertTrue("Unable to determine RDF format for file: " + fileName, rdfFormat.isPresent()); RDFParser parser = Rio.createParser(rdfFormat.get()); parser.setDatatypeHandling(DatatypeHandling.IGNORE); parser.setPreserveBNodeIDs(true); parser.setRDFHandler(new StatementCollector(model)); InputStream in = modelURL.openStream(); try { parser.parse(in, modelURL.toString()); return model; } finally { in.close(); } }
/** * Checks if the stream contains <i>Turtle</i> triple patterns. * * @param is input stream to be verified. * @return <code>true</code> if <i>Turtle</i> patterns are detected, <code>false</code> otherwise. * @throws IOException if there is an error checking the {@link java.io.InputStream} */ public static boolean checkTurtleFormat(InputStream is) throws IOException { String sample = extractDataSample(is, '.'); RDFParser turtleParser = Rio.createParser(RDFFormat.TURTLE); turtleParser.setDatatypeHandling(RDFParser.DatatypeHandling.VERIFY); turtleParser.setStopAtFirstError(true); turtleParser.setVerifyData(true); ByteArrayInputStream bais = new ByteArrayInputStream( sample.getBytes() ); try { turtleParser.parse(bais, ""); return true; } catch (Exception e) { return false; } }
final ExtractionResult extractionResult ) { parser.setDatatypeHandling( verifyDataType ? RDFParser.DatatypeHandling.VERIFY : RDFParser.DatatypeHandling.IGNORE );
rdfParser.setDatatypeHandling(RDFParser.DatatypeHandling.IGNORE);