Exemplo n.º 1
0
 public void TestSimplifyHukziuText()
 {
     using (var openCc = new YngdiengOpenCcClient())
     {
         Assert.Equal("侬裡", openCc.SimplifyHukziuText("儂裡"));
     }
 }
Exemplo n.º 2
0
        public string tH(string hukziuText)
        {
            switch (_zhConversionPreference)
            {
            case ZhConversionPreference.LangaugePreferenceHans:
                return(_openCc.SimplifyHukziuText(hukziuText));

            default:
                return(hukziuText);
            }
        }
Exemplo n.º 3
0
        private void CreateLuceneIndex(YngdiengIndex index)
        {
            var dirInfo = Path.GetFullPath(Path.Join(outputFolder, "lucene"));

            Console.WriteLine($"Writing to {dirInfo}");
            using (var dir = FSDirectory.Open(new DirectoryInfo(dirInfo)))
            {
                var indexConfig = new IndexWriterConfig(LuceneUtils.AppLuceneVersion,
                                                        LuceneUtils.GetAnalyzer());
                using (var writer = new IndexWriter(dir, indexConfig))
                {
                    writer.DeleteAll();
                    foreach (var yDoc in index.YngdiengDocuments)
                    {
                        var doc = new Lucene.Net.Documents.Document {
                            new Int32Field(LuceneUtils.Fields.IsSourceless, yDoc.Sources.Count == 0?1:0, Field.Store.YES),
                            new StringField(LuceneUtils.Fields.DocId, yDoc.DocId, Field.Store.YES),
                            new TextField(LuceneUtils.Fields.Yngping, yDoc.YngpingSandhi, Field.Store.NO),
                            new TextField(LuceneUtils.Fields.Hanzi, yDoc.HanziCanonical.Regular, Field.Store.NO),
                            new StringField(LuceneUtils.Fields.YngpingSandhiTonePattern, GetTonePattern(yDoc.YngpingSandhi), Field.Store.NO)
                        };
                        foreach (var m in yDoc.IndexingExtension.MandarinWords)
                        {
                            doc.Add(new TextField(LuceneUtils.Fields.Mandarin, m, Field.Store.NO));
                            doc.Add(new TextField(LuceneUtils.Fields.Mandarin, openCcClient.SimplifyMandarinText(m), Field.Store.NO));
                        }
                        foreach (var a in yDoc.HanziAlternatives)
                        {
                            doc.Add(new TextField(LuceneUtils.Fields.HanziAlternative, a.Regular, Field.Store.NO));
                        }
                        // Simplify Hanzi for search
                        doc.Add(new TextField(LuceneUtils.Fields.Hanzi, openCcClient.SimplifyHukziuText(yDoc.HanziCanonical.Regular), Field.Store.NO));
                        foreach (var e in yDoc.IndexingExtension.ExplanationText)
                        {
                            doc.Add(new TextField(LuceneUtils.Fields.Explanation, e, Field.Store.NO));
                        }
                        // TODO: encapsulate this in a YngpingAnalyzer
                        foreach (var yp in yDoc.IndexingExtension.YngpingPermutations)
                        {
                            doc.Add(new TextField(LuceneUtils.Fields.Yngping, yp, Field.Store.NO));
                        }
                        writer.AddDocument(doc);
                    }
                    writer.Flush(triggerMerge: false, applyAllDeletes: false);
                }
            }
        }