Commit 0ab7533ba477073840dc70b35a121b3d8409e503
1 parent
847efc48
Exists in
master
and in
6 other branches
Implementing dictionary json parse
Showing
2 changed files
with
82 additions
and
14 deletions
Show diff stats
Assets/Scripts/Animation List/Trie.cs
1 | -using System; | |
1 | +using LAViD.VLibras.Utils; | |
2 | +using System; | |
2 | 3 | using System.Collections.Generic; |
3 | 4 | using System.Linq; |
4 | 5 | using System.Text; |
6 | +using System.Text.RegularExpressions; | |
5 | 7 | |
6 | 8 | namespace LAViD.VLibras.Generic |
7 | 9 | { |
... | ... | @@ -15,6 +17,40 @@ namespace LAViD.VLibras.Generic |
15 | 17 | { |
16 | 18 | private Node root; |
17 | 19 | |
18 | - // public Trie() | |
20 | + public Trie(string json) | |
21 | + { | |
22 | + JSONTrie trie = new JSONTrie(json); | |
23 | + } | |
24 | + } | |
25 | + | |
26 | + class JSONTrie | |
27 | + { | |
28 | + public string[] characters; | |
29 | + public Dictionary<string, int> charactersKeys; | |
30 | + public JSONNode root; | |
31 | + | |
32 | + public JSONTrie(string json) | |
33 | + { | |
34 | + Regex regex = new Regex("{\"(\\w+)\": (.*), \"(\\w+)\": (.*), \"(\\w+)\": (.*)}"); | |
35 | + Match match = regex.Match(json); | |
36 | + | |
37 | + PlayerLogger.Log("Captures:"); | |
38 | + | |
39 | + foreach (Capture capture in match.Captures) | |
40 | + { | |
41 | + PlayerLogger.Log(capture.Index + ", " + capture.Value); | |
42 | + } | |
43 | + } | |
44 | + } | |
45 | + | |
46 | + class JSONNode | |
47 | + { | |
48 | + public bool end; | |
49 | + public JSONNode children; | |
50 | + | |
51 | + public JSONNode(string json) | |
52 | + { | |
53 | + | |
54 | + } | |
19 | 55 | } |
20 | 56 | } | ... | ... |
Assets/Scripts/PlayerManager.cs
... | ... | @@ -3,6 +3,7 @@ using System.Collections; |
3 | 3 | using System; |
4 | 4 | using UnityEngine.UI; |
5 | 5 | using LAViD.VLibras.Utils; |
6 | +using LAViD.VLibras.Generic; | |
6 | 7 | |
7 | 8 | public class PlayerManager : GenericPlayerManager { |
8 | 9 | |
... | ... | @@ -18,6 +19,8 @@ public class PlayerManager : GenericPlayerManager { |
18 | 19 | private const string SERVER_URL = "http://traducao.vlibras.gov.br/translate?text="; |
19 | 20 | private const int VERSION = 1; |
20 | 21 | |
22 | + private Trie signs; | |
23 | + | |
21 | 24 | public enum ERROR_STATUS_MESSAGE |
22 | 25 | { |
23 | 26 | INTERNET_CONNECTION_FAILURE, |
... | ... | @@ -69,8 +72,30 @@ public class PlayerManager : GenericPlayerManager { |
69 | 72 | |
70 | 73 | Screen.fullScreen = false; |
71 | 74 | |
75 | + WWW dictionaryRequest = new WWW("http://dicionario.vlibras.gov.br/signs"); | |
76 | + StartCoroutine(WaitForResponse(dictionaryRequest, | |
77 | + // Success | |
78 | + delegate(WWW www) | |
79 | + { | |
80 | + this.signs = new Trie(www.text); | |
81 | + }, | |
82 | + // Error | |
83 | + delegate (WWW www) | |
84 | + { | |
85 | + if (www.error == null) | |
86 | + PlayerLogger.Log("PM", "S<d>", "Timeout."); | |
87 | + else | |
88 | + PlayerLogger.Log("PM", "S<d>", "WWW error: " + www.error); | |
89 | + } | |
90 | + )); | |
91 | + } | |
92 | + | |
93 | + public IEnumerator LoadDictionary() | |
94 | + { | |
72 | 95 | |
73 | - } | |
96 | + | |
97 | + yield return null; | |
98 | + } | |
74 | 99 | |
75 | 100 | public void playDict(string word) |
76 | 101 | { |
... | ... | @@ -121,11 +146,6 @@ public class PlayerManager : GenericPlayerManager { |
121 | 146 | |
122 | 147 | protected override WWW loadAssetBundle(string aniName) |
123 | 148 | { |
124 | - if (this.regionHash == 1) | |
125 | - { | |
126 | - // Check if it exists in trie | |
127 | - } | |
128 | - | |
129 | 149 | string address = BASE_URL + this.regionPath + WWW.EscapeURL(aniName); |
130 | 150 | |
131 | 151 | PlayerLogger.Log("PM", "lAB", "Requesting bundle: " + address); |
... | ... | @@ -160,8 +180,6 @@ public class PlayerManager : GenericPlayerManager { |
160 | 180 | this.screenManager.switchScreen("translate"); |
161 | 181 | } |
162 | 182 | |
163 | - | |
164 | - | |
165 | 183 | protected override WWW getCheckConnectionRequest() |
166 | 184 | { |
167 | 185 | return new WWW(BASE_URL); |
... | ... | @@ -205,18 +223,22 @@ public class PlayerManager : GenericPlayerManager { |
205 | 223 | return false;*/ |
206 | 224 | } |
207 | 225 | |
208 | - protected override IEnumerator WaitForResponse(WWW www) | |
226 | + protected delegate void SuccessEvent(WWW request); | |
227 | + protected delegate void ErrorEvent(WWW request); | |
228 | + | |
229 | + protected IEnumerator WaitForResponse(WWW www, SuccessEvent success, ErrorEvent error) | |
209 | 230 | { |
210 | 231 | PlayerLogger.Log("PM", "WFR", "Stating time check."); |
211 | - | |
232 | + | |
212 | 233 | const float timeoutLimit = 20f; |
213 | 234 | float timer = 0; |
214 | - | |
215 | - while ( ! www.isDone) | |
235 | + | |
236 | + while (!www.isDone) | |
216 | 237 | { |
217 | 238 | if (timer > timeoutLimit) |
218 | 239 | { |
219 | 240 | PlayerLogger.Log("PM", "WFR", "Timeout (" + timer + ")."); |
241 | + if (error != null) error(www); | |
220 | 242 | yield break; |
221 | 243 | } |
222 | 244 | |
... | ... | @@ -230,6 +252,16 @@ public class PlayerManager : GenericPlayerManager { |
230 | 252 | } |
231 | 253 | |
232 | 254 | PlayerLogger.Log("PM", "WFR", "Done (" + timer + ")."); |
255 | + | |
256 | + if (www.error == null) { | |
257 | + if (success != null) success(www); | |
258 | + } else { | |
259 | + if (error != null) error(www); | |
260 | + } | |
261 | + } | |
262 | + | |
263 | + protected override IEnumerator WaitForResponse(WWW www) { | |
264 | + yield return WaitForResponse(www, null, null); | |
233 | 265 | } |
234 | 266 | |
235 | 267 | private IEnumerator translate(string gloss) | ... | ... |