コード例 #1
0
  public static void main(String[] args) throws IOException {

    InputStream is = new FileInputStream(input1);
    Relation r = null;

    while ((r = Relation.parseDelimitedFrom(is)) != null) {
      for (int i = 0; i < r.getMentionCount(); i++) {
        RelationMentionRef rmf = r.getMention(i);

        System.out.println(r.getSourceGuid() + "\t" + r.getDestGuid() + "\t" + r.getRelType());
      }
    }
    is.close();
  }
コード例 #2
0
 public static void analyzePbData(String pb) throws IOException {
   DelimitedWriter dw = new DelimitedWriter(pb + ".analyze");
   List<Relation> all = new ArrayList<Relation>();
   int numCases = 0;
   {
     HashCount<String> labelDist = new HashCount<String>();
     Relation r = null;
     PbReader pr = new PbReader(pb);
     while ((r = pr.read()) != null) {
       all.add(r);
       labelDist.add(r.getRelType());
       numCases++;
     }
     pr.close();
     dw.write("Label Distribution");
     Iterator<Entry<String, Integer>> it = labelDist.iterator();
     while (it.hasNext()) {
       Entry<String, Integer> e = it.next();
       dw.write(e.getKey(), e.getValue());
     }
   }
   Collections.shuffle(all);
   {
     HashCount<String> hassampled = new HashCount<String>();
     List<String[]> towrite = new ArrayList<String[]>();
     for (int i = 0; i < all.size(); i++) {
       Relation r = all.get(i);
       String rel = r.getRelType();
       if (hassampled.see(rel) < 10) {
         towrite.add(new String[] {rel, r.getSourceGuid(), r.getDestGuid()});
         hassampled.add(rel);
       }
     }
     StringTable.sortByColumn(towrite, new int[] {0});
     for (String[] w : towrite) {
       dw.write(w);
     }
   }
   dw.close();
 }