Search in sources :

Example 6 with QuadWritable

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

the class RdfTypesTest method quad_writable_02.

/**
     * Basic quad writable round tripping test
     * 
     * @throws IOException
     * @throws InstantiationException
     * @throws IllegalAccessException
     * @throws ClassNotFoundException
     */
@Test
public void quad_writable_02() throws IOException, InstantiationException, IllegalAccessException, ClassNotFoundException {
    Quad q = new Quad(Quad.defaultGraphNodeGenerated, NodeFactory.createBlankNode(), NodeFactory.createURI("http://predicate"), NodeFactory.createLiteral("value"));
    QuadWritable qw = new QuadWritable(q);
    testWriteRead(qw, qw);
}
Also used : Quad(org.apache.jena.sparql.core.Quad) QuadWritable(org.apache.jena.hadoop.rdf.types.QuadWritable) Test(org.junit.Test)

Example 7 with QuadWritable

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

the class RdfTypesTest method quad_writable_01.

/**
     * Basic quad writable round tripping test
     * 
     * @throws IOException
     * @throws InstantiationException
     * @throws IllegalAccessException
     * @throws ClassNotFoundException
     */
@Test
public void quad_writable_01() throws IOException, InstantiationException, IllegalAccessException, ClassNotFoundException {
    Quad q = new Quad(Quad.defaultGraphNodeGenerated, NodeFactory.createURI("http://example"), NodeFactory.createURI("http://predicate"), NodeFactory.createLiteral("value"));
    QuadWritable qw = new QuadWritable(q);
    testWriteRead(qw, qw);
}
Also used : Quad(org.apache.jena.sparql.core.Quad) QuadWritable(org.apache.jena.hadoop.rdf.types.QuadWritable) Test(org.junit.Test)

Example 8 with QuadWritable

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

the class TriGBlankNodeOutputTests method generateTuples.

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

Example 9 with QuadWritable

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

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

the class HadoopRdfIORegistry method createQuadWriter.

/**
     * Tries to create a quad writer for the given language
     * 
     * @param lang
     *            Language
     * @param writer
     *            Writer
     * @param config
     *            Configuration
     * 
     * @return Quad writer if one is available
     * @throws IOException
     *             Thrown if a quad writer is not available or the given
     *             language does not support quads
     */
public static <TKey> RecordWriter<TKey, QuadWritable> createQuadWriter(Lang lang, Writer writer, Configuration config) throws IOException {
    if (lang == null)
        throw new IOException("Cannot create a quad writer for an undefined language");
    WriterFactory f = writerFactories.get(lang);
    if (f == null)
        throw new IOException("No factory registered for language " + lang.getName());
    if (!f.canWriteQuads())
        throw new IOException(lang.getName() + " does not support writeing quads");
    RecordWriter<TKey, QuadWritable> rwriter = f.<TKey>createQuadWriter(writer, config);
    if (rwriter == null)
        throw new IOException("Registered factory for " + lang.getName() + " produced a null triples writer");
    return rwriter;
}
Also used : QuadWritable(org.apache.jena.hadoop.rdf.types.QuadWritable) IOException(java.io.IOException)

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