예제 #1
0
    def score_text(self, text):
        """
        Sends text to the server for sentiment scoring
        Returns a list of scores (one for each sentence)
        """
        service = self._text_service
        try:
            msg = Message(text)
            sentiment_scores = post_json(self._text_service, msg.to_JSON())
            return sentiment_scores["scores"]

        except Exception as e:
            #print(e)
            return None
예제 #2
0
    def score_document(self, doc):
        """
        Sends a Document to the server for sentiment scoring.

        Parameters
        ----------
        doc : processors.ds.Document
            The `doc` to be scored

        Returns
        -------
        [int]
            A list of int scores (one for each sentence) ranging from 1 (very negative) to 5 (very positive)

        """
        try:
            sentiment_scores = post_json(self._document_service, doc.to_JSON())
            return sentiment_scores["scores"]

        except Exception as e:
            #print(e)
            return None
예제 #3
0
    def score_sentence(self, sentence):
        """
        Sends a Sentence to the server for sentiment scoring.

        Parameters
        ----------
        sentence : processors.ds.Sentence
            The `sentence` to be scored

        Returns
        -------
        int
            A single score ranging from 1 (very negative) to 5 (very positive)

        """
        try:
            sentiment_scores = post_json(self._sentence_service,
                                         sentence.to_JSON())
            return sentiment_scores["scores"][0]

        except Exception as e:
            print(e)
            return None
예제 #4
0
    def score_segmented_text(self, sentences):
        """
        Sends segmented text to the server for sentiment scoring.

        Parameters
        ----------
        sentences : [str]
            A list of str representing segmented sentences/chunks to be scored.

        Returns
        -------
        [int]
            A list of int scores (one for each sentence/chunk) ranging from 1 (very negative) to 5 (very positive)

        """
        try:
            msg = SegmentedMessage(sentences)
            sentiment_scores = post_json(self._segmented_service,
                                         msg.to_JSON())
            return sentiment_scores["scores"]

        except Exception as e:
            #print(e)
            return None
예제 #5
0
 def _annotate_message(self, msg):
     annotated_text = post_json(self.service, msg.to_JSON())
     return Document.load_from_JSON(annotated_text)
예제 #6
0
 def _message_to_json_dict(self, msg):
     return post_json(self.service, msg.to_JSON())
예제 #7
0
 def _chunk(self, obj):
     return post_json(self.chunk_address, obj.to_JSON())