Skip to content

Commit

Permalink
// CrossFrequencySelectAction.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
notesjor committed Dec 6, 2024
1 parent 04b8d66 commit 2cd369c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
<Compile Include="CooccurrenceSelectedCorrespondingAction.cs" />
<Compile Include="CorrespondingValuesAction.cs" />
<Compile Include="CrossFrequencyCorrespondingAction.cs" />
<Compile Include="CrossFrequencySelectAction.cs" />
<Compile Include="CutOffPhraseAction.cs" />
<Compile Include="DisambiguationeAction.cs" />
<Compile Include="DispersionAction.cs" />
Expand Down
48 changes: 48 additions & 0 deletions Action/CorpusExplorer.Sdk.Action/CrossFrequencySelectAction.cs
Original file line number Diff line number Diff line change
@@ -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<string>(args.Skip(1));

var layerName = args[0];
var block = selection.CreateBlock<CrossFrequencySelectedBlock>();
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);
}
}
}

0 comments on commit 2cd369c

Please sign in to comment.