Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|