コード例 #1
0
        private static string GetPattern(EnumLanguage language = EnumLanguage.NONE)
        {
            string pattern = "";

            switch (language)
            {
            default:
            {
                // circa late eighth to early ninth century AD
                pattern = String.Concat(
                    START,
                    maybe(DateCirca.Pattern(language) + SPACE),
                    maybe(oneof(Lookup <EnumDatePrefix> .Patterns(language), "prefix1") + SPACE),
                    oneof(Lookup <EnumOrdinal> .Patterns(language), "centuryMin"),
                    maybe(SPACE + "century"),
                    @"\s*(?:[e\;\-\/]|to|or)\s*",
                    maybe(oneof(Lookup <EnumDatePrefix> .Patterns(language), "prefix2") + SPACE),
                    oneof(Lookup <EnumOrdinal> .Patterns(language), "centuryMax"),
                    maybe(SPACE + "century"),
                    maybe(SPACE + oneof(Lookup <EnumDateSuffix> .Patterns(language), "suffix")),
                    END
                    );
                break;
            }
            }

            return(pattern);
        }
コード例 #2
0
ファイル: RxSingleYear.cs プロジェクト: cbinding/timespans
        private static string GetPattern(EnumLanguage language = EnumLanguage.NONE)
        {
            string pattern = "";

            switch (language)
            {
            case EnumLanguage.IT:
            {
                // ^(?:(?:dal?|in|nel)\s)?(?:(?:C(?:\.|irca)|Intorno al)\s)?(?<year>\d+)(?:(?<suffix>a\.?C\.?|d\.?C\.?|B\.?P\.?|C\.?E\.?))?$
                pattern = String.Concat(
                    START,                                                               // ^
                    maybe(oneof(new string[] { @"dal?", "in", "nel" }) + SPACE),         // (?:(?:dal?|in|nel)\s)?
                    maybe(DateCirca.Pattern(language) + SPACE),                          // (?:(?:C(?:\.|irca)|Intorno al)\s)?
                    group(@"\d+", "year"),                                               // (?<year>\d+)
                    maybe(SPACE),                                                        // (?:\s)?
                    maybe(oneof(Lookup <EnumDateSuffix> .Patterns(language), "suffix")), // (?:(?<suffix>a\.?C\.?|d\.?C\.?|B\.?P\.?|C\.?E\.?))?
                    END                                                                  // $
                    );
                break;
            }

            default:
            {
                // ^(?:(?:C(?:\.|irca)|around|approx(?:\.|imately)?)\s)?(?<year>\d+)(?:(?<suffix>B\.?C\.?|A\.?D\.?|B\.?P\.?|C\.?E\.?)\s)?$
                pattern = String.Concat(
                    START,                                                          // ^
                    maybe(DateCirca.Pattern(language)),                             // (?:C(?:\.|irca)|around|approx(?:\.|imately)?)?
                    maybe(SPACE),                                                   // (?:\s)?
                    oneof(new string[] {
                        group(@"[+-]?\d+", "year"),
                        String.Concat(
                            group(@"\d+", "year"),                                              // (?<year>\d+)
                            maybe(oneof(new string[] { @"\+", @"\?" })),                        // approximation indicator
                            maybe(SPACE),                                                       // (?:\s)?
                            maybe(oneof(Lookup <EnumDateSuffix> .Patterns(language), "suffix")) // (?<suffix>B\.?C\.?|A\.?D\.?|B\.?P\.?|C\.?E\.?)?
                            ),
                        String.Concat(
                            maybe(oneof(Lookup <EnumDateSuffix> .Patterns(language), "suffix")), // (?<suffix>B\.?C\.?|A\.?D\.?|B\.?P\.?|C\.?E\.?)?
                            maybe(SPACE),                                                        // (?:\s)?
                            group(@"\d+", "year"),                                               // (?<year>\d+)
                            maybe(oneof(new string[] { @"\+", @"\?" }))
                            )
                    }),
                    END                                                             // $
                    );
                break;
            }
            }
            return(pattern);
        }
コード例 #3
0
ファイル: RxMonthYear.cs プロジェクト: cbinding/timespans
        private static string GetPattern(EnumLanguage language = EnumLanguage.NONE)
        {
            string pattern = String.Concat(
                START,
                maybe(DateCirca.Pattern(language) + SPACE),
                oneof(Lookup <EnumMonth> .Patterns(language), "month"),
                //Month.Pattern(language, "month"),
                SPACE,
                group(@"\d+", "year"),
                maybe(SPACE),
                maybe(oneof(Lookup <EnumDateSuffix> .Patterns(language), "suffix")),
                END
                );

            return(pattern);
        }
