diff --git a/Transformation-2023-9-15/.vscode/settings.json b/Transformation-2023-9-15/.vscode/settings.json new file mode 100644 index 0000000..ef43394 --- /dev/null +++ b/Transformation-2023-9-15/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "dotnet.defaultSolution": "Transformation-2023-9-15.sln" +} \ No newline at end of file diff --git a/Transformation-2023-9-15/Program.cs b/Transformation-2023-9-15/Program.cs index 3251f3c..77dd99e 100644 --- a/Transformation-2023-9-15/Program.cs +++ b/Transformation-2023-9-15/Program.cs @@ -1,7 +1,8 @@ using System.IO; using System.Xml.Linq; // See https://aka.ms/new-console-template for more information -const string XML_PATH = "D:/Simon/source/hamann-xml/transformations_2023-9-14_test/"; +const string XML_PATH = "D:/Simon/source/hamann-xml/base/"; +const string DEST_PATH = "D:/Simon/source/hamann-xml/transformations_2023-9-14_test/"; const string GIT_PATH = "../../hamann-xml/"; const string BRANCH_NAME = "testdata"; @@ -20,21 +21,86 @@ if (xmls == null || !xmls.Any()) { throw new("No XML Data fonund!"); } +// Checks are done, we begin here +// State List<(string, XDocument)> Documents = new(); +Dictionary OldNewIndex = new(); +Dictionary> Intlinks = new(); +Dictionary> Marginals = new(); +Dictionary> LetterTexts = new(); +Dictionary> LetterTraditions = new(); +Dictionary> LetterDescs = new(); foreach (var f in xmls) { - Documents.Add((f, XDocument.Load(f, LoadOptions.PreserveWhitespace))); - Console.WriteLine("" + f); + var d = XDocument.Load(f, LoadOptions.PreserveWhitespace); + Documents.Add((f, d)); + + var intlinks = d.Descendants("intlink"); + if (intlinks != null && intlinks.Any()) { + foreach (var e in intlinks) { + if (e.HasAttributes && e.Attribute("letter") != null) { + if (!Intlinks.ContainsKey(e.Attribute("letter").Value)) Intlinks.Add(e.Attribute("letter").Value, new()); + Intlinks[e.Attribute("letter").Value].Add(e); + } + } + } + + var marginals = d.Descendants("marginal"); + if (marginals != null && marginals.Any()) { + foreach (var e in marginals) { + if (e.HasAttributes && e.Attribute("letter") != null) { + if (!Marginals.ContainsKey(e.Attribute("letter").Value)) Marginals.Add(e.Attribute("letter").Value, new()); + Marginals[e.Attribute("letter").Value].Add(e); + } + } + } + + var lettertexts = d.Descendants("letterText"); + if (lettertexts != null && lettertexts.Any()) { + foreach (var e in lettertexts) { + if (e.HasAttributes && e.Attribute("index") != null) { + if (!LetterTexts.ContainsKey(e.Attribute("index").Value)) LetterTexts.Add(e.Attribute("index").Value, new()); + LetterTexts[e.Attribute("index").Value].Add(e); + } + } + } + + var lettertraditions = d.Descendants("letterTradition"); + if (lettertraditions != null && lettertraditions.Any()) { + foreach (var e in lettertraditions) { + if (e.HasAttributes && e.Attribute("ref") != null) { + if (!LetterTraditions.ContainsKey(e.Attribute("ref").Value)) LetterTraditions.Add(e.Attribute("ref").Value, new()); + LetterTraditions[e.Attribute("ref").Value].Add(e); + } + } + } + + var letterdescs = d.Descendants("letterDesc"); + if (letterdescs != null && letterdescs.Any()) { + foreach (var e in letterdescs) { + if (e.HasAttributes && e.Attribute("ref") != null) { + if (!LetterDescs.ContainsKey(e.Attribute("ref").Value)) LetterDescs.Add(e.Attribute("ref").Value, new()); + LetterDescs[e.Attribute("ref").Value].Add(e); + + if (e.Element("autopsic") != null && e.Element("autopsic").HasAttributes && e.Element("autopsic").Attribute("value") != null) + OldNewIndex.Add(e.Attribute("ref").Value, e.Element("autopsic").Attribute("value").Value); + + } + } + } } -void SaveHamannFile(XElement element, string basefilepath, string oldfile) { - var filename = "hamann_" + ".xml"; - var path = Path.Combine(basefilepath, filename); - if (!Directory.Exists(basefilepath)) - Directory.CreateDirectory(basefilepath); - using (var targetStream = System.IO.File.Create(path)) - element.Save(targetStream, SaveOptions.DisableFormatting); - - } \ No newline at end of file +void SaveFile(XDocument element, string basefilepath, string oldfile) { + var filenameold = oldfile.Split('/', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries).LastOrDefault(); + if (filenameold == null) return; + var filename = oldfile + "_transform_" + ".xml"; + var path = Path.Combine(basefilepath, filename); + + if (!Directory.Exists(basefilepath)) + Directory.CreateDirectory(basefilepath); + using (var targetStream = System.IO.File.Create(path)) { + element.Save(targetStream, SaveOptions.DisableFormatting); + } +} \ No newline at end of file diff --git a/Transformation-2023-9-15/Transformation-2023-9-15.sln b/Transformation-2023-9-15/Transformation-2023-9-15.sln new file mode 100644 index 0000000..a7f5d0a --- /dev/null +++ b/Transformation-2023-9-15/Transformation-2023-9-15.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.002.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Transformation-2023-9-15", "Transformation-2023-9-15.csproj", "{7149D531-B686-413A-AFC8-12DCE97C7119}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7149D531-B686-413A-AFC8-12DCE97C7119}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7149D531-B686-413A-AFC8-12DCE97C7119}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7149D531-B686-413A-AFC8-12DCE97C7119}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7149D531-B686-413A-AFC8-12DCE97C7119}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {DCF91CEF-437A-4F52-BA90-CF5EE71C1B96} + EndGlobalSection +EndGlobal