本文整理汇总了Java中org.openrdf.rio.RDFHandler类的典型用法代码示例。如果您正苦于以下问题:Java RDFHandler类的具体用法?Java RDFHandler怎么用?Java RDFHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RDFHandler类属于org.openrdf.rio包,在下文中一共展示了RDFHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: queryAll
import org.openrdf.rio.RDFHandler; //导入依赖的package包/类
/**
* Handles all results of a query. Closes the query iterator when done.
* @param subject the subject {@link Resource} to query for.
* @param predicate the predicate {@link URI} to query for.
* @param object the object {@link Value} to query for.
* @param rdfStatementHandler the {@link RDFHandler} to use for handling
* each statement returned. (not {@code null})
* @param contexts the context {@link Resource}s to query for.
* @throws QueryEvaluationException
*/
public void queryAll(final Resource subject, final URI predicate, final Value object, final RDFHandler rdfStatementHandler, final Resource... contexts) throws QueryEvaluationException {
checkNotNull(rdfStatementHandler);
final CloseableIteration<Statement, QueryEvaluationException> iter = RyaDAOHelper.query(ryaDao, subject, predicate, object, conf, contexts);
try {
while (iter.hasNext()) {
final Statement statement = iter.next();
try {
rdfStatementHandler.handleStatement(statement);
} catch (final Exception e) {
throw new QueryEvaluationException("Error handling statement.", e);
}
}
} finally {
if (iter != null) {
iter.close();
}
}
}
示例2: queryFirst
import org.openrdf.rio.RDFHandler; //导入依赖的package包/类
/**
* Handles only the first result of a query. Closes the query iterator when
* done.
* @param subject the subject {@link Resource} to query for.
* @param predicate the predicate {@link URI} to query for.
* @param object the object {@link Value} to query for.
* @param rdfStatementHandler the {@link RDFHandler} to use for handling the
* first statement returned. (not {@code null})
* @param contexts the context {@link Resource}s to query for.
* @throws QueryEvaluationException
*/
public void queryFirst(final Resource subject, final URI predicate, final Value object, final RDFHandler rdfStatementHandler, final Resource... contexts) throws QueryEvaluationException {
checkNotNull(rdfStatementHandler);
final CloseableIteration<Statement, QueryEvaluationException> iter = RyaDAOHelper.query(ryaDao, subject, predicate, object, conf, contexts);
try {
if (iter.hasNext()) {
final Statement statement = iter.next();
try {
rdfStatementHandler.handleStatement(statement);
} catch (final Exception e) {
throw new QueryEvaluationException("Error handling statement.", e);
}
}
} finally {
if (iter != null) {
iter.close();
}
}
}
示例3: propagateToHandler
import org.openrdf.rio.RDFHandler; //导入依赖的package包/类
private static void propagateToHandler(List<Statement>
statements, RDFHandler handler)
throws RDFHandlerException, RepositoryException{
handler.startRDF();
handler.handleNamespace("rdf",
"http://www.w3.org/1999/02/22-rdf-syntax-ns#");
handler.handleNamespace("rdfs",
"http://www.w3.org/2000/01/rdf-schema#");
handler.handleNamespace("dcat", "http://www.w3.org/ns/dcat#");
handler.handleNamespace("xsd", "http://www.w3.org/2001/XMLSchema#");
handler.handleNamespace("owl", "http://www.w3.org/2002/07/owl#");
handler.handleNamespace("dct", "http://purl.org/dc/terms/");
handler.handleNamespace("lang",
"http://id.loc.gov/vocabulary/iso639-1/");
for(Statement st: statements){
handler.handleStatement(st);
}
handler.endRDF();
}
示例4: writeRDF
import org.openrdf.rio.RDFHandler; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
public static RDFHandler writeRDF(final OutputStream out, final RDFFormat format,
@Nullable final Map<String, String> namespaces,
@Nullable final Map<? extends RioSetting<?>, ? extends Object> settings)
throws IOException, RDFHandlerException {
final RDFWriter writer = Rio.createWriter(format, out);
final WriterConfig config = writer.getWriterConfig();
config.set(BasicWriterSettings.PRETTY_PRINT, true);
config.set(BasicWriterSettings.RDF_LANGSTRING_TO_LANG_LITERAL, true);
config.set(BasicWriterSettings.XSD_STRING_TO_PLAIN_LITERAL, true);
if (format.equals(RDFFormat.RDFXML)) {
config.set(XMLWriterSettings.INCLUDE_XML_PI, true);
config.set(XMLWriterSettings.INCLUDE_ROOT_RDF_TAG, true);
}
if (settings != null) {
for (final Map.Entry entry : settings.entrySet()) {
config.set((RioSetting) entry.getKey(), entry.getValue());
}
}
return namespaces == null ? writer : newNamespaceHandler(writer, namespaces, null);
}
示例5: toByteArray
import org.openrdf.rio.RDFHandler; //导入依赖的package包/类
public static byte[] toByteArray(Set<Statement> statements) {
ByteArrayOutputStream os = new ByteArrayOutputStream();
RDFHandler rdfHandler = new BinaryRDFWriter(os);
try {
rdfHandler.startRDF();
for (Statement statement : statements) {
rdfHandler.handleStatement(statement);
}
rdfHandler.endRDF();
} catch (RDFHandlerException e) {
e.printStackTrace();
}
return os.toByteArray();
}
示例6: toRDF
import org.openrdf.rio.RDFHandler; //导入依赖的package包/类
public URI toRDF(final RDFHandler handler, final String namespace, final Resource ctx)
throws RDFHandlerException {
final URI uri = toURI(namespace);
if (isDateTimeInterval()) {
final URI uriDesc = this.begin.toRDF(handler, namespace, ctx);
emit(handler, uri, OWLTIME.HAS_DATE_TIME_DESCRIPTION, uriDesc, ctx);
emit(handler, uri, RDF.TYPE, OWLTIME.DATE_TIME_INTERVAL, ctx);
} else {
final URI beginURI = this.begin == null ? null : create(this.begin).toRDF(handler,
namespace, ctx);
final URI endURI = this.end == null ? null : create(this.end).toRDF(handler,
namespace, ctx);
emit(handler, uri, OWLTIME.INTERVAL_STARTED_BY, beginURI, ctx);
emit(handler, uri, OWLTIME.INTERVAL_FINISHED_BY, endURI, ctx);
}
emit(handler, uri, RDF.TYPE, OWLTIME.PROPER_INTERVAL, ctx);
emit(handler, uri, RDFS.LABEL, toString(), ctx);
return uri;
}
示例7: reduce
import org.openrdf.rio.RDFHandler; //导入依赖的package包/类
@Override
public void reduce(final Value id, final Statement[] stmts, final RDFHandler handler)
throws RDFHandlerException {
// Split statements into facts and meta
final List<Statement> factStmts = Lists.newArrayListWithCapacity(stmts.length);
final List<Statement> metaStmts = Lists.newArrayListWithCapacity(stmts.length);
for (final Statement stmt : stmts) {
if (id.equals(stmt.getContext())) {
factStmts.add(stmt);
} else {
metaStmts.add(stmt);
}
}
// Emit each fact statement with its own metadata statements, possibly changing IDs
for (final Statement factStmt : factStmts) {
final URI newID = hash(factStmt.getSubject(), factStmt.getPredicate(),
factStmt.getObject());
emit(handler, id, newID, factStmt, metaStmts);
}
}
示例8: generate
import org.openrdf.rio.RDFHandler; //导入依赖的package包/类
public void generate(final KAFDocument document,
@Nullable final Iterable<Integer> sentenceIDs, final RDFHandler handler)
throws RDFHandlerException {
final boolean[] ids = new boolean[document.getNumSentences() + 1];
if (sentenceIDs == null) {
Arrays.fill(ids, true);
} else {
for (final Integer sentenceID : sentenceIDs) {
ids[sentenceID] = true;
}
}
final String baseURI = document.getPublic().uri;
new Extractor(baseURI, handler, document, ids).run();
}
示例9: get
import org.openrdf.rio.RDFHandler; //导入依赖的package包/类
@Override
public boolean get(final Value key, final RDFHandler handler) throws RDFHandlerException {
try {
final byte[] keyBytes = write(this.nsMap, new ByteArrayOutputStream(), key)
.toByteArray();
final byte[] valueBytes = this.reader.getAsByteArray(keyBytes);
if (valueBytes == null) {
return false;
} else {
read(this.nsArray, new ByteArrayInputStream(valueBytes), handler);
return true;
}
} catch (final IOException ex) {
throw Throwables.propagate(ex);
}
}
示例10: read
import org.openrdf.rio.RDFHandler; //导入依赖的package包/类
private static void read(final String[] nsArray, final ByteArrayInputStream stream,
final RDFHandler handler) throws RDFHandlerException {
final Value[] values = new Value[4];
int index = 0;
while (true) {
stream.mark(1);
final int hi = stream.read() & 0xFF;
if (hi == HI_END) {
break;
} else if (hi == HI_END_C) {
index = 0;
} else if (hi == HI_END_S) {
index = 1;
} else if (hi == HI_END_P) {
index = 2;
} else {
stream.reset();
}
values[index++] = read(nsArray, stream);
if (index == 4) {
handler.handleStatement(Statements.VALUE_FACTORY.createStatement(
(Resource) values[1], (URI) values[2], values[3], (Resource) values[0]));
--index;
}
}
}
示例11: retrieveLive
import org.openrdf.rio.RDFHandler; //导入依赖的package包/类
@GET
@Path("/live")
public Response retrieveLive(@QueryParam("uri") String uri) {
if(cacheSailProvider.isEnabled()) {
try {
ClientResponse response = cacheSailProvider.getLDClient().retrieveResource(uri);
ByteArrayOutputStream out = new ByteArrayOutputStream();
RDFHandler handler = new RDFXMLPrettyWriter(out);
ModelCommons.export(response.getData(), handler);
return Response.ok().entity( new String(out.toByteArray(), "utf-8")).build();
} catch (Exception e) {
log.error("exception while retrieving resource",e);
return Response.status(500).entity(e.getMessage()).build();
}
} else {
return Response.status(Status.SERVICE_UNAVAILABLE).entity("caching is disabled").build();
}
}
示例12: includeArtifactCode
import org.openrdf.rio.RDFHandler; //导入依赖的package包/类
private static URI includeArtifactCode(RdfFileContent preprocessedContent, String artifactCode, URI baseUri, Object writerOrHandler)
throws TrustyUriException {
Map<String,String> ns = makeNamespaceMap(preprocessedContent.getStatements(), baseUri, artifactCode);
HashAdder hashAdder;
if (writerOrHandler instanceof RDFWriter) {
hashAdder = new HashAdder(baseUri, artifactCode, (RDFWriter) writerOrHandler, ns);
} else {
hashAdder = new HashAdder(baseUri, artifactCode, (RDFHandler) writerOrHandler, ns);
}
try {
preprocessedContent.propagate(hashAdder);
} catch (RDFHandlerException ex) {
throw new TrustyUriException(ex);
}
return RdfUtils.getTrustyUri(baseUri, artifactCode);
}
示例13: testRunCompletedEventProperties
import org.openrdf.rio.RDFHandler; //导入依赖的package包/类
@Test
public void testRunCompletedEventProperties() throws InterruptedException {
MockApplicationEventPublisher eventPublisher = new MockApplicationEventPublisher();
ETLPipelineImpl instance = new ETLPipelineImpl(id, eventPublisher, repository);
Extractor delayingExtractor = new Extractor() {
@Override
public void extract(RDFHandler handler, ExtractContext context) throws ExtractException {
try {
Thread.sleep(10);
} catch (InterruptedException ex) {
throw new ExtractException(ex);
}
}
};
instance.setExtractors(Arrays.asList(delayingExtractor));
instance.run();
PipelineCompletedEvent completedEvent = eventPublisher.getPublishedEventsOfType(PipelineCompletedEvent.class).get(0);
Assert.assertEquals(instance, completedEvent.getPipeline());
Assert.assertNotNull(completedEvent.getId());
Assert.assertTrue(completedEvent.getDuration() > 0);
}
示例14: testRunExtractFailedEventFired
import org.openrdf.rio.RDFHandler; //导入依赖的package包/类
@Test
public void testRunExtractFailedEventFired() {
MockApplicationEventPublisher eventPublisher = new MockApplicationEventPublisher();
ETLPipelineImpl instance = new ETLPipelineImpl(id, eventPublisher, repository);
Extractor extractor = new MockExtractor() {
@Override
public void extract(RDFHandler handler, ExtractContext context) throws ExtractException {
throw new ExtractException("Test");
}
};
instance.setExtractors(Arrays.asList(extractor));
instance.run();
ExtractFailedEvent failedEvent = eventPublisher.getPublishedEventsOfType(ExtractFailedEvent.class).get(0);
Assert.assertEquals(extractor, failedEvent.getExtractor());
Assert.assertNotNull(failedEvent.getException());
}
示例15: testRunExtractorAbortedEventFired
import org.openrdf.rio.RDFHandler; //导入依赖的package包/类
@Test
public void testRunExtractorAbortedEventFired() {
MockApplicationEventPublisher eventPublisher = new MockApplicationEventPublisher();
ETLPipelineImpl instance = new ETLPipelineImpl(id, eventPublisher, repository);
Extractor extractor = new MockExtractor() {
@Override
public void extract(RDFHandler handler, ExtractContext context) throws ExtractException {
context.cancelPipeline("Test");
}
};
instance.setExtractors(Arrays.asList(extractor));
instance.run();
PipelineAbortedEvent abortedEvent = eventPublisher.getPublishedEventsOfType(PipelineAbortedEvent.class).get(0);
Assert.assertEquals(instance, abortedEvent.getPipeline());
Assert.assertEquals("Test", abortedEvent.getMessage());
}