summaryrefslogtreecommitdiff
path: root/python-lemminflect.spec
blob: 476520507319ef41b7ff964aaa21f09c0aff1f8d (plain)
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
%global _empty_manifest_terminate_build 0
Name:		python-lemminflect
Version:	0.2.3
Release:	1
Summary:	A python module for English lemmatization and inflection.
License:	MIT License
URL:		https://github.com/bjascob/LemmInflect
Source0:	https://mirrors.nju.edu.cn/pypi/web/packages/2d/41/662a99c976acb78907e6423cb666f0001450c35f74362b402716378f45b1/lemminflect-0.2.3.tar.gz
BuildArch:	noarch

Requires:	python3-numpy

%description
#    LemmInflect

**A python module for English lemmatization and inflection.**


## About
LemmInflect uses a dictionary approach to lemmatize English words and inflect them into forms specified by a user supplied [Universal Dependencies](https://universaldependencies.org/u/pos/) or [Penn Treebank](https://www.ling.upenn.edu/courses/Fall_2003/ling001/penn_treebank_pos.html) tag.  The library works with out-of-vocabulary (OOV) words by applying neural network techniques to classify word forms and choose the appropriate morphing rules.

The system acts as a standalone module or as an extension to the [spaCy](https://spacy.io/) NLP system.

The dictionary and morphology rules are derived from the [NIH's SPECIALIST Lexicon](https://lsg3.nlm.nih.gov/LexSysGroup/Projects/lexicon/current/web/index.html) which contains an extensive set information on English word forms.

A more simplistic inflection only system is available as [pyInflect](https://github.com/bjascob/pyInflect).  LemmInflect was created to address some of the shortcoming of that project and add features, such as...

* Independence from the spaCy lemmatizer
* Neural nets to disambiguate out of vocab morphology
* Unigrams to dismabiguate spellings and multiple word forms


## Documentation
For the latest documentation, see **[ReadTheDocs](https://lemminflect.readthedocs.io/en/latest/)**.


## Accuracy of the Lemmatizer
The accuracy of LemmInflect and several other popular NLP utilities was tested using the [Automatically Generated Inflection Database (AGID)](http://wordlist.aspell.net/other) as a baseline.  The AGID has an extensive list of lemmas and their corresponding inflections.  Each inflection was lemmatized by the test software and then compared to the original value in the corpus. The test included 119,194 different inflected words.

```
| Package          | Verb  |  Noun | ADJ/ADV | Overall |  Speed  |
|----------------------------------------------------------------|
| LemmInflect      | 96.1% | 95.4% |  93.9%  |  95.6%  | 42.0 uS |
| CLiPS/pattern.en | 93.6% | 91.1% |   0.0%  |  n/a    |  3.0 uS |
| Stanford CoreNLP | 87.6% | 93.1% |   0.0%  |  n/a    |  n/a    |
| spaCy            | 79.4% | 88.9% |  60.5%  |  84.7%  |  5.0 uS |
| NLTK             | 53.3% | 52.2% |  53.3%  |  52.6%  | 13.0 uS |
|----------------------------------------------------------------|
```
* Speed is in micro-seconds per lemma and was conducted on a i9-7940x CPU.
* The Stanford and CLiPS lemmatizers don't accept part-of-speech information and in the case of the pattern.en, the methods was setup specifically for verbs, not as a lemmatizer for all word types.
* The Stanford CoreNLP lemmatizer is a Java package and testing was done via the built-in HTML server, thus the speed measurement is invalid.


## Requirements and Installation
The only external requirement to run LemmInflect is `numpy` which is used for the matrix math that drives the neural nets.  These nets are relatively small and don't require significant CPU power to run.

To install do..

`pip3 install lemminflect`

The project was built and tested under Python 3 and Ubuntu but should run on any Linux, Windows, Mac, etc.. system.  It is untested under Python 2 but may function in that environment with minimal or no changes.

The code base also includes library functions and scripts to create the various data files and neural nets.  This includes such things as...
* Unigram Extraction from the Gutenberg and Billion Word Corpra
* Python scripts for loading and parsing the SPECIALIST Lexicon
* Nerual network training based on Keras and Tensorflow

None of these are required for run-time operation.  However, if you want of modify the system, see the [documentation](https://lemminflect.readthedocs.io/en/latest/test_dev/) for more info.


## Library Usage
To lemmatize a word use the method `getLemma()`.  This takes a word and a Universal Dependencies tag and returns the lemmas as a list of possible spellings.  The dictionary system is used first, and if no lemma is found, the rules system is employed.
```
> from lemminflect import getLemma
getLemma('watches', upos='VERB')
('watch',)
```
To inflect words, use the method `getInflection`.   This takes a lemma and a Penn Treebank tag and returns a tuple of the specific inflection(s) associated with that tag.  Similary to above, the dictionary is used first and then inflection rules are applied if needed..
```
> from lemminflect import getInflection
> getInflection('watch', tag='VBD')
('watched',)

> getInflection('xxwatch', tag='VBD')
('xxwatched',)
```
The library provides lower-level functions to access the dictionary and the OOV rules directly.  For a detailed description see [Lemmatizer](https://lemminflect.readthedocs.io/en/latest/lemmatizer/) or [Inflections](https://lemminflect.readthedocs.io/en/latest/inflections/).


## Usage as a Spacy Extension
To use as an extension, you need spaCy version 2.0 or later.  Versions 1.9 and earlier do not support the extension methods used here.

To setup the extension, first import `lemminflect`.  This will create new `lemma` and `inflect` methods for each spaCy `Token`. The methods operate similarly to the methods described above, with the exception that a string is returned, containing the most common spelling, rather than a tuple.
```
> import spacy
> import lemminflect
> nlp = spacy.load('en_core_web_sm')
> doc = nlp('I am testing this example.')
> doc[2]._.lemma()
test

> doc[4]._.inflect('NNS')
examples
```

## Issues
If you find a bug, please report it on the [GitHub issues list](https://github.com/bjascob/LemmInflect/issues).  However be aware that when in comes to returning the correct inflection there are a number of different types of issues that can arise.  Some of these are not  readily fixable.  Issues with inflected forms include...
* Multiple spellings for an inflection (ie.. arthroplasties, arthroplastyes or arthroplastys)
* Mass form and plural types (ie.. people vs peoples)
* Forms that depend on context (ie.. further vs farther)
* Infections that are not fully specified by the tag (ie.. be/VBD can be "was" or "were")

One common issue is that some forms of the verb "be" are not completely specified by the treekbank tag.  For instance be/VBD inflects to either "was" or "were" and be/VBP inflects to either "am", or "are".  In order to disambiguate these forms, other words in the sentence need to be inspected.  At this time, LemmInflect doesn't include this functionality.




%package -n python3-lemminflect
Summary:	A python module for English lemmatization and inflection.
Provides:	python-lemminflect
BuildRequires:	python3-devel
BuildRequires:	python3-setuptools
BuildRequires:	python3-pip
%description -n python3-lemminflect
#    LemmInflect

**A python module for English lemmatization and inflection.**


## About
LemmInflect uses a dictionary approach to lemmatize English words and inflect them into forms specified by a user supplied [Universal Dependencies](https://universaldependencies.org/u/pos/) or [Penn Treebank](https://www.ling.upenn.edu/courses/Fall_2003/ling001/penn_treebank_pos.html) tag.  The library works with out-of-vocabulary (OOV) words by applying neural network techniques to classify word forms and choose the appropriate morphing rules.

The system acts as a standalone module or as an extension to the [spaCy](https://spacy.io/) NLP system.

The dictionary and morphology rules are derived from the [NIH's SPECIALIST Lexicon](https://lsg3.nlm.nih.gov/LexSysGroup/Projects/lexicon/current/web/index.html) which contains an extensive set information on English word forms.

A more simplistic inflection only system is available as [pyInflect](https://github.com/bjascob/pyInflect).  LemmInflect was created to address some of the shortcoming of that project and add features, such as...

* Independence from the spaCy lemmatizer
* Neural nets to disambiguate out of vocab morphology
* Unigrams to dismabiguate spellings and multiple word forms


## Documentation
For the latest documentation, see **[ReadTheDocs](https://lemminflect.readthedocs.io/en/latest/)**.


## Accuracy of the Lemmatizer
The accuracy of LemmInflect and several other popular NLP utilities was tested using the [Automatically Generated Inflection Database (AGID)](http://wordlist.aspell.net/other) as a baseline.  The AGID has an extensive list of lemmas and their corresponding inflections.  Each inflection was lemmatized by the test software and then compared to the original value in the corpus. The test included 119,194 different inflected words.

```
| Package          | Verb  |  Noun | ADJ/ADV | Overall |  Speed  |
|----------------------------------------------------------------|
| LemmInflect      | 96.1% | 95.4% |  93.9%  |  95.6%  | 42.0 uS |
| CLiPS/pattern.en | 93.6% | 91.1% |   0.0%  |  n/a    |  3.0 uS |
| Stanford CoreNLP | 87.6% | 93.1% |   0.0%  |  n/a    |  n/a    |
| spaCy            | 79.4% | 88.9% |  60.5%  |  84.7%  |  5.0 uS |
| NLTK             | 53.3% | 52.2% |  53.3%  |  52.6%  | 13.0 uS |
|----------------------------------------------------------------|
```
* Speed is in micro-seconds per lemma and was conducted on a i9-7940x CPU.
* The Stanford and CLiPS lemmatizers don't accept part-of-speech information and in the case of the pattern.en, the methods was setup specifically for verbs, not as a lemmatizer for all word types.
* The Stanford CoreNLP lemmatizer is a Java package and testing was done via the built-in HTML server, thus the speed measurement is invalid.


## Requirements and Installation
The only external requirement to run LemmInflect is `numpy` which is used for the matrix math that drives the neural nets.  These nets are relatively small and don't require significant CPU power to run.

To install do..

`pip3 install lemminflect`

The project was built and tested under Python 3 and Ubuntu but should run on any Linux, Windows, Mac, etc.. system.  It is untested under Python 2 but may function in that environment with minimal or no changes.

The code base also includes library functions and scripts to create the various data files and neural nets.  This includes such things as...
* Unigram Extraction from the Gutenberg and Billion Word Corpra
* Python scripts for loading and parsing the SPECIALIST Lexicon
* Nerual network training based on Keras and Tensorflow

None of these are required for run-time operation.  However, if you want of modify the system, see the [documentation](https://lemminflect.readthedocs.io/en/latest/test_dev/) for more info.


## Library Usage
To lemmatize a word use the method `getLemma()`.  This takes a word and a Universal Dependencies tag and returns the lemmas as a list of possible spellings.  The dictionary system is used first, and if no lemma is found, the rules system is employed.
```
> from lemminflect import getLemma
getLemma('watches', upos='VERB')
('watch',)
```
To inflect words, use the method `getInflection`.   This takes a lemma and a Penn Treebank tag and returns a tuple of the specific inflection(s) associated with that tag.  Similary to above, the dictionary is used first and then inflection rules are applied if needed..
```
> from lemminflect import getInflection
> getInflection('watch', tag='VBD')
('watched',)

> getInflection('xxwatch', tag='VBD')
('xxwatched',)
```
The library provides lower-level functions to access the dictionary and the OOV rules directly.  For a detailed description see [Lemmatizer](https://lemminflect.readthedocs.io/en/latest/lemmatizer/) or [Inflections](https://lemminflect.readthedocs.io/en/latest/inflections/).


## Usage as a Spacy Extension
To use as an extension, you need spaCy version 2.0 or later.  Versions 1.9 and earlier do not support the extension methods used here.

To setup the extension, first import `lemminflect`.  This will create new `lemma` and `inflect` methods for each spaCy `Token`. The methods operate similarly to the methods described above, with the exception that a string is returned, containing the most common spelling, rather than a tuple.
```
> import spacy
> import lemminflect
> nlp = spacy.load('en_core_web_sm')
> doc = nlp('I am testing this example.')
> doc[2]._.lemma()
test

> doc[4]._.inflect('NNS')
examples
```

## Issues
If you find a bug, please report it on the [GitHub issues list](https://github.com/bjascob/LemmInflect/issues).  However be aware that when in comes to returning the correct inflection there are a number of different types of issues that can arise.  Some of these are not  readily fixable.  Issues with inflected forms include...
* Multiple spellings for an inflection (ie.. arthroplasties, arthroplastyes or arthroplastys)
* Mass form and plural types (ie.. people vs peoples)
* Forms that depend on context (ie.. further vs farther)
* Infections that are not fully specified by the tag (ie.. be/VBD can be "was" or "were")

One common issue is that some forms of the verb "be" are not completely specified by the treekbank tag.  For instance be/VBD inflects to either "was" or "were" and be/VBP inflects to either "am", or "are".  In order to disambiguate these forms, other words in the sentence need to be inspected.  At this time, LemmInflect doesn't include this functionality.




%package help
Summary:	Development documents and examples for lemminflect
Provides:	python3-lemminflect-doc
%description help
#    LemmInflect

**A python module for English lemmatization and inflection.**


## About
LemmInflect uses a dictionary approach to lemmatize English words and inflect them into forms specified by a user supplied [Universal Dependencies](https://universaldependencies.org/u/pos/) or [Penn Treebank](https://www.ling.upenn.edu/courses/Fall_2003/ling001/penn_treebank_pos.html) tag.  The library works with out-of-vocabulary (OOV) words by applying neural network techniques to classify word forms and choose the appropriate morphing rules.

The system acts as a standalone module or as an extension to the [spaCy](https://spacy.io/) NLP system.

The dictionary and morphology rules are derived from the [NIH's SPECIALIST Lexicon](https://lsg3.nlm.nih.gov/LexSysGroup/Projects/lexicon/current/web/index.html) which contains an extensive set information on English word forms.

A more simplistic inflection only system is available as [pyInflect](https://github.com/bjascob/pyInflect).  LemmInflect was created to address some of the shortcoming of that project and add features, such as...

* Independence from the spaCy lemmatizer
* Neural nets to disambiguate out of vocab morphology
* Unigrams to dismabiguate spellings and multiple word forms


## Documentation
For the latest documentation, see **[ReadTheDocs](https://lemminflect.readthedocs.io/en/latest/)**.


## Accuracy of the Lemmatizer
The accuracy of LemmInflect and several other popular NLP utilities was tested using the [Automatically Generated Inflection Database (AGID)](http://wordlist.aspell.net/other) as a baseline.  The AGID has an extensive list of lemmas and their corresponding inflections.  Each inflection was lemmatized by the test software and then compared to the original value in the corpus. The test included 119,194 different inflected words.

```
| Package          | Verb  |  Noun | ADJ/ADV | Overall |  Speed  |
|----------------------------------------------------------------|
| LemmInflect      | 96.1% | 95.4% |  93.9%  |  95.6%  | 42.0 uS |
| CLiPS/pattern.en | 93.6% | 91.1% |   0.0%  |  n/a    |  3.0 uS |
| Stanford CoreNLP | 87.6% | 93.1% |   0.0%  |  n/a    |  n/a    |
| spaCy            | 79.4% | 88.9% |  60.5%  |  84.7%  |  5.0 uS |
| NLTK             | 53.3% | 52.2% |  53.3%  |  52.6%  | 13.0 uS |
|----------------------------------------------------------------|
```
* Speed is in micro-seconds per lemma and was conducted on a i9-7940x CPU.
* The Stanford and CLiPS lemmatizers don't accept part-of-speech information and in the case of the pattern.en, the methods was setup specifically for verbs, not as a lemmatizer for all word types.
* The Stanford CoreNLP lemmatizer is a Java package and testing was done via the built-in HTML server, thus the speed measurement is invalid.


## Requirements and Installation
The only external requirement to run LemmInflect is `numpy` which is used for the matrix math that drives the neural nets.  These nets are relatively small and don't require significant CPU power to run.

To install do..

`pip3 install lemminflect`

The project was built and tested under Python 3 and Ubuntu but should run on any Linux, Windows, Mac, etc.. system.  It is untested under Python 2 but may function in that environment with minimal or no changes.

The code base also includes library functions and scripts to create the various data files and neural nets.  This includes such things as...
* Unigram Extraction from the Gutenberg and Billion Word Corpra
* Python scripts for loading and parsing the SPECIALIST Lexicon
* Nerual network training based on Keras and Tensorflow

None of these are required for run-time operation.  However, if you want of modify the system, see the [documentation](https://lemminflect.readthedocs.io/en/latest/test_dev/) for more info.


## Library Usage
To lemmatize a word use the method `getLemma()`.  This takes a word and a Universal Dependencies tag and returns the lemmas as a list of possible spellings.  The dictionary system is used first, and if no lemma is found, the rules system is employed.
```
> from lemminflect import getLemma
getLemma('watches', upos='VERB')
('watch',)
```
To inflect words, use the method `getInflection`.   This takes a lemma and a Penn Treebank tag and returns a tuple of the specific inflection(s) associated with that tag.  Similary to above, the dictionary is used first and then inflection rules are applied if needed..
```
> from lemminflect import getInflection
> getInflection('watch', tag='VBD')
('watched',)

> getInflection('xxwatch', tag='VBD')
('xxwatched',)
```
The library provides lower-level functions to access the dictionary and the OOV rules directly.  For a detailed description see [Lemmatizer](https://lemminflect.readthedocs.io/en/latest/lemmatizer/) or [Inflections](https://lemminflect.readthedocs.io/en/latest/inflections/).


## Usage as a Spacy Extension
To use as an extension, you need spaCy version 2.0 or later.  Versions 1.9 and earlier do not support the extension methods used here.

To setup the extension, first import `lemminflect`.  This will create new `lemma` and `inflect` methods for each spaCy `Token`. The methods operate similarly to the methods described above, with the exception that a string is returned, containing the most common spelling, rather than a tuple.
```
> import spacy
> import lemminflect
> nlp = spacy.load('en_core_web_sm')
> doc = nlp('I am testing this example.')
> doc[2]._.lemma()
test

> doc[4]._.inflect('NNS')
examples
```

## Issues
If you find a bug, please report it on the [GitHub issues list](https://github.com/bjascob/LemmInflect/issues).  However be aware that when in comes to returning the correct inflection there are a number of different types of issues that can arise.  Some of these are not  readily fixable.  Issues with inflected forms include...
* Multiple spellings for an inflection (ie.. arthroplasties, arthroplastyes or arthroplastys)
* Mass form and plural types (ie.. people vs peoples)
* Forms that depend on context (ie.. further vs farther)
* Infections that are not fully specified by the tag (ie.. be/VBD can be "was" or "were")

One common issue is that some forms of the verb "be" are not completely specified by the treekbank tag.  For instance be/VBD inflects to either "was" or "were" and be/VBP inflects to either "am", or "are".  In order to disambiguate these forms, other words in the sentence need to be inspected.  At this time, LemmInflect doesn't include this functionality.




%prep
%autosetup -n lemminflect-0.2.3

%build
%py3_build

%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
	find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
	find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
	find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
	find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
	find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .

%files -n python3-lemminflect -f filelist.lst
%dir %{python3_sitelib}/*

%files help -f doclist.lst
%{_docdir}/*

%changelog
* Sun Apr 23 2023 Python_Bot <Python_Bot@openeuler.org> - 0.2.3-1
- Package Spec generated