private Thesaurus ParseSource(XElement sourceElem, string id, bool authors) { if (sourceElem == null) { return(null); } Thesaurus thesaurus = new Thesaurus( $"apparatus-{(authors? "authors":"witnesses")}.{id}@en"); foreach (XElement child in sourceElem .Elements(XmlHelper.TEI + (authors? "bibl" : "witness"))) { string value = _wsRegex.Replace(child.Value, " ").Trim(); // prepend @n if @ref if (child.Attribute("ref") != null) { value = child.Attribute("n").Value + value; } var entry = new ThesaurusEntry( child.Attribute(XmlHelper.XML + "id").Value, ReduceLabel(value)); thesaurus.AddEntry(entry); } return(thesaurus); }
/// <summary> /// Gets a thesaurus from this object. /// </summary> /// <returns>Thesaurus.</returns> public Thesaurus ToThesaurus() { Thesaurus thesaurus = new Thesaurus(Id) { TargetId = TargetId }; foreach (MongoThesaurusEntry entry in Entries) { thesaurus.AddEntry(entry.ToThesaurusEntry()); } return(thesaurus); }
private static Thesaurus ReadThesaurus(JsonElement thesEl) { string id = thesEl.GetProperty("id").GetString(); Thesaurus thesaurus = new Thesaurus(id); if (thesEl.TryGetProperty("targetId", out JsonElement targetEl)) { thesaurus.TargetId = targetEl.GetString(); } else { foreach (JsonElement entryEl in thesEl.GetProperty("entries") .EnumerateArray()) { thesaurus.AddEntry(new ThesaurusEntry { Id = entryEl.GetProperty("id").GetString(), Value = entryEl.GetProperty("value").GetString() }); } } return(thesaurus); }
public IActionResult AddThesaurus( [FromRoute] string database, [FromBody] ThesaurusBindingModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } ICadmusRepository repository = _repositoryProvider.CreateRepository(database); Thesaurus thesaurus = new Thesaurus(model.Id); foreach (ThesaurusEntryBindingModel entry in model.Entries) { thesaurus.AddEntry(new ThesaurusEntry(entry.Id, entry.Value)); } repository.AddThesaurus(thesaurus); return(CreatedAtRoute("GetThesaurus", new { database, id = thesaurus.Id }, thesaurus)); }