Exemplo n.º 1
0
        public string grabPossiblePunSentences(string currentSentence)
        {
            try
            {
                java.io.InputStream modelIn = new java.io.FileInputStream(@"C:\en-token.bin");
                TokenizerModel model = new TokenizerModel(modelIn);

                Tokenizer tokenizer = new TokenizerME(model);

                string[] words = tokenizer.tokenize(currentSentence);
                List<string> possibleSentences = new List<string>();

                Homonyms homonyms = new Homonyms();

                for (int i = 0; i < words.Length; i++)
                {
                    System.Console.WriteLine();
                    Homonym homonym = homonyms.findWordInList(words[i]);

                    if (homonym.homonyms == null)
                    {

                    }

                    else
                    {
                        string possibleSentence = "";
                        for (int r = 0; r < words.Length; r++)
                        {
                            if (words[i].Equals(words[r]))
                            {
                                Random random = new Random();
                                int randomNumber = random.Next(homonym.homonyms.Length);
                                possibleSentence += " " + homonym.homonyms[randomNumber];
                            }

                            else
                            {
                                possibleSentence += " " + words[r];
                            }
                        }
                        possibleSentences.Add(possibleSentence);
                    }
                }
                currentSentence = choosePossiblePunSentence(currentSentence, possibleSentences);
            }

            catch (Exception e)
            {

            }

            return currentSentence;
        }
Exemplo n.º 2
0
        public void giveDefinitionAndHomonym(string currentSentence)
        {
            try
            {
                java.io.InputStream modelIn = new java.io.FileInputStream(@"C:\en-token.bin");
                TokenizerModel model = new TokenizerModel(modelIn);

                Tokenizer tokenizer = new TokenizerME(model);

                string[] words = tokenizer.tokenize(currentSentence);

                Homonyms homonyms = new Homonyms();

                for (int i = 0; i < words.Length; i++)
                {
                    System.Console.WriteLine();
                    Homonym homonym = homonyms.findWordInList(words[i]);

                    if (homonym.homonyms == null)
                    {
                        System.Console.WriteLine("No homonyms found for: " + words[i]);
                    }

                    else
                    {
                        List<string> selectedHomonyms = homonym.selectedHomonyms();

                        System.Console.WriteLine("Homonyms are: " + words[i]);
                        foreach (string selectedWord in selectedHomonyms)
                        {
                            System.Console.Write(selectedWord + ",");
                        }
                    }

                    System.Console.WriteLine();
                    System.Console.WriteLine("Definition for: " + words[i]);
                    using (WebClient client = new WebClient())
                    {
                        string line = client.DownloadString("http://api.wordnik.com/v4/word.json/" + words[i] + "/definitions?limit=200&includeRelated=true&useCanonical=false&includeTags=false&api_key=a2a73e7b926c924fad7001ca3111acd55af2ffabf50eb4ae5");
                        if (!line.Equals("[]"))
                        {
                            string[] lines1 = System.Text.RegularExpressions.Regex.Split(line, "\"text\":\"");
                            string[] lines2 = System.Text.RegularExpressions.Regex.Split(lines1[1], "\",\"sequence\"[\\W\\w]+");
                            System.Console.WriteLine(lines2[0]);
                        }
                        else
                        {
                            System.Console.WriteLine("Definition cannot be found, word is mispelled or doesn't exist within our current data");
                        }
                    }

                }
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e.Message);
            }
        }