Esempio n. 1
0
        //private IYearSpanParser parser = new YearSpanParser();

        private void compare(String input, IYearSpan expected, EnumLanguage language)
        {
            //IInterval<int> result = parser.Parse(input);
            IYearSpan result = YearSpan.Parse(input, language);

            compare(result, expected);
        }
Esempio n. 2
0
        public void TestCardinalCenturyBC_IT()
        {
            string    input    = @"sec. VIII a.C.";
            IYearSpan expected = new YearSpan(-800, -701, input);
            IYearSpan result   = YearSpan.Parse(input, EnumLanguage.IT);

            compare(result, expected);
        }
Esempio n. 3
0
 private void compare(IYearSpan input, IYearSpan expected)
 {
     //Assert.AreEqual(expected, result, "spans are not equal");
     Assert.IsNotNull(input, "input should not be null");
     Assert.IsNotNull(expected, "expected should not be null");
     Assert.AreEqual(expected.min, input.min, "unexpected min value");
     Assert.AreEqual(expected.max, input.max, "unexpected max value");
 }
Esempio n. 4
0
        public void Test1DigitMaxYear()
        {
            string    input    = @"1521-7";
            IYearSpan expected = new YearSpan(1521, 1527, input);
            //IInterval<int> result = parser.Parse(input);
            IYearSpan result = YearSpan.Parse(input, EnumLanguage.EN);

            compare(expected, result);
        }
Esempio n. 5
0
 /// <summary>Attempt to Parse a <c cref="YearSpan">YearSpan</c> from a <c cref="System.String">String</c> input value</summary>
 /// <param name="s">Input <c cref="System.String">String</c> to be parsed</param>
 /// <param name="result">Output <c cref="YearSpan">YearSpan</c> if successful, <c>null</c> otherwise</param>
 /// <returns>Returns <c>true</c> if parse was successful, <c>false</c> otherwise</returns>
 /// <exception cref="System.ArgumentNullException">Thrown when s is null</exception>
 public static bool TryParse(string s, EnumLanguage language, out IYearSpan result)
 {
     if (s == null)
     {
         throw new System.ArgumentNullException("s", "null input value");
     }
     result = Parse(s, language);
     return(result == null ? false : true);
 }
Esempio n. 6
0
        public static IYearSpan[] Parse(string[] input, EnumLanguage language)
        {
            // get list of parser instances
            //IEnumerable<IYearSpanParser> yearSpanParsers = getParserInstances();
            //IEnumerable<IMatcher<IYearSpan>> yearSpanParsers = getParserInstances();
            System.Collections.Generic.IList <IYearSpan> results = new List <IYearSpan>();

            foreach (string s in input)
            {
                IYearSpan span = Parse(s, language);
                results.Add(span != null ? span : new YearSpan(0, s));


                // try each available parser until first match
                //foreach (IYearSpanParser p in yearSpanParsers)

                /*foreach (IMatcher<IYearSpan> p in yearSpanParsers)
                 * {
                 *  if (p != null)
                 *  {
                 *      if (p.IsMatch(s, language))
                 *      {
                 *          IYearSpan result = p.Match(s, language);
                 *          if (result != null)
                 *          {
                 *              span = result;
                 *              break;
                 *          }
                 *      }
                 *  }
                 * }*/

                /* IList<Type> matchers = getMatcherTypes();
                 * foreach (IMatcher<IYearSpan> m in matchers)
                 * {
                 *   if (m.IsMatch(s, language))
                 *   {
                 *       IYearSpan result = m.Match(s, language);
                 *       if (result != null)
                 *       {
                 *           span = result;
                 *           break;
                 *       }
                 *   }
                 * }
                 * results.Add(span);*/
            }
            return(results.ToArray());
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            // display application name and version in console title

            Console.Title = appFullName;

            // variables to hold values of input args
            //bool showHelp = false;
            Char   delimiter = '\t';  // text delimiter character (default = tab)
            String iFileName = "";    // text input file name with path
            String oFileName = "";    // output file name including path
            String language  = "en";  // language of input data (default 'en')

            var p = new Mono.Options.OptionSet()
            {
                { "i|in|input=", "name of input data {FILE}", v => { if (v != null)
                                                                     {
                                                                         iFileName = v.Trim();
                                                                     }
                  } },
                { "o|out|output=", "name of output {FILE}", v => { if (v != null)
                                                                   {
                                                                       oFileName = v.Trim();
                                                                   }
                  } },
                { "d|delim|delimiter=", "output delimiter (default=tab) {STRING}", v => { if (v != null)
                                                                                          {
                                                                                              delimiter = v.Trim().First();
                                                                                          }
                  } },
                { "l|lang|language=", "language of input data (default=en) {STRING}", v => { if (v != null)
                                                                                             {
                                                                                                 language = v.Trim().ToLower();
                                                                                             }
                  } },
                { "h|?|help", v => showHelp() }
            };

            // validate input args
            try
            {
                p.Parse(args);
            }
            catch (Mono.Options.OptionException e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine("Type {0} --help' for more information", appName);
                Console.WriteLine("Hit any key to exit");
                Console.ReadKey();
                return;
            }


            try
            {
                DateTime started = DateTime.Now;

                // read values to be matched from the input file
                Console.WriteLine("{0} started {1}", appFullName, started.ToLongTimeString());
                Console.WriteLine("Reading from input file '{0}'", iFileName);
                IList <string> outputLines = new List <string>();

                // do the processing
                foreach (string line in System.IO.File.ReadLines(iFileName))
                {
                    if (line.Trim().Length > 0)
                    {
                        IYearSpan result = YearSpan.Parse(line, language);

                        outputLines.Add(String.Format("{1}{0}{2}{0}{3}",
                                                      delimiter,
                                                      result.label.Replace(delimiter, ' '),
                                                      result.min == int.MaxValue ? "" : result.min.ToString("+0000;-0000"),
                                                      result.max == int.MaxValue ? "" : result.max.ToString("+0000;-0000")
                                                      ));
                    }
                }

                // Write how long the process took
                TimeSpan elapsed = DateTime.Now.Subtract(started);
                Console.WriteLine("Processed {0} records [time taken: {1:00}:{2:00}:{3:00}.{4:000}]",
                                  outputLines.Count,
                                  (int)elapsed.TotalHours,
                                  elapsed.Minutes,
                                  elapsed.Seconds,
                                  elapsed.Milliseconds
                                  );

                // finally write the results to the (tab delimited) output file
                if (oFileName.Trim() == "")
                {
                    oFileName = iFileName.Trim() + ".out.txt";
                }
                Console.WriteLine("Writing results to output file '{0}'", oFileName);
                System.IO.File.WriteAllLines(oFileName, outputLines, Encoding.UTF8);
                Console.WriteLine("Finished");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: {0}", ex.Message);
                Console.WriteLine("Type {0} --help' for more information", appName);
                Console.WriteLine("Hit any key to exit");
                Console.ReadKey();
            }

            // don't allow console to disappear automatically
            //Console.WriteLine("Hit any key to exit");
            //Console.ReadKey();
        }