Package kea.util

Examples of kea.util.Counter


      String str = getInputFormat().instance(i).stringValue(m_DocumentAtt);
      HashMap<String,Counter> hash = getPhrasesForDictionary(str);
      Iterator<String> it = hash.keySet().iterator();
      while (it.hasNext()) {
        String phrase = it.next();
        Counter counter = m_Dictionary.get(phrase);
        if (counter == null) {
          m_Dictionary.put(phrase, new Counter());
        } else {
          counter.increment();
        }
      }
    }

    if (m_KFused) {      
     

      // Build dictionary of n-grams that occur as keyphrases
      // with associated keyphrase frequencies
      m_KeyphraseDictionary = new HashMap<String,Counter>();
      for (int i = 0; i < getInputFormat().numInstances(); i++) {
        String str = getInputFormat().instance(i).stringValue(m_KeyphrasesAtt);
        HashMap<String,Counter> hash = getGivenKeyphrases(str, false);
        if (hash != null) {
          Iterator<String> it = hash.keySet().iterator();
          while (it.hasNext()) {
            String phrase = it.next();
            Counter counter = m_KeyphraseDictionary.get(phrase);
            if (counter == null) {
              m_KeyphraseDictionary.put(phrase, new Counter());
            } else {
              counter.increment();
            }
          }
        }
      }
    } else {
View Full Code Here


  private double[] featVals(String id, FastVector phraseInfo,
      boolean training, HashMap<String,Counter> hashKeysEval,
      HashMap<String,Counter> hashKeyphrases, int length, HashMap<String,FastVector> hash) {

    // Compute feature values
    Counter counterLocal = (Counter)phraseInfo.elementAt(1);
    double[] newInst = new double[m_NumFeatures + 1];


    // Compute TFxIDF
    Counter counterGlobal = (Counter)m_Dictionary.get(id);
    double localVal = counterLocal.value(), globalVal = 0;
    if (counterGlobal != null) {
      globalVal = counterGlobal.value();
      if (training) {
        globalVal = globalVal - 1;
      }
    }

    // Just devide by length to get approximation of probability
    // that phrase in document is our phrase
    // newInst[m_TfidfIndex] = (localVal / ((double)length));
    newInst[m_TfidfIndex] = (localVal / ((double)length)) *
    (-Math.log((globalVal + 1)/ ((double)m_NumDocs + 1)));

    // Compute first occurrence
    Counter counterFirst = (Counter)phraseInfo.elementAt(0);
    newInst[m_FirstOccurIndex] = (double)counterFirst.value() /
    (double)length;


    // Is keyphrase frequency attribute being used?
    if (m_KFused) {
      Counter keyphraseC = (Counter)m_KeyphraseDictionary.get(id);
      if ((training) && (hashKeyphrases != null) &&
          (hashKeyphrases.containsKey(id))) {
        newInst[m_KeyFreqIndex] = keyphraseC.value() - 1;
      } else {
        if (keyphraseC != null) {
          newInst[m_KeyFreqIndex] = keyphraseC.value();
        } else {
          newInst[m_KeyFreqIndex] = 0;
        }
      }
    }
View Full Code Here

            } else {
              id = (String)m_Vocabulary.getID(orig);
            }

            if (id != null) {               
              Counter count = (Counter)hash.get(id);
              if (count == null) {
                hash.put(id, new Counter());
              } else {
                count.increment();
              }
              //  System.err.println(orig + "\t" + id);
            }           
          }
        }
View Full Code Here

                } else {
                  vec = new FastVector(2);
                }

                // Update hashtable with all the info
                vec.addElement(new Counter(pos + 1 - i)); //0
                vec.addElement(new Counter()); //1
                vec.addElement(orig); //2

                if (m_STDEVfeature) {
                  FastVector app = new FastVector();
                  app.addElement(new Counter(pos + 1 - i));
                  vec.addElement(app);
                }
                hash.put(id, vec);
              } else {

                // If the phrase already was identified,
                // update its values in the old vector

                // Update number of occurrences
                ((Counter)((FastVector)vec).elementAt(1)).increment();

                if (m_STDEVfeature) {

                  FastVector app = (FastVector)vec.elementAt(3);
                  app.addElement(new Counter(pos + 1 - i));
                  vec.addElement(app);
                }

              }               
            }
View Full Code Here

          id = (String)m_Vocabulary.getID(orig);
        }
        if (id != null) {
          //System.err.println("\t" + id);
          if (!hash.containsKey(id)) {
            hash.put(id, new Counter());
          } else
            Counter c = (Counter)hash.get(id);
            c.increment();
            hash.put(id, c);
            if (forEval && m_Debug) {
              System.err.println("Skipping the phrase " + orig + ", which appears twice in the author-assigned keyphrase set.");
            }
          }
View Full Code Here

TOP

Related Classes of kea.util.Counter

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.