public static Model createModelFromResourceFile(String fileName, RDFFormat format) throws RDFParseException, IOException, RDFHandlerException { RDFParser rdfParser = Rio.createParser(format); Model model = new TreeModel(); StatementCollector collector = new StatementCollector(model); rdfParser.setRDFHandler(collector); rdfParser.parse(Rsine.class.getResourceAsStream(fileName), ""); return model; }
public static void parse(String fileNameOrURL, RDFParser parser, Model model) throws IOException, SAXException, MalformedURLException, ModelException { URL url = new URL(normalizeURI(fileNameOrURL)); // maybe this model is loaded as schema... // Model model = factory.registry().get(url.toString()); // if(model != null) // return model; // Prepare input source model.setSourceURI(url.toString()); InputStream in = url.openStream(); InputSource source = new InputSource(in); source.setSystemId(url.toString()); parser.parse(source, new ModelConsumer(model)); in.close(); }