Esempio n. 1
0
        private static void ParseBasicStuff(ParseOptions options, Response.DictionaryEntry result, Entry searchResult)
        {
            if (result.Artwork != null)
            {
                searchResult.Artwork = new Artwork
                {
                    Caption       = result.Artwork.Caption,
                    HtmlLocation  = ArtworkLinkCreator.CreatePageLink(result.Artwork),
                    ImageLocation = ArtworkLinkCreator.CreateDirectLink(result.Artwork)
                };
            }

            if (!string.IsNullOrEmpty(result.Date))
            {
                searchResult.Date = result.Date;
            }

            if (result.HeadwordInformation != null)
            {
                foreach (var pronunciation in result.HeadwordInformation.Pronunciations)
                {
                    var pron = PronunciationHelper.Parse(pronunciation, searchResult.Metadata.Language, options.AudioFormat);
                    searchResult.Headword.Pronunciations.Add(pron);
                }

                searchResult.Headword.Text = result.HeadwordInformation.Headword;
                searchResult.Headword.ParenthesizedSubjectStatusLabel = result.HeadwordInformation.ParenthesizedSubjectStatusLabel;
            }

            if (result.AlternateHeadwords.Any())
            {
                searchResult.AlternateHeadwords = new List <AlternateHeadwordInformation>();
                foreach (var alternateHeadword in result.AlternateHeadwords)
                {
                    var alternateHeadwordInformation = new AlternateHeadwordInformation
                    {
                        HeadwordCutback = alternateHeadword.HeadwordCutback,
                        ParenthesizedSubjectStatusLabel = alternateHeadword.ParenthesizedSubjectStatusLabel,
                        Text = alternateHeadword.Headword
                    };

                    if (alternateHeadword.Pronunciations.Any())
                    {
                        alternateHeadwordInformation.Pronunciations = new List <Pronunciation>();
                        foreach (var pronunciation in alternateHeadword.Pronunciations)
                        {
                            alternateHeadwordInformation.Pronunciations.Add(PronunciationHelper.Parse(pronunciation, searchResult.Metadata.Language, options.AudioFormat));
                        }
                    }

                    searchResult.AlternateHeadwords.Add(alternateHeadwordInformation);
                }
            }
        }
Esempio n. 2
0
        private static Entry CreateSearchResult(Response.DictionaryEntry result, ParseOptions options)
        {
            var searchResult = new Entry
            {
                Metadata     = result.ParseMetadata(),
                PartOfSpeech = result.FunctionalLabel ?? string.Empty,
                ShortDefs    = result.Shortdefs,
                Homograph    = result.Homograph.GetValueOrDefault()
                               // TODO
                               //Synonyms = result.Metadata.Synonyms.SelectMany(s => s).ToList(),
                               //Antonyms = result.Metadata.Antonyms.SelectMany(s => s).ToList()
            };

            if (!string.IsNullOrEmpty(result.FunctionalLabel))
            {
                searchResult.PartOfSpeech = result.FunctionalLabel;
            }

            if (result.GeneralLabels.Any())
            {
                searchResult.GeneralLabels = new List <Label>();
                foreach (var generalLabel in result.GeneralLabels)
                {
                    searchResult.GeneralLabels.Add(generalLabel);
                }
            }

            if (result.SubjectStatusLabels.Any())
            {
                searchResult.SubjectStatusLabels = new List <Label>();
                foreach (var subjectStatusLabel in result.SubjectStatusLabels)
                {
                    searchResult.SubjectStatusLabels.Add(subjectStatusLabel);
                }
            }

            ParseBasicStuff(options, result, searchResult);

            searchResult.Conjugations = ParseConjugations(result.Supplemental);
            if (result.CrossReferences.Any())
            {
                searchResult.CrossReferences = CrossReferenceHelper.Parse(result.CrossReferences).ToList();
            }

            if (result.CognateCrossReferences.Any())
            {
                searchResult.CognateCrossReferences = CognateCrossReferenceHelper.Parse(result.CognateCrossReferences).ToList();
            }

            if (result.Inflections.Any())
            {
                searchResult.Inflections = InflectionHelper.Parse(result.Inflections, searchResult.Metadata.Language, options.AudioFormat).ToList();
            }

            if (result.Synonyms.Any())
            {
                searchResult.Synonyms = ParseSynonyms(result.Synonyms).ToList();
            }

            if (result.DirectionalCrossReferences.Any())
            {
                searchResult.DirectionalCrossReferences = new List <FormattedText>();
                foreach (var crossReference in result.DirectionalCrossReferences)
                {
                    searchResult.DirectionalCrossReferences.Add(new FormattedText(crossReference));
                }
            }

            if (result.Usages.Any())
            {
                searchResult.Usages = new List <Usage>();
                foreach (var srcUsage in result.Usages)
                {
                    var usage = new Usage
                    {
                        ParagraphLabel = srcUsage.ParagraphLabel
                    };

                    foreach (var complexTypeWrapper in srcUsage.ParagraphText)
                    {
                        var type = complexTypeWrapper[0].TypeLabelOrText;
                        if (type == DefiningTextTypes.Text)
                        {
                            usage.ParagraphTexts.Add(new DefiningText(complexTypeWrapper[1].TypeLabelOrText));
                        }
                        else if (type == DefiningTextTypes.VerbalIllustration)
                        {
                            foreach (var dt in complexTypeWrapper[1].DefiningTextComplexTypes)
                            {
                                usage.ParagraphTexts.Add(VisHelper.Parse(dt.DefiningText));
                            }
                        }
                        else if (type == DefiningTextTypes.InAdditionReference)
                        {
                            // TODO, requires sample json
                        }
                    }

                    searchResult.Usages.Add(usage);
                }
            }

            if (result.Table != null)
            {
                searchResult.Table = new Table
                {
                    Displayname = result.Table.Displayname,
                    TableId     = result.Table.Tableid
                };
            }

            if (result.Bios.Any())
            {
                searchResult.BiographicalNote = new BiographicalNote();
                foreach (var bioElement in result.Bios)
                {
                    foreach (var element in bioElement)
                    {
                        var typeOrText = element[0].TypeOrText;
                        if (typeOrText == "bionw")
                        {
                            var note    = element[1].BiographicalNote;
                            var content = new BiographicalNameWrap()
                            {
                                FirstName     = note.Biopname,
                                AlternateName = note.Bioname,
                                Surname       = note.Biosname
                            };

                            if (note.Prs.Any())
                            {
                                content.Pronunciations = new List <Pronunciation>();
                                foreach (var pronunciation in note.Prs)
                                {
                                    content.Pronunciations.Add(PronunciationHelper.Parse(pronunciation, searchResult.Metadata.Language, options.AudioFormat));
                                }
                            }

                            searchResult.BiographicalNote.Contents.Add(content);
                        }

                        else if (typeOrText == "biodate" || typeOrText == "text" || typeOrText == "biotx")
                        {
                            searchResult.BiographicalNote.Contents.Add(new DefiningText(element[1].TypeOrText));
                        }
                    }
                }
            }

            return(searchResult);
        }