Skip to content

Instantly share code, notes, and snippets.

@pepperbob
Last active December 26, 2015 12:49
Show Gist options
  • Select an option

  • Save pepperbob/7153974 to your computer and use it in GitHub Desktop.

Select an option

Save pepperbob/7153974 to your computer and use it in GitHub Desktop.
This solution uses Sesame-Rio to parse the RDF into single Statements.
private void loadRdfXml(InputStream is, UID context) {
try {
UID currentContext = context != null ? context : defaultGraph;
RDFParser rioParser = Rio.createParser(RDFFormat.RDFXML);
StatementCollector handler = new StatementCollector();
rioParser.setRDFHandler(handler);
rioParser.parse(is, currentContext.getId());
SesameDialect dialect = new SesameDialect(ValueFactoryImpl.getInstance());
Collection<STMT> stmts = new ArrayList<STMT>();
for(org.openrdf.model.Statement s : handler.getStatements()) {
ID subject = dialect.getID(s.getSubject());
UID predicate = dialect.getUID(s.getPredicate());
NODE object = dialect.getNODE(s.getObject());
stmts.add(new STMT(subject, predicate, object, currentContext));
if(stmts.size() > 5000) {
update(null, stmts);
stmts.clear();
}
}
update(null, stmts);
} catch (RDFParseException e) {
throw new RepositoryException(e);
} catch (RDFHandlerException e) {
throw new RepositoryException(e);
} catch (IOException e) {
throw new RepositoryException(e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment