Exemplo n.º 1
0
 def test_custom_names_flesch_kincaid_estimator(self):
     custom_names = ["FKIndex", "fk", "flesch-kincaid"]
     for name in custom_names:
         returned_estimator = DifficultyEstimatorFactory.get_difficulty_estimator(
             name)
         self.assertEqual(returned_estimator,
                          FleschKincaidDifficultyEstimator)
Exemplo n.º 2
0
    def __init__(self,
                 url,
                 title,
                 authors,
                 content,
                 summary,
                 published_time,
                 rss_feed,
                 language,
                 broken=0):
        self.url = url
        self.title = title
        self.authors = authors
        self.content = content
        self.summary = summary
        self.published_time = published_time
        self.rss_feed = rss_feed
        self.language = language
        self.broken = broken

        fk_estimator = DifficultyEstimatorFactory.get_difficulty_estimator(
            "fk")
        fk_difficulty = fk_estimator.estimate_difficulty(
            self.content, self.language, None)['grade']

        # easier to store integer in the DB
        # otherwise we have to use Decimal, and it's not supported on all dbs
        self.fk_difficulty = fk_difficulty
        self.word_count = len(self.content.split())
Exemplo n.º 3
0
    def test_compute_very_simple_text_difficulty(self):
        estimator = DifficultyEstimatorFactory.get_difficulty_estimator(
            "frequency")
        d1 = estimator.estimate_difficulty(SIMPLE_TEXT, self.lan, self.user)

        assert d1['discrete'] == 'EASY'
        assert d1['normalized'] < 0.1
Exemplo n.º 4
0
    def text_difficulty(self, text, language):

        estimator = DifficultyEstimatorFactory.get_difficulty_estimator(
            self.preferred_difficulty_estimator()
        )
        return estimator.estimate_difficulty(text, language, self)
# e.g. doing it for polish
import zeeguu_core
from zeeguu_core.model import Article
from zeeguu_core.language.difficulty_estimator_factory import DifficultyEstimatorFactory

print("starting...")

for article in Article.query.filter_by(language_id=13).all():
    print(f"Difficulty before: {article.fk_difficulty} for {article.title} ")
    fk_estimator = DifficultyEstimatorFactory.get_difficulty_estimator("fk")
    fk_difficulty = fk_estimator.estimate_difficulty(article.content,
                                                     article.language,
                                                     None)['grade']

    article.fk_difficulty = fk_difficulty
    print(f"Difficulty after: {article.fk_difficulty} for {article.title} ")
    print(" ")

    zeeguu_core.db.session.add(article)
    zeeguu_core.db.session.commit()
Exemplo n.º 6
0
 def test_returns_flesch_kincaid_estimator(self):
     estimator_name = "FleschKincaidDifficultyEstimator"
     returned_estimator = DifficultyEstimatorFactory.get_difficulty_estimator(
         estimator_name)
     self.assertEqual(returned_estimator, FleschKincaidDifficultyEstimator)
Exemplo n.º 7
0
 def test_unknown_type_returns_default(self):
     unknown_type = "unknown_type"
     returned_estimator = DifficultyEstimatorFactory.get_difficulty_estimator(
         unknown_type)
     self.assertEqual(returned_estimator, DefaultDifficultyEstimator)
Exemplo n.º 8
0
 def test_ignore_capitalization(self):
     estimator_name = "FKINDEX"
     returned_estimator = DifficultyEstimatorFactory.get_difficulty_estimator(
         estimator_name)
     self.assertEqual(returned_estimator, FleschKincaidDifficultyEstimator)