Search in sources :

Example 1 with NodeWritable

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

the class AbstractCharacteristicSetGeneratingReducer method reduce.

@Override
protected void reduce(NodeWritable key, Iterable<T> values, Context context) throws IOException, InterruptedException {
    Map<NodeWritable, CharacteristicWritable> characteristics = new TreeMap<NodeWritable, CharacteristicWritable>();
    // Firstly need to find individual characteristics
    Iterator<T> iter = values.iterator();
    while (iter.hasNext()) {
        T tuple = iter.next();
        NodeWritable predicate = this.getPredicate(tuple);
        if (characteristics.containsKey(predicate)) {
            characteristics.get(predicate).increment();
        } else {
            characteristics.put(predicate, new CharacteristicWritable(predicate.get()));
        }
    }
    // Then we need to produce all the possible characteristic sets based on
    // this information
    List<CharacteristicWritable> cs = new ArrayList<CharacteristicWritable>(characteristics.values());
    if (cs.size() == 0)
        return;
    for (int i = 1; i <= cs.size(); i++) {
        this.outputSets(cs, i, context);
    }
}
Also used : NodeWritable(org.apache.jena.hadoop.rdf.types.NodeWritable) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) CharacteristicWritable(org.apache.jena.hadoop.rdf.types.CharacteristicWritable)

Example 2 with NodeWritable

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

the class AbstractCharacteristicSetGeneratingReducerTests method characteristic_set_generating_reducer_01.

/**
     * Test basic characteristic set computation
     * 
     * @throws IOException
     */
@Test
public void characteristic_set_generating_reducer_01() throws IOException {
    MapReduceDriver<LongWritable, T, NodeWritable, T, CharacteristicSetWritable, NullWritable> driver = this.getMapReduceDriver();
    T tuple = this.createTuple(1, "http://predicate");
    driver.addInput(new LongWritable(1), tuple);
    this.createSet(driver, 1, "http://predicate");
    driver.runTest(false);
}
Also used : NodeWritable(org.apache.jena.hadoop.rdf.types.NodeWritable) CharacteristicSetWritable(org.apache.jena.hadoop.rdf.types.CharacteristicSetWritable) LongWritable(org.apache.hadoop.io.LongWritable) NullWritable(org.apache.hadoop.io.NullWritable) Test(org.junit.Test)

Example 3 with NodeWritable

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

the class AbstractNodeTupleGroupingMapper method map.

@Override
protected final void map(TKey key, T value, Context context) throws IOException, InterruptedException {
    NodeWritable newKey = this.selectKey(value);
    context.write(newKey, value);
}
Also used : NodeWritable(org.apache.jena.hadoop.rdf.types.NodeWritable)

Example 4 with NodeWritable

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

the class AbstractNodeTupleGroupingTests method generateData.

/**
     * Generates data for use in tests
     * 
     * @param driver
     *            Driver
     * @param num
     *            Number of tuples to generate
     */
protected void generateData(MapDriver<LongWritable, T, NodeWritable, T> driver, int num) {
    for (int i = 0; i < num; i++) {
        LongWritable inputKey = new LongWritable(i);
        T value = this.createValue(i);
        NodeWritable outputKey = this.getOutputKey(value);
        driver.addInput(inputKey, value);
        driver.addOutput(outputKey, value);
    }
}
Also used : NodeWritable(org.apache.jena.hadoop.rdf.types.NodeWritable) LongWritable(org.apache.hadoop.io.LongWritable)

Example 5 with NodeWritable

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

the class AbstractNodeTupleSplitToNodesTests method generateData.

/**
     * Generates data for use in tests
     * 
     * @param driver
     *            Driver
     * @param num
     *            Number of tuples to generate
     */
protected void generateData(MapDriver<LongWritable, T, LongWritable, NodeWritable> driver, int num) {
    for (int i = 0; i < num; i++) {
        LongWritable key = new LongWritable(i);
        T value = this.createValue(i);
        NodeWritable[] nodes = this.getNodes(value);
        driver.addInput(key, value);
        for (NodeWritable n : nodes) {
            driver.addOutput(key, n);
        }
    }
}
Also used : NodeWritable(org.apache.jena.hadoop.rdf.types.NodeWritable) LongWritable(org.apache.hadoop.io.LongWritable)

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