-
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathOverridesLing_MoClasses.cs
More file actions
4811 lines (4454 loc) · 144 KB
/
Copy pathOverridesLing_MoClasses.cs
File metadata and controls
4811 lines (4454 loc) · 144 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) 2002-2017 SIL International
// This software is licensed under the LGPL, version 2.1 or later
// (http://www.gnu.org/licenses/lgpl-2.1.html)
//
// <remarks>
// This file holds the overrides of the generated classes for the Ling module.
// </remarks>
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Xml;
using SIL.Extensions;
using SIL.LCModel.Core.Cellar;
using SIL.LCModel.Core.KernelInterfaces;
using SIL.LCModel.Core.Text;
using SIL.LCModel.Core.WritingSystems;
using SIL.LCModel.DomainServices;
using SIL.LCModel.Infrastructure;
using SIL.LCModel.Infrastructure.Impl;
using SIL.LCModel.Utils;
namespace SIL.LCModel.DomainImpl
{
/// <summary></summary>
internal partial class MoMorphSynAnalysis
{
private int m_MLPartOfSpeechFlid;
private int m_MLInflectionClassFlid;
protected override void SetDefaultValuesAfterInit()
{
base.SetDefaultValuesAfterInit();
m_MLPartOfSpeechFlid = Cache.MetaDataCache.GetFieldId("MoMorphSynAnalysis", "MLPartOfSpeech", false);
m_MLInflectionClassFlid = Cache.MetaDataCache.GetFieldId("MoMorphSynAnalysis", "MLInflectionClass", false);
}
/// <summary>
/// Make the OwningEntry property available for views.
/// </summary>
[VirtualProperty(CellarPropertyType.ReferenceAtomic, "ILexEntry")]
public ILexEntry OwningEntry
{
get
{
return (ILexEntry)Owner;
}
}
/// <summary>
/// This method will be overridden in common subtypes (like MoStemMsa)
/// to use the TsIncStrBldr passed to it instead of creating another builder.
/// (See LT-13728 for performance issues.)
/// </summary>
/// <param name="tisb"></param>
internal virtual void AddChooserNameInItalics(ITsIncStrBldr tisb)
{
ITsStrBldr tsb = ChooserNameTS.GetBldr();
tsb.SetIntPropValues(0, tsb.Length, (int)FwTextPropType.ktptItalic,
(int)FwTextPropVar.ktpvEnum, (int)FwTextToggleVal.kttvForceOn);
tisb.AppendTsString(tsb.GetString());
}
/// <summary>
///
/// </summary>
[VirtualProperty(CellarPropertyType.String)]
public virtual ITsString FeaturesTSS
{
get
{ return TsStringUtils.EmptyString(Cache.DefaultAnalWs); }
}
/// <summary>
///
/// </summary>
[VirtualProperty(CellarPropertyType.String)]
public virtual ITsString ExceptionFeaturesTSS
{
get { return TsStringUtils.EmptyString(Cache.DefaultAnalWs); }
}
/// <summary>
/// Check whether the specified reference attribute HVO is valid for the
/// specified field.
/// </summary>
/// <param name="obj">The object.</param>
/// <param name="flid">the field ID</param>
/// <returns>true if the RA is valid, otherwise false</returns>
protected bool IsReferenceAttributeValid(ICmObject obj, int flid)
{
if (obj == null)
return true;
return ReferenceTargetCandidates(flid).Contains(obj);
}
/// <summary>
/// Need this version, because the ICmObjectInternal.RemoveObjectSideEffects version
/// can't be virtual, and we want subclasses to be able to override the method.
/// </summary>
protected override void RemoveObjectSideEffectsInternal(RemoveObjectEventArgs e)
{
if (e.Flid != MoMorphSynAnalysisTags.kflidComponents) return;
var gonerMsa = (IMoMorphSynAnalysis)e.ObjectRemoved;
if (gonerMsa.CanDelete)
((ILexEntry) Owner).MorphoSyntaxAnalysesOC.Remove(gonerMsa);
}
/// <summary>
/// Removes all invalid feature specifications from the given feature
/// structure.
/// </summary>
/// <param name="pos">the category to check for validity</param>
/// <param name="fs">the field structure</param>
protected void RemoveInvalidFeatureSpecs(IPartOfSpeech pos, IFsFeatStruc fs)
{
if (fs == null || pos == null)
return;
foreach (var spec in fs.FeatureSpecsOC)
{
if (!IsFeatureValid(pos, spec.FeatureRA))
{
fs.FeatureSpecsOC.Remove(spec);
}
}
}
/// <summary>
/// Checks if the specified feature definition is valid for the
/// specified category.
/// </summary>
/// <param name="pos">the category to check for validity</param>
/// <param name="fDefn">the feature definition</param>
/// <returns>true if the feature is valid, otherwise false</returns>
protected bool IsFeatureValid(IPartOfSpeech pos, IFsFeatDefn fDefn)
{
if (fDefn == null)
return false;
while (pos != null)
{
if (pos.InflectableFeatsRC.Contains(fDefn))
return true;
pos = pos.Owner as IPartOfSpeech; // May not cast to POS if it is the owning list.
}
return false;
}
/// <summary>
/// Get gloss of first sense that uses this msa
/// </summary>
/// <returns>the gloss as a string</returns>
public string GetGlossOfFirstSense()
{
return
(from sense in ((ILexEntry)Owner).SensesOS
where sense.MorphoSyntaxAnalysisRA == this
select sense.Gloss.AnalysisDefaultWritingSystem.Text)
.DefaultIfEmpty(Strings.ksQuestions).FirstOrDefault();
}
/// <summary>
/// Gets delete status for the object.
/// True means it can be deleted, otherwise false.
/// </summary>
public override bool CanDelete
{
get
{
return CanDeleteIfSenseDeleted(null);
}
}
/// <summary>
/// Gets delete status for the object.
/// True means it can be deleted if the given sense is deleted first, otherwise false.
/// </summary>
public bool CanDeleteIfSenseDeleted(ILexSense senseToDelete)
{
if (!base.CanDelete)
return false;
var servLoc = m_cache.ServiceLocator;
// If any surviving senses (which must belong to the same entry) refer to it, we can't delete it.
if (((ILexEntry) Owner).AllSenses.FirstOrDefault(
s => s.MorphoSyntaxAnalysisRA == this && (senseToDelete == null || s != senseToDelete)) != null)
{
return false;
}
var allMoMorphAdhocProhib = servLoc.GetInstance<IMoMorphAdhocProhibRepository>().AllInstances();
var mapCount = allMoMorphAdhocProhib.Where(map => map.FirstMorphemeRA == this
|| map.MorphemesRS.Contains(this)
|| map.RestOfMorphsRS.Contains(this)).Count();
if (mapCount > 0) return false;
int msaCount = servLoc.GetInstance<IMoMorphSynAnalysisRepository>().AllInstances().Count(msa => msa.ComponentsRS.Contains(this));
return msaCount < 1;
}
/// <summary>
/// Get a string used to to represent any MSA as a reference target.
/// </summary>
public virtual string InterlinearName
{
get { return Strings.ksProgError; }
}
/// <summary>
/// Abbreviated PartOfSpeech for Interlinear.
/// </summary>
public virtual string InterlinearAbbr
{
get { return InterlinearAbbrTSS.Text; }
}
/// <summary>
/// Check whether this MoMorphSynAnalysis object is empty of any content.
/// </summary>
[VirtualProperty(CellarPropertyType.Boolean)]
public virtual bool IsEmpty
{
get
{
return String.IsNullOrEmpty(GlossString) &&
this.GlossBundleRS.Count == 0 &&
this.ComponentsRS.Count == 0;
}
}
/// <summary>
/// Determines whether the specified Object is equal to the current MoStemMsa.
/// </summary>
/// <param name="msa">The MoStemMsa to compare with the current MoStemMsa.</param>
/// <returns>true if the specified MoStemMsa is equal to the current MoStemMsa; otherwise, false.</returns>
public abstract bool EqualsMsa(IMoMorphSynAnalysis msa);
/// <summary>
/// Determines whether the specified sandbox MSA is equal to the current MSA.
/// </summary>
/// <param name="msa">The MoStemMsa to compare with the current MoStemMsa.</param>
/// <returns>true if the specified MoStemMsa is equal to the current MoStemMsa; otherwise, false.</returns>
public abstract bool EqualsMsa(SandboxGenericMSA msa);
/// <summary>
/// Get a string used to to represent any MSA as a reference target to an environment with
/// no context that would otherwise tell you such things as what LexEntry this belongs to.
/// </summary>
public string LongName
{
get
{
return LongNameTs.Text;
}
}
/// <summary>
/// Get a TS string used to to represent any MSA in the MSADlgLauncherSlice slice.
/// </summary>
/// <remarks>
/// Subclasses must override this to get anything useful.
/// </remarks>
[VirtualProperty(CellarPropertyType.String)]
public abstract ITsString LongNameTs
{
get;
}
/// <summary>
/// Get a string used to to represent any MSA as a reference target.
/// </summary>
public override string ShortName
{
get
{
return this.GlossString;
}
}
/// <summary>
/// Get a string used to to represent any MSA as a reference target.
/// </summary>
public abstract ITsString InterlinearNameTSS
{
get;
}
/// <summary>
/// Return the Grammatical Info. (POS) TsString for the given writing system.
/// </summary>
/// <param name="wsAnal">If this is magic WS then return BestAnalorVern. Otherwise return the
/// string associated with the specific writing system.</param>
/// <returns>Abbreviated PartOfSpeech for Interlinear view.</returns>
public abstract ITsString InterlinAbbrTSS(int wsAnal);
/// <summary>
/// Abbreviated PartOfSpeech for Interlinear.
/// </summary>
public abstract ITsString InterlinearAbbrTSS
{
get;
}
/// <summary>
/// Get a TS string used to to represent any MSA in an ad hoc co-prohibition.
/// TODO (DamienD): register prop change when dependencies change
/// </summary>
[VirtualProperty(CellarPropertyType.String)]
public virtual ITsString LongNameAdHocTs
{
get
{
var tisb = TsStringUtils.MakeIncStrBldr();
tisb.AppendTsString(OwnerOfClass<ILexEntry>().HeadWord);
tisb.Append(" ");
tisb.AppendTsString(InterlinearNameTSS);
return tisb.GetString();
}
}
/// <summary>
/// Get a TS string used to to represent any MSA in an ad hoc co-prohibition.
/// </summary>
public string LongNameAdHoc
{
get
{
return LongNameAdHocTs.Text;
}
}
/// <summary>
/// Makes the target method accessible to XmlViews clients.
/// </summary>
[VirtualProperty(CellarPropertyType.MultiString)]
public ITsMultiString MLPartOfSpeech
{
get { return new VirtualStringAccessor(this, m_MLPartOfSpeechFlid, PartOfSpeechForWsTSS); }
}
/// <summary>
/// Makes the target method accessible to XmlViews clients.
/// </summary>
[VirtualProperty(CellarPropertyType.MultiString)]
public ITsMultiString MLInflectionClass
{
get { return new VirtualStringAccessor(this, m_MLInflectionClassFlid, InflectionClassForWsTSS); }
}
/// <summary>
/// Virtual method to give part of speech depending on type of MSA.
/// </summary>
/// <param name="ws"></param>
/// <returns></returns>
public virtual ITsString PartOfSpeechForWsTSS(int ws)
{
return TsStringUtils.EmptyString(ws);
}
/// <summary>
/// Virtual method to give Inflection Class on type of MSA.
/// </summary>
/// <param name="ws"></param>
/// <returns></returns>
public virtual ITsString InflectionClassForWsTSS(int ws)
{
return TsStringUtils.EmptyString(ws);
}
/// <summary>
/// Return the slot objects for the MSA. Always empty if not inflectional.
/// </summary>
[VirtualProperty(CellarPropertyType.ReferenceSequence, "MoInflAffixSlot")]
public virtual IEnumerable<IMoInflAffixSlot> Slots
{
get
{
return new IMoInflAffixSlot[0];
}
}
/// <summary>
/// Return the MorphType objects for the MSA.
/// </summary>
[VirtualProperty(CellarPropertyType.ReferenceSequence, "MoMorphType")]
public virtual IEnumerable<IMoMorphType> MorphTypes
{
get
{
return new IMoMorphType[0];
}
}
/// <summary>
/// Update an extant MSA to the new values in the sandbox MSA,
/// or make a new MSA with the values in the sandbox msa.
/// </summary>
/// <param name="sandboxMsa">The sandbox msa.</param>
/// <returns></returns>
/// <remarks>
/// Subclasses should override this method to do same-class updates,
/// but then call this method to handle class changing activities.
/// </remarks>
public virtual IMoMorphSynAnalysis UpdateOrReplace(SandboxGenericMSA sandboxMsa)
{
ILexEntry le = (ILexEntry)Owner;
foreach (MoMorphSynAnalysis msa in le.MorphoSyntaxAnalysesOC)
{
// Check other extant MSAs to see if they match the updated one.
if (msa != this && msa.EqualsMsa(sandboxMsa))
{
msa.MergeObject(this);
return msa;
}
}
// Make a new MSA.
IMoMorphSynAnalysis newMsa = null;
switch (sandboxMsa.MsaType)
{
default:
throw new ApplicationException("Cannot create any other kind of MSA here.");
case MsaType.kRoot: // Fall through.
case MsaType.kStem:
newMsa = Services.GetInstance<IMoStemMsaFactory>().Create(le, sandboxMsa);
break;
case MsaType.kDeriv:
newMsa = Services.GetInstance<IMoDerivAffMsaFactory>().Create(le, sandboxMsa);
break;
case MsaType.kInfl:
newMsa = Services.GetInstance<IMoInflAffMsaFactory>().Create(le, sandboxMsa);
break;
case MsaType.kUnclassified:
newMsa = Services.GetInstance<IMoUnclassifiedAffixMsaFactory>().Create(le, sandboxMsa);
break;
}
newMsa.SwitchReferences(this);
return newMsa;
}
/// <summary>
/// A name suitable for export into a pos field, like for use in ToolBox/LexiquePro/WeSay(via LIFT)
/// </summary>
public virtual string PosFieldName
{
get { return this.InterlinearName; }
}
/// <summary>
/// The LiftResidue field stores XML with an outer element <lift-residue> enclosing
/// the actual residue. This returns the actual residue, minus the outer element.
/// </summary>
public string LiftResidueContent
{
get
{
string sResidue = LiftResidue;
if (String.IsNullOrEmpty(sResidue))
return null;
if (sResidue.IndexOf("<lift-residue") != sResidue.LastIndexOf("<lift-residue"))
sResidue = RepairLiftResidue(sResidue);
return LexEntry.ExtractLiftResidueContent(sResidue);
}
}
private string RepairLiftResidue(string sResidue)
{
int idx = sResidue.IndexOf("</lift-residue>");
if (idx > 0)
{
// Remove the repeated occurrences of <lift-residue>...</lift-residue>.
// See LT-10302.
sResidue = sResidue.Substring(0, idx + 15);
LiftResidue = sResidue;
}
return sResidue;
}
/// <summary>
/// Get the dateCreated value stored in LiftResidue (if it exists).
/// </summary>
public string LiftDateCreated
{
get { return LexEntry.ExtractAttributeFromLiftResidue(LiftResidue, "dateCreated"); }
}
/// <summary>
/// Get the dateModified value stored in LiftResidue (if it exists).
/// </summary>
public string LiftDateModified
{
get { return LexEntry.ExtractAttributeFromLiftResidue(LiftResidue, "dateModified"); }
}
/// <summary>
/// Switches select inbound references from the sourceMsa to 'this'.
/// </summary>
public void SwitchReferences(IMoMorphSynAnalysis sourceMsa)
{
foreach (var obj in sourceMsa.ReferringObjects)
{
if (obj is IWfiMorphBundle wmb)
{
wmb.MsaRA = this;
}
else if (obj is ILexSense sense)
{
sense.MorphoSyntaxAnalysisRA = this;
}
else
{
// Alert programmers to need for more code.
Debug.Assert(obj is IWfiMorphBundle || obj is ILexSense);
}
}
}
}
/// <summary></summary>
internal partial class MoDerivAffMsa
{
/// <summary>
/// override to return our MorphTypes.
/// </summary>
public override IEnumerable<IMoMorphType> MorphTypes
{
get
{
return OwningEntry.MorphTypes;
}
}
/// <summary>
///
/// </summary>
public override ITsString FeaturesTSS
{
get
{
IFsFeatStruc featFrom = FromMsFeaturesOA;
IFsFeatStruc featTo = ToMsFeaturesOA;
if (featFrom != null || featTo != null)
{
ITsIncStrBldr tisb = TsStringUtils.MakeIncStrBldr();
if (featFrom != null)
tisb.AppendTsString(featFrom.ShortNameTSS);
else
tisb.AppendTsString(m_cache.MakeUserTss(Strings.ksQuestions));
tisb.AppendTsString(m_cache.MakeUserTss(" > "));
if (featTo != null)
tisb.AppendTsString(featTo.ShortNameTSS);
else
tisb.AppendTsString(m_cache.MakeUserTss(Strings.ksQuestions));
return tisb.GetString();
}
else
{
return base.FeaturesTSS;
}
}
}
/// <summary>
///
/// </summary>
public override ITsString ExceptionFeaturesTSS
{
get
{
ITsIncStrBldr tisb = TsStringUtils.MakeIncStrBldr();
if (FromProdRestrictRC.Count > 0)
{
bool fFirst = true;
foreach (CmPossibility pss in FromProdRestrictRC)
{
if (!fFirst)
tisb.AppendTsString(m_cache.MakeUserTss(","));
tisb.AppendTsString(pss.Abbreviation.BestAnalysisVernacularAlternative);
fFirst = false;
}
}
if (ToProdRestrictRC.Count > 0)
{
if (tisb.Text == null || tisb.Text.Length == 0)
tisb.AppendTsString(m_cache.MakeUserTss(Strings.ksQuestions));
tisb.AppendTsString(m_cache.MakeUserTss(" > "));
bool fFirst = true;
foreach (CmPossibility pss in ToProdRestrictRC)
{
if (!fFirst)
tisb.AppendTsString(m_cache.MakeUserTss(","));
tisb.AppendTsString(pss.Abbreviation.BestAnalysisVernacularAlternative);
fFirst = false;
}
}
else if (tisb.Text != null && tisb.Text.Length > 0)
{
tisb.AppendTsString(m_cache.MakeUserTss(String.Format(" > {0}", Strings.ksQuestions)));
}
else
{
tisb.AppendTsString(m_cache.MakeUserTss(""));
}
return tisb.GetString();
}
}
///<summary>
/// Copies attributes associated with the current "From" POS, such as inflection features and classes, that
/// are valid from the specified MSA to this MSA. If the attribute is not valid, it is removed from
/// this MSA.
///</summary>
///<param name="srcMsa">the source MSA</param>
public void CopyToAttributesIfValid(IMoDerivAffMsa srcMsa)
{
// inflection classes
if (IsReferenceAttributeValid(srcMsa.ToInflectionClassRA, MoDerivAffMsaTags.kflidToInflectionClass))
{
if (srcMsa.ToInflectionClassRA != ToInflectionClassRA)
ToInflectionClassRA = srcMsa.ToInflectionClassRA;
}
else if (ToInflectionClassRA != null)
{
ToInflectionClassRA = null;
}
// inflection features
if (srcMsa.ToMsFeaturesOA == null)
{
ToMsFeaturesOA = null;
}
else
{
if (ToMsFeaturesOA != srcMsa.ToMsFeaturesOA)
CopyObject<IFsFeatStruc>.CloneLcmObject(srcMsa.ToMsFeaturesOA, newMsa => ToMsFeaturesOA = newMsa);
RemoveInvalidFeatureSpecs(ToPartOfSpeechRA, ToMsFeaturesOA);
if (ToMsFeaturesOA.IsEmpty)
ToMsFeaturesOA = null;
}
}
///<summary>
/// Copies attributes associated with the current "To" POS, such as inflection features and classes, that
/// are valid from the specified MSA to this MSA. If the attribute is not valid, it is removed from
/// this MSA.
///</summary>
///<param name="srcMsa">the source MSA</param>
public void CopyFromAttributesIfValid(IMoDerivAffMsa srcMsa)
{
// inflection classes
if (IsReferenceAttributeValid(srcMsa.FromInflectionClassRA, (int)MoDerivAffMsaTags.kflidFromInflectionClass))
{
if (srcMsa.FromInflectionClassRA != FromInflectionClassRA)
FromInflectionClassRA = srcMsa.FromInflectionClassRA;
}
else if (FromInflectionClassRA != null)
{
FromInflectionClassRA = null;
}
// inflection features
if (srcMsa.FromMsFeaturesOA == null)
{
FromMsFeaturesOA = null;
}
else
{
if (FromMsFeaturesOA != srcMsa.FromMsFeaturesOA)
CopyObject<IFsFeatStruc>.CloneLcmObject(srcMsa.FromMsFeaturesOA, newMsa => FromMsFeaturesOA = newMsa);
RemoveInvalidFeatureSpecs(FromPartOfSpeechRA, FromMsFeaturesOA);
if (FromMsFeaturesOA.IsEmpty)
FromMsFeaturesOA = null;
}
// stem names
if (IsReferenceAttributeValid(srcMsa.FromStemNameRA, (int)MoDerivAffMsaTags.kflidFromStemName))
{
if (srcMsa.FromStemNameRA != FromStemNameRA)
FromStemNameRA = srcMsa.FromStemNameRA;
}
else if (FromStemNameRA != null)
{
FromStemNameRA = null;
}
}
/// <summary>
/// the way we want to show this in an interlinear view
/// </summary>
public override string InterlinearName
{
get { return InterlinearNameTSS.Text; }
}
/// <summary>
/// Check whether this MoDerivAffMsa is empty of content.
/// </summary>
[VirtualProperty(CellarPropertyType.Boolean)]
public override bool IsEmpty
{
get
{
return ToPartOfSpeechRA == null &&
FromPartOfSpeechRA == null &&
ToInflectionClassRA == null &&
FromInflectionClassRA == null &&
ToProdRestrictRC.Count == 0 &&
FromProdRestrictRC.Count == 0 &&
ToMsFeaturesOA == null &&
FromMsFeaturesOA == null &&
FromStemNameRA == null &&
AffixCategoryRA == null &&
StratumRA == null &&
base.IsEmpty;
}
}
/// <summary>
/// Determines whether the specified MoDerivAffMsa is equal to the current MoDerivAffMsa.
/// </summary>
/// <param name="msa">The MoDerivAffMsa to compare with the current MoDerivAffMsa.</param>
/// <returns>true if the specified MoDerivAffMsa is equal to the current MoDerivAffMsa; otherwise, false.</returns>
public override bool EqualsMsa(IMoMorphSynAnalysis msa)
{
// This is the behavior defined by Object.Equals().
if (msa == null)
return false;
// Make sure that we can cast this object to a MoDerivAffMsa.
if (!(msa is IMoDerivAffMsa))
return false;
var derivMsa = (IMoDerivAffMsa)msa;
return DomainObjectServices.AreEquivalent(FromMsFeaturesOA, derivMsa.FromMsFeaturesOA)
&& DomainObjectServices.AreEquivalent(ToMsFeaturesOA, derivMsa.ToMsFeaturesOA)
&& FromPartOfSpeechRA == derivMsa.FromPartOfSpeechRA
&& ToPartOfSpeechRA == derivMsa.ToPartOfSpeechRA
&& FromInflectionClassRA == derivMsa.FromInflectionClassRA
&& FromStemNameRA == derivMsa.FromStemNameRA
&& ToInflectionClassRA == derivMsa.ToInflectionClassRA
&& FromProdRestrictRC.IsEquivalent(derivMsa.FromProdRestrictRC)
&& ToProdRestrictRC.IsEquivalent(derivMsa.ToProdRestrictRC);
}
/// <summary>
/// Determines whether the specified Sandbox MSA is equal to the current MSA.
/// </summary>
/// <param name="msa">The MoDerivAffMsa to compare with the current MoDerivAffMsa.</param>
/// <returns>true if the specified MoDerivAffMsa is equal to the current MoDerivAffMsa; otherwise, false.</returns>
public override bool EqualsMsa(SandboxGenericMSA msa)
{
// This is the behavior defined by Object.Equals().
if (msa == null)
return false;
if (msa.MsaType != MsaType.kDeriv)
return false;
// Check the two properties we get from the DLG match, and the others we care about are missing.
return FromPartOfSpeechRA == msa.MainPOS
&& ToPartOfSpeechRA == msa.SecondaryPOS
&& FromInflectionClassRA == null
&& FromStemNameRA == null
&& ToInflectionClassRA == null
&& FromProdRestrictRC.Count == 0
&& ToProdRestrictRC.Count == 0
&& (ToMsFeaturesOA == null)
&& (FromMsFeaturesOA == null);
}
/// <summary>
/// Get a string used to to represent any MSA as a reference target.
/// </summary>
public override string ShortName
{
get { return InterlinearNameTSS.Text; }
}
/// <summary>
/// Get a TS string used to to represent any MSA in the MSADlgLauncherSlice slice.
/// </summary>
public override ITsString LongNameTs
{
get
{
string sMsaName = "";
if (FromPartOfSpeechRA != null && ToPartOfSpeechRA != null)
{
// Both are non-null.
if (FromPartOfSpeechRA == ToPartOfSpeechRA)
{
// Both are the same POS.
sMsaName = String.Format(Strings.ksAffixChangesX,
CmPossibility.BestAnalysisOrVernName(m_cache, FromPartOfSpeechRA).Text);
}
else
{
// Different POSes.
sMsaName = String.Format(Strings.ksAffixConvertsXtoY,
CmPossibility.BestAnalysisOrVernName(m_cache, FromPartOfSpeechRA).Text,
CmPossibility.BestAnalysisOrVernName(m_cache, ToPartOfSpeechRA).Text);
}
}
else
{
// One must be null. Both may be null.
if (FromPartOfSpeechRA == null && ToPartOfSpeechRA == null)
{
// Both are null.
sMsaName = Strings.ksAffixChangesAny;
}
else
{
if (FromPartOfSpeechRA == null)
{
// From POS is null.
sMsaName = String.Format(Strings.ksAffixConvertsAnyToX,
CmPossibility.BestAnalysisOrVernName(m_cache, ToPartOfSpeechRA).Text);
}
else
{
// To POS is null.
sMsaName = String.Format(Strings.ksAffixConvertsXtoAny,
CmPossibility.BestAnalysisOrVernName(m_cache, FromPartOfSpeechRA).Text);
}
}
}
return TsStringUtils.MakeString(
sMsaName,
m_cache.DefaultUserWs);
}
}
/// <summary>
/// The way we want to show this in an interlinear view
/// </summary>
public override ITsString InterlinearNameTSS
{
get
{
return InterlinearAffix(CmPossibility.BestAnalysisOrVernName(m_cache, FromPartOfSpeechRA, Strings.ksAny),
CmPossibility.BestAnalysisOrVernName(m_cache, ToPartOfSpeechRA, Strings.ksAny));
}
}
private ITsString InterlinearAffix(ITsString tssFromPartOfSpeech, ITsString tssToPartOfSpeech)
{
ITsIncStrBldr tisb = TsStringUtils.MakeIncStrBldr();
tisb.AppendTsString(tssFromPartOfSpeech);
tisb.AppendTsString(TsStringUtils.MakeString(">", m_cache.WritingSystemFactory.UserWs));
tisb.AppendTsString(tssToPartOfSpeech);
return tisb.GetString();
}
/// <summary>
/// Abbreviated PartOfSpeech for Interlinear.
/// </summary>
public override ITsString InterlinearAbbrTSS
{
get
{
return InterlinAbbrTSS(WritingSystemServices.kwsFirstAnalOrVern);
}
}
/// <summary>
/// Return the Grammatical Info. (POS) TsString for the given writing system.
/// </summary>
/// <param name="wsAnal">If this is magic WS then return BestAnalorVern. Otherwise return the
/// string associated with the specific writing system.</param>
/// <returns>Abbreviated PartOfSpeech for Interlinear view.</returns>
public override ITsString InterlinAbbrTSS(int wsAnal)
{
return InterlinearAffix(CmPossibility.TSSAbbrforWS(m_cache, FromPartOfSpeechRA, wsAnal),
CmPossibility.TSSAbbrforWS(m_cache, ToPartOfSpeechRA, wsAnal));
}
/// <summary>
/// Get a TsString suitable for use in a chooser.
/// </summary>
public override ITsString ChooserNameTS
{
get { return InterlinearNameTSS; }
}
/// <summary>
/// Get the part of speech ITsString for this MSA.
/// </summary>
/// <param name="ws"></param>
/// <returns>The part of speech abbreviation as a TsString for the given writing system,
/// or null if the part of speech is undefined.</returns>
public override ITsString PartOfSpeechForWsTSS(int ws)
{
var posFrom = FromPartOfSpeechRA;
var posTo = ToPartOfSpeechRA;
if (posFrom != null || posTo != null)
{
var tisb = TsStringUtils.MakeIncStrBldr();
if (posFrom != null)
{
var tssPOS = posFrom.Abbreviation.get_String(ws);
if (tssPOS == null || String.IsNullOrEmpty(tssPOS.Text))
tssPOS = posFrom.Abbreviation.BestAnalysisVernacularAlternative;
tisb.AppendTsString(tssPOS);
}
else
{
tisb.AppendTsString(m_cache.MakeUserTss(Strings.ksQuestions));
}
tisb.AppendTsString(m_cache.MakeUserTss(" > "));
if (posTo != null)
{
var tssPOS = posTo.Abbreviation.get_String(ws);
if (tssPOS == null || String.IsNullOrEmpty(tssPOS.Text))
tssPOS = posTo.Abbreviation.BestAnalysisVernacularAlternative;
tisb.AppendTsString(tssPOS);
}
else
{
tisb.AppendTsString(m_cache.MakeUserTss(Strings.ksQuestions));
}
return tisb.GetString();
}
return base.PartOfSpeechForWsTSS(ws);
}
/// <summary>
/// Get the inflection class ITsString for this MSA.
/// </summary>
/// <param name="ws"></param>
/// <returns>The inflection class abbreviation as a TsString for the given writing system,
/// or null if the inflection class is undefined.</returns>
/// Note. This is not really the right answer for MoDerivAffMsa. This, along with the POS produces
/// something like V>N(I>III), while what would really be desired is V(I)>N(III). There are actually
/// 5 From attributes that need to be nested together with desired order and decorations before the
/// wedge, and then followed by 4 To attributes again nested together with desired order and decorations.
/// This kind of change is going to require more massive changes to support.
public override ITsString InflectionClassForWsTSS(int ws)
{
var icFrom = FromInflectionClassRA;
var icTo = ToInflectionClassRA;
if (icFrom != null || icTo != null)
{
var tisb = TsStringUtils.MakeIncStrBldr();
if (icFrom != null)
{
var tssIC = icFrom.Abbreviation.get_String(ws);
if (tssIC == null || String.IsNullOrEmpty(tssIC.Text))
tssIC = icFrom.Abbreviation.BestAnalysisVernacularAlternative;
tisb.AppendTsString(tssIC);
}
else
{
tisb.AppendTsString(m_cache.MakeUserTss(Strings.ksQuestions));
}
tisb.AppendTsString(m_cache.MakeUserTss(" > "));
if (icTo != null)
{
var tssIC = icTo.Abbreviation.get_String(ws);
if (tssIC == null || String.IsNullOrEmpty(tssIC.Text))
tssIC = icTo.Abbreviation.BestAnalysisVernacularAlternative;
tisb.AppendTsString(tssIC);
}
else
{
tisb.AppendTsString(m_cache.MakeUserTss(Strings.ksQuestions));
}
return tisb.GetString();
}
return base.InflectionClassForWsTSS(ws);
}
partial void FromPartOfSpeechRASideEffects(IPartOfSpeech oldObjValue, IPartOfSpeech newObjValue)
{
if (oldObjValue != null && oldObjValue != newObjValue)
CopyFromAttributesIfValid(this);
}
partial void ToPartOfSpeechRASideEffects(IPartOfSpeech oldObjValue, IPartOfSpeech newObjValue)
{
if (oldObjValue != null && oldObjValue != newObjValue)
CopyToAttributesIfValid(this);
}
/// <summary>
/// Update an extant MSA to the new values in the sandbox MSA,
/// or make a new MSA with the values in the sandbox msa.
/// </summary>
/// <param name="sandboxMsa"></param>
/// <returns></returns>
public override IMoMorphSynAnalysis UpdateOrReplace(SandboxGenericMSA sandboxMsa)
{
if (sandboxMsa.MsaType == MsaType.kDeriv)
{
if (FromPartOfSpeechRA != sandboxMsa.MainPOS)