Search in sources :

Example 1 with QuadWritable

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

the class AbstractQuadOutputFormatTests method generateTuples.

@Override
protected Iterator<QuadWritable> generateTuples(int num) {
    List<QuadWritable> qs = new ArrayList<QuadWritable>();
    for (int i = 0; i < num; i++) {
        Quad q = new Quad(NodeFactory.createURI("http://example.org/graphs/" + i), NodeFactory.createURI("http://example.org/subjects/" + i), NodeFactory.createURI("http://example.org/predicate"), NodeFactory.createLiteral(Integer.toString(i), XSDDatatype.XSDinteger));
        qs.add(new QuadWritable(q));
    }
    return qs.iterator();
}
Also used : Quad(org.apache.jena.sparql.core.Quad) QuadWritable(org.apache.jena.hadoop.rdf.types.QuadWritable) ArrayList(java.util.ArrayList)

Example 2 with QuadWritable

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

the class TestHadoopRdfIORegistry method testLang.

private void testLang(Lang lang, boolean triples, boolean quads, boolean writesSupported) {
    Assert.assertEquals(triples, HadoopRdfIORegistry.hasTriplesReader(lang));
    Assert.assertEquals(quads, HadoopRdfIORegistry.hasQuadReader(lang));
    // Some formats may be asymmetric
    if (writesSupported) {
        Assert.assertEquals(triples, HadoopRdfIORegistry.hasTriplesWriter(lang));
        Assert.assertEquals(quads, HadoopRdfIORegistry.hasQuadWriter(lang));
    } else {
        Assert.assertFalse(HadoopRdfIORegistry.hasTriplesWriter(lang));
        Assert.assertFalse(HadoopRdfIORegistry.hasQuadWriter(lang));
    }
    if (triples) {
        // Check that triples are supported
        RecordReader<LongWritable, TripleWritable> tripleReader;
        try {
            tripleReader = HadoopRdfIORegistry.createTripleReader(lang);
            Assert.assertNotNull(tripleReader);
        } catch (IOException e) {
            Assert.fail("Registry indicates that " + lang.getName() + " can read triples but fails to produce a triple reader when asked: " + e.getMessage());
        }
        if (writesSupported) {
            RecordWriter<NullWritable, TripleWritable> tripleWriter;
            try {
                tripleWriter = HadoopRdfIORegistry.createTripleWriter(lang, new StringWriter(), new Configuration(false));
                Assert.assertNotNull(tripleWriter);
            } catch (IOException e) {
                Assert.fail("Registry indicates that " + lang.getName() + " can write triples but fails to produce a triple writer when asked: " + e.getMessage());
            }
        }
    } else {
        // Check that triples are not supported
        try {
            HadoopRdfIORegistry.createTripleReader(lang);
            Assert.fail("Registry indicates that " + lang.getName() + " cannot read triples but produced a triple reader when asked (error was expected)");
        } catch (IOException e) {
        // This is expected
        }
        try {
            HadoopRdfIORegistry.createTripleWriter(lang, new StringWriter(), new Configuration(false));
            Assert.fail("Registry indicates that " + lang.getName() + " cannot write triples but produced a triple write when asked (error was expected)");
        } catch (IOException e) {
        // This is expected
        }
    }
    if (quads) {
        // Check that quads are supported
        RecordReader<LongWritable, QuadWritable> quadReader;
        try {
            quadReader = HadoopRdfIORegistry.createQuadReader(lang);
            Assert.assertNotNull(quadReader);
        } catch (IOException e) {
            Assert.fail("Registry indicates that " + lang.getName() + " can read quads but fails to produce a quad reader when asked: " + e.getMessage());
        }
        if (writesSupported) {
            RecordWriter<NullWritable, QuadWritable> quadWriter;
            try {
                quadWriter = HadoopRdfIORegistry.createQuadWriter(lang, new StringWriter(), new Configuration(false));
                Assert.assertNotNull(quadWriter);
            } catch (IOException e) {
                Assert.fail("Registry indicates that " + lang.getName() + " can write quads but fails to produce a triple writer when asked: " + e.getMessage());
            }
        }
    } else {
        try {
            HadoopRdfIORegistry.createQuadReader(lang);
            Assert.fail("Registry indicates that " + lang.getName() + " cannot read quads but produced a quad reader when asked (error was expected)");
        } catch (IOException e) {
        // This is expected
        }
        try {
            HadoopRdfIORegistry.createQuadWriter(lang, new StringWriter(), new Configuration(false));
            Assert.fail("Registry indicates that " + lang.getName() + " cannot write quads but produced a quad writer when asked (error was expected)");
        } catch (IOException e) {
        // This is expected
        }
    }
}
Also used : TripleWritable(org.apache.jena.hadoop.rdf.types.TripleWritable) StringWriter(java.io.StringWriter) Configuration(org.apache.hadoop.conf.Configuration) QuadWritable(org.apache.jena.hadoop.rdf.types.QuadWritable) LongWritable(org.apache.hadoop.io.LongWritable) IOException(java.io.IOException) NullWritable(org.apache.hadoop.io.NullWritable)

Example 3 with QuadWritable

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

the class AbstractTriplesToQuadsMapper method map.

@Override
protected final void map(TKey key, TripleWritable value, Context context) throws IOException, InterruptedException {
    Triple triple = value.get();
    Node graphNode = this.selectGraph(triple);
    context.write(key, new QuadWritable(new Quad(graphNode, triple)));
}
Also used : Triple(org.apache.jena.graph.Triple) Quad(org.apache.jena.sparql.core.Quad) QuadWritable(org.apache.jena.hadoop.rdf.types.QuadWritable) Node(org.apache.jena.graph.Node)

Example 4 with QuadWritable

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

the class TriplesToQuadsBySubjectMapperTest 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(t.getSubject(), 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 5 with QuadWritable

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

the class TriplesToQuadsConstantGraphMapperTest 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(Quad.defaultGraphNodeGenerated, 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)

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