예제 #1
0
def iter_from_file(filename):
    """
    Iterate over a CoNLL-U file's sentences.

    Args:
    filename: The name of the file whose sentences should be iterated over.

    Returns:
    An iterator that yields consecutive sentences.
    """
    with open(filename) as f:
        for sentence in iter_sentences(f):
            yield sentence
예제 #2
0
def iter_from_string(source):
    """
    Iterate over a CoNLL-U string's sentences.

    Use this method if you only need to iterate over the CoNLL-U file once and
    do not need to create or store the Conll object.

    Args:
    source: The CoNLL-U string.

    Returns:
    An iterator that yields consecutive sentences.
    """
    lines = source.splitlines()
    for sentence in iter_sentences(lines):
        yield sentence
예제 #3
0
파일: load.py 프로젝트: andidyer/Andiconc
def iter_from_file(filename):
    """
    Iterate over a CoNLL-U file's sentences.

    Args:
        filename: The name of the file whose sentences should be iterated over.

    Yields:
        The sentences that make up the CoNLL-U file.

    Raises:
        IOError if there is an error opening the file.
        ParseError: If there is an error parsing the input into a Conll object.
    """
    with open(filename, encoding='utf-8') as f:
        for sentence in iter_sentences(f):
            yield sentence
예제 #4
0
파일: load.py 프로젝트: andidyer/Andiconc
def iter_from_string(source):
    """
    Iterate over a CoNLL-U string's sentences.

    Use this method if you only need to iterate over the CoNLL-U file once and
    do not need to create or store the Conll object.

    Args:
        source: The CoNLL-U string.

    Yields:
        The sentences that make up the CoNLL-U file.

    Raises:
        ParseError: If there is an error parsing the input into a Conll object.
    """
    lines = source.splitlines()
    for sentence in iter_sentences(lines):
        yield sentence
예제 #5
0
파일: load.py 프로젝트: andidyer/Andiconc
def iter_from_url(url):
    """
    Iterate over a CoNLL-U file that is pointed to by a given URL.

    Args:
        url: The URL that points to the CoNLL-U file.

    Yields:
        The sentences that make up the CoNLL-U file.

    Raises:
        requests.exceptions.RequestException: If the url was unable to be properly
            retrieved.
        ParseError: If there is an error parsing the input into a Conll object.
    """
    resp = requests.get(url)
    resp.raise_for_status()

    resp.encoding = 'utf-8'
    lines = resp.text.splitlines()
    for sentence in iter_sentences(lines):
        yield sentence