From 703fdb42172437ffa4e5b9b33a713e7e6f81e33e Mon Sep 17 00:00:00 2001 From: Robin Munn Date: Tue, 16 Nov 2021 16:28:57 +0700 Subject: [PATCH] Handle canonical LF tag names in LfMerge Now LfMerge can create a CmPossibilityList in FLEx data if it doesn't already exist, which will allow us to create the custom field that will store LF tags in FLEx data. --- .../CanonicalSources/CanonicalLfTagItem.cs | 62 +++++++++++++++++++ .../CanonicalSources/CanonicalLfTagSource.cs | 18 ++++++ .../CanonicalOptionListSource.cs | 2 + src/LfMerge.Core/LfMerge.Core.csproj | 4 ++ src/LfMerge.Core/MagicStrings.cs | 2 + 5 files changed, 88 insertions(+) create mode 100644 src/LfMerge.Core/DataConverters/CanonicalSources/CanonicalLfTagItem.cs create mode 100644 src/LfMerge.Core/DataConverters/CanonicalSources/CanonicalLfTagSource.cs diff --git a/src/LfMerge.Core/DataConverters/CanonicalSources/CanonicalLfTagItem.cs b/src/LfMerge.Core/DataConverters/CanonicalSources/CanonicalLfTagItem.cs new file mode 100644 index 00000000..ff321ab7 --- /dev/null +++ b/src/LfMerge.Core/DataConverters/CanonicalSources/CanonicalLfTagItem.cs @@ -0,0 +1,62 @@ +// Copyright (c) 2016-2018 SIL International +// This software is licensed under the MIT license (http://opensource.org/licenses/MIT) +using System.Xml; +using SIL.LCModel; + +namespace LfMerge.Core.DataConverters.CanonicalSources +{ + public class CanonicalLfTagItem : CanonicalItem + { + public override void PopulateFromXml(XmlReader reader) + { + if (reader.LocalName != "item" || string.IsNullOrEmpty(reader.GetAttribute("guid"))) + return; // If we weren't on the right kind of node, do nothing + GuidStr = reader.GetAttribute("guid"); + while (reader.Read()) + { + switch (reader.NodeType) + { + case XmlNodeType.Element: + { + switch (reader.LocalName) + { + case "item": + if (!string.IsNullOrEmpty(reader.GetAttribute("id"))) + { + Key = reader.GetAttribute("id"); + } + break; + case "abbrev": + AddAbbrev(reader.GetAttribute("ws"), reader.ReadInnerXml()); + break; + case "term": + AddName(reader.GetAttribute("ws"), reader.ReadInnerXml()); + break; + case "def": + AddDescription(reader.GetAttribute("ws"), reader.ReadInnerXml()); + break; + } + break; + } + case XmlNodeType.EndElement: + { + if (reader.LocalName == "item") + { + if (string.IsNullOrEmpty(Key)) { + Key = AbbrevByWs(KeyWs); + } + reader.Read(); // Skip past the closing element before returning + return; + } + break; + } + } + } + } + + protected override void PopulatePossibilityFromExtraData(ICmPossibility poss) + { + // CanonicalLfTagItem instances don't need anything from ExtraData + } + } +} diff --git a/src/LfMerge.Core/DataConverters/CanonicalSources/CanonicalLfTagSource.cs b/src/LfMerge.Core/DataConverters/CanonicalSources/CanonicalLfTagSource.cs new file mode 100644 index 00000000..e4313b4b --- /dev/null +++ b/src/LfMerge.Core/DataConverters/CanonicalSources/CanonicalLfTagSource.cs @@ -0,0 +1,18 @@ +// Copyright (c) 2016 SIL International +// This software is licensed under the MIT license (http://opensource.org/licenses/MIT) + +namespace LfMerge.Core.DataConverters.CanonicalSources +{ + public class CanonicalLfTagSource : CanonicalOptionListSource + { + public CanonicalLfTagSource() + : base("canonical-lf-tags.xml", "item") + { + } + + public override void LoadCanonicalData() + { + LoadCanonicalData(); + } + } +} diff --git a/src/LfMerge.Core/DataConverters/CanonicalSources/CanonicalOptionListSource.cs b/src/LfMerge.Core/DataConverters/CanonicalSources/CanonicalOptionListSource.cs index c8fc23c0..2371447e 100644 --- a/src/LfMerge.Core/DataConverters/CanonicalSources/CanonicalOptionListSource.cs +++ b/src/LfMerge.Core/DataConverters/CanonicalSources/CanonicalOptionListSource.cs @@ -36,6 +36,8 @@ public static CanonicalOptionListSource Create(string listCode) return new CanonicalPartOfSpeechSource(); else if (listCode == MagicStrings.LfOptionListCodeForSemanticDomains) return new CanonicalSemanticDomainSource(); + else if (listCode == MagicStrings.LfOptionListCodeForLfTags) + return new CanonicalLfTagSource(); else return null; } diff --git a/src/LfMerge.Core/LfMerge.Core.csproj b/src/LfMerge.Core/LfMerge.Core.csproj index 59101c2e..8375badb 100644 --- a/src/LfMerge.Core/LfMerge.Core.csproj +++ b/src/LfMerge.Core/LfMerge.Core.csproj @@ -59,5 +59,9 @@ See full changelog at https://github.com/sillsdev/LfMerge/blob/master/CHANGELOG. SemDom.xml SemDom.xml + + canonical-lf-tags.xml + canonical-lf-tags.xml + \ No newline at end of file diff --git a/src/LfMerge.Core/MagicStrings.cs b/src/LfMerge.Core/MagicStrings.cs index bef4967f..cfb8f598 100644 --- a/src/LfMerge.Core/MagicStrings.cs +++ b/src/LfMerge.Core/MagicStrings.cs @@ -16,6 +16,7 @@ static MagicStrings() // Option lists that are currently used in LF (as of 2016-03-01) { LfOptionListCodeForGrammaticalInfo, "Part of Speech" }, { LfOptionListCodeForSemanticDomains, "Semantic Domain" }, + { LfOptionListCodeForLfTags, "LF Tags" }, { LfOptionListCodeForAcademicDomainTypes, "Academic Domains" }, { LfOptionListCodeForEnvironments, "Environments" }, { LfOptionListCodeForLocations, "Location" }, @@ -44,6 +45,7 @@ static MagicStrings() // Option lists that are currently used in LF (as of 2016-03-01) public const string LfOptionListCodeForGrammaticalInfo = "grammatical-info"; public const string LfOptionListCodeForSemanticDomains = "semantic-domain-ddp4"; + public const string LfOptionListCodeForLfTags = "lf-entry-tags"; public const string LfOptionListCodeForAcademicDomainTypes = "domain-type"; public const string LfOptionListCodeForEnvironments = "environments"; public const string LfOptionListCodeForLocations = "location";