Skip to content

Commit

Permalink
// Frequency1PerDocumentAction.cs
Browse files Browse the repository at this point in the history
// Frequency1PerSentenceAction.cs
  • Loading branch information
notesjor committed Dec 6, 2024
1 parent 29515fd commit 04b8d66
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@
<Compile Include="DocumentHashAction.cs" />
<Compile Include="DocumentSimilarityAction.cs" />
<Compile Include="EditDistanceAction.cs" />
<Compile Include="Frequency1PerDocumentAction.cs" />
<Compile Include="Frequency1PerSentenceAction.cs" />
<Compile Include="Frequency1RawAction.cs" />
<Compile Include="Frequency1RawSelectAction.cs" />
<Compile Include="Frequency2RawAction.cs" />
Expand Down
32 changes: 32 additions & 0 deletions Action/CorpusExplorer.Sdk.Action/Frequency1PerDocumentAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Data;
using CorpusExplorer.Sdk.Addon;
using CorpusExplorer.Sdk.Blocks;
using CorpusExplorer.Sdk.Model;
using CorpusExplorer.Sdk.Utils.DataTableWriter.Abstract;

namespace CorpusExplorer.Sdk.Action
{
public class Frequency1PerDocumentAction : IAction
{
public string Action => "frequency1-per-document";
public string Description => "frequency1-per-document {LAYER} - count token frequency on {LAYER} (default: Wort) per doucment";

public void Execute(Selection selection, string[] args, AbstractTableWriter writer)
{
var layerName = args != null && args.Length == 1 ? args[0] : "Wort";
var block = selection.CreateBlock<Frequency1LayerOneOccurrencePerDocument>();
block.LayerDisplayname = layerName;
block.Calculate();

var dt = new DataTable();
dt.Columns.Add(layerName, typeof(string));
dt.Columns.Add("Frequency", typeof(double));
dt.BeginLoadData();
foreach(var x in block.Frequency)
dt.Rows.Add(x.Key, x.Value);
dt.EndLoadData();

writer.WriteTable(selection.Displayname, dt);
}
}
}
34 changes: 34 additions & 0 deletions Action/CorpusExplorer.Sdk.Action/Frequency1PerSentenceAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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;

namespace CorpusExplorer.Sdk.Action
{
public class Frequency1PerSentenceAction : IAction
{
public string Action => "frequency1-per-sentence";
public string Description => "frequency1-per-sentence {LAYER} - count token frequency on {LAYER} (default: Wort) per sentence";

public void Execute(Selection selection, string[] args, AbstractTableWriter writer)
{
var layerName = args != null && args.Length == 1 ? args[0] : "Wort";
var block = selection.CreateBlock<Frequency1LayerOneOccurrencePerSentenceBlock>();
block.LayerDisplayname = layerName;
block.Calculate();

var dt = new DataTable();
dt.Columns.Add(layerName, typeof(string));
dt.Columns.Add("Frequency", typeof(double));
dt.BeginLoadData();
foreach(var x in block.Frequency)
dt.Rows.Add(x.Key, x.Value);
dt.EndLoadData();

writer.WriteTable(selection.Displayname, dt);
}
}
}

0 comments on commit 04b8d66

Please sign in to comment.