Ejemplo n.º 1
0
def main():
    parser = utils.arg_parser()
    parser.add_argument('-v',
                        '--version',
                        action='version',
                        version=('artext %s' % __version__))
    args = parser.parse_args()

    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)

    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)))
Ejemplo n.º 2
0
def test_noise_document(benchmark):
    from artext import config, Artext
    conf = config.Config()
    artxt = Artext(config=conf)

    doc = "I went to Iceland for vacation. The top of the mountain was very cold."
    noises = benchmark(artxt.noise_document, doc)
    assert noises is not None
    assert len(noises) == conf.samples
Ejemplo n.º 3
0
def test_noise_sentence(benchmark):
    from artext import config, Artext
    conf = config.Config()
    artxt = Artext(config=conf)

    sent = "This person tried to keep an eye on the president while doing his work."
    noises = benchmark(artxt.noise_sentence, sent)
    assert noises is not None
    assert len(noises) == conf.samples
Ejemplo n.º 4
0
    def test_noise_document(self):
        from artext import config, Artext
        conf = config.Config()
        artxt = Artext(config=conf)

        # Document Level
        doc = "I went to Iceland for vacation. The top of the mountain was very cold. Fortunately, I was wearing snowboard gear."
        noises = artxt.noise_document(doc)
        self.assertNotEqual(noises, None)
        self.assertEqual(len(noises), conf.samples)
Ejemplo n.º 5
0
    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)
Ejemplo n.º 6
0
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)))