Return SpellcheckError if this non-technical word is invalid.
550869
def _error_if_word_invalid(word,
                           valid_words_dictionary,
                           technical_words_dictionary,
                           line_offset,
                           col_offset):
    """"""
    word_lower = word.lower()
    valid_words_result = valid_words_dictionary.corrections(word_lower)

    if technical_words_dictionary:
        technical_words_result = technical_words_dictionary.corrections(word)
    else:
        # No technical words available to make an otherwise invalid
        # result value.
        technical_words_result = Dictionary.Result(False, list())

    if not valid_words_result.valid and not technical_words_result.valid:
        return SpellcheckError(word,
                               line_offset,
                               col_offset,
                               valid_words_result.suggestions,
                               SpellcheckError.InvalidWord)
291658
def raise_infinitive_error(sentence_str):
    """"""
    sent_doc = textacy.Doc(sentence_str, lang='en_core_web_lg')
    inf_pattern = r'<PART|ADP><VERB>' # To aux/auxpass* csubj
    infinitives = textacy.extract.pos_regex_matches(sent_doc, inf_pattern)
    for inf in infinitives:
        if inf[0].text.lower() != 'to':
            continue
        if inf[-1].tag_ != 'VB':
            raise Exception('InfinitivePhraseError')
1240438
def double_typos(self):
        """"""
        return {e2 for e1 in self.typos()
                for e2 in Word(e1).typos()}
1156715
def to_bool(text):
    '''
    
    '''
    downcased_text = six.text_type(text).strip().lower()

    if downcased_text == 'false':
        return False
    elif downcased_text == 'true':
        return True
    return text
233571
def spell_check_no_pipeline(self, sources, options, personal_dict):
        """"""

        for source in sources:
            if source._has_error():  # pragma: no cover
                yield Results([], source.context, source.category, source.error)

            cmd = self.setup_command(source.encoding, options, personal_dict, source.context)
            self.log('', 3)
            self.log("Command: " + str(cmd), 4)
            try:
                wordlist = util.call_spellchecker(cmd, input_text=None, encoding=source.encoding)
                yield Results(
                    [w for w in sorted(set(wordlist.replace('\r', '').split('\n'))) if w],
                    source.context,
                    source.category
                )
            except Exception as e:  # pragma: no cover
                err = self.get_error(e)
                yield Results([], source.context, source.category, err)
108524
def match_us_state(state_string):
    """"""
    if state_string:
        state_string = state_string.upper().replace('.', '').strip()
        if us_state_to_iso_code.get(state_string):
            return us_state_to_iso_code.get(state_string)
        else:
            for code, state_spellings in us_states_alternative_spellings.items():
                for spelling in state_spellings:
                    if state_string == spelling:
                        return code
    return None
1195955
def _check_for_encoding(b):
    """"""
    eol = b.find(b'\n')
    if eol < 0:
        return _check_line_for_encoding(b)[0]
    enc, again = _check_line_for_encoding(b[:eol])
    if enc or not again:
        return enc
    eol2 = b.find(b'\n', eol + 1)
    if eol2 < 0:
        return _check_line_for_encoding(b[eol + 1:])[0]
    return _check_line_for_encoding(b[eol + 1:eol2])[0]
449290
def check(self, data):
        """"""
        if isinstance(data, Iterable):
            data = "".join(str(x) for x in data)
        try:
            data = str(data)
        except UnicodeDecodeError:
            return False
        return bool(data and self.__regexp.match(data))
876359
def invalid_characters(self, text):
        """"""
        return ''.join(sorted(set([c for c in text if c not in self.alphabet])))
501298
def check(ty, val):
    ""
    
    if isinstance(ty, basestring):
        ty = Parser().parse(ty)

    return ty.enforce(val)
1092321
def check(self):
        """"""
        has_term = False

        if self.START_STATE not in self.states:
            raise SyntaxError('Undefined start rule')

        for state in self.states:
            for rule in self.states[state]:
                if rule is not None:
                    if rule[2] == self.TERM_STATE:
                        has_term = True
                    elif rule[2] not in self.states:
                        raise SyntaxError('Unexpected state: ' + rule[2])

        if not has_term:
            raise SyntaxError('Missed terminate state')
1090855
def check_ellipsis(text):
    """"""
    err = "typography.symbols.ellipsis"
    msg = u"'...' is an approximation, use the ellipsis symbol '…'."
    regex = "\.\.\."

    return existence_check(text, [regex], err, msg, max_errors=3,
                           require_padding=False, offset=0)
1208072
def correctwords(self, originalwords, newwords, **kwargs):
        """"""
        for w in originalwords:
            if not isinstance(w, Word):
                raise Exception("Original word is not a Word instance: " + str(type(w)))
            elif w.sentence() != self:
                raise Exception("Original not found as member of sentence!")
        for w in newwords:
            if not isinstance(w, Word):
                raise Exception("New word is not a Word instance: " + str(type(w)))
        if 'suggest' in kwargs and kwargs['suggest']:
            del kwargs['suggest']
            return self.correct(suggestion=newwords,current=originalwords, **kwargs)
        else:
            return self.correct(original=originalwords, new=newwords, **kwargs)
1202186
def _check_validity(cls, text):
        

        if not text[0].lstrip().startswith('1 ') or not text[1].lstrip().startswith('2 '):
            raise ValueError("Line number check failed")

        for line in text:
            line = line.strip()
            if str(cls._checksum(line)) != line[-1]:
                raise ValueError("Checksum validation failed")
70195
def is_valid(self, qstr=None):
        """"""
        if qstr is None:
            qstr = self.currentText()
        return QUrl(qstr).isValid()
946416
def _report_spelling_error(error, file_path):
    """"""
    line = error.line_offset + 1
    code = "file/spelling_error"
    description = _SPELLCHECK_MESSAGES[error.error_type].format(error.word)
    if error.suggestions is not None:
        description = (description +
                       ", perhaps you meant: " +
                       ", ".join(error.suggestions))

    sys.stdout.write("{0}:{1} [{2}] {3}\n".format(file_path,
                                                  line,
                                                  code,
                                                  description))
1218591
def _normalize(self, word):
        '''
        '''
        if '-' in word and word[0] != '-':
            return '!HYPHEN'
        elif word.isdigit() and len(word) == 4:
            return '!YEAR'
        elif word[0].isdigit():
            return '!DIGITS'
        else:
            return word.lower()