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);
}
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);
}
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();
}
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());
}
}
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;
}
Aggregations