Esempio n. 1
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)
Esempio n. 2
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)
Esempio n. 3
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
Esempio n. 4
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
Esempio n. 5
0
    log = APIAccessLog(key=key, ip=g.last_ip, input=input, output=output)
    log.save()


# All APIs


# artext
@app.route('/artext')
def artext_view():
    return render_template('api_artext.html')


from artext import Artext

artxt = Artext()
artxt.samples = 10
artxt.error_overall = 0.25


@app.route('/api/artext/noise', methods=['POST'])
def api_artext():
    data = request.get_json()
    doc = data['input']
    noises = artxt.noise_document(doc)
    output = '\n'.join(noises)

    log_api_access('artext', input=doc, output=output)
    response = jsonify({'input': doc, 'output': output})
    return response
Esempio 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)))
Esempio n. 7
0
import sys
from artext import config, utils, Artext

if __name__ == "__main__":
    parser = utils.arg_parser()
    args = parser.parse_args('-src test -out test -n 5'.split() + sys.argv[1:])

    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.