public RichTextNode ToRichTextNode(FengDocument doc) { var output = new RichTextNode() { VerticalContainer = new RichTextNode.Types.VerticalContainerNode() { Children = { SectionHeader(zc.tH(doc.HanziOriginal), RenderSourcePronunciations( ToFeng(doc.YngpingUnderlyingOriginal), ToFeng(doc.YngpingCanonicalOriginal))), } } }; if (doc.ExplanationStructured != null) { output.VerticalContainer.Children.Add(explanationRenderer.ToRichTextNode(doc.ExplanationStructured, doc.HanziCanonical)); } else { output.VerticalContainer.Children.Add(SimpleText(zc.tH(doc.Explanation))); } output.VerticalContainer.Children.Add(Source(zc.tM($"出处:冯爱珍. 1998. 福州方言词典. 南京: 江苏教育出版社. 第 {doc.Source.PageNumber} 页. 用字可能经过编辑修订."))); return(output); }
private RichTextNode ToRichTextNode(string example, string currentWord) { var segments = zc.tH(MaybeAddPeriod(example)).Split("~"); var normalTextNodes = segments.Select(s => new RichTextNode.Types.TextNode() { Text = s, }); var currentWordNode = new RichTextNode.Types.TextNode() { Text = zc.tH(currentWord), Styles = { "current-word" } }; var inlineNodes = Join(normalTextNodes, currentWordNode) .Select(t => new RichTextNode.Types.InlineNode() { Text = t }); return(new RichTextNode() { InlineContainer = new RichTextNode.Types.InlineContainerNode() { Children = { inlineNodes } }, Styles = { "example" } }); }
public static async Task <Word> GetWord( IIndexHolder _indexHolder, AdminContext _dbContext, ZhConverter zhConverter, DocRef docRef, Mode mode = Mode.Full) { var maybeYngdiengDocument = _indexHolder.GetIndex().YngdiengDocuments .SingleOrDefault(yDoc => yDoc.DocId == DocRefs.Encode(docRef)); var maybeWordId = string.IsNullOrEmpty(docRef.ZingzeuId) ? (int?)null : int.Parse(docRef.ZingzeuId, NumberStyles.HexNumber); var maybeWord = maybeWordId == null ? null : await _dbContext.Words .Where(w => w.WordId == maybeWordId) .Include(w => w.PreferredSandhiAudio) .SingleOrDefaultAsync(); if (maybeYngdiengDocument == null && maybeWord == null) { throw new RpcException(new Status(StatusCode.NotFound, "Not found.")); } var extensions = await _dbContext.Extensions.Where(e => e.WordId == maybeWordId).ToListAsync(); var prons = await _dbContext.Prons.Where(p => p.WordId == maybeWordId).ToListAsync(); var hanzi = zhConverter.tH(await GetHanzi(_dbContext, maybeYngdiengDocument, maybeWordId)); var recommendedProns = mode == Mode.Snippet ? PronChooser.GetSnippetPronunciations(maybeYngdiengDocument, prons, maybeWord?.PreferredSandhiAudio) : PronChooser.GetRecommendedPronunciations(maybeYngdiengDocument, prons, maybeWord?.PreferredSandhiAudio); var explanations = mode == Mode.Snippet ? Enumerable.Empty <RichTextNode>() : GetExplanations(zhConverter, hanzi, maybeYngdiengDocument, extensions); var audioCards = mode == Mode.Snippet ? Enumerable.Empty <Word.Types.AudioCard>() : await GetAudioCards(_dbContext, recommendedProns, maybeWordId); var wordLists = mode == Mode.Full && maybeWordId.HasValue ? await Queries.QueryWordListsByWordId(_dbContext, maybeWordId.Value).Select(wl => Renderers.ToWordList(wl)).ToListAsync() : Enumerable.Empty <WordList>(); return(new Word { Name = ResourceNames.ToWordName(docRef), Hanzi = hanzi, Pronunciations = { recommendedProns }, Explanation = { explanations }, Snippet = zhConverter.tH(GetSnippet(maybeYngdiengDocument, extensions)), AudioCards = { audioCards }, WordLists = { wordLists } }); }
public RichTextNode ToRichTextNode(ContribDocument doc) { var output = new RichTextNode() { VerticalContainer = new RichTextNode.Types.VerticalContainerNode() { Children = { SectionHeader(doc.Hanzi, RenderSourcePronunciations(doc.YngpingUnderlying, doc.YngpingSandhi)), } } }; if (doc.ExplanationStructured != null) { output.VerticalContainer.Children.Add(explanationRenderer.ToRichTextNode(doc.ExplanationStructured, doc.Hanzi)); } else { output.VerticalContainer.Children.Add(SimpleText(zc.tH(doc.ExplanationRaw))); } output.VerticalContainer.Children.Add( Source(zc.tM("此释义来自网友贡献。 贡献者: " + string.Join(",", doc.Contributors))) ); return(output); }
public RichTextNode ToRichTextNode(HistoricalDocument doc) { var sources = new List <string>(); if (doc.CiklinSource != null) { sources.Add(zc.tM("戚林八音校注")); } if (doc.DfdSource != null) { sources.Add("榕腔注音辞典·目录"); } var children = new List <RichTextNode>(); children.Add(SectionHeader(zc.tH(HanziUtils.HanziToString(doc.HanziCanonical)))); children.Add(Label(zc.tM("音韵地位(戚林八音)"))); children.Add(SimpleText(PhonologyUtils.ToHanzi(doc.Initial, doc.Final, doc.Tone))); children.Add(Label(zc.tM("榕拼(八音)"))); children.Add(SimpleText(doc.Yngping)); children.Add(Label(zc.tM("教会罗马字"))); children.Add(SimpleText(doc.Buc)); if (!string.IsNullOrEmpty(doc.CiklinSource?.ExplanationCik)) { children.Add(Label(zc.tM("戚书释义"))); children.Add(SimpleText(zc.tM(doc.CiklinSource.ExplanationCik))); } if (!string.IsNullOrEmpty(doc.CiklinSource?.ExplanationLing)) { children.Add(Label(zc.tM("林书释义"))); children.Add(SimpleText(zc.tM(doc.CiklinSource.ExplanationLing))); } children.Add(Source(zc.tM("来源:" + string.Join(", ", sources)))); return(new RichTextNode() { VerticalContainer = new RichTextNode.Types.VerticalContainerNode() { Children = { children } } }); }
private IEnumerable <SearchV2Response.Types.SearchCard> RenderDocs(IEnumerable <ScoreDoc> scoreDocs, ZhConverter zhConverter) { var searcher = this._indexHolder.LuceneIndexSearcher; return(scoreDocs.Select(sd => { var docId = searcher.Doc(sd.Doc).GetField(LuceneUtils.Fields.DocId).GetStringValue(); var ydDoc = _indexHolder.GetIndex().YngdiengDocuments.Single(y => y.DocId == docId); return new SearchV2Response.Types.SearchCard { Word = new SearchV2Response.Types.SearchCard.Types.WordCard { Id = docId, Yngping = RichTextUtil.FromString(ydDoc.YngpingSandhi.OrElse(ydDoc.YngpingUnderlying)), Hanzi = RichTextUtil.FromString(zhConverter.tH(HanziUtils.HanziToString(ydDoc.HanziCanonical))), Details = RichTextUtil.FromString(zhConverter.tM(Yngdieng.Backend.Services.Frontend.Words.GetSnippet (ydDoc, new Extension[] { }))), Score = sd.Score } }; })); }