Indexnumber parsing disabled

This commit is contained in:
Simon Martens
2023-09-16 15:43:11 +02:00
parent f054c8913d
commit d86d508786
58 changed files with 447 additions and 297 deletions

View File

@@ -1,17 +1,34 @@
using System.Xml.Linq;
namespace HaDocument.Models {
public class App {
public string Index { get; } = "";
public string Name { get; } = "";
public string Category { get; } = "";
public XElement? XElement { get; }
public App(
string index,
string name,
string category
string category,
XElement? xElement = null
) {
Index = index;
Name = name;
Category = category;
XElement = xElement;
}
public static App? FromXElement(XElement element) {
if (!element.HasAttributes || element.Name != "appDef") return null;
if (element.Attribute("index")?.Value == null || element.Attribute("name")?.Value == null || element.Attribute("category")?.Value == null) return null;
return new App(
element.Attribute("index")!.Value,
element.Attribute("name")!.Value,
element.Attribute("category")!.Value,
element
);
}
}
}

View File

@@ -1,24 +1,68 @@
using System.Xml.Linq;
namespace HaDocument.Models {
public class Backlink {
public string Index { get; } = "";
public string Href { get; } = "";
public string Letter { get; } = "";
public string Page { get; } = "";
public string Line { get; } = "";
public string MarginalIndex { get; } = "";
public string? Letter { get; } = "";
public string? Page { get; } = "";
public string? Line { get; } = "";
public string? Comment { get; }
public Backlink(
string index,
string letter,
string page,
string line,
string marginalindex
string href,
string? letter,
string? page,
string? line,
string? comment = null
) {
Index = index;
Href = href;
Letter = letter;
Page = page;
Line = line;
MarginalIndex = marginalindex;
Comment = comment;
}
public static Backlink? FromXElement(XElement element) {
if (!element.HasAttributes || element.Name != "link") return null;
if (element.Attribute("ref")?.Value == null && element.Attribute("subref")?.Value == null) return null;
if (element.Ancestors("marginal") == null || !element.Ancestors("marginal").Any()) {
var marginal = element.Ancestors("marginal").First();
if (Marginal.FromXElement(marginal) == null) return null;
return new Backlink(
element.Attribute("subref")?.Value ?? element.Attribute("ref")!.Value,
marginal.Attribute("letter")!.Value,
marginal.Attribute("page")!.Value,
marginal.Attribute("line")!.Value
);
}
if (element.Ancestors("subsection") != null || !element.Ancestors("subsection").Any()) {
var subsection = element.Ancestors("subsection").First();
if (subsection.Attribute("id")?.Value == null) return null;
return new Backlink(
element.Attribute("subref")?.Value ?? element.Attribute("ref")!.Value,
null,
null,
null,
subsection.Attribute("id")!.Value
);
}
if (element.Ancestors("kommentar") != null || !element.Ancestors("kommentar").Any()) {
var kommentar = element.Ancestors("kommentar").First();
if (kommentar.Attribute("id")?.Value == null) return null;
return new Backlink(
element.Attribute("subref")?.Value ?? element.Attribute("ref")!.Value,
null,
null,
null,
kommentar.Attribute("id")!.Value
);
}
return null;
}
}
}

View File

