Beispiel #1
0
  public void save(Writer writer) throws IOException {
    writer.write(RefineServlet.VERSION);
    writer.write('\n');

    Properties options = new Properties();
    options.setProperty("mode", "save");
    options.put("pool", this);

    Collection<Recon> recons2 = recons.values();
    writer.write("reconCount=" + recons2.size());
    writer.write('\n');

    for (Recon recon : recons2) {
      JSONWriter jsonWriter = new JSONWriter(writer);
      try {
        recon.write(jsonWriter, options);

        writer.write('\n');
      } catch (JSONException e) {
        e.printStackTrace();
      }
    }
  }
  protected void extendRow(
      Row row, DataExtension dataExtension, int extensionRowIndex, Map<String, Recon> reconMap) {
    Object[] values = dataExtension.data[extensionRowIndex];
    for (int c = 0; c < values.length; c++) {
      Object value = values[c];
      Cell cell = null;

      if (value instanceof ReconCandidate) {
        ReconCandidate rc = (ReconCandidate) value;
        Recon recon;
        if (reconMap.containsKey(rc.id)) {
          recon = reconMap.get(rc.id);
        } else {

          if (rc.id.equals("")) {
            cell = new Cell(rc.name, null);
          } else {

            recon =
                new DBpediaDataExtensionReconConfig(new DBpediaType(rc.name, rc.id))
                    .createNewRecon(_historyEntryID);
            recon.addCandidate(rc);
            recon.service = "dbpedia-extension";
            recon.match = rc;
            recon.matchRank = 0;
            recon.judgment = Judgment.Matched;
            recon.judgmentAction = "auto";
            recon.judgmentBatchSize = 1;

            reconMap.put(rc.id, recon);
            cell = new Cell(rc.name, recon);
          }
        }

      } else {
        cell = new Cell((Serializable) value, null);
      }

      row.setCell(_firstNewCellIndex + c, cell);
    }
  }
  protected void extendRow(
      Row row, DataExtension dataExtension, int extensionRowIndex, Map<String, Recon> reconMap) {
    Object[] values = dataExtension.data[extensionRowIndex];
    for (int c = 0; c < values.length; c++) {
      Object value = values[c];
      Cell cell = null;

      if (value instanceof ReconCandidate) {
        ReconCandidate rc = (ReconCandidate) value;
        Recon recon;
        if (reconMap.containsKey(rc.id)) {
          recon = reconMap.get(rc.id);
        } else {
          if (rc.id.equals("")) {
            cell = new Cell(rc.name, null);
          } else {
            // TODO: maybe zemanta type will be needed
            // what if there are many types? - preview links?
            // maybe recon fields have to be populated with data from results
            recon = new ZemantaDataExtensionReconConfig().createNewRecon(_historyEntryID);
            recon.addCandidate(rc);
            recon.service = "zemanta";
            recon.match = rc;
            recon.matchRank = 0;
            recon.judgment = Judgment.Matched;
            recon.judgmentAction = "auto";
            recon.judgmentBatchSize = 1;

            reconMap.put(rc.id, recon);
            cell = new Cell(rc.name, recon);
          }
        }
      } else {
        cell = new Cell((Serializable) value, null);
      }

      row.setCell(_firstNewCellIndex + c, cell);
    }
  }
Beispiel #4
0
  public void load(Reader reader) throws Exception {
    LineNumberReader reader2 = new LineNumberReader(reader);

    /* String version = */ reader2.readLine();

    String line;
    while ((line = reader2.readLine()) != null) {
      int equal = line.indexOf('=');
      CharSequence field = line.subSequence(0, equal);
      String value = line.substring(equal + 1);

      if ("reconCandidateCount".equals(field)) {
        int count = Integer.parseInt(value);

        for (int i = 0; i < count; i++) {
          line = reader2.readLine();
          if (line != null) {
            ReconCandidate candidate = ReconCandidate.loadStreaming(line);
            if (candidate != null) {
              // pool for backward compatibility
              pool(candidate);
            }
          }
        }
      } else if ("reconCount".equals(field)) {
        int count = Integer.parseInt(value);

        for (int i = 0; i < count; i++) {
          line = reader2.readLine();
          if (line != null) {
            Recon recon = Recon.loadStreaming(line, this);
            if (recon != null) {
              pool(recon);
            }
          }
        }
      }
    }
  }