How to use the sumy._compat.to_string function in sumy

To help you get started, we’ve selected a few sumy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github miso-belica / sumy / tests / test_utils / test_unicode_compatible_class.py View on Github external
def test_to_string():
    returned = compat.to_string(O())
    _assert_strings_equal(NATIVE_STRING, returned)
github miso-belica / sumy / tests / test_utils / test_unicode_compatible_class.py View on Github external
# -*- coding: utf-8 -*-

from __future__ import absolute_import, division, print_function, unicode_literals

import pytest

from sumy import _compat as compat


BYTES_STRING = "ľščťžáýíééäúňô €đ€Ł¤".encode("utf-8")
UNICODE_STRING = "ľščťžáýíééäúňô €đ€Ł¤"
NATIVE_STRING = compat.to_string(UNICODE_STRING)


@compat.unicode_compatible
class O(object):
    def __unicode__(self):
        return UNICODE_STRING


def _assert_strings_equal(str1, str2):
    assert type(str1) is type(str2)
    assert str1 == str2


@pytest.mark.skipif(not compat.PY3, reason="Python 2 doesn't support method `__bytes__`")
def test_native_bytes():
    returned = bytes(O())
github miso-belica / sumy / tests / utils.py View on Github external
def expand_resource_path(path):
    return join(abspath(dirname(__file__)), to_string("data"), to_string(path))
github miso-belica / sumy / sumy / nlp / tokenizers.py View on Github external
def _get_sentence_tokenizer(self, language):
        if language in self.SPECIAL_SENTENCE_TOKENIZERS:
            return self.SPECIAL_SENTENCE_TOKENIZERS[language]
        try:
            path = to_string("tokenizers/punkt/%s.pickle") % to_string(language)
            return nltk.data.load(path)
        except (LookupError, zipfile.BadZipfile):
            raise LookupError(
                "NLTK tokenizers are missing. Download them by following command: "
                '''python -c "import nltk; nltk.download('punkt')"'''
github miso-belica / sumy / sumy / utils.py View on Github external
def expand_resource_path(path):
    directory = dirname(sys.modules["sumy"].__file__)
    directory = abspath(directory)
    return join(directory, to_string("data"), to_string(path))
github miso-belica / sumy / sumy / utils.py View on Github external
def __repr__(self):
        return to_string("" % self._value)
github miso-belica / sumy / sumy / _object.py View on Github external
def __str__(self):
        return to_string(self.__to_unicode())
github miso-belica / sumy / sumy / __main__.py View on Github external
def main(args=None):
    args = docopt(to_string(__doc__), args, version=__version__)
    summarizer, parser, items_count = handle_arguments(args)

    for sentence in summarizer(parser.document, items_count):
        if PY3:
            print(to_unicode(sentence))
        else:
            print(to_bytes(sentence))

    return 0