|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Data; |
| 4 | +using System.Linq; |
| 5 | +using System.Text; |
| 6 | +using System.Threading.Tasks; |
| 7 | +using CorpusExplorer.Sdk.Addon; |
| 8 | +using CorpusExplorer.Sdk.Blocks; |
| 9 | +using CorpusExplorer.Sdk.Blocks.Range; |
| 10 | +using CorpusExplorer.Sdk.Model; |
| 11 | +using CorpusExplorer.Sdk.Utils.DataTableWriter.Abstract; |
| 12 | +using CorpusExplorer.Sdk.ViewModel; |
| 13 | + |
| 14 | +namespace CorpusExplorer.Sdk.Action |
| 15 | +{ |
| 16 | + public class CooccurrenceClassicAction : IAction |
| 17 | + { |
| 18 | + public string Action => "cooccurrence-classic [LAYER] [FROM] [TO]"; |
| 19 | + public string Description { get; } |
| 20 | + public void Execute(Selection selection, string[] args, AbstractTableWriter writer) |
| 21 | + { |
| 22 | + if (args.Length < 4) |
| 23 | + return; |
| 24 | + |
| 25 | + var block = selection.CreateBlock<CooccurrenceClassicBlock>(); |
| 26 | + block.LayerDisplayname = args[0]; |
| 27 | + var from = int.Parse(args[1]); |
| 28 | + var to = int.Parse(args[2]); |
| 29 | + block.Ranges = new RangeSimple(from, to); |
| 30 | + block.LayerQueries = args.Skip(3).ToArray(); |
| 31 | + |
| 32 | + block.Calculate(); |
| 33 | + |
| 34 | + var dt = new DataTable(); |
| 35 | + dt.Columns.Add(args[0], typeof(string)); |
| 36 | + dt.Columns.Add("Cooccurrence", typeof(string)); |
| 37 | + dt.Columns.Add("Frequency", typeof(int)); |
| 38 | + dt.Columns.Add("Significance", typeof(double)); |
| 39 | + |
| 40 | + dt.BeginLoadData(); |
| 41 | + foreach (var x in block.CooccurrenceSignificance) |
| 42 | + foreach (var y in x.Value) |
| 43 | + dt.Rows.Add(x.Key, y.Key, block.CooccurrenceFrequency[x.Key][y.Key], y.Value); |
| 44 | + dt.EndLoadData(); |
| 45 | + |
| 46 | + writer.WriteTable(dt); |
| 47 | + } |
| 48 | + } |
| 49 | +} |
0 commit comments