Skip to content

Commit

Permalink
Handle canonical LF tag names in LfMerge
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rmunn committed Nov 18, 2021
1 parent 2588fd3 commit 703fdb4
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
}
}
}
Original file line number Diff line number Diff line change
@@ -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<CanonicalLfTagItem>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 4 additions & 0 deletions src/LfMerge.Core/LfMerge.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,9 @@ See full changelog at https://github.com/sillsdev/LfMerge/blob/master/CHANGELOG.
<Link>SemDom.xml</Link>
<LogicalName>SemDom.xml</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="..\..\data\canonical-lf-tags.xml">
<Link>canonical-lf-tags.xml</Link>
<LogicalName>canonical-lf-tags.xml</LogicalName>
</EmbeddedResource>
</ItemGroup>
</Project>
2 changes: 2 additions & 0 deletions src/LfMerge.Core/MagicStrings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down Expand Up @@ -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";
Expand Down

0 comments on commit 703fdb4

Please sign in to comment.