Beispiel #1
0
 def __init__(self, answer, i):
     Feature.set_type(self, clas)
     Feature.set_name(self, 'Sentence sentiment')
     sentence = answer.sources[i].sentence
     s = sum(map(lambda word: afinn.get(word, 0), [word.lower() for word in tokenize(sentence)]))
     s = float(s) / len(sentence.split())
     Feature.set_value(self, s)
Beispiel #2
0
 def __init__(self, answer, i):
     Feature.set_type(self, clas)
     Feature.set_name(self, 'Question sentiment')
     q = sum(
         map(lambda word: afinn.get(word, 0),
             [word.lower() for word in tokenize(answer.q.text)]))
     q = float(q) / len(answer.q.text.split())
     Feature.set_value(self, q)
Beispiel #3
0
 def __init__(self, answer, i):
     Feature.set_type(self, clas)
     Feature.set_name(self, 'Sentence sentiment')
     sentence = answer.sources[i].sentence
     s = sum(
         map(lambda word: afinn.get(word, 0),
             [word.lower() for word in tokenize(sentence)]))
     s = float(s) / len(sentence.split())
     Feature.set_value(self, s)
Beispiel #4
0
    def predict(self, answer):
        s0 = ' '.join(tokenize(answer.q.text))
        s1 = [' '.join(tokenize(source.sentence)) for source in answer.sources]
        f = [source.features for source in answer.sources]
        r = {
            's0': s0,
            's1': [dict([('text', s1_)] + [
                        (feat.get_type() + feat.get_name(), feat.get_value())
                        for feat in f_
                        ])
                   for s1_, f_ in zip(s1, f)]
        }
        print(r)

        req = urllib2.Request(self.url + 'score')
        req.add_header('Content-Type', 'application/json')
        resp = urllib2.urlopen(req, json.dumps(r))
        rr = json.loads(resp.read())
        print(rr)

        return {'y': rr['score'], 'class': rr['class'], 'rel': rr['rel']}
Beispiel #5
0
    def predict(self, answer):
        s0 = ' '.join(tokenize(answer.q.text))
        s1 = [' '.join(tokenize(source.sentence)) for source in answer.sources]
        f = [source.features for source in answer.sources]
        r = {
            's0':
            s0,
            's1': [
                dict([('text', s1_)] +
                     [(feat.get_type() + feat.get_name(), feat.get_value())
                      for feat in f_]) for s1_, f_ in zip(s1, f)
            ]
        }
        print(r)

        req = urllib2.Request(self.url + 'score')
        req.add_header('Content-Type', 'application/json')
        resp = urllib2.urlopen(req, json.dumps(r))
        rr = json.loads(resp.read())
        print(rr)

        return {'y': rr['score'], 'class': rr['class'], 'rel': rr['rel']}
Beispiel #6
0
 def __init__(self, answer, i):
     Feature.set_type(self, clas)
     Feature.set_name(self, 'Question sentiment')
     q = sum(map(lambda word: afinn.get(word, 0), [word.lower() for word in tokenize(answer.q.text)]))
     q = float(q) / len(answer.q.text.split())
     Feature.set_value(self, q)