Exemple #1
0
        private static Dictionaries.Keys GetDictionaryKey(string arg, Dictionaries.Keys nullValue)
        {
            // should be of form /D=X
            if (arg.Length == 4)
            {
                // look at last character
                switch (arg[3])
                {
                case 'D':
                case 'F':
                    return(Dictionaries.Keys.dictionary);

                case 'E':
                case '8':
                    return(Dictionaries.Keys.eight_dictionary);

                case 'H':
                case '2':
                    return(Dictionaries.Keys.half_dictionary);

                case 'Q':
                case '4':
                    return(Dictionaries.Keys.quarter_dictionary);

                case 'S':
                case 'T':
                    return(Dictionaries.Keys.very_small_test_dictionary);

                default:
                    break;
                }
            }
            return(nullValue);
        }
Exemple #2
0
        private SocialWordNetwork TestConstructor(Dictionaries.Keys key)
        {
            SocialWordNetwork network = new SocialWordNetwork(key);

            // check keys match
            Assert.AreEqual(key, network.Key, "Key mismatch on creating SocialWordNetwork");
            return(network);
        }
Exemple #3
0
        private void TestDictionary(Dictionaries.Keys key)
        {
            var dict = Dictionaries.Get(key);

            Assert.IsNotNull(dict, String.Format("Dictionary {0} is null", key));
            Assert.IsInstanceOfType(dict, typeof(string[]), String.Format("Dictionary {0} is not a string array", key));
            int expectedLength = GetExpectedLength(key);

            Assert.AreEqual(expectedLength, dict.Length, String.Format("Dictionary {0} has wrong length", key));
        }
Exemple #4
0
        internal static int GetExpectedLength(Dictionaries.Keys key)
        {
            switch (key)
            {
            case Dictionaries.Keys.dictionary:
                return(178692);

            case Dictionaries.Keys.eight_dictionary:
                return(22339);

            case Dictionaries.Keys.half_dictionary:
                return(89346);

            case Dictionaries.Keys.quarter_dictionary:
                return(44674);

            case Dictionaries.Keys.very_small_test_dictionary:
                return(12);
            }
            return(-1);
        }
Exemple #5
0
        private void TestNetwork(Dictionaries.Keys key)
        {
            SocialWordNetwork network = TestConstructor(key);

            TestWordCount(network);
        }
 public SocialWordNetwork(Dictionaries.Keys key)
 {
     // record the key
     Key = key;
 }
Exemple #7
0
        public static void Main(string commandName, string[] args)
        {
            // set defaults
            Dictionaries.Keys dict = Dictionaries.Keys.dictionary;
            string            word = "LISTY";
            bool showWords         = false;
            bool showElapsed       = false;

            // parse command line arguments if present
            if (args != null && args.Length > 0)
            {
                for (int i = 0; i < args.Length; i++)
                {
                    string arg = args[i].ToUpper();
                    // check first two chars of arg for switch character
                    switch (arg.Substring(0, 2))
                    {
                    case @"/H":
                    case @"/?":
                        // display help
                        PrintHelp(commandName);
                        return;

                    case @"/D":
                        // get dictionary
                        dict = GetDictionaryKey(arg, dict);
                        break;

                    case @"/V":
                        // verbose mode
                        showWords = true;
                        break;

                    case @"/E":
                        // show elapsed times
                        showElapsed = true;
                        break;

                    default:
                        // not a switch
                        word = arg;
                        break;
                    }
                }
            }

            // write output
            Console.WriteLine("Extended Network of {0} in {1}.txt", word, dict);

            // create network
            var network = new SocialWordNetwork(dict);

            Console.WriteLine("  Dictionary Size:   {0}", network.Words.Length);
            // get extended network
            var extended = network.GetExtendedNetwork(word);

            // write error if not found
            if (extended.Length == 0)
            {
                Console.WriteLine("  ERROR:             {0} not found in {1}", word, dict);
            }
            // write size
            Console.WriteLine("  Network Size:      {0}", extended.Length);
            // output words if requested
            if (showWords && extended.Length > 0)
            {
                Console.WriteLine("  Network Members:");
                Console.WriteLine("    {");
                for (int i = 0; i < extended.Length; i++)
                {
                    Console.WriteLine("      {0}{1}", network.Words[extended[i]], i + 1 == extended.Length ? String.Empty : ",");
                }
                Console.WriteLine("    }");
                // output size again if list is long
                if (extended.Length > 20)
                {
                    Console.WriteLine("  Network Size:      {0}", extended.Length);
                }
            }
            // output elapsed times if requested
            if (showElapsed)
            {
                Console.WriteLine("  Elapsed Times:");
                WriteElapsedTime("LoadDictionary:      ", network.ElapsedLoadDictionary);
                WriteElapsedTime("BuildNetwork:        ", network.ElapsedBuildNetwork);
                WriteElapsedTime("GetExtendedNetwork:  ", network.ElapsedGetExtendedNetwork);
            }

            Console.WriteLine();
            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }