Пример #1
0
 public String[] srlTriplesFull(DiscriminativeFeatureIndexers featureIndexers) {
   String[] out = new String[srlTriples.length];
   for (int i = 0; i < srlTriples.length; i++) {
     String srlTriple =
         featureIndexers.getValueOfFeature(ExtractFeatures.FEAT_SRL_TRIPLES, srlTriples[i]);
     if (srlTriple.equals("0")) {
       out[i] = "U";
     } else {
       String[] srlTripleAr = srlTriple.split(",");
       String[] srlTriplePosAr =
           featureIndexers
               .getValueOfFeature(ExtractFeatures.FEAT_SRL_TRIPLES_POS, srlTriplesPos[i])
               .split(",");
       out[i] =
           String.format(
               "<%s,%s/%s,%s/%s>:%s",
               featureIndexers.getRole(Integer.valueOf(srlTripleAr[0])), // role
               featureIndexers.getWord(Integer.valueOf(srlTripleAr[1])),
               featureIndexers.getPos(Integer.valueOf(srlTriplePosAr[1])), // arg
               featureIndexers.getWord(Integer.valueOf(srlTripleAr[2])),
               featureIndexers.getPos(Integer.valueOf(srlTriplePosAr[2])), // pred
               argComplete.get(i));
     }
   }
   return out;
 }
Пример #2
0
 /**
  * Bigrams encode indices of trees, rather than the String representations themselves, i.e., "3
  * 56", denotes the prevElemTree indexed at position 3, and the elemTree at position 56 of their
  * corresponding indexers.
  *
  * @param input
  * @param unlex
  * @return
  */
 private String toStringBigram(
     String input, boolean unlex, DiscriminativeFeatureIndexers featureIndexers) {
   if (input.equals("0") || input.equals("U")) return "U";
   StringBuilder str = new StringBuilder();
   String[] inputAr = input.split(" ");
   if (inputAr[0].equals("U")) str.append(inputAr[0]);
   else {
     int prevId = Integer.valueOf(inputAr[0]);
     str.append(
         unlex
             ? featureIndexers.getValueOfFeature(ExtractFeatures.FEAT_PREV_ELEM_TREE_UNLEX, prevId)
             : featureIndexers.getValueOfFeature(ExtractFeatures.FEAT_PREV_ELEM_TREE, prevId));
   }
   str.append(" ");
   if (inputAr[1].equals("U")) {
     str.append(inputAr[1]);
   } else {
     int curId = Integer.valueOf(inputAr[1]);
     str.append(
         unlex
             ? featureIndexers.getValueOfFeature(ExtractFeatures.FEAT_ELEM_TREE_UNLEX, curId)
             : featureIndexers.getValueOfFeature(ExtractFeatures.FEAT_ELEM_TREE, curId));
   }
   return str.toString();
 }
Пример #3
0
 private String toStringFeatureWeight(
     int vecId,
     int featureId,
     DiscriminativeFeatureIndexers featureIndexers,
     DiscriminativeParams params) {
   return String.format(
       "%s\t:\t%s",
       featureIndexers.getValueOfFeature(vecId, featureId),
       params.getParamVecWeight(vecId, featureId));
 }
Пример #4
0
 public String toString(
     DiscriminativeFeatureIndexers featureIndexers, DiscriminativeParams params) {
   StringBuilder str = new StringBuilder();
   str.append(baselineScore)
       .append("\t:\t")
       .append(params.getParamVecWeight(ExtractFeatures.FEAT_BASELINE_SCORE, 0))
       .append("\n")
       .append(baselineWordScore)
       .append("\t:\t")
       .append(params.getParamVecWeight(ExtractFeatures.FEAT_BASELINE_WORD_SCORE, 0))
       .append("\n")
       .append(
           toStringFeatureWeight(
               ExtractFeatures.FEAT_ELEM_TREE, elemTree, featureIndexers, params))
       .append("\n")
       .append(
           toStringFeatureWeight(
               ExtractFeatures.FEAT_PREV_ELEM_TREE, prevElemTree, featureIndexers, params))
       .append("\n")
       .append(
           toStringBigram(
               featureIndexers.getValueOfFeature(
                   ExtractFeatures.FEAT_ELEM_TREE_BIGRAM, elemTreeBigram),
               false,
               featureIndexers))
       .append("\t:\t")
       .append(params.getParamVecWeight(ExtractFeatures.FEAT_ELEM_TREE_BIGRAM, elemTreeBigram))
       .append("\n")
       .append(
           toStringFeatureWeight(
               ExtractFeatures.FEAT_ELEM_TREE_UNLEX, elemTreeUnlex, featureIndexers, params))
       .append("\n")
       .append(
           toStringFeatureWeight(
               ExtractFeatures.FEAT_PREV_ELEM_TREE_UNLEX,
               prevElemTreeUnlex,
               featureIndexers,
               params))
       .append("\n")
       .append(
           toStringBigram(
               featureIndexers.getValueOfFeature(
                   ExtractFeatures.FEAT_ELEM_TREE_UNLEX_BIGRAM, elemTreeUnlexBigram),
               true,
               featureIndexers))
       .append("\t:\t")
       .append(
           params.getParamVecWeight(
               ExtractFeatures.FEAT_ELEM_TREE_UNLEX_BIGRAM, elemTreeUnlexBigram))
       .append("\n")
       .append(
           toStringFeatureWeight(
               ExtractFeatures.FEAT_INTEGRATION_POINT, integrationPoint, featureIndexers, params))
       .append("\n")
       .append(
           toStringIpTree(
               featureIndexers.getValueOfFeature(ExtractFeatures.FEAT_IP_ELEM_TREE, ipElemTree),
               false,
               featureIndexers))
       .append("\n")
       .append("\t:\t")
       .append(params.getParamVecWeight(ExtractFeatures.FEAT_IP_ELEM_TREE, ipElemTree))
       .append("\n")
       .append(
           toStringIpTree(
               featureIndexers.getValueOfFeature(ExtractFeatures.FEAT_IP_ELEM_TREE, ipElemTree),
               true,
               featureIndexers))
       .append("\n")
       .append("\t:\t")
       .append(params.getParamVecWeight(ExtractFeatures.FEAT_IP_ELEM_TREE_UNLEX, ipElemTreeUnlex))
       .append("\n");
   for (Integer srlTriple : srlTriples)
     str.append(
             toStringSrlTriple(
                 featureIndexers.getValueOfFeature(ExtractFeatures.FEAT_SRL_TRIPLES, srlTriple),
                 false,
                 featureIndexers))
         .append("\t:\t")
         .append(params.getParamVecWeight(ExtractFeatures.FEAT_SRL_TRIPLES, srlTriple))
         .append(", ");
   str.append("\n");
   for (Integer srlTriplePos : srlTriplesPos)
     str.append(
             toStringSrlTriple(
                 featureIndexers.getValueOfFeature(
                     ExtractFeatures.FEAT_SRL_TRIPLES_POS, srlTriplePos),
                 true,
                 featureIndexers))
         .append("\t:\t")
         .append(params.getParamVecWeight(ExtractFeatures.FEAT_SRL_TRIPLES_POS, srlTriplePos))
         .append(", ");
   //            str.append("\n").append(semanticScore);
   return str.toString();
 }