コード例 #4
0
        private static string GetPattern(EnumLanguage language = EnumLanguage.NONE)
        {
            string[] patterns =
            {
                String.Concat(
                    START,
                    maybe(DateCirca.Pattern(language) + SPACE),
                    group(@"[+-]?\d+",                         "year"),
                    @"\s*\±\s*",
                    group(@"\d+",                              "tolerance"),
                    END
                    ),
                String.Concat(
                    START,
                    maybe(DateCirca.Pattern(language) + SPACE),
                    group(@"[+-]?\d+",                         "year"),
                    maybe(SPACE),
                    group(@"[+-]\d+",                          "tolerance1"),
                    maybe(SPACE),
                    group(@"[+-]\d+",                          "tolerance2"),
                    END
                    ),
                String.Concat(
                    START,
                    maybe(DateCirca.Pattern(language) + SPACE),
                    group(@"[+-]?\d+",                         "year"),
                    maybe(SPACE),
                    group(@"[+-]\d+",                          "tolerance"),
                    END
                    )
                // @"^(?:c(?:irca|\.|)\s)?(?<year>\d+)\s*\±\s*(?<tolerance>\d+)$",
                // @"^(?:c(?:irca|\.|)\s)?(?<year>\d+)\s*(?<tolerance>[+-]\d+)$",
                // @"^(?:c(?:irca|\.|)\s)?(?<year>\d+)\s*(?<tolerance1>[+-]\d+)\s*(?<tolerance2>[+-]\d+)$"
            };

            return(oneof(patterns)); // (?:pattern1|pattern2|pattern3)
        }
コード例 #5
0
        public static IYearSpan Match(string input, EnumLanguage language = EnumLanguage.NONE)
        {
            string pattern;
            Match  m;

            // look for plusminus symbol tolerance pattern e.g. "1540±9" => { min: 1540, max: 1549, label: "1540+9" }
            // pattern = @"^(?:c(?:irca|\.|)\s)?(?<year>\d+)\s*\±\s*(?<tolerance>\d+)$";
            pattern = String.Concat(
                START,
                maybe(DateCirca.Pattern(language) + SPACE),
                group(@"[+-]?\d+", "year"),
                @"\s*\±\s*",
                group(@"\d+", "tolerance"),
                END
                );
            m = Regex.Match(input.Trim(), pattern, options);
            if (m.Success)
            {
                int year      = 0;
                int tolerance = 0;
                int.TryParse(m.Groups["year"].Value, out year);
                int.TryParse(m.Groups["tolerance"].Value, out tolerance);
                return(new YearSpan(year - tolerance, year + tolerance, input, "RxYearWithTolerance(1)"));
            }

            // look for plus minus tolerance pattern e.g. "1540+9-5" => { min: 1535, max: 1549, label: "1540+9-5" }
            //pattern = @"^(?:c(?:irca|\.|)\s)?(?<year>\d+)\s*(?<tolerance1>[+-]\d+)\s*(?<tolerance2>[+-]\d+)$";
            pattern = String.Concat(
                START,
                maybe(DateCirca.Pattern(language) + SPACE),
                group(@"[+-]?\d+", "year"),
                maybe(SPACE),
                group(@"[+-]\d+", "tolerance1"),
                maybe(SPACE),
                group(@"[+-]\d+", "tolerance2"),
                END
                );
            m = Regex.Match(input.Trim(), pattern, options);
            if (m.Success)
            {
                int year       = 0;
                int tolerance1 = 0;
                int tolerance2 = 0;
                int.TryParse(m.Groups["year"].Value, out year);
                int.TryParse(m.Groups["tolerance1"].Value, out tolerance1);
                int.TryParse(m.Groups["tolerance2"].Value, out tolerance2);
                return(new YearSpan(year + tolerance1, year + tolerance2, input, "RxYearWithTolerance(2)"));
            }

            // look for single tolerance pattern e.g. "1540+9" => { min: 1540, max: 1549, label: "1540+9" }
            //pattern = @"^(?:c(?:irca|\.|)\s)?(?<year>\d+)\s*(?<tolerance>[+-]\d+)$";
            pattern = String.Concat(
                START,
                maybe(DateCirca.Pattern(language) + SPACE),
                group(@"\d+", "year"),
                maybe(SPACE),
                group(@"[+-]\d+", "tolerance"),
                END
                );
            m = Regex.Match(input.Trim(), pattern, options);
            if (m.Success)
            {
                int year      = 0;
                int tolerance = 0;
                int.TryParse(m.Groups["year"].Value, out year);
                int.TryParse(m.Groups["tolerance"].Value, out tolerance);
                return(new YearSpan(year, year + tolerance, input, "RxYearWithTolerance(3)"));
            }

            // if we reach here nothing matched
            return(null);
        }
