Search in sources :

Example 11 with QuadWritable

use of org.apache.jena.hadoop.rdf.types.QuadWritable in project jena by apache.

the class HadoopRdfIORegistry method createQuadReader.

/**
     * Tries to create a quad reader for the given language
     * 
     * @param lang
     *            Language
     * @return Quad reader if one is available
     * @throws IOException
     *             Thrown if a quad reader is not available or the given
     *             language does not support quads
     */
public static RecordReader<LongWritable, QuadWritable> createQuadReader(Lang lang) throws IOException {
    if (lang == null)
        throw new IOException("Cannot create a quad reader for an undefined language");
    ReaderFactory f = readerFactories.get(lang);
    if (f == null)
        throw new IOException("No factory registered for language " + lang.getName());
    if (!f.canReadQuads())
        throw new IOException(lang.getName() + " does not support reading quads");
    RecordReader<LongWritable, QuadWritable> reader = f.createQuadReader();
    if (reader == null)
        throw new IOException("Registered factory for " + lang.getName() + " produced a null triples reader");
    return reader;
}
Also used : QuadWritable(org.apache.jena.hadoop.rdf.types.QuadWritable) IOException(java.io.IOException) LongWritable(org.apache.hadoop.io.LongWritable)

Example 12 with QuadWritable

use of org.apache.jena.hadoop.rdf.types.QuadWritable in project jena by apache.

the class QuadsToTriplesMapperTest method quads_to_triples_mapper_01.

/**
     * Tests quads to triples conversion
     * 
     * @throws IOException
     */
@Test
public void quads_to_triples_mapper_01() throws IOException {
    MapDriver<LongWritable, QuadWritable, LongWritable, TripleWritable> driver = this.getMapDriver();
    Triple t = new Triple(NodeFactory.createURI("http://s"), NodeFactory.createURI("http://p"), NodeFactory.createLiteral("test"));
    Quad q = new Quad(Quad.defaultGraphNodeGenerated, t);
    driver.withInput(new Pair<LongWritable, QuadWritable>(new LongWritable(1), new QuadWritable(q))).withOutput(new Pair<LongWritable, TripleWritable>(new LongWritable(1), new TripleWritable(t)));
    driver.runTest();
}
Also used : Triple(org.apache.jena.graph.Triple) TripleWritable(org.apache.jena.hadoop.rdf.types.TripleWritable) Quad(org.apache.jena.sparql.core.Quad) QuadWritable(org.apache.jena.hadoop.rdf.types.QuadWritable) LongWritable(org.apache.hadoop.io.LongWritable) Pair(org.apache.hadoop.mrunit.types.Pair) Test(org.junit.Test)

Example 13 with QuadWritable

use of org.apache.jena.hadoop.rdf.types.QuadWritable in project jena by apache.

the class TriplesToQuadsBySubjectMapperTest method generateData.

protected void generateData(MapDriver<LongWritable, TripleWritable, LongWritable, QuadWritable> driver, int num) {
    for (int i = 0; i < num; i++) {
        Triple t = new Triple(NodeFactory.createURI("http://subjects/" + i), NodeFactory.createURI("http://predicate"), NodeFactory.createLiteral(Integer.toString(i), XSDDatatype.XSDinteger));
        Quad q = new Quad(t.getSubject(), t);
        driver.addInput(new LongWritable(i), new TripleWritable(t));
        driver.addOutput(new LongWritable(i), new QuadWritable(q));
    }
}
Also used : Triple(org.apache.jena.graph.Triple) Quad(org.apache.jena.sparql.core.Quad) TripleWritable(org.apache.jena.hadoop.rdf.types.TripleWritable) QuadWritable(org.apache.jena.hadoop.rdf.types.QuadWritable) LongWritable(org.apache.hadoop.io.LongWritable)

Example 14 with QuadWritable

use of org.apache.jena.hadoop.rdf.types.QuadWritable in project jena by apache.

the class TriplesToQuadsConstantGraphMapperTest method triples_to_quads_mapper_01.

/**
     * Tests quads to triples conversion
     * 
     * @throws IOException
     */
@Test
public void triples_to_quads_mapper_01() throws IOException {
    MapDriver<LongWritable, TripleWritable, LongWritable, QuadWritable> driver = this.getMapDriver();
    Triple t = new Triple(NodeFactory.createURI("http://s"), NodeFactory.createURI("http://p"), NodeFactory.createLiteral("test"));
    Quad q = new Quad(Quad.defaultGraphNodeGenerated, t);
    driver.withInput(new Pair<LongWritable, TripleWritable>(new LongWritable(1), new TripleWritable(t))).withOutput(new Pair<LongWritable, QuadWritable>(new LongWritable(1), new QuadWritable(q)));
    driver.runTest();
}
Also used : Triple(org.apache.jena.graph.Triple) TripleWritable(org.apache.jena.hadoop.rdf.types.TripleWritable) Quad(org.apache.jena.sparql.core.Quad) QuadWritable(org.apache.jena.hadoop.rdf.types.QuadWritable) LongWritable(org.apache.hadoop.io.LongWritable) Pair(org.apache.hadoop.mrunit.types.Pair) Test(org.junit.Test)

Example 15 with QuadWritable

use of org.apache.jena.hadoop.rdf.types.QuadWritable in project jena by apache.

the class QuadsToTriplesMapperTest method generateData.

protected void generateData(MapDriver<LongWritable, QuadWritable, LongWritable, TripleWritable> driver, int num) {
    for (int i = 0; i < num; i++) {
        Triple t = new Triple(NodeFactory.createURI("http://subjects/" + i), NodeFactory.createURI("http://predicate"), NodeFactory.createLiteral(Integer.toString(i), XSDDatatype.XSDinteger));
        Quad q = new Quad(Quad.defaultGraphNodeGenerated, t);
        driver.addInput(new LongWritable(i), new QuadWritable(q));
        driver.addOutput(new LongWritable(i), new TripleWritable(t));
    }
}
Also used : Triple(org.apache.jena.graph.Triple) Quad(org.apache.jena.sparql.core.Quad) TripleWritable(org.apache.jena.hadoop.rdf.types.TripleWritable) QuadWritable(org.apache.jena.hadoop.rdf.types.QuadWritable) LongWritable(org.apache.hadoop.io.LongWritable)

Aggregations

QuadWritable (org.apache.jena.hadoop.rdf.types.QuadWritable)15 Quad (org.apache.jena.sparql.core.Quad)12 LongWritable (org.apache.hadoop.io.LongWritable)8 Triple (org.apache.jena.graph.Triple)8 TripleWritable (org.apache.jena.hadoop.rdf.types.TripleWritable)8 Test (org.junit.Test)5 IOException (java.io.IOException)3 Pair (org.apache.hadoop.mrunit.types.Pair)3 ArrayList (java.util.ArrayList)2 NullWritable (org.apache.hadoop.io.NullWritable)2 Node (org.apache.jena.graph.Node)2 StringWriter (java.io.StringWriter)1 Configuration (org.apache.hadoop.conf.Configuration)1 Tuple (org.apache.jena.atlas.lib.tuple.Tuple)1 NodeTupleWritable (org.apache.jena.hadoop.rdf.types.NodeTupleWritable)1 NodeWritable (org.apache.jena.hadoop.rdf.types.NodeWritable)1