Package opennlp.ccg.lexicon

Examples of opennlp.ccg.lexicon.Word


        //Extract unbalanced punctuation feature for unbalanced sentence medial punctuation
        if (inputs.length == 2) {
          //Left child has unbalanced punct feature
          SignProps lchildProps=(SignProps)inputs[0].getData(SignProps.class);
          if(lchildProps!=null && lchildProps.getUnbalancedPunct()!=null){
            Word nextWord = inputs[1].getWords().get(0);
            //Check whether right child begins with a punctuation mark; else fire feature
            if (!isPunct(nextWord)){
              inc(punctExtractor);
            }
          }
View Full Code Here


      String cfeat = cls.substring(cls.indexOf(':') + 1);
      f.addFeatureWithProb("XC", cfeat);
    }
    // prior features
    if(priorModel != null) {
      Word w = Word.createWord(n.getPredicateName(), null, null, n.getPredicateName(),
          getPOS(n), null, null);
      priorModel.computePriors(w);
      List<Pair<String, Double>> tags = priorModel.getBetaBestPriors(w, priorBeta);
      for(Pair<String,Double> t : tags) {
        f.addFeatureWithProb("PR_ST", DefaultTokenizer.unescape(t.a), t.b);
View Full Code Here

    return out.toString();
  }

  public Word getPredAsWord(int idx) {
    LfGraphNode n = findNode(idx);
    Word w = Word.createWord(n.getPredicateName(), null, null, n.getPredicateName(),
        getPOS(n), getGoldSupertag(n), null);
    return w;
  }
View Full Code Here

    Word w = Word.createWord(n.getPredicateName(), null, null, n.getPredicateName(),
        getPOS(n), getGoldSupertag(n), null);
    return w;
  }
  private Word getPredAsWord() {
    Word w = Word.createWord(currentPred.getPredicateName(), null, null, currentPred.getPredicateName(), getPOS(currentPred), getGoldSupertag(currentPred), null);
    return w;
  }
View Full Code Here

 
  /** Sets the current words, if null, along with head indices. */
  protected void setCurrentWords() {
    if (currentWords != null) return;
    currentWords = currentSign.getWords();
    Word head = currentSign.getLexHead().getWords().get(0);
    Word sibHead = currentSibling.getLexHead().getWords().get(0);
    currentHeadIndex = find(currentWords, head);
    currentSibHeadIndex = find(currentWords, sibHead);
  }