コード例 #6
0
        private static string GetPattern(EnumLanguage language = EnumLanguage.NONE)
        {
            string pattern = "";

            switch (language)
            {
            case EnumLanguage.IT:
            {
                // ^(?:(?:Intorno\sal|circa)\s)?(?<yearMin>\d{3,})(?:\s*[;\-\/]\s*)(?<yearMax>\d{2,})\s*(?<suffix>a\.?C\.?|d\.?C\.?)?$
                pattern = String.Concat(
                    START,                                                      // ^
                    maybe(oneof(new string[] { "tra lo", "in" }) + SPACE),      // (?:(?:tra lo|in)\s)?
                    maybe(DateCirca.Pattern(language) + SPACE),                 // (?:(?:Intorno\sal|circa)\s)?

                    oneof(new string[] {
                        String.Concat(
                            maybe(oneof(Lookup <EnumDateSuffix> .Patterns(language), "suffix1")),
                            maybe(SPACE),
                            group(@"\d+", "yearMin")
                            ),
                        String.Concat(
                            group(@"\d+", "yearMin"),
                            maybe(SPACE),
                            maybe(oneof(Lookup <EnumDateSuffix> .Patterns(language), "suffix1"))
                            )
                    }),
                    oneof(new string[] { @"\s*[\;\-\/]\s*", @"\sed?\slo\s" }),       // separator

                    oneof(new string[] {
                        String.Concat(
                            maybe(oneof(Lookup <EnumDateSuffix> .Patterns(language), "suffix2")),
                            maybe(SPACE),
                            group(@"\d+", "yearMax")
                            ),
                        String.Concat(
                            group(@"\d+", "yearMax"),
                            maybe(SPACE),
                            maybe(oneof(Lookup <EnumDateSuffix> .Patterns(language), "suffix2"))
                            )
                    }),
                    END                                                        // $
                    );
                break;
            }

            case EnumLanguage.NL:
            {
                pattern = String.Concat(
                    START,
                    maybe(@"tussen" + SPACE),     // "between"
                    maybe(DateCirca.Pattern(language) + maybe(SPACE)),
                    group(@"\d+", "yearMin"),
                    maybe(SPACE),
                    maybe(oneof(Lookup <EnumDateSuffix> .Patterns(language), "suffix1")),
                    @"\s*(?:[\;\-\/]|en)\s*",     // separators
                    maybe(DateCirca.Pattern(language) + maybe(SPACE)),
                    group(@"\d+", "yearMax"),
                    maybe(SPACE),
                    maybe(oneof(Lookup <EnumDateSuffix> .Patterns(language), "suffix2")),
                    END
                    );
                break;
            }

            default:
            {
                // ^(?:c(?:\.|irca)?)?\s*(?<yearMin>\d+)(?:\s*(?:[;\-\/]|to)\s*)(?<yearMax>\d+)\s*(?<suffix>AD|BC|CE|BP)?\s*\??$
                pattern = String.Concat(
                    START,
                    maybe(DateCirca.Pattern(language) + maybe(SPACE)),
                    oneof(new string[] {
                        group(@"[+-]?\d+", "yearMin"),
                        String.Concat(
                            maybe(oneof(Lookup <EnumDateSuffix> .Patterns(language), "suffix1")),
                            maybe(SPACE),
                            group(@"\d+", "yearMin")
                            ),
                        String.Concat(
                            group(@"\d+", "yearMin"),
                            maybe(SPACE),
                            maybe(oneof(Lookup <EnumDateSuffix> .Patterns(language), "suffix1"))
                            )
                    }),
                    @"\s*(?:[\;\-\/]|to)\s*",    // separators
                    oneof(new string[] {
                        group(@"[+-]?\d+", "yearMax"),
                        String.Concat(
                            maybe(oneof(Lookup <EnumDateSuffix> .Patterns(language), "suffix2")),
                            maybe(SPACE),
                            group(@"\d+", "yearMax")
                            ),
                        String.Concat(
                            group(@"\d+", "yearMax"),
                            maybe(SPACE),
                            maybe(oneof(Lookup <EnumDateSuffix> .Patterns(language), "suffix2"))
                            )
                    }),
                    END
                    );
                break;
            }
            }
            return(pattern);
        }
