Detects sentences in a string and returns array of spans

 @param [String] str
 @return [Array<OpenNlp::Util::Span>] array of spans for detected sentences
502023
def pos_detect(str)
      raise ArgumentError, 'str must be a String' unless str.is_a?(String)

      j_instance.sentPosDetect(str).map do |span|
        OpenNlp::Util::Span.new(span.getStart, span.getEnd)
      end
    end
1144300
static private String[] getStringList( String str )
    {
        if ( str == null )
        {
            return null;
        }
        List<String> list = new ArrayList<>();
        int i = 0;
        int length = str.length();
        StringBuffer sb = null;
        while ( i < length )
        {
            char ch = str.charAt( i );
            if ( ch == ' ' )
            {
                // A space was hit. Add string to list
                if ( sb != null )
                {
                    list.add( sb.toString() );
                    sb = null;
                }
            }
            else if ( ch == '\\' )
            {
                // It is a delimiter. Add next character
                if ( i + 1 < length )
                {
                    ch = str.charAt( ++i );
                    if ( sb == null )
                    {
                        sb = new StringBuffer();
                    }
                    sb.append( ch );
                }
            }
            else
            {
                if ( sb == null )
                {
                    sb = new StringBuffer();
                }
                sb.append( ch );
            }
            i++; // Next character
        }
        // Make sure to add the last part to the list too
        if ( sb != null )
        {
            list.add( sb.toString() );
        }
        if ( list.size() == 0 )
        {
            return null;
        }
        String[] results = new String[list.size()];
        return list.toArray( results );
    }
399299
def tokenize(self, text: str, model: object = None):
        
        sentences = re.split(self.pattern, text)
        return sentences
366837
def detect_spans(self, tokens):
        
        candidates = self._get_candidates(tokens)
        results = self._filter_candidates(tokens, candidates)
        return results
975427
def _get_ckw_span(fulltext, spans):
    """"""
    _MAXIMUM_SEPARATOR_LENGTH = max(
        [len(_separator)
         for _separator in
         current_app.config["CLASSIFIER_VALID_SEPARATORS"]]
    )
    if spans[0] < spans[1]:
        words = (spans[0], spans[1])
        dist = spans[1][0] - spans[0][1]
    else:
        words = (spans[1], spans[0])
        dist = spans[0][0] - spans[1][1]

    if dist == 0:
        # Two keywords are adjacent. We have a match.
        return (min(words[0] + words[1]),
                max(words[0] + words[1]))  # FIXME: huh, this is a bug?! a sum?
    elif dist <= _MAXIMUM_SEPARATOR_LENGTH:
        separator = fulltext[words[0][1]:words[1][0] + 1]
        # Check the separator.
        if separator.strip() in current_app.config[
                "CLASSIFIER_VALID_SEPARATORS"]:
            return (min(words[0] + words[1]), max(words[0] + words[1]))

    # There is no inclusion.
    return None
625943
def _to_spans(x):
    """"""
    if isinstance(x, Candidate):
        return [_to_span(m) for m in x]
    elif isinstance(x, Mention):
        return [x.context]
    elif isinstance(x, TemporarySpanMention):
        return [x]
    else:
        raise ValueError(f"{type(x)} is an invalid argument type")
1010792
public static Parser<Void> string(String str) {
    return Patterns.string(str).toScanner(str);
  }
1070446
def tokenize_sents(string):
    
    string = six.text_type(string)

    spans = []
    for match in re.finditer('[^\s]+', string):
        spans.append(match)
    spans_count = len(spans)

    rez = []
    off = 0

    for i in range(spans_count):
        tok = string[spans[i].start():spans[i].end()]
        if i == spans_count - 1:
            rez.append(string[off:spans[i].end()])
        elif tok[-1] in ['.', '!', '?', '…', '»']:
            tok1 = tok[re.search('[.!?…»]', tok).start()-1]
            next_tok = string[spans[i + 1].start():spans[i + 1].end()]
            if (next_tok[0].isupper()
                and not tok1.isupper()
                and not (tok[-1] != '.'
                         or tok1[0] == '('
                         or tok in ABBRS)):
                rez.append(string[off:spans[i].end()])
                off = spans[i + 1].start()

    return rez
1014774
public static function str_split($str, $split_len = 1)
    {
        if (! preg_match('/^[0-9]+$/', $split_len) || $split_len < 1) {
            return false;
        }

        $len = AnHelperString::strlen($str);
        if ($len <= $split_len) {
            return array($str);
        }

        preg_match_all('/.{'.$split_len.'}|[^\x00]{1,'.$split_len.'}$/us', $str, $ar);
        return $ar[0];
    }
565660
public static String[] spansToStrings(Error[] spans, CharSequence s) {
    String[] tokens = new String[spans.length];

    for (int si = 0, sl = spans.length; si < sl; si++) {
      tokens[si] = spans[si].getCoveredText(s).toString();
    }

    return tokens;
  }
252252
def parse(str)
      @document = AST::Document.new(file_path: file_path)
      @root = @document.root

      @dependency_paths = []

      if str.is_a?(Array)
        reset(str, [[@root]])
      else
        reset(str.split(/\r?\n/, -1), [[@root]]) # -1 is for not suppressing empty lines
      end

      parse_line while next_line

      reset

      @document
    end
