User:Bohye Woo/nltk-Terms of Service: Difference between revisions
No edit summary |
No edit summary |
||
Line 2: | Line 2: | ||
===1. To create a virtual environment==== | ===1. To create a virtual environment==== | ||
cd to the place you want to make it and... | cd to the place you want to make it and... | ||
<source lang=" | <source lang="python"> | ||
python3 -m venv venv | python3 -m venv venv | ||
</source> | </source> | ||
Line 8: | Line 8: | ||
===2. To activate a virtual environment=== | ===2. To activate a virtual environment=== | ||
cd to the folder where "venv" is and... | cd to the folder where "venv" is and... | ||
<source lang=" | <source lang="python"> | ||
source venb/bin/activate | source venb/bin/activate | ||
</source> | |||
===NLTK=== | |||
Tokenize | |||
<source lang="python"> | |||
>>> import nltk | |||
>>> text = "If you choose to login to the Services via a third-party platform or social media network, you will need to use your credentials." | |||
>>> token = nltk.word_tokenize(text) | |||
>>> token | |||
['If', 'you', 'choose', 'to', 'login', 'to', 'the', 'Services', 'via', 'a', 'third-party', 'platform', 'or', 'social', 'media', 'network', ',', 'you', 'will', 'need', 'to', 'use', 'your', 'credentials', '.'] | |||
</source> | |||
sort | |||
<source lang="python"> | |||
>>> token.sort() | |||
>>> token | |||
[',', '.', 'If', 'Services', 'a', 'choose', 'credentials', 'login', 'media', 'need', 'network', 'or', 'platform', 'social', 'the', 'third-party', 'to', 'to', 'to', 'use', 'via', 'will', 'you', 'you', 'your'] | |||
</source> | |||
collections | |||
<source lang="python"> | |||
>>> import collections | |||
>>> collections.Counter(token) | |||
Counter({'to': 3, 'you': 2, ',': 1, '.': 1, 'If': 1, 'Services': 1, 'a': 1, 'choose': 1, 'credentials': 1, 'login': 1, 'media': 1, 'need': 1, 'network': 1, 'or': 1, 'platform': 1, 'social': 1, 'the': 1, 'third-party': 1, 'use': 1, 'via': 1, 'will': 1, 'your': 1}) | |||
</source> | </source> |
Revision as of 15:25, 23 March 2020
Virtual Environment
1. To create a virtual environment=
cd to the place you want to make it and...
python3 -m venv venv
2. To activate a virtual environment
cd to the folder where "venv" is and...
source venb/bin/activate
NLTK
Tokenize
>>> import nltk
>>> text = "If you choose to login to the Services via a third-party platform or social media network, you will need to use your credentials."
>>> token = nltk.word_tokenize(text)
>>> token
['If', 'you', 'choose', 'to', 'login', 'to', 'the', 'Services', 'via', 'a', 'third-party', 'platform', 'or', 'social', 'media', 'network', ',', 'you', 'will', 'need', 'to', 'use', 'your', 'credentials', '.']
sort
>>> token.sort()
>>> token
[',', '.', 'If', 'Services', 'a', 'choose', 'credentials', 'login', 'media', 'need', 'network', 'or', 'platform', 'social', 'the', 'third-party', 'to', 'to', 'to', 'use', 'via', 'will', 'you', 'you', 'your']
collections
>>> import collections
>>> collections.Counter(token)
Counter({'to': 3, 'you': 2, ',': 1, '.': 1, 'If': 1, 'Services': 1, 'a': 1, 'choose': 1, 'credentials': 1, 'login': 1, 'media': 1, 'need': 1, 'network': 1, 'or': 1, 'platform': 1, 'social': 1, 'the': 1, 'third-party': 1, 'use': 1, 'via': 1, 'will': 1, 'your': 1})