From bc9521d53eb89d7b870ddf386bfd95ed61238519 Mon Sep 17 00:00:00 2001 From: Simon Martens Date: Thu, 26 Oct 2023 13:04:49 +0200 Subject: [PATCH] Bugfix: doppelte Marginalien --- .../Settings/NodeRules/MarginalCollection.cs | 42 +++++++++++++++++++ .../Settings/NodeRules/StructureCollection.cs | 4 ++ HaWeb/Settings/ParsingRules/TextRules.cs | 5 ++- HaWeb/XMLTests/ICollectionRule.cs | 1 + HaWeb/XMLTests/XMLTester.cs | 5 ++- 5 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 HaWeb/Settings/NodeRules/MarginalCollection.cs diff --git a/HaWeb/Settings/NodeRules/MarginalCollection.cs b/HaWeb/Settings/NodeRules/MarginalCollection.cs new file mode 100644 index 0000000..8773baa --- /dev/null +++ b/HaWeb/Settings/NodeRules/MarginalCollection.cs @@ -0,0 +1,42 @@ +using HaWeb.Models; +using System.Xml.Linq; +using HaWeb.XMLTests; +namespace HaWeb.Settings.NodeRules; + +public class MarginalCollectionRules : ICollectionRule { + public string Name { get; } = "marginal"; + public HamannXPath[] Bases { get; } = { + new HamannXPath() { Documents = new[] { "stellenkommentar" }, XPath = "//marginal"} + }; + public HamannXPath[] Backlinks { get; } = {}; + + public IEnumerable<(string, XElement, XMLRootDocument)> GenerateIdentificationStrings(IEnumerable<(XElement, XMLRootDocument)> list) { + foreach (var e in list) { + var id = e.Item1.Attribute("letter")!.Value; + id += "-"; + id += e.Item1.Attribute("page")!.Value; + id += "-"; + id += e.Item1.Attribute("line")!.Value; + if (e.Item1.HasAttributes && e.Item1.Attribute("sort") != null) { + id += "-"; + id += e.Item1.Attribute("sort")!.Value; + } + yield return ( + id, + e.Item1, + e.Item2 + ); + } + } + + public IEnumerable<(string, XElement, XMLRootDocument, bool)> GenerateBacklinkString(IEnumerable<(XElement, XMLRootDocument)> list) => null; + + + public bool CheckDatatypes(XElement element) { + if (element.HasAttributes && element.Attribute("sort") != null ) { + return Int32.TryParse(element.Attribute("sort").Value, out var _); + } else { + return true; + } + } +} diff --git a/HaWeb/Settings/NodeRules/StructureCollection.cs b/HaWeb/Settings/NodeRules/StructureCollection.cs index f971f65..3ce3887 100644 --- a/HaWeb/Settings/NodeRules/StructureCollection.cs +++ b/HaWeb/Settings/NodeRules/StructureCollection.cs @@ -44,4 +44,8 @@ public class StructureCollection : ICollectionRule { partialmatch); } } + + public bool CheckDatatypes(XElement element) { + return true; + } } diff --git a/HaWeb/Settings/ParsingRules/TextRules.cs b/HaWeb/Settings/ParsingRules/TextRules.cs index 2f04546..86b96cb 100644 --- a/HaWeb/Settings/ParsingRules/TextRules.cs +++ b/HaWeb/Settings/ParsingRules/TextRules.cs @@ -234,8 +234,9 @@ public class TextRules { if(reader.State.ParsedMarginals == null) reader.State.ParsedMarginals = new List<(string, string, string)>(); var sb2 = new StringBuilder(); - // Sortiert an dieser String, nicht nach Zahl: sort 1-9 ist möglich, es gibt keine Abstürze bei fehlerhaften Werten - if (margs.Count() > 1) margs = margs.OrderBy(x => x.Sort ?? " "); + // Sortiert an dieser Stelle nach marginal.Sort, dessen Angabe eine Zahl sein muss. + // Der Syntaxchecker muss also überprüfen, ob doppelte Angaben gemacht sind oder Sort fehlt. + if (margs.Count() > 1) margs = margs.Where(x => Int32.TryParse(x.Sort, out var y)).OrderBy(x => Int32.Parse(x.Sort)); sb.Append(HaWeb.HTMLHelpers.TagHelpers.CreateElement(DEFAULTELEMENT, CSSClasses.COMMENTMARKERCLASS, "ma-" + reader.State.currpage + "-" + reader.State.currline)); sb.Append(HaWeb.HTMLHelpers.TagHelpers.CreateEndElement(DEFAULTELEMENT)); sb.Append(HaWeb.HTMLHelpers.TagHelpers.CreateElement(DEFAULTELEMENT, CSSClasses.MARGINGALBOXCLASS)); diff --git a/HaWeb/XMLTests/ICollectionRule.cs b/HaWeb/XMLTests/ICollectionRule.cs index 11c064a..d9c0b9a 100644 --- a/HaWeb/XMLTests/ICollectionRule.cs +++ b/HaWeb/XMLTests/ICollectionRule.cs @@ -8,4 +8,5 @@ public interface ICollectionRule { public HamannXPath[] Backlinks { get; } public IEnumerable<(string, XElement, XMLRootDocument)> GenerateIdentificationStrings(IEnumerable<(XElement, XMLRootDocument)> List); public IEnumerable<(string, XElement, XMLRootDocument, bool)> GenerateBacklinkString(IEnumerable<(XElement, XMLRootDocument)> List); + public bool CheckDatatypes(XElement element); } \ No newline at end of file diff --git a/HaWeb/XMLTests/XMLTester.cs b/HaWeb/XMLTests/XMLTester.cs index 6d87973..ca19010 100644 --- a/HaWeb/XMLTests/XMLTester.cs +++ b/HaWeb/XMLTests/XMLTester.cs @@ -135,9 +135,12 @@ public class XMLTester { foreach (var r in rule.GenerateIdentificationStrings(elemens)) { if (!hs.Add(r.Item1)) { var lc = getLineColumn(r.Item2); - _Results[r.Item3.File.FileName].Log(lc.Item1, lc.Item2, "Brief-Seite-Zeile " + r.Item1 + " mehrdeutig."); + _Results[r.Item3.File.FileName].Log(lc.Item1, lc.Item2, "Identifikator (Brief-Seite-Zeile(-Sort))" + r.Item1 + " mehrdeutig."); } } + foreach (var e in elemens) { + rule.CheckDatatypes(e.Item1); + } } } _CollectionIDs!.TryAdd(rule.Name, hs);