use of org.eclipse.rdf4j.rio.RDFFormat in project timbuctoo by HuygensING.
the class DescriptionView method init.
private void init(Result<Description> descriptionResult, Interpreter interpreter) {
if (descriptionResult.getContent().isPresent()) {
Description description = descriptionResult.getContent().get();
String mimeType = description.getDescribedByLink().getType().orElse(null);
Optional<RDFFormat> maybeFormat = Rio.getParserFormatForMIMEType(mimeType);
if (!maybeFormat.isPresent()) {
String filename = descriptionResult.getUri().toString();
maybeFormat = Rio.getParserFormatForFileName(filename);
}
if (maybeFormat.isPresent()) {
createDescriptionNode(description, maybeFormat.get(), interpreter);
} else {
rawContent = description.getRawContent();
}
}
}
use of org.eclipse.rdf4j.rio.RDFFormat in project incubator-rya by apache.
the class MongoDbRyaSailFactoryLoadFilesIT method testFileLoading.
@Test
public void testFileLoading() throws Exception {
log.info("Starting file loading test...");
final String query = "SELECT * WHERE { ?s ?p ?o . }";
final String deleteQuery = "DELETE WHERE { ?s ?p ?o . }";
for (final TestFile testFile : TestFileUtils.TEST_FILES) {
final String testFilePath = testFile.getPath();
final RDFFormat rdfFormat = RdfFormatUtils.forFileName(testFilePath, null);
log.info("Loading file \"" + testFilePath + "\" with RDFFormat: " + rdfFormat.getName());
try (final InputStream rdfContent = getClass().getResourceAsStream(testFilePath)) {
addTriples(ryaRepository, rdfContent, rdfFormat);
}
SailRepositoryConnection queryConn = null;
try {
log.info("Querying for triples in the repository from the " + rdfFormat.getName() + " file.");
queryConn = ryaRepository.getConnection();
final int count = performTupleQuery(query, queryConn);
assertEquals("Expected number of triples not found in: " + testFilePath, testFile.getExpectedCount(), count);
} finally {
closeQuietly(queryConn);
}
SailRepositoryConnection deleteConn = null;
try {
log.info("Deleting triples in the repository from the " + rdfFormat.getName() + " file.");
deleteConn = ryaRepository.getConnection();
final Update update = deleteConn.prepareUpdate(QueryLanguage.SPARQL, deleteQuery);
update.execute();
} finally {
closeQuietly(deleteConn);
}
}
log.info("File loading test finished.");
}
use of org.eclipse.rdf4j.rio.RDFFormat in project incubator-rya by apache.
the class MongoSpinIT method insertDataFile.
private void insertDataFile(final URL dataFile, final String defaultNamespace) throws Exception {
final RDFFormat format = Rio.getParserFormatForFileName(dataFile.getFile()).get();
final SailRepositoryConnection conn = repository.getConnection();
try {
conn.add(dataFile, defaultNamespace, format);
} finally {
closeQuietly(conn);
}
}
use of org.eclipse.rdf4j.rio.RDFFormat in project incubator-rya by apache.
the class RdfFileInputFormat method createRecordReader.
/**
* Instantiate a RecordReader for a given task attempt.
* @param inputSplit Input split to handle, may refer to part or all of
* an RDF file
* @param taskAttemptContext Contains configuration options.
* @return A RecordReader that reads and parses RDF text.
*/
@Override
public RecordReader<LongWritable, RyaStatementWritable> createRecordReader(InputSplit inputSplit, TaskAttemptContext taskAttemptContext) {
Configuration conf = taskAttemptContext.getConfiguration();
RDFFormat format = getRDFFormat(taskAttemptContext);
if (format == null) {
format = DEFAULT_RDF_FORMAT;
}
int charBufferSize = conf.getInt(CHAR_BUFFER_SIZE_PROP, DEFAULT_CHAR_BUFFER_SIZE);
int statementBufferSize = conf.getInt(STATEMENT_BUFFER_SIZE_PROP, DEFAULT_STATEMENT_BUFFER_SIZE);
int timeoutSeconds = conf.getInt(TIMEOUT_PROP, DEFAULT_TIMEOUT);
return new RdfFileRecordReader(format, charBufferSize, statementBufferSize, timeoutSeconds);
}
use of org.eclipse.rdf4j.rio.RDFFormat in project incubator-rya by apache.
the class AbstractAccumuloMRTool method setupFileInputs.
/**
* Sets up RDF file input for a job: the job receives
* ({@link org.apache.hadoop.io.LongWritable}, {@link RyaStatementWritable})
* pairs from RDF file(s) found at the specified path.
* @param job Job to configure
* @param commaSeparatedPaths a comma separated list of files or directories
* @param defaultFormat Default RDF serialization format, can be
* overridden by {@link MRUtils#FORMAT_PROP}
* @throws IOException if there's an error interacting with the
* {@link org.apache.hadoop.fs.FileSystem}.
*/
protected void setupFileInputs(Job job, String commaSeparatedPaths, RDFFormat defaultFormat) throws IOException {
RDFFormat format = MRUtils.getRDFFormat(conf);
if (format == null) {
format = defaultFormat;
}
RdfFileInputFormat.addInputPaths(job, commaSeparatedPaths);
RdfFileInputFormat.setRDFFormat(job, format);
job.setInputFormatClass(RdfFileInputFormat.class);
}
Aggregations