Skip to content

Commit 2cd369c

Browse files
committed
// CrossFrequencySelectAction.cs
1 parent 04b8d66 commit 2cd369c

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

Action/CorpusExplorer.Sdk.Action/CorpusExplorer.Sdk.Action.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
<Compile Include="CooccurrenceSelectedCorrespondingAction.cs" />
9898
<Compile Include="CorrespondingValuesAction.cs" />
9999
<Compile Include="CrossFrequencyCorrespondingAction.cs" />
100+
<Compile Include="CrossFrequencySelectAction.cs" />
100101
<Compile Include="CutOffPhraseAction.cs" />
101102
<Compile Include="DisambiguationeAction.cs" />
102103
<Compile Include="DispersionAction.cs" />
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System.Collections.Generic;
2+
using CorpusExplorer.Sdk.Action.Properties;
3+
using CorpusExplorer.Sdk.Addon;
4+
using CorpusExplorer.Sdk.Blocks;
5+
using CorpusExplorer.Sdk.Model;
6+
using CorpusExplorer.Sdk.Utils.DataTableWriter.Abstract;
7+
using CorpusExplorer.Sdk.ViewModel;
8+
using System.Data;
9+
using System.Linq;
10+
using CorpusExplorer.Sdk.Helper;
11+
12+
namespace CorpusExplorer.Sdk.Action
13+
{
14+
public class CrossFrequencySelectAction : IAction
15+
{
16+
public string Action => "cross-frequency-select";
17+
public string Description => "cross-frequency-select [LAYER] [WORDS] - calculates the cross-frequency for [WORDS] based on [LAYER]";
18+
19+
public void Execute(Selection selection, string[] args, AbstractTableWriter writer)
20+
{
21+
if (args.Length < 2)
22+
return;
23+
24+
var queries = new HashSet<string>(args.Skip(1));
25+
26+
var layerName = args[0];
27+
var block = selection.CreateBlock<CrossFrequencySelectedBlock>();
28+
block.LayerDisplayname = layerName;
29+
block.LayerQueries = queries;
30+
block.Calculate();
31+
32+
var fdic = block.CooccurrencesFrequency.CompleteDictionaryToFullDictionary();
33+
34+
var dt = new DataTable();
35+
dt.Columns.Add("Query", typeof(string));
36+
dt.Columns.Add(layerName, typeof(string));
37+
dt.Columns.Add("Frequency", typeof(double));
38+
dt.BeginLoadData();
39+
foreach (var q in queries)
40+
if (fdic.ContainsKey(q))
41+
foreach (var x in fdic[q])
42+
dt.Rows.Add(q, x.Key, x.Value);
43+
dt.EndLoadData();
44+
45+
writer.WriteTable(selection.Displayname, dt);
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)