Skip to content
Snippets Groups Projects
Commit 3cff9580 authored by Alfen, T. van (Tanja)'s avatar Alfen, T. van (Tanja)
Browse files

Merge branch 'SC-147/mistake_counter'

parents 034b664e 3ba5c0fd
No related branches found
No related tags found
1 merge request!79Master
from mistake_enum import Mistake
class MistakeCounter:
"""Class that counts the number of mistakes after alignment of source
and shadow. Calculates accuracy based on the number of mistakes
"""
def __init__(self):
pass
def analyse_mistakes(self, source, shadow):
"""
Counts for every type of mistake the number of mistakes in the
shadowing task.
Args:
source: list of words that are aligned and to which errors are
assigned, of type SourceWord.
shadow: list of words that are aligned and to which errors are
assigned, of type ShadowWord.
Returns:
repetition: number of repetition mistakes in task
phonetic: number of phonetic mistakes in task
semantic: number of semantic mistakes in task
skipped: number of skipped words in source
random: number of not-aligned random mistakes in shadow
form: number of form mistakes in task
"""
repetition = self.count_mistakes(shadow, Mistake.REPETITION)
phonetic = self.count_mistakes(source, Mistake.PHONETIC)
semantic = self.count_mistakes(source, Mistake.SEMANTIC)
skipped = self.count_mistakes(source, Mistake.SKIPPED)
random = self.count_mistakes(shadow, Mistake.RANDOM)
form = self.count_mistakes(source, Mistake.FORM)
print("nr of repetition mistakes:", repetition)
print("nr of phonetic mistakes:", phonetic)
print("nr of semantic mistakes:", semantic)
print("nr of skipped words in source:", skipped)
print("nr of random words in shadow:", random)
print("nr of form mistakes:", form)
return repetition, phonetic, semantic, skipped, random, form
def count_mistakes(self, sentence, mistake):
"""
Counts the number of times the mistake type given is present in the
list of words.
Args:
sentence: list of words that are aligned and to which errors are
assigned, of type Word.
mistake: instance of enumeration mistake, of type Mistake
Returns:
mistakes: number of mistakes of type mistake in the sentence
"""
mistakes = 0
for word in sentence:
if word.mistake == mistake:
mistakes += 1
return mistakes
def calculate_accuracy(self, source, shadow):
"""
Calculates the accuracy of the shadow task given by an aligned
source and shadow list.
Args:
source: list of words that are aligned and to which errors are
assigned, of type SourceWord.
shadow: list of words that are aligned and to which errors are
assigned, of type ShadowWord.
Returns:
accuracy: number representing the accuracy of the shadowing task
"""
repetition, phonetic, semantic, skipped, random, form = \
self.analyse_mistakes(source, shadow)
mistakes = repetition+phonetic+semantic+skipped+random+form
accuracy = (len(source)-mistakes)/len(source)
print("The accuracy of the shadowing task is", accuracy)
return accuracy
\ No newline at end of file
......@@ -4,6 +4,7 @@ from anchor_algorithm import AnchorAlgorithm
from mistake_finder import MistakeFinder
from semantic_checker import SemanticChecker
from form_checker import FormChecker
from mistake_counter import MistakeCounter
from utils import Utils as ut
import time
......@@ -24,6 +25,7 @@ class Statistics:
self._seman_checker = SemanticChecker()
self._form_checker = FormChecker()
self._mistake_finder = MistakeFinder(self._seman_checker)
self._mistake_counter = MistakeCounter()
@property
def strategy(self):
......@@ -60,7 +62,10 @@ class Statistics:
correctness = self._strategy.correctly_shadowed(source)
discrete_time = time.time() - discrete_start_time
results += f'taken time:{discrete_time}\n'
self._mistake_finder.print_for_nw(source_align, shadow_align)
self._mistake_finder.start(source_align, shadow_align)
self._mistake_counter.calculate_accuracy(source_align, shadow_align)
# Alignment 2
print('\n Anchor-algorithm')
......@@ -76,5 +81,7 @@ class Statistics:
self._mistake_finder.start(source_align_em, shadow_align_em)
discrete_time = time.time() - discrete_start_time
results += f'taken time:{discrete_time}\n'
self._mistake_counter.\
calculate_accuracy(source_align_em, shadow_align_em)
return source_align_em, shadow_align_em, correctness
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment