mirror of
https://github.com/Theodor-Springmann-Stiftung/hamann-ausgabe-core.git
synced 2025-10-29 09:15:33 +00:00
Added collection classes. Will not do extra collection for subcomments rn.
This commit is contained in:
@@ -70,7 +70,7 @@ public class Briefecontroller : Controller {
|
||||
else model.ParsedMarginals = parsedLetter.ParsedMarginals;
|
||||
if (parsedLetter.Startline != "-1" && parsedLetter.Startline != "1" && model.MetaData.ParsedZHString != null)
|
||||
model.MetaData.ParsedZHString += " / " + parsedLetter.Startline;
|
||||
if (model.ParsedText == null || String.IsNullOrWhiteSpace(model.ParsedText))
|
||||
if (String.IsNullOrWhiteSpace(model.ParsedText))
|
||||
model.MetaData.HasText = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
using System.Reflection.Emit;
|
||||
using System.Collections;
|
||||
namespace HaWeb.Models;
|
||||
using HaWeb.SearchHelpers;
|
||||
using HaWeb.XMLParser;
|
||||
@@ -5,25 +7,30 @@ using System.Xml.Linq;
|
||||
|
||||
public class CollectedItem : ISearchable {
|
||||
public string Index { get; private set; }
|
||||
public string Collection { get; private set; }
|
||||
public string? SearchText { get; private set; }
|
||||
public Dictionary<string, string[]>? Fields { get; private set; }
|
||||
public IDictionary<string, string>? Fields { get; private set; }
|
||||
public XElement ELement { get; private set; }
|
||||
public IXMLRoot Root { get; private set; }
|
||||
public IXMLCollection Collection { get; private set; }
|
||||
|
||||
public CollectedItem(
|
||||
string index,
|
||||
XElement element,
|
||||
IXMLRoot root,
|
||||
string collection,
|
||||
Dictionary<string, string[]>? fields,
|
||||
IXMLCollection collection,
|
||||
IDictionary<string, string>? fields,
|
||||
string? searchtext = null
|
||||
) {
|
||||
this.Index = index;
|
||||
this.SearchText = searchtext;
|
||||
this.Collection = collection;
|
||||
this.Root = root;
|
||||
this.ELement = element;
|
||||
this.Fields = fields;
|
||||
}
|
||||
|
||||
public string? this[string v] {
|
||||
get {
|
||||
if (Fields != null && Fields.ContainsKey(v))
|
||||
return Fields[v];
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,45 +3,40 @@ using HaWeb.XMLParser;
|
||||
|
||||
public class ItemsCollection {
|
||||
public string Name { get; private set; }
|
||||
public Dictionary<string, CollectedItem> Items { get; private set; }
|
||||
public bool Searchable { get; private set; }
|
||||
public IXMLRoot Root { get; private set; }
|
||||
public Func<List<CollectedItem>, Dictionary<string, Lookup<string, CollectedItem>>?>? GroupingsGeneration { get; private set; }
|
||||
public Func<List<CollectedItem>, Dictionary<string, List<CollectedItem>>?>? SortingsGeneration { get; private set; }
|
||||
public IDictionary<string, CollectedItem> Items { get; private set; }
|
||||
public IXMLCollection Collection { get; private set; }
|
||||
|
||||
public Dictionary<string, Lookup<string, CollectedItem>>? Groupings { get; private set; }
|
||||
public Dictionary<string, List<CollectedItem>>? Sortings { get; private set; }
|
||||
public IDictionary<string, ILookup<string, CollectedItem>>? Groupings { get; private set; }
|
||||
public IDictionary<string, IEnumerable<CollectedItem>>? Sortings { get; private set; }
|
||||
|
||||
public ItemsCollection(
|
||||
string name,
|
||||
bool searchable,
|
||||
IXMLRoot root,
|
||||
Func<List<CollectedItem>, Dictionary<string, Lookup<string, CollectedItem>>?>? groupingsFunc = null,
|
||||
Func<List<CollectedItem>, Dictionary<string, List<CollectedItem>>?>? sortingsFunc = null
|
||||
IXMLCollection collection
|
||||
) {
|
||||
this.Name = name;
|
||||
this.Searchable = searchable;
|
||||
this.Root = root;
|
||||
this.GroupingsGeneration = groupingsFunc;
|
||||
this.SortingsGeneration = sortingsFunc;
|
||||
this.Collection = collection;
|
||||
this.Items = new Dictionary<string, CollectedItem>();
|
||||
}
|
||||
|
||||
public void GenerateGroupings(
|
||||
Func<List<CollectedItem>, Dictionary<string, Lookup<string, CollectedItem>>?>? groupingsFunc = null
|
||||
Func<IEnumerable<CollectedItem>, Dictionary<string, ILookup<string, CollectedItem>>?>? groupingsFunc = null
|
||||
) {
|
||||
if (groupingsFunc != null)
|
||||
this.GroupingsGeneration = groupingsFunc;
|
||||
if (this.GroupingsGeneration != null && this.Items.Any())
|
||||
this.Groupings = GroupingsGeneration(this.Items.Values.ToList());
|
||||
if (groupingsFunc != null) {
|
||||
this.Groupings = groupingsFunc(this.Items.Values.ToList());
|
||||
return;
|
||||
}
|
||||
if (Collection.GroupingsGeneration != null && this.Items.Any())
|
||||
this.Groupings = Collection.GroupingsGeneration(this.Items.Values.ToList());
|
||||
}
|
||||
|
||||
public void GenerateSortings(
|
||||
Func<List<CollectedItem>, Dictionary<string, List<CollectedItem>>?>? sortingsFunc = null
|
||||
Func<IEnumerable<CollectedItem>, Dictionary<string, IEnumerable<CollectedItem>>?>? sortingsFunc = null
|
||||
) {
|
||||
if (sortingsFunc != null)
|
||||
this.SortingsGeneration = sortingsFunc;
|
||||
if (this.SortingsGeneration != null && this.Items.Any())
|
||||
this.Sortings = SortingsGeneration(this.Items.Values.ToList());
|
||||
if (sortingsFunc != null) {
|
||||
this.Sortings = sortingsFunc(this.Items.Values.ToList());
|
||||
return;
|
||||
}
|
||||
if (Collection.SortingsGeneration != null && this.Items.Any())
|
||||
this.Sortings = Collection.SortingsGeneration(this.Items.Values.ToList());
|
||||
}
|
||||
}
|
||||
|
||||
48
HaWeb/Settings/XMLCollections/BacklinkCollection.cs
Normal file
48
HaWeb/Settings/XMLCollections/BacklinkCollection.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
namespace HaWeb.Settings.XMLCollections;
|
||||
using HaWeb.Models;
|
||||
using System.Xml.Linq;
|
||||
|
||||
public class BackLinkCollection : HaWeb.XMLParser.IXMLCollection {
|
||||
private static readonly Random _random = new Random();
|
||||
public string Key { get; } = "backlinks";
|
||||
public string[] xPath { get; } = new string[] { "/opus/data/marginalien/marginal/link", "/opus/marginalien/marginal/link" };
|
||||
public Func<XElement, string?> GenerateKey { get; } = GetKey;
|
||||
public Func<XElement, IDictionary<string, string>?>? GenerateDataFields { get; } = GetDataFields;
|
||||
public Func<IEnumerable<CollectedItem>, IDictionary<string, ILookup<string, CollectedItem>>?>? GroupingsGeneration { get; } = null;
|
||||
public Func<IEnumerable<CollectedItem>, IDictionary<string, IEnumerable<CollectedItem>>?>? SortingsGeneration { get; } = null;
|
||||
public HaWeb.XMLParser.IXMLCollection[]? SubCollections { get; } = null;
|
||||
public bool Searchable { get; } = true;
|
||||
|
||||
public static Func<XElement, string?> GetKey { get; } = (elem) => {
|
||||
var margid = (string?)elem.Ancestors("marginal").First().Attribute("index");
|
||||
if (String.IsNullOrWhiteSpace(margid)) return null;
|
||||
return margid + _random.Next().ToString();
|
||||
};
|
||||
|
||||
public static IDictionary<string, string>? GetDataFields(XElement element) {
|
||||
var res = new Dictionary<string, string>();
|
||||
var marg = element.Ancestors("marginal").First();
|
||||
var index = (string?)marg.Attribute("index");
|
||||
var letter = (string?)marg.Attribute("letter");
|
||||
var page = (string?)marg.Attribute("page");
|
||||
var line = (string?)marg.Attribute("line");
|
||||
var refere = (string?)element.Attribute("ref");
|
||||
var subref = (string?)element.Attribute("subref");
|
||||
if (index == null || letter == null || (refere == null && subref == null)) return null;
|
||||
if (subref != null) res.Add("ref", subref);
|
||||
else res.Add("ref", refere!);
|
||||
res.Add("index", index);
|
||||
res.Add("letter", letter);
|
||||
if(page != null) res.Add("page", page);
|
||||
if(line != null) res.Add("line", line);
|
||||
return res;
|
||||
}
|
||||
|
||||
public static IDictionary<string, ILookup<string, CollectedItem>>? GetLookups(IEnumerable<CollectedItem> items) {
|
||||
var res = new Dictionary<string, ILookup<string, CollectedItem>>();
|
||||
var refs = items.Where(x => x["ref"] != null);
|
||||
if (refs == null || !refs.Any()) return null;
|
||||
res.Add("ref", refs.ToLookup(x => x["ref"])!);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
160
HaWeb/Settings/XMLCollections/CommentCollections.cs
Normal file
160
HaWeb/Settings/XMLCollections/CommentCollections.cs
Normal file
@@ -0,0 +1,160 @@
|
||||
using System.Xml;
|
||||
namespace HaWeb.Settings.XMLCollections;
|
||||
using HaWeb.Models;
|
||||
using System.Xml.Linq;
|
||||
|
||||
public class BibleCommentCollection : HaWeb.XMLParser.IXMLCollection {
|
||||
public string Key { get; } = "bible-comments";
|
||||
public string[] xPath { get; } = new string[] { "/opus/data/kommentare/kommcat[@value='bibel']/kommentar", "/opus/kommentare/kommcat[@value='bibel']/kommentar" };
|
||||
public Func<XElement, string?> GenerateKey { get; } = GetKey;
|
||||
public Func<XElement, IDictionary<string, string>?>? GenerateDataFields { get; } = GetDataFields;
|
||||
public Func<IEnumerable<CollectedItem>, IDictionary<string, ILookup<string, CollectedItem>>?>? GroupingsGeneration { get; } = GetLookups;
|
||||
public Func<IEnumerable<CollectedItem>, IDictionary<string, IEnumerable<CollectedItem>>?>? SortingsGeneration { get; } = null;
|
||||
public HaWeb.XMLParser.IXMLCollection[]? SubCollections { get; } = null;
|
||||
public bool Searchable { get; } = false;
|
||||
|
||||
public static Func<XElement, string?> GetKey { get; } = (elem) => {
|
||||
var index = elem.Attribute("id");
|
||||
if (index != null && !String.IsNullOrWhiteSpace(index.Value))
|
||||
return index.Value;
|
||||
else return null;
|
||||
};
|
||||
|
||||
public static IDictionary<string, string>? GetDataFields(XElement element) {
|
||||
var res = new Dictionary<string, string>();
|
||||
var lemma = element.Descendants("lemma");
|
||||
if (!lemma.Any() || String.IsNullOrWhiteSpace(lemma.First().Value)) return null;
|
||||
res.Add("lemma", lemma.First().Value);
|
||||
return res;
|
||||
}
|
||||
|
||||
public static IDictionary<string, ILookup<string, CollectedItem>>? GetLookups(IEnumerable<CollectedItem> items) {
|
||||
var res = new Dictionary<string, ILookup<string, CollectedItem>>();
|
||||
var lemmas = items.Where(x => !String.IsNullOrWhiteSpace(x.Index));
|
||||
if (lemmas != null && lemmas.Any())
|
||||
res.Add("lemma", lemmas.ToLookup(x => x.Index.Substring(0, 1).ToUpper()));
|
||||
// If we use lemmas
|
||||
// var lemmas = items.Where(x => x.Fields != null && x.Fields.ContainsKey("lemma"));
|
||||
// if (lemmas != null && lemmas.Any())
|
||||
// res.Add("lemma", lemmas.ToLookup(x => x.Fields["lemma"][0].First().ToString()));
|
||||
if (!res.Any()) return null;
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
public class EditionCommentCollection : HaWeb.XMLParser.IXMLCollection {
|
||||
public string Key { get; } = "edition-comments";
|
||||
public string[] xPath { get; } = new string[] { "/opus/data/kommentare/kommcat[@value='editionen']/kommentar", "/opus/kommentare/kommcat[@value='editionen']/kommentar" };
|
||||
public Func<XElement, string?> GenerateKey { get; } = GetKey;
|
||||
public Func<XElement, IDictionary<string, string>?>? GenerateDataFields { get; } = GetDataFields;
|
||||
public Func<IEnumerable<CollectedItem>, IDictionary<string, ILookup<string, CollectedItem>>?>? GroupingsGeneration { get; } = GetLookups;
|
||||
public Func<IEnumerable<CollectedItem>, IDictionary<string, IEnumerable<CollectedItem>>?>? SortingsGeneration { get; } = null;
|
||||
public HaWeb.XMLParser.IXMLCollection[]? SubCollections { get; } = null;
|
||||
public bool Searchable { get; } = true;
|
||||
|
||||
public static Func<XElement, string?> GetKey { get; } = (elem) => {
|
||||
var index = elem.Attribute("id");
|
||||
if (index != null && !String.IsNullOrWhiteSpace(index.Value))
|
||||
return index.Value;
|
||||
else return null;
|
||||
};
|
||||
|
||||
public static IDictionary<string, string>? GetDataFields(XElement element) {
|
||||
var res = new Dictionary<string, string>();
|
||||
var lemma = element.Descendants("lemma");
|
||||
if (!lemma.Any() || String.IsNullOrWhiteSpace(lemma.First().Value)) return null;
|
||||
res.Add("lemma", lemma.First().Value);
|
||||
return res;
|
||||
}
|
||||
|
||||
public static IDictionary<string, ILookup<string, CollectedItem>>? GetLookups(IEnumerable<CollectedItem> items) {
|
||||
var res = new Dictionary<string, ILookup<string, CollectedItem>>();
|
||||
var lemmas = items.Where(x => !String.IsNullOrWhiteSpace(x.Index));
|
||||
if (lemmas != null && lemmas.Any())
|
||||
res.Add("lemma", lemmas.ToLookup(x => x.Index.Substring(0, 1).ToUpper()));
|
||||
// If we use lemmas
|
||||
// var lemmas = items.Where(x => x.Fields != null && x.Fields.ContainsKey("lemma"));
|
||||
// if (lemmas != null && lemmas.Any())
|
||||
// res.Add("lemma", lemmas.ToLookup(x => x.Fields["lemma"][0].First().ToString()));
|
||||
if (!res.Any()) return null;
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
public class RegisterCommentCollection : HaWeb.XMLParser.IXMLCollection {
|
||||
public string Key { get; } = "register-comments";
|
||||
public string[] xPath { get; } = new string[] { "/opus/data/kommentare/kommcat[@value='neuzeit']/kommentar", "/opus/kommentare/kommcat[@value='neuzeit']/kommentar" };
|
||||
public Func<XElement, string?> GenerateKey { get; } = GetKey;
|
||||
public Func<XElement, IDictionary<string, string>?>? GenerateDataFields { get; } = GetDataFields;
|
||||
public Func<IEnumerable<CollectedItem>, IDictionary<string, ILookup<string, CollectedItem>>?>? GroupingsGeneration { get; } = GetLookups;
|
||||
public Func<IEnumerable<CollectedItem>, IDictionary<string, IEnumerable<CollectedItem>>?>? SortingsGeneration { get; } = null;
|
||||
public HaWeb.XMLParser.IXMLCollection[]? SubCollections { get; } = null;
|
||||
public bool Searchable { get; } = true;
|
||||
|
||||
public static Func<XElement, string?> GetKey { get; } = (elem) => {
|
||||
var index = elem.Attribute("id");
|
||||
if (index != null && !String.IsNullOrWhiteSpace(index.Value))
|
||||
return index.Value;
|
||||
else return null;
|
||||
};
|
||||
|
||||
public static IDictionary<string, string>? GetDataFields(XElement element) {
|
||||
var res = new Dictionary<string, string>();
|
||||
var lemma = element.Descendants("lemma");
|
||||
if (!lemma.Any() || String.IsNullOrWhiteSpace(lemma.First().Value)) return null;
|
||||
res.Add("lemma", lemma.First().Value);
|
||||
return res;
|
||||
}
|
||||
|
||||
public static IDictionary<string, ILookup<string, CollectedItem>>? GetLookups(IEnumerable<CollectedItem> items) {
|
||||
var res = new Dictionary<string, ILookup<string, CollectedItem>>();
|
||||
var lemmas = items.Where(x => !String.IsNullOrWhiteSpace(x.Index));
|
||||
if (lemmas != null && lemmas.Any())
|
||||
res.Add("lemma", lemmas.ToLookup(x => x.Index.Substring(0, 1).ToUpper()));
|
||||
// If we use lemmas
|
||||
// var lemmas = items.Where(x => x.Fields != null && x.Fields.ContainsKey("lemma"));
|
||||
// if (lemmas != null && lemmas.Any())
|
||||
// res.Add("lemma", lemmas.ToLookup(x => x.Fields["lemma"][0].First().ToString()));
|
||||
if (!res.Any()) return null;
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
public class ForschungCommentCollection : HaWeb.XMLParser.IXMLCollection {
|
||||
public string Key { get; } = "forschung-comments";
|
||||
public string[] xPath { get; } = new string[] { "/opus/data/kommentare/kommcat[@value='forschung']/kommentar", "/opus/kommentare/kommcat[@value='forschung']/kommentar" };
|
||||
public Func<XElement, string?> GenerateKey { get; } = GetKey;
|
||||
public Func<XElement, IDictionary<string, string>?>? GenerateDataFields { get; } = GetDataFields;
|
||||
public Func<IEnumerable<CollectedItem>, IDictionary<string, ILookup<string, CollectedItem>>?>? GroupingsGeneration { get; } = GetLookups;
|
||||
public Func<IEnumerable<CollectedItem>, IDictionary<string, IEnumerable<CollectedItem>>?>? SortingsGeneration { get; } = null;
|
||||
public HaWeb.XMLParser.IXMLCollection[]? SubCollections { get; } = null;
|
||||
public bool Searchable { get; } = true;
|
||||
|
||||
public static Func<XElement, string?> GetKey { get; } = (elem) => {
|
||||
var index = elem.Attribute("id");
|
||||
if (index != null && !String.IsNullOrWhiteSpace(index.Value))
|
||||
return index.Value;
|
||||
else return null;
|
||||
};
|
||||
|
||||
public static IDictionary<string, string>? GetDataFields(XElement element) {
|
||||
var res = new Dictionary<string, string>();
|
||||
var lemma = element.Descendants("lemma");
|
||||
if (!lemma.Any() || String.IsNullOrWhiteSpace(lemma.First().Value)) return null;
|
||||
res.Add("lemma", lemma.First().Value);
|
||||
return res;
|
||||
}
|
||||
|
||||
public static IDictionary<string, ILookup<string, CollectedItem>>? GetLookups(IEnumerable<CollectedItem> items) {
|
||||
var res = new Dictionary<string, ILookup<string, CollectedItem>>();
|
||||
var lemmas = items.Where(x => !String.IsNullOrWhiteSpace(x.Index));
|
||||
if (lemmas != null && lemmas.Any())
|
||||
res.Add("lemma", lemmas.ToLookup(x => x.Index.Substring(0, 1).ToUpper()));
|
||||
// If we use lemmas
|
||||
// var lemmas = items.Where(x => x.Fields != null && x.Fields.ContainsKey("lemma"));
|
||||
// if (lemmas != null && lemmas.Any())
|
||||
// res.Add("lemma", lemmas.ToLookup(x => x.Fields["lemma"][0].First().ToString()));
|
||||
if (!res.Any()) return null;
|
||||
return res;
|
||||
}
|
||||
}
|
||||
21
HaWeb/Settings/XMLCollections/EditCollection.cs
Normal file
21
HaWeb/Settings/XMLCollections/EditCollection.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
namespace HaWeb.Settings.XMLCollections;
|
||||
using HaWeb.Models;
|
||||
using System.Xml.Linq;
|
||||
|
||||
public class EditCollection : HaWeb.XMLParser.IXMLCollection {
|
||||
public string Key { get; } = "edits";
|
||||
public string[] xPath { get; } = new string[] { "/opus/edits/editreason", "/opus/data/edits/editreason" };
|
||||
public Func<XElement, string?> GenerateKey { get; } = GetKey;
|
||||
public Func<XElement, IDictionary<string, string>?>? GenerateDataFields { get; } = null;
|
||||
public Func<IEnumerable<CollectedItem>, IDictionary<string, ILookup<string, CollectedItem>>?>? GroupingsGeneration { get; } = null;
|
||||
public Func<IEnumerable<CollectedItem>, IDictionary<string, IEnumerable<CollectedItem>>?>? SortingsGeneration { get; } = null;
|
||||
public HaWeb.XMLParser.IXMLCollection[]? SubCollections { get; } = null;
|
||||
public bool Searchable { get; } = true;
|
||||
|
||||
public static Func<XElement, string?> GetKey { get; } = (elem) => {
|
||||
var index = elem.Attribute("index");
|
||||
if (index != null && !String.IsNullOrWhiteSpace(index.Value))
|
||||
return index.Value;
|
||||
else return null;
|
||||
};
|
||||
}
|
||||
21
HaWeb/Settings/XMLCollections/LetterCollection.cs
Normal file
21
HaWeb/Settings/XMLCollections/LetterCollection.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
namespace HaWeb.Settings.XMLCollections;
|
||||
using HaWeb.Models;
|
||||
using System.Xml.Linq;
|
||||
|
||||
public class LetterCollection : HaWeb.XMLParser.IXMLCollection {
|
||||
public string Key { get; } = "letters";
|
||||
public string[] xPath { get; } = new string[] { "/opus/data/document/letterText", "/opus/document/letterText" };
|
||||
public Func<XElement, string?> GenerateKey { get; } = GetKey;
|
||||
public Func<XElement, IDictionary<string, string>?>? GenerateDataFields { get; } = null;
|
||||
public Func<IEnumerable<CollectedItem>, IDictionary<string, ILookup<string, CollectedItem>>?>? GroupingsGeneration { get; } = null;
|
||||
public Func<IEnumerable<CollectedItem>, IDictionary<string, IEnumerable<CollectedItem>>?>? SortingsGeneration { get; } = null;
|
||||
public HaWeb.XMLParser.IXMLCollection[]? SubCollections { get; } = null;
|
||||
public bool Searchable { get; } = true;
|
||||
|
||||
public static Func<XElement, string?> GetKey { get; } = (elem) => {
|
||||
var index = elem.Attribute("index");
|
||||
if (index != null && !String.IsNullOrWhiteSpace(index.Value))
|
||||
return index.Value;
|
||||
else return null;
|
||||
};
|
||||
}
|
||||
41
HaWeb/Settings/XMLCollections/MarginalCollection.cs
Normal file
41
HaWeb/Settings/XMLCollections/MarginalCollection.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
namespace HaWeb.Settings.XMLCollections;
|
||||
using HaWeb.Models;
|
||||
using System.Xml.Linq;
|
||||
|
||||
public class MarginalCollection : HaWeb.XMLParser.IXMLCollection {
|
||||
public string Key { get; } = "marginals";
|
||||
public string[] xPath { get; } = new string[] { "/opus/data/marginalien/marginal", "/opus/marginalien/marginal" };
|
||||
public Func<XElement, string?> GenerateKey { get; } = GetKey;
|
||||
public Func<XElement, IDictionary<string, string>?>? GenerateDataFields { get; } = GetDataFields;
|
||||
public Func<IEnumerable<CollectedItem>, IDictionary<string, ILookup<string, CollectedItem>>?>? GroupingsGeneration { get; } = null;
|
||||
public Func<IEnumerable<CollectedItem>, IDictionary<string, IEnumerable<CollectedItem>>?>? SortingsGeneration { get; } = null;
|
||||
public HaWeb.XMLParser.IXMLCollection[]? SubCollections { get; } = null;
|
||||
public bool Searchable { get; } = true;
|
||||
|
||||
public static Func<XElement, string?> GetKey { get; } = (elem) => {
|
||||
var index = elem.Attribute("index");
|
||||
if (index != null && !String.IsNullOrWhiteSpace(index.Value))
|
||||
return index.Value;
|
||||
else return null;
|
||||
};
|
||||
|
||||
public static IDictionary<string, string>? GetDataFields(XElement element) {
|
||||
var res = new Dictionary<string, string>();
|
||||
var letter = (string?)element.Attribute("letter");
|
||||
var page = (string?)element.Attribute("page");
|
||||
var line = (string?)element.Attribute("line");
|
||||
if (letter == null || page == null || line == null) return null;
|
||||
res.Add("letter", letter);
|
||||
res.Add("page", page);
|
||||
res.Add("line", line);
|
||||
return res;
|
||||
}
|
||||
|
||||
public static IDictionary<string, ILookup<string, CollectedItem>>? GetLookups(IEnumerable<CollectedItem> items) {
|
||||
var res = new Dictionary<string, ILookup<string, CollectedItem>>();
|
||||
var letters = items.Where(x => x["letter"] != null && x["letter"]!.Count() > 0);
|
||||
if (letters == null || !letters.Any()) return null;
|
||||
res.Add("letter", letters.ToLookup(x => x["letter"]!));
|
||||
return res;
|
||||
}
|
||||
}
|
||||
21
HaWeb/Settings/XMLCollections/MetaCollection.cs
Normal file
21
HaWeb/Settings/XMLCollections/MetaCollection.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
namespace HaWeb.Settings.XMLCollections;
|
||||
using HaWeb.Models;
|
||||
using System.Xml.Linq;
|
||||
|
||||
public class MetaCollection : HaWeb.XMLParser.IXMLCollection {
|
||||
public string Key { get; } = "metas";
|
||||
public string[] xPath { get; } = new string[] { "/opus/descriptions/letterDesc", "/opus/data/descriptions/letterDesc" };
|
||||
public Func<XElement, string?> GenerateKey { get; } = GetKey;
|
||||
public Func<XElement, IDictionary<string, string>?>? GenerateDataFields { get; } = null;
|
||||
public Func<IEnumerable<CollectedItem>, IDictionary<string, ILookup<string, CollectedItem>>?>? GroupingsGeneration { get; } = null;
|
||||
public Func<IEnumerable<CollectedItem>, IDictionary<string, IEnumerable<CollectedItem>>?>? SortingsGeneration { get; } = null;
|
||||
public HaWeb.XMLParser.IXMLCollection[]? SubCollections { get; } = null;
|
||||
public bool Searchable { get; } = false;
|
||||
|
||||
public static Func<XElement, string?> GetKey { get; } = (elem) => {
|
||||
var index = elem.Attribute("ref");
|
||||
if (index != null && !String.IsNullOrWhiteSpace(index.Value))
|
||||
return index.Value;
|
||||
return null;
|
||||
};
|
||||
}
|
||||
57
HaWeb/Settings/XMLCollections/ReferenceCollections.cs
Normal file
57
HaWeb/Settings/XMLCollections/ReferenceCollections.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
namespace HaWeb.Settings.XMLCollections;
|
||||
using HaWeb.Models;
|
||||
using System.Xml.Linq;
|
||||
|
||||
public class HandPersonCollection : HaWeb.XMLParser.IXMLCollection {
|
||||
public string Key { get; } = "handpersons";
|
||||
public string[] xPath { get; } = new string[] { "/opus/data/definitions/handDefs/handDef", "/opus/definitions/handDefs/handDef" };
|
||||
public Func<XElement, string?> GenerateKey { get; } = GetKey;
|
||||
public Func<XElement, IDictionary<string, string>?>? GenerateDataFields { get; } = null;
|
||||
public Func<IEnumerable<CollectedItem>, IDictionary<string, ILookup<string, CollectedItem>>?>? GroupingsGeneration { get; } = null;
|
||||
public Func<IEnumerable<CollectedItem>, IDictionary<string, IEnumerable<CollectedItem>>?>? SortingsGeneration { get; } = null;
|
||||
public HaWeb.XMLParser.IXMLCollection[]? SubCollections { get; } = null;
|
||||
public bool Searchable { get; } = false;
|
||||
|
||||
public static Func<XElement, string?> GetKey { get; } = (elem) => {
|
||||
var index = elem.Attribute("index");
|
||||
if (index != null && !String.IsNullOrWhiteSpace(index.Value))
|
||||
return index.Value;
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
public class PersonCollection : HaWeb.XMLParser.IXMLCollection {
|
||||
public string Key { get; } = "persons";
|
||||
public string[] xPath { get; } = new string[] { "/opus/data/definitions/personDefs/personDef", "/opus/definitions/personDefs/personDef" };
|
||||
public Func<XElement, string?> GenerateKey { get; } = GetKey;
|
||||
public Func<XElement, IDictionary<string, string>?>? GenerateDataFields { get; } = null;
|
||||
public Func<IEnumerable<CollectedItem>, IDictionary<string, ILookup<string, CollectedItem>>?>? GroupingsGeneration { get; } = null;
|
||||
public Func<IEnumerable<CollectedItem>, IDictionary<string, IEnumerable<CollectedItem>>?>? SortingsGeneration { get; } = null;
|
||||
public HaWeb.XMLParser.IXMLCollection[]? SubCollections { get; } = null;
|
||||
public bool Searchable { get; } = false;
|
||||
|
||||
public static Func<XElement, string?> GetKey { get; } = (elem) => {
|
||||
var index = elem.Attribute("index");
|
||||
if (index != null && !String.IsNullOrWhiteSpace(index.Value))
|
||||
return index.Value;
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
public class LocationCollection : HaWeb.XMLParser.IXMLCollection {
|
||||
public string Key { get; } = "locations";
|
||||
public string[] xPath { get; } = new string[] { "/opus/data/definitions/locationDefs/locationDef", "/opus/definitions/locationDefs/locationDef" };
|
||||
public Func<XElement, string?> GenerateKey { get; } = GetKey;
|
||||
public Func<XElement, IDictionary<string, string>?>? GenerateDataFields { get; } = null;
|
||||
public Func<IEnumerable<CollectedItem>, IDictionary<string, ILookup<string, CollectedItem>>?>? GroupingsGeneration { get; } = null;
|
||||
public Func<IEnumerable<CollectedItem>, IDictionary<string, IEnumerable<CollectedItem>>?>? SortingsGeneration { get; } = null;
|
||||
public HaWeb.XMLParser.IXMLCollection[]? SubCollections { get; } = null;
|
||||
public bool Searchable { get; } = false;
|
||||
|
||||
public static Func<XElement, string?> GetKey { get; } = (elem) => {
|
||||
var index = elem.Attribute("index");
|
||||
if (index != null && !String.IsNullOrWhiteSpace(index.Value))
|
||||
return index.Value;
|
||||
return null;
|
||||
};
|
||||
}
|
||||
21
HaWeb/Settings/XMLCollections/TraditionCollection.cs
Normal file
21
HaWeb/Settings/XMLCollections/TraditionCollection.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
namespace HaWeb.Settings.XMLCollections;
|
||||
using HaWeb.Models;
|
||||
using System.Xml.Linq;
|
||||
|
||||
public class TraditionCollection : HaWeb.XMLParser.IXMLCollection {
|
||||
public string Key { get; } = "traditions";
|
||||
public string[] xPath { get; } = new string[] { "/opus/data/traditions/letterTradition", "/opus/traditions/letterTradition" };
|
||||
public Func<XElement, string?> GenerateKey { get; } = GetKey;
|
||||
public Func<XElement, IDictionary<string, string>?>? GenerateDataFields { get; } = null;
|
||||
public Func<IEnumerable<CollectedItem>, IDictionary<string, ILookup<string, CollectedItem>>?>? GroupingsGeneration { get; } = null;
|
||||
public Func<IEnumerable<CollectedItem>, IDictionary<string, IEnumerable<CollectedItem>>?>? SortingsGeneration { get; } = null;
|
||||
public HaWeb.XMLParser.IXMLCollection[]? SubCollections { get; } = null;
|
||||
public bool Searchable { get; } = true;
|
||||
|
||||
public static Func<XElement, string?> GetKey { get; } = (elem) => {
|
||||
var index = elem.Attribute("ref");
|
||||
if (index != null && !String.IsNullOrWhiteSpace(index.Value))
|
||||
return index.Value;
|
||||
return null;
|
||||
};
|
||||
}
|
||||
@@ -7,41 +7,12 @@ public class CommentRoot : HaWeb.XMLParser.IXMLRoot {
|
||||
public string Type { get; } = "Register";
|
||||
public string Prefix { get; } = "register";
|
||||
public string[] XPathContainer { get; } = { ".//data//kommentare/kommcat", ".//kommentare/kommcat" };
|
||||
public (
|
||||
string Key,
|
||||
string xPath,
|
||||
Func<XElement, string?> GenerateKey,
|
||||
Func<XElement, Dictionary<string, string[]>?>? GenerateDataFields,
|
||||
Func<List<CollectedItem>, Dictionary<string, Lookup<string, CollectedItem>>?>? GroupingsGeneration,
|
||||
Func<List<CollectedItem>, Dictionary<string, List<CollectedItem>>?>? SortingsGeneration,
|
||||
bool Searchable
|
||||
)[]? Collections { get; } = {
|
||||
("comments-register", "/opus/data/kommentare/kommcat[@value='neuzeit']/kommentar", GetKey, null, null, null, true),
|
||||
("comments-register", "/opus/kommentare/kommcat[@value='neuzeit']/kommentar", GetKey, null, null, null, true),
|
||||
("subcomments-register", "/opus/data/kommentare/kommcat[@value='neuzeit']/kommentar/subsection", GetKey, null, null, null, true),
|
||||
("subcomments-register", "/opus/kommentare/kommcat[@value='neuzeit']/kommentar/subsection", GetKey, null, null, null, true),
|
||||
("comments-edition", "/opus/data/kommentare/kommcat[@value='editionen']/kommentar", GetKey, null, null, null, true),
|
||||
("comments-edition", "/opus/kommentare/kommcat[@value='editionen']/kommentar", GetKey, null, null, null, true),
|
||||
("comments-forschung", "/opus/data/kommentare/kommcat[@value='forschung']/kommentar", GetKey, null, null, null, true),
|
||||
("comments-forschung", "/opus/kommentare/kommcat[@value='forschung']/kommentar", GetKey, null, null, null, true),
|
||||
("comments-bibel", "/opus/data/kommentare/kommcat[@value='bibel']/kommentar", GetKey, null, null, null, false),
|
||||
("comments-bibel", "/opus/kommentare/kommcat[@value='bibel']/kommentar", GetKey, null, null, null, false),
|
||||
("subcomments-bibel", "/opus/data/kommentare/kommcat[@value='bibel']/kommentar/subsection", GetKey, null, null, null, false),
|
||||
("subcomments-bibel", "/opus/kommentare/kommcat[@value='bibel']/kommentar/subsection", GetKey, null, null, null, false),
|
||||
};
|
||||
|
||||
public Predicate<XElement> IsCollectedObject { get; } = (elem) => {
|
||||
if (elem.Name == "kommentar") return true;
|
||||
else return false;
|
||||
};
|
||||
|
||||
public static Func<XElement, string?> GetKey { get; } = (elem) => {
|
||||
var index = elem.Attribute("id");
|
||||
if (index != null && !String.IsNullOrWhiteSpace(index.Value))
|
||||
return index.Value;
|
||||
else return null;
|
||||
};
|
||||
|
||||
public List<(string, string?)>? GenerateFields(XMLRootDocument document) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -7,31 +7,12 @@ public class DescriptionsRoot : HaWeb.XMLParser.IXMLRoot {
|
||||
public string Type { get; } = "Metadaten";
|
||||
public string Prefix { get; } = "metadaten";
|
||||
public string[] XPathContainer { get; } = { ".//data/descriptions", ".//descriptions" };
|
||||
public (
|
||||
string Key,
|
||||
string xPath,
|
||||
Func<XElement, string?> GenerateKey,
|
||||
Func<XElement, Dictionary<string, string[]>?>? GenerateDataFields,
|
||||
Func<List<CollectedItem>, Dictionary<string, Lookup<string, CollectedItem>>?>? GroupingsGeneration,
|
||||
Func<List<CollectedItem>, Dictionary<string, List<CollectedItem>>?>? SortingsGeneration,
|
||||
bool Searchable
|
||||
)[]? Collections { get; } = {
|
||||
("metas", "/opus/descriptions/letterDesc", GetKey, null, null, null, false),
|
||||
("metas", "/opus/data/descriptions/letterDesc", GetKey, null, null, null, false)
|
||||
};
|
||||
|
||||
public Predicate<XElement> IsCollectedObject { get; } = (elem) => {
|
||||
if (elem.Name == "letterDesc") return true;
|
||||
return false;
|
||||
};
|
||||
|
||||
public static Func<XElement, string?> GetKey { get; } = (elem) => {
|
||||
var index = elem.Attribute("ref");
|
||||
if (index != null && !String.IsNullOrWhiteSpace(index.Value))
|
||||
return index.Value;
|
||||
return null;
|
||||
};
|
||||
|
||||
public List<(string, string?)>? GenerateFields(XMLRootDocument document) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -8,31 +8,12 @@ public class DocumentRoot : HaWeb.XMLParser.IXMLRoot {
|
||||
public string Type { get; } = "Brieftext";
|
||||
public string Prefix { get; } = "brieftext";
|
||||
public string[] XPathContainer { get; } = { ".//data/document", ".//document" };
|
||||
public (
|
||||
string Key,
|
||||
string xPath,
|
||||
Func<XElement, string?> GenerateKey,
|
||||
Func<XElement, Dictionary<string, string[]>?>? GenerateDataFields,
|
||||
Func<List<CollectedItem>, Dictionary<string, Lookup<string, CollectedItem>>?>? GroupingsGeneration,
|
||||
Func<List<CollectedItem>, Dictionary<string, List<CollectedItem>>?>? SortingsGeneration,
|
||||
bool Searchable
|
||||
)[]? Collections { get; } = {
|
||||
("letters", "/opus/data/document/letterText", GetKey, null, null, null, true),
|
||||
("letters", "/opus/document/letterText", GetKey, null, null, null, true)
|
||||
};
|
||||
|
||||
public Predicate<XElement> IsCollectedObject { get; } = (elem) => {
|
||||
if (elem.Name == "letterText") return true;
|
||||
else return false;
|
||||
};
|
||||
|
||||
public static Func<XElement, string?> GetKey { get; } = (elem) => {
|
||||
var index = elem.Attribute("index");
|
||||
if (index != null && !String.IsNullOrWhiteSpace(index.Value))
|
||||
return index.Value;
|
||||
else return null;
|
||||
};
|
||||
|
||||
public List<(string, string?)>? GenerateFields(XMLRootDocument document) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -7,31 +7,12 @@ public class EditsRoot : HaWeb.XMLParser.IXMLRoot {
|
||||
public string Type { get; } = "Texteingriffe";
|
||||
public string Prefix { get; } = "texteingriffe";
|
||||
public string[] XPathContainer { get; } = { ".//data/edits", ".//edits" };
|
||||
public (
|
||||
string Key,
|
||||
string xPath,
|
||||
Func<XElement, string?> GenerateKey,
|
||||
Func<XElement, Dictionary<string, string[]>?>? GenerateDataFields,
|
||||
Func<List<CollectedItem>, Dictionary<string, Lookup<string, CollectedItem>>?>? GroupingsGeneration,
|
||||
Func<List<CollectedItem>, Dictionary<string, List<CollectedItem>>?>? SortingsGeneration,
|
||||
bool Searchable
|
||||
)[]? Collections { get; } = {
|
||||
("edits", "/data/edits/editreason", GetKey, null, null, null, true),
|
||||
("edits", "/edits/editreason", GetKey, null, null, null, true)
|
||||
};
|
||||
|
||||
public Predicate<XElement> IsCollectedObject { get; } = (elem) => {
|
||||
if (elem.Name == "editreason") return true;
|
||||
else return false;
|
||||
};
|
||||
|
||||
public static Func<XElement, string?> GetKey { get; } = (elem) => {
|
||||
var index = elem.Attribute("index");
|
||||
if (index != null && !String.IsNullOrWhiteSpace(index.Value))
|
||||
return index.Value;
|
||||
else return null;
|
||||
};
|
||||
|
||||
public List<(string, string?)>? GenerateFields(XMLRootDocument document) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -7,31 +7,12 @@ public class MarginalsRoot : HaWeb.XMLParser.IXMLRoot {
|
||||
public string Type { get; } = "Stellenkommentar";
|
||||
public string Prefix { get; } = "stellenkommentar";
|
||||
public string[] XPathContainer { get; } = { ".//data/marginalien", ".//marginalien" };
|
||||
public (
|
||||
string Key,
|
||||
string xPath,
|
||||
Func<XElement, string?> GenerateKey,
|
||||
Func<XElement, Dictionary<string, string[]>?>? GenerateDataFields,
|
||||
Func<List<CollectedItem>, Dictionary<string, Lookup<string, CollectedItem>>?>? GroupingsGeneration,
|
||||
Func<List<CollectedItem>, Dictionary<string, List<CollectedItem>>?>? SortingsGeneration,
|
||||
bool Searchable
|
||||
)[]? Collections { get; } = {
|
||||
("marginals", "/data/marginalien/marginal", GetKey, null, null, null, true),
|
||||
("marginals", "/marginalien/marginal", GetKey, null, null, null, true)
|
||||
};
|
||||
|
||||
public Predicate<XElement> IsCollectedObject { get; } = (elem) => {
|
||||
if (elem.Name == "marginal") return true;
|
||||
else return false;
|
||||
};
|
||||
|
||||
public static Func<XElement, string?> GetKey { get; } = (elem) => {
|
||||
var index = elem.Attribute("index");
|
||||
if (index != null && !String.IsNullOrWhiteSpace(index.Value))
|
||||
return index.Value;
|
||||
else return null;
|
||||
};
|
||||
|
||||
public List<(string, string?)>? GenerateFields(XMLRootDocument document) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -7,22 +7,6 @@ public class ReferencesRoot : HaWeb.XMLParser.IXMLRoot {
|
||||
public string Type { get; } = "Personen / Orte";
|
||||
public string Prefix { get; } = "personenorte";
|
||||
public string[] XPathContainer { get; } = { ".//data/definitions", ".//definitions" };
|
||||
public (
|
||||
string Key,
|
||||
string xPath,
|
||||
Func<XElement, string?> GenerateKey,
|
||||
Func<XElement, Dictionary<string, string[]>?>? GenerateDataFields,
|
||||
Func<List<CollectedItem>, Dictionary<string, Lookup<string, CollectedItem>>?>? GroupingsGeneration,
|
||||
Func<List<CollectedItem>, Dictionary<string, List<CollectedItem>>?>? SortingsGeneration,
|
||||
bool Searchable
|
||||
)[]? Collections { get; } = {
|
||||
("person-definitions", "/opus/data/definitions/personDefs/personDef", GetKey, null, null, null, false),
|
||||
("person-definitions", "/opus/definitions/personDefs/personDef", GetKey, null, null, null, false),
|
||||
("hand-definitions", "/opus/data/definitions/handDefs/handDef", GetKey, null, null, null, false),
|
||||
("hand-definitions", "/opus/definitions/handDefs/handDef", GetKey, null, null, null, false),
|
||||
("location-definitions", "/opus/data/definitions/locationDefs/locationDef", GetKey, null, null, null, false),
|
||||
("location-definitions", "/opus/definitions/locationDefs/locationDef", GetKey, null, null, null, false)
|
||||
};
|
||||
|
||||
public Predicate<XElement> IsCollectedObject { get; } = (elem) => {
|
||||
if (elem.Name == "personDefs" || elem.Name == "structureDefs" || elem.Name == "handDefs" || elem.Name == "locationDefs")
|
||||
@@ -30,10 +14,6 @@ public class ReferencesRoot : HaWeb.XMLParser.IXMLRoot {
|
||||
return false;
|
||||
};
|
||||
|
||||
public static Func<XElement, string?> GetKey { get; } = (elem) => {
|
||||
return elem.Attribute("index") != null ? elem.Attribute("index")!.Value : null;
|
||||
};
|
||||
|
||||
public List<(string, string?)>? GenerateFields(XMLRootDocument document) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -7,31 +7,12 @@ public class TraditionsRoot : HaWeb.XMLParser.IXMLRoot {
|
||||
public string Type { get; } = "Überlieferung";
|
||||
public string Prefix { get; } = "ueberlieferung";
|
||||
public string[] XPathContainer { get; } = { ".//data/traditions", ".//traditions" };
|
||||
public (
|
||||
string Key,
|
||||
string xPath,
|
||||
Func<XElement, string?> GenerateKey,
|
||||
Func<XElement, Dictionary<string, string[]>?>? GenerateDataFields,
|
||||
Func<List<CollectedItem>, Dictionary<string, Lookup<string, CollectedItem>>?>? GroupingsGeneration,
|
||||
Func<List<CollectedItem>, Dictionary<string, List<CollectedItem>>?>? SortingsGeneration,
|
||||
bool Searchable
|
||||
)[]? Collections { get; } = {
|
||||
("tradition", "/opus/data/traditions/letterTradition", GetKey, null, null, null, true),
|
||||
("tradition", "/opus/traditions/letterTradition", GetKey, null, null, null, true)
|
||||
};
|
||||
|
||||
public Predicate<XElement> IsCollectedObject { get; } = (elem) => {
|
||||
if (elem.Name == "letterTradition") return true;
|
||||
else return false;
|
||||
};
|
||||
|
||||
public static Func<XElement, string?> GetKey { get; } = (elem) => {
|
||||
var index = elem.Attribute("ref");
|
||||
if (index != null && !String.IsNullOrWhiteSpace(index.Value))
|
||||
return index.Value;
|
||||
return null;
|
||||
};
|
||||
|
||||
public List<(string, string?)>? GenerateFields(XMLRootDocument document) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
@await Html.PartialAsync("/Views/Shared/_LetterHead.cshtml", (Model.MetaData, false))
|
||||
<div class="ha-letterheadernav">
|
||||
<div class="ha-lettertabs">
|
||||
@if (Model.ParsedText != null && !String.IsNullOrWhiteSpace(Model.ParsedText))
|
||||
@if (!String.IsNullOrWhiteSpace(Model.ParsedText))
|
||||
{
|
||||
<a class="" id="ha-lettertextbtn">Brieftext</a>
|
||||
@if (Model.ParsedMarginals != null)
|
||||
|
||||
24
HaWeb/XMLParser/IXMLCollection.cs
Normal file
24
HaWeb/XMLParser/IXMLCollection.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
namespace HaWeb.XMLParser;
|
||||
using HaWeb.Models;
|
||||
using System.Xml.Linq;
|
||||
|
||||
public interface IXMLCollection {
|
||||
// Collections of Elements to be created a Hamann File Root
|
||||
// Key: the key under which the element(s) will be filed
|
||||
// xPath: (absolute, realtive if subelement) XPaths to the element(s)
|
||||
// GenerateKey: How to extract an identifier for the single element in the collection
|
||||
// GenerateDataFields: Generate a dict of data associated with each of the collected Elements input: XElement output: Dictonary<string>
|
||||
// GroupingsGeneration: datafields by which dictorary-like groups should be held in memory input: List<CollectedItem> output: Dictonary<string, Lookup<string, CollectedItem[]>>
|
||||
// SortingsGeneration: datafields by which a sorting should be held in memory input: List<CollectedItem> output: ordered List<CollectedItem>
|
||||
// SubCollections to be created in this element
|
||||
// Searchable: Will the element be indexed for full-text-search?
|
||||
|
||||
abstract string Key { get; }
|
||||
abstract string[] xPath { get; }
|
||||
abstract Func<XElement, string?> GenerateKey { get; }
|
||||
abstract Func<XElement, IDictionary<string, string>?>? GenerateDataFields { get; }
|
||||
abstract Func<IEnumerable<CollectedItem>, IDictionary<string, ILookup<string, CollectedItem>>?>? GroupingsGeneration { get; }
|
||||
abstract Func<IEnumerable<CollectedItem>, IDictionary<string, IEnumerable<CollectedItem>>?>? SortingsGeneration { get; }
|
||||
abstract IXMLCollection[]? SubCollections { get; }
|
||||
abstract bool Searchable { get; }
|
||||
}
|
||||
@@ -13,24 +13,6 @@ public interface IXMLRoot {
|
||||
// XPaths to determine if container is present
|
||||
public abstract string[] XPathContainer { get; }
|
||||
|
||||
// Collections of Elements to be created from this Root
|
||||
// Key: the key under which the element(s) will be files
|
||||
// xPath: the (absolute) XPath to the element(s)
|
||||
// Searchable: Will the element be indexed for full-text-search?
|
||||
// GenerateKey: How to extrect an identifier for the single element in the collection
|
||||
// GenerateDataFields: Generate a dict of data associated with each of the collected Elements input: XElement output: Dictonary<string>
|
||||
// GroupingsGeneration: datafields by which dictorary-like groups should be held in memory input: List<CollectedItem> output: Dictonary<string, Lookup<string, CollectedItem[]>>
|
||||
// SortingsGeneration: datafields by which a sorting should be held in memory input: List<CollectedItem> output: ordered List<CollectedItem>
|
||||
public abstract (
|
||||
string Key,
|
||||
string xPath,
|
||||
Func<XElement, string?> GenerateKey,
|
||||
Func<XElement, Dictionary<string, string[]>?>? GenerateDataFields,
|
||||
Func<List<CollectedItem>, Dictionary<string, Lookup<string, CollectedItem>>?>? GroupingsGeneration,
|
||||
Func<List<CollectedItem>, Dictionary<string, List<CollectedItem>>?>? SortingsGeneration,
|
||||
bool Searchable
|
||||
)[]? Collections { get; }
|
||||
|
||||
// Determines child objects to be collected
|
||||
// (deprecated see collections above; only used internally)
|
||||
public abstract Predicate<XElement> IsCollectedObject { get; }
|
||||
|
||||
@@ -12,6 +12,7 @@ using HaXMLReader.Interfaces;
|
||||
public class XMLService : IXMLService {
|
||||
private Dictionary<string, FileList?>? _Used;
|
||||
private Dictionary<string, IXMLRoot>? _Roots;
|
||||
private Dictionary<string, IXMLCollection>? _Collections;
|
||||
|
||||
private Stack<Dictionary<string, FileList?>>? _InProduction;
|
||||
|
||||
@@ -20,15 +21,25 @@ public class XMLService : IXMLService {
|
||||
|
||||
public XMLService() {
|
||||
// Getting all classes which implement IXMLRoot for possible document endpoints
|
||||
var types = _GetAllTypesThatImplementInterface<IXMLRoot>().ToList();
|
||||
types.ForEach( x => {
|
||||
var roottypes = _GetAllTypesThatImplementInterface<IXMLRoot>().ToList();
|
||||
roottypes.ForEach( x => {
|
||||
if (this._Roots == null) this._Roots = new Dictionary<string, IXMLRoot>();
|
||||
var instance = (IXMLRoot)Activator.CreateInstance(x)!;
|
||||
if (instance != null) this._Roots.Add(instance.Prefix, instance);
|
||||
});
|
||||
|
||||
var collectiontypes = _GetAllTypesThatImplementInterface<IXMLCollection>().ToList();
|
||||
collectiontypes.ForEach( x => {
|
||||
if (this._Collections == null) this._Collections = new Dictionary<string, IXMLCollection>();
|
||||
var instance = (IXMLCollection)Activator.CreateInstance(x)!;
|
||||
if (instance != null) this._Collections.Add(instance.Key, instance);
|
||||
});
|
||||
|
||||
if (_Roots == null || !_Roots.Any())
|
||||
throw new Exception("No classes for upload endpoints were found!");
|
||||
|
||||
if (_Collections == null || !_Collections.Any())
|
||||
throw new Exception("No classes for object collection were found!");
|
||||
}
|
||||
|
||||
public IXMLRoot? GetRoot(string name) {
|
||||
@@ -66,33 +77,32 @@ public class XMLService : IXMLService {
|
||||
int startingSize = 2909;
|
||||
int startingSizeAllCollections = 23;
|
||||
var ret = new ConcurrentDictionary<string, ItemsCollection>(concurrencyLevel, startingSizeAllCollections);
|
||||
foreach (var root in _Roots) {
|
||||
if (root.Value.Collections != null)
|
||||
foreach (var coll in root.Value.Collections) {
|
||||
var elem = document.XPathSelectElements(coll.xPath);
|
||||
if (elem != null && elem.Any()) {
|
||||
var items = new ConcurrentDictionary<string, CollectedItem>(concurrencyLevel, startingSize);
|
||||
Parallel.ForEach(elem, (e) => {
|
||||
var k = coll.GenerateKey(e);
|
||||
if (k != null) {
|
||||
var searchtext = coll.Searchable ?
|
||||
StringHelpers.NormalizeWhiteSpace(e.ToString(), ' ', false) :
|
||||
null;
|
||||
var datafileds = coll.GenerateDataFields != null ?
|
||||
coll.GenerateDataFields(e) :
|
||||
null;
|
||||
items[k] = new CollectedItem(k, e, root.Value, coll.Key, datafileds, searchtext);
|
||||
}
|
||||
});
|
||||
if (items.Any()) {
|
||||
if (!ret.ContainsKey(coll.Key))
|
||||
ret[coll.Key] = new ItemsCollection(coll.Key, coll.Searchable, root.Value, coll.GroupingsGeneration, coll.SortingsGeneration);
|
||||
foreach (var item in items)
|
||||
ret[coll.Key].Items.Add(item.Key, item.Value);
|
||||
|
||||
if (_Collections != null)
|
||||
foreach (var coll in _Collections) {
|
||||
var elem = coll.Value.xPath.Aggregate(new List<XElement>(), (x, y) => { x.AddRange(document.XPathSelectElements(y).ToList()); return x; } );
|
||||
if (elem != null && elem.Any()) {
|
||||
var items = new ConcurrentDictionary<string, CollectedItem>(concurrencyLevel, startingSize);
|
||||
Parallel.ForEach(elem, (e) => {
|
||||
var k = coll.Value.GenerateKey(e);
|
||||
if (k != null) {
|
||||
var searchtext = coll.Value.Searchable ?
|
||||
StringHelpers.NormalizeWhiteSpace(e.ToString(), ' ', false) :
|
||||
null;
|
||||
var datafileds = coll.Value.GenerateDataFields != null ?
|
||||
coll.Value.GenerateDataFields(e) :
|
||||
null;
|
||||
items[k] = new CollectedItem(k, e, coll.Value, datafileds, searchtext);
|
||||
}
|
||||
});
|
||||
if (items.Any()) {
|
||||
if (!ret.ContainsKey(coll.Key))
|
||||
ret[coll.Key] = new ItemsCollection(coll.Key, coll.Value);
|
||||
foreach (var item in items)
|
||||
ret[coll.Key].Items.Add(item.Key, item.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ret.Any()) {
|
||||
Parallel.ForEach(ret, (collection) => {
|
||||
|
||||
Reference in New Issue
Block a user