예제 #1
0
        private TranslationResult mapResponse()
        {
            TranslationResult translationResult = new TranslationResult(this.ProviderName);

            translationResult.Results.Add(new Result());



            if (translationResultRaw != null)
            {
                translationResult.Results[0].OnlineExamples = translationResultRaw?
                                                              .Examples.Select(
                    x => new OnlineExample()
                {
                    Author = x?.Author,
                    Text   = x?.Text,
                    Title  = x?.Title,
                    Url    = x?.Url,
                    Word   = x?.Word,
                    Year   = x?.Year
                }
                    )
                                                              .Where(x => !string.IsNullOrEmpty(x.Title) || !string.IsNullOrEmpty(x.Text))?
                                                              .ToList();
            }
            else
            {
                translationResult = translationResult.GetEmptyTranslationResult();
            }

            ProviderHelper.CountResults(translationResult);

            return(translationResult);
        }
예제 #2
0
        private TranslationResult mapResponse()
        {
            TranslationResult translationResult = new TranslationResult(this.ProviderName);

            if (translationResultRaw != null)
            {
                translationResult.Results = translationResultRaw?
                                            .Select(x => new Result()
                {
                    Word             = null, //to be removed
                    ShortTranslation = null, //to be removed


                    Definitions =
                    { new TranslationDefinition {
                          Definition      = x.hwi.Word,
                          Example         = x.ShortTranslation.FirstOrDefault(),
                          Pronounciations =
                          { new Pronounciation {
                                                      Sound = x.hwi.prs
                                                              .Where
                                                                  (x => !string.IsNullOrEmpty(x.sound?.Audio))
                                                              .FirstOrDefault()?.sound ?? x.hwi?.prs?.FirstOrDefault().sound //this was prepopulated in constructor so either first not empty element or just first one (it could be either populated or not)
                                                      , Pron = x.hwi.prs
                                                               .Where(x => !string.IsNullOrEmpty(x.ipa)).FirstOrDefault()?.ipa
                                                  } }
                      } }
                })
                                            .ToList();
            }
            else
            {
                translationResult = translationResult.GetEmptyTranslationResult();
            }

            ProviderHelper.CountResults(translationResult);

            return(translationResult);
        }
        /// <summary>
        /// depends on the phrase, the JSON 'meaning' response can contain either 'adjective' or  'noun' so both should be mapped
        /// </summary>
        /// <returns></returns>
        private TranslationResult mapResponse()
        {
            TranslationResult translationResult = new TranslationResult(this.ProviderName);

            var adj  = translationResultRaw?.Select(x => x.Meaning.Adjective).FirstOrDefault()?.ToList();
            var noun = translationResultRaw?.Select(x => x.Meaning.Noun).FirstOrDefault()?.ToList();

            var res = new List <Result>();

            if (translationResultRaw != null)
            {
                if (adj != null)
                {
                    res = adj
                          .Select(x => new Result()
                    {
                        Definitions =
                        {
                            new TranslationDefinition {
                                Definition      = x.Definition,
                                Pronounciations = null,
                                Synonyms        = x.Synonyms?.Select(item => new Synonym()
                                {
                                    Name = item
                                })?.ToList(),                                                          //convert list<string> to list of new objects!!!!
                                Example = x.Example
                            }
                        }
                    })?.ToList();
                }

                if (noun != null)
                {
                    res = noun
                          .Select(x => new Result()
                    {
                        Definitions =
                        {
                            new TranslationDefinition {
                                Definition      = x.Definition,
                                Pronounciations = null,
                                Synonyms        = x.Synonyms?.Select(item => new Synonym()
                                {
                                    Name = item
                                })?.ToList(),                                                          //convert list<string> to list of new objects!!!!
                                Example = x.Example
                            }
                        }
                    })?.ToList();
                }
                translationResult.Results = res;
            }
            else
            {
                translationResult = translationResult.GetEmptyTranslationResult();
            }



            ProviderHelper.CountResults(translationResult);

            return(translationResult);
        }