private void analyzeWriteResult(string input, WorkerArgs args, string outputPath) { string[] lines = args.byline ? input.Trim().Split('\n') : new string[] { input.Trim() }; instKiwi.setOption(KiwiCS.KIWI_INTEGRATE_ALLOMORPH, args.integrateAllomorph ? 1 : 0); using (StreamWriter output = new StreamWriter(outputPath)) { foreach (string line in lines) { if (line.Length == 0) { continue; } var res = instKiwi.analyze(line.Trim(), args.topN); string ret = ""; foreach (var r in res) { foreach (var m in r.morphs) { if (ret.Length > 0) { ret += args.formatSep; } ret += m.Item1; if (args.formatTag) { ret += "/" + m.Item2; } } } output.WriteLine(line.Trim()); output.WriteLine(ret); } } }
private void AnalyzeBtn_Click(object sender, RoutedEventArgs e) { ResultBlock.Document.Blocks.Clear(); App.monitor.TrackAtomicFeature("Kiwi_Menu", "Analyze", InputTxt.Text); string[] lines = TypeCmb.SelectedIndex == 0 ? InputTxt.Text.Trim().Split('\n') : new string[] { InputTxt.Text.Trim() }; int topN = TopNCmb.SelectedIndex + 1; instKiwi.setOption(KiwiCS.KIWI_INTEGRATE_ALLOMORPH, IntegratedAllomorph.IsChecked.Value ? 1 : 0); Brush brushDef = new SolidColorBrush(Color.FromRgb(0, 0, 0)); Brush brushMorph = new SolidColorBrush(Color.FromRgb(0, 150, 0)); Brush brushTag = new SolidColorBrush(Color.FromRgb(0, 0, 150)); bool content = false; foreach (var line in lines) { if (line.Length == 0) { continue; } content = true; var res = instKiwi.analyze(line.Trim(), topN); Run t = new Run(line.Trim()); t.Foreground = brushDef; Paragraph para = new Paragraph(); para.Inlines.Add(t); foreach (var r in res) { para.Inlines.Add(new LineBreak()); int c = 0; foreach (var m in r.morphs) { if (c++ > 0) { t = new Run(" + "); t.Foreground = brushDef; para.Inlines.Add(t); } Bold b = new Bold(); b.Inlines.Add(m.Item1); b.Foreground = brushMorph; para.Inlines.Add(b); t = new Run("/"); t.Foreground = brushDef; para.Inlines.Add(t); b = new Bold(); b.Inlines.Add(m.Item2); b.Foreground = brushTag; para.Inlines.Add(b); } } ResultBlock.Document.Blocks.Add(para); } MenuSave.IsEnabled = content; }