private AOTypeDictionary GetDictionaryFromSql() { var dictionary = new AOTypeDictionary(); foreach (var type in DataContext.AddressObjectType) { if (!string.IsNullOrEmpty(type.SCNAME) && !bannedAbbriviatedNames.Contains(type.SCNAME)) { dictionary.Add(new AddressSplitterLib.AddressObjectType(type.SOCRNAME, type.SCNAME, type.LEVEL)); } if (!string.IsNullOrEmpty(type.SOCRNAME) && !bannedAbbriviatedNames.Contains(type.SOCRNAME)) { dictionary.Add(new AddressSplitterLib.AddressObjectType(type.SOCRNAME, type.SOCRNAME, type.LEVEL)); } } return(dictionary); }
internal AddressTruncator(AOTypeDictionary typeDictionary) { this.typeDictionary = typeDictionary; sb = new StringBuilder(); houseTypesMultiPattern = typeDictionary.GetRegexMultiPattern((int)ObjectLevel.House); roomTypesMultiPattern = typeDictionary.GetRegexMultiPattern((int)ObjectLevel.Room); regionTypesMultiPattern = typeDictionary.GetRegexMultiPattern((int)ObjectLevel.Region, GenderNoun.Fiminine); streetTypesMultiPattern = typeDictionary.GetRegexMultiPattern((int)ObjectLevel.Street); fullHouseTypesPattern = String.Format(typeAndNumber, houseTypesMultiPattern); fullRoomTypesPattern = String.Format(typeAndNumber, roomTypesMultiPattern); regionPattern = String.Format("^[^ ]+ая +{0}(?=[^а-я]+?)", regionTypesMultiPattern); allTypesMultiPattern = String.Format(@"(?<=[^а-я]|^){0}(\.+?|(?=[^а-я]|$))", typeDictionary.GetRegexMultiPattern()); housePredictPattern = String.Format("(?<=([^а-я]|^){0}[^а-я]*)[0-9]+([^а-я]*)([а-я](?=[^а-я]|$))*", streetTypesMultiPattern) + litterPattern; regexGroup = new RegexGroup(RegexOptions.Compiled | RegexOptions.IgnoreCase); }
public FiasParser(string connectionString) { DataContext = new FiasClassesDataContext(connectionString); DataContext.CommandTimeout = 0; if (!DataContext.DatabaseExists()) { throw new BadLoginException("Не удалось подключиться к БД."); } bannedAbbriviatedNames = new List <string>(); bannedAbbriviatedNames.Add("к."); bannedAbbriviatedNames.Add("вал"); sb = new StringBuilder(); dictionary = GetDictionaryFromSql(); dictionary.Add(new AddressSplitterLib.AddressObjectType("область", "область", 1, AddressSplitterLib.AddressObjectType.GenderNoun.Fiminine)); dictionary.Add(new AddressSplitterLib.AddressObjectType("область", "обл", 1, AddressSplitterLib.AddressObjectType.GenderNoun.Fiminine)); dictionary.Add(new AddressSplitterLib.AddressObjectType("проспект", "пр-т", 7)); dictionary.Add(new AddressSplitterLib.AddressObjectType("проспект", "пр.", 7)); dictionary.Add(new AddressSplitterLib.AddressObjectType("квартира", "к", 9)); dictionary.Sort(); parser = new AddressParser(dictionary); }
public AddressParser(AOTypeDictionary dictionary) { truncator = new AddressTruncator(dictionary); sb = new StringBuilder(); }