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