Exemplo n.º 1
0
        public LanguageIndexer(LanguageSettings languageSettings)
        {
            LanguageSettings = languageSettings;
            Exclusions       = (from item in LanguageSettings.Tokens.Where(y => y.Type == TokenTypeOption.Stop) select item.Content).ToList();

            HashSet <char> hs = new HashSet <char>();

            if (LanguageSettings.Tokens.Any(y => y.Type.Equals(TokenTypeOption.Whitelist)))
            {
                foreach (var item in LanguageSettings.Tokens.Where(x => x.Type.Equals(TokenTypeOption.Whitelist)))
                {
                    foreach (var c in item.Content.ToCharArray())
                    {
                        if (hs.Add(c))
                        {
                            Whitelist.Add(c);
                        }
                    }
                }
            }
            else
            {
                Whitelist.AddRange(Span(65, 90));
                Whitelist.AddRange(Span(97, 122));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Interpreters a series of access tags for a series of vehicle types.
        /// </summary>
        public static bool InterpretAccessValues(IAttributeCollection attributes, Whitelist whiteList, IEnumerable <string> keys, params string[] rootKeys)
        {
            bool?value   = null;
            var  usedKey = string.Empty;

            for (var i = 0; i < rootKeys.Length; i++)
            {
                var currentAccess = Vehicle.InterpretAccessValue(attributes, rootKeys[i]);
                if (currentAccess != null)
                {
                    value   = currentAccess;
                    usedKey = rootKeys[i];
                }
            }
            foreach (var key in keys)
            {
                var currentAccess = Vehicle.InterpretAccessValue(attributes, key);
                if (currentAccess != null)
                {
                    value   = currentAccess;
                    usedKey = key;
                }
            }
            if (!string.IsNullOrWhiteSpace(usedKey))
            {
                whiteList.Add(usedKey);
            }

            return(!value.HasValue || value.Value);
        }
Exemplo n.º 3
0
        private void ImportWhiteListFromCsv()
        {
            var importAction = new CsvImportAndExport();
            var filePath     = importAction.ImportCsv();

            if (filePath is null)
            {
                return;
            }

            try
            {
                var importData = new List <Whitelist>(importAction.GetCsvRecords <Whitelist>(importAction.LoadCsv <WhitelistMap>(filePath)));
                foreach (var data in importData)
                {
                    Whitelist.Add(data);
                }

                MessageBox.Show(Properties.Resources.SuccessfulImport, Properties.Resources.AppName, MessageBoxButton.OK);
            }
            catch (Exception)
            {
                MessageBox.Show(Properties.Resources.ImportFailed, Properties.Resources.AppName, MessageBoxButton.OK);
            }
        }
Exemplo n.º 4
0
        private void LoadWhitelistData()
        {
            var readCsv   = new ReadAndWriteCsv("Whitelist.csv");
            var whitelist = readCsv.GetCsvRecords <Whitelist>(readCsv.LoadCsv <WhitelistMap>());

            foreach (var data in whitelist)
            {
                Whitelist.Add(data);
            }
        }
Exemplo n.º 5
0
        private static short?IsOneway(IAttributeCollection attributes, Whitelist whitelist, String name)
        {
            String oneway = null;

            if (attributes.TryGetValue(name, out oneway))
            {
                whitelist.Add(name);
                if (!String.IsNullOrEmpty(oneway))
                {
                    if (oneway == "yes" ||
                        oneway == "true" ||
                        oneway == "1")
                    {
                        return(1);
                    }
                    if (oneway == "-1")
                    {
                        return(2);
                    }
                }
            }
            return(null);
        }
Exemplo n.º 6
0
        internal static FactorAndSpeed FactorAndSpeed(IAttributeCollection attributes,
                                                      Whitelist whitelist)
        {
            if (attributes == null || attributes.Count == 0)
            {
                return(Itinero.Profiles.FactorAndSpeed.NoFactor);
            }

            string highway = null;

            if (attributes.TryGetValue("highway", out highway))
            {
                whitelist.Add("highway");
            }
            string foot = null;

            if (attributes.TryGetValue("foot", out foot))
            {
                if (foot == "no" || foot == "0")
                {
                    return(Itinero.Profiles.FactorAndSpeed.NoFactor);
                }
                whitelist.Add("foot");
            }
            string footway;

            if (attributes.TryGetValue("footway", out footway))
            {
                whitelist.Add("footway");
            }
            var   result    = new FactorAndSpeed();
            var   speed     = 0.0f;
            short direction = 0;
            var   canstop   = true;

            if (String.IsNullOrEmpty(highway))
            {
                if (!String.IsNullOrEmpty(foot))
                {
                    highway = "footway";
                }
                else
                {
                    return(Itinero.Profiles.FactorAndSpeed.NoFactor);
                }
            }
            //get default speed profiles
            var highway_speed = SpeedProfiles.ContainsKey(highway) ? (int?)SpeedProfiles[highway] : null;

            if (highway_speed != null)
            {
                speed     = highway_speed.Value;
                direction = 0;
                canstop   = true;
            }
            else
            {
                return(Itinero.Profiles.FactorAndSpeed.NoFactor);
            }

            if (CanAccess(attributes) == false || speed == 0)
            {
                return(Itinero.Profiles.FactorAndSpeed.NoFactor);
            }

            result.SpeedFactor = 1.0f / (speed / 3.6f); // 1/m/s
            result.Value       = result.SpeedFactor;
            result.Direction   = direction;
            if (!canstop)
            {
                result.Direction += 3;
            }
            return(result);
        }
Exemplo n.º 7
0
        internal static FactorAndSpeed FactorAndSpeed(IAttributeCollection attributes,
                                                      Whitelist whitelist)
        {
            if (attributes == null || attributes.Count == 0)
            {
                return(Profiles.FactorAndSpeed.NoFactor);
            }
            string highway = null;

            if (attributes.TryGetValue("highway", out highway))
            {
                whitelist.Add("highway");
            }
            var   result    = new FactorAndSpeed();
            var   speed     = 0.0f;
            short direction = 0;
            var   canstop   = true;
            //set highway to ferry when ferry.
            string route = null;

            if (attributes.TryGetValue("route", out route))
            {
                whitelist.Add("route");
            }
            if (route == "ferry")
            {
                highway = "ferry";
            }

            if (String.IsNullOrEmpty(highway))
            {
                return(Itinero.Profiles.FactorAndSpeed.NoFactor);
            }
            //get default speed profiles
            var highway_speed = _speedProfiles.ContainsKey(highway) ? (int?)_speedProfiles[highway] : null;

            if (highway_speed != null)
            {
                speed     = highway_speed.Value;
                direction = 0;
                canstop   = true;
                if (highway == "motorway" ||
                    highway == "motorway_link")
                {
                    canstop = false;
                }
            }
            else
            {
                return(Itinero.Profiles.FactorAndSpeed.NoFactor);
            }

            if (CanAccess(attributes) == false)
            {
                return(Itinero.Profiles.FactorAndSpeed.NoFactor);
            }

            //get maxspeed if any.
            string maxSpeed = null;

            if (attributes.TryGetValue("maxspeed", out maxSpeed))
            {
                whitelist.Add("maxspeed");
                float lspeed;
                if (float.TryParse(maxSpeed, out lspeed))
                {
                    speed = lspeed * 0.75f;
                }
            }

            //get maxweight and maxwidth constraints if any
            var    maxweight       = 0.0f;
            var    maxwidth        = 0.0f;
            string maxWeightString = null;

            if (attributes.TryGetValue("maxweight", out maxWeightString))
            {
                whitelist.Add("maxweight");
                float.TryParse(maxWeightString, out maxweight);
            }

            string maxWidthString = null;

            if (attributes.TryGetValue("maxwidth", out maxWidthString))
            {
                whitelist.Add("maxwidth");
                float.TryParse(maxWidthString, out maxwidth);
            }

            if (maxwidth != 0 || maxweight != 0)
            {
                result.Constraints = new[]
                { maxweight, maxwidth };
            }

            //get directional information
            String junction = null;

            if (attributes.TryGetValue("junction", out junction))
            {
                whitelist.Add("junction");
                if (junction == "roundabout")
                {
                    direction = 1;
                }
            }
            var ldirection = IsOneway(attributes, whitelist, "oneway");

            if (ldirection != null)
            {
                direction = ldirection.Value;
            }
            if (speed == 0)
            {
                return(Itinero.Profiles.FactorAndSpeed.NoFactor);
            }
            result.SpeedFactor = 1.0f / (speed / 3.6f); // 1/m/s
            result.Value       = result.SpeedFactor;
            result.Direction   = direction;
            if (!canstop)
            {
                result.Direction += 3;
            }
            return(result);
        }