Search in sources :

Example 11 with NodeWritable

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

the class RdfTypesTest method node_writable_literal_07.

/**
     * Basic node writable round tripping test
     * 
     * @throws IOException
     * @throws InstantiationException
     * @throws IllegalAccessException
     * @throws ClassNotFoundException
     */
@Test
public void node_writable_literal_07() throws IOException, InstantiationException, IllegalAccessException, ClassNotFoundException {
    Node n = NodeFactory.createLiteral("true", XSDDatatype.XSDboolean);
    NodeWritable nw = new NodeWritable(n);
    testWriteRead(nw, nw);
}
Also used : NodeWritable(org.apache.jena.hadoop.rdf.types.NodeWritable) Node(org.apache.jena.graph.Node) Test(org.junit.Test)

Example 12 with NodeWritable

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

the class RdfTypesTest method node_writable_literal_04.

/**
     * Basic node writable round tripping test
     * 
     * @throws IOException
     * @throws InstantiationException
     * @throws IllegalAccessException
     * @throws ClassNotFoundException
     */
@Test
public void node_writable_literal_04() throws IOException, InstantiationException, IllegalAccessException, ClassNotFoundException {
    Node n = NodeFactory.createLiteral("1234", XSDDatatype.XSDinteger);
    NodeWritable nw = new NodeWritable(n);
    testWriteRead(nw, nw);
}
Also used : NodeWritable(org.apache.jena.hadoop.rdf.types.NodeWritable) Node(org.apache.jena.graph.Node) Test(org.junit.Test)

Example 13 with NodeWritable

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

the class TripleDataTypeCountMapper method getNodes.

@Override
protected NodeWritable[] getNodes(TripleWritable tuple) {
    Node object = tuple.get().getObject();
    if (!object.isLiteral())
        return EMPTY;
    String dtUri = object.getLiteralDatatypeURI();
    if (dtUri == null)
        return EMPTY;
    return new NodeWritable[] { new NodeWritable(NodeFactory.createURI(dtUri)) };
}
Also used : NodeWritable(org.apache.jena.hadoop.rdf.types.NodeWritable) Node(org.apache.jena.graph.Node)

Example 14 with NodeWritable

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

the class QuadDataTypeCountMapper method getNodes.

@Override
protected NodeWritable[] getNodes(QuadWritable tuple) {
    Node object = tuple.get().getObject();
    if (!object.isLiteral())
        return EMPTY;
    String dtUri = object.getLiteralDatatypeURI();
    if (dtUri == null)
        return EMPTY;
    return new NodeWritable[] { new NodeWritable(NodeFactory.createURI(dtUri)) };
}
Also used : NodeWritable(org.apache.jena.hadoop.rdf.types.NodeWritable) Node(org.apache.jena.graph.Node)

Example 15 with NodeWritable

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

Aggregations

NodeWritable (org.apache.jena.hadoop.rdf.types.NodeWritable)29 Test (org.junit.Test)19 Node (org.apache.jena.graph.Node)16 LongWritable (org.apache.hadoop.io.LongWritable)10 NullWritable (org.apache.hadoop.io.NullWritable)6 CharacteristicSetWritable (org.apache.jena.hadoop.rdf.types.CharacteristicSetWritable)5 Ignore (org.junit.Ignore)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 TreeMap (java.util.TreeMap)1 Tuple (org.apache.jena.atlas.lib.tuple.Tuple)1 Triple (org.apache.jena.graph.Triple)1 CharacteristicWritable (org.apache.jena.hadoop.rdf.types.CharacteristicWritable)1 NodeTupleWritable (org.apache.jena.hadoop.rdf.types.NodeTupleWritable)1 QuadWritable (org.apache.jena.hadoop.rdf.types.QuadWritable)1 TripleWritable (org.apache.jena.hadoop.rdf.types.TripleWritable)1 Quad (org.apache.jena.sparql.core.Quad)1