Skip to content

Commit

Permalink
Fix own properties
Browse files Browse the repository at this point in the history
Closes GH-6.
  • Loading branch information
facundoolano authored and wooorm committed Jun 7, 2016
1 parent cbac5d1 commit fe7bd31
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
13 changes: 8 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ var visit = require('unist-util-visit');
var nlcstToString = require('nlcst-to-string');
var pos = require('retext-pos');

/*
* Methods.
*/

var own = Object.prototype.hasOwnProperty;

/**
* Get the stem of a node.
*
Expand Down Expand Up @@ -92,7 +98,7 @@ function getImportantWords(node) {
'parent': parent
};

if (!(stem in words)) {
if (!own.call(words, stem)) {
words[stem] = {
'matches': [match],
'stem': stem,
Expand Down Expand Up @@ -264,11 +270,9 @@ function getKeyphrases(results, maximum) {
var score;
var first;
var match;

/*
* Iterate over all grouped important words...
*/

for (keyword in results) {
matches = results[keyword].matches;
length = matches.length;
Expand All @@ -292,8 +296,7 @@ function getKeyphrases(results, maximum) {
* If we've detected the same stemmed
* phrase somewhere.
*/

if (stemmedPhrase) {
if (own.call(stemmedPhrases, phrase.value)) {
/*
* Add weight per phrase to the score of
* the phrase.
Expand Down
19 changes: 11 additions & 8 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,31 @@ var equal = assert.strictEqual;
* Fixture.
*
* First three paragraphs on Term Extraction from Wikipedia:
* http://en.wikipedia.org/wiki/Terminology_extraction
* http://en.wikipedia.org/wiki/Terminology_extraction.
*
* There’s also some `constructor`s sprinkled throughout the
* document to check if prototypal properties work correctly.
*/

var fixture = 'Terminology mining, term extraction, term recognition, or ' +
'glossary extraction, is a subtask of information extraction. ' +
'The goal of terminology extraction is to automatically extract ' +
'relevant terms from a given corpus.' +
'relevant terms from a given corpus constructor.' +
'\n\n' +
'In the semantic web era, a growing number of communities and ' +
'networked enterprises started to access and interoperate through ' +
'the internet. Modeling these communities and their information ' +
'needs is important for several web applications, like ' +
'topic-driven web crawlers, web services, recommender systems, ' +
'etc. The development of terminology extraction is essential to ' +
'the language industry.' +
'the language industry constructor.' +
'\n\n' +
'One of the first steps to model the knowledge domain of a ' +
'virtual community is to collect a vocabulary of domain-relevant ' +
'terms, constituting the linguistic surface manifestation of ' +
'domain concepts. Several methods to automatically extract ' +
'technical terms from domain-specific document warehouses have ' +
'been described in the literature.' +
'been described in the literature constructor.' +
'\n\n' +
'Typically, approaches to automatic term extraction make use of ' +
'linguistic processors (part of speech tagging, phrase chunking) ' +
Expand All @@ -51,15 +54,15 @@ var fixture = 'Terminology mining, term extraction, term recognition, or ' +
'and prepositional-NPs "board of directors" - in English, the ' +
'first two constructs are the most frequent). Terminological ' +
'entries are then filtered from the candidate list using ' +
'statistical and machine learning methods. Once filtered, ' +
'statistical and machine learning methods constructor. Once filtered, ' +
'because of their low ambiguity and high specificity, these terms ' +
'are particularly useful for conceptualizing a knowledge domain ' +
'or for supporting the creation of a domain ontology. Furthermore, ' +
'terminology extraction is a very useful starting point for ' +
'semantic similarity, knowledge management, human translation ' +
'and machine translation, etc.';
'and machine translation, etc. constructor.';

var keyScores = [1, 1, 0.71, 0.57, 0.57];
var keyScores = [1, 1, 0.71, 0.71, 0.57, 0.57];
var phraseScores = [1, 0.55, 0.53, 0.24, 0.18];

/*
Expand All @@ -78,7 +81,7 @@ describe('keywords()', function () {
assert('keywords' in namespace);
assert('keyphrases' in namespace);

equal(namespace.keywords.length, 5);
equal(namespace.keywords.length, 6);
equal(namespace.keyphrases.length, 5);
});

Expand Down

0 comments on commit fe7bd31

Please sign in to comment.