de-compromise 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +15 -11
- package/builds/de-compromise.cjs +2284 -1216
- package/builds/de-compromise.min.js +3 -1
- package/builds/de-compromise.mjs +3 -1
- package/package.json +42 -39
- package/src/01-one/lexicon/_data.js +22 -22
- package/src/01-one/lexicon/compute/root.js +3 -3
- package/src/01-one/lexicon/lexicon.js +6 -6
- package/src/01-one/lexicon/methods/_data.js +29 -174
- package/src/01-one/lexicon/methods/adjectives/_test-back.js +1 -1
- package/src/01-one/lexicon/methods/adjectives/_test.js +4 -4
- package/src/01-one/lexicon/methods/adjectives/inflect.js +1 -1
- package/src/01-one/lexicon/methods/adjectives/new/adjective.js +1 -1
- package/src/01-one/lexicon/methods/adjectives/new/comparative.js +1 -1
- package/src/01-one/lexicon/methods/adjectives/new/superlative.js +1 -1
- package/src/01-one/lexicon/methods/adjectives/toRoot.js +1 -1
- package/src/01-one/lexicon/methods/nouns/_test-back.js +6 -6
- package/src/01-one/lexicon/methods/nouns/new.js +1 -1
- package/src/01-one/lexicon/methods/nouns/toPlural.js +2 -2
- package/src/01-one/lexicon/methods/nouns/toSingular.js +2 -2
- package/src/01-one/lexicon/methods/verbs/conjugate.js +4 -4
- package/src/01-one/lexicon/methods/verbs/custom/_test-from.js +6 -6
- package/src/01-one/lexicon/methods/verbs/custom/_test-to.js +7 -7
- package/src/01-one/lexicon/methods/verbs/custom/fromPastParticiple.js +1 -1
- package/src/01-one/lexicon/methods/verbs/custom/rules.js +2 -2
- package/src/01-one/lexicon/methods/verbs/custom/toPastParticiple.js +2 -2
- package/src/01-one/lexicon/methods/verbs/irregulars.js +6 -6
- package/src/01-one/lexicon/methods/verbs/toRoot.js +8 -8
- package/src/01-one/splitter/build.js +3 -3
- package/src/01-one/splitter/compute/splitter.js +4 -4
- package/src/01-one/splitter/model/index.js +4 -4
- package/src/01-one/splitter/trie.js +3 -3
- package/src/01-one/tagset/plugin.js +1 -1
- package/src/01-one/tagset/tags/dates.js +10 -0
- package/src/01-one/tagset/tags/misc.js +21 -2
- package/src/01-one/tagset/tags/nouns.js +26 -1
- package/src/01-one/tagset/tags/values.js +10 -0
- package/src/01-one/tagset/tags/verbs.js +18 -0
- package/src/01-one/tokenizer/is-sentence.js +3 -3
- package/src/01-one/tokenizer/unicode.js +2 -2
- package/src/02-two/preTagger/compute/1st-pass/regex.js +4 -4
- package/src/02-two/preTagger/compute/1st-pass/titlecase.js +2 -2
- package/src/02-two/preTagger/compute/1st-pass/year.js +2 -2
- package/src/02-two/preTagger/compute/2nd-pass/acronym.js +3 -3
- package/src/02-two/preTagger/compute/2nd-pass/fallback.js +2 -2
- package/src/02-two/preTagger/compute/2nd-pass/prefix-lookup.js +5 -5
- package/src/02-two/preTagger/compute/2nd-pass/suffix-lookup.js +5 -5
- package/src/02-two/preTagger/compute/index.js +1 -1
- package/src/03-three/adjectives/api.js +3 -3
- package/src/03-three/nouns/api.js +6 -6
- package/src/03-three/numbers/api.js +35 -35
- package/src/03-three/numbers/data.js +2 -2
- package/src/03-three/numbers/format/index.js +2 -2
- package/src/03-three/numbers/format/toText.js +12 -12
- package/src/03-three/numbers/parse/fromText.js +3 -3
- package/src/03-three/numbers/parse/index.js +5 -5
- package/src/03-three/verbs/api.js +1 -1
- package/src/_version.js +1 -1
- package/src/index.js +2 -2
- package/types/index.d.cts +9 -0
- package/types/index.d.ts +2 -2
- package/types/view/de.ts +1 -1
- package/types/view/one.ts +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
const data = {
|
|
2
2
|
ones: [
|
|
3
3
|
[1, 'eins', 'erste'],
|
|
4
4
|
[2, 'zwei', 'zweite'],
|
|
@@ -57,7 +57,7 @@ const toNumber = {}
|
|
|
57
57
|
|
|
58
58
|
Object.keys(data).forEach(k => {
|
|
59
59
|
data[k].forEach(a => {
|
|
60
|
-
|
|
60
|
+
const [num, w, ord] = a
|
|
61
61
|
toCardinal[ord] = w
|
|
62
62
|
toOrdinal[w] = ord
|
|
63
63
|
toNumber[w] = num
|
|
@@ -4,8 +4,8 @@ import { toOrdinal } from '../data.js'
|
|
|
4
4
|
|
|
5
5
|
const formatNumber = function (parsed, fmt) {
|
|
6
6
|
if (fmt === 'TextOrdinal') {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const words = toText(parsed.num)
|
|
8
|
+
const last = words[words.length - 1]
|
|
9
9
|
words[words.length - 1] = toOrdinal[last]
|
|
10
10
|
return words.join('')
|
|
11
11
|
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { data } from '../data.js'
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
const tens = data.tens.reverse()
|
|
3
|
+
const teens = data.teens.reverse()
|
|
4
|
+
const ones = data.ones.reverse()
|
|
5
|
+
const hundreds = data.hundreds.reverse()
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
const doThousands = function (num) {
|
|
9
|
-
|
|
9
|
+
const words = []
|
|
10
10
|
// hunderttausend
|
|
11
11
|
if (num >= 100000) {
|
|
12
12
|
for (let i = 0; i < ones.length; i += 1) {
|
|
13
13
|
if (num >= ones[i][0] * 100000) {
|
|
14
|
-
|
|
14
|
+
const found = ones[i][0] === 1 ? 'ein' : ones[i][1]
|
|
15
15
|
words.push(found)
|
|
16
16
|
words.push('hunderttausend')
|
|
17
17
|
num -= teens[i][0] * 100000
|
|
@@ -31,7 +31,7 @@ const doThousands = function (num) {
|
|
|
31
31
|
// dreitausend, viertausend...
|
|
32
32
|
for (let i = 0; i < ones.length; i += 1) {
|
|
33
33
|
if (num >= ones[i][0] * 1000) {
|
|
34
|
-
|
|
34
|
+
const found = ones[i][0] === 1 ? 'ein' : ones[i][1]
|
|
35
35
|
return [found, 'tausend']
|
|
36
36
|
}
|
|
37
37
|
}
|
|
@@ -39,7 +39,7 @@ const doThousands = function (num) {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
const doHundreds = function (num) {
|
|
42
|
-
|
|
42
|
+
const words = []
|
|
43
43
|
for (let i = 0; i < hundreds.length; i += 1) {
|
|
44
44
|
if (num >= hundreds[i][0]) {
|
|
45
45
|
words.push(hundreds[i][1])
|
|
@@ -52,7 +52,7 @@ const doHundreds = function (num) {
|
|
|
52
52
|
|
|
53
53
|
// 23 -> '[drei][und][zwanzig]'
|
|
54
54
|
const twoDigit = function (num) {
|
|
55
|
-
|
|
55
|
+
const words = []
|
|
56
56
|
// ninety, eighty ...
|
|
57
57
|
for (let i = 0; i < tens.length; i += 1) {
|
|
58
58
|
if (num >= tens[i][0]) {
|
|
@@ -74,7 +74,7 @@ const twoDigit = function (num) {
|
|
|
74
74
|
// drei und zwanzig
|
|
75
75
|
if (words.length === 1) {
|
|
76
76
|
// use '[ein][und][zwanzig]', not 'eins..'
|
|
77
|
-
|
|
77
|
+
const found = ones[i][0] === 1 ? 'ein' : ones[i][1]
|
|
78
78
|
return [found, 'und', words[0]]
|
|
79
79
|
}
|
|
80
80
|
// just 'drei'
|
|
@@ -99,13 +99,13 @@ const toText = function (num) {
|
|
|
99
99
|
}
|
|
100
100
|
// do '[sieben][tausend]'
|
|
101
101
|
if (num >= 1000) {
|
|
102
|
-
|
|
102
|
+
const res = doThousands(num)
|
|
103
103
|
words = words.concat(res)
|
|
104
104
|
num %= 1000
|
|
105
105
|
}
|
|
106
106
|
// do '[zwei][hundert]'
|
|
107
107
|
if (num >= 100) {
|
|
108
|
-
|
|
108
|
+
const res = doHundreds(num)
|
|
109
109
|
words = words.concat(res)
|
|
110
110
|
num %= 100
|
|
111
111
|
}
|
|
@@ -5,9 +5,9 @@ const parseNumbers = function (terms = []) {
|
|
|
5
5
|
let carry = 0
|
|
6
6
|
let minus = false
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
const words = terms[0].splits || []
|
|
9
9
|
// console.log(words)
|
|
10
|
-
|
|
10
|
+
const tags = terms[0].tags
|
|
11
11
|
for (let i = 0; i < words.length; i += 1) {
|
|
12
12
|
let w = words[i]
|
|
13
13
|
|
|
@@ -25,7 +25,7 @@ const parseNumbers = function (terms = []) {
|
|
|
25
25
|
}
|
|
26
26
|
// 'hundert'
|
|
27
27
|
if (isMultiple.has(w)) {
|
|
28
|
-
|
|
28
|
+
const mult = toNumber[w] || 1
|
|
29
29
|
if (carry === 0) {
|
|
30
30
|
carry = 1
|
|
31
31
|
}
|
|
@@ -5,12 +5,12 @@ const fromNumber = function (m) {
|
|
|
5
5
|
let str = (m.text() || m.text('normal')).toLowerCase().trim()
|
|
6
6
|
str = str.replace(/(e|er)$/, '')
|
|
7
7
|
// get prefix/suffix
|
|
8
|
-
|
|
8
|
+
const arr = str.split(/([0-9.,]*)/)
|
|
9
9
|
let [prefix, num] = arr
|
|
10
10
|
let suffix = arr.slice(2).join('')
|
|
11
11
|
// german format - '.' groups thousands, ',' marks the decimal
|
|
12
12
|
num = num.replace(/[.,]$/, '')
|
|
13
|
-
|
|
13
|
+
const hasComma = /\d\.\d/.test(num)
|
|
14
14
|
num = num.replace(/\./g, '').replace(/,/, '.')
|
|
15
15
|
if (num !== '' && m.length < 2) {
|
|
16
16
|
num = Number(num)
|
|
@@ -34,16 +34,16 @@ const fromNumber = function (m) {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
const parseNumber = function (m) {
|
|
37
|
-
|
|
37
|
+
const terms = m.docs[0]
|
|
38
38
|
let num = null
|
|
39
39
|
let prefix = ''
|
|
40
40
|
let suffix = ''
|
|
41
41
|
let hasComma = false
|
|
42
|
-
|
|
42
|
+
const isText = m.has('#TextValue')
|
|
43
43
|
if (isText) {
|
|
44
44
|
num = fromText(terms)
|
|
45
45
|
} else {
|
|
46
|
-
|
|
46
|
+
const res = fromNumber(m)
|
|
47
47
|
prefix = res.prefix
|
|
48
48
|
suffix = res.suffix
|
|
49
49
|
num = res.num
|
|
@@ -17,7 +17,7 @@ const api = function (View) {
|
|
|
17
17
|
const methods = this.methods.two.transform.verb
|
|
18
18
|
const { toPresent, toPast, toSubjunctive1, toSubjunctive2, toImperative, toPastParticiple, toPresentParticiple } = methods
|
|
19
19
|
return getNth(this, n).map(m => {
|
|
20
|
-
|
|
20
|
+
const str = getRoot(m, methods)
|
|
21
21
|
return {
|
|
22
22
|
infinitive: str,
|
|
23
23
|
presentTense: toPresent(str),
|
package/src/_version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '0.1.
|
|
1
|
+
export default '0.1.2'
|
package/src/index.js
CHANGED
|
@@ -23,7 +23,7 @@ nlp.plugin(adjectives)
|
|
|
23
23
|
nlp.plugin(nouns)
|
|
24
24
|
|
|
25
25
|
const de = function (txt, lex) {
|
|
26
|
-
|
|
26
|
+
const dok = nlp(txt, lex)
|
|
27
27
|
return dok
|
|
28
28
|
}
|
|
29
29
|
|
|
@@ -41,7 +41,7 @@ Object.defineProperty(de, '_world', {
|
|
|
41
41
|
})
|
|
42
42
|
/** log the decision-making to console */
|
|
43
43
|
de.verbose = function (set) {
|
|
44
|
-
|
|
44
|
+
const env = typeof process === 'undefined' ? self.env || {} : process.env //use window, in browser
|
|
45
45
|
env.DEBUG_TAGS = set === 'tagger' || set === true ? true : ''
|
|
46
46
|
env.DEBUG_MATCH = set === 'match' || set === true ? true : ''
|
|
47
47
|
env.DEBUG_CHUNKS = set === 'chunker' || set === true ? true : ''
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// CommonJS exports the callable directly; share its API with the ESM declarations.
|
|
2
|
+
import type esm from './index.js' with { "resolution-mode": "import" }
|
|
3
|
+
|
|
4
|
+
declare const nlp: typeof esm
|
|
5
|
+
declare namespace nlp {
|
|
6
|
+
export type TypedPlugin<Methods extends object> = esm.TypedPlugin<Methods>
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export = nlp
|
package/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Lexicon, Plugin, matchOptions, Match, Net } from './misc'
|
|
2
|
-
import View from './view/de'
|
|
1
|
+
import { Lexicon, Plugin, matchOptions, Match, Net } from './misc.js'
|
|
2
|
+
import View from './view/de.js'
|
|
3
3
|
|
|
4
4
|
/** parse a given text */
|
|
5
5
|
declare function nlp(text: string, lexicon?: Lexicon): View
|
package/types/view/de.ts
CHANGED
package/types/view/one.ts
CHANGED