# -*- coding: utf8 -*-

from __future__ import absolute_import
from __future__ import division, print_function, unicode_literals

import sys

from functools import wraps
from os.path import dirname, abspath, join, exists
from ._compat import to_string, to_unicode, string_types


def cached_property(getter):
    """
    Decorator that converts a method into memoized property.
    The decorator works as expected only for classes with
    attribute '__dict__' and immutable properties.
    """
    @wraps(getter)
    def decorator(self):
        key = "_cached_property_" + getter.__name__

        if not hasattr(self, key):
            setattr(self, key, getter(self))

        return getattr(self, key)

    return property(decorator)


def expand_resource_path(path):
    directory = dirname(sys.modules["sumy"].__file__)
    directory = abspath(directory)
    return join(directory, to_string("data"), to_string(path))


def get_stop_words(language):
    path = expand_resource_path("stopwords/%s.txt" % language)
    if not exists(path):
        raise ValueError("Stop-words are not available for language %s." % language)

    with open(path, "rb") as file:
        return frozenset(to_unicode(w.rstrip()) for w in file.readlines())


class ItemsCount(object):
    def __init__(self, value):
        self._value = value

    def __call__(self, sequence):
        if isinstance(self._value, string_types):
            if self._value.endswith("%"):
                total_count = len(sequence)
                percentage = int(self._value[:-1])
                count = total_count*percentage // 100
                return sequence[:count]
            else:
                return sequence[:int(self._value)]
        elif isinstance(self._value, int):
            return sequence[:self._value]
        else:
            ValueError("Unsuported value of items count '%s'." % self._value)

@@ -1559,23 +1559,88 @@
         
-count =
+# at least one sentence should be choosen%0A                count = max(1,
  total_c
@@ -1661,16 +1661,17 @@
 e // 100
+)
 %0A       

Add to summary at least 1 sentence if possible