Skip to content

Commit 5c45187

Browse files
committed
// token-list-select um FILE Option erweitert
1 parent 0807888 commit 5c45187

3 files changed

Lines changed: 36 additions & 4 deletions

File tree

Action/CorpusExplorer.Sdk.Action/Properties/Resources.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Action/CorpusExplorer.Sdk.Action/Properties/Resources.resx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@
376376
<value>token-list [LAYER] - list of all tokens in [LAYER]</value>
377377
</data>
378378
<data name="DescTokeListSelect" xml:space="preserve">
379-
<value>token-list-select [LAYER] [REGEX] - list of all tokens in [LAYER] who are matching the [REGEX]-expression</value>
379+
<value>token-list-select [LAYER] [REGEX/FILE] - list of all tokens in [LAYER] who are matching the [REGEX]-expression or [FILE]</value>
380380
</data>
381381
<data name="DescKwitSelect" xml:space="preserve">
382382
<value>kwit-n [LAYER1] [LAYER2] [minFREQ] [PRE] [POST] [WORDS] - Like kwit (but you can specificate the range [PRE] and [POST] the match - e.g. [PRE] = 3)</value>

Action/CorpusExplorer.Sdk.Action/TokenListSelectAction.cs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
using System.Collections.Generic;
12
using System.Data;
3+
using System.IO;
24
using System.Linq;
5+
using System.Text;
36
using System.Text.RegularExpressions;
47
using CorpusExplorer.Sdk.Action.Properties;
58
using CorpusExplorer.Sdk.Addon;
9+
using CorpusExplorer.Sdk.Ecosystem.Model;
610
using CorpusExplorer.Sdk.Model;
711
using CorpusExplorer.Sdk.Utils.DataTableWriter.Abstract;
812

@@ -18,15 +22,43 @@ public void Execute(Selection selection, string[] args, AbstractTableWriter writ
1822
var dt = new DataTable();
1923
dt.Columns.Add(Resources.Tokens, typeof(string));
2024

25+
if (args[1].StartsWith("FILE:"))
26+
dt = ExecuteFile(selection, args, dt);
27+
else
28+
dt = ExecuteRegex(selection, args, dt);
29+
writer.WriteTable(selection.Displayname, dt);
30+
}
31+
32+
private DataTable ExecuteFile(Selection selection, string[] args, DataTable dt)
33+
{
34+
var lines = File.ReadAllLines(args[1].Substring(5), Configuration.Encoding);
35+
var values = new HashSet<string>(selection.GetLayers(args[0]).FirstOrDefault().Values);
36+
37+
foreach (var q in lines)
38+
if (q.StartsWith("*"))
39+
foreach (var c in values.Where(v => v.EndsWith(q.Substring(1))))
40+
dt.Rows.Add(c);
41+
else if (q.EndsWith("*"))
42+
foreach (var c in values.Where(v => v.StartsWith(q.Substring(0, q.Length - 1))))
43+
dt.Rows.Add(c);
44+
else
45+
if (values.Contains(q))
46+
dt.Rows.Add(q);
47+
48+
return dt;
49+
}
50+
51+
private static DataTable ExecuteRegex(Selection selection, string[] args, DataTable dt)
52+
{
2153
var regex = new Regex(args[1], RegexOptions.Compiled);
2254

2355
dt.BeginLoadData();
2456
foreach (var v in selection.GetLayers(args[0]).FirstOrDefault().Values)
25-
if(regex.IsMatch(v))
57+
if (regex.IsMatch(v))
2658
dt.Rows.Add(v);
2759
dt.EndLoadData();
2860

29-
writer.WriteTable(selection.Displayname, dt);
61+
return dt;
3062
}
3163
}
3264
}

0 commit comments

Comments
 (0)