예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CollinsWord"/> class.
        /// </summary>
        /// <param name="entry">The <see cref="CollinsJsonEnglishDictionaryEntryContentEntry"/> corresponding to this
        /// word.</param>
        /// <param name="id">The unique ID of this word.</param>
        /// <param name="label">The label (word name) of this word.</param>
        /// <param name="url">The URL pointing to the page on the Collins Dictionary Web site where the definition can
        /// be seen.</param>
        public CollinsWord(CollinsJsonEnglishDictionaryEntryContentEntry entry, string id, string label, Uri url)
        {
            if (entry == null)
            {
                throw new ArgumentNullException("entry");
            }

            if (id == null)
            {
                throw new ArgumentNullException("id");
            }

            if (label == null)
            {
                throw new ArgumentNullException("label");
            }

            if (url == null)
            {
                throw new ArgumentNullException("url");
            }

            this._collinsEntry = entry;
            this.EntryId       = id;
            this.Term          = label;
            this.Url           = url;
            this.Level         = new AsyncLazy <LanguageLevelClassification>(async() =>
            {
                return(await WordSearchUtilities.GetMostProbable(await OfflineWord.Search(this.Term, SupportedLanguage.English).ConfigureAwait(false)).Level);
            });
        }
예제 #2
0
파일: EssayExercise.cs 프로젝트: TellOP/APP
        private async Task <IWord> ProcessSingleWord(string cleanToken)
        {
            string msg = "'" + cleanToken + "' ";
            IWord  w;

            if (this.Language == SupportedLanguage.English)
            {
                IList <IWord> offlineWords = await OfflineWord.Search(cleanToken);

                if (offlineWords.Count > 0)
                {
                    w = WordSearchUtilities.GetMostProbable(offlineWords);
                }
                else
                {
                    // TODO: find a better way to add a word that is not found in the database.
                    msg += "SearchCount is zero, so I'm creating a new word with an unclassified part of speech and an unknown language level";
                    w    = new OfflineWord()
                    {
                        Term         = cleanToken,
                        JsonLevel    = LanguageLevelClassification.Unknown,
                        PartOfSpeech = PartOfSpeech.Unclassified,
                        Language     = (string)new SupportedLanguageToLcidConverter().Convert(SupportedLanguage.English, typeof(string), null, CultureInfo.InvariantCulture)
                    };
                }

                Tools.Logger.Log("ProcessSingleWord", msg);
                return(w);
            }
            else if (this.Language == SupportedLanguage.English)
            {
                Tools.Logger.Log("ProcessSingleWord", "Call remote SpanishTagger");
                SpanishPOSTagger    es_tagger = new SpanishPOSTagger(App.OAuth2Account, cleanToken);
                IList <SpanishWord> results   = await es_tagger.CallEndpointAsObjectAsync();

                Tools.Logger.Log("ProcessSingleWord", "Got the results!");
                try
                {
                    return(results.First());
                }
                catch (Exception)
                {
                    return(new OfflineWord()
                    {
                        Term = cleanToken,
                        JsonLevel = LanguageLevelClassification.Unknown,
                        PartOfSpeech = PartOfSpeech.Unclassified,
                        Language = (string)new SupportedLanguageToLcidConverter().Convert(SupportedLanguage.Spanish, typeof(string), null, CultureInfo.InvariantCulture)
                    });
                }
            }

            return(new OfflineWord()
            {
                Term = cleanToken,
                JsonLevel = LanguageLevelClassification.Unknown,
                PartOfSpeech = PartOfSpeech.Unclassified,
                Language = (string)new SupportedLanguageToLcidConverter().Convert(SupportedLanguage.English, typeof(string), null, CultureInfo.InvariantCulture)
            });
        }
예제 #3
0
        private async Task <IWord> ProcessSingleWord(string token)
        {
            IWord  w;
            string cleanToken = await OfflineLemma.RetrieveBase(token);

            if (cleanToken == null)
            {
                cleanToken = token;
            }

            IList <IWord> offlineWords = await OfflineWord.Search(cleanToken);

            if (offlineWords.Count > 0)
            {
                w = WordSearchUtilities.GetMostProbable(offlineWords);
            }
            else
            {
                // TODO: find a better way to add a word that is not found in the database.
                Tools.Logger.Log(this.GetType().Name, "Count is zero, so I'm creating a new word with an unclassified part of speech and an unknown language level");
                w = new OfflineWord()
                {
                    Term         = cleanToken,
                    JSONLevel    = LanguageLevelClassification.Unknown,
                    PartOfSpeech = PartOfSpeech.Unclassified,
                    Language     = (string)new SupportedLanguageToLcidConverter().Convert(SupportedLanguage.USEnglish, typeof(string), null, CultureInfo.InvariantCulture)
                };
            }

            if (this.ExcludeFunctionalWords && (
                    w.PartOfSpeech == PartOfSpeech.ClauseOpener ||
                    w.PartOfSpeech == PartOfSpeech.Conjunction ||
                    w.PartOfSpeech == PartOfSpeech.Determiner ||
                    w.PartOfSpeech == PartOfSpeech.DeterminerPronoun ||
                    w.PartOfSpeech == PartOfSpeech.ExistentialParticle ||
                    w.PartOfSpeech == PartOfSpeech.Genitive ||
                    w.PartOfSpeech == PartOfSpeech.InfinitiveMarker ||
                    w.PartOfSpeech == PartOfSpeech.InterjectionOrDiscourseMarker ||
                    w.PartOfSpeech == PartOfSpeech.NegativeMarker ||
                    w.PartOfSpeech == PartOfSpeech.CardinalNumber ||
                    w.PartOfSpeech == PartOfSpeech.Ordinal ||
                    w.PartOfSpeech == PartOfSpeech.Preposition ||
                    w.PartOfSpeech == PartOfSpeech.Pronoun ||
                    w.PartOfSpeech == PartOfSpeech.ModalVerb))
            {
                return(null);
            }
            else
            {
                return(w);
            }
        }
예제 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Stands4Word"/> class.
        /// </summary>
        /// <param name="definition">An instance of <see cref="DictionarySingleDefinition"/> containing the definition
        /// extracted from the Web service.</param>
        public Stands4Word(DictionarySingleDefinition definition)
        {
            if (definition == null)
            {
                throw new ArgumentNullException("definition");
            }

            this.PartOfSpeech = definition.PartOfSpeech;
            this.Definition   = definition.Definition;
            this.Examples     = definition.Examples;
            this.Term         = definition.Term;
            this.Level        = new AsyncLazy <LanguageLevelClassification>(async() =>
            {
                return(await WordSearchUtilities.GetMostProbable(await OfflineWord.Search(this.Term, SupportedLanguage.English).ConfigureAwait(false)).Level);
            });
        }