Esempio n. 1
0
 def test_store_triples(self):
     from amcat.models.token import TripleValues
     aa = amcattest.create_test_analysis_article()
     t1 = amcattest.create_tokenvalue(analysis_article=aa)
     t2 = amcattest.create_tokenvalue(
         analysis_sentence=t1.analysis_sentence, word="x")
     tr = TripleValues(t1.analysis_sentence,
                       parent=t1.position,
                       child=t2.position,
                       relation='su')
     aa.store_analysis(tokens=[t1, t2], triples=[tr])
     aa = AnalysisArticle.objects.get(pk=aa.id)
     triple, = list(
         Triple.objects.filter(parent__sentence__analysis_article=aa))
     self.assertEqual(triple.parent.word.word, t1.word)
     self.assertEqual(triple.child.word.lemma.lemma, t2.lemma)
Esempio n. 2
0
def profile_store_triples():
    transaction.enter_transaction_management()
    transaction.managed(True)
    try:
        aa = amcattest.create_test_analysis_article()
        log.info("Created test article %i" % aa.id)
        tokens = []
        for s in range(5):
            log.info("Creating test sentence %i" % s)
            s = amcattest.create_test_analysis_sentence(aa)
            log.info("Created test sentence %i" % s.id)

            tokens += [
                amcattest.create_tokenvalue(analysis_sentence=s.id,
                                            word=w,
                                            lemma=w) for w in "123456789" * 3
            ]
        log.info("Storing %i tokens" % len(tokens))
        with djangotoolkit.list_queries() as queries:
            aa.store_analysis(tokens=tokens)
        djangotoolkit.query_list_to_table(queries,
                                          maxqlen=150,
                                          output=print,
                                          encoding="utf-8")
    finally:
        transaction.rollback()
        transaction.leave_transaction_management()
Esempio n. 3
0
 def test_store_triples(self):
     aa = amcattest.create_test_analysis_article()
     t1 = amcattest.create_tokenvalue(analysis_article=aa)
     t2 = amcattest.create_tokenvalue(
         analysis_sentence=t1.analysis_sentence, word="x")
     tr = TripleValues(t1.analysis_sentence,
                       parent=t1.position,
                       child=t2.position,
                       relation='su')
     AddTokens(analysisarticle=aa.id,
               tokens=json.dumps([t1, t2]),
               triples=json.dumps([tr])).run()
     aa = AnalysisArticle.objects.get(pk=aa.id)
     triple, = list(
         Triple.objects.filter(parent__sentence__analysis_article=aa))
     self.assertEqual(triple.parent.word.word, t1.word)
     self.assertEqual(triple.child.word.lemma.lemma, t2.lemma)
Esempio n. 4
0
 def test_store_tokens(self):
     s = amcattest.create_test_analysis_sentence()
     t1 = amcattest.create_tokenvalue(analysis_sentence=s)
     s.analysis_article.store_analysis(tokens=[t1])
     aa = AnalysisArticle.objects.get(pk=s.analysis_article.id)
     self.assertEqual(aa.done, True)
     token, = list(Token.objects.filter(sentence__analysis_article=aa))
     self.assertEqual(token.word.word, t1.word)
     self.assertRaises(aa.store_analysis, tokens=[t1])
Esempio n. 5
0
 def test_store_tokens(self):
     aa = amcattest.create_test_analysis_article()
     t1 = amcattest.create_tokenvalue(analysis_article=aa)
     AddTokens(analysisarticle=aa.id, tokens=json.dumps([t1])).run()
     aa = AnalysisArticle.objects.get(pk=aa.id)
     self.assertEqual(aa.done, True)
     token, = list(Token.objects.filter(sentence__analysis_article=aa))
     self.assertEqual(token.word.word, t1.word)
     self.assertRaises(aa.store_analysis, tokens=[t1])
     with self.assertRaises(Exception):
         AddTokens(analysisarticle=aa.id, tokens=json.dumps([t1])).run()
Esempio n. 6
0
def profile_store_triples():
    transaction.enter_transaction_management()
    transaction.managed(True)
    try:
        aa = amcattest.create_test_analysis_article()
        log.info("Created test article %i" % aa.id)
        tokens = []
        for s in range(5):
            log.info("Creating test sentence %i" % s)
            s = amcattest.create_test_analysis_sentence(aa)
            log.info("Created test sentence %i" % s.id)

            tokens += [amcattest.create_tokenvalue(analysis_sentence=s.id, word=w, lemma=w) for w in "123456789"*3]
        log.info("Storing %i tokens" % len(tokens))
        with djangotoolkit.list_queries() as queries:
            aa.store_analysis(tokens=tokens)
        djangotoolkit.query_list_to_table(queries, maxqlen=150, output=print, encoding="utf-8")
    finally:
        transaction.rollback()
        transaction.leave_transaction_management()