awacke1 commited on
Commit
bcf5ff3
·
1 Parent(s): 45c58d0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -22
app.py CHANGED
@@ -1,51 +1,58 @@
1
- import streamlit as st
2
  import nltk
3
- from nltk.tokenize import word_tokenize, NLTKWordTokenizer, regexp_tokenize, TweetTokenizer
4
  from nltk.tokenize.treebank import TreebankWordDetokenizer
 
5
 
6
- # Regression Tests: NLTKWordTokenizer
7
-
8
- st.write('Regression Tests: NLTKWordTokenizer\nTokenizing some test strings.')
9
-
10
  s1 = "On a $50,000 mortgage of 30 years at 8 percent, the monthly payment would be $366.88."
11
- st.write(f"Tokenized: {word_tokenize(s1)}")
12
 
13
  s2 = "\"We beat some pretty good teams to get here,\" Slocum said."
14
- st.write(f"Tokenized: {word_tokenize(s2)}")
15
 
16
  s3 = "Well, we couldn't have this predictable, cliche-ridden, \"Touched by an Angel\" (a show creator John Masius worked on) wanna-be if she didn't."
17
- st.write(f"Tokenized: {word_tokenize(s3)}")
18
 
19
  s4 = "I cannot cannot work under these conditions!"
20
- st.write(f"Tokenized: {word_tokenize(s4)}")
21
 
22
  s5 = "The company spent $30,000,000 last year."
23
- st.write(f"Tokenized: {word_tokenize(s5)}")
24
 
25
  s6 = "The company spent 40.75% of its income last year."
26
- st.write(f"Tokenized: {word_tokenize(s6)}")
27
 
28
  s7 = "He arrived at 3:00 pm."
29
- st.write(f"Tokenized: {word_tokenize(s7)}")
30
 
31
  s8 = "I bought these items: books, pencils, and pens."
32
- st.write(f"Tokenized: {word_tokenize(s8)}")
33
 
34
  s9 = "Though there were 150, 100 of them were old."
35
- st.write(f"Tokenized: {word_tokenize(s9)}")
36
 
37
  s10 = "There were 300,000, but that wasn't enough."
38
- st.write(f"Tokenized: {word_tokenize(s10)}")
39
 
40
  s11 = "It's more'n enough."
41
- st.write(f"Tokenized: {word_tokenize(s11)}")
42
 
43
  s = '''Good muffins cost $3.88\nin New (York). Please (buy) me\ntwo of them.\n(Thanks).'''
44
- expected = [(0, 4), (5, 12), (13, 17), (18, 19), (19, 23), (24, 26), (27, 30), (31, 32), (32, 36), (36, 37), (37, 38), (40, 46), (47, 48), (48, 51), (51, 52), (53, 55), (56, 59), (60, 62), (63, 68), (69, 70), (70, 76), (76, 77), (77, 78)]
45
- st.write(f"Gathering the spans of the tokenized strings: {list(NLTKWordTokenizer().span_tokenize(s)) == expected}")
 
 
 
46
 
47
- expected = ['Good', 'muffins', 'cost', '$', '3.88', 'in', 'New', '(', 'York', ')', '.', 'Please', '(', 'buy', ')', 'me', 'two', 'of', 'them.', '(', 'Thanks', ')', '.']
48
- st.write(f"Gathering the spans of the tokenized strings: {[s[start:end] for start, end in NLTKWordTokenizer().span_tokenize(s)] == expected}")
 
 
49
 
50
  sx1 = '\xabNow that I can do.\xbb'
51
- expected = ['\xab', 'Now', 'that
 
 
 
 
 
1
+ # Import required libraries
2
  import nltk
3
+ from nltk.tokenize import word_tokenize, sent_tokenize, regexp_tokenize, TweetTokenizer
4
  from nltk.tokenize.treebank import TreebankWordDetokenizer
5
+ from nltk.tokenize import NLTKWordTokenizer
6
 
7
+ # Test cases for NLTKWordTokenizer
 
 
 
8
  s1 = "On a $50,000 mortgage of 30 years at 8 percent, the monthly payment would be $366.88."
9
+ print(word_tokenize(s1))
10
 
11
  s2 = "\"We beat some pretty good teams to get here,\" Slocum said."
12
+ print(word_tokenize(s2))
13
 
14
  s3 = "Well, we couldn't have this predictable, cliche-ridden, \"Touched by an Angel\" (a show creator John Masius worked on) wanna-be if she didn't."
15
+ print(word_tokenize(s3))
16
 
17
  s4 = "I cannot cannot work under these conditions!"
18
+ print(word_tokenize(s4))
19
 
20
  s5 = "The company spent $30,000,000 last year."
21
+ print(word_tokenize(s5))
22
 
23
  s6 = "The company spent 40.75% of its income last year."
24
+ print(word_tokenize(s6))
25
 
26
  s7 = "He arrived at 3:00 pm."
27
+ print(word_tokenize(s7))
28
 
29
  s8 = "I bought these items: books, pencils, and pens."
30
+ print(word_tokenize(s8))
31
 
32
  s9 = "Though there were 150, 100 of them were old."
33
+ print(word_tokenize(s9))
34
 
35
  s10 = "There were 300,000, but that wasn't enough."
36
+ print(word_tokenize(s10))
37
 
38
  s11 = "It's more'n enough."
39
+ print(word_tokenize(s11))
40
 
41
  s = '''Good muffins cost $3.88\nin New (York). Please (buy) me\ntwo of them.\n(Thanks).'''
42
+ expected = [(0, 4), (5, 12), (13, 17), (18, 19), (19, 23),
43
+ (24, 26), (27, 30), (31, 32), (32, 36), (36, 37), (37, 38),
44
+ (40, 46), (47, 48), (48, 51), (51, 52), (53, 55), (56, 59),
45
+ (60, 62), (63, 68), (69, 70), (70, 76), (76, 77), (77, 78)]
46
+ print(list(NLTKWordTokenizer().span_tokenize(s)) == expected)
47
 
48
+ expected = ['Good', 'muffins', 'cost', '$', '3.88', 'in',
49
+ 'New', '(', 'York', ')', '.', 'Please', '(', 'buy', ')',
50
+ 'me', 'two', 'of', 'them.', '(', 'Thanks', ')', '.']
51
+ print([s[start:end] for start, end in NLTKWordTokenizer().span_tokenize(s)] == expected)
52
 
53
  sx1 = '\xabNow that I can do.\xbb'
54
+ expected = ['\xab', 'Now', 'that', 'I', 'can', 'do', '.', '\xbb']
55
+ print(word_tokenize(sx1) == expected)
56
+
57
+ sx2 = 'The unicode 201C and 201D \u201cLEFT(RIGHT) DOUBLE QUOTATION MARK\u201d is also OPEN_PUNCT and CLOSE_PUNCT.'
58
+ expected = ['The', 'unicode', '201C', 'and', '201D', '\u201c', 'LEFT', '(', 'RIGHT', ')', 'DOUBLE', 'QUOTATION', 'MARK', '\u201d', 'is', 'also', 'OPEN_PUNCT