Exemplo n.º 1
0
    def test_paa(self):
        order = 'Execute paa on timeserie at 5 points'

        data = response(self, order)
        self.assertEqual(data['queryResult']['intent']['displayName'], 'DoDimensionality')
        self.assertGreater(data['queryResult']['intentDetectionConfidence'], 0.85)
        self.assertEqual(data['queryResult']['parameters']['operation'], 'paa')
        self.assertEqual(data['queryResult']['parameters']['Dataset'], 'timeserie')
        self.assertEqual(data['queryResult']['parameters']['number'], 5)

        tt = pd.DataFrame([0, 0.1, -0.1, 5.0, 6.0, 7.0, 8.1, 9.0, 9.0, 9.0])
        self.workspace.save_dataset('timeserie', tt)
        al.do_dimensionality(data['queryResult']['parameters'])
        paa_result = al.Workspace().get_dataset("paa0")
        val = paa_result.values
        expected = [0.05, 2.45, 6.5, 8.55, 9.0]
        for i in range(len(expected)):
            self.assertAlmostEqual(val[i], expected[i], delta=self.DELTA)
Exemplo n.º 2
0
    def test_visvalingam(self):
        order = 'Execute visvalingam on timeserie at 5 points'

        data = response(self, order)
        self.assertEqual(data['queryResult']['intent']['displayName'], 'DoDimensionality')
        self.assertGreater(data['queryResult']['intentDetectionConfidence'], 0.85)
        self.assertEqual(data['queryResult']['parameters']['operation'], 'visvalingam')
        self.assertEqual(data['queryResult']['parameters']['Dataset'], 'timeserie')
        self.assertEqual(data['queryResult']['parameters']['number'], 5)

        tt = pd.DataFrame([0, 0.1, -0.1, 5.0, 6.0, 7.0, 8.1, 9.0, 9.0, 9.0])
        self.workspace.save_dataset('timeserie', tt)
        al.do_dimensionality(data['queryResult']['parameters'])
        visvalingam_result = al.Workspace().get_dataset("visvalingam0")
        ind = visvalingam_result.index.to_list()
        val = visvalingam_result.values
        expected = [[0, 2, 3, 6, 9], [0, -0.1, 5.0, 9.0, 9.0]]
        for i in range(len(expected)):
            self.assertAlmostEqual(ind[i], expected[0][i], delta=self.DELTA)
            self.assertAlmostEqual(val[i], expected[1][i], delta=self.DELTA)
Exemplo n.º 3
0
    def test_ramer_douglas_peucker(self):
        order = 'Execute ramerDouglasPeucker on timeserie with an epsilon of 1.0'

        data = response(self, order)
        self.assertEqual(data['queryResult']['intent']['displayName'], 'DoDimensionality')
        self.assertGreater(data['queryResult']['intentDetectionConfidence'], 0.85)
        self.assertEqual(data['queryResult']['parameters']['operation'], 'ramer_douglas_peucker')
        self.assertEqual(data['queryResult']['parameters']['Dataset'], 'timeserie')
        self.assertEqual(data['queryResult']['parameters']['number'], 1.0)

        tt = pd.DataFrame([0, 0.1, -0.1, 5.0, 6.0, 7.0, 8.1, 9.0, 9.0, 9.0])
        self.workspace.save_dataset('timeserie', tt)
        al.do_dimensionality(data['queryResult']['parameters'])
        ramer_douglas_peucker_result = al.Workspace().get_dataset("RDP0")
        ind = ramer_douglas_peucker_result.index.to_list()
        val = ramer_douglas_peucker_result.values
        expected = [[0, 2, 3, 6, 9], [0, -0.1, 5.0, 8.1, 9.0]]
        for i in range(len(expected)):
            self.assertAlmostEqual(ind[i], expected[0][i], delta=self.DELTA)
            self.assertAlmostEqual(val[i], expected[1][i], delta=self.DELTA)
