get Proofreading errors of sentence out of paragraph matches from cache
976595
SingleProofreadingError[] getFromPara(int numberOfParagraph,
              int startOfSentencePosition, int endOfSentencePosition) {
    for (CacheEntry anEntry : entries) {
      if (anEntry.numberOfParagraph == numberOfParagraph) {
        List<SingleProofreadingError> errorList = new ArrayList<>();
        for (SingleProofreadingError eArray : anEntry.errorArray) {
          if (eArray.nErrorStart >= startOfSentencePosition && eArray.nErrorStart < endOfSentencePosition) {
            errorList.add(eArray);
          }
        }
        return errorList.toArray(new SingleProofreadingError[0]);
      }
    }
    return null;
  }
427016
def _run_spellcheck_linter(matched_filenames, cache_dir, show_lint_files):
    """"""
    from polysquarelinter import lint_spelling_only as lint
    from prospector.message import Message, Location

    for filename in matched_filenames:
        _debug_linter_status("spellcheck-linter", filename, show_lint_files)

    return_dict = dict()

    def _custom_reporter(error, file_path):
        line = error.line_offset + 1
        key = _Key(file_path, line, "file/spelling_error")
        loc = Location(file_path, None, None, line, 0)
        # suppress(protected-access)
        desc = lint._SPELLCHECK_MESSAGES[error.error_type].format(error.word)
        return_dict[key] = Message("spellcheck-linter",
                                   "file/spelling_error",
                                   loc,
                                   desc)

    # suppress(protected-access,unused-attribute)
    lint._report_spelling_error = _custom_reporter
    lint.main([
        "--spellcheck-cache=" + os.path.join(cache_dir, "spelling"),
        "--stamp-file-path=" + os.path.join(cache_dir,
                                            "jobstamps",
                                            "polysquarelinter"),
        "--technical-terms=" + os.path.join(cache_dir, "technical-terms"),
    ] + matched_filenames)

    return return_dict
219615
function _error(data) {
            if (options.debug) {
                process.stderr.write(data);
            }
            const cc = cache.controlChars.step;
            // concatenate the data with cache.stderr
            const stderr = cache.stderr + data;
            // if control character stripping is enabled, do it.
            cache.stderr = cc.strip === false ? stderr : stderr.replace(cc.regexp, '');
        }
953232
def go_to_error(self, text):
        """"""
        match = get_error_match(to_text_string(text))
        if match:
            fname, lnb = match.groups()
            self.edit_script(fname, int(lnb))
1263421
function() {
        var line = cleanText(self.history.textAfter(self.line).slice(self.offset));
        var match = (self.caseFold ? line.toLowerCase() : line).indexOf(string);
        if (match > -1)
          return {from: {node: self.line, offset: self.offset + match},
                  to: {node: self.line, offset: self.offset + match + string.length}};
      }
1174751
def _check_grain_pcre_minions(self, expr, delimiter, greedy):
        '''
        
        '''
        return self._check_cache_minions(expr,
                                         delimiter,
                                         greedy,
                                         'grains',
                                         regex_match=True)
325476
def _write_cache(self, lines, append=False):
        """"""
        mode = 'at' if append else 'wt'
        with open(self.filepath, mode, encoding='utf8') as fh:
            fh.writelines(line + '\n' for line in lines)
765343
def pre_check(self, data):
        """"""
        sentences = len(re.findall('[\.!?]+\W+', data)) or 1
        chars = len(data) - len(re.findall('[^a-zA-Z0-9]', data))
        num_words = len(re.findall('\s+', data))
        data = re.split('[^a-zA-Z]+', data)
        return data, sentences, chars, num_words
1027549
private SingleProofreadingError createOOoError(RuleMatch ruleMatch, int startIndex, int sentencesLength, char lastChar) {
    SingleProofreadingError aError = new SingleProofreadingError();
    aError.nErrorType = TextMarkupType.PROOFREADING;
    // the API currently has no support for formatting text in comments
    aError.aFullComment = ruleMatch.getMessage()
        .replaceAll("<suggestion>", "\"").replaceAll("</suggestion>", "\"")
        .replaceAll("([\r]*\n)", " ");
    // not all rules have short comments
    if (!StringTools.isEmpty(ruleMatch.getShortMessage())) {
      aError.aShortComment = ruleMatch.getShortMessage();
    } else {
      aError.aShortComment = aError.aFullComment;
    }
    aError.aShortComment = org.languagetool.gui.Tools.shortenComment(aError.aShortComment);
    int numSuggestions;
    String[] allSuggestions;
    numSuggestions = ruleMatch.getSuggestedReplacements().size();
    allSuggestions = ruleMatch.getSuggestedReplacements().toArray(new String[numSuggestions]);
    //  Filter: remove suggestions for override dot at the end of sentences
    //  needed because of error in dialog
    if (lastChar == '.' && (ruleMatch.getToPos() + startIndex) == sentencesLength) {
      int i = 0;
      while (i < numSuggestions && i < MAX_SUGGESTIONS
          && allSuggestions[i].length() > 0 && allSuggestions[i].charAt(allSuggestions[i].length()-1) == '.') {
        i++;
      }
      if (i < numSuggestions && i < MAX_SUGGESTIONS) {
      numSuggestions = 0;
      allSuggestions = new String[0];
      }
    }
    //  End of Filter
    if (numSuggestions > MAX_SUGGESTIONS) {
      aError.aSuggestions = Arrays.copyOfRange(allSuggestions, 0, MAX_SUGGESTIONS);
    } else {
      aError.aSuggestions = allSuggestions;
    }
    aError.nErrorStart = ruleMatch.getFromPos() + startIndex;
    aError.nErrorLength = ruleMatch.getToPos() - ruleMatch.getFromPos();
    aError.aRuleIdentifier = ruleMatch.getRule().getId();
    // LibreOffice since version 3.5 supports an URL that provides more information about the error,
    // LibreOffice since version 6.2 supports the change of underline color (key: "LineColor", value: int (RGB))
    // LibreOffice since version 6.2 supports the change of underline style (key: "LineType", value: short (DASHED = 5))
    // older version will simply ignore the properties
    Color underlineColor = config.getUnderlineColor(ruleMatch.getRule().getCategory().getName());
    URL url = ruleMatch.getUrl();
    if (url == null) {                      // match URL overrides rule URL 
      url = ruleMatch.getRule().getUrl();
    }
    if(underlineColor != Color.blue) {
      int ucolor = underlineColor.getRGB() & 0xFFFFFF;
      if (url != null) {
        aError.aProperties = new PropertyValue[] { new PropertyValue(
            "FullCommentURL", -1, url.toString(), PropertyState.DIRECT_VALUE),
            new PropertyValue("LineColor", -1, ucolor, PropertyState.DIRECT_VALUE) };
      } else {
        aError.aProperties = new PropertyValue[] {
            new PropertyValue("LineColor", -1, ucolor, PropertyState.DIRECT_VALUE) };
      }
    } else {
      if (url != null) {
        aError.aProperties = new PropertyValue[] { new PropertyValue(
            "FullCommentURL", -1, url.toString(), PropertyState.DIRECT_VALUE) };
      } else {
        aError.aProperties = new PropertyValue[0];
      }
    }
    return aError;
  }
