~ubuntu-branches/ubuntu/saucy/pida/saucy

« back to all changes in this revision

Viewing changes to src/plugins/culebra/words.py

  • Committer: Bazaar Package Importer
  • Author(s): Ante Karamatic
  • Date: 2005-09-27 10:19:38 UTC
  • Revision ID: james.westby@ubuntu.com-20050927101938-o7ak8uqyuvewfuw8
Tags: upstream-0.2.2
ImportĀ upstreamĀ versionĀ 0.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import gtk
 
2
special_chars = (" ", "\n", ".", ":", ",", "'", 
 
3
                '"', "(", ")", "{", "}", "[", "]")
 
4
 
 
5
def wordcount(b):
 
6
    i1 = b.get_start_iter()
 
7
    
 
8
    i2 = i1.copy()
 
9
    i2.forward_word_end()
 
10
 
 
11
    i = 0
 
12
 
 
13
    while i2.get_offset() <> i1.get_offset():
 
14
        i += 1
 
15
        i1 = i2.copy()
 
16
        i2.forward_word_end()
 
17
    
 
18
    return i
 
19
 
 
20
def buffer_wordlist(b):
 
21
    i1 = b.get_start_iter()
 
22
    
 
23
    i2 = i1.copy()
 
24
    i2.forward_word_end()
 
25
 
 
26
    wl = []
 
27
    
 
28
    i1, i2 = b.get_bounds()
 
29
    
 
30
    text = b.get_text(i1, i2)
 
31
        
 
32
    text = text.replace("\n", " ")
 
33
    text = text.replace(",", " ")
 
34
    text = text.replace(".", " ")
 
35
    text = text.replace(":", " ")
 
36
    text = text.replace("(", " ")
 
37
    text = text.replace(")", " ")
 
38
    text = text.replace("'", " ")
 
39
    text = text.replace('"', " ")
 
40
    b = gtk.TextBuffer()
 
41
    b.set_text(text)
 
42
 
 
43
    i1 = b.get_start_iter()
 
44
    
 
45
    i2 = i1.copy()
 
46
    i2.forward_word_end()
 
47
 
 
48
    while i2.get_offset() <> i1.get_offset():
 
49
        
 
50
        
 
51
 
 
52
        word = b.get_text(i1, i2).strip()
 
53
 
 
54
        #print word
 
55
 
 
56
        if not word in wl:
 
57
            wl.append(word)
 
58
            
 
59
        i1 = i2.copy()
 
60
        i2.forward_word_end()
 
61
 
 
62
    return wl
 
63
 
 
64
def text_wordlist(text):
 
65
 
 
66
    for i in special_chars:
 
67
        text = text.replace(i, " ")
 
68
    wl = text.split(" ")
 
69
    
 
70
    wl = [x for x in wl if x != '']
 
71
    
 
72
    return wl
 
73
    
 
74
if __name__ == "__main__":
 
75
 
 
76
    b = gtk.TextBuffer()
 
77
    
 
78
    print text_wordlist("veo un marciano sentado en el ala de un vuelo de taca en un dia como el de hoy")
 
79