Skip to content

Commit 097e920

Browse files
authored
Merge pull request #83 from DAAily/SSD-752-Sparky-The-language-nl-is-not-supported-for-syntax-analysis---On-the-Google-Cloud-Language-API
SSD-752 Sparky: The language nl is not supported for syntax analysis …
2 parents d4e9537 + c393333 commit 097e920

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

daaily/lucy/enums.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,11 @@ def extract_from_extension(extension: str): # noqa: C901
9696
return MimeType.CSV
9797
if extension == "json":
9898
return MimeType.JSON
99+
100+
101+
class Language(str, Enum):
102+
EN = "en"
103+
DE = "de"
104+
ES = "es"
105+
FR = "fr"
106+
IT = "it"

daaily/score/client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def re_encode(self, text: str) -> str:
7777
text_io = io.TextIOWrapper(bytes_object, encoding="utf-8-sig")
7878
return text_io.read().strip()
7979

80-
def _grammar_check(self, text: str) -> tuple[float, list[str]]:
80+
def _grammar_check(self, text: str, language_iso: str) -> tuple[float, list[str]]:
8181
"""
8282
Perform a grammar check on the provided text using Google's NL API.
8383
@@ -90,6 +90,7 @@ def _grammar_check(self, text: str) -> tuple[float, list[str]]:
9090
9191
Parameters:
9292
text (str): The text to check for grammar issues.
93+
language_iso (str): The ISO code for the language of the text.
9394
9495
Returns:
9596
tuple[float, list[str]]:
@@ -100,6 +101,7 @@ def _grammar_check(self, text: str) -> tuple[float, list[str]]:
100101
document = language_v1.Document( # type: ignore
101102
content=text,
102103
type_=language_v1.Document.Type.PLAIN_TEXT, # type: ignore
104+
language=language_iso,
103105
)
104106
response = self._lang_client.analyze_syntax(
105107
document=document,

daaily/score/product.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from daaily.lucy.enums import Language
12
from daaily.score.client import Client
23
from daaily.score.constants import PRODUCT_WEIGHTS, TEXT_SIMILARITY_TOPICS
34
from daaily.score.models import (
@@ -202,7 +203,9 @@ def score_text_en(
202203
flesch = round(min(self._calculate_flesch_reading_ease(text_en) / 100, 1), 2)
203204
spelling_score, spelling_errors = self._calculate_spelling_score(text_en)
204205
spelling_score = round(min(spelling_score / 100, 1), 2)
205-
grammar_score, grammar_issues = self._grammar_check(text_en)
206+
grammar_score, grammar_issues = self._grammar_check(
207+
text=text_en, language_iso=Language.EN.value
208+
)
206209
score_result = ScoreResult(
207210
field_name=field_name,
208211
weight=weight,

0 commit comments

Comments
 (0)