Package edu.stanford.nlp.sempre.paraphrase

Examples of edu.stanford.nlp.sempre.paraphrase.Interval


    private int end;
    private int lastItemMatched=0;

    public LangExpMatch(int start, int end) {
      itemMap = new ArrayList<Interval>();
      itemMap.add(new Interval(start,end));
      this.end = end;
    }
View Full Code Here


    }
   
    public LangExpMatch(LangExpMatch other) {
      itemMap = new ArrayList<Interval>();
      for(Interval otherInterval: other.itemMap)
        itemMap.add(new Interval(otherInterval.start, otherInterval.end));
     
      this.end = other.end;
      this.lastItemMatched = other.lastItemMatched;
    }
View Full Code Here

  public String toString() {
    return expressionTree.toString();
  }

  public boolean match(LanguageInfo utterance, int start, int end) {
    return match(utterance, start).contains(new Interval(start, end));
  }
View Full Code Here

      List<Interval> res = new ArrayList<Interval>();

      Set<Integer> currStates = new HashSet<Integer>();
      currStates.addAll(startStates);
      if(currStates.contains(numOfStates-1))
        res.add(new Interval(startIndex, startIndex));

      for(int i = startIndex; i < utterance.numTokens(); ++i) {
        Set<Integer> newStates = new HashSet<Integer>();
        for(Integer currState: currStates) {
          Map<LanguageExpToken,Set<Integer>> out = outgoingEdges[currState]; //could be NULL - allowed for efficiency
          if(out!=null) {
            for(LanguageExpToken langExpToken: out.keySet()) {
              if(matchLangExpTokenToLangInfo(langExpToken, utterance, i)) {
                newStates.addAll(out.get(langExpToken));
              }
            }
          }
        }
        currStates = newStates;
        if(currStates.contains(numOfStates-1)) //match
          res.add(new Interval(startIndex, i+1));
      }
      return res;
    }
View Full Code Here

    for(Object obj: rhs) {
      if(obj instanceof WordInfo) {
        res.addWordInfo(((WordInfo) obj));
      }
      else if(obj instanceof Integer) {
        Interval matchingInterval = match.get(((Integer) obj));
        res.addSpan(antecedent, matchingInterval.start, matchingInterval.end);
      }
      else
        throw new RuntimeException("Rhs should be a list of wordinfo or integer keys to intervals only");
    }
View Full Code Here

      String[] tokens = line.split("\t");
      if(!lemmaToInterval.containsKey(tokens[0]) || !lemmaToInterval.containsKey(tokens[1])) {
        numOfNoNounRules++;
        continue;
      }
      Interval interval1 = lemmaToInterval.get(tokens[0]);
      Interval interval2 = lemmaToInterval.get(tokens[1]);
      if(nounNounAlignment(tokens[2],interval1,interval2)) {
        List<String> question1 = Arrays.asList(tokens[0].split("\\s+"));
        List<String> question2 = Arrays.asList(tokens[1].split("\\s+"));
        Context context1 = new Context(question1, interval1);
        Context context2 = new Context(question2, interval2);
View Full Code Here

      String[] lemmas = tokens[3].split("\\s+");
      if(posTags.length!=lemmas.length) {
        numOfLinesWithDifferentNumberOfTokens++;
        continue;
      }
      Interval interval = getNounInterval(posTags);
      if(interval!=null) {
        if(opts.verbose>=3)
          LogInfo.logs("ParalexRules.populateLemmaToPos: a single noun=%s",line);
        lemmaToInterval.put(tokens[3], interval);
      }
View Full Code Here

    //if more than one noun return null
    for(int i = start+1; i < end; ++i) {
      if(!LanguageUtils.sameProperNounClass(posTags[i], posTags[i-1]))
        return null;
    }
    return new Interval(start, end);
  }
View Full Code Here

   * @return
   */
  private Interval getInterval(int[] alignment) {
    int state=0;
    int start=-1;
    Interval interval=null;
    
    for(int i=0; i < alignment.length; ++i) {
      if(state==0 && alignment[i]==-1) {
        state=1;
        start = i;
      }
      else if(state==1 && alignment[i]!=-1) {
        state=2;
        interval = new Interval(start, i);
      }
      else if(state==2 && alignment[i]==-1) {
        return null;
      }    
    }
    if(state==0)
      return new Interval(0, 0);
    if(state==1)
      return new Interval(start, alignment.length);
    return interval;  
  }
View Full Code Here

      return new Interval(start, alignment.length);
    return interval;  
  }
 
  public boolean isLegalSingleGap() {
    Interval sourceInterval = getSourceInterval();
    Interval targetInterval = getTargetInterval();
    if(sourceInterval==null || targetInterval==null)
      return false;
    if(sourceInterval.length()==0 || targetInterval.length()==0)
      return true;
    if(sourceInterval.start==0 && targetInterval.start==0)
      return true;
    if(sourceInterval.end==sourceAlignment.length && targetInterval.end==targetAlignment.length)
      return true;
View Full Code Here

TOP

Related Classes of edu.stanford.nlp.sempre.paraphrase.Interval

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.