@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Collections.Immutable;
namespace HaDocument.Models{
public class Comment : HaDocument.Interfaces.ISearchable {
public class Comment {
public string Element { get; } = "";
public string Index { get; } = "";
public string Type { get; } = "";

View File

@@ -1,5 +1,7 @@
using System.Xml.Linq;
namespace HaDocument.Models {
public class Editreason : HaDocument.Interfaces.ISearchable {
public class Editreason {
public string Index { get; } = "";
public string Element { get; } = "";
public string Letter { get; } = "";
@@ -28,5 +30,9 @@ namespace HaDocument.Models {
EndLine = endline;
Reference = reference;
}
public static Editreason? FromXElement(XElement element) {
throw new NotImplementedException("We need two Elements for editreason");
}
}
}

View File

@@ -1,15 +0,0 @@
using System;
using HaXMLReader.EvArgs;
using System.Collections.Generic;
namespace HaDocument.Models {
public abstract class HaModel {
protected static List<(Func<Tag, bool>, Action<Tag>)> FieldActions = null;
internal static void AddAction(Func<Tag, bool> If, Action<Tag> Then) {
if (If == null || Then == null) throw new ArgumentNullException();
if (FieldActions == null) FieldActions = new List<(Func<Tag, bool>, Action<Tag>)>();
FieldActions.Add((If, Then));
}
}
}

View File

@@ -1,5 +1,5 @@
namespace HaDocument.Models {
public class Hand : HaModel {
public class Hand {
public string Letter { get; } = "";
public string Person { get; } = "";
public string StartPage { get; } = "";

View File

@@ -9,7 +9,7 @@ namespace HaDocument.Models
public Dictionary<string, Person> Persons;
public Dictionary<string, Meta> Metas;
public Dictionary<string, Meta> ExcludedMetas;
public Dictionary<string, Marginal> Marginals;
public Dictionary<string, List<Marginal>> Marginals;
public Dictionary<string, Location> Locations;
public Dictionary<string, Letter> Letters;
public Dictionary<string, Person> HandPersons;

View File

@@ -1,14 +1,29 @@
using System.Xml.Linq;
namespace HaDocument.Models {
public class Letter : HaModel, HaDocument.Interfaces.ISearchable {
public string Index { get; } = "";
public class Letter {
public string ID { get; } = "";
public string Element { get; } = "";
public XElement? XElement { get; }
public Letter(
string index,
string element
string id,
string element,
XElement? xelement = null
) {
Index = index;
ID = id;
Element = element;
XElement = xelement;
}
public static Letter? FromXElement(XElement element) {
if (!element.HasAttributes || element.IsEmpty || element.Name != "letterText") return null;
if (element.Attribute("letter")?.Value == null) return null;
return new Letter(
element.Attribute("letter")!.Value,
element.ToString(),
element
);
}
}
}

View File

@@ -15,7 +15,7 @@ namespace HaDocument.Models
public ImmutableDictionary<string, Person> Persons { get; }
public ImmutableDictionary<string, Meta> Metas { get; }
public ImmutableDictionary<string, Meta> ExcludedMetas { get; }
public ImmutableDictionary<string, Marginal> Marginals { get; }
public ImmutableDictionary<string, List<Marginal>> Marginals { get; }
public ImmutableDictionary<string, Location> Locations { get; }
public ImmutableDictionary<string, Letter> Letters { get; }
public ImmutableDictionary<string, Person> HandPersons { get; }
@@ -35,8 +35,6 @@ namespace HaDocument.Models
public Lookup<string, Comment> CommentsByCategory { get; }
// Auswählen von Subkommentaren nach ID
public ImmutableDictionary<string, Comment> SubCommentsByID { get; }
// Auswählen von Marginalien nach Briefen
public Lookup<string, Marginal> MarginalsByLetter { get; }
// Ausw?hlen von Edits nach Briefen
public Lookup<string, Editreason> EditreasonsByLetter { get; }
// Auswählen von Briefen nach autoptischer Numemr und in zeitlich sortierter Reihenfolge.
@@ -51,7 +49,7 @@ namespace HaDocument.Models
Dictionary<string, Person> persons,
Dictionary<string, Meta> meta,
Dictionary<string, Meta> excludedMeta,
Dictionary<string, Marginal> marginals,
Dictionary<string, List<Marginal>> marginals,
Dictionary<string, Location> locations,
Dictionary<string, Letter> letters,
Dictionary<string, Person> handPersons,
@@ -95,7 +93,6 @@ namespace HaDocument.Models
CommentsByLetter_builder.Add(ts.Key, (Lookup<string, Comment>)ts.ToLookup(x => x.Index.Substring(0, 1).ToUpper()));
}
CommentsByCategoryLetter = CommentsByLetter_builder.ToImmutableDictionary();
MarginalsByLetter = (Lookup<string, Marginal>)Marginals.Values.ToLookup(x => x.Letter);
EditreasonsByLetter = (Lookup<string, Editreason>)Editreasons.Values.ToLookup(x => x.Letter);
MetasByDate = Metas.Values.ToImmutableSortedSet<Meta>(new DefaultComparer());
MetasByYear = Metas.Values.ToLookup(x => x.Sort.Year);

View File

@@ -1,14 +1,33 @@
using System.Xml.Linq;
namespace HaDocument.Models {
public class Location {
public string Index { get; } = "";
public string Name { get; } = "";
public string? Reference { get; }
public XElement? XElement { get; }
public Location(
string index,
string name
string name,
string? reference,
XElement? xelement = null
) {
Index = index;
Name = name;
XElement = xelement;
Reference = reference;
}
public static Location? FromXElement(XElement element) {
if (!element.HasAttributes || element.Name != "locationDef") return null;
if (element.Attribute("index")?.Value == null || element.Attribute("name")?.Value == null) return null;
return new Location(
element.Attribute("index")!.Value,
element.Attribute("name")!.Value,
element.Attribute("ref")?.Value,
element
);
}
}
}

View File

@@ -1,23 +1,41 @@
using System.Xml.Linq;
namespace HaDocument.Models {
public class Marginal : HaDocument.Interfaces.ISearchable {
public string Index { get; } = "";
public class Marginal {
public string? Sort { get; } = "";
public string Letter { get; } = "";
public string Page { get; } = "";
public string Line { get; } = "";
public string Element { get; } = "";
public XElement? XElement { get; }
public Marginal(
string index,
string letter,
string page,
string line,
string element
string? sort,
string element,
XElement? xelement = null
) {
Index = index;
Letter = letter;
Page = page;
Line = line;
Sort = sort;
Element = element;
XElement = xelement;
}
public static Marginal? FromXElement(XElement element) {
if (!element.HasAttributes || element.Name != "marginal" || element.IsEmpty) return null;
if (element.Attribute("letter")?.Value == null || element.Attribute("page")?.Value == null || element.Attribute("line")?.Value == null) return null;
return new Marginal(
element.Attribute("letter")!.Value,
element.Attribute("page")!.Value,
element.Attribute("line")!.Value,
element.Attribute("sort")?.Value,
element.ToString(),
element
);
}
}
}

View File

@@ -4,35 +4,32 @@ using HaXMLReader.EvArgs;
namespace HaDocument.Models {
public class Meta {
public string Index { get; } = "";
public string Autopsic { get; } = "";
public string ID { get; } = "";
public string Date { get; } = "";
public DateTime Sort { get; } = new DateTime(1700, 1, 1);
public int Order { get; } = -1;
public string Location { get; } = "";
public List<string> Senders { get; } = null;
public List<string> Receivers { get; } = null;
public OptionalBool hasOriginal { get; } = OptionalBool.None;
public OptionalBool isProofread { get; } = OptionalBool.None;
public OptionalBool isDraft { get; } = OptionalBool.None;
public bool? hasOriginal { get; }
public bool? isProofread { get; }
public bool? isDraft { get; }
public ZHInfo ZH { get; } = null;
public Meta(
string index,
string autopsic,
string id,
string date,
DateTime sort,
int order,
OptionalBool hasOriginal,
OptionalBool isProofread,
OptionalBool isDraft,
bool? hasOriginal,
bool? isProofread,
bool? isDraft,
string location,
List<string> senders,
List<string> receivers,
ZHInfo ZH
) {
Index = index;
Autopsic = autopsic;
ID = id;
Date = date;
Sort = sort;
Order = order;

View File

@@ -1,13 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace HaDocument.Models
{
public enum OptionalBool
{
True,
False,
None
}
}

View File

@@ -1,23 +1,44 @@
using System.Xml.Linq;
namespace HaDocument.Models {
public class Person {
public string Index { get; } = "";
public string Name { get; } = "";
public string Prename { get; } = "";
public string Surname { get; } = "";
public string Index { get; } = string.Empty;
public string Name { get; } = string.Empty;
public string? Prename { get; }
public string? Surname { get; }
public string? Komm { get; }
public string? Reference { get; }
public XElement? XElement { get; }
public Person(
string index,
string name,
string prename,
string surname,
string? komm
string? prename,
string? surname,
string? komm,
string? reference,
XElement? xElement = null
) {
Index = index;
Name = name;
Prename = prename;
Surname = surname;
Komm = komm;
Reference = reference;
}
public static Person? FromXElement(XElement element) {
if (!element.HasAttributes || (element.Name != "personDef" && element.Name != "handDef")) return null;
if (element.Attribute("index")?.Value == null || element.Attribute("name")?.Value == null) return null;
return new Person(
element.Attribute("index")!.Value,
element.Attribute("name")!.Value,
element.Attribute("vorname")?.Value,
element.Attribute("nachname")?.Value,
element.Attribute("komm")?.Value,
element.Attribute("ref")?.Value,
element
);
}
}
}

View File

@@ -1,14 +1,30 @@
using System.Xml.Linq;
namespace HaDocument.Models {
public class Tradition : HaDocument.Interfaces.ISearchable {
public string Index { get; } = "";
public class Tradition {
public string ID { get; } = "";
public string Element { get; } = "";
public XElement? XElement { get; }
public Tradition(
string index,
string element
string id,
string element,
XElement? xelement = null
) {
Index = index;
ID = id;
Element = element;
XElement = xelement;
}
public static Tradition? FromXElement(XElement element) {
if (!element.HasAttributes || element.IsEmpty || element.Name != "letterTradition") return null;
if (element.Attribute("letter")?.Value == null) return null;
return new Tradition(
element.Attribute("letter")!.Value,
element.ToString(),
element
);
}
}
}