Skip to content

Commit 64d456d

Browse files
committed
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.
1 parent 2588fd3 commit 64d456d

File tree

4 files changed

+86
-0
lines changed

4 files changed

+86
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright (c) 2016-2018 SIL International
2+
// This software is licensed under the MIT license (http://opensource.org/licenses/MIT)
3+
using System.Xml;
4+
using SIL.LCModel;
5+
6+
namespace LfMerge.Core.DataConverters.CanonicalSources
7+
{
8+
public class CanonicalLfTagItem : CanonicalItem
9+
{
10+
public override void PopulateFromXml(XmlReader reader)
11+
{
12+
if (reader.LocalName != "item" || string.IsNullOrEmpty(reader.GetAttribute("guid")))
13+
return; // If we weren't on the right kind of node, do nothing
14+
GuidStr = reader.GetAttribute("guid");
15+
while (reader.Read())
16+
{
17+
switch (reader.NodeType)
18+
{
19+
case XmlNodeType.Element:
20+
{
21+
switch (reader.LocalName)
22+
{
23+
case "item":
24+
if (!string.IsNullOrEmpty(reader.GetAttribute("id")))
25+
{
26+
Key = reader.GetAttribute("id");
27+
}
28+
break;
29+
case "abbrev":
30+
AddAbbrev(reader.GetAttribute("ws"), reader.ReadInnerXml());
31+
break;
32+
case "term":
33+
AddName(reader.GetAttribute("ws"), reader.ReadInnerXml());
34+
break;
35+
case "def":
36+
AddDescription(reader.GetAttribute("ws"), reader.ReadInnerXml());
37+
break;
38+
}
39+
break;
40+
}
41+
case XmlNodeType.EndElement:
42+
{
43+
if (reader.LocalName == "item")
44+
{
45+
if (string.IsNullOrEmpty(Key)) {
46+
Key = AbbrevByWs(KeyWs);
47+
}
48+
reader.Read(); // Skip past the closing element before returning
49+
return;
50+
}
51+
break;
52+
}
53+
}
54+
}
55+
}
56+
57+
protected override void PopulatePossibilityFromExtraData(ICmPossibility poss)
58+
{
59+
// CanonicalLfTagItem instances don't need anything from ExtraData
60+
}
61+
}
62+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) 2016 SIL International
2+
// This software is licensed under the MIT license (http://opensource.org/licenses/MIT)
3+
4+
namespace LfMerge.Core.DataConverters.CanonicalSources
5+
{
6+
public class CanonicalLfTagSource : CanonicalOptionListSource
7+
{
8+
public CanonicalLfTagSource()
9+
: base("canonical-lf-tags.xml", "item")
10+
{
11+
}
12+
13+
public override void LoadCanonicalData()
14+
{
15+
LoadCanonicalData<CanonicalLfTagItem>();
16+
}
17+
}
18+
}

src/LfMerge.Core/LfMerge.Core.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,9 @@ See full changelog at https://github.com/sillsdev/LfMerge/blob/master/CHANGELOG.
5959
<Link>SemDom.xml</Link>
6060
<LogicalName>SemDom.xml</LogicalName>
6161
</EmbeddedResource>
62+
<EmbeddedResource Include="..\..\data\canonical-lf-tags.xml">
63+
<Link>canonical-lf-tags.xml</Link>
64+
<LogicalName>canonical-lf-tags.xml</LogicalName>
65+
</EmbeddedResource>
6266
</ItemGroup>
6367
</Project>

src/LfMerge.Core/MagicStrings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ static MagicStrings()
1616
// Option lists that are currently used in LF (as of 2016-03-01)
1717
{ LfOptionListCodeForGrammaticalInfo, "Part of Speech" },
1818
{ LfOptionListCodeForSemanticDomains, "Semantic Domain" },
19+
{ LfOptionListCodeForLfTags, "LF Tags" },
1920
{ LfOptionListCodeForAcademicDomainTypes, "Academic Domains" },
2021
{ LfOptionListCodeForEnvironments, "Environments" },
2122
{ LfOptionListCodeForLocations, "Location" },
@@ -44,6 +45,7 @@ static MagicStrings()
4445
// Option lists that are currently used in LF (as of 2016-03-01)
4546
public const string LfOptionListCodeForGrammaticalInfo = "grammatical-info";
4647
public const string LfOptionListCodeForSemanticDomains = "semantic-domain-ddp4";
48+
public const string LfOptionListCodeForLfTags = "lf-entry-tags";
4749
public const string LfOptionListCodeForAcademicDomainTypes = "domain-type";
4850
public const string LfOptionListCodeForEnvironments = "environments";
4951
public const string LfOptionListCodeForLocations = "location";

0 commit comments

Comments
 (0)