Package maui.util

Examples of maui.util.Candidate


            // that map to nothing in the vocabulary
            if (!candidateNames.isEmpty()) {

              for (String name : candidateNames) {

                Candidate candidate = candidatesTable.get(name);

                if (candidate == null) {
                  // this is the first occurrence of this
                  // candidate
                  // create a candidate object

                  if (vocabularyName.equals("wikipedia")) {
                    Anchor anchor;
                    try {
                      anchor = new Anchor(form,
                          textProcessor, wikipedia
                          .getDatabase());
                      double probability = anchor.getLinkProbability();
                      if (probability >= minKeyphraseness) {
                        // add this candidate to the
                        // list
                        countCandidates++;
                        totalFrequency++;
                        firstWord = pos - i;
                        candidate = new Candidate(name,
                            form, firstWord, anchor, probability);
                       
                      }

                    } catch (SQLException e) {
                      System.err
                      .println("Error adding ngram "
                          + form);
                      e.printStackTrace();
                    }

                  } else {

                    firstWord = pos - i;
                    candidate = new Candidate(name, form,
                        firstWord);
                    totalFrequency++;
                    // if it's a controlled vocabulary, this
                    // allows
                    // retrieve how this topic is refered to
                    // by a descriptor
                    if (!vocabularyName.equals("none")) {
                      candidate.setTitle(vocabulary
                          .getTerm(name));
                    }

                  }

                } else {

                  // candidate has been observed before
                  // update its values
                  // System.out.println(form);
                  firstWord = pos - i;
                  candidate.recordOccurrence(form, firstWord);
                  countCandidates++;
                  totalFrequency++;

                }
                if (candidate != null) {
                  candidatesTable.put(name, candidate);
                }
              }
            }
          }

        }
      }
    }

    for (Candidate candidate : candidatesTable.values()) {
      candidate.normalize(totalFrequency, pos);
    }

    if (vocabularyName.equals("wikipedia")) {
      candidatesTable = disambiguateCandidates(candidatesTable.values());
    }
View Full Code Here


      try {

        // assessing each sense of the candidate
        for (Anchor.Sense sense : candidate.getAnchor().getSenses()) {

          Candidate candidateCopy = candidate.getCopy();

          double senseProbablity = sense.getProbability();

          if (senseProbablity < minSenseProbability)
            break;

          // if unambiguous, add immidiately
          if (senseProbablity == 1.0) {

            id = sense.getId() + "";
            candidateCopy.setName(id);
            candidateCopy.setTitle(sense.getTitle());
            candidateCopy.setArticle(sense);
            if (disambiguatedTopics.containsKey(id)) {
              Candidate previousCandidate = disambiguatedTopics
              .get(id);
              // update the values of the previous candidate by
              // the values of the new one
            //  System.out.println("WAS1 " +
            //   previousCandidate.getInfo());
            //   System.out.println("MRG1 " +
            //   candidateCopy.getInfo());
              candidateCopy.mergeWith(previousCandidate);
            //   System.out.println("NOW1 " +
            //   candidateCopy.getInfo());

            }
            disambiguatedTopics.put(id, candidateCopy);

            // else resolve ambiguity
          } else {

            // to avoid multiplication by 0
            // in cases where an ngram is never an anchor text
            // but appears as a title of Wikipedia page
            if (senseProbablity == 0) {
              senseProbablity = minSenseProbability;
            }

            double semanticRelatedness = 0;
            try {
              // compute the relatedness to context and the
              // commonness of the meaning
              semanticRelatedness = getRelatednessTo(sense,
                  context);
            } catch (Exception e) {
              System.err
              .println("Error computing semantic relatedness for the sense "
                  + sense);
              e.printStackTrace();
            }

            // final score
            double disambiguationScore = senseProbablity
            * semanticRelatedness;

            if (disambiguationScore > 0.01) {
              // this is a valid sense (there may be more than
              // one)

              id = sense.getId() + "";
              candidateCopy.setName(id);
              candidateCopy.setTitle(sense.getTitle());
              candidateCopy.setArticle(sense);
              if (disambiguatedTopics.containsKey(id)) {
                Candidate previousCandidate = disambiguatedTopics
                .get(id);
                // update the values of the previous candidate
                // by the values of the new one
            //     System.out.println("WAS2 " +
            //     previousCandidate.getInfo());
View Full Code Here

TOP

Related Classes of maui.util.Candidate

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.