From e21ff780ea856316e3f496e887e044e9feb31cdc Mon Sep 17 00:00:00 2001 From: Mateus Pires Date: Fri, 14 Oct 2016 22:15:53 -0300 Subject: [PATCH] Implementing dictionary json parser --- Assets/Scripts/Animation List/Trie.cs | 38 +++++++++++++++++++++++++++++++------- Assets/Scripts/PlayerManager.cs | 13 +++---------- ProjectSettings/QualitySettings.asset | 2 +- 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/Assets/Scripts/Animation List/Trie.cs b/Assets/Scripts/Animation List/Trie.cs index 7012ef1..a040286 100644 --- a/Assets/Scripts/Animation List/Trie.cs +++ b/Assets/Scripts/Animation List/Trie.cs @@ -1,6 +1,7 @@ using LAViD.VLibras.Utils; using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Text; using System.Text.RegularExpressions; @@ -31,15 +32,38 @@ namespace LAViD.VLibras.Generic public JSONTrie(string json) { - Regex regex = new Regex("{\"(\\w+)\": (.*), \"(\\w+)\": (.*), \"(\\w+)\": (.*)}"); - Match match = regex.Match(json); + Stopwatch watch = new Stopwatch(); + watch.Start(); - PlayerLogger.Log("Captures:"); + // Separate main fields - foreach (Capture capture in match.Captures) - { - PlayerLogger.Log(capture.Index + ", " + capture.Value); - } + GroupCollection mainFields = new Regex("^{\"keys\": (.*), \"trie\": (.*), \"characters\": (.*)}$").Match(Regex.Unescape(json)).Groups; + + string keysJSON = mainFields[1].Value; + string trieJSON = mainFields[2].Value; + string charactersJSON = mainFields[3].Value; + + PlayerLogger.Log("T", "()", "keysJSON: " + keysJSON); + PlayerLogger.Log("T", "()", "trieJSON: " + trieJSON); + PlayerLogger.Log("T", "()", "charactersJSON: " + charactersJSON); + + // Parse characters + + MatchCollection matches = new Regex("\"(.)\"").Matches(charactersJSON); + this.characters = new string[matches.Count]; + + for (int i = 0; i < matches.Count; i++) + this.characters[i] = matches[i].Groups[1].Value; + + // Parse keys + + MatchCollection matches = new Regex("\"(.)\"").Matches(charactersJSON); + this.charactersKeys = new Dictionary(); + + + + watch.Stop(); + PlayerLogger.Log("T", "()", "Passed:" + watch.ElapsedMilliseconds); } } diff --git a/Assets/Scripts/PlayerManager.cs b/Assets/Scripts/PlayerManager.cs index 7878883..80e6efa 100644 --- a/Assets/Scripts/PlayerManager.cs +++ b/Assets/Scripts/PlayerManager.cs @@ -71,9 +71,9 @@ public class PlayerManager : GenericPlayerManager { #endif Screen.fullScreen = false; - - WWW dictionaryRequest = new WWW("http://dicionario.vlibras.gov.br/signs"); - StartCoroutine(WaitForResponse(dictionaryRequest, + + StartCoroutine(WaitForResponse( + new WWW("http://dicionario.vlibras.gov.br/signs"), // Success delegate(WWW www) { @@ -90,13 +90,6 @@ public class PlayerManager : GenericPlayerManager { )); } - public IEnumerator LoadDictionary() - { - - - yield return null; - } - public void playDict(string word) { PlayerLogger.Log("Requesting dictionary: " + word); diff --git a/ProjectSettings/QualitySettings.asset b/ProjectSettings/QualitySettings.asset index 6f41c93..93dcd48 100644 --- a/ProjectSettings/QualitySettings.asset +++ b/ProjectSettings/QualitySettings.asset @@ -151,7 +151,7 @@ QualitySettings: textureQuality: 0 anisotropicTextures: 2 antiAliasing: 2 - softParticles: 1 + softParticles: 0 softVegetation: 1 realtimeReflectionProbes: 1 billboardsFaceCameraPosition: 1 -- libgit2 0.21.2