@Override
  public Object call() {

    try {

      F2SF f = para;

      short[] pos = is.pposs[i];
      int length = pos.length;

      long[] gvs = new long[50];
      long[] svs = new long[220];

      while (true) {

        DSet set = get();
        if (set == null) {
          break;
        }

        int w1 = set.w1;
        int w2 = set.w2;

        f.clear();
        extractor.basic(pos, w1, w2, f);
        d.pl[w1][w2] = f.getScoreF();

        f.clear();

        extractor.basic(pos, w2, w1, f);
        d.pl[w2][w1] = f.getScoreF();

        short[] labels = Edges.get(pos[w1], pos[w2]);
        float[] lab = d.lab[w1][w2];

        final Long2IntInterface li = extractor.li;

        int c = extractor.firstm(is, i, w1, w2, 0, cluster, svs);

        for (int l = 0; l < lab.length; l++) {
          lab[l] = -100;
        }

        for (int l = 0; l < labels.length; l++) {
          short label = labels[l];

          f.clear();
          int lv = extractor.d0.computeLabeValue(label, Extractor.s_type);
          for (int k = 0; k < c; k++) {
            if (svs[k] > 0) {
              f.add(li.l2i(svs[k] + lv));
            }
          }

          lab[label] = f.getScoreF();
        }

        labels = Edges.get(pos[w2], pos[w1]);
        lab = d.lab[w2][w1];

        for (int l = 0; l < lab.length; l++) {
          lab[l] = -100;
        }

        for (int l = 0; l < labels.length; l++) {
          int label = labels[l];

          f.clear();
          int lv = extractor.d0.computeLabeValue(label + Extractor.s_rel1, Extractor.s_type);
          for (int k = 0; k < c; k++) {
            if (svs[k] > 0) {
              f.add(li.l2i(svs[k] + lv));
            }
          }

          lab[label] = f.getScoreF();
        }

        int s = w1 < w2 ? w1 : w2;
        int e = w1 < w2 ? w2 : w1;

        for (int m = 0; m < length; m++) {

          int g = (m == s || e == m) ? -1 : m;

          int cn = extractor.second(is, i, w1, w2, g, 0, cluster, svs);
          int cc = extractor.addClusterFeatures(is, i, w1, w2, g, cluster, 0, gvs, 0);
          // for(int k=0;k<c;k++) dl1.map(f,svs[k]);

          if (m >= w1) {
            labels = Edges.get(pos[w1], pos[w2]);
            float[] lab2 = new float[labels.length];
            for (int l = 0; l < labels.length; l++) {

              short label = labels[l];

              int lx = label + Extractor.s_rel1 * (g < w2 ? 0 : 2);

              f.clear();
              int lv = extractor.d0.computeLabeValue(lx, Extractor.s_type);
              for (int k = 0; k < cn; k++) {
                if (svs[k] > 0) {
                  f.add(li.l2i(svs[k] + lv));
                }
              }
              for (int k = 0; k < cc; k++) {
                if (gvs[k] > 0) {
                  f.add(li.l2i(gvs[k] + lv));
                }
              }

              lab2[l] = f.getScoreF();
            }
            d.gra[w1][w2][m] = lab2;
          }

          if (m <= w2) {
            labels = Edges.get(pos[w2], pos[w1]);
            float lab2[];
            d.gra[w2][w1][m] = lab2 = new float[labels.length];
            for (int l = 0; l < labels.length; l++) {

              int label = labels[l];
              int lx = label + Extractor.s_rel1 * (1 + (g < w1 ? 0 : 2));

              f.clear();
              int lv = extractor.d0.computeLabeValue(lx, Extractor.s_type);
              for (int k = 0; k < cn; k++) {
                if (svs[k] > 0) {
                  f.add(li.l2i(svs[k] + lv));
                }
              }
              for (int k = 0; k < cc; k++) {
                if (gvs[k] > 0) {
                  f.add(li.l2i(gvs[k] + lv));
                }
              }

              lab2[l] = f.getScoreF();
            }
          }

          g = (m == s || e == m) ? -1 : m;

          //	int cn = extractor.second(is,i,w1,w2,g,0, cluster, svs,Extractor._SIB);
          if (m >= w1 && m <= w2) {
            labels = Edges.get(pos[w1], pos[w2]);
            float lab2[] = new float[labels.length];
            d.sib[w1][w2][m] = lab2;

            for (int l = 0; l < labels.length; l++) {

              short label = labels[l];

              int lx = label + Extractor.s_rel1 * (8);
              f.clear();
              int lv = extractor.d0.computeLabeValue(lx, Extractor.s_type);
              for (int k = 0; k < cn; k++) {
                if (svs[k] > 0) {
                  f.add(li.l2i(svs[k] + lv));
                }
              }
              for (int k = 0; k < cc; k++) {
                if (gvs[k] > 0) {
                  f.add(li.l2i(gvs[k] + lv));
                }
              }

              lab2[l] = (float) f.score; // f.getScoreF();
            }
          }
          if (m >= w1 && m <= w2) {
            labels = Edges.get(pos[w2], pos[w1]);
            float[] lab2 = new float[labels.length];
            d.sib[w2][w1][m] = lab2;
            for (int l = 0; l < labels.length; l++) {

              int label = labels[l];

              int lx = label + Extractor.s_rel1 * (9);

              f.clear();
              int lv = extractor.d0.computeLabeValue(lx, Extractor.s_type);
              for (int k = 0; k < cn; k++) {
                if (svs[k] > 0) {
                  f.add(li.l2i(svs[k] + lv));
                }
              }
              for (int k = 0; k < cc; k++) {
                if (gvs[k] > 0) {
                  f.add(li.l2i(gvs[k] + lv));
                }
              }

              lab2[l] = f.score; // f.getScoreF();
            }
          }
        }
      }

    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }
예제 #2
0
  public void createInstances(String file, Instances is)
        //	throws Exception

      {

    CONLLReader09 depReader = new CONLLReader09(file);

    mf.register(REL, "<root-type>");

    // register at least one predicate since the parsing data might not contain predicates as in
    // the Japaness corpus but the development sets contains some

    long sl = 0;

    System.out.print("Registering feature parts of sentence: ");
    int ic = 0;
    int del = 0;
    while (true) {
      SentenceData09 instance = depReader.getNext();
      if (instance == null) break;
      ic++;

      sl += instance.labels.length;

      if (ic % 1000 == 0) {
        del = outValue(ic, del);
      }

      String[] labs1 = instance.labels;
      for (int i1 = 0; i1 < labs1.length; i1++) mf.register(REL, labs1[i1]);

      String[] w = instance.forms;
      for (int i1 = 0; i1 < w.length; i1++) mf.register(WORD, depReader.normalize(w[i1]));

      w = instance.plemmas;
      for (int i1 = 0; i1 < w.length; i1++) mf.register(WORD, depReader.normalize(w[i1]));

      w = instance.ppos;
      for (int i1 = 0; i1 < w.length; i1++) mf.register(POS, w[i1]);

      w = instance.gpos;
      for (int i1 = 0; i1 < w.length; i1++) mf.register(POS, w[i1]);

      if (instance.feats != null) {
        String fs[][] = instance.feats;
        for (int i1 = 0; i1 < fs.length; i1++) {
          w = fs[i1];
          if (w == null) continue;
          for (int i2 = 0; i2 < w.length; i2++) mf.register(FEAT, w[i2]);
        }
      }

      if ((ic - 1) > options.count) break;
    }
    del = outValue(ic, del);

    System.out.println();
    ExtractorReranker.initFeatures();

    ExtractorReranker.maxForm = mf.getFeatureCounter().get(WORD);

    if (options.clusterFile == null) cl = new Cluster();
    else cl = new Cluster(options.clusterFile, mf, 6);

    mf.calculateBits();
    extractor.initStat();

    System.out.println("" + mf.toString());

    extractor.init();
    depReader.startReading(file);

    int num1 = 0;

    is.init(ic, new MFB());

    Edges.init(mf.getFeatureCounter().get(POS));

    del = 0;

    del = outValue(num1, del);
    System.out.println();
  }