Beispiel #1
0
 def test_clear_sentences3(self):
     s = [
         Sentence(
             'snowboarding is harder to learn but easier to master than skiing',
             20, '', '')
     ]
     s = clear_sentences(s, self.objA, self.objB)
     self.assertFalse(s)
Beispiel #2
0
 def test_clear_sentences2(self):
     s = [
         Sentence('Dog is worse than cat', 20, '', ''),
         Sentence('Dog didn\'t look better than cat', 20, '', '')
     ]
     s = clear_sentences(s, self.objA, self.objB)
     self.assertTrue('Dog didn\'t look better than cat' in
                     [sentence.text for sentence in s])
Beispiel #3
0
 def test_clear_sentences9(self):
     obj_a = Argument('coca-cola light')
     obj_b = Argument('pepsi light')
     s = [
         Sentence('Coca Cola™ light tastes better than Pepsi™ light', 20,
                  '', '')
     ]
     s = clear_sentences(s, obj_a, obj_b)
     self.assertTrue(s)
Beispiel #4
0
 def test_clear_sentences5(self):
     s = [
         Sentence('Cat and dog work well together', 10, '', ''),
         Sentence('Cat are worse than dog', 20, '', '')
     ]
     s = clear_sentences(s, self.objA, self.objB)
     self.assertFalse('Cats and dogs work well together' in
                      [sentence.text for sentence in s])
     self.assertTrue(s)
Beispiel #5
0
 def test_clear_sentences4(self):
     s = [
         Sentence('A better cat is still no dog', 20, '', ''),
         Sentence('Cat are worse than dog', 20, '', '')
     ]
     s = clear_sentences(s, self.objA, self.objB)
     self.assertFalse('A better cat is still no dog' in
                      [sentence.text for sentence in s])
     self.assertTrue(s)
Beispiel #6
0
 def test_clear_sentences6(self):
     s = [
         Sentence('Cat is worse than dog', 10, '', ''),
         Sentence(
             'Cat are more beautiful, but are harder to raise than dog', 20,
             '', '')
     ]
     s = clear_sentences(s, self.objA, self.objB)
     self.assertFalse('Cat are wiser, but are harder to raise than dog' in
                      [sentence.text for sentence in s])
     self.assertTrue(s)
Beispiel #7
0
def cam():
    '''
    to be visited after a user clicked the 'compare' button.
    '''
    load_config()

    fast_search = request.args.get('fs')
    obj_a = Argument(request.args.get('objectA').lower().strip())
    obj_b = Argument(request.args.get('objectB').lower().strip())
    aspects = extract_aspects(request)
    model = request.args.get('model')
    statusID = request.args.get('statusID')

    if model == 'default' or model is None:
        # json obj with all ES hits containing obj_a, obj_b and a marker.
        setStatus(statusID, 'Request ES')
        json_compl = request_es(fast_search, obj_a, obj_b)

        # list of all sentences containing obj_a, obj_b and a marker.
        setStatus(statusID, 'Extract sentences')
        all_sentences = extract_sentences(json_compl)

        # removing sentences that can't be properly analyzed
        setStatus(statusID, 'Clear sentences')
        all_sentences = clear_sentences(all_sentences, obj_a, obj_b)

        # find the winner of the two objects
        setStatus(statusID, 'Find winner')
        return jsonify(find_winner(all_sentences, obj_a, obj_b, aspects))

    else:
        setStatus(statusID, 'Request all sentences containing the objects')
        if aspects:
            json_compl_triples = request_es_triple(obj_a, obj_b, aspects)
        json_compl = request_es_ML(fast_search, obj_a, obj_b)

        setStatus(statusID, 'Extract sentences')
        if aspects:
            all_sentences = extract_sentences(json_compl_triples)
            all_sentences.extend([
                sentence for sentence in extract_sentences(json_compl)
                if sentence.text not in
                [sentence.text for sentence in all_sentences]
            ])
        else:
            all_sentences = extract_sentences(json_compl)

        if len(all_sentences) == 0:
            return jsonify(find_winner(all_sentences, obj_a, obj_b, aspects))

        remove_questions(all_sentences)

        setStatus(statusID, 'Prepare sentences for classification')
        prepared_sentences = prepare_sentence_DF(all_sentences, obj_a, obj_b)

        setStatus(statusID, 'Classify sentences')
        classification_results = classify_sentences(prepared_sentences, model)

        setStatus(statusID, 'Evaluate classified sentences; Find winner')
        final_dict = evaluate(all_sentences, prepared_sentences,
                              classification_results, obj_a, obj_b, aspects)

        return jsonify(final_dict)
Beispiel #8
0
 def test_clear_sentences1(self):
     s = [Sentence('Dog is worse than cat?', 20, '', '')]
     s = clear_sentences(s, self.objA, self.objB)
     self.assertFalse(s)