Skip to content

Commit 04b8d66

Browse files
committed
// Frequency1PerDocumentAction.cs
// Frequency1PerSentenceAction.cs
1 parent 29515fd commit 04b8d66

3 files changed

Lines changed: 68 additions & 0 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@
104104
<Compile Include="DocumentHashAction.cs" />
105105
<Compile Include="DocumentSimilarityAction.cs" />
106106
<Compile Include="EditDistanceAction.cs" />
107+
<Compile Include="Frequency1PerDocumentAction.cs" />
108+
<Compile Include="Frequency1PerSentenceAction.cs" />
107109
<Compile Include="Frequency1RawAction.cs" />
108110
<Compile Include="Frequency1RawSelectAction.cs" />
109111
<Compile Include="Frequency2RawAction.cs" />
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System.Data;
2+
using CorpusExplorer.Sdk.Addon;
3+
using CorpusExplorer.Sdk.Blocks;
4+
using CorpusExplorer.Sdk.Model;
5+
using CorpusExplorer.Sdk.Utils.DataTableWriter.Abstract;
6+
7+
namespace CorpusExplorer.Sdk.Action
8+
{
9+
public class Frequency1PerDocumentAction : IAction
10+
{
11+
public string Action => "frequency1-per-document";
12+
public string Description => "frequency1-per-document {LAYER} - count token frequency on {LAYER} (default: Wort) per doucment";
13+
14+
public void Execute(Selection selection, string[] args, AbstractTableWriter writer)
15+
{
16+
var layerName = args != null && args.Length == 1 ? args[0] : "Wort";
17+
var block = selection.CreateBlock<Frequency1LayerOneOccurrencePerDocument>();
18+
block.LayerDisplayname = layerName;
19+
block.Calculate();
20+
21+
var dt = new DataTable();
22+
dt.Columns.Add(layerName, typeof(string));
23+
dt.Columns.Add("Frequency", typeof(double));
24+
dt.BeginLoadData();
25+
foreach(var x in block.Frequency)
26+
dt.Rows.Add(x.Key, x.Value);
27+
dt.EndLoadData();
28+
29+
writer.WriteTable(selection.Displayname, dt);
30+
}
31+
}
32+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using CorpusExplorer.Sdk.Action.Properties;
2+
using CorpusExplorer.Sdk.Addon;
3+
using CorpusExplorer.Sdk.Blocks;
4+
using CorpusExplorer.Sdk.Model;
5+
using CorpusExplorer.Sdk.Utils.DataTableWriter.Abstract;
6+
using CorpusExplorer.Sdk.ViewModel;
7+
using System.Data;
8+
9+
namespace CorpusExplorer.Sdk.Action
10+
{
11+
public class Frequency1PerSentenceAction : IAction
12+
{
13+
public string Action => "frequency1-per-sentence";
14+
public string Description => "frequency1-per-sentence {LAYER} - count token frequency on {LAYER} (default: Wort) per sentence";
15+
16+
public void Execute(Selection selection, string[] args, AbstractTableWriter writer)
17+
{
18+
var layerName = args != null && args.Length == 1 ? args[0] : "Wort";
19+
var block = selection.CreateBlock<Frequency1LayerOneOccurrencePerSentenceBlock>();
20+
block.LayerDisplayname = layerName;
21+
block.Calculate();
22+
23+
var dt = new DataTable();
24+
dt.Columns.Add(layerName, typeof(string));
25+
dt.Columns.Add("Frequency", typeof(double));
26+
dt.BeginLoadData();
27+
foreach(var x in block.Frequency)
28+
dt.Rows.Add(x.Key, x.Value);
29+
dt.EndLoadData();
30+
31+
writer.WriteTable(selection.Displayname, dt);
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)