use of org.apache.jena.hadoop.rdf.types.TripleWritable in project jena by apache.
the class AbstractTripleOutputFormatTests method generateTuples.
@Override
protected Iterator<TripleWritable> generateTuples(int num) {
List<TripleWritable> ts = new ArrayList<TripleWritable>();
for (int i = 0; i < num; i++) {
Triple t = new Triple(NodeFactory.createURI("http://example.org/subjects/" + i), NodeFactory.createURI("http://example.org/predicate"), NodeFactory.createLiteral(Integer.toString(i), XSDDatatype.XSDinteger));
ts.add(new TripleWritable(t));
}
return ts.iterator();
}
use of org.apache.jena.hadoop.rdf.types.TripleWritable 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.TripleWritable in project jena by apache.
the class TestDistinctTriples method distinct_triples_03.
@Test
public void distinct_triples_03() throws IOException {
MapReduceDriver<LongWritable, TripleWritable, TripleWritable, NullWritable, NullWritable, TripleWritable> driver = this.getMapReduceDriver();
Triple t = new Triple(NodeFactory.createURI("urn:s"), NodeFactory.createURI("urn:p"), NodeFactory.createLiteral("1"));
Triple t2 = new Triple(t.getSubject(), t.getPredicate(), NodeFactory.createLiteral("2"));
Assert.assertNotEquals(t, t2);
TripleWritable tw = new TripleWritable(t);
TripleWritable tw2 = new TripleWritable(t2);
Assert.assertNotEquals(tw, tw2);
driver.addInput(new LongWritable(1), tw);
driver.addInput(new LongWritable(2), tw2);
driver.addOutput(NullWritable.get(), tw);
driver.addOutput(NullWritable.get(), tw2);
driver.runTest(false);
}
use of org.apache.jena.hadoop.rdf.types.TripleWritable in project jena by apache.
the class TestDistinctTriples method distinct_triples_04.
@Test
public void distinct_triples_04() throws IOException {
MapReduceDriver<LongWritable, TripleWritable, TripleWritable, NullWritable, NullWritable, TripleWritable> driver = this.getMapReduceDriver();
Node s1 = NodeFactory.createURI("urn:nf#cbf2b2c7-109e-4097-bbea-f67f272c7fcc");
Node s2 = NodeFactory.createURI("urn:nf#bb08b75c-1ad2-47ef-acd2-eb2d92b94b89");
Node p = NodeFactory.createURI("urn:p");
Node o = NodeFactory.createURI("urn:66.230.159.118");
Assert.assertNotEquals(s1, s2);
Triple t1 = new Triple(s1, p, o);
Triple t2 = new Triple(s2, p, o);
Assert.assertNotEquals(t1, t2);
TripleWritable tw1 = new TripleWritable(t1);
TripleWritable tw2 = new TripleWritable(t2);
Assert.assertNotEquals(tw1, tw2);
Assert.assertNotEquals(0, tw1.compareTo(tw2));
driver.addInput(new LongWritable(1), tw1);
driver.addInput(new LongWritable(2), tw2);
driver.addOutput(NullWritable.get(), tw1);
driver.addOutput(NullWritable.get(), tw2);
driver.runTest(false);
}
use of org.apache.jena.hadoop.rdf.types.TripleWritable 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();
}
Aggregations