/** * Creates a new instance and reads its data from the given input * * @param input * Input * @return New instance * @throws IOException */ public static CharacteristicSetWritable read(DataInput input) throws IOException { CharacteristicSetWritable set = new CharacteristicSetWritable(); set.readFields(input); return set; }
/** * Adds the contents of the other characteristic set to this characteristic * set * * @param set * Characteristic set */ public void add(CharacteristicSetWritable set) { this.increment(set.getCount().get()); Iterator<CharacteristicWritable> iter = set.getCharacteristics(); while (iter.hasNext()) { this.add(iter.next()); } }
/** * Gets whether the set contains a characteristic for the given predicate * * @param n * Predicate * @return True if contained in the set, false otherwise */ public boolean hasCharacteristic(Node n) { return this.hasCharacteristic(new NodeWritable(n)); }
@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()); } }
@Override public int hashCode() { // Build a hash code from characteristics if (this.characteristics.size() == 0) return 0; Iterator<CharacteristicWritable> iter = this.getCharacteristics(); int hash = 17; while (iter.hasNext()) { hash = hash * 31 + iter.next().hashCode(); } return hash; }
/** * Test characteristic set reduction * * @throws IOException */ @Test public void characteristic_set_reducer_06() throws IOException { MapReduceDriver<CharacteristicSetWritable, CharacteristicSetWritable, CharacteristicSetWritable, CharacteristicSetWritable, CharacteristicSetWritable, NullWritable> driver = this .getMapReduceDriver(); this.createSet(driver, 2, 1, "http://predicate", "http://other"); this.createSet(driver, 1, 1, "http://other"); driver.runTest(false); driver = getMapReduceDriver(); createSet(driver, 2, 1, "http://predicate", "http://other"); 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.hasCharacteristic("http://predicate"); Assert.assertEquals(expectTwo ? 2 : 1, cw.getCount().get()); } } }
/** * 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()); } }
/** * Adds some characteristics to the set merging them with the appropriate * existing characteristics if applicable * * @param characteristics */ public void add(CharacteristicWritable... characteristics) { for (CharacteristicWritable characteristic : characteristics) { this.add(characteristic); } }
CharacteristicWritable[] result, Context context) throws IOException, InterruptedException { if (len == 0) { CharacteristicSetWritable set = new CharacteristicSetWritable(result); context.write(set, NullWritable.get()); if (this.tracing) {
/** * 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()); }
@Override public boolean equals(Object other) { if (!(other instanceof CharacteristicSetWritable)) return false; return this.compareTo((CharacteristicSetWritable) other) == 0; }
if (perSet == 1) { for (CharacteristicWritable c : cs) { CharacteristicSetWritable set = new CharacteristicSetWritable(c); context.write(set, NullWritable.get()); if (this.tracing) { CharacteristicSetWritable set = new CharacteristicSetWritable(); for (CharacteristicWritable c : cs) { set.add(c);
@Override public int hashCode() { // Build a hash code from characteristics if (this.characteristics.size() == 0) return 0; Iterator<CharacteristicWritable> iter = this.getCharacteristics(); int hash = 17; while (iter.hasNext()) { hash = hash * 31 + iter.next().hashCode(); } return hash; }
/** * Adds some characteristics to the set merging them with the appropriate * existing characteristics if applicable * * @param characteristics */ public void add(CharacteristicWritable... characteristics) { for (CharacteristicWritable characteristic : characteristics) { this.add(characteristic); } }
@Override public boolean equals(Object other) { if (!(other instanceof CharacteristicSetWritable)) return false; return this.compareTo((CharacteristicSetWritable) other) == 0; }
/** * Creates a set consisting of the given predicates * * @param predicates * Predicates * @return Set */ protected CharacteristicSetWritable createSet(MapReduceDriver<LongWritable, T, NodeWritable, T, CharacteristicSetWritable, NullWritable> driver, int occurrences, String... predicates) { CharacteristicSetWritable set = new CharacteristicSetWritable(); for (String predicateUri : predicates) { set.add(new CharacteristicWritable(NodeFactory.createURI(predicateUri))); } for (int i = 1; i <= occurrences; i++) { driver.addOutput(set, NullWritable.get()); } return set; }
/** * Adds the contents of the other characteristic set to this characteristic * set * * @param set * Characteristic set */ public void add(CharacteristicSetWritable set) { this.increment(set.getCount().get()); Iterator<CharacteristicWritable> iter = set.getCharacteristics(); while (iter.hasNext()) { this.add(iter.next()); } }
/** * Creates a new instance and reads its data from the given input * * @param input * Input * @return New instance * @throws IOException */ public static CharacteristicSetWritable read(DataInput input) throws IOException { CharacteristicSetWritable set = new CharacteristicSetWritable(); set.readFields(input); return set; }
@Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append("{ "); builder.append(this.count.get()); Iterator<CharacteristicWritable> iter = this.getCharacteristics(); while (iter.hasNext()) { builder.append(" , "); builder.append(iter.next().toString()); } builder.append(" }"); return builder.toString(); }
/** * Gets whether the set contains a characteristic for the given predicate * * @param uri * Predicate URI * @return True if contained in the set, false otherwise */ public boolean hasCharacteristic(String uri) { return this.hasCharacteristic(NodeFactory.createURI(uri)); }