From 2cd369cb43d992fd3edb82a13d1966c1ec29031e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Oliver=20R=C3=BCdiger?= Date: Fri, 6 Dec 2024 14:17:44 +0100 Subject: [PATCH] // CrossFrequencySelectAction.cs --- .../CorpusExplorer.Sdk.Action.csproj | 1 + .../CrossFrequencySelectAction.cs | 48 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 Action/CorpusExplorer.Sdk.Action/CrossFrequencySelectAction.cs diff --git a/Action/CorpusExplorer.Sdk.Action/CorpusExplorer.Sdk.Action.csproj b/Action/CorpusExplorer.Sdk.Action/CorpusExplorer.Sdk.Action.csproj index 2a757fe..5e3f36b 100644 --- a/Action/CorpusExplorer.Sdk.Action/CorpusExplorer.Sdk.Action.csproj +++ b/Action/CorpusExplorer.Sdk.Action/CorpusExplorer.Sdk.Action.csproj @@ -97,6 +97,7 @@ + diff --git a/Action/CorpusExplorer.Sdk.Action/CrossFrequencySelectAction.cs b/Action/CorpusExplorer.Sdk.Action/CrossFrequencySelectAction.cs new file mode 100644 index 0000000..c26e42e --- /dev/null +++ b/Action/CorpusExplorer.Sdk.Action/CrossFrequencySelectAction.cs @@ -0,0 +1,48 @@ +using System.Collections.Generic; +using CorpusExplorer.Sdk.Action.Properties; +using CorpusExplorer.Sdk.Addon; +using CorpusExplorer.Sdk.Blocks; +using CorpusExplorer.Sdk.Model; +using CorpusExplorer.Sdk.Utils.DataTableWriter.Abstract; +using CorpusExplorer.Sdk.ViewModel; +using System.Data; +using System.Linq; +using CorpusExplorer.Sdk.Helper; + +namespace CorpusExplorer.Sdk.Action +{ + public class CrossFrequencySelectAction : IAction + { + public string Action => "cross-frequency-select"; + public string Description => "cross-frequency-select [LAYER] [WORDS] - calculates the cross-frequency for [WORDS] based on [LAYER]"; + + public void Execute(Selection selection, string[] args, AbstractTableWriter writer) + { + if (args.Length < 2) + return; + + var queries = new HashSet(args.Skip(1)); + + var layerName = args[0]; + var block = selection.CreateBlock(); + block.LayerDisplayname = layerName; + block.LayerQueries = queries; + block.Calculate(); + + var fdic = block.CooccurrencesFrequency.CompleteDictionaryToFullDictionary(); + + var dt = new DataTable(); + dt.Columns.Add("Query", typeof(string)); + dt.Columns.Add(layerName, typeof(string)); + dt.Columns.Add("Frequency", typeof(double)); + dt.BeginLoadData(); + foreach (var q in queries) + if (fdic.ContainsKey(q)) + foreach (var x in fdic[q]) + dt.Rows.Add(q, x.Key, x.Value); + dt.EndLoadData(); + + writer.WriteTable(selection.Displayname, dt); + } + } +} \ No newline at end of file