-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.php
70 lines (58 loc) · 1.6 KB
/
build.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
<?
function GetChildren($vals, &$i)
{
$children = array();
if ($vals[$i]['value'])
array_push($children, $vals[$i]['value']);
while (++$i < count($vals)) { // so pra nao botar while true ;-)
switch ($vals[$i]['type']) {
case 'cdata':
array_push($children, $vals[$i]['value']);
break;
case 'complete':
array_push($children, array('tag' => $vals[$i]['tag'], 'value' => $vals[$i]['value']));
break;
case 'open':
array_push($children, array('tag' => $vals[$i]['tag'], 'children' => GetChildren($vals, $i)));
break;
case 'close':
return $children;
}
}
}
function GetXMLTree($file)
{
$data = implode('', file($file));
$p = xml_parser_create();
xml_parser_set_option($p, XML_OPTION_SKIP_WHITE, 0);
xml_parse_into_struct($p, $data, $vals);
xml_parser_free($p);
$tree = array();
$i = 0;
array_push($tree, array('tag' => $vals[$i]['tag'], 'children' => GetChildren($vals, $i)));
return $tree;
}
function GetVocab() {
$num = 0;
for ($file = 1; $file <= 40; $file++) {
$xmldict = GetXMLTree("dict/$file");
for ($i = 0; $i < sizeof($xmldict[0]['children']); $i++) {
$childi = $xmldict[0]['children'][$i];
if (!isset($childi['tag']) || strcasecmp($childi['tag'], "ENTRY"))
continue;
for ($j = 0; $j < sizeof($childi['children']); $j++) {
if (!isset($childi['children'][$j]['tag']))
continue;
$tag = $childi['children'][$j]['tag'];
if (strlen($tag) == 1)
continue;
$value = $childi['children'][$j]['value'];
$vocab[$num][$tag] = $value;
}
$num++;
}
}
return $vocab;
}
$vocab = GetVocab();
?>