/** * Writes the given key * * @param key * Key */ protected void writeKey(NodeWritable key) { writeNode(key.get()); }
/** * Writes the given key * * @param key * Key */ protected void writeKey(NodeWritable key) { writeNode(key.get()); }
@Override public String toString() { // Use get() rather than accessing the field directly because the node // field is lazily instantiated from the Thrift term Node n = this.get(); if (n == null) return ""; return n.toString(); }
@Override public String toString() { // Use get() rather than accessing the field directly because the node // field is lazily instantiated from the Thrift term Node n = this.get(); if (n == null) return ""; return n.toString(); }
@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); } }
@Override public void readFields(DataInput input) throws IOException { // Determine how many nodes int size = WritableUtils.readVInt(input); Node[] ns = new Node[size]; NodeWritable nw = new NodeWritable(); for (int i = 0; i < ns.length; i++) { nw.readFields(input); ns[i] = nw.get(); } // Load the tuple this.tuple = this.createTuple(ns); }
@Override public void readFields(DataInput input) throws IOException { // Determine how many nodes int size = WritableUtils.readVInt(input); Node[] ns = new Node[size]; NodeWritable nw = new NodeWritable(); for (int i = 0; i < ns.length; i++) { nw.readFields(input); ns[i] = nw.get(); } // Load the tuple this.tuple = this.createTuple(ns); }
/** * Extracts the namespace from a node * <p> * Finds the URI for the node (if any) and then invokes * {@link #extractNamespace(String)} to extract the actual namespace URI. * </p> * <p> * Derived classes may override this to change the logic of how namespaces * are extracted. * </p> * * @param nw * Node * @return Namespace */ protected String extractNamespace(NodeWritable nw) { Node n = nw.get(); if (n.isBlank() || n.isVariable()) return NO_NAMESPACE; if (n.isLiteral()) { String dtUri = n.getLiteralDatatypeURI(); if (dtUri == null) return NO_NAMESPACE; return extractNamespace(dtUri); } return extractNamespace(n.getURI()); }
/** * 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()); } }