Search in sources :

Example 41 with RDFFormat

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();
        }
    }
}
Also used : Description(nl.knaw.huygens.timbuctoo.remote.rs.discover.Description) RDFFormat(org.eclipse.rdf4j.rio.RDFFormat)

Example 42 with RDFFormat

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.");
}
Also used : InputStream(java.io.InputStream) TestFile(org.apache.rya.helper.TestFile) SailRepositoryConnection(org.eclipse.rdf4j.repository.sail.SailRepositoryConnection) Update(org.eclipse.rdf4j.query.Update) RDFFormat(org.eclipse.rdf4j.rio.RDFFormat) Test(org.junit.Test)

Example 43 with RDFFormat

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);
    }
}
Also used : SailRepositoryConnection(org.eclipse.rdf4j.repository.sail.SailRepositoryConnection) RDFFormat(org.eclipse.rdf4j.rio.RDFFormat)

Example 44 with RDFFormat

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);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) RDFFormat(org.eclipse.rdf4j.rio.RDFFormat)

Example 45 with RDFFormat

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);
}
Also used : RDFFormat(org.eclipse.rdf4j.rio.RDFFormat)

Aggregations

RDFFormat (org.eclipse.rdf4j.rio.RDFFormat)62 ByteArrayOutputStream (java.io.ByteArrayOutputStream)17 IOException (java.io.IOException)17 WriteRdf4j (mom.trd.opentheso.core.exports.rdf4j.WriteRdf4j)14 InputStream (java.io.InputStream)12 RDFParseException (org.eclipse.rdf4j.rio.RDFParseException)11 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)8 FileInputStream (java.io.FileInputStream)7 Model (org.eclipse.rdf4j.model.Model)6 RDFHandlerException (org.eclipse.rdf4j.rio.RDFHandlerException)6 RDFParser (org.eclipse.rdf4j.rio.RDFParser)5 UnsupportedRDFormatException (org.eclipse.rdf4j.rio.UnsupportedRDFormatException)5 Rdf2GoCore (de.knowwe.rdf2go.Rdf2GoCore)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 File (java.io.File)4 NodePreference (mom.trd.opentheso.bdd.helper.nodes.NodePreference)4 ExportRdf4jHelper (mom.trd.opentheso.core.exports.rdf4j.ExportRdf4jHelper)4 IRI (org.eclipse.rdf4j.model.IRI)4 Statement (org.eclipse.rdf4j.model.Statement)4 Test (org.junit.Test)4