use of org.apache.jena.hadoop.rdf.types.CharacteristicWritable 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.CharacteristicWritable in project jena by apache.
the class AbstractCharacteristicSetGeneratingReducer method outputSets.
/**
* Output all sets of a given size
*
* @param cs
* Characteristics
* @param perSet
* Set size
* @param context
* Context to output sets to
* @throws IOException
* @throws InterruptedException
*/
protected void outputSets(List<CharacteristicWritable> cs, int perSet, Context context) throws IOException, InterruptedException {
if (perSet == 1) {
for (CharacteristicWritable c : cs) {
CharacteristicSetWritable set = new CharacteristicSetWritable(c);
context.write(set, NullWritable.get());
if (this.tracing) {
LOG.trace("Key = {}", set);
}
}
} else if (perSet == cs.size()) {
CharacteristicSetWritable set = new CharacteristicSetWritable();
for (CharacteristicWritable c : cs) {
set.add(c);
}
context.write(set, NullWritable.get());
if (this.tracing) {
LOG.trace("Key = {}", set);
}
} else {
CharacteristicWritable[] members = new CharacteristicWritable[perSet];
this.combinations(cs, perSet, 0, members, context);
}
}
use of org.apache.jena.hadoop.rdf.types.CharacteristicWritable in project jena by apache.
the class CharacteristicTests method checkRoundTrip.
/**
* Checks whether a writable round trips successfully
*
* @param cw
* Characteristic writable
* @throws IOException
*/
private void checkRoundTrip(CharacteristicWritable cw) throws IOException {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
DataOutputStream output = new DataOutputStream(outputStream);
cw.write(output);
ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
DataInputStream input = new DataInputStream(inputStream);
CharacteristicWritable actual = CharacteristicWritable.read(input);
Assert.assertEquals(cw, actual);
}
use of org.apache.jena.hadoop.rdf.types.CharacteristicWritable in project jena by apache.
the class CharacteristicTests method characteristic_set_writable_01.
/**
* Tests characteristic sets
*
* @throws IOException
*/
@Test
public void characteristic_set_writable_01() throws IOException {
CharacteristicSetWritable set = new CharacteristicSetWritable();
// Add some characteristics
CharacteristicWritable cw1 = new CharacteristicWritable(NodeFactory.createURI("http://example.org"));
CharacteristicWritable cw2 = new CharacteristicWritable(NodeFactory.createURI("http://example.org/other"));
set.add(cw1);
set.add(cw2);
this.checkCharacteristicSet(set, 2, new long[] { 1, 1 });
this.checkRoundTrip(set);
}
use of org.apache.jena.hadoop.rdf.types.CharacteristicWritable in project jena by apache.
the class CharacteristicTests method characteristic_writable_02.
/**
* Tests characteristic properties
*
* @throws IOException
*/
@Test
public void characteristic_writable_02() throws IOException {
Node n = NodeFactory.createURI("http://example.org");
CharacteristicWritable cw1 = new CharacteristicWritable(n);
CharacteristicWritable cw2 = new CharacteristicWritable(n, 100);
this.checkRoundTrip(cw1);
this.checkRoundTrip(cw2);
// Should still be equal since equality is only on the node not the
// count
Assert.assertEquals(cw1, cw2);
}
Aggregations