retext-keywords
Advanced tools
Comparing version 2.0.1 to 2.0.2
@@ -5,2 +5,7 @@ <!--remark setext--> | ||
2.0.2 / 2016-06-22 | ||
================== | ||
* Update code-style ([`4749704`](https://github.com/wooorm/retext-keywords/commit/4749704)) | ||
2.0.1 / 2016-06-07 | ||
@@ -7,0 +12,0 @@ ================== |
107
index.js
/** | ||
* @author Titus Wormer | ||
* @copyright 2014-2016 Titus Wormer | ||
* @copyright 2014 Titus Wormer | ||
* @license MIT | ||
* @module retext:keywords | ||
* @fileoverview Keyword extraction with Retext. | ||
* @fileoverview Detect the sentiment of text with Retext. | ||
*/ | ||
@@ -13,6 +13,3 @@ | ||
/* | ||
* Dependencies. | ||
*/ | ||
/* Dependencies. */ | ||
var stemmer = require('stemmer'); | ||
@@ -23,6 +20,3 @@ var visit = require('unist-util-visit'); | ||
/* | ||
* Methods. | ||
*/ | ||
/* Methods. */ | ||
var own = Object.prototype.hasOwnProperty; | ||
@@ -98,5 +92,5 @@ | ||
match = { | ||
'node': word, | ||
'index': index, | ||
'parent': parent | ||
node: word, | ||
index: index, | ||
parent: parent | ||
}; | ||
@@ -106,5 +100,5 @@ | ||
words[stem] = { | ||
'matches': [match], | ||
'stem': stem, | ||
'score': 1 | ||
matches: [match], | ||
stem: stem, | ||
score: 1 | ||
}; | ||
@@ -215,5 +209,5 @@ } else { | ||
return { | ||
'stems': stems, | ||
'words': words, | ||
'nodes': nodes | ||
stems: stems, | ||
words: words, | ||
nodes: nodes | ||
}; | ||
@@ -248,5 +242,5 @@ } | ||
return { | ||
'stems': stems, | ||
'value': stems.join(' '), | ||
'nodes': merge(prev.nodes, node, next.nodes) | ||
stems: stems, | ||
value: stems.join(' '), | ||
nodes: merge(prev.nodes, node, next.nodes) | ||
}; | ||
@@ -279,5 +273,4 @@ } | ||
var match; | ||
/* | ||
* Iterate over all grouped important words... | ||
*/ | ||
/* Iterate over all grouped important words... */ | ||
for (keyword in results) { | ||
@@ -288,6 +281,3 @@ matches = results[keyword].matches; | ||
/* | ||
* Iterate over every occurence of a certain keyword... | ||
*/ | ||
/* Iterate over every occurence of a certain keyword... */ | ||
while (++index < length) { | ||
@@ -299,25 +289,17 @@ phrase = findPhrase(matches[index]); | ||
match = { | ||
'nodes': phrase.nodes, | ||
'parent': matches[index].parent | ||
nodes: phrase.nodes, | ||
parent: matches[index].parent | ||
}; | ||
/* | ||
* If we've detected the same stemmed | ||
* phrase somewhere. | ||
*/ | ||
/* 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. | ||
*/ | ||
/* Add weight per phrase to the score of | ||
* the phrase. */ | ||
stemmedPhrase.score += stemmedPhrase.weight; | ||
/* | ||
* If this is the first time we walk over | ||
/* 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. | ||
*/ | ||
* list of matching phrases. */ | ||
if (initialWords.indexOf(first) === -1) { | ||
@@ -334,7 +316,4 @@ initialWords.push(first); | ||
/* | ||
* For every stem in phrase, add its | ||
* score to score. | ||
*/ | ||
/* For every stem in phrase, add its | ||
* score to score. */ | ||
while (stems[++otherIndex]) { | ||
@@ -345,7 +324,7 @@ score += results[stems[otherIndex]].score; | ||
stemmedPhrases[phrase.value] = { | ||
'score': score, | ||
'weight': score, | ||
'stems': stems, | ||
'value': phrase.value, | ||
'matches': [match] | ||
score: score, | ||
weight: score, | ||
stems: stems, | ||
value: phrase.value, | ||
matches: [match] | ||
}; | ||
@@ -359,9 +338,6 @@ } | ||
/* | ||
* Modify its score to be the rounded result of | ||
/* 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. */ | ||
phrase.score = Math.round( | ||
@@ -391,5 +367,5 @@ phrase.score * phrase.matches.length / phrase.stems.length | ||
result[key] = { | ||
'matches': match.matches, | ||
'stem': match.stem, | ||
'score': match.score | ||
matches: match.matches, | ||
stem: match.stem, | ||
score: match.score | ||
} | ||
@@ -432,6 +408,3 @@ } | ||
/* | ||
* Expose. | ||
*/ | ||
/* Expose. */ | ||
module.exports = attacher; |
{ | ||
"name": "retext-keywords", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "Keyword extraction with Retext", | ||
@@ -14,8 +14,2 @@ "license": "MIT", | ||
], | ||
"dependencies": { | ||
"nlcst-to-string": "^1.0.0", | ||
"retext-pos": "^1.0.0", | ||
"stemmer": "^0.1.4", | ||
"unist-util-visit": "^1.0.0" | ||
}, | ||
"files": [ | ||
@@ -34,2 +28,8 @@ "index.js" | ||
], | ||
"dependencies": { | ||
"nlcst-to-string": "^2.0.0", | ||
"retext-pos": "^1.0.0", | ||
"stemmer": "^0.1.4", | ||
"unist-util-visit": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
@@ -42,22 +42,22 @@ "browserify": "^13.0.1", | ||
"jscs-jsdoc": "^2.0.0", | ||
"remark": "^4.0.0", | ||
"remark-comment-config": "^3.0.0", | ||
"remark-github": "^4.0.1", | ||
"remark-cli": "^1.0.0", | ||
"remark-comment-config": "^4.0.0", | ||
"remark-github": "^5.0.0", | ||
"remark-lint": "^4.0.0", | ||
"remark-validate-links": "^3.0.0", | ||
"mocha": "^2.0.0", | ||
"retext": "^2.0.0" | ||
"remark-validate-links": "^4.0.0", | ||
"retext": "^3.0.0", | ||
"tape": "^4.0.0" | ||
}, | ||
"scripts": { | ||
"build-md": "remark . --quiet --frail", | ||
"build-bundle": "browserify index.js --ignore-missing --no-builtins --standalone retextKeywords > retext-keywords.js", | ||
"build-bundle": "browserify index.js --ignore-missing --bare -s retextKeywords > retext-keywords.js", | ||
"build-mangle": "esmangle retext-keywords.js > retext-keywords.min.js", | ||
"build": "npm run build-bundle && npm run build-md && npm run build-mangle", | ||
"build": "npm run build-md && npm run build-bundle && npm run build-mangle", | ||
"lint-api": "eslint .", | ||
"lint-style": "jscs --reporter inline .", | ||
"lint": "npm run lint-api && npm run lint-style", | ||
"test-api": "mocha --check-leaks test.js", | ||
"test-coverage": "istanbul cover _mocha -- test.js", | ||
"test-api": "node test.js", | ||
"test-coverage": "istanbul cover test.js", | ||
"test": "npm run build && npm run lint && npm run test-coverage" | ||
} | ||
} |
# retext-keywords [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov] | ||
<!-- lint disable heading-increment --> | ||
<!--lint disable heading-increment list-item-spacing--> | ||
@@ -15,2 +15,5 @@ Keyword extraction with [**retext**][retext]. | ||
**retext-keywords** is also available as an AMD, CommonJS, and | ||
globals module, [uncompressed and compressed][releases]. | ||
## Usage | ||
@@ -100,19 +103,9 @@ | ||
### `retext.use(keywords[, options])` | ||
### `retext().use(keywords[, options])` | ||
Extract keywords and key-phrases from the document. | ||
[Read more about `use` »][use] | ||
###### Options | ||
* `maximum` (default: 5) — Try to detect `words` and `phrases` words; | ||
Note that actual counts may differ. For example, when two words | ||
have the same score, both will be returned. Or when too few words | ||
exist, less will be returned. the same goes for phrases. | ||
The results are stored in the `retext` namespace on the virtual file: | ||
keywords at `file.namespace('retext').keywords` and key-phrases at | ||
`file.namespace('retext').keyphrases`. Both are lists. | ||
`file.namespace('retext').keyphrases`. Both are lists. | ||
@@ -148,2 +141,11 @@ A single keyword looks as follows: | ||
###### `options` | ||
* `maximum` (default: `5`) — Try to detect `words` and `phrases` | ||
words; | ||
Note that actual counts may differ. For example, when two words | ||
have the same score, both will be returned. Or when too few words | ||
exist, less will be returned. the same goes for phrases. | ||
## License | ||
@@ -165,2 +167,4 @@ | ||
[releases]: https://github.com/wooorm/retext-keywords/releases | ||
[license]: LICENSE | ||
@@ -171,3 +175,1 @@ | ||
[retext]: https://github.com/wooorm/retext | ||
[use]: https://github.com/wooorm/retext#retextuseplugin-options |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18799
5
171
342
+ Addednlcst-to-string@2.0.4(transitive)
- Removednlcst-to-string@1.1.0(transitive)
Updatednlcst-to-string@^2.0.0