Skip to content

Commit dd6900d

Browse files
authored
LT-22124: Fix Sense homographs in Lexical Relations (#437)
When getting a property value for a field on a ISenseOrEntry object, call the new method added to LCM that determines the specific object (Sense or Entry), and the specific field on that object, that should be queried to get the value. In this specific defect we are trying to get the HeadWordRef and the ISenseOrEntry is a LexSense. The specific field remains HeadWordRef, but the specific object we need to get the value from is the associated LexEntry. This is because the LexEntry adjusts the HeadWordRef based on the decorator, the LexSense does not.
1 parent c569ec8 commit dd6900d

2 files changed

Lines changed: 26 additions & 25 deletions

File tree

Src/xWorks/ConfiguredLcmGenerator.cs

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -682,50 +682,51 @@ private static IFragment GenerateContentForGroupingNode(object field, List<Confi
682682
}
683683

684684
/// <summary>
685-
/// Gets the value of the requested custom field associated with the fieldOwner object
685+
/// Gets the value of the requested field associated with the fieldOwner object
686686
/// </summary>
687-
/// <returns>true if the custom field was valid and false otherwise</returns>
688-
/// <remarks>propertyValue can be null if the custom field is valid but no value is stored for the owning object</remarks>
687+
/// <returns>true if the field was valid and false otherwise</returns>
688+
/// <remarks>propertyValue can be null if the field is valid but no value is stored for the owning object</remarks>
689689
private static bool GetPropValueForModelField(object fieldOwner, ConfigurableDictionaryNode config,
690-
LcmCache cache, ISilDataAccess decorator, string customFieldName, ref object propertyValue, string cfOwnerClassName = null)
690+
LcmCache cache, ISilDataAccess decorator, string fieldName, ref object propertyValue, string cfOwnerClassName = null)
691691
{
692-
var customFieldOwnerClassName = cfOwnerClassName;
692+
var fieldOwnerClassName = cfOwnerClassName;
693+
var specificFieldName = fieldName;
693694
ICmObject specificObject;
694695
if (fieldOwner is ISenseOrEntry senseOrEntry)
695696
{
696-
// assign the customFieldOwnerClassName if it was not passed in
697-
customFieldOwnerClassName = customFieldOwnerClassName ?? senseOrEntry.Item.ClassName;
698-
specificObject = senseOrEntry.Item;
697+
senseOrEntry.SpecificItemAndFieldName(fieldName, out specificObject, out specificFieldName);
699698
}
700699
else if(fieldOwner is ICmObject owner)
701700
{
702701
specificObject = owner;
703-
// assign the customFieldOwnerClassName if it was not passed in
704-
customFieldOwnerClassName = customFieldOwnerClassName ?? specificObject.ClassName;
705702
senseOrEntry = null;
706703
}
707704
else
708705
{
709706
// throw an argument exception if the field owner is not a valid type
710707
throw new ArgumentException("The field owner is not a valid type", nameof(fieldOwner));
711708
}
709+
710+
// assign the fieldOwnerClassName if it was not passed in
711+
fieldOwnerClassName = fieldOwnerClassName ?? specificObject.ClassName;
712+
712713
if (decorator == null)
713714
decorator = cache.DomainDataByFlid;
714-
int customFieldFlid = GetCustomFieldFlid(config, cache, customFieldOwnerClassName, customFieldName);
715-
if (customFieldFlid == 0)
715+
int fieldFlid = GetCustomFieldFlid(config, cache, fieldOwnerClassName, specificFieldName);
716+
if (fieldFlid == 0)
716717
return false;
717718

718-
var customFieldType = cache.MetaDataCacheAccessor.GetFieldType(customFieldFlid);
719+
var fieldType = cache.MetaDataCacheAccessor.GetFieldType(fieldFlid);
719720
if (senseOrEntry != null)
720721
{
721-
if (!((IFwMetaDataCacheManaged)cache.MetaDataCacheAccessor).GetFields(senseOrEntry.Item.ClassID,
722-
true, (int)CellarPropertyTypeFilter.All).Contains(customFieldFlid))
722+
if (!((IFwMetaDataCacheManaged)cache.MetaDataCacheAccessor).GetFields(specificObject.ClassID,
723+
true, (int)CellarPropertyTypeFilter.All).Contains(fieldFlid))
723724
{
724725
return false;
725726
}
726727
}
727728

728-
switch (customFieldType)
729+
switch (fieldType)
729730
{
730731
case (int)CellarPropertyType.ReferenceCollection:
731732
case (int)CellarPropertyType.OwningCollection:
@@ -735,11 +736,11 @@ private static bool GetPropValueForModelField(object fieldOwner, ConfigurableDic
735736
{
736737
var sda = decorator;
737738
// This method returns the hvo of the object pointed to
738-
var chvo = sda.get_VecSize(specificObject.Hvo, customFieldFlid);
739+
var chvo = sda.get_VecSize(specificObject.Hvo, fieldFlid);
739740
int[] contents;
740741
using (var arrayPtr = MarshalEx.ArrayToNative<int>(chvo))
741742
{
742-
sda.VecProp(specificObject.Hvo, customFieldFlid, chvo, out chvo, arrayPtr);
743+
sda.VecProp(specificObject.Hvo, fieldFlid, chvo, out chvo, arrayPtr);
743744
contents = MarshalEx.NativeToArray<int>(arrayPtr, chvo);
744745
}
745746
// Convert the contents to IEnumerable<T>
@@ -763,36 +764,36 @@ private static bool GetPropValueForModelField(object fieldOwner, ConfigurableDic
763764
case (int)CellarPropertyType.OwningAtomic:
764765
{
765766
// This method returns the hvo of the object pointed to
766-
propertyValue = decorator.get_ObjectProp(specificObject.Hvo, customFieldFlid);
767+
propertyValue = decorator.get_ObjectProp(specificObject.Hvo, fieldFlid);
767768
// if the hvo is invalid set propertyValue to null otherwise get the object
768769
propertyValue = (int)propertyValue > 0 ? cache.LangProject.Services.GetObject((int)propertyValue) : null;
769770
break;
770771
}
771772
case (int)CellarPropertyType.GenDate:
772773
{
773-
propertyValue = new GenDate(decorator.get_IntProp(specificObject.Hvo, customFieldFlid));
774+
propertyValue = new GenDate(decorator.get_IntProp(specificObject.Hvo, fieldFlid));
774775
break;
775776
}
776777

777778
case (int)CellarPropertyType.Time:
778779
{
779-
propertyValue = SilTime.ConvertFromSilTime(decorator.get_TimeProp(specificObject.Hvo, customFieldFlid));
780+
propertyValue = SilTime.ConvertFromSilTime(decorator.get_TimeProp(specificObject.Hvo, fieldFlid));
780781
break;
781782
}
782783
case (int)CellarPropertyType.MultiUnicode:
783784
case (int)CellarPropertyType.MultiString:
784785
{
785-
propertyValue = decorator.get_MultiStringProp(specificObject.Hvo, customFieldFlid);
786+
propertyValue = decorator.get_MultiStringProp(specificObject.Hvo, fieldFlid);
786787
break;
787788
}
788789
case (int)CellarPropertyType.String:
789790
{
790-
propertyValue = decorator.get_StringProp(specificObject.Hvo, customFieldFlid);
791+
propertyValue = decorator.get_StringProp(specificObject.Hvo, fieldFlid);
791792
break;
792793
}
793794
case (int)CellarPropertyType.Integer:
794795
{
795-
propertyValue = decorator.get_IntProp(specificObject.Hvo, customFieldFlid);
796+
propertyValue = decorator.get_IntProp(specificObject.Hvo, fieldFlid);
796797
break;
797798
}
798799
}

Src/xWorks/DictionaryPublicationDecorator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ private string GetSenseNumber(ILexSense sense)
246246

247247
public override ITsMultiString get_MultiStringProp(int hvo, int tag)
248248
{
249-
if (tag == m_mlHeadwordFlid || tag == m_headwordRefFlid)
249+
if (tag == m_mlHeadwordFlid || tag == m_headwordRefFlid || tag == m_mlOwnerOutlineFlid)
250250
{
251251
return new PublicationAwareMultiStringAccessor(hvo, tag, this);
252252
}

0 commit comments

Comments
 (0)