コード例 #7
0
        // done like this so they are only read once

        /* private static Lazy<IList<Ordinal>> _ordinals = new Lazy<IList<Ordinal>>(() => getOrdinals(), true);
         * private static IList<Ordinal> ordinals
         * {
         *   get
         *   {
         *       return _ordinals.Value;
         *   }
         * }
         * private static IList<Ordinal> getOrdinals()
         * {
         *   IList<Ordinal> ordinals = null;
         *   string path = "";
         *   if (System.Web.HttpContext.Current != null)
         *       path = System.Web.HttpContext.Current.Request.MapPath("~\\ordinals.json");
         *   else
         *       path = "ordinals.json"; // tests don't have HttpContext, so were failing
         *   ordinals = Newtonsoft.Json.JsonConvert.DeserializeObject<IList<Ordinal>>(System.IO.File.ReadAllText(path));
         *   return ordinals;
         * }
         */
        // attempt to get a match on ordinal

        /*protected int getOrdinalNoFromName(string name, EnumLanguage language)
         * {
         *  IOrdinal match = null;
         *  match = ordinals.FirstOrDefault(o => o.label == name.Trim().ToLower() && (language != EnumLanguage.NONE ? o.language == language : true));
         *  return (match == null ? 0 : match.value);
         * }      */

        private static string GetPattern(EnumLanguage language = EnumLanguage.NONE)
        {
            string pattern = "";

            switch (language)
            {
            case EnumLanguage.CY:
                pattern = String.Concat(
                    START,
                    maybe(DateCirca.Pattern(language) + SPACE),
                    maybe(oneof(Lookup <EnumDatePrefix> .Patterns(language), "prefix") + SPACE),
                    oneof(Lookup <EnumOrdinal> .Patterns(language), "ordinal"),
                    SPACE,
                    @"[cg]anrif",
                    maybe(SPACE + oneof(Lookup <EnumDateSuffix> .Patterns(language), "suffix")),
                    END
                    );
                break;

            case EnumLanguage.FR:
                pattern = String.Concat(
                    START,
                    maybe(DateCirca.Pattern(language) + SPACE),
                    maybe(oneof(Lookup <EnumDatePrefix> .Patterns(language), "prefix") + SPACE),
                    oneof(Lookup <EnumOrdinal> .Patterns(language), "ordinal"),
                    SPACE,
                    @"s(?:\.|iècle)",
                    maybe(SPACE + oneof(Lookup <EnumDateSuffix> .Patterns(language), "suffix")),
                    END
                    );
                break;

            case EnumLanguage.IT:
                pattern = String.Concat(
                    START,                                         // ^
                    maybe(DateCirca.Pattern(language) + SPACE),    // (?:(?:C(?:\.|irca)|Intorno al)\s)?
                    maybe(oneof(Lookup <EnumDatePrefix> .Patterns(language), "prefix") + SPACE),
                    oneof(new string[] {
                    @"sec(?:\.|olo)" + SPACE + oneof(Lookup <EnumOrdinal> .Patterns(language), "ordinal"),
                    oneof(Lookup <EnumOrdinal> .Patterns(language), "ordinal") + SPACE + @"sec(?:\.|olo)"
                }),
                    maybe(SPACE + oneof(Lookup <EnumDateSuffix> .Patterns(language), "suffix")), // (?:\s(?<suffix>a\.?C\.?|d\.?C\.?))?
                    END                                                                          // $
                    );
                break;

            case EnumLanguage.NL:
                pattern = String.Concat(
                    START,
                    maybe(DateCirca.Pattern(language) + SPACE),
                    maybe(oneof(Lookup <EnumDatePrefix> .Patterns(language), "prefix") + SPACE),
                    oneof(Lookup <EnumOrdinal> .Patterns(language), "ordinal"),
                    SPACE,
                    @"eeuw",
                    maybe(SPACE + oneof(Lookup <EnumDateSuffix> .Patterns(language), "suffix")),
                    END
                    );
                break;

            case EnumLanguage.SV:
                pattern = String.Concat(
                    START,
                    maybe(DateCirca.Pattern(language) + SPACE),
                    maybe(oneof(Lookup <EnumDatePrefix> .Patterns(language), "prefix") + SPACE),
                    oneof(Lookup <EnumOrdinal> .Patterns(language), "ordinal"),
                    SPACE,
                    @"århundrade",
                    maybe(SPACE + oneof(Lookup <EnumDateSuffix> .Patterns(language), "suffix")),
                    END
                    );
                break;

            default:
                pattern = String.Concat(
                    START,                                                                       // ^
                    maybe(DateCirca.Pattern(language) + SPACE),
                    maybe(oneof(Lookup <EnumDatePrefix> .Patterns(language), "prefix") + SPACE), // (?:
                    oneof(Lookup <EnumOrdinal> .Patterns(language), "ordinal"),
                    SPACE,
                    @"centur(?:y|ies)",
                    maybe(SPACE + oneof(Lookup <EnumDateSuffix> .Patterns(language), "suffix")),
                    END
                    );
                break;
            }
            return(pattern);
        }
