-
Notifications
You must be signed in to change notification settings - Fork 20
/
partOfSpeech.ts
216 lines (197 loc) · 8.4 KB
/
partOfSpeech.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
import { hasProp } from './util';
const clauses = {
'n..': 'noun',
'n.': 'noun',
n: 'noun',
'adj.': 'adjective',
'a. .': 'adjective',
'a.': 'adjective',
a: 'adjective',
'p. a.': 'participial adjective',
'p.a.': 'participial adjective',
'pr. a.': 'proper adjective', // ? not listed in abbrevn.lst
'v.': 'verb',
'v. i.': 'intransitive verb',
'v. t.': 'transitive verb',
'imp.': 'imperfect',
'imp. sing.': 'singular imperfect',
'imp. pl.': 'plural imperfect',
'p. p.': 'past participle',
'past part.': 'past participle',
'p. p': 'past participle',
'imp. p. p.': 'imperfect & past participle', // ? or is it 'imperfect past participle' - not listed in abbrevn.lst
'present participle': 'present participle',
'p. pr.': 'present participle',
'p. pr': 'present participle',
'p, pr': 'present participle',
'p pr.': 'present participle',
'adv.': 'adverb',
adv: 'adverb',
'ads.': 'adverb', // ? not listed in abbrevn.lst
'superl.': 'superlative',
superl: 'superlative',
'comp.': 'comparative', // ? abbrevn.lst says it’s 'compound' but that doesn't always make sense
compar: 'comparative',
'compar.': 'comparative',
'prep.': 'preposition',
'interj.': 'interjection',
'pron.': 'pronoun', // can also be pronounciation/pronounced
'pron. pl.': 'plural pronoun',
'conj.': 'conjunction',
'third pers. sing. pres.': 'third-person singular present',
'3d. pers. sing. pres.': 'third-person singular present',
'3d pers. sing. pres.': 'third-person singular present',
'3d sing. pres.': 'third-person singular present',
'3d pers. sing. pr.': 'third-person singular present',
'3d sing. pr.': 'third-person singular present',
'3d pers. sing. present': 'third-person singular present',
'3d pers. pres.': 'third-person present',
'3d pers. sing.': 'third-person singular',
'imperative sing.': 'imperative singular',
'2d pers. sing. imp.': 'second-person singular imperfect',
'2d pers. sing. pres.': 'second-person singular present',
'infinitive.': 'infinitive',
'inf.': 'infinitive',
'pref.': 'prefix',
'prefix.': 'prefix',
'suff.': 'suffix',
'suffix.': 'suffix',
'possess.': 'possessive', // ? not listed in abbrevn.lst
'poss.': 'possessive', // ? not listed in abbrevn.lst
'obj.': 'objective', // ? not listed in abbrevn.lst
'object.': 'objective', // ? not listed in abbrevn.lst
'dat.': 'dative',
'pret.': 'preterit',
'v. inf': 'infinitive verb',
'v. inf.': 'infinitive verb',
'v. impers.': 'impersonal verb', // ? not listed in abbrevn.lst
'v. impersonal': 'impersonal verb', // ? not listed in abbrevn.lst
'a. superl.': 'superlative adjective',
'prep. phr.': 'preposition phrase',
'indic. present': 'plural indicative present',
'pl. indic. pr.': 'plural indicative present',
participle: 'participle',
auxiliary: 'auxiliary verb',
'auxiliary.': 'auxiliary verb',
'part. adj': 'participal adjective', // ? not listed in abbrevn.lst but lsted under 'p. a.'
'part. adj.': 'participal adjective',
'masc. a.': 'masculine adjective',
'fem. a.': 'feminine adjective',
'a. m.': 'masculine adjective',
'a. f.': 'feminine adjective',
'strong imp.': 'strong imperfect',
'nom.': 'nominative',
'pl. nom.': 'plural nominative',
'n.pl.': 'plural noun',
'peop. n.': 'peop. noun', // ? not listed in abbrevn.lst
'p. pr. vb. n.': 'present participle verbal noun',
'pres. sing.': 'present-tense singular',
'indef. pron.': 'indefinite pronoun',
'possessive pron.': 'possessive pronoun',
'pr. n. pl.': 'plural proper noun', // ? not listed in abbrevn.lst
'pl. pres.': 'plural present', // ? not listed in abbrevn.lst
'a. pron.': 'adjective pronoun',
'2d person': 'second-person',
'a. compar.': 'comparative adjective',
'n.sing.': 'singular noun',
'plural pres.': 'plural present',
'sing. pres.': 'singular present',
'poss. pron.': 'possessive pronoun',
'contrac.': 'contraction',
'pers. pron.': 'personal pronoun', // ? 'pers.' Is listed as 'person'
'sing. pres. ind.': 'singular present-tense indicative',
'pres. subj.': 'present subjunctive',
'pres.': 'present', // ? not listed in abbrevn.lst
'v. imperative.': 'imperative verb',
'2d pers. pl.': 'second-person plural',
'2d pers. sing.': 'second-person singular',
'2d per. sing.': 'second-person singular',
'sing. nom.': 'singular nominative',
'abl.': 'ablative',
'subj. 3d pers. sing.': 'subjunctive third-person singular',
'archaic imp.': '(archaic) imperfect',
'syntactically sing.': 'syntactically singular',
'definite article.': 'definite article',
'def. art.': 'definite article',
'imperative.': 'imperative',
'interrog. adv.': 'interrogative adverb',
'rare vb. n.': '(rarely) verbal noun',
'archaic p. p.': '(archaic) past participle'
};
const nouns = {
vb: 'verbal',
'vb.': 'verbal',
'vb/': 'verbal', // ?
'vvb.': 'verbal', // ?
'pr.': 'proper',
'fem.': 'feminine',
'f.': 'feminine',
'masc.': 'masculine',
'm.': 'masculine',
'sing.': 'singular',
'pl.': 'plural',
pl: 'plural'
};
const whole = {
'n. & v. t. & i.': 'noun, transitive verb, or intransitive verb',
'v. i. & i.': 'transitive or intransitive verb', // ?
'v. t. & i.': 'transitive or intransitive verb',
'v. i. & t.': 'intransitive or transitive verb',
'p. p. & a.': 'past participle or predicative adjective',
'p. & a.': '????',
'p. p. or a.': 'past participle or predicative adjective',
'pres. indic. sing., 1st & 3d pers.': 'present indicative singular; first or third person',
'pres. indic., 1st & 3d pers. sing.':
'present indicative; first or third person singular',
'pres. indic. 1st & 3d pers. sing.':
'present indicative; first or third person singular',
'n. collect & pl.': 'collective or plural noun',
'n. collect. & pl.': 'collective or plural noun',
'n. sing. & pl.': 'singular or plural noun',
'pres. & imp. sing. & pl.': 'present, imperative singular or plural',
'imp. (and rare p. p.)': `${clauses['imp.']} (and rarely ${clauses['p. p.']})`,
'a.; also adv.': `${clauses.a}; also ${clauses.adv}`,
'1st & 3d pers. sing. pres.': 'first- or third-person singular present',
'p, pr. & vb. n.': 'present participle or verbal noun' // ?
};
const set = new Set();
const extras = { set };
export default Object.assign((pos: string) => {
function parse (pos: string): string {
if (hasProp(whole, pos)) return whole[pos];
if (hasProp(clauses, pos)) return clauses[pos];
if (hasProp(nouns, pos)) return nouns[pos];
const segments = pos.split(/\s*(?:&|or|,(?:\s*(?:&|or))?)[.\s]*/);
if (segments.length === 1) {
if (pos.startsWith('prop. ')) {
return `proper ${parse(pos.slice(6))}`;
}
if (pos.startsWith('n. ')) {
return `${parse(pos.slice(3))} noun`;
}
if (pos.endsWith(' n.')) {
return `${parse(pos.slice(0, -3))} noun`;
}
if (pos.endsWith(' n')) {
return `${parse(pos.slice(0, -2))} noun`;
}
if (pos.startsWith('obs. ')) {
return `obsolete ${parse(pos.slice(5))}`;
}
return 'xxxx';
}
return segments.map(parse).join(' or ');
}
const prefix = pos.match(/^\s*/)![0]; // eslint-disable-line
const suffix = pos.match(/[,\s]*$/)![0]; // eslint-disable-line
pos = pos
.slice(prefix.length, suffix ? -suffix.length : undefined)
.toLowerCase();
const result = parse(pos);
if (result.includes('xxxx')) {
// console.log(pos)
set.add(pos);
return null;
}
return prefix + result + suffix;
}, extras);