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.
Browse files
Browse the repository at this point in the history
xmlの小説の読み込み部分の作成
- Loading branch information
Showing
10 changed files
with
189 additions
and
28 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,34 @@ | ||
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) | ||
{ | ||
int sectionNumber = 1; | ||
return new EpubDocument(aiStory.Title, "AI", "", id) | ||
{ | ||
Chapters = [new Chapter() | ||
{ | ||
Sections = aiStory.Sections.Select(s => new Section($"第{sectionNumber++}章") | ||
{ | ||
Elements = s.Paragraphs.SelectMany(p => | ||
_splitBraceService.SplitBrace(p.GetText()) | ||
.Zip(_splitBraceService.SplitBrace(p.GetScript())) | ||
.Select(Element (p) => new Paragraph | ||
{ | ||
Text = p.First, | ||
ScriptLine = new(p.Second, "", "") | ||
}) | ||
).ToList(), | ||
}).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,52 @@ | ||
using System.Xml.Serialization; | ||
|
||
namespace KoeBook.Models; | ||
|
||
[XmlRoot("Book")] | ||
public record AiStory( | ||
[property: XmlElement("Title", typeof(string), IsNullable = false)] string Title, | ||
[property: XmlArray("Content", IsNullable = false), XmlArrayItem("Section", IsNullable = false)] AiStory.Section[] Sections) | ||
{ | ||
private AiStory() : this("", []) { } | ||
|
||
public record Section( | ||
[property: XmlArrayItem("Paragraph", IsNullable = false)] Paragraph[] Paragraphs) | ||
{ | ||
private Section() : this([]) { } | ||
} | ||
|
||
|
||
public record Paragraph( | ||
[property: XmlElement("Text", typeof(TextElement), IsNullable = false), XmlElement("Ruby", typeof(Ruby), IsNullable = false)] InlineElement[] Inlines) | ||
{ | ||
private Paragraph() : this([]) { } | ||
|
||
public string GetText() => string.Concat(Inlines.Select(e => e.Text)); | ||
|
||
public string GetScript() => string.Concat(Inlines.Select(e => e.Script)); | ||
} | ||
|
||
public abstract record class InlineElement | ||
{ | ||
public abstract string Text { get; } | ||
public abstract string Script { get; } | ||
} | ||
|
||
public record TextElement([property: XmlText] string InnerText) : InlineElement | ||
{ | ||
private TextElement() : this("") { } | ||
|
||
public override string Text => 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 Text => Rb; | ||
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
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
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