Skip to content

Commit

Permalink
Script for recomputing FK scores for languages with new constants
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavkrist committed Oct 7, 2024
1 parent a71c82d commit d45e4ff
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tools/recompute_fk_difficulties.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import zeeguu.core
from zeeguu.api.app import create_app
from zeeguu.core.model import Article, Language
from zeeguu.core.language.difficulty_estimator_factory import DifficultyEstimatorFactory

app = create_app()
app.app_context().push()

print("starting...")


session = zeeguu.core.model.db.session
with session.begin():
for article in Article.query.filter(
Article.language.has(Language.code.in_(["es", "fr", "it", "nl", "ru"]))
).all():
print(f"Article language: {article.language}")
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}\n")

session.add(article)
session.commit()

0 comments on commit d45e4ff

Please sign in to comment.