public void generate(final KAFDocument document, @Nullable final Iterable<Integer> sentenceIDs, final Collection<? super Statement> output) { final RDFHandler handler = RDFHandlers.wrap(output); try { generate(document, sentenceIDs, handler); } catch (final Throwable ex) { throw new RuntimeException("Unexpected exception (!)", ex); } }
source.emit(RDFHandlers.ignoreMethods(writer, RDFHandlers.METHOD_START_RDF | RDFHandlers.METHOD_END_RDF } else { java.nio.file.Files.createDirectories(output.getParent()); source.emit(RDFHandlers.write(null, 1, output .toAbsolutePath().toString()), 1);
@Override public void reduce(final Value key, final Statement[] stmts, final RDFHandler handler) throws RDFHandlerException { final RDFHandler session = RuleProcessor.this.engine.newSession(RDFHandlers .ignoreMethods(handler, RDFHandlers.METHOD_START_RDF | RDFHandlers.METHOD_END_RDF | RDFHandlers.METHOD_CLOSE)); try { session.startRDF(); for (final Statement stmt : stmts) { session.handleStatement(stmt); } session.endRDF(); } finally { IO.closeQuietly(session); } }
try { Files.createParentDirs(this.outputFile); writer = RDFHandlers.write(null, 1, Runner.this.outputFile.getAbsolutePath()); writer.startRDF(); } catch (final Throwable ex) {
@Override public void map(final QuadModel model) throws Exception { final List<Statement> statements = new ArrayList<>(); final RDFSource source = RDFSources.wrap(model); final RDFHandler handler = RDFHandlers.wrap(statements); processor.wrap(source).emit(handler, 1); model.addAll(statements); }
public RuleProcessor(final Ruleset ruleset, @Nullable final Mapper mapper, final boolean dropBNodeTypes, @Nullable final RDFSource staticData, final boolean emitStatic, @Nullable final URI staticContext) { // Setup the handler receiving closure of static data, if any. final List<Statement> staticClosure = new ArrayList<>(); RDFHandler staticSink = RDFHandlers.NIL; if (staticData != null && emitStatic) { staticSink = RDFHandlers.wrap(staticClosure); if (staticContext != null) { final URI uri = staticContext.equals(SESAME.NIL) ? null : staticContext; staticSink = new AbstractRDFHandlerWrapper(staticSink) { @Override public void handleStatement(final Statement stmt) throws RDFHandlerException { super.handleStatement(Statements.VALUE_FACTORY.createStatement( stmt.getSubject(), stmt.getPredicate(), stmt.getObject(), uri)); } }; } } // Build the dynamic rule engine by closing static data and proprocessing rules final RuleEngine engine = preprocess(ruleset, staticData, staticSink); // Setup object this.engine = engine; this.mapper = mapper; this.staticClosure = RDFSources.wrap(staticClosure); this.dropBNodeTypes = dropBNodeTypes; }
private Engine(final Dictionary dictionary, final KieContainer container, final List<Quad> axioms, final List<Expression> expressions, final List<String> ruleIDs) { this.dictionary = dictionary; this.container = container; this.axioms = new ArrayList<>(); this.expressions = expressions; this.ruleIDs = ruleIDs; if (!axioms.isEmpty()) { final List<Statement> statements = new ArrayList<>(); try (Handler handler = new Handler(RDFHandlers.wrap(statements), null)) { handler.startRDF(); for (final Quad axiom : axioms) { handler.handleStatement(axiom.decode(this.dictionary)); } handler.endRDF(); for (final Statement statement : statements) { this.axioms.add(Quad.encode(dictionary, statement)); } } catch (final Throwable ex) { throw new Error("Could not materialize axioms' closure", ex); } } }
.emit(RDFHandlers.wrap(smushedStmts), 1);