Search in sources :

Example 1 with CharacteristicSetWritable

use of org.apache.jena.hadoop.rdf.types.CharacteristicSetWritable 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);
    }
}
Also used : CharacteristicSetWritable(org.apache.jena.hadoop.rdf.types.CharacteristicSetWritable) CharacteristicWritable(org.apache.jena.hadoop.rdf.types.CharacteristicWritable)

Example 2 with CharacteristicSetWritable

use of org.apache.jena.hadoop.rdf.types.CharacteristicSetWritable 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 CharacteristicSetWritable

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

the class CharacteristicSetReducerTest method characteristic_set_reducer_04.

/**
     * Test characteristic set reduction
     * 
     * @throws IOException
     */
@Test
public void characteristic_set_reducer_04() throws IOException {
    MapReduceDriver<CharacteristicSetWritable, CharacteristicSetWritable, CharacteristicSetWritable, CharacteristicSetWritable, CharacteristicSetWritable, NullWritable> driver = this.getMapReduceDriver();
    this.createSet(driver, 2, 1, "http://predicate");
    this.createSet(driver, 1, 1, "http://other");
    driver.runTest(false);
    driver = getMapReduceDriver();
    createSet(driver, 2, 1, "http://predicate");
    createSet(driver, 1, 1, "http://other");
    List<Pair<CharacteristicSetWritable, NullWritable>> results = driver.run();
    for (Pair<CharacteristicSetWritable, NullWritable> pair : results) {
        CharacteristicSetWritable cw = pair.getFirst();
        boolean expectTwo = cw.getCharacteristics().next().getNode().get().hasURI("http://predicate");
        Assert.assertEquals(expectTwo ? 2 : 1, cw.getCount().get());
    }
}
Also used : CharacteristicSetWritable(org.apache.jena.hadoop.rdf.types.CharacteristicSetWritable) NullWritable(org.apache.hadoop.io.NullWritable) Pair(org.apache.hadoop.mrunit.types.Pair) Test(org.junit.Test)

Example 4 with CharacteristicSetWritable

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

the class CharacteristicSetReducerTest method characteristic_set_reducer_02.

/**
     * Test characteristic set reduction
     * 
     * @throws IOException
     */
@Test
public void characteristic_set_reducer_02() throws IOException {
    MapReduceDriver<CharacteristicSetWritable, CharacteristicSetWritable, CharacteristicSetWritable, CharacteristicSetWritable, CharacteristicSetWritable, NullWritable> driver = this.getMapReduceDriver();
    this.createSet(driver, 2, 1, "http://predicate");
    driver.runTest(false);
    driver = getMapReduceDriver();
    createSet(driver, 2, 1, "http://predicate");
    List<Pair<CharacteristicSetWritable, NullWritable>> results = driver.run();
    CharacteristicSetWritable cw = results.get(0).getFirst();
    Assert.assertEquals(2, cw.getCount().get());
}
Also used : CharacteristicSetWritable(org.apache.jena.hadoop.rdf.types.CharacteristicSetWritable) NullWritable(org.apache.hadoop.io.NullWritable) Pair(org.apache.hadoop.mrunit.types.Pair) Test(org.junit.Test)

Example 5 with CharacteristicSetWritable

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

the class CharacteristicTests method checkRoundTrip.

/**
     * Checks that a writable round trips
     * 
     * @param set
     *            Characteristic set
     * @throws IOException
     */
private void checkRoundTrip(CharacteristicSetWritable set) throws IOException {
    // Test round trip
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    DataOutputStream output = new DataOutputStream(outputStream);
    set.write(output);
    ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
    DataInputStream input = new DataInputStream(inputStream);
    CharacteristicSetWritable actual = CharacteristicSetWritable.read(input);
    Assert.assertEquals(set, actual);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) CharacteristicSetWritable(org.apache.jena.hadoop.rdf.types.CharacteristicSetWritable) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream)

Aggregations

CharacteristicSetWritable (org.apache.jena.hadoop.rdf.types.CharacteristicSetWritable)15 Test (org.junit.Test)11 NullWritable (org.apache.hadoop.io.NullWritable)8 LongWritable (org.apache.hadoop.io.LongWritable)5 NodeWritable (org.apache.jena.hadoop.rdf.types.NodeWritable)5 CharacteristicWritable (org.apache.jena.hadoop.rdf.types.CharacteristicWritable)4 Pair (org.apache.hadoop.mrunit.types.Pair)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1