Search in sources :

Example 6 with TripleWritable

use of org.apache.jena.hadoop.rdf.types.TripleWritable 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));
    }
}
Also used : Triple(org.apache.jena.graph.Triple) Quad(org.apache.jena.sparql.core.Quad) TripleWritable(org.apache.jena.hadoop.rdf.types.TripleWritable) QuadWritable(org.apache.jena.hadoop.rdf.types.QuadWritable) LongWritable(org.apache.hadoop.io.LongWritable)

Example 7 with TripleWritable

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

the class TurtleBlankNodeOutputTests method generateTuples.

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

Example 8 with TripleWritable

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

the class HadoopRdfIORegistry method createTripleWriter.

/**
     * Tries to create a triple writer for the given language
     * 
     * @param lang
     *            Language
     * @param writer
     *            Writer
     * @param config
     *            Configuration
     * @return Triple writer if one is available
     * @throws IOException
     *             Thrown if a triple writer is not available or the given
     *             language does not support triple
     */
public static <TKey> RecordWriter<TKey, TripleWritable> createTripleWriter(Lang lang, Writer writer, Configuration config) throws IOException {
    if (lang == null)
        throw new IOException("Cannot create a triple 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.canWriteTriples())
        throw new IOException(lang.getName() + " does not support writing triples");
    RecordWriter<TKey, TripleWritable> rwriter = f.<TKey>createTripleWriter(writer, config);
    if (rwriter == null)
        throw new IOException("Registered factory for " + lang.getName() + " produced a null triples writer");
    return rwriter;
}
Also used : TripleWritable(org.apache.jena.hadoop.rdf.types.TripleWritable) IOException(java.io.IOException)

Example 9 with TripleWritable

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

the class HadoopRdfIORegistry method createTripleReader.

/**
     * Tries to create a triple reader for the given language
     * 
     * @param lang
     *            Language
     * @return Triple reader if one is available
     * @throws IOException
     *             Thrown if a triple reader is not available or the given
     *             language does not support triple
     */
public static RecordReader<LongWritable, TripleWritable> createTripleReader(Lang lang) throws IOException {
    if (lang == null)
        throw new IOException("Cannot create a triple reader for an undefined language");
    ReaderFactory f = readerFactories.get(lang);
    if (f == null)
        throw new IOException("No factory registered for language " + lang.getName());
    if (!f.canReadTriples())
        throw new IOException(lang.getName() + " does not support reading triples");
    RecordReader<LongWritable, TripleWritable> reader = f.createTripleReader();
    if (reader == null)
        throw new IOException("Registered factory for " + lang.getName() + " produced a null triples reader");
    return reader;
}
Also used : TripleWritable(org.apache.jena.hadoop.rdf.types.TripleWritable) IOException(java.io.IOException) LongWritable(org.apache.hadoop.io.LongWritable)

Example 10 with TripleWritable

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

the class TestDistinctTriples method distinct_triples_02.

@Test
public void distinct_triples_02() 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"));
    TripleWritable tw = new TripleWritable(t);
    for (int i = 0; i < 100; i++) {
        driver.addInput(new LongWritable(i), tw);
    }
    driver.addOutput(NullWritable.get(), tw);
    driver.runTest();
}
Also used : Triple(org.apache.jena.graph.Triple) TripleWritable(org.apache.jena.hadoop.rdf.types.TripleWritable) LongWritable(org.apache.hadoop.io.LongWritable) NullWritable(org.apache.hadoop.io.NullWritable) Test(org.junit.Test)

Aggregations

TripleWritable (org.apache.jena.hadoop.rdf.types.TripleWritable)18 Triple (org.apache.jena.graph.Triple)15 LongWritable (org.apache.hadoop.io.LongWritable)12 Test (org.junit.Test)9 QuadWritable (org.apache.jena.hadoop.rdf.types.QuadWritable)8 Quad (org.apache.jena.sparql.core.Quad)7 NullWritable (org.apache.hadoop.io.NullWritable)6 IOException (java.io.IOException)3 Pair (org.apache.hadoop.mrunit.types.Pair)3 ArrayList (java.util.ArrayList)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