from .base_tests import OutputTuple, InputTuple, TestPromptPostProcessorBase if __name__ == "__main__": raise SystemExit("This script must not be run directly") class TestSendToNegative(TestPromptPostProcessorBase): def setUp(self): # pylint: disable=arguments-differ super().setUp(enable_file_logging=False) # Send To Negative tests def test_stn_simple(self): # negtags with different parameters and separations self.process( InputTuple( "flowersred, green, blueyellow, purpleblack", "normal quality, worse quality", ), OutputTuple("flowers", "red, green, yellow, normal quality, purple, worse quality, black, blue"), ) def test_stn_complex(self): # complex negtags self.process( InputTuple( "red ((pink)), flowers purple, mauveblue, yellow green", "normal quality, , bad quality, worse quality", ), OutputTuple( "flowers", "red, (pink:1.21), normal quality, mauve, yellow, bad quality, green, worse quality, purple, blue", ), ) def test_stn_complex_nocleanup(self): # complex negtags with no cleanup self.process( InputTuple( "red ((pink)), flowers purple, mauveblue, yellow green", "normal quality, , bad quality, worse quality", ), OutputTuple( " (()), flowers , , ", "red, ((pink)), normal quality, mauve, yellow, bad quality, green, worse quality, purple, blue", ), ppp="nocup", ) def test_stn_inside_attention(self): # negtag inside attention self.process( InputTuple( "[neg1] this is a ((testneg2) (test:2.0): 1.5 ) (red[square]:1.5)", "normal quality", ), OutputTuple( "this is a ((test) (test:2):1.5) (red:1.5)", "[neg1], (square:1.35), normal quality, (neg2:1.65)" ), ) def test_stn_inside_alternation(self): # negtag inside alternation self.process( InputTuple( "this is a (([complexneg1|simpleneg2|regularneg3] test)(test:2.0):1.5)", "normal quality", ), OutputTuple( "this is a (([complex|simple|regular] test)(test:2):1.5)", "([neg1||]:1.65), ([|neg2|]:1.65), ([||neg3]:1.65), normal quality", ), ) def test_stn_inside_alternation_recursive(self): # negtag inside alternation (recursive alternation) self.process( InputTuple( "this is a (([complexneg1[one|twoneg12||three|four(neg14)]|simpleneg2|regularneg3] test)(test:2.0):1.5)", "normal quality", ), OutputTuple( "this is a (([complex[one|two||three|four]|simple|regular] test)(test:2):1.5)", "([neg1||]:1.65), ([[|neg12|||]||]:1.65), ([[||||(neg14)]||]:1.65), ([|neg2|]:1.65), ([||neg3]:1.65), normal quality", ), ) def test_stn_inside_scheduling(self): # negtag inside scheduling self.process( InputTuple("this is [abcneg1:defneg2: 5 ]", "normal quality"), OutputTuple("this is [abc:def:5]", "[neg1::5], normal quality, [neg2:5]"), ) def test_stn_complex_features(self): # complex negtags with AND, BREAK and other features self.process( InputTuple( "[neg5] this \\(is\\): a (([complex|simpleneg6|regular] testneg1)(test:2.0):1.5) \nBREAK, BREAK with [abcneg4:defneg2(neg3:1.6):5]:0.5 AND loratrigger AND AND hypernettrigger :0.3", "normal quality, ", ), OutputTuple( "this \\(is\\): a (([complex|simple|regular] test)(test:2):1.5)\nBREAK with [abc:def:5]:0.5 AND loratrigger AND hypernettrigger :0.3", "[neg5], ([|neg6|]:1.65), (neg1:1.65), [neg4::5], normal quality, [neg2(neg3:1.6):5]", ), ) def test_stn_complex_features_newformat(self): # complex negtags with AND, BREAK and other features (new format) self.process( InputTuple( "[neg5] this \\(is\\): a (([complex|simpleneg6|regular] testneg1)(test:2.0):1.5) \nBREAK, BREAK with [abcneg4:defneg2(neg3:1.6):5]:0.5 AND loratrigger AND AND hypernettrigger :0.3", "normal quality, ", ), OutputTuple( "this \\(is\\): a (([complex|simple|regular] test)(test:2):1.5)\nBREAK with [abc:def:5]:0.5 AND loratrigger AND hypernettrigger :0.3", "[neg5], ([|neg6|]:1.65), (neg1:1.65), [neg4::5], normal quality, [neg2(neg3:1.6):5]", ), ) def test_stn_inside_alternation_recursive_2(self): # negtag inside alternation (recursive alternation) self.process( InputTuple( "[pos1neg1[pos11|pos12neg12||pos14|pos15neg15]|pos2neg2|pos3neg3]", "", ), OutputTuple( "[pos1[pos11|pos12||pos14|pos15]|pos2|pos3]", "[neg1||], [[|neg12|||]||], [[||||neg15]||], [|neg2|], [||neg3]", # "[neg1[|neg12|||neg15]|neg2|neg3]", # expected output if the constructs were unified ), )