forked from ninjamuffin/SeniorDesignGroup5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
queries.php
111 lines (102 loc) · 3.02 KB
/
queries.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
108
109
110
111
<?php
include_once 'base.php';
function get_expression_query_string($words, $PoS, $offsets)
{
$num_words = count($words);
$num_tags = count($PoS);
$query_length = max($num_words, $num_tags);
$query = "";
$params = array();
$query .= "SELECT Ex.ExpressionID, Ex.Expression, Ex.[Context/Vocabulary], Ex.Topic_ID FROM Expressions Ex, Dictionary D, SequentialWords SW WHERE Ex.ExpressionID in (SELECT ) ";
for($i = 0; $i < $query_length; $i++)
{
$word = $words[$i];
$tag = $PoS[$i];
if ( (count($word) == 0 ) && (count($tag) == 0 ) )
continue;
if ( count($word) == 0)
{
$query .= "D.PoS = ? OR";
$params .= $tag;
}
}
}
function get_dictionary_entries($words, $tags)
{
$query = "SELECT WordID, Form, PoS, Frequency FROM Dictionary WHERE ";
$options = array( "Scrollable" => 'static' );
$num_words = count($words);
$num_tags = count($tags);
$input_length = max($num_words, $num_tags);
$query_length = 0;
$num_tags = 0;
$num_words = 0;
for ($i = 0; $i < $input_length; $i++)
{
if ( (strlen($words[$i]) > 0) || (strlen($tags[$i]) > 0))
$query_length++;
if ( strlen($words[$i]) > 0)
$num_words++;
if ( strlen($tags[$i]) > 0)
$num_tags++;
}
$params = array();
for ($i = 0; $i < $query_length - 1; $i++)
{
if ( (strlen($words[$i]) > 0) && (strlen($tags[$i]) > 0))
{
$query .= "(Form = ? AND PoS = ?) OR ";
$params[] = $words[$i];
$params[] = $tags[$i];
}
elseif (strlen($words[$i]) > 0)
{
$query .= "(Form = ?) OR ";
$params[] = $words[$i];
}
elseif (strlen($tags[$i]) > 0)
{
$query .= "(PoS = ?) OR ";
$params[] = $tags[$i];
}
}
// Last instance
if ( $query_length > 0 )
{
if ( (strlen($words[$query_length - 1]) > 0) && (strlen($tags[$query_length - 1]) > 0))
{
$query .= "(Form = ? AND PoS = ?)";
$params[] = $words[$i];
$params[] = $tags[$i];
}
elseif (strlen($words[$query_length - 1]) > 0)
{
$query .= "(Form = ?)";
$params[] = $words[$i];
}
elseif (strlen($tags[$query_length - 1]) > 0)
{
$query .="(PoS = ?)";
$params[] = $tags[$i];
}
}
/*$stmt = sqlsrv_query($con, $query, $params, $options);
if ($stmt === false)
die (print_r(sqlsrv_errors(), true));
$ids = [];
$forms = [];
$tags = [];
$freq = [];
while (sqlsrv_fetch($stmt) === true)
{
$ids = sqlsrv_get_field($stmt, 0);
$forms = sqlsrv_get_field($stmt, 1);
$tags = sqlsrv_get_field($stmt, 2);
$freq = sqlsrv_get_field($stmt, 3);
}
$result = array($ids, $forms, $tags, $freq);
return $result;
*/
return array($query, $params);
}
?>