コード例 #8
0
        private static string GetPattern(EnumLanguage language = EnumLanguage.NONE)
        {
            string pattern = "";

            switch (language)
            {
            case EnumLanguage.CY:
            {
                pattern = String.Concat(
                    START,
                    maybe(DateCirca.Pattern(language) + SPACE),
                    maybe(oneof(Lookup <EnumDatePrefix> .Patterns(language), "prefix1") + SPACE),
                    group(@"\d+", "centuryMin"),
                    oneof(new string[] { "af", "a?il", "ydd", "f?ed", "eg", "ain" }),
                    maybe(SPACE + "ganrif"),
                    @"\s*[\s\;\-\/]\s*",
                    maybe(oneof(Lookup <EnumDatePrefix> .Patterns(language), "prefix2") + SPACE),
                    group(@"\d+", "centuryMax"),
                    oneof(new string[] { "af", "a?il", "ydd", "f?ed", "eg", "ain" }),
                    SPACE,
                    "ganrif",
                    maybe(SPACE + oneof(Lookup <EnumDateSuffix> .Patterns(language), "suffix")),
                    END
                    );
                break;
            }

            case EnumLanguage.FR:
            {
                pattern = String.Concat(
                    START,
                    maybe(DateCirca.Pattern(language) + SPACE),
                    maybe(oneof(Lookup <EnumDatePrefix> .Patterns(language), "prefix1") + SPACE),
                    group(ROMAN, "centuryMin"),                          // (?<centuryMin>[MCDLXVI]+)
                    oneof(new string[] { "è?[mr]e", "er", "re", "[eè]", "n?de?", "o" }),
                    maybe(SPACE + @"s(?:\.|iècle)"),
                    @"\s*[\;\-\/]\s*",          // separators
                    maybe(oneof(Lookup <EnumDatePrefix> .Patterns(language), "prefix2") + SPACE),
                    group(ROMAN, "centuryMax"), // (?<centuryMax>[MCDLXVI]+)
                    oneof(new string[] { "è?[mr]e", "er", "re", "[eè]", "n?de?", "o" }),
                    maybe(SPACE + @"s(?:\.|iècle)"),
                    maybe(SPACE + oneof(Lookup <EnumDateSuffix> .Patterns(language), "suffix")),    // (?:\s(?<suffix>a\.?C\.?|d\.?C\.?))?
                    END
                    );
                break;
            }

            case EnumLanguage.IT:
            {
                pattern = String.Concat(
                    START,
                    maybe(@"tra(?:\slo)?" + SPACE),
                    maybe(DateCirca.Pattern(language) + SPACE),                                  // (?:(?:Intorno\sal|circa)\s)?
                    maybe(oneof(Lookup <EnumDatePrefix> .Patterns(language), "prefix1") + SPACE),
                    group(ROMAN, "centuryMin"),                                                  // (?<centuryMin>[MCDLXVI]+)
                    oneof(new string[] { @"\s*[e\;\-\/]\s*", @"\sed?\slo\s" }),                  // separator
                    maybe(oneof(Lookup <EnumDatePrefix> .Patterns(language), "prefix2") + SPACE),
                    group(ROMAN, "centuryMax"),                                                  // (?<centuryMax>[MCDLXVI]+)
                    maybe(SPACE + @"sec(?:\.|olo)"),
                    maybe(SPACE + oneof(Lookup <EnumDateSuffix> .Patterns(language), "suffix")), // (?:\s(?<suffix>a\.?C\.?|d\.?C\.?))?
                    END
                    );
                break;
            }

            case EnumLanguage.NL:
            {
                pattern = String.Concat(
                    START,
                    maybe(@"tussen" + SPACE),
                    maybe(DateCirca.Pattern(language) + SPACE),
                    maybe(oneof(Lookup <EnumDatePrefix> .Patterns(language), "prefix1") + SPACE),     //
                    group(@"\d+", "centuryMin"),
                    oneof(new string[] { "e", "ste", "de" }),
                    maybe(SPACE + "eeuw"),
                    @"\s*(?:[e\;\-\/]|en)\s*",     //separators
                    maybe(oneof(Lookup <EnumDatePrefix> .Patterns(language), "prefix2") + SPACE),
                    group(@"\d+", "centuryMax"),
                    oneof(new string[] { "e", "ste", "de" }),
                    SPACE,
                    "eeuw",
                    maybe(SPACE + oneof(Lookup <EnumDateSuffix> .Patterns(language), "suffix")),
                    END
                    );
                break;
            }

            default:
            {
                pattern = String.Concat(
                    START,                                                                        // ^
                    maybe(DateCirca.Pattern(language) + SPACE),
                    maybe(oneof(Lookup <EnumDatePrefix> .Patterns(language), "prefix1") + SPACE), //
                    group(@"\d+", "centuryMin"),                                                  // (?<centuryMin>\d+)
                    oneof(new string[] { "st", "nd", "rd", "th" }),
                    @"\s*(?:[e\;\-\/]|to)\s*",                                                    // separator
                    maybe(oneof(Lookup <EnumDatePrefix> .Patterns(language), "prefix2") + SPACE),
                    group(@"\d+", "centuryMax"),                                                  // (?<centuryMax>\d+)
                    oneof(new string[] { "st", "nd", "rd", "th" }),
                    SPACE,
                    "century",                                                                   // century
                    maybe(SPACE + oneof(Lookup <EnumDateSuffix> .Patterns(language), "suffix")), // (?:\s(?<suffix>A\.?D\.?|B\.?C\.?))?
                    END                                                                          // $
                    );
                break;
            }
            }

            return(pattern);
        }
