Last active
December 26, 2015 12:49
-
-
Save pepperbob/7153974 to your computer and use it in GitHub Desktop.
This solution uses Sesame-Rio to parse the RDF into single Statements.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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