1295499
def complete_ls(self, text, *_):
        
        return [t + " " for t in self.engine.cached_descriptions if t.startswith(text)]
1334903
function (context, next) {
        this._cache.read(context.cached._id, function (err, doc) {
            if (err || !doc)
                return next(err || new Error('Critical failure! A cache entry has mysteriously disappeared...'));
            context.cached = doc;
            // this should happen only for internal phantom errors, not client javascript errors.
            if (context.cached.error) {
                this.logger.warn('The last try gave us an error, try to recompute.', { error: context.cached.error });
                context.options.force = true;
                context.options.wait = true;
            }
            next(null);
        });
    }
774071
def _mangle_sentences_from_file(input_file):
    """"""
    try:
        with open(input_file, 'r') as f:
            # final sentence may not be a complete sentence, save and prepend to next chunk
            leftovers = ''
            sentence_no = 0
            for chunk in read_in_chunks(f): # lazy way of reading our file in case it's large
                # prepend leftovers to chunk
                chunk = chunk.decode('utf8')
                chunk = leftovers + chunk
                chunk = chunk.replace(';', '.') # replace semi colons with periods 
                doc = nlp(chunk)

                # last sentence may not be sentence, move to next chunk
                sents = [sent.string.strip() for sent in doc.sents]
                if len(sents) > 1:
                    leftovers = sents[-1] + chunk.rpartition(sents[-1])[-1]
                    sents = sents[:-1]

                for sent in sents:
                    sent = sent.replace('\n', ' ')
                    sent = sent.replace('\r', ' ')
                    sent = re.sub( '\s+', ' ', sent ).strip()
                    if len(sent) < 5:
                        continue # skip tiny sentences
                    # add original sentence to database
                    cursor.execute('''insert into orignal_sentences (sentence,
                    flesch_reading_ease, flesch_kincaid_grade_level) values (?,
                    ?, ?)''', (sent, textstat.flesch_reading_ease(sent),
                        textstat.flesch_kincaid_grade(sent)))
                    og_sent_id = cursor.lastrowid
                    for mangled_sentence in mangle_agreement(sent):
                        # add mangled sentence to database
                        cursor.execute('''insert into mangled_sentences
                        (original_sentence_id, sentence) values (?, ?)''',
                        (og_sent_id, mangled_sentence))
                conn.commit() # commit all sentences in this chunk

    except Exception as e:
        print('error on {}'.format(input_file))
        print(e)
146276
def cwms_process_text():
    """"""
    if request.method == 'OPTIONS':
        return {}
    response = request.body.read().decode('utf-8')
    body = json.loads(response)
    text = body.get('text')
    cp = cwms.process_text(text)
    return _stmts_from_proc(cp)
526615
def _from_match(match):
        """"""
        addr_beg, addr_end, r, w, x, p, offset, dev, inode, pathname = match.groups()
        return MemoryRegion(addr_beg=int(addr_beg, 16),
                            addr_end=int(addr_end, 16),
                            readable=(r == "r"),
                            writable=(w == "w"),
                            executable=(x == "x"),
                            private=(p == "p"),
                            offset=int(offset, 16),
                            dev=dev,
                            inode=int(inode),
                            pathname=pathname)
35547
def get_pystache_parsed(mustache_file):
    """"""
    with open(mustache_file, 'r') as file_:
        parsed = pystache.parse(file_.read())
    return parsed
472226
function processUncached( $tpl, $functionChildren, $rootNamespace, $currentNamespace )
    {
        $children = $functionChildren;

        $childTextElements = array();
        if ( is_array( $children ) )
        {
            foreach ( array_keys( $children ) as $childKey )
            {
                $child =& $children[$childKey];
                $tpl->processNode( $child, $childTextElements, $rootNamespace, $currentNamespace );
            }
        }
        $text = implode( '', $childTextElements );
        return $text;
    }
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')