コード例 #9
0
        private static string GetPattern(EnumLanguage language = EnumLanguage.NONE)
        {
            string pattern = "";

            switch (language)
            {
            case EnumLanguage.CY:
            {
                pattern = String.Concat(
                    START,
                    maybe(DateCirca.Pattern(language) + SPACE),
                    maybe(oneof(Lookup <EnumDatePrefix> .Patterns(language), "prefix") + SPACE),
                    group(@"\d+", "century"),
                    oneof(new string[] { "af", @"a?il", "ain", "ydd", @"f?ed", "eg" }),
                    SPACE,
                    "[cg]anrif",
                    maybe(SPACE + oneof(Lookup <EnumDateSuffix> .Patterns(language), "suffix")),
                    END
                    );
                break;
            }

            case EnumLanguage.DE:
            {
                pattern = String.Concat(
                    START,
                    maybe(DateCirca.Pattern(language) + SPACE),
                    maybe(oneof(Lookup <EnumDatePrefix> .Patterns(language), "prefix") + SPACE),
                    group(@"\d+", "century"),
                    @"\.",
                    SPACE,
                    "Jahrhundert",
                    END
                    );
                break;
            }

            case EnumLanguage.IT:
            {
                // ^(?:(?:C(?:\.|irca)|Intorno al)\s)?(?<millennium>[MCDLXVI]+)\s?(?:esimo|mo|°|º)?\smillennio(?:\s(?<suffix>a\.?C\.?|d\.?C\.?))?$
                // eg XI secolo | secolo XI | XIesimo secolo | XImo secolo | 11 ° secolo
                pattern = String.Concat(
                    START,                                              // ^
                    maybe(DateCirca.Pattern(language) + SPACE),         // (?:(?:C(?:\.|irca)|Intorno al)\s)?
                    maybe(oneof(Lookup <EnumDatePrefix> .Patterns(language), "prefix") + SPACE),
                    oneof(new string[] {
                        String.Concat(
                            @"sec(?:\.|olo)",
                            SPACE,
                            group(ROMAN, "century")
                            ),
                        String.Concat(
                            group(ROMAN, "century"),
                            SPACE,
                            @"sec(?:\.|olo)"
                            ),
                        String.Concat(
                            group(@"\d+", "century"),
                            maybe(SPACE),
                            maybe(oneof(new string[] { "esimo", "mo", "°", "º" })),          // (?:esimo|mo|°|º)?
                            SPACE,
                            @"sec(?:\.|olo)"
                            ),
                        group(ROMAN, "century")
                    }),
                    maybe(SPACE + oneof(Lookup <EnumDateSuffix> .Patterns(language), "suffix")), // (?:\s(?<suffix>a\.?C\.?|d\.?C\.?))?
                    END                                                                          // $
                    );
                break;
            }

            case EnumLanguage.FR:
            {
                // 11e siècle | XIe siècle av. J-C. | apr. J-C.
                // pattern = @"^(?<century>[MCDLXVI]+|\d+)e\s+siècle(?:\s+(?<suffix>av\.\sJ\-C\.|apr\.\sJ\-C\.))?$";
                pattern = String.Concat(
                    START,
                    maybe(DateCirca.Pattern(language) + SPACE),
                    maybe(oneof(Lookup <EnumDatePrefix> .Patterns(language), "prefix") + SPACE),
                    oneof(new string[] { ROMAN, @"\d+" }, "century"),
                    oneof(new string[] { "è?[mr]e", "er", "re", "[eè]", "n?de?", "o" }),
                    SPACE,
                    @"s(?:\.|iècle)",
                    maybe(SPACE + oneof(Lookup <EnumDateSuffix> .Patterns(language), "suffix")),
                    END
                    );
                break;
            }

            case EnumLanguage.ES:
            {
                // XI siglo | siglo XI
                //pattern = @"^(?:siglo\s+)?(?<century>[MCDLXVI]+|\d+)(?:\s+siglo)?$";
                pattern = String.Concat(
                    START,
                    maybe(DateCirca.Pattern(language) + SPACE),
                    maybe(oneof(Lookup <EnumDatePrefix> .Patterns(language), "prefix") + SPACE),
                    maybe("Siglo" + SPACE),
                    oneof(new string[] { ROMAN, @"\d+" }, "century"),
                    maybe(SPACE + "Siglo"),
                    maybe(SPACE + oneof(Lookup <EnumDateSuffix> .Patterns(language), "suffix")),
                    END
                    );
                break;
            }

            case EnumLanguage.NL:
            {
                pattern = String.Concat(
                    START,
                    maybe(DateCirca.Pattern(language) + SPACE),
                    maybe(oneof(Lookup <EnumDatePrefix> .Patterns(language), "prefix") + SPACE),
                    group(@"\d+", "century"),
                    oneof(new string[] { "e", "ste", "de" }),
                    SPACE,
                    "eeuw",
                    maybe(SPACE + oneof(Lookup <EnumDateSuffix> .Patterns(language), "suffix")),
                    END
                    );
                break;
            }

            case EnumLanguage.SV:
            {
                // 1700-talet | 18:e århundradet | 18:e seklet | 1700-tal
                pattern = String.Concat(
                    START,
                    maybe(DateCirca.Pattern(language) + SPACE),
                    maybe(oneof(Lookup <EnumDatePrefix> .Patterns(language), "prefix") + SPACE),
                    oneof(new string[] {
                        String.Concat(
                            group(@"\d+", "century"),
                            oneof(new string[] { ":a", ":e" }),
                            SPACE,
                            oneof(new string[] { "århundradet", "seklet" })
                            ),
                        String.Concat(
                            group(@"\d+00", "century"),
                            @"-tal",
                            maybe("et")
                            )
                    }),
                    maybe(SPACE + oneof(Lookup <EnumDateSuffix> .Patterns(language), "suffix")),
                    END
                    );
                break;
            }

            default:
            {
                //pattern = @"^(?:c(?:irca|\.)?\s+)?(?<centuryNo>\d+)(?:st|nd|rd|th)\s+(?:century|centuries)(?:\s+(?<suffix>ad|bc|ce))?$";
                pattern = String.Concat(
                    START,                                                                       // ^
                    maybe(DateCirca.Pattern(language) + SPACE),
                    maybe(oneof(Lookup <EnumDatePrefix> .Patterns(language), "prefix") + SPACE), // (?:(?:C(?:\.|irca)|Intorno al)\s)?
                    group(@"\d+", "century"),                                                    // (?<century>\d+)
                    oneof(new string[] { "st", "nd", "rd", "th" }),
                    SPACE,
                    "century",                                                                   // century
                    maybe(SPACE + oneof(Lookup <EnumDateSuffix> .Patterns(language), "suffix")), // (?:\s(?<suffix>A\.?D\.?|B\.?C\.?))?
                    END                                                                          // $
                    );
                break;
            }
            }
            return(pattern);
        }
