Skip to content

Commit

Permalink
WIP Edit code to conform to JS standard (#572)
Browse files Browse the repository at this point in the history
* Edited stemmers to comply with standard JS

* Edited the tokenizers to comply with standard JS

* fixed tests for removed attach() method

* Brill's tagger conforms to standard JS

* Classifiers in standard JS

* Distance to standard JS

* Inflectors to Standard JS

* Ngrams to standard JS

* Normalizers to standard JS

* Phonetics to standard JS

* Sentiment analyzer in standard JS

* Spellcheck to standard JS

* Add trie to standard JS

* Util folder to standard JS

* Wordnet to standard JS

* index.js to standard js

* sentence_analyse in standard JS

* Tools of sentiment analyser to standard JS

* Tests in io_spec conform to standard JS

* io_spec conforms to standard JS

* examples in standard JS

* Specs to standard JS

* Last files to conform to standard JS

* Add linter to Github actions

* Added standard JS badge to README

* README for linter

* Padding for license agreement

* Attempt to repair url in README

* Padding in license texts

* Removed some code clones

* Removed editor config

* Repaired code duplicaties in specs

* Excluded generated files for jscpd

* Adapted path of ignore files for jscpd

* Split classifier.js te prevent code duplication

* Add new file for classifier

* Repaired parallel trainer

* Removed duplication from classifier spec

* Repaired Bayes classifier

* Repaired further...

* Double metaphone test

* Ignore TF_Parser
  • Loading branch information
Hugo-ter-Doest committed Feb 3, 2021
1 parent 4104219 commit f23ad2b
Show file tree
Hide file tree
Showing 236 changed files with 21,299 additions and 18,184 deletions.
7 changes: 0 additions & 7 deletions .editorconfig

This file was deleted.

55 changes: 55 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
###########################
###########################
## Linter GitHub Actions ##
###########################
###########################
name: Lint Code Base

#
# Documentation:
# https://help.github.com/en/articles/workflow-syntax-for-github-actions
#

#############################
# Start the job on all push #
#############################
on:
push:
branches-ignore: [master]
# Remove the line above to run when pushing to master
pull_request:
branches: [master]

###############
# Set the Job #
###############
jobs:
build:
# Name the Job
name: Lint Code Base
# Set the agent to run on
runs-on: ubuntu-latest

##################
# Load all steps #
##################
steps:
##########################
# Checkout the code base #
##########################
- name: Checkout Code
uses: actions/checkout@v2
with:
# Full git history is needed to get a proper list of changed files within `super-linter`
fetch-depth: 0

################################
# Run Linter against code base #
################################
- name: Lint Code Base
uses: github/super-linter@v3
env:
VALIDATE_ALL_CODEBASE: false
DEFAULT_BRANCH: master
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28 changes: 24 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# natural

[![NPM version](https://img.shields.io/npm/v/natural.svg)](https://www.npmjs.com/package/natural)
[![Build Status](https://travis-ci.org/NaturalNode/natural.png?branch=master)](https://travis-ci.org/NaturalNode/natural)
[![Node.js CI](https://github.com/NaturalNode/natural/workflows/Node.js%20CI/badge.svg)](https://github.com/marketplace/actions/setup-node-js-environment)
[![GitHub Super-Linter](https://github.com/NaturalNode/natural/workflows/Lint%20Code%20Base/badge.svg)](https://github.com/marketplace/actions/super-linter)
[![Slack](https://slack.bri.im/badge.svg)](https://slack.bri.im)

"Natural" is a general natural language facility for nodejs. It offers a broad range of functionalities for natural language processing. Documentation can be found [here on Github Pages](http://naturalnode.github.io/natural/).


# License
## License

Copyright (c) 2011, 2012 Chris Umbel, Rob Ellis, Russell Mull

Expand All @@ -29,9 +30,28 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

# WordNet License
## WordNet License

This license is available as the file LICENSE in any downloaded version of WordNet.
WordNet 3.0 license: (Download)

WordNet Release 3.0 This software and database is being provided to you, the LICENSEE, by Princeton University under the following license. By obtaining, using and/or copying this software and database, you agree that you have read, understood, and will comply with these terms and conditions.: Permission to use, copy, modify and distribute this software and database and its documentation for any purpose and without fee or royalty is hereby granted, provided that you agree to comply with the following copyright notice and statements, including the disclaimer, and that the same appear on ALL copies of the software, database and documentation, including modifications that you make for internal use or for distribution. WordNet 3.0 Copyright 2006 by Princeton University. All rights reserved. THIS SOFTWARE AND DATABASE IS PROVIDED "AS IS" AND PRINCETON UNIVERSITY MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PRINCETON UNIVERSITY MAKES NO REPRESENTATIONS OR WARRANTIES OF MERCHANT- ABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE LICENSED SOFTWARE, DATABASE OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. The name of Princeton University or Princeton may not be used in advertising or publicity pertaining to distribution of the software and/or database. Title to copyright in this software, database and any associated documentation shall at all times remain with Princeton University and LICENSEE agrees to preserve same.
WordNet Release 3.0 This software and database is being provided to you, the
LICENSEE, by Princeton University under the following license. By obtaining,
using and/or copying this software and database, you agree that you have read,
understood, and will comply with these terms and conditions.: Permission to use,
copy, modify and distribute this software and database and its documentation for
any purpose and without fee or royalty is hereby granted, provided that you
agree to comply with the following copyright notice and statements, including
the disclaimer, and that the same appear on ALL copies of the software, database
and documentation, including modifications that you make for internal use or for
distribution. WordNet 3.0 Copyright 2006 by Princeton University. All rights
reserved. THIS SOFTWARE AND DATABASE IS PROVIDED "AS IS" AND PRINCETON
UNIVERSITY MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF
EXAMPLE, BUT NOT LIMITATION, PRINCETON UNIVERSITY MAKES NO REPRESENTATIONS OR
WARRANTIES OF MERCHANT- ABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT
THE USE OF THE LICENSED SOFTWARE, DATABASE OR DOCUMENTATION WILL NOT INFRINGE
ANY THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. The name of
Princeton University or Princeton may not be used in advertising or publicity
pertaining to distribution of the software and/or database. Title to copyright
in this software, database and any associated documentation shall at all times
remain with Princeton University and LICENSEE agrees to preserve same.
35 changes: 15 additions & 20 deletions benchmarks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,27 @@
* Module dependencies.
*/

var uubench = require('uubench')
, natural = require('../');

fs = require('fs');
metaphone = natural.Metaphone.process;
soundex = natural.SoundEx.process;
stemmerId = natural.StemmerId
const uubench = require('uubench')

/* global suite:writable */
suite = new uubench.Suite({
start: function(){
console.log();
start: function () {
console.log()
},

result: function(name, stats){
var persec = 1000 / stats.elapsed
, ops = stats.iterations * persec;
console.log(' \033[90m%s : \033[36m%s \033[90mops/s\033[0m', name, ops | 0);
result: function (name, stats) {
const persec = 1000 / stats.elapsed
const ops = stats.iterations * persec
console.log('%s : %s ops/s', name, ops | 0)
},

done: function(){
console.log();
done: function () {
console.log()
}
});
})

require('./metaphone');
require('./soundex');
require('./stemmer_id');
require('./metaphone')
require('./soundex')
require('./stemmer_id')

suite.run();
suite.run()
38 changes: 22 additions & 16 deletions benchmarks/metaphone.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@

const fs = require('fs')
const natural = require('../')
const metaphone = natural.Metaphone.process

/* global suite */

// single word

suite.bench('metaphone() word', function(next){
metaphone('stephen');
next();
});
suite.bench('metaphone() word', function (next) {
metaphone('stephen')
next()
})

// small body of text

var words = fs.readFileSync('lib/natural/index.js', 'utf8').split(/\W+/);
suite.bench('metaphone() small', function(next){
for (var i = 0, len = words.length; i < len; ++i) {
metaphone(words[i]);
const words = fs.readFileSync('lib/natural/index.js', 'utf8').split(/\W+/)
suite.bench('metaphone() small', function (next) {
for (let i = 0, len = words.length; i < len; ++i) {
metaphone(words[i])
}
next();
});
next()
})

// medium body of text

var words2 = fs.readFileSync('README.md', 'utf8').split(/\W+/);
suite.bench('metaphone() medium', function(next){
for (var i = 0, len = words2.length; i < len; ++i) {
metaphone(words2[i]);
const words2 = fs.readFileSync('README.md', 'utf8').split(/\W+/)
suite.bench('metaphone() medium', function (next) {
for (let i = 0, len = words2.length; i < len; ++i) {
metaphone(words2[i])
}
next();
});
next()
})
37 changes: 21 additions & 16 deletions benchmarks/soundex.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
const fs = require('fs')
const natural = require('../')
const soundex = natural.SoundEx.process

/* global suite */

// single word

suite.bench('soundex() word', function(next){
soundex('stephen');
next();
});
suite.bench('soundex() word', function (next) {
soundex('stephen')
next()
})

// small body of text

var words = fs.readFileSync('lib/natural/index.js', 'utf8').split(/\W+/);
suite.bench('soundex() small', function(next){
for (var i = 0, len = words.length; i < len; ++i) {
soundex(words[i]);
const words = fs.readFileSync('lib/natural/index.js', 'utf8').split(/\W+/)
suite.bench('soundex() small', function (next) {
for (let i = 0, len = words.length; i < len; ++i) {
soundex(words[i])
}
next();
});
next()
})

// medium body of text

var words2 = fs.readFileSync('README.md', 'utf8').split(/\W+/);
suite.bench('soundex() medium', function(next){
for (var i = 0, len = words2.length; i < len; ++i) {
soundex(words2[i]);
const words2 = fs.readFileSync('README.md', 'utf8').split(/\W+/)
suite.bench('soundex() medium', function (next) {
for (let i = 0, len = words2.length; i < len; ++i) {
soundex(words2[i])
}
next();
});
next()
})
17 changes: 11 additions & 6 deletions benchmarks/stemmer_id.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
const fs = require('fs')
const natural = require('../')
const stemmerId = natural.StemmerId

var words = fs.readFileSync('benchmarks/sample-id.txt', 'utf8').split(/\W+/);
suite.bench('stemmerId() sample text', function(next){
for (var i = 0, len = words.length; i < len; ++i) {
stemmerId.stem(words[i]);
/* global suite */

const words = fs.readFileSync('benchmarks/sample-id.txt', 'utf8').split(/\W+/)
suite.bench('stemmerId() sample text', function (next) {
for (let i = 0, len = words.length; i < len; ++i) {
stemmerId.stem(words[i])
}
next();
});
next()
})
19 changes: 10 additions & 9 deletions examples/classification/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

var natural = require('natural'),
classifier = new natural.BayesClassifier();
'use strict'

const natural = require('natural')
const classifier = new natural.BayesClassifier()

classifier.addDocument('my unit-tests failed.', 'software');
classifier.addDocument('tried the program, but it was buggy.', 'software');
classifier.addDocument('the drive has a 2TB capacity.', 'hardware');
classifier.addDocument('i need a new power supply.', 'hardware');
classifier.addDocument('my unit-tests failed.', 'software')
classifier.addDocument('tried the program, but it was buggy.', 'software')
classifier.addDocument('the drive has a 2TB capacity.', 'hardware')
classifier.addDocument('i need a new power supply.', 'hardware')

classifier.train();
classifier.train()

console.log(classifier.classify('did the tests pass?'));
console.log(classifier.classify('did you buy a new drive?'));
console.log(classifier.classify('did the tests pass?'))
console.log(classifier.classify('did you buy a new drive?'))
15 changes: 10 additions & 5 deletions examples/classification/recall.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

var natural = require('natural'),
classifier = new natural.BayesClassifier();
'use strict'

natural.BayesClassifier.load('classifier.json', null, function(err, classifier) {
console.log(classifier.classify('did the tests pass?'));
});
const natural = require('natural')

natural.BayesClassifier.load('classifier.json', null, function (err, classifier) {
if (err) {
console.log(err)
return
}
console.log(classifier.classify('did the tests pass?'))
})
25 changes: 14 additions & 11 deletions examples/classification/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,21 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

var natural = require('natural'),
classifier = new natural.BayesClassifier();
'use strict'

const natural = require('natural')
const classifier = new natural.BayesClassifier()

classifier.addDocument('my unit-tests failed.', 'software');
classifier.addDocument('tried the program, but it was buggy.', 'software');
classifier.addDocument('the drive has a 2TB capacity.', 'hardware');
classifier.addDocument('i need a new power supply.', 'hardware');
classifier.addDocument('my unit-tests failed.', 'software')
classifier.addDocument('tried the program, but it was buggy.', 'software')
classifier.addDocument('the drive has a 2TB capacity.', 'hardware')
classifier.addDocument('i need a new power supply.', 'hardware')

classifier.train();

classifier.save('classifier.json', function(err, classifier) {
// the classifier is saved to the classifier.json file!
});
classifier.train()

classifier.save('classifier.json', function (err, classifier) {
if (err) {
console.log(err)
}
// the classifier is saved to the classifier.json file!
})
26 changes: 14 additions & 12 deletions examples/inflection/count.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,18 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

var natural = require('natural'),
inflector = natural.CountInflector;
'use strict'

console.log(inflector.nth(1));
console.log(inflector.nth(2));
console.log(inflector.nth(3));
console.log(inflector.nth(4));
console.log(inflector.nth(10));
console.log(inflector.nth(11));
console.log(inflector.nth(101));
console.log(inflector.nth(102));
console.log(inflector.nth(103));
console.log(inflector.nth(104));
const natural = require('natural')
const inflector = natural.CountInflector

console.log(inflector.nth(1))
console.log(inflector.nth(2))
console.log(inflector.nth(3))
console.log(inflector.nth(4))
console.log(inflector.nth(10))
console.log(inflector.nth(11))
console.log(inflector.nth(101))
console.log(inflector.nth(102))
console.log(inflector.nth(103))
console.log(inflector.nth(104))

0 comments on commit f23ad2b

Please sign in to comment.