forked from kc3hack/2024_H
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
901 additions
and
100 deletions.
There are no files selected for viewing
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,40 @@ | ||
using KoeBook.Epub.Contracts.Services; | ||
using KoeBook.Epub.Models; | ||
using KoeBook.Models; | ||
|
||
namespace KoeBook.Epub.Services; | ||
|
||
public partial class AiStoryAnalyzerService(ISplitBraceService splitBraceService) | ||
{ | ||
private readonly ISplitBraceService _splitBraceService = splitBraceService; | ||
|
||
|
||
public EpubDocument CreateEpubDocument(AiStory aiStory, Guid id) | ||
{ | ||
return new EpubDocument(aiStory.Title, "AI", "", id) | ||
{ | ||
Chapters = [new Chapter() | ||
{ | ||
Sections = [ | ||
new Section("本編") | ||
{ | ||
Elements = aiStory.Lines.SelectMany(s => | ||
s.SelectMany(p => _splitBraceService.SplitBrace(p.GetText()) | ||
.Zip(_splitBraceService.SplitBrace(p.GetScript())) | ||
.Select(Element (p) => new Paragraph | ||
{ | ||
Text = p.First, | ||
ScriptLine = new(p.Second, "", "") | ||
})) | ||
.Append(new Paragraph() | ||
{ | ||
Text = "", | ||
ScriptLine = new("", "", "") | ||
}) | ||
).ToList(), | ||
} | ||
] | ||
}] | ||
}; | ||
} | ||
} |
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
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
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,8 @@ | ||
using Claudia; | ||
|
||
namespace KoeBook.Core.Contracts.Services; | ||
|
||
public interface IClaudeService | ||
{ | ||
IMessages? Messages { get; } | ||
} |
19 changes: 19 additions & 0 deletions
19
KoeBook.Core/Contracts/Services/ICreateCoverFileService.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,19 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace KoeBook.Core.Contracts.Services; | ||
|
||
public interface ICreateCoverFileService | ||
{ | ||
/// <summary> | ||
/// 表紙用の画像を作成 | ||
/// </summary> | ||
/// <param name="title">作品の題名</param> | ||
/// <param name="author">作品の著者名</param> | ||
/// <param name="coverFilePath">表紙の画像を置くフォルダのパス</param> | ||
/// <returns>成功すれば、true、失敗すれば、false</returns> | ||
void Create(string title, string author, string coverFilePath); | ||
} |
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
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,9 @@ | ||
using KoeBook.Core.Models; | ||
|
||
namespace KoeBook.Core.Contracts.Services; | ||
|
||
public interface IStoryCreatorService | ||
{ | ||
/// <returns>XML</returns> | ||
public ValueTask<string> CreateStoryAsync(StoryGenre genre, string instruction, CancellationToken cancellationToken); | ||
} |
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
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
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,50 @@ | ||
using System.Xml.Serialization; | ||
|
||
namespace KoeBook.Models; | ||
|
||
[XmlRoot("Book")] | ||
public class AiStory | ||
{ | ||
|
||
[XmlElement("Title", typeof(string), IsNullable = false)] | ||
public string Title { get; init; } = ""; | ||
|
||
[XmlArray("Content", IsNullable = false)] | ||
[XmlArrayItem("Section", IsNullable = false)] | ||
[XmlArrayItem("Paragraph", IsNullable = false, NestingLevel = 1)] | ||
public Line[][] Lines { get; init; } = []; | ||
|
||
public record Line( | ||
[property: XmlElement("Text", typeof(Text), IsNullable = false), XmlElement("Ruby", typeof(Ruby), IsNullable = false)] InlineElement[] Inlines) | ||
{ | ||
private Line() : this([]) { } | ||
|
||
public string GetText() => string.Concat(Inlines.Select(e => e.Html)); | ||
|
||
public string GetScript() => string.Concat(Inlines.Select(e => e.Script)); | ||
} | ||
|
||
public abstract record class InlineElement | ||
{ | ||
public abstract string Html { get; } | ||
public abstract string Script { get; } | ||
} | ||
|
||
public record Text([property: XmlText] string InnerText) : InlineElement | ||
{ | ||
private Text() : this("") { } | ||
|
||
public override string Html => InnerText; | ||
public override string Script => InnerText; | ||
} | ||
|
||
public record Ruby( | ||
[property: XmlElement("Rb", IsNullable = false)] string Rb, | ||
[property: XmlElement("Rt", IsNullable = false)] string Rt) : InlineElement | ||
{ | ||
private Ruby() : this("", "") { } | ||
|
||
public override string Html => $"<ruby>{Rb}<rt>{Rt}</rt></ruby>"; | ||
public override string Script => Rt; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,13 +1,34 @@ | ||
namespace KoeBook.Core.Models; | ||
using KoeBook.Models; | ||
|
||
namespace KoeBook.Core.Models; | ||
|
||
/// <summary> | ||
/// 読み上げる本の情報 | ||
/// </summary> | ||
public class BookProperties(Guid id, string source, SourceType sourceType) | ||
public class BookProperties | ||
{ | ||
public Guid Id { get; } = id; | ||
public BookProperties(Guid id, string source, SourceType sourceType) | ||
{ | ||
if (sourceType != SourceType.FilePath && sourceType != SourceType.Url) | ||
throw new ArgumentException($"{nameof(sourceType)}は{nameof(SourceType.FilePath)}か{nameof(SourceType.Url)}である必要があります。"); | ||
Id = id; | ||
Source = source; | ||
SourceType = sourceType; | ||
} | ||
|
||
public BookProperties(Guid id, AiStory aiStory) | ||
{ | ||
Id = id; | ||
Source = aiStory; | ||
SourceType = SourceType.AiStory; | ||
} | ||
|
||
public Guid Id { get; } | ||
|
||
public string Source { get; } = source; | ||
/// <summary> | ||
/// UriまたはAiStory | ||
/// </summary> | ||
public object Source { get; } | ||
|
||
public SourceType SourceType { get; } = sourceType; | ||
public SourceType SourceType { get; } | ||
} |
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
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 |
---|---|---|
|
@@ -9,4 +9,7 @@ public enum SourceType | |
|
||
[EnumMember(Value = "ローカルファイル")] | ||
FilePath, | ||
|
||
[EnumMember(Value = "AI生成")] | ||
AiStory, | ||
} |
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,4 @@ | ||
namespace KoeBook.Core.Models; | ||
|
||
public record class StoryGenre(string Genre, string Description); | ||
|
Oops, something went wrong.