Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(On hold) Handle new "tags" field in Language Forge #142

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
237 changes: 237 additions & 0 deletions data/canonical-lf-tags.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
<?xml version="1.0" encoding="utf-8"?>
<LfTagList>
<item type="category" id="star" guid="6dd9aa6b-de10-459e-b563-f50e8a7b9da0">
<abbrev ws="en">★</abbrev>
<abbrev ws="es">★</abbrev>
<abbrev ws="fr">★</abbrev>
<abbrev ws="zh-CN">★</abbrev>
<abbrev ws="ko">★</abbrev>
<abbrev ws="fa">★</abbrev>
<abbrev ws="ru">★</abbrev>
<abbrev ws="id">★</abbrev>
<term ws="en">star</term>
<term ws="es"/>
<term ws="fr">étoile</term>
<term ws="zh-CN"/>
<term ws="ko"/>
<term ws="fa"/>
<term ws="ru"/>
<term ws="id"/>
<def ws="en"/>
<def ws="es"/>
<def ws="fr"/>
<def ws="zh-CN"/>
<def ws="ko"/>
<def ws="fa"/>
<def ws="ru"/>
<def ws="id"/>
</item>
<item type="category" id="red" guid="75c8515d-3f21-4141-99d0-ac8ecca06e1b">
<abbrev ws="en">red</abbrev>
<abbrev ws="es"/>
<abbrev ws="fr">rouge</abbrev>
<abbrev ws="zh-CN"/>
<abbrev ws="ko"/>
<abbrev ws="fa"/>
<abbrev ws="ru"/>
<abbrev ws="id"/>
<term ws="en">red</term>
<term ws="es"/>
<term ws="fr">rouge</term>
<term ws="zh-CN"/>
<term ws="ko"/>
<term ws="fa"/>
<term ws="ru"/>
<term ws="id"/>
<def ws="en"/>
<def ws="es"/>
<def ws="fr"/>
<def ws="zh-CN"/>
<def ws="ko"/>
<def ws="fa"/>
<def ws="ru"/>
<def ws="id"/>
</item>
<item type="category" id="yellow" guid="acf6a418-fb50-4144-a1c7-44d1415f8743">
<abbrev ws="en">yellow</abbrev>
<abbrev ws="es"/>
<abbrev ws="fr">jaune</abbrev>
<abbrev ws="zh-CN"/>
<abbrev ws="ko"/>
<abbrev ws="fa"/>
<abbrev ws="ru"/>
<abbrev ws="id"/>
<term ws="en">yellow</term>
<term ws="es"/>
<term ws="fr">jaune</term>
<term ws="zh-CN"/>
<term ws="ko"/>
<term ws="fa"/>
<term ws="ru"/>
<term ws="id"/>
<def ws="en"/>
<def ws="es"/>
<def ws="fr"/>
<def ws="zh-CN"/>
<def ws="ko"/>
<def ws="fa"/>
<def ws="ru"/>
<def ws="id"/>
</item>
<item type="category" id="green" guid="7e440bb3-e3e8-4066-b740-20584cab8598">
<abbrev ws="en">green</abbrev>
<abbrev ws="es"/>
<abbrev ws="fr">vert</abbrev>
<abbrev ws="zh-CN"/>
<abbrev ws="ko"/>
<abbrev ws="fa"/>
<abbrev ws="ru"/>
<abbrev ws="id"/>
<term ws="en">green</term>
<term ws="es"/>
<term ws="fr">vert</term>
<term ws="zh-CN"/>
<term ws="ko"/>
<term ws="fa"/>
<term ws="ru"/>
<term ws="id"/>
<def ws="en"/>
<def ws="es"/>
<def ws="fr"/>
<def ws="zh-CN"/>
<def ws="ko"/>
<def ws="fa"/>
<def ws="ru"/>
<def ws="id"/>
</item>
<item type="category" id="blue" guid="660b6299-8eab-41f6-a1f6-b2b5b0f5a9b3">
<abbrev ws="en">blue</abbrev>
<abbrev ws="es"/>
<abbrev ws="fr">bleu</abbrev>
<abbrev ws="zh-CN"/>
<abbrev ws="ko"/>
<abbrev ws="fa"/>
<abbrev ws="ru"/>
<abbrev ws="id"/>
<term ws="en">blue</term>
<term ws="es"/>
<term ws="fr">bleu</term>
<term ws="zh-CN"/>
<term ws="ko"/>
<term ws="fa"/>
<term ws="ru"/>
<term ws="id"/>
<def ws="en"/>
<def ws="es"/>
<def ws="fr"/>
<def ws="zh-CN"/>
<def ws="ko"/>
<def ws="fa"/>
<def ws="ru"/>
<def ws="id"/>
</item>
<item type="category" id="purple" guid="b7b36374-a833-4376-984d-51ca9c08ec73">
<abbrev ws="en">purple</abbrev>
<abbrev ws="es"/>
<abbrev ws="fr">violet</abbrev>
<abbrev ws="zh-CN"/>
<abbrev ws="ko"/>
<abbrev ws="fa"/>
<abbrev ws="ru"/>
<abbrev ws="id"/>
<term ws="en">purple</term>
<term ws="es"/>
<term ws="fr">violet</term>
<term ws="zh-CN"/>
<term ws="ko"/>
<term ws="fa"/>
<term ws="ru"/>
<term ws="id"/>
<def ws="en"/>
<def ws="es"/>
<def ws="fr"/>
<def ws="zh-CN"/>
<def ws="ko"/>
<def ws="fa"/>
<def ws="ru"/>
<def ws="id"/>
</item>
<item type="category" id="brown" guid="5c01207f-7b89-4a0e-ab3f-8980344c46ab">
<abbrev ws="en">brown</abbrev>
<abbrev ws="es"/>
<abbrev ws="fr">marron</abbrev>
<abbrev ws="zh-CN"/>
<abbrev ws="ko"/>
<abbrev ws="fa"/>
<abbrev ws="ru"/>
<abbrev ws="id"/>
<term ws="en">brown</term>
<term ws="es"/>
<term ws="fr">marron</term>
<term ws="zh-CN"/>
<term ws="ko"/>
<term ws="fa"/>
<term ws="ru"/>
<term ws="id"/>
<def ws="en"/>
<def ws="es"/>
<def ws="fr"/>
<def ws="zh-CN"/>
<def ws="ko"/>
<def ws="fa"/>
<def ws="ru"/>
<def ws="id"/>
</item>
<item type="category" id="lightgray" guid="be6ec356-37c1-40a4-8adf-605c93bf2022">
<abbrev ws="en">lt. gray</abbrev>
<abbrev ws="es"/>
<abbrev ws="fr">gris cl.</abbrev>
<abbrev ws="zh-CN"/>
<abbrev ws="ko"/>
<abbrev ws="fa"/>
<abbrev ws="ru"/>
<abbrev ws="id"/>
<term ws="en">light gray</term>
<term ws="es"/>
<term ws="fr">gris clair</term>
<term ws="zh-CN"/>
<term ws="ko"/>
<term ws="fa"/>
<term ws="ru"/>
<term ws="id"/>
<def ws="en"/>
<def ws="es"/>
<def ws="fr"/>
<def ws="zh-CN"/>
<def ws="ko"/>
<def ws="fa"/>
<def ws="ru"/>
<def ws="id"/>
</item>
<item type="category" id="darkgray" guid="47fdcf50-7594-4318-a83d-b4df294903c2">
<abbrev ws="en">dk. gray</abbrev>
<abbrev ws="es"/>
<abbrev ws="fr">gris f.</abbrev>
<abbrev ws="zh-CN"/>
<abbrev ws="ko"/>
<abbrev ws="fa"/>
<abbrev ws="ru"/>
<abbrev ws="id"/>
<term ws="en">dark gray</term>
<term ws="es"/>
<term ws="fr">gris foncé</term>
<term ws="zh-CN"/>
<term ws="ko"/>
<term ws="fa"/>
<term ws="ru"/>
<term ws="id"/>
<def ws="en"/>
<def ws="es"/>
<def ws="fr"/>
<def ws="zh-CN"/>
<def ws="ko"/>
<def ws="fa"/>
<def ws="ru"/>
<def ws="id"/>
</item>
</LfTagList>
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public CanonicalItem()
ExtraData = new Dictionary<string, object>();
}

