Example #1
0
    def create_topic_distribution(self, topic_model, input_data=None,
                                  args=None, wait_time=3, retries=10):
        """Creates a new topic distribution.

        """
        topic_model_id = get_topic_model_id(topic_model)
        if topic_model_id is not None:
            check_resource(topic_model_id,
                           query_string=TINY_RESOURCE,
                           wait_time=wait_time, retries=retries,
                           raise_on_error=True, api=self)
        else:
            resource_type = get_resource_type(topic_model)
            raise Exception("A topic model id is needed to create a"
                            " topic distribution. %s found." % resource_type)

        if input_data is None:
            input_data = {}
        create_args = {}
        if args is not None:
            create_args.update(args)
        create_args.update({
            "input_data": input_data,
            "topicmodel": topic_model_id})

        body = json.dumps(create_args)
        return self._create(self.topic_distribution_url, body,
                            verify=self.verify_prediction)
Example #2
0
    def get_topic_model(self,
                        topic_model,
                        query_string='',
                        shared_username=None,
                        shared_api_key=None):
        """Retrieves a Topic Model.

           The topic_model parameter should be a string containing the
           topic model ID or the dict returned by create_topic_model.
           As the topic model is an evolving object that is processed
           until it reaches the FINISHED or FAULTY state, the function will
           return a dict that encloses the topic model values and state info
           available at the time it is called.

           If this is a shared topic model, the username and sharing api key
           must also be provided.
        """
        check_resource_type(topic_model,
                            TOPIC_MODEL_PATH,
                            message="A Topic Model id is needed.")
        topic_model_id = get_topic_model_id(topic_model)
        if topic_model_id:
            return self._get("%s%s" % (self.url, topic_model_id),
                             query_string=query_string,
                             shared_username=shared_username,
                             shared_api_key=shared_api_key)
Example #3
0
    def delete_topic_model(self, topic_model):
        """Deletes a Topic Model.

        """
        check_resource_type(topic_model, TOPIC_MODEL_PATH,
                            message="A topic model id is needed.")
        topic_model_id = get_topic_model_id(topic_model)
        if topic_model_id:
            return self._delete("%s%s" % (self.url, topic_model_id))
    def delete_topic_model(self, topic_model):
        """Deletes a Topic Model.

        """
        check_resource_type(topic_model, TOPIC_MODEL_PATH,
                            message="A topic model id is needed.")
        topic_model_id = get_topic_model_id(topic_model)
        if topic_model_id:
            return self._delete("%s%s" % (self.url, topic_model_id))
Example #5
0
    def update_topic_model(self, topic_model, changes):
        """Updates a Topic Model.

        """
        check_resource_type(topic_model, TOPIC_MODEL_PATH,
                            message="A topic model id is needed.")
        topic_model_id = get_topic_model_id(topic_model)
        if topic_model_id:
            body = json.dumps(changes)
            return self._update("%s%s" % (self.url, topic_model_id), body)
    def update_topic_model(self, topic_model, changes):
        """Updates a Topic Model.

        """
        check_resource_type(topic_model, TOPIC_MODEL_PATH,
                            message="A topic model id is needed.")
        topic_model_id = get_topic_model_id(topic_model)
        if topic_model_id:
            body = json.dumps(changes)
            return self._update("%s%s" % (self.url, topic_model_id), body)
Example #7
0
    def get_topic_model(self, topic_model, query_string='',
                        shared_username=None, shared_api_key=None):
        """Retrieves a Topic Model.

           The topic_model parameter should be a string containing the
           topic model ID or the dict returned by create_topic_model.
           As the topic model is an evolving object that is processed
           until it reaches the FINISHED or FAULTY state, the function will
           return a dict that encloses the topic model values and state info
           available at the time it is called.

           If this is a shared topic model, the username and sharing api key
           must also be provided.
        """
        check_resource_type(topic_model, TOPIC_MODEL_PATH,
                            message="A Topic Model id is needed.")
        topic_model_id = get_topic_model_id(topic_model)
        if topic_model_id:
            return self._get("%s%s" % (self.url, topic_model_id),
                             query_string=query_string,
                             shared_username=shared_username,
                             shared_api_key=shared_api_key)
    def create_topic_distribution(self,
                                  topic_model,
                                  input_data=None,
                                  args=None,
                                  wait_time=3,
                                  retries=10):
        """Creates a new topic distribution.

        """
        topic_model_id = get_topic_model_id(topic_model)
        if topic_model_id is not None:
            check_resource(topic_model_id,
                           query_string=TINY_RESOURCE,
                           wait_time=wait_time,
                           retries=retries,
                           raise_on_error=True,
                           api=self)
        else:
            resource_type = get_resource_type(topic_model)
            raise Exception("A topic model id is needed to create a"
                            " topic distribution. %s found." % resource_type)

        if input_data is None:
            input_data = {}
        create_args = {}
        if args is not None:
            create_args.update(args)
        create_args.update({
            "input_data": input_data,
            "topicmodel": topic_model_id
        })

        body = json.dumps(create_args)
        return self._create(self.topic_distribution_url,
                            body,
                            verify=self.verify_prediction)