-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: 책 이름과 약자를 다국어로 사용할 수 있게 준비
* 다국어 책 이름, 약자 제공자 추가 resolves #96, resolves #97 * 성경 소스가 다국어 책 이름 약자를 매칭하는 방법 개선 resolves #95 * 성경 구절 검색어로 다국어 책 이름 약자 사용 resolves #93
- Loading branch information
1 parent
7138e9f
commit 6609400
Showing
36 changed files
with
1,056 additions
and
198 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
Bible2PPT.Services.BibleIndexService.Tests/Bible2PPT.Services.BibleIndexService.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" /> | ||
<PackageReference Include="Shouldly" Version="4.0.3" /> | ||
<PackageReference Include="xunit" Version="2.4.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="3.1.2"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Bible2PPT.Services.BibleIndexService\Bible2PPT.Services.BibleIndexService.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
global using Shouldly; | ||
global using Xunit; |
36 changes: 36 additions & 0 deletions
36
Bible2PPT.Services.BibleIndexService.Tests/VerseQueryParserTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Bible2PPT.Services.BibleIndexService.Tests; | ||
|
||
public class VerseQueryParserTest | ||
{ | ||
[Theory] | ||
[InlineData("", 0)] | ||
[InlineData(" ", 0)] | ||
[InlineData("창", 1)] | ||
[InlineData(" 창", 1)] | ||
[InlineData(" 창 ", 1)] | ||
[InlineData("창1", 1)] | ||
[InlineData("창 롬", 2)] | ||
[InlineData("창 롬1", 2)] | ||
[InlineData("창1 롬", 2)] | ||
[InlineData("창1 롬1", 2)] | ||
public void Parse_Counts(string queryString, int count) | ||
{ | ||
var parser = GetVerseQueryParser(); | ||
|
||
parser.ParseVerseQueries(queryString).Count().ShouldBe(count); | ||
} | ||
|
||
private static VerseQueryParser GetVerseQueryParser() | ||
{ | ||
var services = new ServiceCollection(); | ||
services.AddBibleIndexService(options => options.UseSqlite("Data Source=file::memory:?cache=shared")); | ||
|
||
var serviceProvider = services.BuildServiceProvider(); | ||
serviceProvider.UseBibleIndexService(); | ||
|
||
return serviceProvider.GetRequiredService<VerseQueryParser>(); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
Bible2PPT.Services.BibleIndexService.Tests/VerseQueryRangeTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System.Globalization; | ||
|
||
namespace Bible2PPT.Services.BibleIndexService.Tests; | ||
|
||
public class VerseQueryRangeTest | ||
{ | ||
[Theory] | ||
[InlineData(null, 1, 1, null, null)] | ||
[InlineData("", 1, 1, null, null)] | ||
[InlineData("4", 4, 1, 4, null)] | ||
[InlineData("4-9", 4, 1, 9, null)] | ||
[InlineData("4-9:8", 4, 1, 9, 8)] | ||
[InlineData("4:3", 4, 3, 4, 3)] | ||
[InlineData("4:3-8", 4, 3, 4, 8)] | ||
[InlineData("4:3-9:8", 4, 3, 9, 8)] | ||
public void Parse_Success(string? s, int startChapter, int startVerse, int? endChapter, int? endVerse) | ||
{ | ||
VerseQueryRange.TryParse(s, CultureInfo.InvariantCulture, out var result).ShouldBeTrue(); | ||
|
||
result.StartChapterNumber.ShouldBe(startChapter); | ||
result.StartVerseNumber.ShouldBe(startVerse); | ||
result.EndChapterNumber.ShouldBe(endChapter); | ||
result.EndVerseNumber.ShouldBe(endVerse); | ||
} | ||
|
||
[Theory] | ||
[InlineData("GEN")] | ||
[InlineData("1SAM")] | ||
public void Parse_BookAbbr_Fail(string s) | ||
{ | ||
VerseQueryRange.TryParse(s, CultureInfo.InvariantCulture, out _).ShouldBeFalse(); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
Bible2PPT.Services.BibleIndexService/Bible2PPT.Services.BibleIndexService.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<LangVersion>preview</LangVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.1"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.1" /> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace Bible2PPT.Services.BibleIndexService; | ||
|
||
public class BibleIndexContext : DbContext | ||
{ | ||
public BibleIndexContext(DbContextOptions<BibleIndexContext> options) | ||
: base(options) | ||
{ | ||
} | ||
|
||
public DbSet<BookInfo> BookInfos => Set<BookInfo>(); | ||
|
||
protected override void OnModelCreating(ModelBuilder modelBuilder) | ||
{ | ||
modelBuilder.Entity<BookInfo>().HasKey(x => new { x.Key, x.Kind, x.LanguageCode, x.Version }); | ||
modelBuilder.Entity<BookInfo>().HasData(new[] | ||
{ | ||
BibleIndexSeed.SeedKoreanV1(), | ||
BibleIndexSeed.SeedKoreanV2(), | ||
} | ||
.SelectMany(x => x)); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
Bible2PPT.Services.BibleIndexService/BibleIndexSeed.KoreanV1.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
namespace Bible2PPT.Services.BibleIndexService; | ||
|
||
internal static partial class BibleIndexSeed | ||
{ | ||
public static IEnumerable<BookInfo> SeedKoreanV1() => | ||
new CsvBibleIndexSeedBuilder("ko", "개역 성경") | ||
.Build($""" | ||
{BookKey.Genesis},창세기,창 | ||
{BookKey.Exodus},출애굽기,출 | ||
{BookKey.Leviticus},레위기,레 | ||
{BookKey.Numbers},민수기,민 | ||
{BookKey.Deuteronomy},신명기,신 | ||
{BookKey.Joshua},여호수아,수 | ||
{BookKey.Judges},사사기,삿 | ||
{BookKey.Ruth},룻기,룻 | ||
{BookKey.ISamuel},사무엘상,삼상 | ||
{BookKey.IISamuel},사무엘하,삼하 | ||
{BookKey.IKings},열왕기상,왕상 | ||
{BookKey.IIKings},열왕기하,왕하 | ||
{BookKey.IChronicles},역대상,대상 | ||
{BookKey.IIChronicles},역대하,대하 | ||
{BookKey.Ezra},에스라,스 | ||
{BookKey.Nehemiah},느헤미야,느 | ||
{BookKey.Esther},에스더,에 | ||
{BookKey.Job},욥기,욥 | ||
{BookKey.Psalms},시편,시 | ||
{BookKey.Proverbs},잠언,잠 | ||
{BookKey.Ecclesiastes},전도서,전 | ||
{BookKey.SongOfSolomon},아가,아 | ||
{BookKey.Isaiah},이사야,사 | ||
{BookKey.Jeremiah},예레미야,렘 | ||
{BookKey.Lamentations},예레미야애가,애 | ||
{BookKey.Ezekiel},에스겔,겔 | ||
{BookKey.Daniel},다니엘,단 | ||
{BookKey.Hosea},호세아,호 | ||
{BookKey.Joel},요엘,욜 | ||
{BookKey.Amos},아모스,암 | ||
{BookKey.Obadiah},오바댜,옵 | ||
{BookKey.Jonah},요나,욘 | ||
{BookKey.Micah},미가,미 | ||
{BookKey.Nahum},나홈,나 | ||
{BookKey.Habakkuk},하박국,합 | ||
{BookKey.Zephaniah},스바냐,습 | ||
{BookKey.Haggai},학개,학 | ||
{BookKey.Zechariah},스가랴,슥 | ||
{BookKey.Malachi},말라기,말 | ||
{BookKey.Matthew},마태복음,마 | ||
{BookKey.Mark},마가복음,막 | ||
{BookKey.Luke},누가복음,눅 | ||
{BookKey.John},요한복음,요 | ||
{BookKey.Acts},사도행전,행 | ||
{BookKey.Romans},로마서,롬 | ||
{BookKey.ICorinthians},고린도전서,고전 | ||
{BookKey.IICorinthians},고린도후서,고후 | ||
{BookKey.Galatians},갈라디아서,갈 | ||
{BookKey.Ephesians},에베소서,엡 | ||
{BookKey.Philippians},빌립보서,빌 | ||
{BookKey.Colossians},골로새서,골 | ||
{BookKey.IThessalonians},데살로니가전서,살전 | ||
{BookKey.IIThessalonians},데살로니가후서,살후 | ||
{BookKey.ITimothy},디모데전서,딤전 | ||
{BookKey.IITimothy},디모데후서,딤후 | ||
{BookKey.Titus},디도서,딛 | ||
{BookKey.Philemon},빌레몬서,몬 | ||
{BookKey.Hebrews},히브리서,히 | ||
{BookKey.James},야고보서,약 | ||
{BookKey.IPeter},베드로전서,벧전 | ||
{BookKey.IIPeter},베드로후서,벧후 | ||
{BookKey.IJohn},요한일서,요일 | ||
{BookKey.IIJohn},요한이서,요이 | ||
{BookKey.IIIJohn},요한삼서,요삼 | ||
{BookKey.Jude},유다서,유 | ||
{BookKey.Revelation},요한계시록,계 | ||
"""); | ||
} |
75 changes: 75 additions & 0 deletions
75
Bible2PPT.Services.BibleIndexService/BibleIndexSeed.KoreanV2.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
namespace Bible2PPT.Services.BibleIndexService; | ||
|
||
internal static partial class BibleIndexSeed | ||
{ | ||
public static IEnumerable<BookInfo> SeedKoreanV2() => | ||
new CsvBibleIndexSeedBuilder("ko", "새번역 성경") | ||
.Build($""" | ||
{BookKey.Genesis},창세기,창 | ||
{BookKey.Exodus},출애굽기,출 | ||
{BookKey.Leviticus},레위기,레 | ||
{BookKey.Numbers},민수기,민 | ||
{BookKey.Deuteronomy},신명기,신 | ||
{BookKey.Joshua},여호수아,수 | ||
{BookKey.Judges},사사기,삿 | ||
{BookKey.Ruth},룻기,룻 | ||
{BookKey.ISamuel},사무엘상,삼상 | ||
{BookKey.IISamuel},사무엘하,삼하 | ||
{BookKey.IKings},열왕기상,왕상 | ||
{BookKey.IIKings},열왕기하,왕하 | ||
{BookKey.IChronicles},역대상,대상 | ||
{BookKey.IIChronicles},역대하,대하 | ||
{BookKey.Ezra},에스라,라 | ||
{BookKey.Nehemiah},느헤미야,느 | ||
{BookKey.Esther},에스더,더 | ||
{BookKey.Job},욥기,욥 | ||
{BookKey.Psalms},시편,시 | ||
{BookKey.Proverbs},잠언,잠 | ||
{BookKey.Ecclesiastes},전도서,전 | ||
{BookKey.SongOfSolomon},아가,아 | ||
{BookKey.Isaiah},이사야,사 | ||
{BookKey.Jeremiah},예레미야,렘 | ||
{BookKey.Lamentations},예레미야애가,애 | ||
{BookKey.Ezekiel},에스겔,겔 | ||
{BookKey.Daniel},다니엘,단 | ||
{BookKey.Hosea},호세아,호 | ||
{BookKey.Joel},요엘,욜 | ||
{BookKey.Amos},아모스,암 | ||
{BookKey.Obadiah},오바댜,옵 | ||
{BookKey.Jonah},요나,욘 | ||
{BookKey.Micah},미가,미 | ||
{BookKey.Nahum},나홈,나 | ||
{BookKey.Habakkuk},하박국,합 | ||
{BookKey.Zephaniah},스바냐,습 | ||
{BookKey.Haggai},학개,학 | ||
{BookKey.Zechariah},스가랴,슥 | ||
{BookKey.Malachi},말라기,말 | ||
{BookKey.Matthew},마태복음,마 | ||
{BookKey.Mark},마가복음,막 | ||
{BookKey.Luke},누가복음,눅 | ||
{BookKey.John},요한복음,요 | ||
{BookKey.Acts},사도행전,행 | ||
{BookKey.Romans},로마서,롬 | ||
{BookKey.ICorinthians},고린도전서,고전 | ||
{BookKey.IICorinthians},고린도후서,고후 | ||
{BookKey.Galatians},갈라디아서,갈 | ||
{BookKey.Ephesians},에베소서,엡 | ||
{BookKey.Philippians},빌립보서,빌 | ||
{BookKey.Colossians},골로새서,골 | ||
{BookKey.IThessalonians},데살로니가전서,살전 | ||
{BookKey.IIThessalonians},데살로니가후서,살후 | ||
{BookKey.ITimothy},디모데전서,딤전 | ||
{BookKey.IITimothy},디모데후서,딤후 | ||
{BookKey.Titus},디도서,딛 | ||
{BookKey.Philemon},빌레몬서,몬 | ||
{BookKey.Hebrews},히브리서,히 | ||
{BookKey.James},야고보서,약 | ||
{BookKey.IPeter},베드로전서,벧전 | ||
{BookKey.IIPeter},베드로후서,벧후 | ||
{BookKey.IJohn},요한일서,요일 | ||
{BookKey.IIJohn},요한이서,요이 | ||
{BookKey.IIIJohn},요한삼서,요삼 | ||
{BookKey.Jude},유다서,유 | ||
{BookKey.Revelation},요한계시록,계 | ||
"""); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace Bible2PPT.Services.BibleIndexService; | ||
|
||
public class BibleIndexService | ||
{ | ||
private readonly IDbContextFactory<BibleIndexContext> _dbFactory; | ||
|
||
public BibleIndexService(IDbContextFactory<BibleIndexContext> dbFactory) | ||
{ | ||
_dbFactory = dbFactory; | ||
} | ||
|
||
public BookInfo GetBookInfo(BookKey key, string languageCode) | ||
{ | ||
using var db = _dbFactory.CreateDbContext(); | ||
return db.BookInfos | ||
.Where(x => (x.Key == key) && (x.LanguageCode == languageCode)) | ||
.OrderByDescending(x => x.IsPrimary) | ||
.First(); | ||
} | ||
|
||
public string GetBookName(BookKey key, string languageCode) | ||
{ | ||
using var db = _dbFactory.CreateDbContext(); | ||
|
||
return GetBookInfoCandidates(db, key, languageCode) | ||
.Where(x => x.Kind == BookInfoKind.Name) | ||
.OrderByDescending(x => x.IsPrimary) | ||
.First() | ||
.Value; | ||
} | ||
|
||
public string GetBookAbbreviation(BookKey key, string languageCode) | ||
{ | ||
using var db = _dbFactory.CreateDbContext(); | ||
|
||
return GetBookInfoCandidates(db, key, languageCode) | ||
.Where(x => x.Kind == BookInfoKind.Abbreviation) | ||
.OrderByDescending(x => x.IsPrimary) | ||
.First() | ||
.Value; | ||
} | ||
|
||
public void AddBookInfos(IEnumerable<BookInfo> bookInfos) | ||
{ | ||
using var db = _dbFactory.CreateDbContext(); | ||
db.BookInfos.AddRange(bookInfos); | ||
} | ||
|
||
public BookInfo? FindBookInfoExactAbbreviation(string abbr) | ||
{ | ||
using var db = _dbFactory.CreateDbContext(); | ||
|
||
var infos = db.BookInfos.Where(x => x.Kind == BookInfoKind.Abbreviation && x.Value == abbr); | ||
if (infos.Select(x => x.Key).Distinct().Count() != 1) | ||
{ | ||
return null; | ||
} | ||
|
||
return infos.First(); | ||
} | ||
|
||
private static IQueryable<BookInfo> GetBookInfoCandidates(BibleIndexContext db, BookKey key, string languageCode) | ||
{ | ||
var bookInfo = db.BookInfos.Where(x => x.Key == key); | ||
|
||
var languageMatches = bookInfo.Where(x => x.LanguageCode == languageCode); | ||
if (!languageMatches.Any()) | ||
{ | ||
return bookInfo; | ||
} | ||
|
||
return languageMatches; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace Bible2PPT.Services.BibleIndexService; | ||
|
||
public record BookInfo | ||
{ | ||
public BookKey Key { get; set; } | ||
public BookInfoKind Kind { get; set; } | ||
public string LanguageCode { get; set; } = null!; | ||
public string Version { get; set; } = null!; | ||
|
||
public string Value { get; set; } = null!; | ||
|
||
public bool IsPrimary { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Bible2PPT.Services.BibleIndexService; | ||
|
||
public enum BookInfoKind | ||
{ | ||
Name, | ||
Abbreviation, | ||
} |
Oops, something went wrong.