Package maui.util

Examples of maui.util.Counter


    // Build a dictionary of candidates with associated
    // document frequencies
    globalDictionary = new HashMap<String, Counter>();
    for (HashMap<String, Candidate> candidates : allCandidates.values()) {
      for (String candidateName : candidates.keySet()) {
        Counter counter = globalDictionary.get(candidateName);
        if (counter == null) {
          globalDictionary.put(candidateName, new Counter());
        } else {
          counter.increment();
        }
      }
    }

    if (debugMode) {
      System.err.println("--- Building keyphraseness dictionary");
    }
    // Build a dictionary of candidates that occur as keyphrases
    // with associated keyphrase frequencies
    keyphraseDictionary = new HashMap<String, Counter>();
    for (int i = 0; i < getInputFormat().numInstances(); i++) {
      String str = getInputFormat().instance(i)
      .stringValue(keyphrasesAtt);
      HashMap<String, Counter> hash = getGivenKeyphrases(str);
      if (hash != null) {
        for (String term : hash.keySet()) {

          Counter documentCount = hash.get(term);
          Counter counter = keyphraseDictionary.get(term);
          if (counter == null) {
            keyphraseDictionary.put(term, new Counter(documentCount
                .value()));
          } else {
            counter.increment(documentCount.value());
          }
        }
      }
    }
View Full Code Here


    String name = candidate.getName();
    String original = candidate.getBestFullForm();
    String title = candidate.getTitle();

    // Compute TFxIDF
    Counter counterGlobal = (Counter) globalDictionary.get(name);
    double globalVal = 0;
    if (counterGlobal != null) {
      globalVal = counterGlobal.value();
      if (training) {
        globalVal = globalVal - 1;
      }
    }
    double tf = candidate.getTermFrequency();
    double idf = -Math.log((globalVal + 1) / ((double) numDocs + 1));
    // System.out.println(candidate + " count: " + candidate.getFrequency() + "
    // tf: " + tf + " glob val: " + globalVal + " numDocs: " + numDocs + " idf:
    // " + idf);

    if (useBasicFeatures) {
      newInst[tfidfIndex] = tf * idf;
      newInst[firstOccurIndex] = candidate.getFirstOccurrence();
    }

    if (useFrequencyFeatures) {
      newInst[tfIndex] = tf;
      newInst[idfIndex] = idf;
    }

    if (usePositionsFeatures) {
      newInst[lastOccurIndex] = candidate.getLastOccurrence();
      newInst[spreadOccurIndex] = candidate.getSpread();
    }

    if (useKeyphrasenessFeature) {
      if (vocabularyName.equals("wikipedia")) {
        name = title;
      }
      Counter domainKeyphr = keyphraseDictionary.get(name);
      if ((training) && (hashKeyphrases != null)
          && (hashKeyphrases.containsKey(name))) {
        newInst[domainKeyphIndex] = domainKeyphr.value() - 1;
      } else {
        if (domainKeyphr != null) {
          newInst[domainKeyphIndex] = domainKeyphr.value();
        } else {
          newInst[domainKeyphIndex] = 0;
        }
      }
    }
View Full Code Here

      }

      if (vocabularyName.equals("none")) {

        keyphrase = pseudoPhrase(keyphrase);
        Counter counter = keyphrases.get(keyphrase);
        if (counter == null) {
          keyphrases.put(keyphrase, new Counter(frequency));
        } else {
          counter.increment(frequency);
        }
      } else if (vocabularyName.equals("wikipedia")) {
        // just use the title to denote manually chosen Wikipedia
        // articles
        int colonIndex = keyphrase.indexOf(":");
        if (colonIndex != -1) {
          keyphrase = keyphrase.substring(colonIndex + 2);
        }
        Counter counter = keyphrases.get(keyphrase);
        if (counter == null) {
          keyphrases.put(keyphrase, new Counter(frequency));
        } else {
          counter.increment(frequency);
        }

      } else {
        for (String id : vocabulary.getSenses(keyphrase)) {
          keyphrase = vocabulary.getTerm(id);
          Counter counter = keyphrases.get(keyphrase);
          if (counter == null) {
            keyphrases.put(keyphrase, new Counter(frequency));
          } else {
            counter.increment(frequency);
          }
        }
      }
    }
View Full Code Here

TOP

Related Classes of maui.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.