コード例 #1
0
def test_get_or_create__wrong_args():
    languages = "english"
    with pytest.raises(ValueError):
        criterion = LikelihoodCriterionRules.get_or_create(languages=languages)

    languages = ["wrong"]
    with pytest.raises(ValueError):
        criterion = LikelihoodCriterionRules.get_or_create(languages=languages)

    max_gram = 0
    with pytest.raises(ValueError):
        criterion = LikelihoodCriterionRules.get_or_create(max_gram=max_gram)

    threshold = 2
    with pytest.raises(ValueError):
        criterion = LikelihoodCriterionRules.get_or_create(threshold=threshold)
コード例 #2
0
def test_get_or_create__create():
    languages = ["english"]
    max_gram = 1

    criterion = LikelihoodCriterionRules.get_or_create(languages=languages,
                                                       max_gram=max_gram)
    assert map(attrgetter("language"), criterion.languages.all()) == languages
    assert criterion.max_gram == max_gram
コード例 #3
0
ファイル: test_criterion.py プロジェクト: aahilgert/dalite-ng
def test_evaluate__default__random(likelihood_criterion, answers):
    answer = answers[0]
    answer.rationale = "".join(
        random.choice([" "] + list(string.ascii_letters))
        for _ in range(random.randint(5, 50)))
    answer.save()

    likelihood_rules = LikelihoodCriterionRules.get_or_create()

    assert (likelihood_criterion.evaluate(
        answer, likelihood_rules.pk)["quality"] < 0.95)
コード例 #4
0
ファイル: test_criterion.py プロジェクト: aahilgert/dalite-ng
def test_evaluate__default__french(likelihood_criterion, answers):
    answer = answers[0]
    answer.rationale = (
        "Les familles heureuses se ressemblent toutes; les familles "
        "malheureuses sont malheureuses chacune à leur façon.")
    answer.save()

    likelihood_rules = LikelihoodCriterionRules.get_or_create()

    assert (likelihood_criterion.evaluate(
        answer, likelihood_rules.pk)["quality"] >= 0.95)
コード例 #5
0
ファイル: test_criterion.py プロジェクト: aahilgert/dalite-ng
def test_evaluate__default__english(likelihood_criterion, answers):
    answer = answers[0]
    answer.rationale = (
        "All happy families are alike; each unhappy family is unhappy in its "
        "own way.")
    answer.save()

    likelihood_rules = LikelihoodCriterionRules.get_or_create()

    assert (likelihood_criterion.evaluate(
        answer, likelihood_rules.pk)["quality"] >= 0.95)
コード例 #6
0
def test_get_or_create__get(likelihood_rules):
    languages = list(likelihood_rules.languages.all())
    max_gram = likelihood_rules.max_gram
    threshold = likelihood_rules.threshold
    n_rules = LikelihoodCriterionRules.objects.count()

    criterion = LikelihoodCriterionRules.get_or_create(threshold=threshold,
                                                       languages=languages,
                                                       max_gram=max_gram)
    assert list(criterion.languages.all()) == languages
    assert criterion.max_gram == max_gram
    assert LikelihoodCriterionRules.objects.count() == n_rules
コード例 #7
0
ファイル: test_criterion.py プロジェクト: aahilgert/dalite-ng
def test_batch_evaluate__default__random(likelihood_criterion, answers):
    answers = answers[:3]
    for answer in answers:
        answer.rationale = "".join(
            random.choice([" "] + list(string.ascii_letters))
            for _ in range(random.randint(5, 50)))
        answer.save()

    likelihood_rules = LikelihoodCriterionRules.get_or_create()

    quality = likelihood_criterion.batch_evaluate(answers, likelihood_rules.pk)
    for q in quality:
        assert q["quality"] < 0.95
コード例 #8
0
ファイル: test_criterion.py プロジェクト: aahilgert/dalite-ng
def test_batch_evaluate__default__french(likelihood_criterion, answers):
    answers = answers[:3]
    for answer in answers:
        answer.rationale = (
            "Les familles heureuses se ressemblent toutes; les familles "
            "malheureuses sont malheureuses chacune à leur façon.")
        answer.save()

    likelihood_rules = LikelihoodCriterionRules.get_or_create()

    quality = likelihood_criterion.batch_evaluate(answers, likelihood_rules.pk)
    for q in quality:
        assert q["quality"] >= 0.95
コード例 #9
0
ファイル: test_criterion.py プロジェクト: aahilgert/dalite-ng
def test_batch_evaluate__default__english(likelihood_criterion, answers):
    answers = answers[:3]
    for answer in answers:
        answer.rationale = (
            "All happy families are alike; each unhappy family is unhappy in "
            "its own way.")
        answer.save()

    likelihood_rules = LikelihoodCriterionRules.get_or_create()

    quality = likelihood_criterion.batch_evaluate(answers, likelihood_rules.pk)
    for q in quality:
        assert q["quality"] >= 0.95