index.js
function getKeyphrases(results, maximum) {
  var stemmedPhrases = {}
  var initialWords = []
  var stemmedPhrase
  var index
  var length
  var otherIndex
  var keyword
  var matches
  var phrase
  var stems
  var score
  var first
  var match

  // Iterate over all grouped important words...
  for (keyword in results) {
    matches = results[keyword].matches
    length = matches.length
    index = -1

    // Iterate over every occurence of a certain keyword...
    while (++index < length) {
      phrase = findPhrase(matches[index])
      stemmedPhrase = stemmedPhrases[phrase.value]
      first = phrase.nodes[0]

      match = {
        nodes: phrase.nodes,
        parent: matches[index].parent
      }

      // If we've detected the same stemmed phrase somewhere.
      if (own.call(stemmedPhrases, phrase.value)) {
        // Add weight per phrase to the score of the phrase.
        stemmedPhrase.score += stemmedPhrase.weight

        // If this is the first time we walk over the phrase (exact match but
        // containing another important word), add it to the list of matching
        // phrases.
        if (initialWords.indexOf(first) === -1) {
          initialWords.push(first)
          stemmedPhrase.matches.push(match)
        }
      } else {
        otherIndex = -1
        score = -1
        stems = phrase.stems

        initialWords.push(first)

        // For every stem in phrase, add its score to score.
        while (stems[++otherIndex]) {
          score += results[stems[otherIndex]].score
        }

        stemmedPhrases[phrase.value] = {
          score: score,
          weight: score,
          stems: stems,
          value: phrase.value,
          matches: [match]
        }
      }
    }
  }

  for (stemmedPhrase in stemmedPhrases) {
    phrase = stemmedPhrases[stemmedPhrase]

    // Modify its score to be the rounded result of multiplying it with the
    // number of occurances, and dividing it by the ammount of words in the
    // phrase.
    phrase.score = Math.round(
      (phrase.score * phrase.matches.length) / phrase.stems.length
    )
  }

  return filterResults(stemmedPhrases, maximum)
}
function getKeyphrases(results, maximum) {
  var stemmedPhrases = {}
  var initialWords = []
  var stemmedPhrase
  var index
  var length
  var otherIndex
  var keyword
  var matches
  var phrase
  var stems
  var score
  var first
  var match

  // Iterate over all grouped important words...
  for (keyword in results) {
    matches = results[keyword].matches
    length = matches.length
    index = -1

    // Iterate over every occurence of a certain keyword...
    while (++index < length) {
      phrase = findPhrase(matches[index])
      stemmedPhrase = stemmedPhrases[phrase.value]
      first = phrase.nodes[0]

      match = {
        nodes: phrase.nodes,
        parent: matches[index].parent
      }

      // If we've detected the same stemmed phrase somewhere.
      if (own.call(stemmedPhrases, phrase.value)) {
        // Add weight per phrase to the score of the phrase.
        stemmedPhrase.score += stemmedPhrase.weight

        // If this is the first time we walk over the phrase (exact match but
        // containing another important word), add it to the list of matching
        // phrases.
        if (initialWords.indexOf(first) === -1) {
          initialWords.push(first)
          stemmedPhrase.matches.push(match)
        }
      } else {
        otherIndex = -1
        score = -1
        stems = phrase.stems

        initialWords.push(first)

        // For every stem in phrase, add its score to score.
        while (stems[++otherIndex]) {
          score += results[stems[otherIndex]].score
        }

        stemmedPhrases[phrase.value] = {
          score: score,
          weight: score,
          stems: stems,
          value: phrase.value,
          matches: [match]
        }
      }
    }
  }

  for (stemmedPhrase in stemmedPhrases) {
    phrase = stemmedPhrases[stemmedPhrase]

    // Modify its score to be the rounded result of multiplying it with the
    // number of occurances, and dividing it by the ammount of words in the
    // phrase.
    phrase.score = Math.round(
      (phrase.score * phrase.matches.length) / phrase.stems.length
    )
  }

  return filterResults(stemmedPhrases, maximum)
}
function getKeyphrases ( results , maximum ) { var stemmedPhrases = { } var initialWords = [ ] var stemmedPhrase var index var length var otherIndex var keyword var matches var phrase var stems var score var first var match // Iterate over all grouped important words... for ( keyword in results ) { matches = results [ keyword ] . matches length = matches . length index = - 1 // Iterate over every occurence of a certain keyword... while ( ++ index < length ) { phrase = findPhrase ( matches [ index ] ) stemmedPhrase = stemmedPhrases [ phrase . value ] first = phrase . nodes [ 0 ] match = { nodes : phrase . nodes , parent : matches [ index ] . parent } // If we've detected the same stemmed phrase somewhere. if ( own . call ( stemmedPhrases , phrase . value ) ) { // Add weight per phrase to the score of the phrase. stemmedPhrase . score += stemmedPhrase . weight // If this is the first time we walk over the phrase (exact match but // containing another important word), add it to the list of matching // phrases. if ( initialWords . indexOf ( first ) === - 1 ) { initialWords . push ( first ) stemmedPhrase . matches . push ( match ) } } else { otherIndex = - 1 score = - 1 stems = phrase . stems initialWords . push ( first ) // For every stem in phrase, add its score to score. while ( stems [ ++ otherIndex ] ) { score += results [ stems [ otherIndex ] ] . score } stemmedPhrases [ phrase . value ] = { score : score , weight : score , stems : stems , value : phrase . value , matches : [ match ] } } } } for ( stemmedPhrase in stemmedPhrases ) { phrase = stemmedPhrases [ stemmedPhrase ] // Modify its score to be the rounded result of multiplying it with the // number of occurances, and dividing it by the ammount of words in the // phrase. phrase . score = Math . round ( ( phrase . score * phrase . matches . length ) / phrase . stems . length ) } return filterResults ( stemmedPhrases , maximum ) }
Get the top important phrases in `self`.
Get the top important phrases in self .