Package edu.stanford.nlp.sempre

Examples of edu.stanford.nlp.sempre.FeatureVector


class EditDistance implements FeatureSimilarityComputer {
  @Override
  public void computeSimilarity(ParaphraseExample ex, Params params) {
    ex.ensureAnnotated();
    int editDistance = ParaphraseUtils.editDistance(ex.sourceInfo.lemmaTokens, ex.targetInfo.lemmaTokens);
    FeatureVector fv = new FeatureVector();
    fv.add("EditDistance", "distance", (double) editDistance);
    ex.setVectorSpaceSimilarity(new FeatureSimilarity(fv,ex.source,ex.target,params));
  }
View Full Code Here


  @Override
  public void computeSimilarity(ParaphraseExample ex, Params params) {
   
    ex.ensureAnnotated();
   
    FeatureVector fv = new FeatureVector();
    double precision = MathUtils.coverage(ex.sourceInfo.tokens, ex.targetInfo.tokens);
    double recall = MathUtils.coverage(ex.targetInfo.tokens, ex.sourceInfo.tokens);
    double f1 = (precision+recall<=0d)? 0d
        (2 * precision * recall) / (precision+recall);
    double lemmaPrecision = MathUtils.coverage(ex.sourceInfo.lemmaTokens, ex.targetInfo.lemmaTokens);
    double lemmaRecall = MathUtils.coverage(ex.targetInfo.lemmaTokens, ex.sourceInfo.lemmaTokens);
    addIfBetweenZeroAndOne(fv, "Wan", "precision", precision);
    addIfBetweenZeroAndOne(fv, "Wan", "recall", recall);
    addIfBetweenZeroAndOne(fv, "Wan", "f1", f1);
    addIfBetweenZeroAndOne(fv, "Wan", "lemmaPrecision", lemmaPrecision);
    addIfBetweenZeroAndOne(fv, "Wan", "lemmaRecall", lemmaRecall);
    fv.add("Wan", "lengthDiff", ex.sourceInfo.numTokens()-ex.targetInfo.numTokens());
    fv.add("Wan", "AbsLengthDiff", Math.abs(ex.sourceInfo.numTokens()-ex.targetInfo.numTokens()));
    int editDistance = ParaphraseUtils.editDistance(ex.sourceInfo.tokens, ex.targetInfo.tokens);
    int lemmaEditDistance = ParaphraseUtils.editDistance(ex.sourceInfo.lemmaTokens, ex.targetInfo.lemmaTokens);
    fv.add("Wan", "editDistance", editDistance);
    fv.add("Wan", "lemmaEditDistance", lemmaEditDistance);
    double precisionBleu = MathUtils.bleu(ex.sourceInfo.tokens, ex.targetInfo.tokens);
    double recallBleu = MathUtils.bleu(ex.targetInfo.tokens, ex.sourceInfo.tokens);
    double lemmaPecisionBleu = MathUtils.bleu(ex.sourceInfo.lemmaTokens, ex.targetInfo.lemmaTokens);
    double lemmaRecallBleu = MathUtils.bleu(ex.targetInfo.lemmaTokens, ex.sourceInfo.lemmaTokens);
    addIfBetweenZeroAndOne(fv, "Wan", "precisionBlue", precisionBleu);
View Full Code Here

    this.target=target;
    this.score=score;
  }

  public FeatureSimilarity copy() {
    FeatureVector newFv = new FeatureVector();
    newFv.add(featureVector);
    return new FeatureSimilarity(newFv, source, target, score);
  }
View Full Code Here

  private FeatureVector featurizeSubstitutedSpan(Interval antecedentInterval,
      Interval targetInterval, LanguageInfo antecedent,
      LanguageInfo target) {

    FeatureVector res = new FeatureVector();
    String antecedentLemmas = antecedent.lemmaPhrase(antecedentInterval.start, antecedentInterval.end);
    String targetLemmas = target.lemmaPhrase(targetInterval.start, targetInterval.end);

    if(ParaphraseFeatureMatcher.containsDomain(SUBST)) {
      int editDist = StringUtils.editDistance(antecedentLemmas, targetLemmas);
      boolean prefix = antecedentLemmas.startsWith(targetLemmas) || targetLemmas.startsWith(antecedentLemmas);
      res.add(SUBST, "l="+antecedentLemmas+",r="+targetLemmas);
      res.add(SUBST, "l_pos="+antecedent.posSeq(antecedentInterval.start, antecedentInterval.end)+
          ",r_pos="+target.posSeq(targetInterval.start, targetInterval.end));
      if(editDist==0)
        res.add(SUBST, "dist=0");
      else if(editDist<4)
        res.add(SUBST, "dist="+editDist);
      else
        res.add(SUBST, "dist>3");
      if(prefix)
        res.add(SUBST, "prefix");
    }
    return res;
  }
View Full Code Here

    return res;
  }

  private FeatureVector featurizeMovedSpan(LanguageInfo antecedent,
      Interval matchedInterval) {
    FeatureVector res = new FeatureVector();

    if(ParaphraseFeatureMatcher.containsDomain(MOVE)) {
      res.add(MOVE,"lemmas="+antecedent.lemmaPhrase(matchedInterval.start, matchedInterval.end));
      res.add(MOVE,"pos="+antecedent.posSeq(matchedInterval.start, matchedInterval.end));
      res.add(MOVE,"ner="+antecedent.nerSeq(matchedInterval.start, matchedInterval.end));
    }
    return res;
  }
View Full Code Here

  private FeatureVector featureizePhraseTablespan(String lemmaPhrase,
      String rhsLemmaSpan, AlignmentStats count, LanguageInfo antecedent, int matchStart,
      int matchEnd, LanguageInfo target, int targetStart, int targetEnd) {

    FeatureVector res = new FeatureVector();
    if(ParaphraseFeatureMatcher.containsDomain(PHRASE_TABLE)) {
      res.add(SUBST, "l="+lemmaPhrase+",r="+rhsLemmaSpan);
      res.add(SUBST, "l_pos="+antecedent.posSeq(matchStart, matchEnd)+",r_pos="+target.posSeq(targetStart, targetEnd));
      //res.add(PHRASE_TABLE, "PtScore", Math.log(count+1));
    }
    return res;
  }
View Full Code Here

TOP

Related Classes of edu.stanford.nlp.sempre.FeatureVector

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.