Datasets:
File size: 1,028 Bytes
70954e8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
"""
Run through language tool, to get some hints.
"""
import logging
import langid
import language_tool_python
LOG = logging.getLogger(__name__)
def test_report_language_tool_warnings(lyrics):
lyrics_by_language = {}
for lyric, file in lyrics:
lang = langid.classify(lyric)[0]
if lang in {"en", "fr", "es", "de"}:
lyrics_by_language.setdefault(lang, []).append((lyric, file))
else:
LOG.warning(
f'Failed to correctly identify language of {file}. Guessed "{lang}". Skipping.'
)
for lang, lyrics_list in lyrics_by_language.items():
LOG.info(f'Checking lyrics in "{lang}" with language tool.')
tool = language_tool_python.LanguageTool(
lang, config={"disabledRuleIds": "GONNA,OUTTA,WANNA,GOTTA,Y_ALL"}
)
try:
for lyric, file in lyrics_list:
for match in tool.check(lyric):
LOG.warning(f"{file}: {match}")
finally:
tool.close()
|