Ejemplo n.º 1
0
        /// <summary>
        /// 建物の階数・部屋番号を正規化する
        /// </summary>
        /// <param name="name">建物名</param>
        /// <returns>建物名</returns>
        private static string NormalizeBuildingName(string name)
        {
            var m = Regex.Match(name.Trim(), @"(.+?)(([\d〇一二三四五六七八九十百千万]+)(階|F|F|号|号室))$");

            if (m.Success)
            {
                var floor  = KanjiNumeralUtil.Convert(m.Groups[3].Value);
                var suffix = m.Groups[4].Value;
                if (suffix == "階" || suffix == "F" || suffix == "F")
                {
                    suffix = "階";
                }
                return($"{m.Groups[1].Value.Trim()} {floor}{suffix}");
            }
            return(name.Trim());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 丁目・番地と建物に分割する
        /// </summary>
        /// <param name="address">住所</param>
        /// <returns>丁目・番地と建物のタプル</returns>
        private static (string addr, string other) GetAddress(string address)
        {
            // 「先頭は数字、途中は数字か繋ぎ文字1、最後は数字か繋ぎ文字2」を満たす正規表現
            var allNum = @"[\d一二三四五六七八九十百千万]+";
            var pat    = $"(.*?)({allNum}({allNum}|丁目|丁|番地|番|号|-|‐|ー|−|の|東|西|南|北)*({allNum}|丁目|丁|番地|番|号))(.*)";
            var m      = Regex.Match(address.Trim(), pat);

            if (m.Success)
            {
                var addr = string.Join("-",
                                       Regex.Matches(m.Groups[2].Value, allNum)
                                       .GetGenericEnumerator()
                                       .Select(v => KanjiNumeralUtil.Convert(v.Value).ToString()));
                var building = NormalizeBuildingName(m.Groups[5].Value);
                return($"{m.Groups[1].Value.Trim()}{addr}", building);
            }
            return("", address.Trim());
        }