MCPcopy
hub / github.com/Mimino666/langdetect / add_char

Method add_char

langdetect/utils/ngram.py:31–48  ·  view source on GitHub ↗

Append a character into ngram buffer.

(self, ch)

Source from the content-addressed store, hash-verified

29 self.capitalword = False
30
31 def add_char(self, ch):
32 '''Append a character into ngram buffer.'''
33 ch = self.normalize(ch)
34 last_char = self.grams[-1]
35 if last_char == ' ':
36 self.grams = ' '
37 self.capitalword = False
38 if ch == ' ':
39 return
40 elif len(self.grams) >= self.N_GRAM:
41 self.grams = self.grams[1:]
42 self.grams += ch
43
44 if ch.isupper():
45 if last_char.isupper():
46 self.capitalword = True
47 else:
48 self.capitalword = False
49
50 def get(self, n):
51 '''Get n-gram.'''

Callers 4

_extract_ngramsMethod · 0.95
updateMethod · 0.95
test_ngramMethod · 0.95
test_ngram3Method · 0.95

Calls 1

normalizeMethod · 0.95

Tested by 2

test_ngramMethod · 0.76
test_ngram3Method · 0.76