View Full Code Here

        e.printStackTrace();
      }
      List<List<Pair<Double,String>>> lfTagging = new ArrayList<List<Pair<Double,String>>>();
      List<Word> gsTagging = new ArrayList<Word>();
      List<Pair<Double,String>> tags;
      Word w;
      for(int bi = 0; bi < ht.betas.length; bi++) {
        gsTagging = new ArrayList<Word>();
        lfTagging = new ArrayList<List<Pair<Double,String>>>();
        ht.setBetaIndex(bi);
        ht.tdErr = errFiles.get(bi);
        for(int i = 0; i < ht.maxIndex(); i++) {
          ht.setPred(i);
          if(ht.currentPred == null) {
            //System.err.println("Skipping null pred " + i);
            continue;
          }
          w = ht.getPredAsWord();
          tags = ht.getSupertagsAsList();
          lfTagging.add(tags);
          gsTagging.add(w);
          if(dump != null) {
            if(options.has("G") && w.getSupertag() != null) {
              dump.write(w.getSupertag() + " ");
            }
            dump.write(w.getForm() + " ");
            for(int j = 0; j < tags.size(); j++) {
              dump.write(tags.get(j).a + " " + tags.get(j).b + " ");
            }
            dump.write("\n");
          }
View Full Code Here

    setCurrentWords();
    int min = Math.min(currentHeadIndex, currentSibHeadIndex);
    int max = Math.max(currentHeadIndex, currentSibHeadIndex);
    int count = 0;
    for (int i=min+1; i < max; i++) {
      Word w = currentWords.get(i);
      if (isPunct(w)) count++;
    }
    switch (count) {
      case 0: return currentDistP = "0p";
      case 1: return currentDistP = "1p";
View Full Code Here

    setCurrentWords();
    int min = Math.min(currentHeadIndex, currentSibHeadIndex);
    int max = Math.max(currentHeadIndex, currentSibHeadIndex);
    int count = 0;
    for (int i=min+1; i < max; i++) {
      Word w = currentWords.get(i);
      if (isVerb(w)) count++;
    }
    switch (count) {
      case 0: return currentDistV = "0v";
      case 1: return currentDistV = "1v";
View Full Code Here

                 
                  Iterator<Word> sentiter = sent.iterator();
                  // output file format = word goldtag tag1 ... tagK                 
                  outf.write("<s>"+System.getProperty("line.separator"));
                  for(List<Pair<Double,String>> tagging : taggings) {                     
                      Word nextw = sentiter.next();
                      outf.write(nextw.getForm() + "\t1\t" + nextw.getPOS() + "\t1.0\t" + tagging.size() + "\t");// + nextw.getSupertag() + " ");
                      //outf.write(nextw.getForm() + "|||"+ nextw.getStem() + "|||" + nextw.getPOS() + "|||");
                      String tags = "";
                      for(Pair<Double,String> tg : tagging) {
                          //tags+="^"+tg.b+":"+tg.a;
                          tags+= "\t" + tg.b + "\t"+tg.a;
View Full Code Here

        for (int u = 0; u < observationSequence.size(); u++) {
            List<Pair<Double, String>> tw = observationSequence.get(u);
            double normTot = 0.0;
            // for each of its tags within the search beam.
            for (int v = 0; v < tw.size(); v++) {
                Word currTag = seqLabs.getCoord(u, v);
                List<Word> bestHist = null;
                Double seqScore = null;

                Double obsScore = initScores.getCoord(u, v);
                if (u == 0) {
                    // beginning of sequence.                   
                    bestHist = getBestHist(u, v, order);
                    bestHist.add(currTag);
                    seqScore = lmScore(bestHist);

                    double fs = seqScore + obsScore;

                    normTot += Math.exp(fs);
                    fbScores.setCoord(u, v, fs);
                } else {
                    // use dynamic programming-computed scores to progress.
                    List<Pair<Double, String>> prevTaggedWord = observationSequence.get(u - 1);
                    ProbIndexPair[] bestPrevScores = new ProbIndexPair[Math.min(prevTaggedWord.size(), searchBeam)];

                    for (int z = 0; z < Math.min(prevTaggedWord.size(), searchBeam); z++) {
                        bestHist = getBestHist(u - 1, z, order - 1);
                        bestHist.add(currTag);
                        seqScore = lmScore(bestHist);
                        double fs = fbScores.getCoord(u - 1, z) + seqScore;
                        fs += obsScore;                        
                        bestPrevScores[z] = new ProbIndexPair(
                                Double.valueOf(fs),
                                Integer.valueOf(z));

                    }

                    // sort descending based on score.
                    Arrays.sort(bestPrevScores);

                    // add up the prob's of all sequences leading to this node.
                    double fsum = 0.0;
                    for (int q = 0; q < bestPrevScores.length; q++) {
                        fsum += Math.exp(bestPrevScores[q].a);
                    }
                    normTot += fsum;
                    //fbScores.setCoord(u, v, bestPrevScores[0].a.doubleValue());
                    fbScores.setCoord(u, v, Math.log(fsum));

                    // add n-best backpointers.
                    List<Integer> bks = new ArrayList<Integer>(bestPrevScores.length);
                    for (int q = 0; q < bestPrevScores.length; q++) {
                        bks.add(bestPrevScores[q].b);
                    }
                    backPointers.setCoord(u, v, new Backpointer(bks));
                }
            }

            // normalise.           
            for (int v = 0; v < tw.size(); v++) {
                fbScores.setCoord(u, v, Math.log(Math.exp(fbScores.getCoord(u, v)) / normTot));
            }
        }

        // backward loop.
        int size = observationSequence.size();
        if (alg == Constants.TaggingAlgorithm.FORWARDBACKWARD) {
            // for each word...
            for (int u = size - 1; u >= 0; u--) {
                List<Pair<Double, String>> tw = observationSequence.get(u);
                double normTot = 0.0;
                // for each of its tags...
                for (int v = 0; v < tw.size(); v++) {
                    List<Word> bestHist = null;
                   
                    Double obsScore = initScores.getCoord(u, v);
                   
                    if (u == (size - 1)) { // right-hand end of sequence.

                        bestHist = getBestHist(u, v, order - 1);
                        bestHist.add(words.intern(Word.createWord("</s>", null, null, null, null, null, null)));
                        double bsc = fbScores.getCoord(u, v) + obsScore;
                        normTot += Math.exp(bsc);
                        fbScores.setCoord(u, v, bsc);
                    } else {
                        // use dynamic programming-computed scores to progress backwards.
                        bestHist = getBestHist(u, v, order - 1);
                        List<Pair<Double, String>> followingTaggedWd = observationSequence.get(u + 1);
                        double backwardSum = 0.0;
                        for (int z = 0; z < followingTaggedWd.size(); z++) {
                            Word followingTag = words.intern(Word.createWord(followingTaggedWd.get(z).b.intern(), null, null, null, null, null, null));
                            if (z > 0) {
                                bestHist.remove(bestHist.size() - 1);
                            }
                            bestHist.add(followingTag);
                            backwardSum += Math.exp(lmScore(bestHist) + fbScores.getCoord(u + 1, z));
View Full Code Here

TOP

Related Classes of opennlp.ccg.lexicon.Word

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.