Added initial version of Generic Text Classifier
[platform/core/api/generic-text-classifier.git] / src / gc_internal.c
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <malloc.h>
18 #include <string.h>
19 #include <stdbool.h>
20
21 #include "gc_internal.h"
22 #include "gc_inference.h"
23 #include "gc_private.h"
24
25 static bool is_initialized = false;
26 static gc_classifier_h *gc_handle = NULL;
27
28 int _initialize(void)
29 {
30         if (is_initialized)
31                 return GC_ERROR_ALREADY_DONE;
32
33         is_initialized = true;
34
35         return GC_ERROR_NONE;
36 }
37
38 int _deinitialize(void)
39 {
40         if (!is_initialized)
41                 return GC_ERROR_ALREADY_DONE;
42
43         is_initialized = false;
44
45         return GC_ERROR_NONE;
46 }
47
48 int _gc_check_init_status(void)
49 {
50         int ret_val = GC_ERROR_NONE;
51
52         if (is_initialized == false)
53                 ret_val = GC_ERROR_INITIALIZATION_NOT_DONE;
54
55         return ret_val;
56 }
57
58 int _create_classifier(gc_classifier_h *classifier_handle, char *app_id, char *user_id)
59 {
60         int ret_val = GC_ERROR_NONE;
61
62         return ret_val;
63 }
64
65 int _gc_check_handle_creation(void)
66 {
67         int ret_val = GC_ERROR_NONE;
68
69         if (gc_handle == NULL)
70                 ret_val = GC_ERROR_HANDLE_NOT_CREATED;
71
72         return ret_val;
73 }
74
75 int _gc_check_handle_validity(gc_classifier_h *classifier_handle)
76 {
77         int ret_val = GC_ERROR_NONE;
78
79         return ret_val;
80 }
81
82 int _delete_classifier(gc_classifier_h *classifier_handle)
83 {
84         int ret_val = GC_ERROR_NONE;
85
86         free(gc_handle);
87         gc_handle = NULL;
88
89         return ret_val;
90
91 }
92
93 int _get_category(gc_classifier_s *classifier_handle, char *text_data, int text_data_len, gc_category_s *category_list)
94 {
95
96         int ret_val = GC_ERROR_NONE;
97
98         gc_get_category_result result = get_category(classifier_handle->uID, classifier_handle->appID, text_data);
99
100         strncpy(category_list->first_category, result.first_category, strlen(result.first_category) + 1);
101         strncpy(category_list->second_category, result.second_category, strlen(result.second_category) + 1);
102         strncpy(category_list->third_category, result.third_category, strlen(result.third_category) + 1);
103
104         category_list->first_category_score = result.first_category_score;
105         category_list->second_category_score = result.second_category_score;
106         category_list->third_category_score = result.third_category_score;
107         return ret_val;
108 }
109
110 int _add_category(gc_classifier_s *classifier_handle, char *category_name)
111 {
112
113         int ret_val = add_category(classifier_handle->appID, classifier_handle->uID, category_name);
114
115         return ret_val;
116 }
117
118 int _delete_category(gc_classifier_s *classifier_handle, char *category_name)
119 {
120
121         int ret_val = delete_category(classifier_handle->appID, classifier_handle->uID, category_name);
122
123         return ret_val;
124 }
125
126 int _update_category(gc_classifier_s *classifier_handle, char *category_name, char *text_data, int text_data_len)
127 {
128
129         int ret_val = update_category(classifier_handle->appID, classifier_handle->uID, category_name, text_data, text_data_len);
130
131         return ret_val;
132 }