Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auchann-compatible error detection method #7

Merged
merged 1 commit into from
Nov 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion deregularise.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import csv
import re
import os
from typing import Dict, List, Tuple
from typing import cast, Dict, List, Optional, Tuple
from config import SD_DIR

tab = '\t'
Expand All @@ -50,6 +50,14 @@
wrongen = 'Wrong -en suffix'
nolabel = 'Correct'

chat_errors = {
'Overgeneralisation': 'm',
'Lacking ge prefix': 'm',
'Prefix ge without onset': 'm',
'Wrong Overgeneralisation': 'm',
'Wrong -en suffix': 'm'
}

metaarr = {}
metaarr['ge'] = ''
metaarr[''] = noge
Expand Down Expand Up @@ -98,6 +106,34 @@ def correctinflection(word: str) -> List[Tuple[str, str]]:
return result


def map_error(error_type: str) -> str:
try:
return chat_errors[error_type]
except KeyError:
return error_type


def detect_error(original: str, correction: str) -> Tuple[int, Optional[str]]:
"""Detects an error comparing a text with a correction and returns
the desired editing distance and the CHAT error code

Args:
original (str): transcribed text
correction (str): correction

Returns:
Tuple[int, Optional[str]]: editing distance and error code
"""
error = None
for candidate, candidate_error in correctinflection(original):
if candidate == correction:
error = map_error(candidate_error)
if error is not None:
return 1, cast(str, error)
else:
return 0, None


def alt(thestr):
result = '[' + thestr + ']'
return result
Expand Down