Search in sources :

Example 11 with TripleWritable

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

the class AbstractNodeWriter method writeValue.

/**
     * Writes the given value
     * <p>
     * If the value is one of the RDF primitives - {@link NodeWritable},
     * {@link TripleWritable}, {@link QuadWritable} and
     * {@link NodeTupleWritable} - then it is formatted as a series of nodes
     * separated by the separator. Otherwise it is formatted by simply calling
     * {@code toString()} on it.
     * </p>
     * 
     * @param value
     *            Values
     */
protected void writeValue(TValue value) {
    // Handle null specially
    if (value instanceof NullWritable || value == null)
        return;
    // Handle RDF primitives specially and format them as proper nodes
    if (value instanceof NodeWritable) {
        this.writeKey((NodeWritable) value);
    } else if (value instanceof TripleWritable) {
        Triple t = ((TripleWritable) value).get();
        this.writeNodes(t.getSubject(), t.getPredicate(), t.getObject());
    } else if (value instanceof QuadWritable) {
        Quad q = ((QuadWritable) value).get();
        this.writeNodes(q.getGraph(), q.getSubject(), q.getPredicate(), q.getObject());
    } else if (value instanceof NodeTupleWritable) {
        Tuple<Node> tuple = ((NodeTupleWritable) value).get();
        Node[] n = new Node[tuple.len()];
        tuple.copyInto(n);
        this.writeNodes(n);
    } else {
        // For arbitrary values just toString() them
        this.writer.write(value.toString());
    }
}
Also used : Triple(org.apache.jena.graph.Triple) NodeWritable(org.apache.jena.hadoop.rdf.types.NodeWritable) TripleWritable(org.apache.jena.hadoop.rdf.types.TripleWritable) Quad(org.apache.jena.sparql.core.Quad) QuadWritable(org.apache.jena.hadoop.rdf.types.QuadWritable) NullWritable(org.apache.hadoop.io.NullWritable) Tuple(org.apache.jena.atlas.lib.tuple.Tuple) NodeTupleWritable(org.apache.jena.hadoop.rdf.types.NodeTupleWritable)

Example 12 with TripleWritable

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

the class RdfTypesTest method triple_writable_01.

/**
     * Basic triple writable round tripping test
     * 
     * @throws IOException
     * @throws InstantiationException
     * @throws IllegalAccessException
     * @throws ClassNotFoundException
     */
@Test
public void triple_writable_01() throws IOException, InstantiationException, IllegalAccessException, ClassNotFoundException {
    Triple t = new Triple(NodeFactory.createURI("http://example"), NodeFactory.createURI("http://predicate"), NodeFactory.createLiteral("value"));
    TripleWritable tw = new TripleWritable(t);
    testWriteRead(tw, tw);
}
Also used : Triple(org.apache.jena.graph.Triple) TripleWritable(org.apache.jena.hadoop.rdf.types.TripleWritable) Test(org.junit.Test)

Example 13 with TripleWritable

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

the class RdfTypesTest method triple_writable_02.

/**
     * Basic triple writable round tripping test
     * 
     * @throws IOException
     * @throws InstantiationException
     * @throws IllegalAccessException
     * @throws ClassNotFoundException
     */
@Test
public void triple_writable_02() throws IOException, InstantiationException, IllegalAccessException, ClassNotFoundException {
    Triple t = new Triple(NodeFactory.createBlankNode(), NodeFactory.createURI("http://predicate"), NodeFactory.createLiteral("value"));
    TripleWritable tw = new TripleWritable(t);
    testWriteRead(tw, tw);
}
Also used : Triple(org.apache.jena.graph.Triple) TripleWritable(org.apache.jena.hadoop.rdf.types.TripleWritable) Test(org.junit.Test)

Example 14 with TripleWritable

use of org.apache.jena.hadoop.rdf.types.TripleWritable 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 15 with TripleWritable

use of org.apache.jena.hadoop.rdf.types.TripleWritable 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)

Aggregations

TripleWritable (org.apache.jena.hadoop.rdf.types.TripleWritable)18 Triple (org.apache.jena.graph.Triple)15 LongWritable (org.apache.hadoop.io.LongWritable)12 Test (org.junit.Test)9 QuadWritable (org.apache.jena.hadoop.rdf.types.QuadWritable)8 Quad (org.apache.jena.sparql.core.Quad)7 NullWritable (org.apache.hadoop.io.NullWritable)6 IOException (java.io.IOException)3 Pair (org.apache.hadoop.mrunit.types.Pair)3 ArrayList (java.util.ArrayList)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