-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
108 lines (93 loc) · 3.44 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
include_once 'config.php';
include_once 'db.php';
function elimina_acentos($text){
$text = htmlentities($text, ENT_QUOTES, 'UTF-8');
$text = strtolower($text);
$patron = array (
// Espacios, puntos y comas por guion
//'/[\., ]+/' => ' ',
// Vocales
'/\+/' => '',
'/à/' => 'a',
'/è/' => 'e',
'/ì/' => 'i',
'/ò/' => 'o',
'/ù/' => 'u',
'/á/' => 'a',
'/é/' => 'e',
'/í/' => 'i',
'/ó/' => 'o',
'/ú/' => 'u',
'/â/' => 'a',
'/ê/' => 'e',
'/î/' => 'i',
'/ô/' => 'o',
'/û/' => 'u',
'/ã/' => 'a',
'/&etilde;/' => 'e',
'/ĩ/' => 'i',
'/õ/' => 'o',
'/ũ/' => 'u',
'/ä/' => 'a',
'/ë/' => 'e',
'/ï/' => 'i',
'/ö/' => 'o',
'/ü/' => 'u',
'/ä/' => 'a',
'/ë/' => 'e',
'/ï/' => 'i',
'/ö/' => 'o',
'/ü/' => 'u',
// Otras letras y caracteres especiales
'/å/' => 'a',
'/ñ/' => 'n',
// Agregar aqui mas caracteres si es necesario
);
$text = preg_replace(array_keys($patron),array_values($patron),$text);
return $text;
}
function get_iRespuesta($transcript){
$db = db_connect();
if ($db['error']){
$response['error'] = true;
$response['error_msg'] = $db['msg'];
} else{
$sql = 'SELECT type, pregunta, respuesta FROM sp_dialogo WHERE pregunta="'.$transcript.'"';
$query_response = db_query_select($sql, $db['conexion']);
if ($query_response['error']){
$response['error'] = true;
$response['error_msg'] = $query_response['msg'];
} else {
$response['error'] = false;
if ($response['result']['type'] == 0){
$response['result'] = $query_response['result']['respuesta'];
} else if ($response['result']['type'] == 1){
$response['result'] = $query_response['result']['pregunta'];
}
db_close($db['conexion']);
}
}
return $response;
}
function insert_encoded_audio($transcript,$encoded_audio,$audio_file){
$retocado = elimina_acentos($transcript);
$db = db_connect();
if ($db['error']){
$response['error'] = true;
$response['msg'] = $db['msg'];
} else{
$sql = "INSERT INTO sp_encoded_audio (transcript, encoded_audio, audio_file) VALUES ('".$retocado."', '".$encoded_audio."', '".$audio_file."')";
$query_response = db_query_insert($sql, $db['conexion']);
if ($query_response['error']){
$response['error'] = true;
$response['msg'] = $query_response['msg'];
} else {
$response['error'] = false;
$response['result'] = $query_response['respuesta'];
db_close($db['conexion']);
}
}
return $response;
}
?>