-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathTokenization.py
More file actions
33 lines (23 loc) · 792 Bytes
/
Copy pathTokenization.py
File metadata and controls
33 lines (23 loc) · 792 Bytes
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
# -*- coding: utf-8 -*-
"""
Created on Mon Jan 11 00:40:11 2021
@author: User
"""
import nltk
from nltk.tokenize import word_tokenize
quote = "Big dreams have small beginnings"
quote_tokens = word_tokenize(quote)
print(quote_tokens)
print(len(quote_tokens))
from nltk.util import bigrams, trigrams, ngrams
string = "Sit alone, you will find all your answers."
tokens = word_tokenize(string)
string_bigrams = list(nltk.bigrams(tokens))
print("******************Bigrams******************")
print(string_bigrams)
string_trigrams = list(nltk.trigrams(tokens))
print("******************Trigrams******************")
print(string_trigrams)
string_ngrams = list(nltk.ngrams(tokens, 5))
print("******************Ngrams******************")
print(string_ngrams)