mirror of
https://github.com/gmihaila/ml_things.git
synced 2021-10-04 01:29:04 +03:00
Create README.md
This commit is contained in:
42
pos_tagging/README.md
Normal file
42
pos_tagging/README.md
Normal file
@@ -0,0 +1,42 @@
|
||||
# POS Tagging
|
||||
|
||||
## Python Code Snippet
|
||||
|
||||
### Imports:
|
||||
|
||||
```python
|
||||
from nltk.corpus import wordnet as wn
|
||||
|
||||
nltk.download('wordnet')
|
||||
``
|
||||
|
||||
### Function:
|
||||
|
||||
```python
|
||||
def word_pos(word):
|
||||
"""Convert word to POS TAG if exists in WordNet.
|
||||
Imports: 'from nltk.corpus import wordnet as wn'.
|
||||
Download WordNet: 'nltk.download('wordnet')'
|
||||
Pos Names: 'NOUN', 'VERB', 'ADJECTIVE', 'ADJECTIVE SATELITE', 'ADVERB'
|
||||
Pos Tags: 'n', 'v', 'a', 's', 'r'
|
||||
|
||||
Note:
|
||||
Regarding ADJECTIVE SATELITE:
|
||||
Certain adjectives bind minimal meaning. e.g. "dry", "good", &tc.
|
||||
Each of these is the center of an adjective synset in WN.
|
||||
Adjective satellites imposes additional commitments on top of the meaning
|
||||
of the central adjective, e.g. "arid" = "dry" + a particular context
|
||||
(i.e. climates).
|
||||
"""
|
||||
# from nltk.corpus import wordnet as wn
|
||||
# nltk.download('wordnet')
|
||||
# Certain adjectives bind minimal meaning. e.g. "dry", "good", &tc. Each of these is the center of an adjective synset in WN.
|
||||
tag = wn.synsets(word)
|
||||
if len(tag) > 0:
|
||||
tag = tag[0].pos()
|
||||
# https://wordnet.princeton.edu/documentation/wndb5wn
|
||||
pos_decode = {'n':'NOUN', 'v':'VERB', 'a':'ADJECTIVE', 's':'ADJECTIVE SATELITE', 'r':'ADVERB'}
|
||||
return pos_decode[tag]
|
||||
else:
|
||||
return None
|
||||
```
|
||||
Reference in New Issue
Block a user