Search in sources :

Example 6 with CharacteristicSetWritable

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

Example 7 with CharacteristicSetWritable

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

the class AbstractCharacteristicSetGeneratingReducer method combinations.

/**
     * Calculate all available combinations of N elements from the given
     * characteristics
     * 
     * @param cs
     *            Characteristics
     * @param len
     *            Desired number of elements
     * @param startPosition
     *            Start position
     * @param result
     *            Result array to fill
     * @param context
     *            Context to write completed combinations to
     * @throws IOException
     * @throws InterruptedException
     */
protected final void combinations(List<CharacteristicWritable> cs, int len, int startPosition, CharacteristicWritable[] result, Context context) throws IOException, InterruptedException {
    if (len == 0) {
        CharacteristicSetWritable set = new CharacteristicSetWritable(result);
        context.write(set, NullWritable.get());
        if (this.tracing) {
            LOG.trace("Key = {}", set);
        }
        return;
    }
    for (int i = startPosition; i <= cs.size() - len; i++) {
        result[result.length - len] = cs.get(i);
        combinations(cs, len - 1, i + 1, result, context);
    }
}
Also used : CharacteristicSetWritable(org.apache.jena.hadoop.rdf.types.CharacteristicSetWritable)

Example 8 with CharacteristicSetWritable

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

the class CharacteristicSetReducer method reduce.

@Override
protected void reduce(CharacteristicSetWritable key, Iterable<CharacteristicSetWritable> values, Context context) throws IOException, InterruptedException {
    Iterator<CharacteristicSetWritable> iter = values.iterator();
    CharacteristicSetWritable output = new CharacteristicSetWritable(0);
    if (this.tracing) {
        LOG.trace("Key = {}", key);
    }
    while (iter.hasNext()) {
        CharacteristicSetWritable set = iter.next();
        if (this.tracing) {
            LOG.trace("Value = {}", set);
        }
        output.add(set);
    }
    context.write(output, NullWritable.get());
}
Also used : CharacteristicSetWritable(org.apache.jena.hadoop.rdf.types.CharacteristicSetWritable)

Example 9 with CharacteristicSetWritable

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

the class CharacteristicTests method characteristic_set_writable_03.

/**
     * Tests characteristic sets
     * 
     * @throws IOException
     */
@Test
public void characteristic_set_writable_03() throws IOException {
    CharacteristicSetWritable set1 = new CharacteristicSetWritable();
    CharacteristicSetWritable set2 = new CharacteristicSetWritable();
    // Add some characteristics
    CharacteristicWritable cw1 = new CharacteristicWritable(NodeFactory.createURI("http://example.org"));
    CharacteristicWritable cw2 = new CharacteristicWritable(NodeFactory.createURI("http://example.org/other"));
    set1.add(cw1);
    set2.add(cw2);
    this.checkCharacteristicSet(set1, 1, new long[] { 1 });
    this.checkCharacteristicSet(set2, 1, new long[] { 1 });
    this.checkRoundTrip(set1);
    this.checkRoundTrip(set2);
    Assert.assertNotEquals(set1, set2);
}
Also used : CharacteristicSetWritable(org.apache.jena.hadoop.rdf.types.CharacteristicSetWritable) CharacteristicWritable(org.apache.jena.hadoop.rdf.types.CharacteristicWritable) Test(org.junit.Test)

Example 10 with CharacteristicSetWritable

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

the class CharacteristicTests method characteristic_set_writable_02.

/**
     * Tests characteristic sets
     * 
     * @throws IOException
     */
@Test
public void characteristic_set_writable_02() 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"), 2);
    set.add(cw1);
    set.add(cw2);
    this.checkCharacteristicSet(set, 1, new long[] { 3 });
    this.checkRoundTrip(set);
}
Also used : CharacteristicSetWritable(org.apache.jena.hadoop.rdf.types.CharacteristicSetWritable) CharacteristicWritable(org.apache.jena.hadoop.rdf.types.CharacteristicWritable) Test(org.junit.Test)

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