Skip to content

Commit 6019d92

Browse files
committed
1. Embed jieba.NET source code.
2. Remove publish profile. 3. Fix docker build
1 parent 6eeb617 commit 6019d92

33 files changed

Lines changed: 2176 additions & 131 deletions

BotSharp.Algorithm/BotSharp.Algorithm.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
5-
<Configurations>Debug;Release;RASA NLU;DIALOGFLOW;RASA</Configurations>
5+
<Configurations>Debug;Release;RASA;DIALOGFLOW</Configurations>
66
<Platforms>AnyCPU;x64</Platforms>
77
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
88
<PackageIconUrl>https://raw.githubusercontent.com/Oceania2018/BotSharp/master/BotSharp.WebHost/wwwroot/images/BotSharp.png</PackageIconUrl>
@@ -16,6 +16,7 @@
1616

1717
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='RASA|AnyCPU'">
1818
<OutputPath>bin\RASA</OutputPath>
19+
<DefineConstants>TRACE;DEBUG;RASA</DefineConstants>
1920
</PropertyGroup>
2021

2122
</Project>

BotSharp.Core/BotSharp.Core.csproj

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<SccAuxPath>SAK</SccAuxPath>
77
<SccLocalPath>SAK</SccLocalPath>
88
<Platforms>AnyCPU;x64</Platforms>
9-
<Configurations>Debug;Release;RASA NLU;DIALOGFLOW;RASA</Configurations>
9+
<Configurations>Debug;Release;DIALOGFLOW;RASA</Configurations>
1010
</PropertyGroup>
1111

1212
<PropertyGroup>
@@ -37,48 +37,18 @@ If you feel that this project is helpful to you, please Star on the project, we
3737
</PropertyGroup>
3838

3939
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='RASA|AnyCPU'">
40-
<DefineConstants>TRACE;DEBUG</DefineConstants>
41-
</PropertyGroup>
42-
43-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='RASA NLU|AnyCPU'">
44-
<DefineConstants>TRACE;DEBUG</DefineConstants>
45-
</PropertyGroup>
46-
47-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
48-
<DefineConstants>TRACE;DEBUG</DefineConstants>
49-
</PropertyGroup>
50-
51-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='RASA|x64'">
52-
<DefineConstants>TRACE;DEBUG</DefineConstants>
53-
</PropertyGroup>
54-
55-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='RASA NLU|x64'">
56-
<DefineConstants>TRACE;DEBUG</DefineConstants>
40+
<DefineConstants>TRACE;DEBUG;RASA</DefineConstants>
41+
<OutputPath>bin\RASA</OutputPath>
5742
</PropertyGroup>
5843

5944
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
60-
<DefineConstants>TRACE;MODEL_PER_CONTEXTS</DefineConstants>
45+
<DefineConstants>TRACE;</DefineConstants>
6146
</PropertyGroup>
6247

