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