Skip to content

Commit

Permalink
feat: 다국어 책 이름과 약자 데이터 추가
Browse files Browse the repository at this point in the history
resolves #96, resolves #95, resolves #97
  • Loading branch information
sunghwan2789 committed Feb 23, 2022
1 parent 7138e9f commit de2de2d
Show file tree
Hide file tree
Showing 24 changed files with 731 additions and 104 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</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>
24 changes: 24 additions & 0 deletions Bible2PPT.Services.BibleIndexService/BibleIndexContext.cs
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));
}
}
83 changes: 83 additions & 0 deletions Bible2PPT.Services.BibleIndexService/BibleIndexSeed.KoreanV1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
namespace Bible2PPT.Services.BibleIndexService;

internal static partial class BibleIndexSeed
{
public static IEnumerable<BookInfo> SeedKoreanV1() =>
new[]
{
@$"{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},요한계시록,계",
}
.Select(x => x.Split(','))
.Select(x => new { Key = Enum.Parse<BookKey>(x[0]), Data = x[1..] })
.SelectMany(x => new[]
{
new BookInfo { Key = x.Key, Kind = BookInfoKind.Name, Value = x.Data[0] },
new BookInfo { Key = x.Key, Kind = BookInfoKind.Abbreviation, Value = x.Data[1] },
})
.Select(x => x with { LanguageCode = "ko", Version = "개역 성경" });
}
83 changes: 83 additions & 0 deletions Bible2PPT.Services.BibleIndexService/BibleIndexSeed.KoreanV2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
namespace Bible2PPT.Services.BibleIndexService;

internal static partial class BibleIndexSeed
{
public static IEnumerable<BookInfo> SeedKoreanV2() =>
new[]
{
@$"{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},요한계시록,계",
}
.Select(x => x.Split(','))
.Select(x => new { Key = Enum.Parse<BookKey>(x[0]), Data = x[1..] })
.SelectMany(x => new[]
{
new BookInfo { Key = x.Key, Kind = BookInfoKind.Name, Value = x.Data[0] },
new BookInfo { Key = x.Key, Kind = BookInfoKind.Abbreviation, Value = x.Data[1] },
})
.Select(x => x with { LanguageCode = "ko", Version = "새번역 성경" });
}
63 changes: 63 additions & 0 deletions Bible2PPT.Services.BibleIndexService/BibleIndexService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
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);
}

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;
}
}
13 changes: 13 additions & 0 deletions Bible2PPT.Services.BibleIndexService/BookInfo.cs
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; }
}
7 changes: 7 additions & 0 deletions Bible2PPT.Services.BibleIndexService/BookInfoKind.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Bible2PPT.Services.BibleIndexService;

public enum BookInfoKind
{
Name,
Abbreviation,
}
90 changes: 90 additions & 0 deletions Bible2PPT.Services.BibleIndexService/BookKey.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
namespace Bible2PPT.Services.BibleIndexService;

public enum BookKey
{
Unknown,
// 구약
Genesis,
Exodus,
Leviticus,
Numbers,
Deuteronomy,
Joshua,
Judges,
Ruth,
ISamuel,
IISamuel,
IKings,
IIKings,
IChronicles,
IIChronicles,
Ezra,
Nehemiah,
Esther,
Job,
Psalms,
Proverbs,
Ecclesiastes,
SongOfSolomon,
Isaiah,
Jeremiah,
Lamentations,
Ezekiel,
Daniel,
Hosea,
Joel,
Amos,
Obadiah,
Jonah,
Micah,
Nahum,
Habakkuk,
Zephaniah,
Haggai,
Zechariah,
Malachi,
// 외경
Tobit,
Judith,
AdditionsToEsther,
Wisdom,
Sirach,
Baruch,
LetterOfJeremiah,
PrayerOfAzariahAndTheSongOfThreeJews,
Susanna,
BelAndTheDragon,
IMaccabees,
IIMaccabees,
IEsdras,
IIEsdras,
PrayerOfManasseh,
// 신약
Matthew,
Mark,
Luke,
John,
Acts,
Romans,
ICorinthians,
IICorinthians,
Galatians,
Ephesians,
Philippians,
Colossians,
IThessalonians,
IIThessalonians,
ITimothy,
IITimothy,
Titus,
Philemon,
Hebrews,
James,
IPeter,
IIPeter,
IJohn,
IIJohn,
IIIJohn,
Jude,
Revelation,
}
Loading

0 comments on commit de2de2d

Please sign in to comment.