public override string ToString()
{
return $"{Key} ({GuidStr})";
}

/// <summary>
/// Given an XmlReader positioned on this node's XML representation, populate its names, abbrevs, etc. from the XML.
/// After running PopulateFromXml, the reader should be positioned just past this node's closing element.
Expand Down
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,42 @@
// Copyright (c) 2016 SIL International
// This software is licensed under the MIT license (http://opensource.org/licenses/MIT)

using LfMerge.Core.FieldWorks;
using SIL.LCModel;
using System.Collections.Generic;

namespace LfMerge.Core.DataConverters.CanonicalSources
{
public class CanonicalLfTagSource : CanonicalOptionListSource
{
public CanonicalLfTagSource()
: base("canonical-lf-tags.xml", "item")
{
}

public override void LoadCanonicalData()
{
LoadCanonicalData<CanonicalLfTagItem>();
}

public ICmPossibilityList EnsureLcmPossibilityListExists(FwServiceLocatorCache serviceLocator, System.Guid parentListGuid, string listName, int wsForKeys) {
if (byKey.Count == 0) {
LoadCanonicalData();
}
var repo = serviceLocator.GetInstance<ICmPossibilityListRepository>();
var listFactory = serviceLocator.GetInstance<ICmPossibilityListFactory>();
var guid = new System.Guid(MagicStrings.LcmOptionListGuidForLfTags);
ICmPossibilityList possList;
if (!repo.TryGetObject(guid, out possList)) {
possList = listFactory.CreateUnowned(guid, MagicStrings.LcmCustomFieldNameForLfTags, wsForKeys);
}
var converter = new ConvertMongoToLcmOptionList(serviceLocator.GetInstance<ICmPossibilityRepository>(), null, null, possList, wsForKeys, this);
foreach (KeyValuePair<string,CanonicalItem> item in this.byKey)
{
converter.FindOrCreateFromCanonicalItem(item.Value);
}
// TODO: Write acceptance test that verifies that a CmPossibilityList with the right GUID gets created and populated.
return possList;
}
}
}
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 Expand Up @@ -71,6 +73,10 @@ public bool TryGetByKey(string key, out CanonicalItem result)
return (result != null);
}