329471
String[] tokenize(String sentence) {
    TokenizerME tokenizer = new TokenizerME(tokenModel);
    String cleanString = sentence.replace('’', '\'');  // this is the type of apostrophe that OpenNLP expects
    return tokenizer.tokenize(cleanString);
  }
1102062
def split_sentences_regex(text):
    
    parts = regex.split(r'([a-zA-Z0-9][.?!])[\s$]', text)
    sentences = [''.join(s) for s in zip(parts[0::2], parts[1::2])]
    return sentences + [parts[-1]] if len(parts) % 2 else sentences
613034
def segment_sentences(self, sentences, lower=True, use_stop_words=True, use_speech_tags_filter=False):
        

        res = []
        for sentence in sentences:
            res.append(self.segment(text=sentence,
                                    lower=lower,
                                    use_stop_words=use_stop_words,
                                    use_speech_tags_filter=use_speech_tags_filter))
        return res
897233
def call(str)
      pos = 0
      buffers = []
      result = [:multi]
      buffers << result
      match = nil

      str.scan(ERB_EXPR) do |indicator, code, newlines|
        match = Regexp.last_match
        len  = match.begin(0) - pos

        text = str[pos, len]
        pos  = match.end(0)
        ch   = indicator ? indicator[0] : nil

        if text and !text.empty? # text
          buffers.last << [:static, text]
        end

        if ch == ?= # <%= %>
          if code =~ BLOCK_EXPR
            buffers.last << [:erb, :block, code, block = [:multi]] # picked up by our own BlockFilter.
            buffers << block
          else
            buffers.last << [:dynamic, code]
          end
        elsif ch =~ /#/ # DISCUSS: doesn't catch <% # this %>
          newlines = code.count("\n")
          buffers.last.concat  [[:newline]] * newlines if newlines > 0
        elsif code =~ /\bend\b/ # <% end %>
          buffers.pop
        elsif ch == ?@
          buffers.last << [:capture, :block, code, block = [:multi]] # picked up by our own BlockFilter. # TODO: merge with %= ?
          buffers << block
        else # <% %>
          if code =~ BLOCK_EXEC
            buffers.last << [:block, code, block = [:multi]] # picked up by Temple's ControlFlow filter.
            buffers << block
          else
            buffers.last << [:code, code]
          end
        end

        # FIXME: only adds one newline.
        # TODO: does that influence speed?
        buffers.last << [:newline] if newlines
      end

      # add text after last/none ERB tag.
      buffers.last << [:static, str[pos..str.length]] if pos < str.length

      buffers.last
    end
556757
def converter(input_string, block_size=2):
    

    sentences = textprocessing.getSentences(input_string)
    blocks = textprocessing.getBlocks(sentences, block_size)
    parse.makeIdentifiers(blocks)
1280653
def _subspan(self, s, span, nextspan):
        """"""
        text = s[span[0]:span[1]]
        lowertext = text.lower()

        # Skip if only a single character or a split sequence
        if span[1] - span[0] < 2 or text in self.SPLIT or text in self.SPLIT_END_WORD or text in self.SPLIT_START_WORD or lowertext in self.NO_SPLIT:
            return [span]

        # Skip if it looks like URL
        if text.startswith('http://') or text.startswith('ftp://') or text.startswith('www.'):
            return [span]

        # Split full stop at end of final token (allow certain characters to follow) unless ellipsis
        if self.split_last_stop and nextspan is None and text not in self.NO_SPLIT_STOP and not text[-3:] == '...':
            if text[-1] == '.':
                return self._split_span(span, -1)
            ind = text.rfind('.')
            if ind > -1 and all(t in '\'‘’"“”)]}' for t in text[ind + 1:]):
                return self._split_span(span, ind, 1)

        # Split off certain sequences at the end of a word
        for spl in self.SPLIT_END_WORD:
            if text.endswith(spl) and len(text) > len(spl) and text[-len(spl) - 1].isalpha():
                return self._split_span(span, -len(spl), 0)

        # Split off certain sequences at the start of a word
        for spl in self.SPLIT_START_WORD:
            if text.startswith(spl) and len(text) > len(spl) and text[-len(spl) - 1].isalpha():
                return self._split_span(span, len(spl), 0)

        # Split around certain sequences
        for spl in self.SPLIT:
            ind = text.find(spl)
            if ind > -1:
                return self._split_span(span, ind, len(spl))

        # Split around certain sequences unless followed by a digit
        for spl in self.SPLIT_NO_DIGIT:
            ind = text.rfind(spl)
            if ind > -1 and (len(text) <= ind + len(spl) or not text[ind + len(spl)].isdigit()):
                return self._split_span(span, ind, len(spl))

        # Characters to split around, but with exceptions
        for i, char in enumerate(text):
            if char == '-':
                before = lowertext[:i]
                after = lowertext[i+1:]
                # By default we split on hyphens
                split = True
                if before in self.NO_SPLIT_PREFIX or after in self.NO_SPLIT_SUFFIX:
                    split = False  # Don't split if prefix or suffix in list
                elif not before.strip(self.NO_SPLIT_CHARS) or not after.strip(self.NO_SPLIT_CHARS):
                    split = False  # Don't split if prefix or suffix entirely consist of certain characters
                if split:
                    return self._split_span(span, i, 1)

        # Split contraction words
        for contraction in self.CONTRACTIONS:
            if lowertext == contraction[0]:
                return self._split_span(span, contraction[1])
        return [span]