Skip to content

Commit 4afc5f5

Browse files
committed
Use lower strings. Filter URL's out.
1 parent f8ac357 commit 4afc5f5

2 files changed

Lines changed: 46 additions & 37 deletions

File tree

‎README.md‎

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -176,53 +176,54 @@ Count work frequencies within a file.
176176
```
177177
$ word-counter.py README.md
178178
179+
179180
=== Sliding Window: 1 ===
180-
14: 'resume'
181-
7: 'Python'
181+
15: 'resume'
182+
9: 'python'
183+
8: 'using'
184+
8: 'markdown'
182185
6: 'scripts'
183-
6: 'Markdown'
184-
5: 'detailed'
186+
6: 'latex,'
185187
5: 'script'
186-
5: 'using'
187-
5: 'overview.'
188-
5: 'blank'
189188
5: 'pages'
189+
5: 'generated'
190+
5: '[blog'
190191
191192
=== Sliding Window: 2 ===
192193
5: 'detailed overview.'
193-
3: 'Markdown source'
194-
3: 'Description ----|----|----'
195-
3: 'Python scripts'
194+
4: 'sliding window:'
195+
3: 'neue, using'
196+
3: 'pretty html,'
196197
3: 'blank pages.'
197-
2: 'undergraduate Computer'
198-
2: 'etc.) [icco/Resume](https://github.com/icco/Resume)'
199-
2: 'Generates pretty'
200-
2: 'column resume'
201-
2: 'using XeTeX,'
198+
3: 'computer science'
199+
3: 'science student'
200+
3: 'resumé generator'
201+
3: 'python scripts'
202+
3: 'description ----|----|----'
202203
203204
=== Sliding Window: 3 ===
204-
2: 'asymmetric column resume'
205-
2: 'build instructions. [deedydas/Deedy-Resume](https://github.com/deedydas/Deedy-Resume)'
206-
2: 'HTML, LaTeX, markdown,'
207-
2: 'resumé generator [prat0318/json_resume](https://github.com/prat0318/json_resume)'
208-
2: 'Helvetica Neue, using'
205+
2: 'pretty html, latex,'
206+
2: 'undergraduate computer science'
207+
2: 'html, latex, markdown,'
208+
2: 'pdf/html resumé generator'
209+
2: 'computer science student'
210+
2: 'generates pretty html,'
209211
2: 'multiple formats (such'
210-
2: 'PDF/HTML resumé generator'
211-
2: 'Neue, using XeTeX,'
212-
2: '(TODO), etc.) [icco/Resume](https://github.com/icco/Resume)'
213-
2: 'Computer Science student'
212+
2: 'commented latex sources'
213+
2: 'might interest somebody'
214+
2: 'neue, using xetex,'
214215
215216
=== Sliding Window: 4 ===
216-
2: 'Computer Science student [divad12/resume](https://github.com/divad12/resume)'
217-
2: 'Generates pretty HTML, LaTeX,'
218-
2: 'Helvetica Neue, using XeTeX,'
219-
2: 'PDF/HTML resumé generator [prat0318/json_resume](https://github.com/prat0318/json_resume)'
220-
2: 'pretty HTML, LaTeX, markdown,'
217+
2: 'helvetica neue, using xetex,'
218+
2: 'pretty html, latex, markdown,'
219+
2: 'undergraduate computer science student'
221220
2: 'asymmetric column resume template'
222-
2: 'undergraduate Computer Science student'
223-
1: 'Linux system configurations. ```Bash'
224-
1: 'http://bamos.github.io/2014/07/05/music-organizer/ [repo-summary-post]: http://bamos.github.io/2014/11/02/github-repo-summary/ [mpv]:'
225-
1: 'blank pages. Merged output'
221+
2: 'generates pretty html, latex,'
222+
1: 'a.pdf b.pdf c.pdf --modulo'
223+
1: ''blank pages. merged output''
224+
1: 'this is a collection'
225+
1: ''generates pretty html, latex,''
226+
1: ''asymmetric column resume template''
226227
```
227228

228229

‎python3/word-counter.py‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
from itertools import islice
77
import operator
88

9+
url_re = re.compile(
10+
'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+'
11+
)
12+
13+
914
parser = argparse.ArgumentParser()
1015
parser.add_argument('--numWords',type=int,default=10)
1116
parser.add_argument('--maxTuples',type=int,default=4)
@@ -21,16 +26,19 @@ def window(seq, n):
2126
yield result
2227
for elem in it:
2328
result = result[1:] + (elem,)
24-
containsShortWord = False
29+
useThisWindow = True
2530
for i in result:
2631
if len(i) < args.minWordLength:
27-
containsShortWord = True
32+
useThisWindow = False
33+
break
34+
elif url_re.search(i):
35+
useThisWindow = False
2836
break
29-
if not containsShortWord:
37+
if useThisWindow:
3038
yield result
3139

3240
with open(args.file,'r') as f:
33-
content = f.read().replace('\n',' ')
41+
content = f.read().replace('\n',' ').lower()
3442
words = re.findall(r'\S+', content)
3543
for i in range(1,args.maxTuples+1):
3644
print("\n=== Sliding Window: {} ===".format(i))

0 commit comments

Comments
 (0)