Browse code
added a simple program to check for the correct use of articles in a writing sample
Ed L authored on 29/02/2012 01:30:19
Showing 1 changed files
Showing 1 changed files
1 | 1 |
new file mode 100755 |
... | ... |
@@ -0,0 +1,28 @@ |
1 |
+#!/usr/bin/python |
|
2 |
+ |
|
3 |
+import fileinput |
|
4 |
+ |
|
5 |
+a = fileinput.FileInput() |
|
6 |
+ |
|
7 |
+def window_iterate(sequence, width=2, begin=0): |
|
8 |
+ while begin < len(sequence): |
|
9 |
+ result = sequence[begin:begin+width] |
|
10 |
+ |
|
11 |
+ while len(result) < width: result.append('') |
|
12 |
+ |
|
13 |
+ yield result |
|
14 |
+ begin += 1 |
|
15 |
+ |
|
16 |
+for line in a: |
|
17 |
+ line = line.split() |
|
18 |
+ |
|
19 |
+ out = [] |
|
20 |
+ for window in window_iterate(line): |
|
21 |
+ if window[0] in set(['a', 'an']): |
|
22 |
+ if any(window[1].startswith(vowel) for vowel in 'aeiouh'): |
|
23 |
+ window[0] = 'an' |
|
24 |
+ else: |
|
25 |
+ window[0] = 'a' |
|
26 |
+ out.append(window[0]) |
|
27 |
+ print(' '.join(out)) |
|
28 |
+ |