Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
woodthom2 committed Jun 5, 2024
1 parent 2d61da7 commit 5d67152
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions src/harmony/matching/negator.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@
'''

import spacy
import re

nlp = spacy.blank("en")



def get_change_en(doc) -> dict:
"""
Identify how to change an English sentence from positive to negative or vice versa.
Expand Down Expand Up @@ -81,15 +79,6 @@ def get_change_pt(doc) -> dict:
return result
return {0: ("insert_before", "não")}

def get_change_fr(doc) -> dict:
"""
Identify how to change a French sentence from positive to negative. Note that negative to positive
is not currently supported.
:param doc:
:return:
"""
return negate_french_sentence(doc)


def get_change_es(doc) -> dict:
"""
Expand All @@ -98,7 +87,8 @@ def get_change_es(doc) -> dict:
:return:
"""
for tok in doc:
if tok.text.lower() in {"siempre", "bastante", "realmente", "muy", "mucho", "totalmente", "totalmente", "absolutamente",
if tok.text.lower() in {"siempre", "bastante", "realmente", "muy", "mucho", "totalmente", "totalmente",
"absolutamente",
"completamente",
"frecuentemente", "frequentemente", "veces"}:
return {tok.i: ("replace", "nunca")}
Expand All @@ -110,28 +100,30 @@ def get_change_es(doc) -> dict:
return {0: ("insert_before", "no")}



def get_change_it(doc) -> dict:
"""
# Team Cheemu: Identify how to change an Italian sentence from positive to negative or vice versa.
:param doc:
:return:
"""
for tok in doc:
if tok.text.lower() in {"sempre", "abbastanza", "realmente", "davvero", "veramente", "molto", "molta", "molti", "molte", "totalmente", "assolutamente",
if tok.text.lower() in {"sempre", "abbastanza", "realmente", "davvero", "veramente", "molto", "molta", "molti",
"molte", "totalmente", "assolutamente",
"completamente",
"frequentemente", "qualche volta", "a volte", "ogni tanto"}:
return {tok.i: ("replace", "mai")}
if tok.text.lower() in {"mai", "né", "non", "nessuno", "nulla", "niente"}:
return {tok.i: ("replace", "")}
result = {}
for tok in doc:
if tok.text.lower() in {"è", "sono", "ero", "erano", "avevano", "avevo", "ho avuto", "sono stato", "sono stata", "sono stati", "siamo stati", "sono state"}:
if tok.text.lower() in {"è", "sono", "ero", "erano", "avevano", "avevo", "ho avuto", "sono stato", "sono stata",
"sono stati", "siamo stati", "sono state"}:
result[tok.i] = "insert_before", "non"
if len(result) > 0:
return result
return {0: ("insert_before", "non")}


def get_change_de(doc) -> dict:
"""
# Team Cheemu: Identify how to change a German sentence from positive to negative or vice versa.
Expand All @@ -149,6 +141,8 @@ def get_change_de(doc) -> dict:
if len(result) > 0:
return result
return {0: ("insert_before", "nicht")}


# if we had time: add functionality to handle german word order using Spacy


Expand All @@ -163,7 +157,8 @@ def get_change_fr(doc) -> dict:
"complètement", "plus", "trop de", "plein de",
"souvent", "de temps en temps"}:
return {tok.i: ("replace", "nie")}
if tok.text.lower() in {"personne", "jamais", "ni", "rien", "pas", "non", "ne", "n'", "nulle", "aucun", "aucune", "guère"}:
if tok.text.lower() in {"personne", "jamais", "ni", "rien", "pas", "non", "ne", "n'", "nulle", "aucun",
"aucune", "guère"}:
return {tok.i: ("replace", "")}
result = {}
if len(result) > 0:
Expand Down Expand Up @@ -207,4 +202,4 @@ def negate(text: str, language: str) -> str:
elif change_operation == "insert_before":
this_token_text = change_text + " " + this_token_text
text += this_token_text + tok.whitespace_
return text
return text

0 comments on commit 5d67152

Please sign in to comment.