ja-compromise 0.0.1 → 0.1.0
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 +21 -0
- package/README.md +367 -6
- package/builds/ja-compromise.cjs +4389 -2286
- package/builds/ja-compromise.min.js +1 -1
- package/builds/ja-compromise.mjs +1 -1
- package/package.json +36 -23
- package/src/01-one/conjugate/conjugate-adj.js +53 -0
- package/src/01-one/conjugate/conjugate-verb.js +145 -0
- package/src/01-one/conjugate/deconjugate.js +178 -0
- package/src/01-one/conjugate/index.js +13 -0
- package/src/01-one/conjugate/kana.js +38 -0
- package/src/01-one/conjugate/tags.js +85 -0
- package/src/01-one/conjugate/verb-class.js +105 -0
- package/src/01-one/lexicon/_data.js +30 -0
- package/src/01-one/lexicon/api.js +61 -0
- package/src/01-one/lexicon/lexicon.js +163 -0
- package/src/01-one/lexicon/misc.js +115 -0
- package/src/01-one/lexicon/plugin.js +20 -0
- package/src/01-one/numbers/api.js +202 -0
- package/src/01-one/numbers/kanji-number.js +69 -0
- package/src/01-one/numbers/to-kanji.js +66 -0
- package/src/01-one/output/compute/dict.js +13 -0
- package/src/01-one/output/compute/english.js +13 -0
- package/src/01-one/output/compute/root.js +30 -0
- package/src/01-one/output/debug/_color.js +16 -0
- package/src/01-one/output/debug/index.js +24 -0
- package/src/01-one/output/debug/tags.js +56 -0
- package/src/01-one/output/plugin.js +13 -0
- package/src/01-one/romanji/api.js +16 -0
- package/src/01-one/romanji/compute/index.js +36 -0
- package/src/01-one/romanji/compute/kanji-reading/index.js +91 -0
- package/src/01-one/romanji/compute/kanji-reading/readings.js +861 -0
- package/src/01-one/romanji/compute/kanji-reading/words.js +31 -0
- package/src/01-one/romanji/compute/toRomanji/hiragana-map.js +175 -0
- package/src/01-one/romanji/compute/toRomanji/index.js +84 -0
- package/src/01-one/romanji/compute/toRomanji/katakana-map.js +128 -0
- package/src/01-one/romanji/plugin.js +7 -0
- package/src/01-one/tokenizer/methods/join-numbers.js +32 -0
- package/src/01-one/tokenizer/methods/join-up.js +66 -0
- package/src/01-one/tokenizer/methods/lib.js +66 -0
- package/src/01-one/tokenizer/methods/naiive-split.js +88 -0
- package/src/01-one/tokenizer/methods/okurigana.js +58 -0
- package/src/01-one/tokenizer/methods/terms.js +143 -0
- package/src/01-one/tokenizer/methods/trie/build.js +13 -0
- package/src/01-one/tokenizer/methods/trie/split-up.js +29 -0
- package/src/01-one/tokenizer/methods/whitespace.js +44 -0
- package/src/01-one/tokenizer/plugin.js +13 -0
- package/src/02-two/preTagger/compute/01-script.js +44 -0
- package/src/02-two/preTagger/compute/02-particles.js +82 -0
- package/src/02-two/preTagger/compute/03-verbs.js +111 -0
- package/src/02-two/preTagger/compute/04-adjectives.js +43 -0
- package/src/02-two/preTagger/compute/05-people.js +22 -0
- package/src/02-two/preTagger/compute/06-numbers.js +80 -0
- package/src/02-two/preTagger/compute/07-dates.js +105 -0
- package/src/02-two/preTagger/compute/index.js +52 -0
- package/src/02-two/preTagger/plugin.js +9 -0
- package/src/02-two/tagset/plugin.js +12 -0
- package/src/02-two/tagset/tags/dates.js +58 -0
- package/src/02-two/tagset/tags/misc.js +91 -0
- package/src/02-two/tagset/tags/nouns.js +131 -0
- package/src/02-two/tagset/tags/particles.js +50 -0
- package/src/02-two/tagset/tags/values.js +68 -0
- package/src/02-two/tagset/tags/verbs.js +93 -0
- package/src/_lib.js +2 -0
- package/src/_version.js +1 -0
- package/src/index.js +82 -0
- package/types/index.d.ts +268 -0
- package/types/japanese.d.ts +159 -0
- package/types/misc.d.ts +92 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
Verb: {
|
|
3
|
+
not: ['Noun', 'Adjective', 'Adverb', 'Value', 'Expression'],
|
|
4
|
+
},
|
|
5
|
+
ConditionalVerb: {
|
|
6
|
+
is: 'Verb',
|
|
7
|
+
},
|
|
8
|
+
Passive: {
|
|
9
|
+
is: 'Verb',
|
|
10
|
+
},
|
|
11
|
+
Causative: {
|
|
12
|
+
is: 'Verb',
|
|
13
|
+
},
|
|
14
|
+
// tense is a facet, not a class: japanese adjectives carry it too
|
|
15
|
+
// (高かった is a past-tense *adjective*), so these must not imply #Verb
|
|
16
|
+
PresentTense: {
|
|
17
|
+
not: ['PastTense'],
|
|
18
|
+
},
|
|
19
|
+
Infinitive: {
|
|
20
|
+
is: 'Verb',
|
|
21
|
+
not: ['Gerund'],
|
|
22
|
+
},
|
|
23
|
+
Imperative: {
|
|
24
|
+
is: 'Verb',
|
|
25
|
+
},
|
|
26
|
+
// the て-form takes its tense from the helper verb that follows it
|
|
27
|
+
// (読んで いました), so it must not fight with #PastTense
|
|
28
|
+
Gerund: {},
|
|
29
|
+
PastTense: {
|
|
30
|
+
not: ['PresentTense'],
|
|
31
|
+
},
|
|
32
|
+
Copula: {
|
|
33
|
+
is: 'Verb',
|
|
34
|
+
},
|
|
35
|
+
Modal: {
|
|
36
|
+
is: 'Verb',
|
|
37
|
+
not: ['Infinitive'],
|
|
38
|
+
},
|
|
39
|
+
PerfectTense: {
|
|
40
|
+
is: 'Verb',
|
|
41
|
+
not: ['Gerund'],
|
|
42
|
+
},
|
|
43
|
+
Pluperfect: {
|
|
44
|
+
is: 'Verb',
|
|
45
|
+
},
|
|
46
|
+
Participle: {
|
|
47
|
+
is: 'PastTense',
|
|
48
|
+
},
|
|
49
|
+
PhrasalVerb: {
|
|
50
|
+
is: 'Verb',
|
|
51
|
+
},
|
|
52
|
+
Particle: {
|
|
53
|
+
is: 'PhrasalVerb',
|
|
54
|
+
not: ['PastTense', 'PresentTense', 'Copula', 'Gerund'],
|
|
55
|
+
},
|
|
56
|
+
Auxiliary: {
|
|
57
|
+
is: 'Verb',
|
|
58
|
+
not: ['Conjunction'],
|
|
59
|
+
},
|
|
60
|
+
// japanese stacks these onto a single word, so they're facets, not classes
|
|
61
|
+
Negative: {
|
|
62
|
+
not: ['Noun', 'Value'],
|
|
63
|
+
},
|
|
64
|
+
Polite: {},
|
|
65
|
+
Volitional: {
|
|
66
|
+
is: 'Verb',
|
|
67
|
+
},
|
|
68
|
+
Potential: {
|
|
69
|
+
is: 'Verb',
|
|
70
|
+
},
|
|
71
|
+
Progressive: {
|
|
72
|
+
is: 'Verb',
|
|
73
|
+
},
|
|
74
|
+
Desire: {
|
|
75
|
+
is: 'Verb',
|
|
76
|
+
},
|
|
77
|
+
Representative: {
|
|
78
|
+
is: 'Verb',
|
|
79
|
+
},
|
|
80
|
+
Presumptive: {},
|
|
81
|
+
Continuative: {
|
|
82
|
+
is: 'Verb',
|
|
83
|
+
},
|
|
84
|
+
// 連用形 - the 'masu-stem'. it heads a verb-phrase (泳ぎます) but stands
|
|
85
|
+
// alone as a noun too - 泳ぎ is 'a swim'
|
|
86
|
+
VerbStem: {
|
|
87
|
+
is: 'Noun',
|
|
88
|
+
},
|
|
89
|
+
// 勉強, which is a noun until it meets する
|
|
90
|
+
SuruVerb: {
|
|
91
|
+
is: 'Noun',
|
|
92
|
+
},
|
|
93
|
+
}
|
package/src/_lib.js
ADDED
package/src/_version.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default '0.1.0'
|
package/src/index.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import nlp from './_lib.js'
|
|
2
|
+
import lexicon from './01-one/lexicon/plugin.js'
|
|
3
|
+
import toTerms from './01-one/tokenizer/methods/whitespace.js'
|
|
4
|
+
import romanji from './01-one/romanji/plugin.js'
|
|
5
|
+
import tokenizer from './01-one/tokenizer/plugin.js'
|
|
6
|
+
import output from './01-one/output/plugin.js'
|
|
7
|
+
import tagset from './02-two/tagset/plugin.js'
|
|
8
|
+
import preTagger from './02-two/preTagger/plugin.js'
|
|
9
|
+
import version from './_version.js'
|
|
10
|
+
import { methods as lexMethods } from './01-one/lexicon/api.js'
|
|
11
|
+
import toNumber from './01-one/numbers/kanji-number.js'
|
|
12
|
+
import toKanji from './01-one/numbers/to-kanji.js'
|
|
13
|
+
import numbers from './01-one/numbers/api.js'
|
|
14
|
+
|
|
15
|
+
nlp.plugin(tokenizer)
|
|
16
|
+
nlp.plugin(tagset)
|
|
17
|
+
nlp.plugin(lexicon)
|
|
18
|
+
nlp.plugin(output)
|
|
19
|
+
nlp.plugin(romanji)
|
|
20
|
+
nlp.plugin(preTagger)
|
|
21
|
+
nlp.plugin(numbers)
|
|
22
|
+
|
|
23
|
+
const ja = function (txt, lex) {
|
|
24
|
+
// split sentences
|
|
25
|
+
let doc = nlp.tokenize(txt, lex)
|
|
26
|
+
// tokenize terms ourselves - compromise splits on whitespace, which japanese
|
|
27
|
+
// mostly doesn't use. every whitespace-chunk still needs splitting, so run
|
|
28
|
+
// the tokenizer over each of them and keep their surrounding punctuation.
|
|
29
|
+
doc.document = doc.document.map(a => {
|
|
30
|
+
let out = []
|
|
31
|
+
// if the sentence has spaces in it, they're real word-boundaries
|
|
32
|
+
let spaced = a.length > 1
|
|
33
|
+
a.forEach(term => {
|
|
34
|
+
let terms = toTerms(term.text, spaced)
|
|
35
|
+
if (terms.length === 0) {
|
|
36
|
+
out.push(term)
|
|
37
|
+
return
|
|
38
|
+
}
|
|
39
|
+
terms[0].pre = (term.pre || '') + terms[0].pre
|
|
40
|
+
terms[terms.length - 1].post += term.post || ''
|
|
41
|
+
out = out.concat(terms)
|
|
42
|
+
})
|
|
43
|
+
return out
|
|
44
|
+
})
|
|
45
|
+
const world = nlp.world()
|
|
46
|
+
doc.compute(world.hooks)
|
|
47
|
+
return doc
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// copy constructor methods over
|
|
51
|
+
Object.keys(nlp).forEach(k => {
|
|
52
|
+
if (nlp.hasOwnProperty(k)) {
|
|
53
|
+
ja[k] = nlp[k]
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
// this one is hidden
|
|
58
|
+
Object.defineProperty(ja, '_world', {
|
|
59
|
+
value: nlp._world,
|
|
60
|
+
writable: true,
|
|
61
|
+
})
|
|
62
|
+
/** log the decision-making to console */
|
|
63
|
+
ja.verbose = function (set) {
|
|
64
|
+
let env = typeof process === 'undefined' ? self.env || {} : process.env //use window, in browser
|
|
65
|
+
env.DEBUG_TAGS = set === 'tagger' || set === true ? true : ''
|
|
66
|
+
env.DEBUG_MATCH = set === 'match' || set === true ? true : ''
|
|
67
|
+
env.DEBUG_CHUNKS = set === 'chunker' || set === true ? true : ''
|
|
68
|
+
return this
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// conjugation helpers, usable without a document
|
|
72
|
+
Object.assign(ja, lexMethods)
|
|
73
|
+
|
|
74
|
+
/** parse a japanese numeral - nlp.toNumber('二十三') === 23 */
|
|
75
|
+
ja.toNumber = toNumber
|
|
76
|
+
|
|
77
|
+
/** write a number in kanji - nlp.toKanji(23) === '二十三' */
|
|
78
|
+
ja.toKanji = toKanji
|
|
79
|
+
|
|
80
|
+
ja.version = version
|
|
81
|
+
|
|
82
|
+
export default ja
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Document, Pointer, Groups, JsonProps, outMethods, Term, Net,
|
|
3
|
+
Lexicon, Plugin, matchOptions, Match,
|
|
4
|
+
} from './misc'
|
|
5
|
+
import type {
|
|
6
|
+
VerbClass, VerbConjugation, IAdjectiveConjugation, NaAdjectiveConjugation,
|
|
7
|
+
Deconjugation, NumberParse,
|
|
8
|
+
} from './japanese'
|
|
9
|
+
|
|
10
|
+
/** a view onto some part of a parsed document */
|
|
11
|
+
declare class View {
|
|
12
|
+
// ---- utils ----
|
|
13
|
+
/** is this document empty? */
|
|
14
|
+
found: boolean
|
|
15
|
+
/** the term objects in this view */
|
|
16
|
+
docs: Document
|
|
17
|
+
/** the whole parsed document */
|
|
18
|
+
document: Document
|
|
19
|
+
/** the indexes for the current view */
|
|
20
|
+
pointer: Pointer[] | null
|
|
21
|
+
/** explicit indexes for the current view */
|
|
22
|
+
fullPointer: Pointer[]
|
|
23
|
+
/** internal library methods */
|
|
24
|
+
methods: object
|
|
25
|
+
/** internal library data */
|
|
26
|
+
model: object
|
|
27
|
+
/** which compute methods run by default */
|
|
28
|
+
hooks: string[]
|
|
29
|
+
/** helper for detecting a compromise object */
|
|
30
|
+
isView: boolean
|
|
31
|
+
/** the number of characters in each match */
|
|
32
|
+
length: number
|
|
33
|
+
|
|
34
|
+
update: (pointer: Pointer | null) => View
|
|
35
|
+
toView: (pointer: Pointer | null) => View
|
|
36
|
+
fromText: (text: string) => View
|
|
37
|
+
/** .docs [alias] */
|
|
38
|
+
termList: () => Term[]
|
|
39
|
+
/** run a named analysis - 'root', 'romanji', 'readings', 'english' */
|
|
40
|
+
compute: (method: string | string[]) => View
|
|
41
|
+
/** deep-copy the document, so no references remain */
|
|
42
|
+
clone: (shallow?: boolean) => View
|
|
43
|
+
|
|
44
|
+
// ---- loops ----
|
|
45
|
+
forEach: (fn: (m: View) => void) => View
|
|
46
|
+
map: (fn: (m: View) => any, emptyResult?: any) => View | []
|
|
47
|
+
filter: (fn: (m: View) => boolean) => View
|
|
48
|
+
find: (fn: (m: View) => boolean) => View | undefined
|
|
49
|
+
some: (fn: (m: View) => boolean) => View
|
|
50
|
+
random: (n?: number) => View
|
|
51
|
+
|
|
52
|
+
// ---- accessors ----
|
|
53
|
+
terms: (n?: number) => View
|
|
54
|
+
groups: (name?: string) => View | Groups
|
|
55
|
+
eq: (n: number) => View
|
|
56
|
+
first: (n?: number) => View
|
|
57
|
+
last: (n?: number) => View
|
|
58
|
+
firstTerms: () => View
|
|
59
|
+
lastTerms: () => View
|
|
60
|
+
slice: (start: number, end?: number) => View
|
|
61
|
+
all: () => View
|
|
62
|
+
fullSentences: () => View
|
|
63
|
+
none: () => View
|
|
64
|
+
isDoc: (view?: View) => boolean
|
|
65
|
+
wordCount: () => number
|
|
66
|
+
|
|
67
|
+
// ---- match ----
|
|
68
|
+
match: (match: string | View | Net, group?: string | number, options?: matchOptions) => View
|
|
69
|
+
matchOne: (match: string | View | Net, group?: string | number, options?: matchOptions) => View
|
|
70
|
+
has: (match: string | View | Net, group?: string | number, options?: matchOptions) => boolean
|
|
71
|
+
if: (match: string | View | Net, group?: string | number, options?: matchOptions) => View
|
|
72
|
+
ifNo: (match: string | View | Net, group?: string | number, options?: matchOptions) => View
|
|
73
|
+
before: (match: string | View, group?: string | number, options?: matchOptions) => View
|
|
74
|
+
after: (match: string | View, group?: string | number, options?: matchOptions) => View
|
|
75
|
+
growLeft: (match: string | View, group?: string | number, options?: matchOptions) => View
|
|
76
|
+
growRight: (match: string | View, group?: string | number, options?: matchOptions) => View
|
|
77
|
+
grow: (match: string | View, group?: string | number, options?: matchOptions) => View
|
|
78
|
+
sweep: (match: Net, opts?: object) => { view: View; found: object[] }
|
|
79
|
+
splitOn: (match?: string, group?: string | number) => View
|
|
80
|
+
splitBefore: (match?: string, group?: string | number) => View
|
|
81
|
+
splitAfter: (match?: string, group?: string | number) => View
|
|
82
|
+
split: (match?: string, group?: string | number) => View
|
|
83
|
+
|
|
84
|
+
// ---- case ----
|
|
85
|
+
toLowerCase: () => View
|
|
86
|
+
toUpperCase: () => View
|
|
87
|
+
toTitleCase: () => View
|
|
88
|
+
toCamelCase: () => View
|
|
89
|
+
|
|
90
|
+
// ---- insert ----
|
|
91
|
+
concat: (input: string | View) => View
|
|
92
|
+
insertBefore: (input: string | View) => View
|
|
93
|
+
prepend: (input: string | View) => View
|
|
94
|
+
insertAfter: (text: string | View) => View
|
|
95
|
+
append: (text: string | View) => View
|
|
96
|
+
insert: (text: string | View) => View
|
|
97
|
+
remove: (match?: string | View) => View
|
|
98
|
+
delete: (match?: string | View) => View
|
|
99
|
+
replace: (from: string | View, to?: string | Function, keep?: object) => View
|
|
100
|
+
replaceWith: (to: string | Function, keep?: object) => View
|
|
101
|
+
unique: () => View
|
|
102
|
+
reverse: () => View
|
|
103
|
+
sort: (method?: string | Function) => View
|
|
104
|
+
|
|
105
|
+
// ---- whitespace ----
|
|
106
|
+
pre: (str?: string, concat?: boolean) => View
|
|
107
|
+
post: (str?: string, concat?: boolean) => View
|
|
108
|
+
trim: () => View
|
|
109
|
+
hyphenate: () => View
|
|
110
|
+
dehyphenate: () => View
|
|
111
|
+
deHyphenate: () => View
|
|
112
|
+
toQuotations: (start?: string, end?: string) => View
|
|
113
|
+
toQuotation: (start?: string, end?: string) => View
|
|
114
|
+
toParentheses: (start?: string, end?: string) => View
|
|
115
|
+
|
|
116
|
+
// ---- output ----
|
|
117
|
+
/** the document as text. `'root'` gives dictionary-forms */
|
|
118
|
+
text: (options?: string | object) => string
|
|
119
|
+
json: (options?: JsonProps | string) => any
|
|
120
|
+
/** pretty-print the document and its tags to the console */
|
|
121
|
+
debug: () => View
|
|
122
|
+
out: (format?: outMethods) => any
|
|
123
|
+
html: (toHighlight: object) => string
|
|
124
|
+
wrap: (matches: object) => string
|
|
125
|
+
|
|
126
|
+
// ---- pointers ----
|
|
127
|
+
union: (match: string | View) => View
|
|
128
|
+
and: (match: string | View) => View
|
|
129
|
+
intersection: (match: string | View) => View
|
|
130
|
+
not: (match: string | View, options?: any) => View
|
|
131
|
+
difference: (match: string | View, options?: any) => View
|
|
132
|
+
complement: (match: string | View) => View
|
|
133
|
+
settle: (match: string | View) => View
|
|
134
|
+
|
|
135
|
+
// ---- tags ----
|
|
136
|
+
tag: (tag: string, reason?: string) => View
|
|
137
|
+
tagSafe: (tag: string, reason?: string) => View
|
|
138
|
+
unTag: (tag: string, reason?: string) => View
|
|
139
|
+
canBe: (tag: string) => View
|
|
140
|
+
|
|
141
|
+
// ---- cache ----
|
|
142
|
+
cache: (options?: object) => View
|
|
143
|
+
uncache: (options?: object) => View
|
|
144
|
+
lookup: (trie: object | string[], opts?: object) => View
|
|
145
|
+
autoFill: () => View
|
|
146
|
+
|
|
147
|
+
// ---- japanese ----
|
|
148
|
+
/** every 動詞 in the document */
|
|
149
|
+
verbs: () => View
|
|
150
|
+
/** every 名詞 in the document */
|
|
151
|
+
nouns: () => View
|
|
152
|
+
/** every 形容詞 and 形容動詞 in the document */
|
|
153
|
+
adjectives: () => View
|
|
154
|
+
/** every 助詞 in the document */
|
|
155
|
+
particles: () => View
|
|
156
|
+
/** every number in the document */
|
|
157
|
+
numbers: (n?: number) => Numbers
|
|
158
|
+
/** .numbers() alias */
|
|
159
|
+
values: (n?: number) => Numbers
|
|
160
|
+
/** every 助数詞 in the document */
|
|
161
|
+
counters: (n?: number) => View
|
|
162
|
+
/** every 円/ドル amount */
|
|
163
|
+
money: (n?: number) => View
|
|
164
|
+
/** every percentage */
|
|
165
|
+
percentages: (n?: number) => View
|
|
166
|
+
/** every date, time and duration */
|
|
167
|
+
dates: () => View
|
|
168
|
+
/** the document sounded-out in the latin alphabet */
|
|
169
|
+
romanji: () => string
|
|
170
|
+
/** the dictionary-form of each match - 食べました → 食べる */
|
|
171
|
+
toInfinitive: () => string[]
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** a view of the numbers in a document */
|
|
175
|
+
declare class Numbers extends View {
|
|
176
|
+
/** the parsed number, and how it was written */
|
|
177
|
+
parse: (n?: number) => NumberParse[]
|
|
178
|
+
/** the value of each number - 「二十三」 gives 23 */
|
|
179
|
+
get: (n?: number) => (number | null)[]
|
|
180
|
+
/** the 助数詞 attached to each number - 五冊 gives 冊 */
|
|
181
|
+
units: () => View
|
|
182
|
+
/** only the ordinals */
|
|
183
|
+
isOrdinal: () => Numbers
|
|
184
|
+
/** only the cardinals */
|
|
185
|
+
isCardinal: () => Numbers
|
|
186
|
+
/** rewrite each number in digits - 二十三 becomes 23 */
|
|
187
|
+
toNumber: () => Numbers
|
|
188
|
+
/** rewrite each number in kanji - 23 becomes 二十三 */
|
|
189
|
+
toText: () => Numbers
|
|
190
|
+
/** add thousands-separators - 1234 becomes 1,234 */
|
|
191
|
+
toLocaleString: () => Numbers
|
|
192
|
+
/** replace each number, keeping the script it was written in */
|
|
193
|
+
set: (n: number) => Numbers
|
|
194
|
+
add: (n: number) => Numbers
|
|
195
|
+
subtract: (n: number) => Numbers
|
|
196
|
+
increment: () => Numbers
|
|
197
|
+
decrement: () => Numbers
|
|
198
|
+
isEqual: (n: number) => Numbers
|
|
199
|
+
greaterThan: (n: number) => Numbers
|
|
200
|
+
lessThan: (n: number) => Numbers
|
|
201
|
+
between: (min: number, max: number) => Numbers
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** parse some japanese text */
|
|
205
|
+
declare function nlp(text: string, lexicon?: Lexicon): View
|
|
206
|
+
|
|
207
|
+
declare namespace nlp {
|
|
208
|
+
// ---- constructor ----
|
|
209
|
+
/** interpret text without tagging */
|
|
210
|
+
export function tokenize(text: string, lexicon?: Lexicon): View
|
|
211
|
+
/** mix-in a compromise plugin */
|
|
212
|
+
export function plugin(plugin: Plugin): any
|
|
213
|
+
/** mix-in a compromise plugin */
|
|
214
|
+
export function extend(plugin: Plugin): any
|
|
215
|
+
/** turn a match-string into json */
|
|
216
|
+
export function parseMatch(match: string, opts?: matchOptions): object[]
|
|
217
|
+
/** grab library internals */
|
|
218
|
+
export function world(): object
|
|
219
|
+
/** grab all current linguistic data */
|
|
220
|
+
export function model(): object
|
|
221
|
+
/** grab exposed library methods */
|
|
222
|
+
export function methods(): object
|
|
223
|
+
/** which compute methods run automatically */
|
|
224
|
+
export function hooks(): string[]
|
|
225
|
+
/** log the tagger's decision-making to the console */
|
|
226
|
+
export function verbose(mode?: boolean | 'tagger' | 'match' | 'chunker'): any
|
|
227
|
+
/** current semver version of the library */
|
|
228
|
+
export const version: string
|
|
229
|
+
/** connect new tags to the tagset graph */
|
|
230
|
+
export function addTags(tags: object): any
|
|
231
|
+
/** add new words to the lexicon */
|
|
232
|
+
export function addWords(words: Lexicon): any
|
|
233
|
+
/** turn a list of words into a searchable graph */
|
|
234
|
+
export function buildTrie(words: string[]): object
|
|
235
|
+
/** compile a set of match objects into a faster form */
|
|
236
|
+
export function buildNet(matches: Match[]): Net
|
|
237
|
+
/** add words to the autoFill dictionary */
|
|
238
|
+
export function typeahead(words: Lexicon): any
|
|
239
|
+
|
|
240
|
+
// ---- japanese ----
|
|
241
|
+
/**
|
|
242
|
+
* the full paradigm of a dictionary-form verb.
|
|
243
|
+
* returns null if the word isn't a shape we can conjugate.
|
|
244
|
+
*/
|
|
245
|
+
export function conjugate(dictionaryForm: string): VerbConjugation | null
|
|
246
|
+
/**
|
|
247
|
+
* the paradigm of an adjective. a word ending in い is treated as an
|
|
248
|
+
* い-adjective, anything else as a な-adjective.
|
|
249
|
+
*/
|
|
250
|
+
export function conjugateAdjective(word: string): IAdjectiveConjugation | NaAdjectiveConjugation | null
|
|
251
|
+
/** walk a conjugated verb back to its dictionary-form */
|
|
252
|
+
export function deconjugate(word: string): Deconjugation | null
|
|
253
|
+
/** which paradigm a dictionary-form verb follows */
|
|
254
|
+
export function verbClass(dictionaryForm: string): VerbClass | null
|
|
255
|
+
/**
|
|
256
|
+
* parse a japanese numeral - `nlp.toNumber('二十三')` is 23.
|
|
257
|
+
* handles kanji, half-width and full-width digits. null if it isn't one.
|
|
258
|
+
*/
|
|
259
|
+
export function toNumber(numeral: string): number | null
|
|
260
|
+
/** write a number in kanji - `nlp.toKanji(23)` is 二十三 */
|
|
261
|
+
export function toKanji(num: number): string | null
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export default nlp
|
|
265
|
+
export type {
|
|
266
|
+
View, Numbers, VerbClass, VerbConjugation, IAdjectiveConjugation,
|
|
267
|
+
NaAdjectiveConjugation, Deconjugation, NumberParse, Term, Lexicon, Plugin,
|
|
268
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
// the japanese-specific shapes: conjugation paradigms and verb classes.
|
|
2
|
+
|
|
3
|
+
/** which paradigm a verb follows */
|
|
4
|
+
export type VerbClass =
|
|
5
|
+
| 'godan' // 五段 - 書く, 話す, 帰る
|
|
6
|
+
| 'ichidan' // 一段 - 食べる, 見る
|
|
7
|
+
| 'suru' // する, and every 〜する compound
|
|
8
|
+
| 'kuru' // 来る, and て-form + 来る
|
|
9
|
+
| 'aru' // ある - its negative is ない, not あらない
|
|
10
|
+
| 'iku' // 行く - its て-form is 行って, not 行いて
|
|
11
|
+
| 'ou' // 問う, 請う - 問うて, not 問って
|
|
12
|
+
| 'aru5' // くださる, なさる, いらっしゃる - masu-stem drops the り
|
|
13
|
+
|
|
14
|
+
/** every form of a verb, built from its dictionary-form */
|
|
15
|
+
export interface VerbConjugation {
|
|
16
|
+
/** which paradigm produced these */
|
|
17
|
+
class: VerbClass
|
|
18
|
+
/** 辞書形 - 書く */
|
|
19
|
+
Infinitive: string
|
|
20
|
+
/** 連用形, the 'masu-stem' - 書き */
|
|
21
|
+
Stem: string
|
|
22
|
+
/** 書く */
|
|
23
|
+
PresentTense: string
|
|
24
|
+
/** 書いた */
|
|
25
|
+
PastTense: string
|
|
26
|
+
/** 書かない */
|
|
27
|
+
Negative: string
|
|
28
|
+
/** 書かなかった */
|
|
29
|
+
PastNegative: string
|
|
30
|
+
/** て形 - 書いて */
|
|
31
|
+
Gerund: string
|
|
32
|
+
/** 書かなくて */
|
|
33
|
+
NegativeGerund: string
|
|
34
|
+
/** 書きます */
|
|
35
|
+
Polite: string
|
|
36
|
+
/** 書きました */
|
|
37
|
+
PolitePast: string
|
|
38
|
+
/** 書きません */
|
|
39
|
+
PoliteNegative: string
|
|
40
|
+
/** 書きませんでした */
|
|
41
|
+
PolitePastNegative: string
|
|
42
|
+
/** 書きましょう */
|
|
43
|
+
PoliteVolitional: string
|
|
44
|
+
/** 命令形 - 書け */
|
|
45
|
+
Imperative: string
|
|
46
|
+
/** 書くな */
|
|
47
|
+
NegativeImperative: string
|
|
48
|
+
/** 書こう */
|
|
49
|
+
Volitional: string
|
|
50
|
+
/** 可能形 - 書ける */
|
|
51
|
+
Potential: string
|
|
52
|
+
/** 受身形 - 書かれる */
|
|
53
|
+
Passive: string
|
|
54
|
+
/** 使役形 - 書かせる */
|
|
55
|
+
Causative: string
|
|
56
|
+
/** 書かせられる */
|
|
57
|
+
CausativePassive: string
|
|
58
|
+
/** 〜たら - 書いたら */
|
|
59
|
+
Conditional: string
|
|
60
|
+
/** 〜ば - 書けば */
|
|
61
|
+
Provisional: string
|
|
62
|
+
/** 書いている */
|
|
63
|
+
Progressive: string
|
|
64
|
+
/** 書いています */
|
|
65
|
+
ProgressivePolite: string
|
|
66
|
+
/** 書いていた */
|
|
67
|
+
PastProgressive: string
|
|
68
|
+
/** 書きたい */
|
|
69
|
+
Desire: string
|
|
70
|
+
/** 〜たり - 書いたり */
|
|
71
|
+
Representative: string
|
|
72
|
+
/** 書くだろう */
|
|
73
|
+
Presumptive: string
|
|
74
|
+
/** 書きながら */
|
|
75
|
+
Continuative: string
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** every form of an い-adjective */
|
|
79
|
+
export interface IAdjectiveConjugation {
|
|
80
|
+
/** 高い */
|
|
81
|
+
Infinitive: string
|
|
82
|
+
PresentTense: string
|
|
83
|
+
/** 高くない */
|
|
84
|
+
Negative: string
|
|
85
|
+
/** 高かった */
|
|
86
|
+
PastTense: string
|
|
87
|
+
/** 高くなかった */
|
|
88
|
+
PastNegative: string
|
|
89
|
+
/** 高くて */
|
|
90
|
+
Gerund: string
|
|
91
|
+
/** 高く */
|
|
92
|
+
Adverb: string
|
|
93
|
+
/** 高ければ */
|
|
94
|
+
Provisional: string
|
|
95
|
+
/** 高かろう */
|
|
96
|
+
Presumptive: string
|
|
97
|
+
/** 高いです */
|
|
98
|
+
Polite: string
|
|
99
|
+
/** 高かったです */
|
|
100
|
+
PolitePast: string
|
|
101
|
+
/** 高くないです */
|
|
102
|
+
PoliteNegative: string
|
|
103
|
+
/** 高すぎる */
|
|
104
|
+
Superlative: string
|
|
105
|
+
/** 高そう */
|
|
106
|
+
Impression: string
|
|
107
|
+
/** 高さ */
|
|
108
|
+
Nominal: string
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** every form of a な-adjective. it inflects with the copula */
|
|
112
|
+
export interface NaAdjectiveConjugation {
|
|
113
|
+
/** 静か */
|
|
114
|
+
Infinitive: string
|
|
115
|
+
/** 静かな */
|
|
116
|
+
Adnominal: string
|
|
117
|
+
/** 静かだ */
|
|
118
|
+
PresentTense: string
|
|
119
|
+
/** 静かじゃない */
|
|
120
|
+
Negative: string
|
|
121
|
+
/** 静かだった */
|
|
122
|
+
PastTense: string
|
|
123
|
+
/** 静かじゃなかった */
|
|
124
|
+
PastNegative: string
|
|
125
|
+
/** 静かで */
|
|
126
|
+
Gerund: string
|
|
127
|
+
/** 静かに */
|
|
128
|
+
Adverb: string
|
|
129
|
+
/** 静かです */
|
|
130
|
+
Polite: string
|
|
131
|
+
/** 静かでした */
|
|
132
|
+
PolitePast: string
|
|
133
|
+
/** 静かじゃありません */
|
|
134
|
+
PoliteNegative: string
|
|
135
|
+
/** 静かなら */
|
|
136
|
+
Provisional: string
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** the result of walking a conjugated verb back to its dictionary-form */
|
|
140
|
+
export interface Deconjugation {
|
|
141
|
+
/** the dictionary-form - 書きました → 書く */
|
|
142
|
+
root: string
|
|
143
|
+
/** what the ending told us - ['Verb', 'PastTense', 'Polite'] */
|
|
144
|
+
tags: string[]
|
|
145
|
+
/** every dictionary-form the ending could have come from */
|
|
146
|
+
candidates: string[]
|
|
147
|
+
/** true when no candidate could be confirmed, and `root` is a guess */
|
|
148
|
+
guess?: boolean
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** what `.numbers().parse()` reports about a number */
|
|
152
|
+
export interface NumberParse {
|
|
153
|
+
/** the value, or null if it couldn't be read */
|
|
154
|
+
num: number | null
|
|
155
|
+
/** written in kanji (二十三) rather than digits */
|
|
156
|
+
kanji: boolean
|
|
157
|
+
/** written in full-width digits (23) */
|
|
158
|
+
wide: boolean
|
|
159
|
+
}
|
package/types/misc.d.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// shared types.
|
|
2
|
+
// compromise ships its own copies of these, but its `./one` subpath has no
|
|
3
|
+
// `types` condition in its exports map, so they can't be imported from here.
|
|
4
|
+
// they're restated rather than re-exported - keep them in sync with
|
|
5
|
+
// compromise/types/misc.ts when bumping the dependency.
|
|
6
|
+
|
|
7
|
+
export type Document = Term[][]
|
|
8
|
+
|
|
9
|
+
export type Pointer = [n?: number, start?: number, end?: number, startId?: string, endId?: string]
|
|
10
|
+
|
|
11
|
+
export type outMethods = 'text' | 'normal' | 'offset' | 'terms' | 'topk' | 'json' | 'tags' | 'array' | 'debug'
|
|
12
|
+
|
|
13
|
+
export type Groups = object
|
|
14
|
+
|
|
15
|
+
export interface Term {
|
|
16
|
+
text: string
|
|
17
|
+
pre: string
|
|
18
|
+
post: string
|
|
19
|
+
normal: string
|
|
20
|
+
tags?: Set<string>
|
|
21
|
+
index?: [n?: number, start?: number]
|
|
22
|
+
id?: string
|
|
23
|
+
chunk?: string
|
|
24
|
+
dirty?: boolean
|
|
25
|
+
/** the dictionary-form, after `.compute('root')` - 食べました → 食べる */
|
|
26
|
+
root?: string
|
|
27
|
+
/** latin-alphabet spelling, after `.compute('romanji')` */
|
|
28
|
+
romanji?: string
|
|
29
|
+
/** kana spelling of the word's kanji, after `.compute('readings')` */
|
|
30
|
+
reading?: string
|
|
31
|
+
/** the parsed value of a numeral - 「二十三」 gives 23 */
|
|
32
|
+
number?: number
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** options for `.json()` */
|
|
36
|
+
export interface JsonProps {
|
|
37
|
+
text?: boolean
|
|
38
|
+
normal?: boolean
|
|
39
|
+
reduced?: boolean
|
|
40
|
+
trim?: boolean
|
|
41
|
+
offset?: boolean
|
|
42
|
+
count?: boolean
|
|
43
|
+
unique?: boolean
|
|
44
|
+
index?: boolean
|
|
45
|
+
terms?: {
|
|
46
|
+
text?: boolean
|
|
47
|
+
normal?: boolean
|
|
48
|
+
clean?: boolean
|
|
49
|
+
implicit?: boolean
|
|
50
|
+
tags?: boolean
|
|
51
|
+
whitespace?: boolean
|
|
52
|
+
id?: boolean
|
|
53
|
+
offset?: boolean
|
|
54
|
+
bestTag?: boolean
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** a key-value object of words and their tags */
|
|
59
|
+
export interface Lexicon {
|
|
60
|
+
[key: string]: string
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface Plugin {
|
|
64
|
+
methods?: object
|
|
65
|
+
model?: object
|
|
66
|
+
compute?: object
|
|
67
|
+
hooks?: string[]
|
|
68
|
+
tags?: object
|
|
69
|
+
words?: object
|
|
70
|
+
lib?: () => object
|
|
71
|
+
api?: (fn: (view: any) => {}) => void
|
|
72
|
+
mutate?: (fn: (world: object) => {}) => void
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface matchOptions {
|
|
76
|
+
fuzzy?: number
|
|
77
|
+
caseSensitive?: boolean
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface Match {
|
|
81
|
+
match: string
|
|
82
|
+
tag?: string | string[]
|
|
83
|
+
unTag?: string | string[]
|
|
84
|
+
group?: string | number
|
|
85
|
+
reason?: string
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface Net {
|
|
89
|
+
hooks: object
|
|
90
|
+
always?: any
|
|
91
|
+
isNet: boolean
|
|
92
|
+
}
|