Get random line from another document for nextSentence task.
        :return: str, content of one line
516186
def get_random_line(self):
        
        # Similar to original tf repo: This outer loop should rarely go for more than one iteration for large
        # corpora. However, just to be careful, we try to make sure that
        # the random document is not the same as the document we're processing.
        for _ in range(10):
            if self.on_memory:
                rand_doc_idx = random.randint(0, len(self.all_docs)-1)
                rand_doc = self.all_docs[rand_doc_idx]
                line = rand_doc[random.randrange(len(rand_doc))]
            else:
                rand_index = random.randint(1, self.corpus_lines if self.corpus_lines < 1000 else 1000)
                #pick random line
                for _ in range(rand_index):
                    line = self.get_next_line()
            #check if our picked random line is really from another doc like we want it to be
            if self.current_random_doc != self.current_doc:
                break
        return line
334538
public synchronized Document next() {
        Document next = new StringDocument(nextLine);
        try {
            nextLine = documentsReader.readLine();

            // close the stream if there were no more lines
            if (nextLine == null) {
                documentsReader.close();
            }
        } catch (Throwable t) {
            t.printStackTrace();
            nextLine = null;
        }
        return next;
    }
567255
def lines(text):
    
    assert text is not None
    assert '\r' not in text
    previous_newline_index = 0
    newline_index = text.find('\n')
    while newline_index != -1:
        yield text[previous_newline_index:newline_index]
        previous_newline_index = newline_index + 1
        newline_index = text.find('\n', previous_newline_index)
    last_line = text[previous_newline_index:]
    if last_line != '':
        yield last_line
319061
def generate_text(self, max_length=None):
        
        return self._text_generator(next_token=self._generate_next_token, max_length=max_length)
55917
def build_documentation_lines(self):
        
        return [
            line_string for key in sorted(self.keys)
            for line_string in self.build_paramter_string(key)
        ]
1139946
def get_current_line(self):
        """"""
        cursor = self.textCursor()
        cursor.select(QTextCursor.BlockUnderCursor)
        return to_text_string(cursor.selectedText())
910018
def _next_record(self, next_line):
        
        record = self.loader.parse_record_stream(self.reader,
                                                 next_line,
                                                 self.known_format,
                                                 self.no_record_parse,
                                                 self.ensure_http_headers)

        self.member_info = None

        # Track known format for faster parsing of other records
        if not self.mixed_arc_warc:
            self.known_format = record.format

        return record
316764
def random_data(line_count=1, chars_per_line=80):
    
    divide_lines = chars_per_line * line_count
    return '\n'.join(random_line_data(chars_per_line) for x in range(int(divide_lines / chars_per_line)))
862922
def read(self):
        
        lines = self.readlines()
        if lines:
            try:
                return ''.join(lines)
            except TypeError:
                return ''.join(force_text(line) for line in lines)
        else:
            return None
282143
def join_next_line(self, separator=' '):
        
        if not self.document.on_last_line:
            self.cursor_position += self.document.get_end_of_line_position()
            self.delete()

            # Remove spaces.
            self.text = (self.document.text_before_cursor + separator +
                         self.document.text_after_cursor.lstrip(' '))
675678
def iter_lines(self, chunk_size=ITER_CHUNK_SIZE, decode_unicode=None, delimiter=None):
        

        pending = None

        for chunk in self.iter_content(chunk_size=chunk_size, decode_unicode=decode_unicode):

            if pending is not None:
                chunk = pending + chunk

            if delimiter:
                lines = chunk.split(delimiter)
            else:
                lines = chunk.splitlines()

            if lines and lines[-1] and chunk and lines[-1][-1] == chunk[-1]:
                pending = lines.pop()
            else:
                pending = None

            for line in lines:
                yield line

        if pending is not None:
            yield pending
620592
def transform_current_line(self, transform_callback):
        
        document = self.document
        a = document.cursor_position + document.get_start_of_line_position()
        b = document.cursor_position + document.get_end_of_line_position()
        self.text = (
            document.text[:a] +
            transform_callback(document.text[a:b]) +
            document.text[b:])
966069
def get_lines(self, first, last):
        """"""
        line = 1
        linestring = []
        linestrings = []
        for char in self.string:
            if line >= first and line <= last:
                linestring.append(char)
                if char == '\n':
                    linestrings.append((''.join(linestring), line))
                    linestring = []
            elif line > last:
                break

            if char == '\n':
                line += 1
        if linestring:
            linestrings.append((''.join(linestring), line))
        elif not linestrings:
            return None

        return [SourceLine(string, lineno) for string, lineno in linestrings]
1299592
def read_content(path: str, limit: Optional[int] = None) -> Iterator[List[str]]:
    
    with smart_open(path) as indata:
        for i, line in enumerate(indata):
            if limit is not None and i == limit:
                break
            yield list(get_tokens(line))
432691
def text(self, max_lines=sys.maxsize):
        
        ret_val = []
        block = self._trigger.next()
        _, end = self.get_range()
        while (block.isValid() and block.blockNumber() <= end and
               len(ret_val) < max_lines):
            ret_val.append(block.text())
            block = block.next()
        return '\n'.join(ret_val)
810336
def get_line(thing):
    
    try:
        return inspect.getsourcelines(thing)[1]
    except TypeError:
        # Might be a property
        return inspect.getsourcelines(thing.fget)[1]
    except Exception as e:
        # print(thing)
        raise e
860699
def _get_document(self, source):
        """"""
        scheme_url = source
        if not source.startswith("http"):
            scheme_url = "http://%s" % source

        text = source

        try:
            text = urllib.urlopen(scheme_url).read()
        except:
            pass
        else:
            return (text, scheme_url)

        try:
            text = open(source, "r").read()
        except:
            pass
        else:
            return (text, source)

        return (text, None)