def test_noise_sentence(self): from artext import config, Artext conf = config.Config() artxt = Artext(config=conf) # Sentence Level sent = "This person tried to keep an eye on the president while doing his work." noises = artxt.noise_sentence(sent) self.assertNotEqual(noises, None) self.assertEqual(len(noises), conf.samples)
from artext import config, utils, Artext if __name__ == "__main__": parser = utils.arg_parser() args = parser.parse_args() conf = config.Config() conf.error_rate = args.error_rate conf.path_protected_tokens = args.protected_tokens conf.samples = args.samples artxt = Artext(config=conf) with open(args.source, 'r') as fin, open(args.output, 'w') as fout: if args.level == 'sent': for line in fin: noises = artxt.noise_sentence(line) fout.write("{}\n".format(args.separator.join(noises))) elif args.level == 'doc': for line in fin: noises = artxt.noise_document(line) fout.write("{}\n".format(args.separator.join(noises)))
conf = config.Config() conf.error_rate = args.error_rate conf.path_protected_tokens = args.protected_tokens conf.samples = args.samples conf.separator = args.separator artxt = Artext(config=conf) # Sentence Level print('Sentence Level') sent = "So, I think if we have to go somewhere on foot, we must put on our hat." learner = "So, I think if we have to go somewhere on foot, we must put our hat." print('Input (Lang-8 target):\n{}\n'.format(sent)) print('Human (Lang-8 source):\n{}\n'.format(learner)) noises = artxt.noise_sentence(sent) print('Artext:') for noise in noises: print('-', noise) # Document Level print('\nDocument Level') doc = """This morning I found out that one of my favourite bands released a new album. I already forgot about Rise Against and it is a great surprise for me, because I haven't listened to them for 2 years. I hope this band didn't become worse, like many others big ones did, and I 'll enjoy listening to it. Well, I just have to get it and check it out.""" learner = """This morning I found out that one of my favourite band released his new album. I already forgot about Rise Against an it is a great surprise for me, because I didn't return to them for 2 years. I hope this band did n't become worse yet like many others big ones and I'll enjoy listening it. Well , there remains to get it and check it out."""