From 6c2af753df909b853a9ee1d53b2f3634809a5fe3 Mon Sep 17 00:00:00 2001 From: Wojciech Jarmosz Date: Thu, 9 Jun 2022 01:32:43 +0200 Subject: [PATCH] Filter dummy errors --- backend/requirements.txt | 15 +++++++++++++++ backend/translation/views.py | 21 +++++++++++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 backend/requirements.txt diff --git a/backend/requirements.txt b/backend/requirements.txt new file mode 100644 index 0000000..9f670b8 --- /dev/null +++ b/backend/requirements.txt @@ -0,0 +1,15 @@ +asgiref==3.5.2 +backports.zoneinfo==0.2.1 +defusedxml==0.7.1 +Django==4.0.4 +django-cors-headers==3.12.0 +django-environ==0.8.1 +djangorestframework==3.13.1 +djangorestframework-xml==2.0.0 +langdetect==1.0.9 +lxml==4.8.0 +pytz==2022.1 +regex==2022.4.24 +six==1.16.0 +sqlparse==0.4.2 +websocket-client==1.3.2 diff --git a/backend/translation/views.py b/backend/translation/views.py index 65d41af..2fe2bcc 100644 --- a/backend/translation/views.py +++ b/backend/translation/views.py @@ -11,12 +11,27 @@ from pathlib import Path import regex as re import uuid import os +from langdetect import detect BASE_DIR = Path(__file__).resolve().parent from rest_framework.decorators import api_view, renderer_classes, parser_classes from .renderers import MyXMLRenderer +def filter_dummy_errors(original, error): + + if '//' in error: + return (False, "") + elif error.split(" ") > 2: + return (False, "") + # Check if is not english + elif detect(error) != 'pl': + return (False, "") + + return (True, error) + + + def get_context(line, start_index, end_index): start_index = start_index - 20 @@ -46,8 +61,10 @@ def diff_text(original, corrected): start_position = re.search('\[-([^\[]*?)\+}', line).start() end_position = re.search('\[-([^\[]*?)\+}', line).end() - - output.append({'id': 'grammar-error', 'type': 'grammar', 'correction': added[0], 'context': f'{get_context(lines[idx], start_position, end_position)}', 'msg': f"Zamiana '{removed[0]}' na '{added[0]}'"}) + is_error, error = filter_dummy_errors(removed, added) + + if is_error: + output.append({'id': 'grammar-error', 'type': 'grammar', 'correction': added[0], 'context': f'{get_context(lines[idx], start_position, end_position)}', 'msg': f"Zamiana '{removed[0]}' na '{added[0]}'"}) removed = re.findall('\[\-(.*?)\-]', new_line) added = re.findall('{\+(.*?)\+}', new_line)