本文整理汇总了Java中org.openrdf.rio.RDFHandler.endRDF方法的典型用法代码示例。如果您正苦于以下问题:Java RDFHandler.endRDF方法的具体用法?Java RDFHandler.endRDF怎么用?Java RDFHandler.endRDF使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openrdf.rio.RDFHandler
的用法示例。
在下文中一共展示了RDFHandler.endRDF方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
示例2: 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();
}
示例3: loadAllTriples
import org.openrdf.rio.RDFHandler; //导入方法依赖的package包/类
@Override
public void loadAllTriples(RDFHandler rdfHandler) throws LDFusionToolException {
LOG.info("Parsing all quads from data source {}", source);
String query = "";
try {
rdfHandler.startRDF();
SparqlRestriction restriction = getSparqlRestriction();
long totalStartTime = System.currentTimeMillis();
int totalLoadedQuads = 0;
int lastLoadedQuads = Integer.MAX_VALUE;
for (int offset = initialOffset; lastLoadedQuads >= maxSparqlResultsSize; offset = initialOffset + totalLoadedQuads) {
query = formatQuery(LOAD_SPARQL_QUERY, restriction, maxSparqlResultsSize, offset);
long lastStartTime = System.currentTimeMillis();
lastLoadedQuads = addQuadsFromQueryWithRetry(query, rdfHandler);
totalLoadedQuads += lastLoadedQuads;
logProgress(lastLoadedQuads, totalLoadedQuads, lastStartTime, totalStartTime);
}
rdfHandler.endRDF();
} catch (OpenRDFException | InterruptedException e) {
throw new LDFusionToolQueryException(LDFusionToolErrorCodes.ALL_TRIPLES_QUERY_QUADS, query, source.getName(), e);
}
}
示例4: propagateToHandler
import org.openrdf.rio.RDFHandler; //导入方法依赖的package包/类
public static void propagateToHandler(Nanopub nanopub, RDFHandler handler)
throws RDFHandlerException {
handler.startRDF();
String s = nanopub.getUri().toString();
if (nanopub instanceof NanopubWithNs && !((NanopubWithNs) nanopub).getNsPrefixes().isEmpty()) {
NanopubWithNs np = (NanopubWithNs) nanopub;
for (String p : np.getNsPrefixes()) {
handler.handleNamespace(p, np.getNamespace(p));
}
} else {
handler.handleNamespace("this", s);
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("rdfg", "http://www.w3.org/2004/03/trix/rdfg-1/");
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("dce", "http://purl.org/dc/elements/1.1/");
handler.handleNamespace("pav", "http://purl.org/pav/");
handler.handleNamespace("np", "http://www.nanopub.org/nschema#");
}
for (Statement st : getStatements(nanopub)) {
handler.handleStatement(st);
}
handler.endRDF();
}
示例5: propagate
import org.openrdf.rio.RDFHandler; //导入方法依赖的package包/类
public void propagate(RDFHandler handler, boolean doStardAndEnd) throws RDFHandlerException {
if (doStardAndEnd) handler.startRDF();
for (Pair<String,String> ns : namespaces) {
handler.handleNamespace(ns.getLeft(), ns.getRight());
}
for (Statement st : statements) {
handler.handleStatement(st);
}
if (doStardAndEnd) handler.endRDF();
}
示例6: copyInputsToTempFiles
import org.openrdf.rio.RDFHandler; //导入方法依赖的package包/类
/**
* Reads all input quads and outputs them to temporary files.
* Data are written to temporary files in the following format:
* <ul>
* <li> c(S) S P O G for input quads (S,P,O,G) to {@code dataFile}</li>
* <li> c(O) c(S) for input quads (S,P,O,G) such that P is a resource description URI to {@code attributeIndexFile} and O is a {@link org.openrdf.model.Resource}</li>
* </ul>
* where c(x) is the canonical version of x.
*/
private void copyInputsToTempFiles(Collection<AllTriplesLoader> dataSources, UriMappingIterable uriMapping, File dataFile, File attributeIndexFile)
throws LDFusionToolException {
NTuplesWriter dataFileWriter = null;
NTuplesWriter attributeIndexFileWriter = null;
try {
dataFileWriter = new NTuplesWriter(createTempFileWriter(dataFile));
attributeIndexFileWriter = new NTuplesWriter(createTempFileWriter(attributeIndexFile));
RDFHandler tempFilesWriteHandler = new FederatedRDFHandler(
new DataFileNTuplesWriter(dataFileWriter, uriMapping),
new AtributeIndexFileNTuplesWriter(attributeIndexFileWriter, canonicalResourceDescriptionProperties, uriMapping));
ExternalSortingInputLoaderPreprocessor inputLoaderPreprocessor = new ExternalSortingInputLoaderPreprocessor(
tempFilesWriteHandler, VF);
tempFilesWriteHandler.startRDF();
for (AllTriplesLoader dataSource : dataSources) {
try {
inputLoaderPreprocessor.setDefaultContext(dataSource.getDefaultContext());
dataSource.loadAllTriples(inputLoaderPreprocessor);
// TODO: Presort in memory (presort NTuples wrapper) & do not write to disc if small enough?
} finally {
dataSource.close();
}
}
tempFilesWriteHandler.endRDF();
} catch (Exception e) {
throw new LDFusionToolApplicationException(LDFusionToolErrorCodes.INPUT_LOADER_TMP_FILE_INIT,
"Error while writing quads to temporary file in input loader", e);
} finally {
tryCloseWriter(dataFileWriter);
tryCloseWriter(attributeIndexFileWriter);
}
}
示例7: main
import org.openrdf.rio.RDFHandler; //导入方法依赖的package包/类
public static void main(final String... args) {
try {
// Parse command line
final CommandLine cmd = CommandLine
.parser()
.withName("eval-converter")
.withHeader("Convert a tool output in the format used for the evaluation.")
.withOption("o", "output", "the output file", "FILE", Type.STRING, true,
false, true)
.withOption("f", "format", "the format (fred, pikes, gold)", "FMT",
Type.STRING, true, false, true)
.withOption("n", "replace-nominal",
"replaces nominal frames with association " //
+ " relations (for FRED compatibility)")
.withLogger(LoggerFactory.getLogger("eu.fbk")) //
.parse(args);
// Extract options
final String format = cmd.getOptionValue("f", String.class).trim().toLowerCase();
final String outputFile = cmd.getOptionValue("o", String.class);
final List<String> inputFiles = cmd.getArgs(String.class);
final boolean replaceNominalFrames = cmd.hasOption("n");
// Obtain the converter corresponding to the format specified
Converter converter;
if (format.equalsIgnoreCase("fred")) {
converter = FRED_CONVERTER;
} else if (format.equalsIgnoreCase("gold")) {
converter = GOLD_CONVERTER;
} else if (format.equalsIgnoreCase("pikes")) {
converter = PIKES_CONVERTER;
} else {
throw new IllegalArgumentException("Unknown format: " + format);
}
// Read the input
final Map<String, String> namespaces = Maps.newHashMap();
final QuadModel input = QuadModel.create();
RDFSources.read(false, false, null, null,
inputFiles.toArray(new String[inputFiles.size()])).emit(
RDFHandlers.wrap(input, namespaces), 1);
// Perform the conversion
final QuadModel output = converter.convert(input);
// Replace nominal frames if requested
if (replaceNominalFrames) {
replaceNominalFrames(output);
}
// Write the output
final RDFHandler out = RDFHandlers.write(null, 1000, outputFile);
out.startRDF();
namespaces.put(DCTERMS.PREFIX, DCTERMS.NAMESPACE);
namespaces.put("pb", "http://pikes.fbk.eu/ontologies/propbank#");
namespaces.put("nb", "http://pikes.fbk.eu/ontologies/nombank#");
namespaces.put("vn", "http://pikes.fbk.eu/ontologies/verbnet#");
namespaces.put("fn", "http://pikes.fbk.eu/ontologies/framenet#");
namespaces.put("dul", "http://www.ontologydesignpatterns.org/ont/dul/DUL.owl#");
final Set<String> outputNS = Sets.newHashSet();
collectNS(outputNS, output);
for (final Map.Entry<String, String> entry : namespaces.entrySet()) {
if (!entry.getKey().isEmpty() && outputNS.contains(entry.getValue())) {
out.handleNamespace(entry.getKey(), entry.getValue());
}
}
for (final Statement stmt : Ordering.from(
Statements.statementComparator("cspo",
Statements.valueComparator(RDF.NAMESPACE))).sortedCopy(output)) {
out.handleStatement(stmt);
}
out.endRDF();
} catch (final Throwable ex) {
// Display error information and terminate
CommandLine.fail(ex);
}
}
示例8: main
import org.openrdf.rio.RDFHandler; //导入方法依赖的package包/类
public static void main(final String[] args) {
try {
// Parse command line
final CommandLine cmd = CommandLine
.parser()
.withName("eval-aligner")
.withHeader("Alignes the knowledge graphs produced by different tools " //
+ "againsts a gold graph")
.withOption("o", "output", "the output file", "FILE", Type.STRING, true,
false, true) //
.withLogger(LoggerFactory.getLogger("eu.fbk")) //
.parse(args);
// Extract options
final String outputFile = cmd.getOptionValue("o", String.class);
final List<String> inputFiles = cmd.getArgs(String.class);
// Read the input
final Map<String, String> namespaces = Maps.newHashMap();
final QuadModel input = QuadModel.create();
RDFSources.read(false, false, null, null,
inputFiles.toArray(new String[inputFiles.size()])).emit(
RDFHandlers.wrap(input, namespaces), 1);
// Perform the alignment
final List<Statement> mappingStmts = align(input);
input.addAll(mappingStmts);
// Write the output
final RDFHandler out = RDFHandlers.write(null, 1000, outputFile);
out.startRDF();
namespaces.put(DCTERMS.PREFIX, DCTERMS.NAMESPACE);
for (final Map.Entry<String, String> entry : namespaces.entrySet()) {
if (!entry.getKey().isEmpty()) {
out.handleNamespace(entry.getKey(), entry.getValue());
}
}
for (final Statement stmt : Ordering.from(
Statements.statementComparator("cspo",
Statements.valueComparator(RDF.NAMESPACE))).sortedCopy(input)) {
out.handleStatement(stmt);
}
out.endRDF();
} catch (final Throwable ex) {
// Display error information and terminate
CommandLine.fail(ex);
}
}
示例9: exportTriples
import org.openrdf.rio.RDFHandler; //导入方法依赖的package包/类
private void exportTriples(Iterable<Triple> triples, RDFHandler handler) throws RDFHandlerException {
handler.startRDF();
addNamespaces(handler);
populateRepository(triples, handler);
handler.endRDF();
}
示例10: endRDF
import org.openrdf.rio.RDFHandler; //导入方法依赖的package包/类
@Override
public void endRDF() throws RDFHandlerException {
for (RDFHandler rdfHandler : rdfHandlers) {
rdfHandler.endRDF();
}
}