public Dictionary<Guid, CanonicalItem>.ValueCollection ValuesByGuid => this.byGuid.Values;
public Dictionary<string, CanonicalItem>.ValueCollection ValuesByKey => this.byKey.Values;
public int Count => this.byGuid.Count;

// Descendants will override this to specify the generic type T.
// E.g., LoadCanonicalData<CanonicalPartOfSpeechItem>();
public abstract void LoadCanonicalData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,15 @@ Dictionary<string, string> lfCustomFieldTypes
/// <param name="objectType">Either "entry", "senses", or "examples"</param>
/// <param name="listConverters">Dictionary of ConvertLcmToMongoOptionList instances, keyed by list code</param>
public BsonDocument GetCustomFieldsForThisCmObject(ICmObject cmObj, string objectType,
IDictionary<string, ConvertLcmToMongoOptionList> listConverters)
IDictionary<string, ConvertLcmToMongoOptionList> listConverters,
params string[] fieldNamesToSkip)
{
if (cmObj == null) return null;

List<int> customFieldIds = new List<int>(
LcmMetaData.GetFields(cmObj.ClassID, false, (int)CellarPropertyTypeFilter.All)
.Where(flid => cache.GetIsCustomField(flid)));
.Where(flid => cache.GetIsCustomField(flid))
.Where(flid => !fieldNamesToSkip.Contains(LcmMetaData.GetFieldName(flid))));

var customFieldData = new BsonDocument();
var customFieldGuids = new BsonDocument();
Expand Down
Loading