Skip to content

Commit 929d12b

Browse files
committed
Merge branch 'master' of github.com:notesjor/CorpusExplorer.Terminal.Console
2 parents cf78efc + 5c45187 commit 929d12b

6 files changed

Lines changed: 103 additions & 18 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
}

CorpusExplorer.Terminal.Console.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@
175175
</ItemGroup>
176176
<ItemGroup>
177177
<PackageReference Include="Microsoft.OpenApi">
178-
<Version>1.6.22</Version>
178+
<Version>1.6.23</Version>
179179
</PackageReference>
180180
<PackageReference Include="Newtonsoft.Json">
181181
<Version>13.0.3</Version>

DotNet5/CorpusExplorer.Terminal.Console.DotNet5/CorpusExplorer.Terminal.Console.DotNet5.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,14 @@
8181
</ItemGroup>
8282

8383
<ItemGroup>
84-
<PackageReference Include="HtmlAgilityPack" Version="1.11.71" />
84+
<PackageReference Include="HtmlAgilityPack" Version="1.11.72" />
8585
<PackageReference Include="K4os.Compression.LZ4" Version="1.3.8" />
8686
<PackageReference Include="K4os.Compression.LZ4.Streams" Version="1.3.8" />
8787
<PackageReference Include="K4os.Hash.xxHash" Version="1.0.8" />
88-
<PackageReference Include="Microsoft.OpenApi" Version="1.6.22" />
88+
<PackageReference Include="Microsoft.OpenApi" Version="1.6.23" />
8989
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
9090
<PackageReference Include="System.Runtime.Serialization.Formatters" Version="4.3.0" />
91+
<PackageReference Include="System.Security.Permissions" Version="9.0.1" />
9192
</ItemGroup>
9293

9394
<ItemGroup>

Program.cs

Lines changed: 63 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,36 +77,76 @@ private static void DebugScript(string[] args)
7777
}
7878
}
7979

80+
private class PInfo
81+
{
82+
public DateTime DateTimeStart { get; set; }
83+
public DateTime DateTimeLoad { get; set; }
84+
85+
public double SizeAppInRam { get; set; }
86+
public double SizeCorpusInRam { get; set; }
87+
public double SizeMaxRamUse { get; set; }
88+
89+
public void Print()
90+
{
91+
var end = DateTime.Now;
92+
System.Console.WriteLine($"RAM (app): {SizeAppInRam / 1024 / 1024}");
93+
System.Console.WriteLine($"Load corpus: {(DateTimeLoad - DateTimeStart).Milliseconds}ms");
94+
System.Console.WriteLine($"RAM (corpus): {SizeCorpusInRam / 1024 / 1024} MB");
95+
System.Console.WriteLine($"Execute action: {(end - DateTimeLoad).Milliseconds}ms");
96+
System.Console.WriteLine($"RAM (all): {SizeMaxRamUse / 1024 / 1024} MB");
97+
}
98+
}
99+
100+
private static PInfo _pInfo = null;
101+
80102
private static void Execute(string[] args)
81103
{
82-
if (args.Length > 0 && args[0] == "/WAIT")
104+
if (args == null || args.Length == 0)
83105
{
84-
System.Console.WriteLine("...PRESS ENTER TO CONTINUE...");
85-
System.Console.ReadLine();
106+
PrintHelp(true);
107+
return;
108+
}
86109

110+
// --> Start of dev-relevant arguments
111+
if (args.Length > 0 && args[0] == "/PINFO")
112+
{
87113
var tmp = args.ToList();
88114
tmp.RemoveAt(0);
89115

90116
args = tmp.ToArray();
117+
_pInfo = new PInfo
118+
{
119+
DateTimeStart = DateTime.Now,
120+
SizeAppInRam = GC.GetTotalMemory(false)
121+
};
91122
}
92123

93-
if (args == null || args.Length == 0)
124+
if (args.Length > 0 && args[0] == "/WAIT")
94125
{
95-
PrintHelp(true);
96-
return;
126+
System.Console.WriteLine("...PRESS ENTER TO CONTINUE...");
127+
System.Console.ReadLine();
128+
129+
var tmp = args.ToList();
130+
tmp.RemoveAt(0);
131+
132+
args = tmp.ToArray();
97133
}
98134

99135
if (args.Length == 1 && args[0] == "--github")
100136
{
101137
PrintDocs();
102138
return;
103139
}
140+
// <-- End of dev-relevant arguments
104141

105-
if (args[0].StartsWith("WAIT:"))
142+
if (args.Length > 0 && args[0] == "/WAIT")
106143
{
107-
Wait(args[0]);
144+
System.Console.WriteLine("...PRESS ENTER TO CONTINUE...");
145+
System.Console.ReadLine();
146+
108147
var tmp = args.ToList();
109148
tmp.RemoveAt(0);
149+
110150
args = tmp.ToArray();
111151
}
112152

@@ -226,8 +266,8 @@ private static void ExecuteWebservice(string[] args)
226266
file = arg;
227267
}
228268

229-
#if Featherweight
230-
#else
269+
#if Featherweight
270+
#else
231271
if (file.Contains("#"))
232272
{
233273
var ws = new WebService(_writer, ip, port, file, timeout);
@@ -238,7 +278,7 @@ private static void ExecuteWebservice(string[] args)
238278
var ws = new WebService(_writer, ip, port, file, timeout);
239279
ws.Run();
240280
}
241-
#endif
281+
#endif
242282
}
243283

244284
private static void ExecuteDirect(string[] args)
@@ -253,10 +293,22 @@ private static void ExecuteDirect(string[] args)
253293
if (selection == null)
254294
return;
255295

296+
if(_pInfo != null)
297+
{
298+
_pInfo.DateTimeLoad = DateTime.Now;
299+
_pInfo.SizeCorpusInRam = GC.GetTotalMemory(false);
300+
}
301+
256302
var temp = args.ToList();
257303
temp.RemoveAt(0); // CorpusFile (no longer needed)
258304
temp.RemoveAt(0); // Action (no longer needed)
259305
action.Execute(selection, temp.ToArray(), _writer);
306+
307+
if (_pInfo != null)
308+
{
309+
_pInfo.SizeMaxRamUse = GC.GetTotalMemory(false);
310+
_pInfo.Print();
311+
}
260312
}
261313

262314
private static void ExecuteShell()

0 commit comments

Comments
 (0)