Commit 52644f75 authored by Ludan Stoecklé's avatar Ludan Stoecklé

starting

parent 35e051dc
lib/
.nyc_output
test/
tsconfig.json
example.js
README.md
# English verbs
## Features
Agreement of English verbs, based on `compromise` lib.
## Installation
```sh
npm install english-verbs
```
## Usage
```javascript
```
const EnglishVerbs = require('./dist/index.js');
console.log(EnglishVerbs.getConjugation('eat', 'PRESENT', 'S'));
console.log(EnglishVerbs.getConjugation('eat', 'PRESENT', 'P'));
export type EnglishTense = 'PRESENT' | 'PAST' | 'FUTURE';
export type Numbers = 'S' | 'P';
import compromise from 'compromise';
export function getConjugation(verb: string, tense: EnglishTense, number: Numbers): string {
if (!verb) {
const err = new Error();
err.name = 'TypeError';
err.message = 'verb must not be null';
throw err;
}
if (tense === 'PRESENT' && number === 'P') {
return verb;
}
const tenseMapping = {
PRESENT: 'PresentTense',
PAST: 'PastTense',
FUTURE: 'FutureTense',
};
const conjugated: any[] = compromise('he ' + verb)
.verbs()
.conjugate();
if (conjugated && conjugated.length > 0) {
return conjugated[0][tenseMapping[tense]];
}
const err = new Error();
err.name = 'InvalidArgumentError';
err.message = `could not conjugate ${verb} properly using compromise lib`;
throw err;
}
{
"name": "english-verbs",
"version": "0.0.1",
"description": "English verbs conjugation, based on compromise lib",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "nyc mocha",
"clean": "rm -rf dist/",
"build": "cp lib/ExoticInterface.d.ts dist && tsc"
},
"repository": {
"type": "git",
"url": "git@gitlab.com:rosaenlg-projects/rosaenlg.git"
},
"nyc": {
"extension": [
".ts"
],
"exclude": [
"test/"
],
"check-coverage": true,
"statements": 95,
"lines": 95,
"functions": 95,
"branches": 95,
"watermarks": {
"statements": [
60,
95
],
"lines": [
60,
95
],
"functions": [
60,
95
],
"branches": [
60,
95
]
}
},
"dependencies": {
"compromise": "^13.0.0"
},
"devDependencies": {
"mocha": "^6.2.2",
"nyc": "^14.1.1",
"typescript": "^3.7.2"
},
"keywords": [
"verbs",
"conjugation",
"English"
],
"author": "Ludan Stoecklé <ludan.stoeckle@rosaenlg.org>",
"license": "MIT"
}
const assert = require('assert');
const EnglishVerbs = require('../dist/index.js');
const testCases = [
['eat', 'PRESENT', 'S', 'eats'],
['eat', 'PRESENT', 'P', 'eat'],
];
describe('english-verbs', function() {
describe('#getConjugation()', function() {
describe('nominal cases', function() {
for (let i = 0; i < testCases.length; i++) {
const testCase = testCases[i];
const verb = testCase[0];
const tense = testCase[1];
const number = testCase[2];
const expected = testCase[3];
it(`${verb} ${tense} ${number} => ${expected}`, function() {
assert.equal(EnglishVerbs.getConjugation(verb, tense, number), expected);
});
}
});
});
});
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"typeRoots": [
"../../node_modules/@types"
],
"sourceMap": true,
"outDir": "dist",
"declaration": true,
"allowJs": false,
"esModuleInterop": true
}
}
\ No newline at end of file
......@@ -118,7 +118,8 @@
"rosaenlg-yseop": "2.8.0",
"synonym-optimizer": "2.8.0",
"write-int": "^0.0.2",
"written-number": "^0.9.1"
"written-number": "^0.9.1",
"english-verbs": "^0.0.1"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^11.0.1",
......
......@@ -33,6 +33,7 @@ const libs = [
['compromise', 'en_US', true, null],
['better-title-case', true, null],
['english-determiners', true, null],
['english-verbs', true, null],
// de_DE specific
['stopwords-de', 'de_DE', true, null],
['snowball-stemmer.jsx/dest/german-stemmer.common.js', 'de_DE', true, null],
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment