Skip to content

Commit a3469f6

Browse files
committed
// KwitFrequencyAction.cs
1 parent 1eff8bc commit a3469f6

2 files changed

Lines changed: 92 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
@@ -136,6 +136,7 @@
136136
<Compile Include="Frequency1RawSelectAction.cs" />
137137
<Compile Include="Frequency2RawAction.cs" />
138138
<Compile Include="CentralSnipTreeAction.cs" />
139+
<Compile Include="KwitFrequencyAction.cs" />
139140
<Compile Include="NGramCharAction.cs" />
140141
<Compile Include="Phrase2LayerCountAction.cs" />
141142
<Compile Include="Frequency3RawAction.cs" />
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Globalization;
4+
using System.Linq;
5+
using System.Text;
6+
using CorpusExplorer.Sdk.Action.Helper;
7+
using CorpusExplorer.Sdk.Action.Properties;
8+
using CorpusExplorer.Sdk.Addon;
9+
using CorpusExplorer.Sdk.Model;
10+
using CorpusExplorer.Sdk.Utils.DataTableWriter.Abstract;
11+
using CorpusExplorer.Sdk.Utils.Filter.Abstract;
12+
using CorpusExplorer.Sdk.Utils.Filter.Queries;
13+
using CorpusExplorer.Sdk.ViewModel;
14+
15+
namespace CorpusExplorer.Sdk.Action
16+
{
17+
public class KwitFrequencyAction : IAction
18+
{
19+
public string Action => "kwit-frequency";
20+
21+
public string Description => "kwit-frequency [LAYER1] [LAYER2] [minFREQ] {ANY/FIRST/SENTENCE/PHRASE} [WORDS] - Like kwit but only prints out the outgoing/incoming frequency. Search all [WORDS] in [LAYER1] (with minimum frequency [minFREQ]) - Output in [LAYER2] - [WORDS] = space separated tokens. {A/F/S/P} = Serch Operator (default: PHRASE)";
22+
23+
public void Execute(Selection selection, string[] args, AbstractTableWriter writer)
24+
{
25+
if (args == null || args.Length < 4)
26+
return;
27+
28+
var queries = new List<string>(args);
29+
queries.RemoveAt(0);
30+
queries.RemoveAt(0);
31+
queries.RemoveAt(0);
32+
33+
var query = GetQuery(args[0], ref queries);
34+
35+
var vm = new TextFlowSearchViewModel
36+
{
37+
Selection = selection,
38+
LayerDisplayname = args[1],
39+
MinFrequency = int.Parse(args[2]),
40+
LayerQuery = query,
41+
AutoJoin = true,
42+
HighlightCooccurrences = false
43+
};
44+
vm.Execute();
45+
46+
writer.WriteTable(vm.GetDataTable());
47+
}
48+
49+
private AbstractFilterQuery GetQuery(string layerDisplayname, ref List<string> queries)
50+
{
51+
var filter = new HashSet<string>{ "ANY", "FIRST", "SENTENCE", "PHRASE" };
52+
if (!filter.Contains(queries[0]))
53+
return new FilterQuerySingleLayerExactPhrase
54+
{
55+
LayerDisplayname = layerDisplayname,
56+
LayerQueries = queries
57+
};
58+
59+
var match = queries[0];
60+
queries.RemoveAt(0);
61+
62+
switch (match)
63+
{
64+
case "ANY":
65+
return new FilterQuerySingleLayerAnyMatch
66+
{
67+
LayerDisplayname = layerDisplayname,
68+
LayerQueries = queries
69+
};
70+
case "FIRST":
71+
return new FilterQuerySingleLayerFirstAndAnyOtherMatch
72+
{
73+
LayerDisplayname = layerDisplayname,
74+
LayerQueries = queries
75+
};
76+
case "SENTENCE":
77+
return new FilterQuerySingleLayerAllInOneSentence
78+
{
79+
LayerDisplayname = layerDisplayname,
80+
LayerQueries = queries
81+
};
82+
default:
83+
return new FilterQuerySingleLayerExactPhrase
84+
{
85+
LayerDisplayname = layerDisplayname,
86+
LayerQueries = queries
87+
};
88+
}
89+
}
90+
}
91+
}

0 commit comments

Comments
 (0)