Exemplo n.º 4
0
def detect_intent_text(project_id, session_id, text, language_code):
    """
    Detects the intent of the text and execute some instruction

    Using the same `session_id` between requests allows continuation of the conversation.

    :param project_id: ID of the project
    :param session_id: ID of the session
    :param text: The text input for analyse
    :param language_code: Code of the language
    """

    session_client = dialogflow.SessionsClient()

    session = session_client.session_path(project_id, session_id)
    print('Session path: {}\n'.format(session))

    text_input = dialogflow.types.TextInput(text=text, language_code=language_code)

    query_input = dialogflow.types.QueryInput(text=text_input)

    response = session_client.detect_intent(session=session, query_input=query_input)

    """Conversion of Protocol Buffer to JSON"""
    response_json = pbjson.MessageToJson(response)
    data = json.loads(response_json)
    parameters = data['queryResult']['parameters']
    print(parameters)

    print('=' * 20)
    print('DEBUG: Query text: {}'.format(response.query_result.query_text))
    print('DEBUG: Detected intent: {} (confidence: {})\n'.format(
        response.query_result.intent.display_name,
        response.query_result.intent_detection_confidence))
    try:
        if response.query_result.intent.display_name == 'RandomDataset':
            al.create_dataset(parameters)

        elif response.query_result.intent.display_name == 'LoadDataset':
            al.load_dataset(parameters)

        elif response.query_result.intent.display_name == 'ShowWorkspace':
            workspace = al.Workspace()
            print(list(workspace.get_all_dataset()))
        
        elif response.query_result.intent.display_name == 'GetBackend':
            al.get_library_backend(parameters['library'])

        elif response.query_result.intent.display_name == 'SetBackend':
            al.set_library_backend(parameters)

        elif response.query_result.intent.display_name == 'Exit - yes':
            al.exiting_yes(response.query_result.fulfillment_text)

        elif response.query_result.intent.display_name == 'Exit - no':
            al.exiting_no(response.query_result.fulfillment_text)

        elif not re.search("^Default|Exit", response.query_result.intent.display_name):

            if not parameters.get("Dataset"):
                parameters['Dataset'] = 'current'

            if al.check_dataset(parameters):

                if response.query_result.intent.display_name == 'ChangeName':
                    al.change_name(parameters)

                elif response.query_result.intent.display_name == 'ShowResult':
                    al.execute_plot(parameters)

                elif response.query_result.intent.display_name == 'PrintResult':
                    al.execute_print(parameters)

                elif response.query_result.intent.display_name == 'SubDatasetRow':
                    al.get_subdataset_rows(parameters)

                elif response.query_result.intent.display_name == 'SubDatasetCols':
                    al.get_subdataset_columns(parameters)

                elif response.query_result.intent.display_name == 'JoinByCols':
                    al.join_by_cols(parameters)

                elif response.query_result.intent.display_name == 'JoinByRows':
                    al.join_by_rows(parameters)

                elif response.query_result.intent.display_name == 'SplitByCols':
                    al.split_by_cols(parameters)

                elif response.query_result.intent.display_name == 'SplitByRows':
                    al.split_by_rows(parameters)

                elif response.query_result.intent.display_name == 'DoDimensionality':
                    al.do_dimensionality(parameters)

                elif response.query_result.intent.display_name == 'DoClustering':
                    al.do_clustering(parameters)

                elif response.query_result.intent.display_name == 'DoMatrix_Stomp':
                    al.do_matrix(parameters)

                elif response.query_result.intent.display_name == 'DoMatrix_Best':
                    al.do_matrix(parameters)

                elif response.query_result.intent.display_name == 'DoNormalization':
                    al.do_normalization(parameters)

                elif response.query_result.intent.display_name == 'DoFeatures':
                    al.do_features(parameters)

            else:
                if parameters["Dataset"] != 'current':
                    print("The object " + parameters["Dataset"] + " does not exist.")
                    al.voice("The object " + parameters["Dataset"] + " does not exist.")
                else:
                    print("There is no loaded dataset.")
                    al.voice("There is no loaded dataset.")
                print("Please, load a dataset or use a previously stored one before using any function.")
                al.voice("Please, load a dataset or use a previously stored one before using any function.")
                return

        print('DEBUG: Fulfillment text: {}\n'.format(response.query_result.fulfillment_text))
        if response.query_result.fulfillment_text:
            al.voice(response.query_result.fulfillment_text)
    except Exception as e:
        print('An error in the execution has been raised.')
        print(e)
        return