コード例 #10
0
        private static string GetPattern(EnumLanguage language = EnumLanguage.NONE)
        {
            string pattern = "";

            switch (language)
            {
            case EnumLanguage.CY:
            {
                pattern = String.Concat(
                    START,
                    maybe(DateCirca.Pattern(language) + SPACE),
                    maybe(oneof(Lookup <EnumDatePrefix> .Patterns(language), "prefix") + SPACE),
                    group(@"\d+", "millennium"),
                    oneof(new string[] { "af", @"a?il", "ain", "ydd", @"f?ed", "eg" }),
                    SPACE,
                    "mileniwm",
                    maybe(SPACE + oneof(Lookup <EnumDateSuffix> .Patterns(language), "suffix")),
                    END
                    );
                break;
            }

            case EnumLanguage.FR:
            {
                pattern = String.Concat(
                    START,
                    maybe(DateCirca.Pattern(language) + SPACE),
                    maybe(oneof(Lookup <EnumDatePrefix> .Patterns(language), "prefix") + SPACE),
                    oneof(new string[] { ROMAN, @"\d+" }, "millennium"),
                    oneof(new string[] { "è?[mr]e", "er", "re", "[eè]", "n?de?", "o" }),
                    SPACE,
                    "millénaire",
                    maybe(SPACE + oneof(Lookup <EnumDateSuffix> .Patterns(language), "suffix")),
                    END
                    );
                break;
            }

            case EnumLanguage.IT:
                // ^(?:(?:C(?:\.|irca)|Intorno al)\s)?(?<millennium>[MCDLXVI]+)\s?(?:esimo|mo|°|º)?\smillennio(?:\s(?<suffix>a\.?C\.?|d\.?C\.?))?$
                pattern = String.Concat(
                    START,
                    maybe(DateCirca.Pattern(language) + SPACE),
                    maybe(oneof(Lookup <EnumDatePrefix> .Patterns(language), "prefix") + SPACE),     // (?:(?:C(?:\.|irca)|Intorno al)\s)?
                    oneof(new string[] {
                    String.Concat(
                        "millennio",
                        SPACE,
                        oneof(new string[] { ROMAN, @"\d+" }, "millennium"),
                        maybe(SPACE),
                        maybe(oneof(new string[] { "esimo", "mo", "°", "º" }))         // (?:esimo|mo|°|º)?
                        ),
                    String.Concat(
                        oneof(new string[] { ROMAN, @"\d+" }, "millennium"),
                        maybe(SPACE),
                        maybe(oneof(new string[] { "esimo", "mo", "°", "º" })),         // (?:esimo|mo|°|º)?
                        "millennio"
                        )
                }),
                    maybe(SPACE + oneof(Lookup <EnumDateSuffix> .Patterns(language), "suffix")), // (?:\s(?<suffix>a\.?C\.?|d\.?C\.?))?
                    END                                                                          // $
                    );
                break;

            default:
                // ^(?:(?:C(?:\.|irca)|around|approx(?:\.|imately))\s)?(?<millennium>\d+)(?:st|nd|rd|th)\smillennium(?:\s(?<suffix>AD|BC|CE|BP))?$
                pattern = String.Concat(
                    START,
                    maybe(DateCirca.Pattern(language) + SPACE),
                    maybe(oneof(Lookup <EnumDatePrefix> .Patterns(language), "prefix") + SPACE), // (?:(?:C(?:\.|irca)|around|approx(?:\.|imately))\s)?
                    group(@"\d+", "millennium"),                                                 // (?<millennium>\d+)
                    oneof(new string[] { "st", "nd", "rd", "th" }),                              // (?:st|nd|rd|th)
                    SPACE,                                                                       // \s
                    "millennium",                                                                // millennium
                    maybe(SPACE + oneof(Lookup <EnumDateSuffix> .Patterns(language), "suffix")), // (?:\s(?<suffix>AD|BC|CE|BP))?
                    END                                                                          // $
                    );
                break;
            }
            return(pattern);
        }
