Skip to content

Commit

Permalink
Turn LanguageModel into protocol (interface in CSharp). (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShikiSuen authored Jun 21, 2022
1 parent 8380a6f commit c4bdba5
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Megrez.Tests/Megrez.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<ReleaseVersion>1.2.4</ReleaseVersion>
<ReleaseVersion>1.2.5</ReleaseVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
5 changes: 3 additions & 2 deletions Megrez.Tests/MegrezTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,9 @@ public SimpleLM(string input, bool swapKeyValue = false) {
}
}
}
public override List<Unigram> UnigramsFor(string key) => _database.ContainsKey(key) ? _database[key] : new();
public override bool HasUnigramsFor(string key) => _database.ContainsKey(key);
public List<Bigram> BigramsForKeys(string precedingKey, string key) { return new(); }
public List<Unigram> UnigramsFor(string key) => _database.ContainsKey(key) ? _database[key] : new();
public bool HasUnigramsFor(string key) => _database.ContainsKey(key);
}

public class TestClass {
Expand Down
2 changes: 1 addition & 1 deletion Megrez.sln
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ Global
$0.DotNetNamingPolicy = $4
$4.DirectoryNamespaceAssociation = PrefixedHierarchical
$0.StandardHeader = $5
version = 1.2.4
version = 1.2.5
EndGlobalSection
EndGlobal
25 changes: 5 additions & 20 deletions Megrez/5_LanguageModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,44 +28,29 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

namespace Megrez {
/// <summary>
/// 語言模型框架,回頭實際使用時需要派生一個型別、且重寫相關函式。
/// 語言模型框架協定,實際使用時需要派生一個型別、且重寫相關函式。
/// </summary>
public class LanguageModel {
/// <summary>
/// 語言模型框架,回頭實際使用時需要派生一個型別、且重寫相關函式。
/// </summary>
public LanguageModel() {}

// This function works merely as a placeholder.
// Please override this function to implement your own methods.
public interface LanguageModel {
/// <summary>
/// 給定鍵,讓語言模型找給一組單元圖陣列。
/// </summary>
/// <param name="key">給定鍵。</param>
/// <returns>一組單元圖陣列。</returns>
public virtual List<Unigram> UnigramsFor(string key) {
return key.Length == 0 ? new List<Unigram>().ToList() : new();
}
public List<Unigram> UnigramsFor(string key);

// This function works merely as a placeholder.
// Please override this function to implement your own methods.
/// <summary>
/// 給定當前鍵與前述鍵,讓語言模型找給一組雙元圖陣列。
/// </summary>
/// <param name="precedingKey">前述鍵。</param>
/// <param name="key">當前鍵。</param>
/// <returns>一組雙元圖陣列。</returns>
public virtual List<Bigram> BigramsForKeys(string precedingKey, string key) {
return precedingKey == key ? new List<Bigram>().ToList() : new();
}
public List<Bigram> BigramsForKeys(string precedingKey, string key);

// This function works merely as a placeholder.
// Please override this function to implement your own methods.
/// <summary>
/// 給定鍵,確認是否有單元圖記錄在庫。
/// </summary>
/// <param name="key">給定鍵。</param>
/// <returns>True 則表示在庫,False 則表示不在庫。</returns>
public virtual bool HasUnigramsFor(string key) { return key.Length != 0; }
public bool HasUnigramsFor(string key);
}
}
8 changes: 4 additions & 4 deletions Megrez/Megrez.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ReleaseVersion>1.2.4</ReleaseVersion>
<ReleaseVersion>1.2.5</ReleaseVersion>
<PackageId>vChewing.Megrez</PackageId>
<Authors>Shiki Suen</Authors>
<Company>Atelier Inmu</Company>
<Copyright>(c) 2022 and onwards The vChewing Project (MIT-NTL License).</Copyright>
<RepositoryUrl>https://github.com/ShikiSuen/MegrezNT</RepositoryUrl>
<NeutralLanguage>zh-TW</NeutralLanguage>
<AssemblyVersion>1.2.4</AssemblyVersion>
<FileVersion>1.2.4</FileVersion>
<Version>1.2.4</Version>
<AssemblyVersion>1.2.5</AssemblyVersion>
<FileVersion>1.2.5</FileVersion>
<Version>1.2.5</Version>
<Product>Megrez</Product>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down

0 comments on commit c4bdba5

Please sign in to comment.