public VIntWritable readVInt(VIntWritable iw) throws IOException {
   if (iw == null) {
     iw = new VIntWritable();
   }
   iw.set(in.readInt());
   return iw;
 }
  @Override
  protected void reduce(TaggedItem<KeyType> key, Iterable<VIntWritable> values, Context context)
      throws IOException, InterruptedException {
    Set<Integer> that = Sets.newHashSet();
    for (VIntWritable tag : values) {
      that.add(tag.get());
    }

    if (that.contains(1) & !that.contains(2)) {
      context.write(D, key.getKey());
    }

    if (!that.contains(1) & that.contains(2)) {
      context.write(A, key.getKey());
    }
  }
Exemple #3
0
  @Override
  public Map.Entry<Text, Text> splitValue(Writable writable, VIntWritable tag) {
    Text that = (Text) writable;
    int tagValue = tag.get();
    String line = that.toString();

    if (tagValue < 3) {
      if (line.startsWith("#")) return null;

      String subject;
      String predicate;
      String object;

      Iterator<String> parts = WHITESPACE_SPLITTER.split(line).iterator();
      try {
        subject = parts.next();
        predicate = parts.next();
        object = parts.next();
      } catch (NoSuchElementException ex) {
        return null;
      }

      if (tagValue == 1) {
        return immutableEntry(new Text(subject), new Text(""));
      } else if (tagValue == 2) {
        return immutableEntry(new Text(subject), new Text(object));
      }
    }

    Iterator<String> parts = WHITESPACE_SPLITTER.split(line).iterator();
    String label;
    String name;
    String score;
    try {
      label = parts.next();
      name = parts.next();
      score = parts.next();
    } catch (NoSuchElementException ex) {
      return null;
    }

    if (!label.equals("en")) return null;

    StringBuilder uri = new StringBuilder();
    uri.append("<");
    uri.append("http://dbpedia.org/resource/");
    uri.append(name);
    uri.append(">");

    return immutableEntry(new Text(uri.toString()), new Text(score));
  }