예제 #1
0
        public AerDB(string systemsJson, string stationsJson, string commoditiesJson)
        {
            _SystemRegistry        = new Dictionary <int, EliteSystem>();
            _SystemNameRegistry    = new Dictionary <string, int>();
            _CommodityRegistry     = new Dictionary <int, EliteCommodity>();
            _CommodityNameRegistry = new Dictionary <string, int>();

            if (File.Exists(systemsJson) && File.Exists(commoditiesJson) && File.Exists(stationsJson))
            {
                try
                {
                    _ParseSystems(File.ReadAllText(systemsJson));
                    _ParseCommodities(File.ReadAllText(commoditiesJson));
                    _ParseStations(File.ReadAllText(stationsJson));
                }
                catch (Exception e)
                {
                    AerDebug.LogError("Encountered a problem parsing EDDB json files");
                    AerDebug.LogException(e);
                }
            }
            else
            {
                AerDebug.LogError("Could not find JSON files!");
            }
            Loaded = true;
        }
예제 #2
0
        public string CalculationResult(string query)
        {
            string result = null;

            try
            {
                result = _dataDownloader.DownloadString("https://www.calcatraz.com/calculator/api?c=" + WebUtility.UrlEncode(query)).Trim();
                if (result == "answer")
                {
                    result = null;
                }
            }
            catch (Exception e)
            {
                AerDebug.LogException(e);
            }

            return(result);
        }
예제 #3
0
        /// <summary>
        /// Populates the Station Data with data from the eddb json string
        /// </summary>
        /// <param name="json">Json string of EDDB stations.json data</param>
        private void _ParseStations(string json)
        {
            JsonTextReader jsonReader = new JsonTextReader(new StringReader(json));
            int            arrayDepth = 0;

            while (jsonReader.Read())
            {
                switch (jsonReader.TokenType)
                {
                case JsonToken.StartArray:
                    arrayDepth++;
                    break;

                case JsonToken.StartObject:
                    try
                    {
                        EliteStation es = _ParseJsonStation(jsonReader);
                        es.System.Stations.Add(es);
                    }
                    catch (Exception e)
                    {
                        AerDebug.LogError("Encountered a problem parsing stations.");
                        AerDebug.LogException(e);
                    }
                    break;

                case JsonToken.EndArray:
                    arrayDepth--;
                    break;

                default:
                    AerDebug.LogError("Unknown JSON TokenType: " + jsonReader.TokenType);
                    break;
                }
            }

            if (arrayDepth != 0)
            {
                AerDebug.LogError("Malformed JSON parsing - arrayDepth == " + arrayDepth + " at end of parse");
            }
        }
예제 #4
0
        /// <summary>
        /// Pulls data out of the settings file
        /// </summary>
        protected virtual void LoadSettings()
        {
            string rspSpeed = Settings.Load(Settings.RESPONSE_SPEED_NODE, "750");

            if (rspSpeed == null)
            {
                AerDebug.LogError("Could not load ResponseSpeed from settings file!");
                rspSpeed = "750";
            }

            try
            {
                _ResponseSpeed = int.Parse(rspSpeed);
            }
            catch (Exception e)
            {
                AerDebug.LogError("Invalid ResponseSpeed in settings file!");
                AerDebug.LogException(e);
                _ResponseSpeed = 750; //Default if it breaks.
            }

            _CultureInfo = Settings.Load(Settings.CULTURE_NODE, "en-US");
        }
예제 #5
0
        public AerRecognitionResult BuildAerRecognition(RecognitionResult input)
        {
            int numberOfSemantics       = 0;
            AerRecognitionResult output = new AerRecognitionResult();

            output.Confidence = input.Confidence;
            try
            {
                if (input.Semantics.ContainsKey("Command") && input.Semantics["Command"] != null)
                {
                    output.Command = input.Semantics["Command"].Value.ToString();
                    numberOfSemantics++;
                }

                if (input.Semantics.ContainsKey("Data") && input.Semantics["Data"] != null)
                {
                    output.Data = input.Semantics["Data"].Value.ToString();
                    numberOfSemantics++;
                }

                if (input.Semantics.ContainsKey("CommodityId") && input.Semantics["CommodityId"] != null)
                {
                    int commodityId = int.Parse(input.Semantics["CommodityId"].Value.ToString());
                    output.Commodity = _Eddb.GetCommodity(commodityId);
                    numberOfSemantics++;
                }

                if (input.Semantics.ContainsKey("SystemName") && input.Semantics["SystemName"] != null)
                {
                    string systemName = input.Semantics["SystemName"].Value.ToString();

                    if (systemName.Equals("__last__"))
                    {
                        output.System = _LastSystem;
                    }

                    else
                    {
                        if (systemName.Equals("__local__"))
                        {
                            output.System = LocalSystem;
                        }
                        else
                        {
                            output.System = _Eddb.GetSystem(systemName);
                        }
                    }

                    _LastSystem = output.System;

                    numberOfSemantics++;
                }

                if (input.Semantics.ContainsKey("FromSystem") && input.Semantics["FromSystem"] != null)
                {
                    string systemName = input.Semantics["FromSystem"].Value.ToString();

                    if (systemName.Equals("__last__"))
                    {
                        output.FromSystem = _LastSystem;
                    }
                    else
                    {
                        if (systemName.Equals("__local__"))
                        {
                            output.FromSystem = LocalSystem;
                        }
                        else
                        {
                            output.FromSystem = _Eddb.GetSystem(systemName);
                        }
                    }
                    numberOfSemantics++;
                }

                if (input.Semantics.ContainsKey("ToSystem") && input.Semantics["ToSystem"] != null)
                {
                    string systemName = input.Semantics["ToSystem"].Value.ToString();

                    if (systemName.Equals("__last__"))
                    {
                        output.ToSystem = _LastSystem;
                    }
                    else
                    {
                        if (systemName.Equals("__local__"))
                        {
                            output.ToSystem = LocalSystem;
                        }
                        else
                        {
                            output.ToSystem = _Eddb.GetSystem(systemName);
                        }
                    }
                    numberOfSemantics++;
                }

                if (input.Semantics.ContainsKey("StationName") && input.Semantics["StationName"] != null)
                {
                    string station = input.Semantics["StationName"].Value.ToString();

                    if (station.Equals("__last__"))
                    {
                        output.Station = _LastStation;
                    }

                    if (output.System != null)
                    {
                        output.Station = _Eddb.GetStation(output.System, station);

                        _LastStation = output.Station;
                    }

                    numberOfSemantics++;
                }
            }
            catch (Exception e)
            {
                AerDebug.LogError("Could not parse grammar semantics, " + e.Message);
                AerDebug.LogException(e);
            }

            output.RequiredConfidence = 0.92f - 0.02 * (numberOfSemantics * numberOfSemantics);

            return(output);
        }