63-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
64-
<DefineConstants>TRACE;MODEL_PER_CONTEXTS</DefineConstants>
65-
</PropertyGroup>
66-
67-
<ItemGroup>
68-
<Compile Remove="Accounts\**" />
69-
<Compile Remove="Engines\CoreNlp\**" />
70-
<EmbeddedResource Remove="Accounts\**" />
71-
<EmbeddedResource Remove="Engines\CoreNlp\**" />
72-
<None Remove="Accounts\**" />
73-
<None Remove="Engines\CoreNlp\**" />
74-
</ItemGroup>
75-
7648
<ItemGroup>
77-
<PackageReference Include="BotSharp.NLP" Version="0.3.0" />
7849
<PackageReference Include="Colorful.Console" Version="1.2.9" />
7950
<PackageReference Include="DotNetToolkit" Version="1.6.0" />
8051
<PackageReference Include="EntityFrameworkCore.BootKit" Version="1.9.1" />
81-
<PackageReference Include="JiebaNet.Segmenter" Version="1.0.4" />
8252
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="2.1.1" />
8353
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
8454
<PackageReference Include="RestSharp" Version="106.3.1" />
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<ShowAllFiles>false</ShowAllFiles>
5+
</PropertyGroup>
6+
</Project>
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
5+
namespace JiebaNet.Segmenter.Common
6+
{
7+
public interface ICounter<T>
8+
{
9+
int Count { get; }
10+
int Total { get; }
11+
int this[T key] { get; set; }
12+
IEnumerable<KeyValuePair<T, int>> Elements { get; }
13+
14+
/// <summary>
15+
/// Lists the n most common elements from the most common to the least.
16+
/// </summary>
17+
/// <param name="n">Number of elements, list all elements if n is less than 0.</param>
18+
/// <returns></returns>
19+
IEnumerable<KeyValuePair<T, int>> MostCommon(int n = -1);
20+
21+
/// <summary>
22+
/// Subtracts items from a counter.
23+
/// </summary>
24+
/// <param name="items"></param>
25+
void Subtract(IEnumerable<T> items);
26+
27+
/// <summary>
28+
/// Subtracts counts from another counter.
29+
/// </summary>
30+
/// <param name="other"></param>
31+
void Subtract(ICounter<T> other);
32+
33+
/// <summary>
34+
/// Adds items to a counter.
35+
/// </summary>
36+
/// <param name="items"></param>
37+
void Add(IEnumerable<T> items);
38+
39+
/// <summary>
40+
/// Adds another counter.
41+
/// </summary>
42+
/// <param name="other"></param>
43+
void Add(ICounter<T> other);
44+
45+
/// <summary>
46+
/// Union is the maximum of value in either of the input <see cref="ICounter{T}"/>.
47+
/// </summary>
48+
/// <param name="other">The other counter.</param>
49+
ICounter<T> Union(ICounter<T> other);
50+
51+
void Remove(T key);
52+
void Clear();
53+
bool Contains(T key);
54+
}
55+
56+
public class Counter<T>: ICounter<T>
57+
{
58+
private Dictionary<T, int> data = new Dictionary<T, int>();
59+
60+
public Counter() {}
61+
62+
public Counter(IEnumerable<T> items)
63+
{
64+
CountItems(items);
65+
}
66+
67+
public int Count => data.Count;
68+
public int Total => data.Values.Sum();
69+
public IEnumerable<KeyValuePair<T, int>> Elements => data;
70+
71+
public int this[T key]
72+
{
73+
get => data.ContainsKey(key) ? data[key] : 0;
74+
set => data[key] = value;
75+
}
76+
77+
public IEnumerable<KeyValuePair<T, int>> MostCommon(int n = -1)
78+
{
79+
var pairs = data.Where(pair => pair.Value > 0).OrderByDescending(pair => pair.Value);
80+
return n < 0 ? pairs : pairs.Take(n);
81+
}
82+
83+
public void Subtract(IEnumerable<T> items)
84+
{
85+
SubtractItems(items);
86+
}
87+
88+
public void Subtract(ICounter<T> other)
89+
{
90+
SubtractPairs(other.Elements);
91+
}
92+
93+
public void Add(IEnumerable<T> items)
94+
{
95+
CountItems(items);
96+
}
97+
98+
public void Add(ICounter<T> other)
99+
{
100+
CountPairs(other.Elements);
101+
}
102+
103+
public ICounter<T> Union(ICounter<T> other)
104+
{
105+
var result = new Counter<T>();
106+
foreach (var pair in data)
107+
{
108+
var count = pair.Value;
109+
var otherCount = other[pair.Key];
110+
var newCount = count < otherCount ? otherCount : count;
111+
result[pair.Key] = newCount;
112+
}
113+
114+
foreach (var pair in other.Elements)
115+
{
116+
if (!Contains(pair.Key))
117+
{
118+
result[pair.Key] = pair.Value;
119+
}
120+
}
121+
return result;
122+
}
123+
124+
public void Remove(T key)
125+
{
126+
if (data.ContainsKey(key))
127+
{
128+
data.Remove(key);
129+
}
130+
}
131+
132+
public void Clear()
133+
{
134+
data.Clear();
135+
}
136+
137+
public bool Contains(T key)
138+
{
139+
return data.ContainsKey(key);
140+
}
141+
142+
#region Private Methods
143+
144+
private void CountItems(IEnumerable<T> items)
145+
{
146+
foreach (var item in items)
147+
{
148+
data[item] = data.GetDefault(item, 0) + 1;
149+
}
150+
}
151+
152+
private void CountPairs(IEnumerable<KeyValuePair<T, int>> pairs)
153+
{
154+
foreach (var pair in pairs)
155+
{
156+
this[pair.Key] += pair.Value;
157+
}
158+
}
159+
160+
private void SubtractItems(IEnumerable<T> items)
161+
{
162+
foreach (var item in items)
163+
{
164+
data[item] = data.GetDefault(item, 0) - 1;
165+
}
166+
}
167+
168+
private void SubtractPairs(IEnumerable<KeyValuePair<T, int>> pairs)
169+
{
170+
foreach (var pair in pairs)
171+
{
172+
this[pair.Key] -= pair.Value;
173+
}
174+
}
175+
176+
#endregion
177+
}
178+
}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text.RegularExpressions;
5+
6+
namespace JiebaNet.Segmenter.Common
7+
{
8+
public static class Extensions
9+
{
10+
private static readonly Regex RegexDigits = new Regex(@"\d+", RegexOptions.Compiled);
11+
private static readonly Regex RegexNewline = new Regex("(\r\n|\n|\r)", RegexOptions.Compiled);
12+
13+
#region Objects
14+
15+
public static bool IsNull(this object obj)
16+
{
17+
return obj == null;
18+
}
19+
20+
public static bool IsNotNull(this object obj)
21+
{
22+
return obj != null;
23+
}
24+
25+
#endregion
26+
27+
28+
#region Enumerable
29+
30+
public static bool IsEmpty<T>(this IEnumerable<T> enumerable)
31+
{
32+
return (enumerable == null) || !enumerable.Any();
33+
}
34+
35+
public static bool IsNotEmpty<T>(this IEnumerable<T> enumerable)
36+
{
37+
return (enumerable != null) && enumerable.Any();
38+
}
39+
40+
public static TValue GetValueOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> d, TKey key)
41+
{
42+
return d.ContainsKey(key) ? d[key] : default(TValue);
43+
}
44+
45+
public static TValue GetDefault<TKey, TValue>(this IDictionary<TKey, TValue> dict, TKey key, TValue defaultValue)
46+
{
47+
if (dict.ContainsKey(key))
48+
{
49+
return dict[key];
50+
}
51+
return defaultValue;
52+
}
53+
54+
public static void Update<TKey, TValue>(this IDictionary<TKey, TValue> dict, IDictionary<TKey, TValue> other)
55+
{
56+
foreach (var key in other.Keys)
57+
{
58+
dict[key] = other[key];
59+
}
60+
}
61+
62+
#endregion
63+
64+
#region String & Text
65+
66+
public static string Left(this string s, int endIndex)
67+
{
68+
if (string.IsNullOrEmpty(s))
69+
{
70+
return s;
71+
}
72+
73+
return s.Substring(0, endIndex);
74+
}
75+
76+
public static string Right(this string s, int startIndex)
77+
{
78+
if (string.IsNullOrEmpty(s))
79+
{
80+
return s;
81+
}
82+
83+
84+
return s.Substring(startIndex);
85+
}
86+
87+
public static string Sub(this string s, int startIndex, int endIndex)
88+
{
89+
return s.Substring(startIndex, endIndex - startIndex);
90+
}
91+
92+
public static bool IsInt32(this string s)
93+
{
94+
return RegexDigits.IsMatch(s);
95+
}
96+
97+
public static string[] SplitLines(this string s)
98+
{
99+
return RegexNewline.Split(s);
100+
}
101+
102+
public static string Join(this IEnumerable<string> inputs, string separator = ", ")
103+
{
104+
return string.Join(separator, inputs);
105+
}
106+
107+
public static IEnumerable<string> SubGroupValues(this GroupCollection groups)
108+
{
109+
var result = from Group g in groups
110+
select g.Value;
111+
return result.Skip(1);
112+
}
113+
114+
#endregion
115+
116+
#region Conversion
117+
118+
public static int ToInt32(this char ch)
119+
{
120+
return ch;
121+
}
122+
123+
public static char ToChar(this int i)
124+
{
125+
return (char)i;
126+
}
127+
128+
#endregion
129+
}
130+
}

0 commit comments

Comments
 (0)