Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion mapper.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
#!/usr/bin/env python
import sys
import string

# get all lines from stdin
for line in sys.stdin:
# remove leading and trailing whitespace
line = line.strip()

# make lowercase
line = line.lower()

# https://stackoverflow.com/questions/34860982/replace-the-punctuation-with-whitespace
# remove punctuation
punctuations = list(string.punctuation)
for p in punctuations:
if p in line:
line = line.replace(p, '')

# split the line into words; splits on any whitespace
words = line.split()

# output tuples (word, 1) in tab-delimited format
stopwords = set(['the', 'and', 'is', 'a', 'this', 'that', 'it', 'to', 'in', 'an', 'as'])

for word in words:
print '%s\t%s' % (word, "1")
if word not in stopwords:
print '%s\t%s' % (word, "1")