Exemplo n.º 1
0
        static void Main(string[] args)
        {
            bool wordmode = false;
            int n = 1;
            string sourcetextfile = null;

            // Read arguments
            if(args.Length == 0) { ShowUsage(); return; }
            for (int i = 0; i < args.Length; i++)
            {
                if (args[i] == "-i")
                {
                    if (args.Length < i + 2) { Console.Error.WriteLine("\nThe -i option requires a input file path."); ShowUsage(); return; };
                    sourcetextfile = args[++i];
                    if (!File.Exists(sourcetextfile)) { Console.Error.WriteLine("\nThe file {0} could not be found. Please check path.", sourcetextfile); ShowUsage(); return; }
                }

                if (args[i] == "-n" ) if (args.Length < i + 2 || !int.TryParse(args[++i], out n)) { Console.Error.WriteLine("\nThe -n option requires an integer."); ShowUsage(); return; };
                if (args[i] == "-w") wordmode = true;
                if (args[i] == "-h" || args[i] == "--help" || args[i] == "/?") { ShowUsage(); return; } 

            }

            // Execute ngram generation if required arguments are valid
            if (string.IsNullOrWhiteSpace(sourcetextfile)) { ShowUsage(); return; }
            else
            {
                ngramextraction ngrams = new ngramextraction(sourcetextfile, n, wordmode);
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            bool   wordmode       = false;
            int    n              = 1;
            string sourcetextfile = null;

            // Read arguments
            if (args.Length == 0)
            {
                ShowUsage(); return;
            }
            for (int i = 0; i < args.Length; i++)
            {
                if (args[i] == "-i")
                {
                    if (args.Length < i + 2)
                    {
                        Console.Error.WriteLine("\nThe -i option requires a input file path."); ShowUsage(); return;
                    }
                    ;
                    sourcetextfile = args[++i];
                    if (!File.Exists(sourcetextfile))
                    {
                        Console.Error.WriteLine("\nThe file {0} could not be found. Please check path.", sourcetextfile); ShowUsage(); return;
                    }
                }

                if (args[i] == "-n")
                {
                    if (args.Length < i + 2 || !int.TryParse(args[++i], out n))
                    {
                        Console.Error.WriteLine("\nThe -n option requires an integer."); ShowUsage(); return;
                    }
                }
                ;
                if (args[i] == "-w")
                {
                    wordmode = true;
                }
                if (args[i] == "-h" || args[i] == "--help" || args[i] == "/?")
                {
                    ShowUsage(); return;
                }
            }

            // Execute ngram generation if required arguments are valid
            if (string.IsNullOrWhiteSpace(sourcetextfile))
            {
                ShowUsage(); return;
            }
            else
            {
                ngramextraction ngrams = new ngramextraction(sourcetextfile, n, wordmode);
            }
        }