public static IEnumerable <GeonamesAlternateNameEntity> Parse(string path)
        {
            using (var file = new StreamReader(path))
            {
                string line;

                while ((line = file.ReadLine()) != null)
                {
                    if (string.IsNullOrWhiteSpace(line))
                    {
                        continue;
                    }

                    if (line.TrimStart().StartsWith("#"))
                    {
                        continue;
                    }

                    var parse  = line.Split(new char[] { '\t' });
                    var entity = GeonamesAlternateNameEntity.Parse(parse);

                    yield return(entity);
                }
            }
        }
示例#2
0
        public static GeonamesAlternateNameEntity Parse(string[] parts)
        {
            if (parts.Length < 4)
            {
                throw new ArgumentException("Expecting at least 4 columns as input");
            }

            var entity = new GeonamesAlternateNameEntity()
            {
                AlternateNameId = int.Parse(parts[0]),
                Id              = int.Parse(parts[1]),
                ISOLanguage     = parts[2],
                AlternateName   = parts[3],
                IsPreferredName = false,
                IsShortName     = false,
                IsColloquial    = false,
                IsHistoric      = false
            };

            if (parts.Length >= 5 && parts[4].Length > 0)
            {
                entity.IsPreferredName = parts[4] == "1" ? true : false;
            }

            if (parts.Length >= 6 && parts[5].Length > 0)
            {
                entity.IsShortName = parts[5] == "1" ? true : false;
            }

            if (parts.Length >= 7 && parts[6].Length > 0)
            {
                entity.IsColloquial = parts[6] == "1" ? true : false;
            }

            if (parts.Length >= 8 && parts[7].Length > 0)
            {
                entity.IsHistoric = parts[7] == "1" ? true : false;
            }

            return(entity);
        }