forked from Slevinski/swis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspl.php
More file actions
229 lines (216 loc) · 5.25 KB
/
spl.php
File metadata and controls
229 lines (216 loc) · 5.25 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<?php
/**
* SignPuddle Legacy support
*
* This file is part of SWIS: the SignWriting Icon Server.
*
* SWIS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SWIS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with SWIS. If not, see <http://www.gnu.org/licenses/>.
*
* END Copyright
*
* @copyright 2007-2012 Stephen E Slevinski Jr
* @author Steve Slevinski (slevin@signpuddle.net)
* @version 1
* @section License
* GPL 3, http://www.opensource.org/licenses/gpl-3.0.html
* @brief legacy support for SignPuddle alternate encodings
* @file
*
*/
/**
* primary compatibility SignPuddle library
*/
function swml2ksw($source){
$tree = GetXMLTree($source);
$signCount=count($tree['SWML'][0]['SIGN']);
$bsw = '';
for ($i=0;$i<$signCount;$i++){
$signData=$tree['SWML'][0]['SIGN'][$i];
$lane = $signData[ATTRIBUTES][LANE];
// $gloss = $signData[ATTRIBUTES][GLOSS];
$ksw = '';
switch($lane){
case -1:
$ksw = " L";
break;
case 0:
$ksw = " M";
break;
case 1:
$ksw = " R";
}
foreach ($signData['SYMBOL'] as $symbols) {
$key = id2key($symbols[VALUE],1);
$strnum = koord2str($symbols[ATTRIBUTES][X], $symbols[ATTRIBUTES][Y]);
$ksw .= "S" . $key . $strnum;
}
}
$ksw = raw2ksw(trim($ksw));
return $ksw;
}
function lst2ksw($list){
$units = array();
$list = explode("\n",$list);
foreach($list as $bld){
$units[] = bld2ksw($bld);
}
return implode($units,' ');
}
function bld2ksw($bld){
global $sym_sizer;
if (!$bld){return;}
$build = explode(',',$bld);
$cnt = count($build);
$cnt = $cnt - ($cnt%3);
$keys=array();
$xs=array();
$ys=array();
for ($i=0;$i<$cnt;$i++){
$sym=$build[$i];
$key = id2key($sym);
if ($key) {
$keys[]=$key;
$i++;
$xs[]=$build[$i];
$i++;
$ys[]=$build[$i];
} else {//ignore
$i++;
$i++;
}
}
$i++;
$lane = $build[$i];
//now determine punc or control char
if (isPunc($keys[0])){
$data = 'S' . $keys[0];
} else { //determine lane
switch ($lane){
//written using bsw 3, rather than bsw 3c structure markers
case 0:
$data .= 'M';
break;
case -1:
$data .= 'L';
break;
case 1:
$data .= 'R';
break;
default:
echo ("what lane is this?" . $lane);
die("what lane is this?" . $lane);
}
$cnt = count($keys);
for ($i=0;$i<$cnt;$i++){
if (!isPunc($keys[$i])){
$data .= 'S' . $keys[$i];
$data .= koord2str($xs[$i],$ys[$i]);
}
}
}
return raw2ksw($data);
}
/**
* from IMWA symbol id to ISWA 2008 symbol id
*/
$imwa = array();
function imwa2iswa($imwa_id){
global $imwa;
if (count($imwa)==0){
$filename = 'iswa/data/imwa_iswa.txt';
$contents = trim(file_get_contents($filename));
$rows = explode("\n",$contents);
foreach ($rows as $i => $row){
$parts = explode(',',$row);
$imwa[$parts[0]] = $parts[1];
}
}
return $imwa[$imwa_id];
}
/**
* from ISWA 2008 symbol id to ISWA 2010 symbol id
*/
$iswa_08 = array();
function iswa_08_10($iswa_08_id){
global $iswa_08;
if (count($iswa_08)==0){
$filename = 'iswa/data/iswa_08_10.txt';
$contents = trim(file_get_contents($filename));
$rows = explode("\n",$contents);
foreach ($rows as $i => $row){
$parts = explode(',',$row);
$iswa_08[$parts[0]] = $parts[1];
}
}
return $iswa_08[$iswa_08_id];
}
function ksw2bld($ksw,$force){
if(!$ksw) return;
if (!$force) die("ksw2bld");
if (!kswLayout($ksw) && !isPunc($ksw)) die("invalid word " . $ksw);
$cluster=ksw2cluster($ksw);
$lane = $cluster[0][0];
$max = str2koord($cluster[0][1]);
$min = cluster2min($cluster);
$adjX = intval((250 - ($max[0] - $min[0]))/2) - $min[0];
$adjY = intval((250 - ($max[1] - $min[1]))/2) - $min[1];
// echo "From " . $min[0] . ',' . $min[1] . ' with ' . $max[0] . ',' . $max[1];
$bld = array();
for ($i=1;$i<count($cluster);$i++){
$key = $cluster[$i][0];
$coord = str2koord($cluster[$i][1]);
$bld[] = key2id($key,$force);
$bld[] = $coord[0] + $adjX;
$bld[] = $coord[1] + $adjY;
}
if ($lane=="L") {
$bld[] = '';
$bld[] = -1;
} else if ($lane=="R") {
$bld[] = '';
$bld[] = 1;
} else {
//middle lane ignore
}
return implode(',',$bld);
}
function ksw2lst($ksw,$force){
if (!$force) die("ksw2lst");
$words = explode(" ",$ksw);
$blds = array();
foreach ($words as $word){
if(!$word) continue;
$blds[] = ksw2bld($word,1);
}
return implode("\n",$blds);
}
function puddle_spf(){
global $ui;
global $sgn;
if ($ui and $sgn){
$type='sgn';
$id = $sgn;
} else if ($sgn) {
$type='ui';
$id=$sgn;
} else if ($ui) {
$type='sgn';
$id='';
} else {
$type='ui';
$id='';
}
return get_spml($type,$id);
}
?>