(self, byte_str)
| 75 | return self._model.get('language') |
| 76 | |
| 77 | def feed(self, byte_str): |
| 78 | if not self._model['keep_english_letter']: |
| 79 | byte_str = self.filter_international_words(byte_str) |
| 80 | if not byte_str: |
| 81 | return self.state |
| 82 | char_to_order_map = self._model['char_to_order_map'] |
| 83 | for i, c in enumerate(byte_str): |
| 84 | # XXX: Order is in range 1-64, so one would think we want 0-63 here, |
| 85 | # but that leads to 27 more test failures than before. |
| 86 | order = char_to_order_map[c] |
| 87 | # XXX: This was SYMBOL_CAT_ORDER before, with a value of 250, but |
| 88 | # CharacterCategory.SYMBOL is actually 253, so we use CONTROL |
| 89 | # to make it closer to the original intent. The only difference |
| 90 | # is whether or not we count digits and control characters for |
| 91 | # _total_char purposes. |
| 92 | if order < CharacterCategory.CONTROL: |
| 93 | self._total_char += 1 |
| 94 | if order < self.SAMPLE_SIZE: |
| 95 | self._freq_char += 1 |
| 96 | if self._last_order < self.SAMPLE_SIZE: |
| 97 | self._total_seqs += 1 |
| 98 | if not self._reversed: |
| 99 | i = (self._last_order * self.SAMPLE_SIZE) + order |
| 100 | model = self._model['precedence_matrix'][i] |
| 101 | else: # reverse the order of the letters in the lookup |
| 102 | i = (order * self.SAMPLE_SIZE) + self._last_order |
| 103 | model = self._model['precedence_matrix'][i] |
| 104 | self._seq_counters[model] += 1 |
| 105 | self._last_order = order |
| 106 | |
| 107 | charset_name = self._model['charset_name'] |
| 108 | if self.state == ProbingState.DETECTING: |
| 109 | if self._total_seqs > self.SB_ENOUGH_REL_THRESHOLD: |
| 110 | confidence = self.get_confidence() |
| 111 | if confidence > self.POSITIVE_SHORTCUT_THRESHOLD: |
| 112 | self.logger.debug('%s confidence = %s, we have a winner', |
| 113 | charset_name, confidence) |
| 114 | self._state = ProbingState.FOUND_IT |
| 115 | elif confidence < self.NEGATIVE_SHORTCUT_THRESHOLD: |
| 116 | self.logger.debug('%s confidence = %s, below negative ' |
| 117 | 'shortcut threshhold %s', charset_name, |
| 118 | confidence, |
| 119 | self.NEGATIVE_SHORTCUT_THRESHOLD) |
| 120 | self._state = ProbingState.NOT_ME |
| 121 | |
| 122 | return self.state |
| 123 | |
| 124 | def get_confidence(self): |
| 125 | r = 0.01 |
nothing calls this directly
no test coverage detected