hunspell-reader
Advanced tools
Comparing version 2.0.2 to 2.0.3
@@ -112,2 +112,3 @@ import { Converter } from './converter'; | ||
getMatchingRules(rules: string): Rule[]; | ||
joinRules(rules: string[]): string; | ||
separateRules(rules: string): string[]; | ||
@@ -114,0 +115,0 @@ readonly iConv: Converter; |
@@ -39,3 +39,3 @@ "use strict"; | ||
}), { rulesApplied: affWord.rulesApplied, flags: affWord.flags }); | ||
const rules = allRules.filter(rule => !rule.flags).map(rule => rule.id).join(''); | ||
const rules = this.joinRules(allRules.filter(rule => !rule.flags).map(rule => rule.id)); | ||
const affixRules = allRules.map(rule => rule.sfx || rule.pfx).filter(a => !!a); | ||
@@ -51,7 +51,7 @@ const wordWithFlags = { word, flags, rulesApplied, rules: '' }; | ||
applyAffixesToWord(affixRules, affWord) { | ||
const combinableSfx = affixRules | ||
const combineableRules = affixRules | ||
.filter(rule => rule.type === 'SFX') | ||
.filter(rule => rule.combinable === true) | ||
.map(({ id }) => id) | ||
.join(''); | ||
.map(({ id }) => id); | ||
const combinableSfx = this.joinRules(combineableRules); | ||
const r = affixRules | ||
@@ -70,4 +70,5 @@ .map(affix => this.applyAffixToWord(affix, affWord, combinableSfx)) | ||
const flags = Object.assign({}, affWord.flags, { isNeedAffix: false }); | ||
return [...affix.substitutionSets.values()] | ||
.filter(sub => sub.match.test(word)) | ||
const matchingSubstitutions = [...affix.substitutionSets.values()] | ||
.filter(sub => sub.match.test(word)); | ||
return matchingSubstitutions | ||
.map(sub => sub.substitutions) | ||
@@ -91,9 +92,19 @@ .reduce((a, b) => a.concat(b), []) | ||
} | ||
joinRules(rules) { | ||
switch (this.affInfo.FLAG) { | ||
case 'long': | ||
return rules.join(''); | ||
case 'num': | ||
return rules.join(','); | ||
} | ||
return rules.join(''); | ||
} | ||
separateRules(rules) { | ||
if (this.affInfo.FLAG === 'long') { | ||
return rules.replace(/(..)/g, '$1//').split('//').slice(0, -1); | ||
switch (this.affInfo.FLAG) { | ||
case 'long': | ||
return rules.replace(/(..)/g, '$1//').split('//').slice(0, -1); | ||
case 'num': | ||
return rules.split(','); | ||
} | ||
else { | ||
return rules.split(''); | ||
} | ||
return rules.split(''); | ||
} | ||
@@ -100,0 +111,0 @@ get iConv() { |
@@ -38,3 +38,18 @@ "use strict"; | ||
} | ||
const regExpStartsWithPlus = /^\+/; | ||
function tablePfxOrSfx(fieldValue, _, args, type) { | ||
/* | ||
Fields of an affix rules: | ||
(0) Option name | ||
(1) Flag | ||
(2) stripping characters from beginning (at prefix rules) or end (at suffix rules) of the word | ||
(3) affix (optionally with flags of continuation classes, separated by a slash) | ||
(4) condition. | ||
Zero stripping or affix are indicated by zero. Zero condition is indicated by dot. | ||
Condition is a simplified, regular expression-like pattern, which must be met before the affix can be applied. | ||
(Dot signs an arbitrary character. Characters in braces sign an arbitrary character from the character subset. | ||
Dash hasn't got special meaning, but circumflex (^) next the first brace sets the complementer character set.) | ||
(5) Optional morphological fields separated by spaces or tabulators. | ||
*/ | ||
const posCondition = 2; | ||
if (fieldValue === undefined) { | ||
@@ -57,2 +72,11 @@ fieldValue = new Map(); | ||
} | ||
if (subValues.length < 2) { | ||
console.log(`Affix rule missing values: ${args.join(' ')}`); | ||
return; | ||
} | ||
if (regExpStartsWithPlus.test(subValues[posCondition] || '')) { | ||
// sometimes the condition is left off, but there are morphological fields | ||
// so we need to inject a '.'. | ||
subValues.splice(posCondition, 0, '.'); | ||
} | ||
const fixRuleSet = fieldValue.get(subField); | ||
@@ -59,0 +83,0 @@ const substitutionSets = fixRuleSet.substitutionSets; |
{ | ||
"name": "hunspell-reader", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"description": "A library for reading Hunspell Dictionary Files", | ||
@@ -19,4 +19,4 @@ "bin": "./dist/app.js", | ||
"generate-code-coverage": "NODE_ENV=test nyc npm run test-ts", | ||
"test-ts": "NODE_ENV=test mocha --compilers ts:ts-node/register --recursive --bail \"src/**/*.test.ts\"", | ||
"test-watch": "npm run build && mocha --compilers ts:ts-node/register --watch --recursive \"src/**/*.test.ts\"", | ||
"test-ts": "NODE_ENV=test mocha --require ts-node/register --recursive --bail \"src/**/*.test.ts\"", | ||
"test-watch": "npm run build && mocha --require ts-node/register --watch --recursive \"src/**/*.test.ts\"", | ||
"coverage-coveralls": "nyc report --reporter=text-lcov | coveralls", | ||
@@ -43,9 +43,9 @@ "travis-coverage": "npm run generate-code-coverage && npm run coverage-coveralls", | ||
"@types/mocha": "^5.2.0", | ||
"@types/node": "^8.10.12", | ||
"@types/node": "^8.10.17", | ||
"chai": "^4.1.2", | ||
"coveralls": "^3.0.1", | ||
"mocha": "^5.1.1", | ||
"nyc": "^11.7.1", | ||
"mocha": "^5.2.0", | ||
"nyc": "^11.8.0", | ||
"rimraf": "^2.6.2", | ||
"ts-node": "^6.0.2", | ||
"ts-node": "^6.0.5", | ||
"typescript": "^2.8.3" | ||
@@ -58,3 +58,3 @@ }, | ||
"gensequence": "^2.1.1", | ||
"rxjs": "^6.1.0", | ||
"rxjs": "^6.2.0", | ||
"rxjs-stream": "^2.0.3" | ||
@@ -61,0 +61,0 @@ }, |
@@ -87,1 +87,4 @@ # hunspell-reader | ||
## Reference | ||
* [Hunspell Docs](https://github.com/hunspell/hunspell/blob/master/docs/hunspell.5.md) |
@@ -147,3 +147,3 @@ import * as util from 'util'; | ||
}), { rulesApplied: affWord.rulesApplied, flags: affWord.flags}); | ||
const rules = allRules.filter(rule => !rule.flags).map(rule => rule.id).join(''); | ||
const rules = this.joinRules(allRules.filter(rule => !rule.flags).map(rule => rule.id)); | ||
const affixRules = allRules.map(rule => rule.sfx! || rule.pfx!).filter(a => !!a); | ||
@@ -161,7 +161,7 @@ const wordWithFlags = {word, flags, rulesApplied, rules: ''}; | ||
applyAffixesToWord(affixRules: Fx[], affWord: AffWord): AffWord[] { | ||
const combinableSfx = affixRules | ||
const combineableRules = affixRules | ||
.filter(rule => rule.type === 'SFX') | ||
.filter(rule => rule.combinable === true) | ||
.map(({id}) => id) | ||
.join(''); | ||
.map(({id}) => id); | ||
const combinableSfx = this.joinRules(combineableRules); | ||
const r = affixRules | ||
@@ -182,4 +182,5 @@ .map(affix => this.applyAffixToWord(affix, affWord, combinableSfx)) | ||
const flags = { ...affWord.flags, isNeedAffix: false }; | ||
return [...affix.substitutionSets.values()] | ||
.filter(sub => sub.match.test(word)) | ||
const matchingSubstitutions = [...affix.substitutionSets.values()] | ||
.filter(sub => sub.match.test(word)); | ||
return matchingSubstitutions | ||
.map(sub => sub.substitutions) | ||
@@ -206,8 +207,20 @@ .reduce((a, b) => a.concat(b), []) | ||
joinRules(rules: string[]): string { | ||
switch (this.affInfo.FLAG) { | ||
case 'long': | ||
return rules.join(''); | ||
case 'num': | ||
return rules.join(','); | ||
} | ||
return rules.join(''); | ||
} | ||
separateRules(rules: string): string[] { | ||
if (this.affInfo.FLAG === 'long') { | ||
return rules.replace(/(..)/g, '$1//').split('//').slice(0, -1); | ||
} else { | ||
return rules.split(''); | ||
switch (this.affInfo.FLAG) { | ||
case 'long': | ||
return rules.replace(/(..)/g, '$1//').split('//').slice(0, -1); | ||
case 'num': | ||
return rules.split(','); | ||
} | ||
return rules.split(''); | ||
} | ||
@@ -214,0 +227,0 @@ |
@@ -19,2 +19,3 @@ | ||
export interface ConvEntry { from: string; to: string; } | ||
@@ -51,3 +52,20 @@ function convEntry(fieldValue: ConvEntry[], _: string, args: string[]) { | ||
const regExpStartsWithPlus = /^\+/; | ||
function tablePfxOrSfx(fieldValue: Map<string, Fx>, _: string, args: string[], type: string) { | ||
/* | ||
Fields of an affix rules: | ||
(0) Option name | ||
(1) Flag | ||
(2) stripping characters from beginning (at prefix rules) or end (at suffix rules) of the word | ||
(3) affix (optionally with flags of continuation classes, separated by a slash) | ||
(4) condition. | ||
Zero stripping or affix are indicated by zero. Zero condition is indicated by dot. | ||
Condition is a simplified, regular expression-like pattern, which must be met before the affix can be applied. | ||
(Dot signs an arbitrary character. Characters in braces sign an arbitrary character from the character subset. | ||
Dash hasn't got special meaning, but circumflex (^) next the first brace sets the complementer character set.) | ||
(5) Optional morphological fields separated by spaces or tabulators. | ||
*/ | ||
const posCondition = 2; | ||
if (fieldValue === undefined) { | ||
@@ -70,2 +88,11 @@ fieldValue = new Map<string, Fx>(); | ||
} | ||
if (subValues.length < 2) { | ||
console.log(`Affix rule missing values: ${args.join(' ')}`); | ||
return; | ||
} | ||
if (regExpStartsWithPlus.test(subValues[posCondition] || '')) { | ||
// sometimes the condition is left off, but there are morphological fields | ||
// so we need to inject a '.'. | ||
subValues.splice(posCondition, 0, '.'); | ||
} | ||
const fixRuleSet = fieldValue.get(subField)!; | ||
@@ -72,0 +99,0 @@ const substitutionSets = fixRuleSet.substitutionSets; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
79381
1408
90
Updatedrxjs@^6.2.0