コード例 #1
0
    def analyse_entry(self, entry, params):
        lang = params["language"]
        res = requests.post(
            ENDPOINT,
            json.dumps({
                "language": lang,
                "data": [{
                    "text": entry['nif:isString']
                }]
            }))
        p = params.get("prefix", None)
        polarity_value = self.maxPolarityValue * int(
            res.json()["data"][0]["polarity"]) * 0.25
        polarity = "marl:Neutral"
        neutral_value = self.maxPolarityValue / 2.0
        if polarity_value > neutral_value:
            polarity = "marl:Positive"
        elif polarity_value < neutral_value:
            polarity = "marl:Negative"

        sentiment = Sentiment(prefix=p,
                              marl__hasPolarity=polarity,
                              marl__polarityValue=polarity_value)
        sentiment.prov__wasGeneratedBy = self.id
        entry.sentiments.append(sentiment)
        entry.language = lang
        yield entry
コード例 #2
0
    def analyse(self, **params):
        lang = params.get("language", "auto")
        res = requests.post(
            "http://www.sentiment140.com/api/bulkClassifyJson",
            json.dumps({
                "language": lang,
                "data": [{
                    "text": params["input"]
                }]
            }))

        p = params.get("prefix", None)
        response = Results(prefix=p)
        polarity_value = self.maxPolarityValue * int(
            res.json()["data"][0]["polarity"]) * 0.25
        polarity = "marl:Neutral"
        neutral_value = self.maxPolarityValue / 2.0
        if polarity_value > neutral_value:
            polarity = "marl:Positive"
        elif polarity_value < neutral_value:
            polarity = "marl:Negative"

        entry = Entry(id="Entry0", nif__isString=params["input"])
        sentiment = Sentiment(id="Sentiment0",
                              prefix=p,
                              marl__hasPolarity=polarity,
                              marl__polarityValue=polarity_value)
        sentiment.prov__wasGeneratedBy = self.id
        entry.sentiments = []
        entry.sentiments.append(sentiment)
        entry.language = lang
        response.entries.append(entry)
        return response
コード例 #3
0
ファイル: sentiment140.py プロジェクト: anukat2015/senpy
    def analyse(self, **params):
        lang = params.get("language", "auto")
        res = requests.post("http://www.sentiment140.com/api/bulkClassifyJson",
                            json.dumps({"language": lang,
                                        "data": [{"text": params["input"]}]
                                        }
                                       )
                            )

        p = params.get("prefix", None)
        response = Results(prefix=p)
        polarity_value = self.maxPolarityValue*int(res.json()["data"][0]
                                                   ["polarity"]) * 0.25
        polarity = "marl:Neutral"
        neutral_value = self.maxPolarityValue / 2.0
        if polarity_value > neutral_value:
            polarity = "marl:Positive"
        elif polarity_value < neutral_value:
            polarity = "marl:Negative"

        entry = Entry(id="Entry0",
                      nif__isString=params["input"])
        sentiment = Sentiment(id="Sentiment0",
                            prefix=p,
                            marl__hasPolarity=polarity,
                            marl__polarityValue=polarity_value)
        sentiment.prov__wasGeneratedBy = self.id
        entry.sentiments = []
        entry.sentiments.append(sentiment)
        entry.language = lang
        response.entries.append(entry)
        return response
コード例 #4
0
ファイル: sentiment140.py プロジェクト: MixedEmotions/senpy
    def analyse_entry(self, entry, params):
        lang = params.get("language", "auto")
        res = requests.post("http://www.sentiment140.com/api/bulkClassifyJson",
                            json.dumps({
                                "language": lang,
                                "data": [{
                                    "text": entry.text
                                }]
                            }))
        p = params.get("prefix", None)
        polarity_value = self.maxPolarityValue * int(
            res.json()["data"][0]["polarity"]) * 0.25
        polarity = "marl:Neutral"
        neutral_value = self.maxPolarityValue / 2.0
        if polarity_value > neutral_value:
            polarity = "marl:Positive"
        elif polarity_value < neutral_value:
            polarity = "marl:Negative"

        sentiment = Sentiment(
            prefix=p,
            marl__hasPolarity=polarity,
            marl__polarityValue=polarity_value)
        sentiment.prov__wasGeneratedBy = self.id
        entry.sentiments = []
        entry.sentiments.append(sentiment)
        entry.language = lang
        yield entry
コード例 #5
0
ファイル: sentiment140.py プロジェクト: ddwell/senpy
    def analyse_entry(self, entry, params):
        lang = params.get("language", "auto")
        res = requests.post(
            "http://www.sentiment140.com/api/bulkClassifyJson",
            json.dumps({
                "language": lang,
                "data": [{
                    "text": entry.text
                }]
            }))
        p = params.get("prefix", None)
        polarity_value = self.maxPolarityValue * int(
            res.json()["data"][0]["polarity"]) * 0.25
        polarity = "marl:Neutral"
        neutral_value = self.maxPolarityValue / 2.0
        if polarity_value > neutral_value:
            polarity = "marl:Positive"
        elif polarity_value < neutral_value:
            polarity = "marl:Negative"

        sentiment = Sentiment(prefix=p,
                              marl__hasPolarity=polarity,
                              marl__polarityValue=polarity_value)
        sentiment.prov__wasGeneratedBy = self.id
        entry.sentiments = []
        entry.sentiments.append(sentiment)
        entry.language = lang
        yield entry
コード例 #6
0
ファイル: test_models.py プロジェクト: gsi-upm/senpy
 def test_sentiment(self):
     s = Sentiment()
     self.assertRaises(jsonschema.ValidationError, s.validate)
     s.nif__anchorOf = "so much testing"
     s.prov__wasGeneratedBy = ""
     s.validate()
コード例 #7
0
ファイル: test_models.py プロジェクト: Shasthojoy/senpy
 def test_sentiment(self):
     s = Sentiment()
     self.assertRaises(jsonschema.ValidationError, s.validate)
     s.nif__anchorOf = "so much testing"
     s.prov__wasGeneratedBy = ""
     s.validate()