本文整理汇总了Java中eu.unifiedviews.helpers.dataunit.rdf.RdfDataUnitUtils类的典型用法代码示例。如果您正苦于以下问题:Java RdfDataUnitUtils类的具体用法?Java RdfDataUnitUtils怎么用?Java RdfDataUnitUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RdfDataUnitUtils类属于eu.unifiedviews.helpers.dataunit.rdf包,在下文中一共展示了RdfDataUnitUtils类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadRdfIntoObject
import eu.unifiedviews.helpers.dataunit.rdf.RdfDataUnitUtils; //导入依赖的package包/类
private <TYPE> void loadRdfIntoObject(RepositoryConnection connection, IRI resourceClass, TYPE object)
throws DataUnitException, RepositoryException, SerializationFailure, SerializationRdfFailure {
final List<RDFDataUnit.Entry> etries = DataUnitUtils.getEntries(sourceDataUnit,
RDFDataUnit.Entry.class);
final IRI [] graphs = RdfDataUnitUtils.asGraphs(etries);
// Load subjects.
final List<Resource> resources = getConfigurationSubject(resourceClass, graphs);
if (resources.isEmpty()) {
// No configuration resource.
LOG.debug("No configuration object found.");
return;
}
if (resources.size() > 1) {
LOG.info("Loading from multiple instances.");
}
// For each subject load data.
for (Resource resource : resources) {
serialization.convert(connection, resource, etries, object, null);
}
}
示例2: checkParamsFromMapAreInOutput
import eu.unifiedviews.helpers.dataunit.rdf.RdfDataUnitUtils; //导入依赖的package包/类
@Test
public void checkParamsFromMapAreInOutput() throws Exception {
addFileToInput("valid.xml");
// Prepare configuration.
final WritableRDFDataUnit configRdf = env.createRdfInput("config", false);
InputOutputUtils.extractFromFile(new File(getClass().getClassLoader().getResource("config.ttl").toURI()), RDFFormat.TURTLE, configRdf,
RdfDataUnitUtils.addGraph(configRdf, "main-config"));
// configure DPU
XSLTConfig_V1 config = new XSLTConfig_V1();
config.setXslTemplate(resourceAsString("output-params.xslt"));
dpu.configure((new ConfigurationBuilder()).setDpuConfiguration(config).toString());
// run DPU
env.run(dpu);
// check output for parameters
List<FilesDataUnit.Entry> outputList = new ArrayList<>(FilesHelper.getFiles(output));
Iterator<FilesDataUnit.Entry> outputIterator = outputList.iterator();
while (outputIterator.hasNext()) {
String outputContents = IOUtils.toString(java.net.URI.create(outputIterator.next().getFileURIString()), "UTF-8");
// verify result
assertTrue("Output contents should contain string '1'", outputContents.contains("1"));
assertTrue("Output contents should contain string '2'", outputContents.contains("2"));
}
}
示例3: RemoteRdfDataUnit
import eu.unifiedviews.helpers.dataunit.rdf.RdfDataUnitUtils; //导入依赖的package包/类
RemoteRdfDataUnit(ExecContext<?> execContext, String endpointUrl, IRI... graphs)
throws ExternalError {
this.execContext = execContext;
this.repository = new SPARQLRepository(endpointUrl);
try {
this.repository.initialize();
} catch (RepositoryException ex) {
throw new ExternalError("Can't create remote HTTP repository.", ex);
}
// Initialize entries.
entries = new ArrayList<>(graphs.length);
for (IRI uri : graphs) {
entries.add(new RdfDataUnitUtils.InMemoryEntry(uri, "remote: " + endpointUrl));
}
}
示例4: asGraph
import eu.unifiedviews.helpers.dataunit.rdf.RdfDataUnitUtils; //导入依赖的package包/类
/**
* Convert {@link RDFDataUnit.Entry} to {@link IRI}
*
* @param faultTolerance
* @param entry
* @return
* @throws DPUException
*/
public static IRI asGraph(FaultTolerance faultTolerance, final RDFDataUnit.Entry entry)
throws DPUException {
return faultTolerance.execute(new FaultTolerance.ActionReturn<IRI>() {
@Override
public IRI action() throws Exception {
return RdfDataUnitUtils.asGraph(entry);
}
});
}
示例5: convert
import eu.unifiedviews.helpers.dataunit.rdf.RdfDataUnitUtils; //导入依赖的package包/类
@Override
public void convert(RepositoryConnection connection, Resource rootResource,
List<RDFDataUnit.Entry> context, Object object, Configuration config)
throws SerializationFailure, SerializationRdfFailure, DataUnitException, RepositoryException {
if (config == null) {
config = SerializationUtils.createConfiguration(object.getClass());
}
// Get read graphs.
final IRI[] graphs = RdfDataUnitUtils.asGraphs(context);
// Load object.
loadIntoObject(new Context(connection, graphs, config), rootResource, object);
}
示例6: prepareDataset
import eu.unifiedviews.helpers.dataunit.rdf.RdfDataUnitUtils; //导入依赖的package包/类
/**
* @return Null if no dataset should be used.
*/
protected static Dataset prepareDataset(List<RDFDataUnit.Entry> source, RDFDataUnit.Entry target)
throws DataUnitException {
final SimpleDataset dataset = new SimpleDataset();
// Add read graphs.
for (IRI uri : RdfDataUnitUtils.asGraphs(source)) {
dataset.addDefaultGraph(uri);
}
// Add write graph.
if (target != null) {
dataset.setDefaultInsertGraph(target.getDataGraphURI());
dataset.addDefaultRemoveGraph(target.getDataGraphURI());
}
return dataset;
}
示例7: getMetadataEntries
import eu.unifiedviews.helpers.dataunit.rdf.RdfDataUnitUtils; //导入依赖的package包/类
/**
* Provide access to metadata in same form as to any other graph. As a symbolic name fixed value is used.
* Do not write into input metadata graphs as it would corrupt data for other DPUs.
*
* @param dataUnit
* @return
*/
public static List<RDFDataUnit.Entry> getMetadataEntries(MetadataDataUnit dataUnit)
throws DataUnitException {
final List<RDFDataUnit.Entry> result = new LinkedList<>();
for (IRI graphName : dataUnit.getMetadataGraphnames()) {
result.add(new RdfDataUnitUtils.InMemoryEntry(graphName, METADATA_GRAPH_SYMBOLIC_NAME));
}
return result;
}
示例8: innerExecute
import eu.unifiedviews.helpers.dataunit.rdf.RdfDataUnitUtils; //导入依赖的package包/类
@Override
protected void innerExecute() throws DPUException {
// Prepare tabular convertor.
final TableToRdf tableToRdf = new TableToRdf(
config.getTableToRdfConfig(),
rdfTableWrap,
rdfTableWrap.getValueFactory());
// Prepare parser based on type.
final Parser parser;
switch (config.getTableType()) {
case CSV:
parser = new ParserCsv(config.getParserCsvConfig(), tableToRdf, ctx);
break;
case DBF:
parser = new ParserDbf(config.getParserDbfConfig(), tableToRdf, ctx);
break;
case XLS:
parser = new ParserXls(config.getParserXlsConfig(), tableToRdf, ctx);
break;
default:
throw ContextUtils.dpuException(this.ctx, "execution.errors.table.unknown", this.config.getXlsSheetName());
}
// Get files to process.
final List<FilesDataUnit.Entry> files = FaultToleranceUtils.getEntries(faultTolerance, inFilesTable,
FilesDataUnit.Entry.class);
for (final FilesDataUnit.Entry entry : files) {
if (ctx.canceled()) {
throw ContextUtils.dpuExceptionCancelled(ctx);
}
// Set output graph.
final RDFDataUnit.Entry entryOutput = faultTolerance.execute(new FaultTolerance.ActionReturn<RDFDataUnit.Entry>() {
@Override
public RDFDataUnit.Entry action() throws Exception {
return RdfDataUnitUtils.addGraph(outRdfTables, entry.getSymbolicName());
}
});
rdfTableWrap.setOutput(entryOutput);
final String symbolicName = faultTolerance.execute(new FaultTolerance.ActionReturn<String>() {
@Override
public String action() throws Exception {
return entry.getSymbolicName();
}
});
ContextUtils.sendShortInfo(this.ctx, "dpu.execution.file.processing", symbolicName);
// Output data.
try {
// If set add subject for the whole table.
if (config.isUseTableSubject()) {
// Prepare subject for table.
// TODO: We can use better subject here!
final IRI tableURI = faultTolerance.execute(new FaultTolerance.ActionReturn<IRI>() {
@Override
public IRI action() throws Exception {
return rdfTableWrap.getValueFactory().createIRI(entry.getFileURIString());
}
});
// Set as a table subject.
tableToRdf.setTableSubject(tableURI);
// Add metadata (symbolic name) to table subject.
faultTolerance.execute(new FaultTolerance.Action() {
@Override
public void action() throws Exception {
rdfTableWrap.add(tableURI, TabularOntology.TABLE_SYMBOLIC_NAME,
rdfTableWrap.getValueFactory().createLiteral(entry.getSymbolicName()));
}
});
}
// Parse file.
parser.parse(FaultToleranceUtils.asFile(faultTolerance, entry));
} catch (ParseFailed ex) {
throw ContextUtils.dpuException(this.ctx, ex, "dpu.execution.errors.conversion.failed", entry);
}
}
}
示例9: innerExecute
import eu.unifiedviews.helpers.dataunit.rdf.RdfDataUnitUtils; //导入依赖的package包/类
@Override
protected void innerExecute() throws DPUException {
// Get list of input graphs.
final List<RDFDataUnit.Entry> inputEntries = FaultToleranceUtils.getEntries(faultTolerance, rdfInput,
RDFDataUnit.Entry.class);
// Prepare output graph.
final RDFDataUnit.Entry outputEntry = faultTolerance.execute(new FaultTolerance.ActionReturn<RDFDataUnit.Entry>() {
@Override
public RDFDataUnit.Entry action() throws Exception {
return RdfDataUnitUtils.addGraph(rdfOutput, generateOutputSymbolicName());
}
});
// Per-graph execution.
int counter = 0;
for (final RDFDataUnit.Entry entry : inputEntries) {
LOG.info("Processing {}/{}", ++counter, inputEntries.size());
faultTolerance.execute(rdfInput, new FaultTolerance.ConnectionAction() {
@Override
public void action(RepositoryConnection connection) throws Exception {
final SparqlUtils.SparqlUpdateObject update =
SparqlUtils.createInsert(COPY_QUERY, Arrays.asList(entry), outputEntry);
// Copy statementes.
SparqlUtils.execute(connection, update);
}
});
}
faultTolerance.execute(new FaultTolerance.ActionReturn<Boolean>() {
@Override
public Boolean action() throws Exception {
Resource resource = ResourceHelpers.getResource(rdfOutput, outputEntry.getSymbolicName());
Date now = new Date();
resource.setLast_modified(now);
resource.setCreated(now);
ResourceHelpers.setResource(rdfOutput, outputEntry.getSymbolicName(), resource);
if (config.getVirtualGraph() != null) {
VirtualGraphHelpers.setVirtualGraph(rdfOutput, outputEntry.getSymbolicName(), config.getVirtualGraph().toString());
}
return Boolean.TRUE;
}
});
}
示例10: getWritableMetadataEntry
import eu.unifiedviews.helpers.dataunit.rdf.RdfDataUnitUtils; //导入依赖的package包/类
/**
* Provide access to metadata in the same form as to any other graph. This graph can be used to write
* operation but it should be used with caution.
*
* @param dataUnit
* @return
* @throws DataUnitException
*/
public static RDFDataUnit.Entry getWritableMetadataEntry(WritableMetadataDataUnit dataUnit)
throws DataUnitException {
return new RdfDataUnitUtils.InMemoryEntry(dataUnit.getMetadataWriteGraphname(),
WRITABLE_METADATA_GRAPH_SYMBOLIC_NAME);
}