コード例 #1
0
        public async void getAntonyms()
        {
            string lang;

            if (SelectedInput.Equals("English"))
            {
                lang = "en";
            }
            else
            {
                lang = " ";
            }
            var uri = "/api/v1/entries/" + lang + "/" + Word + "/antonyms";

            if (SelectedInput == null)
            {
                DependencyService.Get <IMessage>().LongAlert("Please select language!");
            }
            else
            {
                AntResult = await service.GetSynonymsAsync(uri);

                if (AntResult != null)
                {
                    setAntonymValues();
                }
                else
                {
                    Antonyms.Clear();
                }
            }
        }
コード例 #2
0
        private async void SentenceClick(string obj)
        {
            Translations.Clear();
            Synonyms.Clear();
            Antonyms.Clear();
            Sentences.Clear();

            var reply = await new OxfordDictionaryMVVMService().GetSentenceAsync(chosenSrc, obj);

            if (reply != null)
            {
                foreach (var result in reply.results)
                {
                    foreach (var lexicalEntry in result.lexicalEntries)
                    {
                        foreach (var sentence in lexicalEntry.sentences)
                        {
                            Sentences.Add(sentence.text);
                        }
                    }
                }
            }

            // exception handling
            else if (ChosenSrc.ToString() != "en" && ChosenSrc.ToString() != "es")
            {
                var messageDialog = new MessageDialog("Sentences are not supported in this language at present.")
                {
                    Title = "Warning"
                };
                messageDialog.Commands.Add(new UICommand("Close"));

                await messageDialog.ShowAsync();
            }
            else
            {
                var messageDialog = new MessageDialog("There is no example sentence for that word!")
                {
                    Title = "Warning"
                };

                messageDialog.Commands.Add(new UICommand("Close"));

                await messageDialog.ShowAsync();
            }
        }
コード例 #3
0
 public void setAntonymValues()
 {
     Antonyms.Clear();
     foreach (var i in AntResult.results)
     {
         foreach (var j in i.lexicalEntries)
         {
             var antonym = new Antonym();
             antonym.Type         = j.lexicalCategory;
             antonym.AntonymItems = "";
             foreach (var k in j.entries)
             {
                 foreach (var l in k.senses)
                 {
                     foreach (var item in l.antonyms)
                     {
                         antonym.AntonymItems += "\n" + item.text;
                     }
                 }
             }
             Antonyms.Add(antonym);
         }
     }
 }
コード例 #4
0
        private async void TranslateClick(string obj)
        {
            Translations.Clear();
            Synonyms.Clear();
            Antonyms.Clear();
            Sentences.Clear();

            var reply = await new OxfordDictionaryMVVMService().GetTranslationAsync(chosenSrc, obj, ChosenDest);

            if (reply != null)
            {
                foreach (var result in reply.results)
                {
                    foreach (var lexicalEntry in result.lexicalEntries)
                    {
                        foreach (var entry in lexicalEntry.entries)
                        {
                            foreach (var sense in entry.senses)
                            {
                                if (sense.translations == null) // exception handling
                                {
                                    return;
                                }
                                foreach (var translation in sense.translations)
                                {
                                    Translations.Add(translation.text);
                                }
                            }
                        }
                    }
                }
            } // exception handling
            else if (ChosenSrc == null)
            {
                var messageDialog = new MessageDialog("Choose a source language!")
                {
                    Title = "Error"
                };

                messageDialog.Commands.Add(new UICommand("Close"));

                await messageDialog.ShowAsync();
            }
            else if (ChosenDest == null)
            {
                var messageDialog = new MessageDialog("Choose a destination language!")
                {
                    Title = "Error"
                };

                messageDialog.Commands.Add(new UICommand("Close"));

                await messageDialog.ShowAsync();
            }
            else
            {
                var messageDialog = new MessageDialog("There is no translation for that word!")
                {
                    Title = "Warning"
                };

                messageDialog.Commands.Add(new UICommand("Close"));

                await messageDialog.ShowAsync();
            }
        }
コード例 #5
0
        private async void AntonymClick(string obj)
        {
            Translations.Clear();
            Synonyms.Clear();
            Antonyms.Clear();
            Sentences.Clear();

            var reply = await new OxfordDictionaryMVVMService().GetAntonymAsync(chosenSrc, obj);

            if (reply != null)
            {
                foreach (var result in reply.results)
                {
                    foreach (var lexicalEntry in result.lexicalEntries)
                    {
                        foreach (var entry in lexicalEntry.entries)
                        {
                            foreach (var sense in entry.senses)
                            {
                                foreach (var anonym in sense.antonyms)
                                {
                                    Antonyms.Add(anonym.text);
                                }
                            }
                        }
                    }
                }
            }

            // exception handling
            else if (ChosenSrc == null)
            {
                var messageDialog = new MessageDialog("Choose a source language!")
                {
                    Title = "Error"
                };

                messageDialog.Commands.Add(new UICommand("Close"));

                await messageDialog.ShowAsync();
            }
            else if (ChosenSrc.ToString() != "en")
            {
                var messageDialog = new MessageDialog("Antonyms are not supported in this language at present.")
                {
                    Title = "Warning"
                };
                messageDialog.Commands.Add(new UICommand("Close"));

                await messageDialog.ShowAsync();
            }
            else
            {
                var messageDialog = new MessageDialog("There is no antonym for that word!")
                {
                    Title = "Warning"
                };

                messageDialog.Commands.Add(new UICommand("Close"));

                await messageDialog.ShowAsync();
            }
        }