mirror of
https://github.com/Theodor-Springmann-Stiftung/hamann-ausgabe-core.git
synced 2025-10-29 09:15:33 +00:00
Tranbsformations
This commit is contained in:
File diff suppressed because one or more lines are too long
7
Transformation-2023-9-15/.vscode/launch.json
vendored
7
Transformation-2023-9-15/.vscode/launch.json
vendored
@@ -1,7 +0,0 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": []
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"dotnet.defaultSolution": "Transformation-2023-9-15.sln"
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
using System.IO;
|
||||
using System.Security;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
// See https://aka.ms/new-console-template for more information
|
||||
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 XML_PATH = "C:/Users/simon/source/hamann-xml/base/";
|
||||
const string DEST_PATH = "C:/Users/simon/source/hamann-xml/transformations_2023-9-14_test/";
|
||||
const string GIT_PATH = "C:/Users/simon/source/hamann-xml/";
|
||||
const string BRANCH_NAME = "testdata";
|
||||
|
||||
if (File.Exists(GIT_PATH + ".git/HEAD") || !Directory.Exists(XML_PATH)) {
|
||||
@@ -23,7 +25,7 @@ if (xmls == null || !xmls.Any()) {
|
||||
|
||||
// Checks are done, we begin here
|
||||
// State
|
||||
List<(string, XDocument)> Documents = new();
|
||||
List<(string, XDocument, bool)> Documents = new();
|
||||
Dictionary<string, string> OldNewIndex = new();
|
||||
Dictionary<string, List<XElement>> Intlinks = new();
|
||||
Dictionary<string, List<XElement>> Marginals = new();
|
||||
@@ -31,16 +33,29 @@ Dictionary<string, List<XElement>> LetterTexts = new();
|
||||
Dictionary<string, List<XElement>> LetterTraditions = new();
|
||||
Dictionary<string, List<XElement>> LetterDescs = new();
|
||||
|
||||
List<XElement> Autopsic = new();
|
||||
|
||||
foreach (var f in xmls) {
|
||||
var d = XDocument.Load(f, LoadOptions.PreserveWhitespace);
|
||||
Documents.Add((f, d));
|
||||
XmlReaderSettings set = new XmlReaderSettings();
|
||||
set.IgnoreWhitespace = false;
|
||||
set.CheckCharacters = false;
|
||||
using (FileStream fs = File.Open(f, FileMode.Open)) {
|
||||
using (var r = new XmlTextReader(fs) { Normalization = false, WhitespaceHandling = WhitespaceHandling.All, EntityHandling = EntityHandling.ExpandCharEntities}) {
|
||||
|
||||
var d = XDocument.Load(r);
|
||||
var affected = false;
|
||||
|
||||
var intlinks = d.Descendants("intlink");
|
||||
if (intlinks != null && intlinks.Any()) {
|
||||
foreach (var e in intlinks) {
|
||||
if (e.HasAttributes && e.Attribute("letter") != null) {
|
||||
int letter = -1;
|
||||
if (Int32.TryParse(e.Attribute("letter").Value, out letter) && letter > 368) {
|
||||
if (!Intlinks.ContainsKey(e.Attribute("letter").Value)) Intlinks.Add(e.Attribute("letter").Value, new());
|
||||
Intlinks[e.Attribute("letter").Value].Add(e);
|
||||
Console.WriteLine(e.ToString());
|
||||
affected = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -51,6 +66,7 @@ foreach (var f in xmls) {
|
||||
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);
|
||||
affected = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -61,6 +77,7 @@ foreach (var f in xmls) {
|
||||
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);
|
||||
affected = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -71,6 +88,7 @@ foreach (var f in xmls) {
|
||||
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);
|
||||
affected = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,25 +100,66 @@ foreach (var f in xmls) {
|
||||
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)
|
||||
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);
|
||||
Autopsic.Add(e.Element("autopsic"));
|
||||
affected = true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Documents.Add((f, d, affected));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<Dictionary<string, List<XElement>>> Collections = new() { Intlinks, Marginals, LetterTexts, LetterTraditions, LetterDescs };
|
||||
foreach (var number in OldNewIndex) {
|
||||
if (number.Key == number.Value) continue;
|
||||
foreach (var c in Collections) {
|
||||
if (c != null && c.ContainsKey(number.Key)) {
|
||||
foreach (var v in c[number.Key]) {
|
||||
if (v.HasAttributes && v.Attribute("letter") != null) {
|
||||
v.Attribute("letter").Value = number.Value;
|
||||
} else if (v.HasAttributes && v.Attribute("ref") != null) {
|
||||
v.Attribute("ref").Value = number.Value;
|
||||
} else if (v.HasAttributes && v.Attribute("index") != null) {
|
||||
v.Attribute("index").Value = number.Value;
|
||||
}
|
||||
// NOT POSSIBLE:
|
||||
// if (v.HasAttributes && v.Attribute("autopsic") != null) {
|
||||
// v.Attribute("autopsic").Remove();
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
foreach (var d in Documents) {
|
||||
//if (d.Item3) SaveFile(d.Item2, DEST_PATH, d.Item1);
|
||||
}
|
||||
|
||||
void SaveFile(XDocument element, string basefilepath, string oldfile) {
|
||||
if (!Directory.Exists(basefilepath)) {
|
||||
Directory.CreateDirectory(basefilepath);
|
||||
}
|
||||
var filenameold = oldfile.Split('/', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries).LastOrDefault();
|
||||
if (filenameold == null) return;
|
||||
var filename = oldfile + "_transform_" + ".xml";
|
||||
var filename = oldfile;
|
||||
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);
|
||||
}
|
||||
File.WriteAllText(path, element.ToString());
|
||||
// XmlWriterSettings set = new XmlWriterSettings() {
|
||||
// CheckCharacters = false
|
||||
// };
|
||||
// using (XmlTextWriter wr = new XmlTextWriter(path, System.Text.Encoding.UTF8) { Formatting = System.Xml.Formatting.None }) {
|
||||
// element.Save(wr);
|
||||
// }
|
||||
// using (var targetStream = System.IO.File.Create(path)) {
|
||||
// element.Save(targetStream, SaveOptions.DisableFormatting);
|
||||
//}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<RootNamespace>Transformation_2023_9_15</RootNamespace>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
@@ -3,7 +3,7 @@ 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}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Transformation-2023-9-15", "Transformation-2023-9-15.csproj", "{18C971BB-9528-4991-BD98-50C4ABD3BCAE}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@@ -11,15 +11,15 @@ Global
|
||||
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
|
||||
{18C971BB-9528-4991-BD98-50C4ABD3BCAE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{18C971BB-9528-4991-BD98-50C4ABD3BCAE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{18C971BB-9528-4991-BD98-50C4ABD3BCAE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{18C971BB-9528-4991-BD98-50C4ABD3BCAE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {DCF91CEF-437A-4F52-BA90-CF5EE71C1B96}
|
||||
SolutionGuid = {FF6C9F4E-8781-4E3E-8A17-D7279CB58974}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
Reference in New Issue
Block a user