public static Map getPropertyMappings(String infileurl, boolean recommend, Map mappings) throws IOException { if (mappings == null) mappings = new HashMap(); else mappings = new HashMap(mappings); GrabMappingsHandler handler = new GrabMappingsHandler(mappings, recommend); if (infileurl.endsWith(".rdf")) parseRDFXML(handler, infileurl); else if (infileurl.endsWith(".n3")) parseN3(handler, infileurl); else if (infileurl.endsWith(".ntriple")) parseN3(handler, infileurl); else parseRDFXML(handler, infileurl); return handler.getMappings(); }
private static void parseN3(GrabMappingsHandler handler, String infileurl) { Model model = ModelFactory.createDefaultModel(); model.read(infileurl, "N3"); AResourceImpl sub = new AResourceImpl(); AResourceImpl pred = new AResourceImpl(); AResourceImpl objres = new AResourceImpl(); ALiteralImpl objlit = new ALiteralImpl(); StmtIterator it = model.listStatements(); while (it.hasNext()) { Statement stmt = it.nextStatement(); RDFNode object = stmt.getObject(); sub.setResource(stmt.getSubject()); pred.setResource(stmt.getPredicate()); if (object instanceof Literal) { objlit.setLiteral((Literal) object); handler.statement(sub, pred, objlit); } else { objres.setResource((Resource) object); handler.statement(sub, pred, objres); } } }