Commit e21ff780ea856316e3f496e887e044e9feb31cdc
1 parent
0ab7533b
Exists in
master
and in
6 other branches
Implementing dictionary json parser
Showing
3 changed files
with
35 additions
and
18 deletions
Show diff stats
Assets/Scripts/Animation List/Trie.cs
1 | 1 | using LAViD.VLibras.Utils; |
2 | 2 | using System; |
3 | 3 | using System.Collections.Generic; |
4 | +using System.Diagnostics; | |
4 | 5 | using System.Linq; |
5 | 6 | using System.Text; |
6 | 7 | using System.Text.RegularExpressions; |
... | ... | @@ -31,15 +32,38 @@ namespace LAViD.VLibras.Generic |
31 | 32 | |
32 | 33 | public JSONTrie(string json) |
33 | 34 | { |
34 | - Regex regex = new Regex("{\"(\\w+)\": (.*), \"(\\w+)\": (.*), \"(\\w+)\": (.*)}"); | |
35 | - Match match = regex.Match(json); | |
35 | + Stopwatch watch = new Stopwatch(); | |
36 | + watch.Start(); | |
36 | 37 | |
37 | - PlayerLogger.Log("Captures:"); | |
38 | + // Separate main fields | |
38 | 39 | |
39 | - foreach (Capture capture in match.Captures) | |
40 | - { | |
41 | - PlayerLogger.Log(capture.Index + ", " + capture.Value); | |
42 | - } | |
40 | + GroupCollection mainFields = new Regex("^{\"keys\": (.*), \"trie\": (.*), \"characters\": (.*)}$").Match(Regex.Unescape(json)).Groups; | |
41 | + | |
42 | + string keysJSON = mainFields[1].Value; | |
43 | + string trieJSON = mainFields[2].Value; | |
44 | + string charactersJSON = mainFields[3].Value; | |
45 | + | |
46 | + PlayerLogger.Log("T", "()", "keysJSON: " + keysJSON); | |
47 | + PlayerLogger.Log("T", "()", "trieJSON: " + trieJSON); | |
48 | + PlayerLogger.Log("T", "()", "charactersJSON: " + charactersJSON); | |
49 | + | |
50 | + // Parse characters | |
51 | + | |
52 | + MatchCollection matches = new Regex("\"(.)\"").Matches(charactersJSON); | |
53 | + this.characters = new string[matches.Count]; | |
54 | + | |
55 | + for (int i = 0; i < matches.Count; i++) | |
56 | + this.characters[i] = matches[i].Groups[1].Value; | |
57 | + | |
58 | + // Parse keys | |
59 | + | |
60 | + MatchCollection matches = new Regex("\"(.)\"").Matches(charactersJSON); | |
61 | + this.charactersKeys = new Dictionary<string, int>(); | |
62 | + | |
63 | + | |
64 | + | |
65 | + watch.Stop(); | |
66 | + PlayerLogger.Log("T", "()", "Passed:" + watch.ElapsedMilliseconds); | |
43 | 67 | } |
44 | 68 | } |
45 | 69 | ... | ... |
Assets/Scripts/PlayerManager.cs
... | ... | @@ -71,9 +71,9 @@ public class PlayerManager : GenericPlayerManager { |
71 | 71 | #endif |
72 | 72 | |
73 | 73 | Screen.fullScreen = false; |
74 | - | |
75 | - WWW dictionaryRequest = new WWW("http://dicionario.vlibras.gov.br/signs"); | |
76 | - StartCoroutine(WaitForResponse(dictionaryRequest, | |
74 | + | |
75 | + StartCoroutine(WaitForResponse( | |
76 | + new WWW("http://dicionario.vlibras.gov.br/signs"), | |
77 | 77 | // Success |
78 | 78 | delegate(WWW www) |
79 | 79 | { |
... | ... | @@ -90,13 +90,6 @@ public class PlayerManager : GenericPlayerManager { |
90 | 90 | )); |
91 | 91 | } |
92 | 92 | |
93 | - public IEnumerator LoadDictionary() | |
94 | - { | |
95 | - | |
96 | - | |
97 | - yield return null; | |
98 | - } | |
99 | - | |
100 | 93 | public void playDict(string word) |
101 | 94 | { |
102 | 95 | PlayerLogger.Log("Requesting dictionary: " + word); | ... | ... |
ProjectSettings/QualitySettings.asset