コード例 #11
0
        private static string GetPattern(EnumLanguage language = EnumLanguage.NONE)
        {
            string pattern = "";

            switch (language)
            {
            case EnumLanguage.CY:
                pattern = String.Concat(
                    START,
                    maybe(DateCirca.Pattern(language) + SPACE),
                    maybe(oneof(Lookup <EnumDatePrefix> .Patterns(language), "prefix") + SPACE),
                    oneof(Lookup <EnumOrdinal> .Patterns(language), "ordinal"),
                    SPACE,
                    "mileniwm",
                    maybe(SPACE + oneof(Lookup <EnumDateSuffix> .Patterns(language), "suffix")),
                    END
                    );
                break;

            case EnumLanguage.FR:
                pattern = String.Concat(
                    START,
                    maybe(DateCirca.Pattern(language) + SPACE),
                    maybe(oneof(Lookup <EnumDatePrefix> .Patterns(language), "prefix") + SPACE),
                    oneof(Lookup <EnumOrdinal> .Patterns(language), "ordinal"),
                    SPACE,
                    "millénaire",
                    maybe(SPACE + oneof(Lookup <EnumDateSuffix> .Patterns(language), "suffix")),
                    END
                    );
                break;

            case EnumLanguage.IT:
                pattern = String.Concat(
                    START,                                         // ^
                    maybe(DateCirca.Pattern(language) + SPACE),    // (?:(?:C(?:\.|irca)|Intorno al)\s)?
                    maybe(oneof(Lookup <EnumDatePrefix> .Patterns(language), "prefix") + SPACE),
                    oneof(new string[] {
                    @"millennio\s" + oneof(Lookup <EnumOrdinal> .Patterns(language), "ordinal"),
                    oneof(Lookup <EnumOrdinal> .Patterns(language), "ordinal") + @"\smillennio"
                }),
                    maybe(SPACE + oneof(Lookup <EnumDateSuffix> .Patterns(language), "suffix")), // (?:\s(?<suffix>a\.?C\.?|d\.?C\.?))?
                    END                                                                          // $
                    );
                break;

            default:
                pattern = String.Concat(
                    START,                                                                       // ^
                    maybe(DateCirca.Pattern(language) + SPACE),
                    maybe(oneof(Lookup <EnumDatePrefix> .Patterns(language), "prefix") + SPACE), // (?:
                    oneof(Lookup <EnumOrdinal> .Patterns(language), "ordinal"),
                    SPACE,
                    "millennium",
                    maybe(SPACE + oneof(Lookup <EnumDateSuffix> .Patterns(language), "suffix")),
                    END
                    );
                break;
            }
            return(pattern);
        }
コード例 #12
0
ファイル: RxDecade.cs プロジェクト: cbinding/timespans
        private static string GetPattern(EnumLanguage language)
        {
            string pattern = "";

            switch (language)
            {
            case EnumLanguage.CY:
                // e.g. 1550au
                pattern = String.Concat(
                    START,                           // ^
                    maybe(DateCirca.Pattern(language) + SPACE),
                    group(@"\d+0", "decade"),        // (?<decade>\d+0)
                    @"au",
                    END
                    );
                break;

            case EnumLanguage.DE:
                // ^(?:Um\s)?(?<decade>\d+0)\'?s$
                // e.g. Um 1850's
                pattern = String.Concat(
                    START,                                      // ^
                    maybe(DateCirca.Pattern(language) + SPACE), // (?:Um\s)?
                    group(@"\d+0", "decade"),                   // (?<decade>\d+0)
                    @"\'?s",                                    // \'?s
                    END                                         // $
                    );
                break;

            case EnumLanguage.FR:
                // ^(?:Vers\s)?(?<decade>\d+0)\'?s$
                // e.g. Vers 1850's
                pattern = String.Concat(
                    START,                                      // ^
                    maybe(DateCirca.Pattern(language) + SPACE), // (?:Vers\s)?
                    @"les années\s",
                    group(@"\d+0", "decade"),                   // (?<decade>\d+0)
                    END                                         // $
                    );
                break;

            case EnumLanguage.NL:
                // ^(?:Circa\s)?(?<decade>\d+0)\'?s$ (not right)
                pattern = String.Concat(
                    START,                                      // ^
                    maybe(DateCirca.Pattern(language) + SPACE), // (?:Circa\s)
                    group(@"\d+0", "decade"),
                    @"\'?s",
                    END
                    );
                break;

            case EnumLanguage.SV:
                // ^(?:C(?:\.|irka)?\s)?(?<decade>\d+0)\-talet$
                pattern = String.Concat(
                    START,
                    maybe(DateCirca.Pattern(language) + SPACE),
                    group(@"\d+0", "decade"),
                    @"\-talet",
                    END
                    );
                break;

            case EnumLanguage.IT:
                // ^(?:Intorno\sal|circa)?\s*decennio\s(?<decade>\d+[1-9]0)(?:esimo)?$
                // e.g. "Intorno al decennio 1850esimo" => "around the decade of 1850's"
                pattern = String.Concat(
                    START,
                    maybe(DateCirca.Pattern(language) + SPACE),
                    @"decennio\s",
                    group(@"\d+0", "decade"),
                    maybe("esimo"),
                    END
                    );
                break;

            default:
                // ^(?:c(?:irca|\.|)\s*)?(?<decade>\d+[1-9]0)\'?s$
                // e.g. "1850s" "circa 1920's"
                pattern = String.Concat(
                    START,
                    maybe(DateCirca.Pattern(language) + SPACE),
                    group(@"\d+0", "decade"),
                    @"\'?s",
                    END
                    );
                break;
            }

            return(pattern);
        }