import piglatin

from interfaces.SentenceOperation import SentenceOperation
from tasks.TaskTypes import TaskType

class PigLatin(SentenceOperation):
    tasks = [
        TaskType.TEXT_CLASSIFICATION,
        TaskType.TEXT_TO_TEXT_GENERATION,
        TaskType.TEXT_TAGGING,
    ]
    languages = ["en"]

    def __init__(self, seed=0, max_outputs=1):
        super().__init__(seed, max_outputs=max_outputs)

    def generate(self, sentence: str):
        output_sentence = piglatin.translate(sentence.lower())
        piglatin_sentence = []
        for word in output_sentence.split():
            piglatin_sentence.append(word.replace('-', ''))
        piglatin_sentence = ' '.join(piglatin_sentence)
        return [piglatin_sentence]

@@ -8,16 +8,30 @@
 piglatin
+%0Aimport random
 %0A%0Afrom i
@@ -355,16 +355,34 @@
 utputs=1
+, replace_prob=1.0
 ):%0A     
@@ -431,16 +431,57 @@
 outputs)
+%0A        self.replace_prob = replace_prob
 %0A%0A    de
@@ -521,22 +521,24 @@
         
-output
+piglatin
 _sentenc
@@ -542,48 +542,61 @@
 ence
+s
  = 
-piglatin.translate(sentence.lower())%0A
+%5B%5D%0A        for _ in range(self.max_outputs):%0A    
     
@@ -626,24 +626,28 @@
  %5B%5D%0A        
+    
 for word in 
@@ -650,15 +650,8 @@
  in 
-output_
 sent
@@ -655,16 +655,24 @@
 entence.
+lower().
 split():
@@ -672,16 +672,190 @@
 plit():%0A
+                if random.random() %3C self.replace_prob:%0A                    new_word = piglatin.translate(word)%0A                else:%0A                    new_word = word%0A    
         
@@ -883,16 +883,20 @@
 .append(
+new_
 word.rep
@@ -910,16 +910,20 @@
 ', ''))%0A
+    
         
@@ -970,16 +970,73 @@
 ntence)%0A
+            piglatin_sentences.append(piglatin_sentence)%0A
         
@@ -1042,17 +1042,16 @@
  return 
-%5B
 piglatin
@@ -1059,10 +1059,10 @@
 sentence
-%5D
+s
 %0A

Add per-word replace probability, max outputs.