Massive renaming!

This commit is contained in:
Crista Lopes
2019-08-12 14:38:16 -07:00
parent e6c1238a56
commit 61d5f74ad9
90 changed files with 0 additions and 0 deletions

16
27-spreadsheet/README.md Normal file
View File

@@ -0,0 +1,16 @@
Style #26
==============================
Constraints:
- The problem is modeled like a spreadsheet, with columns of data and formulas
- Some data depends on other data according to formulas. When data
changes, the dependent data also changes automatically.
Possible names:
- Spreadsheet
- Dataflow
- Active data

48
27-spreadsheet/tf-27.py Executable file
View File

@@ -0,0 +1,48 @@
#!/usr/bin/env python
import sys, re, itertools, operator
#
# The columns. Each column is a data element and a formula.
# The first 2 columns are the input data, so no formulas.
#
all_words = [(), None]
stop_words = [(), None]
non_stop_words = [(), lambda : \
list(map(lambda w : \
w if w not in stop_words[0] else '',\
all_words[0]))]
unique_words = [(),lambda :
set([w for w in non_stop_words[0] if w!=''])]
counts = [(), lambda :
list(map(lambda w, word_list : word_list.count(w), \
unique_words[0], \
itertools.repeat(non_stop_words[0], \
len(unique_words[0]))))]
sorted_data = [(), lambda : sorted(zip(list(unique_words[0]), \
list(counts[0])), \
key=operator.itemgetter(1),
reverse=True)]
# The entire spreadsheet
all_columns = [all_words, stop_words, non_stop_words,\
unique_words, counts, sorted_data]
#
# The active procedure over the columns of data.
# Call this everytime the input data changes, or periodically.
#
def update():
global all_columns
# Apply the formula in each column
for c in all_columns:
if c[1] != None:
c[0] = c[1]()
# Load the fixed data into the first 2 columns
all_words[0] = re.findall('[a-z]{2,}', open(sys.argv[1]).read().lower())
stop_words[0] = set(open('../stop_words.txt').read().split(','))
# Update the columns with formulas
update()
for (w, c) in sorted_data[0][:25]:
print(w, '-', c)