diff --git a/Src/LexText/ParserCore/HCLoader.cs b/Src/LexText/ParserCore/HCLoader.cs index 2ccbcde8fe..08b81ef8c8 100644 --- a/Src/LexText/ParserCore/HCLoader.cs +++ b/Src/LexText/ParserCore/HCLoader.cs @@ -2,26 +2,24 @@ // This software is licensed under the LGPL, version 2.1 or later // (http://www.gnu.org/licenses/lgpl-2.1.html) -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Globalization; -using System.Linq; -using System.Text; -using System.Xml; -using System.Xml.Linq; -using SIL.Collections; using SIL.Extensions; +using SIL.LCModel; using SIL.LCModel.Core.Phonology; using SIL.LCModel.Core.WritingSystems; -using SIL.LCModel; using SIL.Machine.Annotations; -using SIL.Machine.DataStructures; using SIL.Machine.FeatureModel; using SIL.Machine.Matching; using SIL.Machine.Morphology.HermitCrab; using SIL.Machine.Morphology.HermitCrab.MorphologicalRules; using SIL.Machine.Morphology.HermitCrab.PhonologicalRules; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Xml; +using System.Xml.Linq; namespace SIL.FieldWorks.WordWorks.Parser { @@ -86,9 +84,9 @@ private HCLoader(LcmCache cache, IHCLoadErrorLogger logger) XElement parserParamsElem = XElement.Parse(m_cache.LanguageProject.MorphologicalDataOA.ParserParameters); XElement hcElem = parserParamsElem.Element("HC"); - m_noDefaultCompounding = hcElem != null && ((bool?) hcElem.Element("NoDefaultCompounding") ?? false); - m_notOnClitics = hcElem == null || ((bool?) hcElem.Element("NotOnClitics") ?? true); - m_acceptUnspecifiedGraphemes = hcElem != null && ((bool?) hcElem.Element("AcceptUnspecifiedGraphemes") ?? false); + m_noDefaultCompounding = hcElem != null && ((bool?)hcElem.Element("NoDefaultCompounding") ?? false); + m_notOnClitics = hcElem == null || ((bool?)hcElem.Element("NotOnClitics") ?? true); + m_acceptUnspecifiedGraphemes = hcElem != null && ((bool?)hcElem.Element("AcceptUnspecifiedGraphemes") ?? false); m_naturalClasses = new Dictionary(); m_charDefs = new Dictionary(); @@ -96,26 +94,26 @@ private HCLoader(LcmCache cache, IHCLoadErrorLogger logger) private void LoadLanguage() { - m_language = new Language {Name = m_cache.ProjectId.Name}; + m_language = new Language { Name = m_cache.ProjectId.Name }; - var inflClassesGroup = new MprFeatureGroup {Name = "inflClasses", MatchType = MprFeatureGroupMatchType.Any}; + var inflClassesGroup = new MprFeatureGroup { Name = "inflClasses", MatchType = MprFeatureGroupMatchType.Any }; var posSymbols = new List(); foreach (IPartOfSpeech pos in m_cache.LanguageProject.AllPartsOfSpeech) { - posSymbols.Add(new FeatureSymbol("pos" + pos.Hvo) {Description = pos.Abbreviation.BestAnalysisAlternative.Text}); + posSymbols.Add(new FeatureSymbol("pos" + pos.Hvo) { Description = pos.Abbreviation.BestAnalysisAlternative.Text }); foreach (IMoInflClass inflClass in pos.InflectionClassesOC) LoadInflClassMprFeature(inflClass, inflClassesGroup); } if (inflClassesGroup.MprFeatures.Count > 0) m_language.MprFeatureGroups.Add(inflClassesGroup); - var prodRestrictsGroup = new MprFeatureGroup {Name = "exceptionFeatures", MatchType = MprFeatureGroupMatchType.All}; + var prodRestrictsGroup = new MprFeatureGroup { Name = "exceptionFeatures", MatchType = MprFeatureGroupMatchType.All }; foreach (ICmPossibility prodRestrict in m_cache.LanguageProject.MorphologicalDataOA.ProdRestrictOA.ReallyReallyAllPossibilities) LoadMprFeature(prodRestrict, prodRestrictsGroup); if (prodRestrictsGroup.MprFeatures.Count > 0) m_language.MprFeatureGroups.Add(prodRestrictsGroup); - var lexEntryInflTypesGroup = new MprFeatureGroup {Name = "lexEntryInflTypes", MatchType = MprFeatureGroupMatchType.All}; + var lexEntryInflTypesGroup = new MprFeatureGroup { Name = "lexEntryInflTypes", MatchType = MprFeatureGroupMatchType.All }; foreach (ILexEntryInflType inflType in m_cache.ServiceLocator.GetInstance().AllInstances()) LoadMprFeature(inflType, lexEntryInflTypesGroup); if (lexEntryInflTypesGroup.MprFeatures.Count > 0) @@ -127,7 +125,7 @@ private void LoadLanguage() LoadFeatureSystem(m_cache.LanguageProject.PhFeatureSystemOA, m_language.PhonologicalFeatureSystem); - var anyNC = new NaturalClass(FeatureStruct.New().Value) {Name = "Any"}; + var anyNC = new NaturalClass(FeatureStruct.New().Value) { Name = "Any" }; m_language.NaturalClasses.Add(anyNC); m_any = new SimpleContext(anyNC, Enumerable.Empty()); @@ -148,19 +146,19 @@ private void LoadLanguage() if (regions.Count > 0) { - var hcStemName = new StemName(regions) {Name = stemName.Name.BestAnalysisAlternative.Text}; + var hcStemName = new StemName(regions) { Name = stemName.Name.BestAnalysisAlternative.Text }; m_stemNames[stemName] = hcStemName; m_language.StemNames.Add(hcStemName); } } - m_morphophonemic = new Stratum(m_table) {Name = "Morphophonemic", MorphologicalRuleOrder = MorphologicalRuleOrder.Unordered}; + m_morphophonemic = new Stratum(m_table) { Name = "Morphophonemic", MorphologicalRuleOrder = MorphologicalRuleOrder.Unordered }; m_language.Strata.Add(m_morphophonemic); - m_clitic = new Stratum(m_table) {Name = "Clitic", MorphologicalRuleOrder = MorphologicalRuleOrder.Unordered}; + m_clitic = new Stratum(m_table) { Name = "Clitic", MorphologicalRuleOrder = MorphologicalRuleOrder.Unordered }; m_language.Strata.Add(m_clitic); - m_language.Strata.Add(new Stratum(m_table) {Name = "Surface"}); + m_language.Strata.Add(new Stratum(m_table) { Name = "Surface" }); if (m_cache.LanguageProject.MorphologicalDataOA.CompoundRulesOS.Count == 0 && !m_noDefaultCompounding) { @@ -173,11 +171,11 @@ private void LoadLanguage() switch (compoundRule.ClassID) { case MoEndoCompoundTags.kClassId: - m_morphophonemic.MorphologicalRules.Add(LoadEndoCompoundingRule((IMoEndoCompound) compoundRule)); + m_morphophonemic.MorphologicalRules.Add(LoadEndoCompoundingRule((IMoEndoCompound)compoundRule)); break; case MoExoCompoundTags.kClassId: - m_morphophonemic.MorphologicalRules.AddRange(LoadExoCompoundingRule((IMoExoCompound) compoundRule)); + m_morphophonemic.MorphologicalRules.AddRange(LoadExoCompoundingRule((IMoExoCompound)compoundRule)); break; } } @@ -198,9 +196,9 @@ private void LoadLanguage() if (IsValidLexEntryForm(form)) { if (IsCliticType(form.MorphTypeRA)) - cliticStemAllos.Add((IMoStemAllomorph) form); + cliticStemAllos.Add((IMoStemAllomorph)form); else - stemAllos.Add((IMoStemAllomorph) form); + stemAllos.Add((IMoStemAllomorph)form); } if (IsValidRuleForm(form)) @@ -234,7 +232,7 @@ private void LoadLanguage() switch (prule.ClassID) { case PhRegularRuleTags.kClassId: - var regRule = (IPhRegularRule) prule; + var regRule = (IPhRegularRule)prule; if (regRule.StrucDescOS.Count > 0 || regRule.RightHandSidesOS.Any(rhs => rhs.StrucChangeOS.Count > 0)) { RewriteRule hcRegRule = LoadRewriteRule(regRule); @@ -246,7 +244,7 @@ private void LoadLanguage() break; case PhMetathesisRuleTags.kClassId: - var metaRule = (IPhMetathesisRule) prule; + var metaRule = (IPhMetathesisRule)prule; if (metaRule.LeftSwitchIndex != -1 && metaRule.RightSwitchIndex != -1) { MetathesisRule hcMetaRule = LoadMetathesisRule(metaRule); @@ -323,12 +321,12 @@ private bool IsValidRuleForm(IMoForm form) case MoMorphTypeTags.kMorphSuffix: case MoMorphTypeTags.kMorphSuffixingInterfix: if (formStr.Contains("[") && !formStr.Contains("[...]")) - return ((IMoAffixAllomorph) form).PhoneEnvRC.Any(env => IsValidEnvironment(env.StringRepresentation.Text)); + return ((IMoAffixAllomorph)form).PhoneEnvRC.Any(env => IsValidEnvironment(env.StringRepresentation.Text)); return true; case MoMorphTypeTags.kMorphInfix: case MoMorphTypeTags.kMorphInfixingInterfix: - return ((IMoAffixAllomorph) form).PositionRS.Any(env => IsValidEnvironment(env.StringRepresentation.Text)); + return ((IMoAffixAllomorph)form).PositionRS.Any(env => IsValidEnvironment(env.StringRepresentation.Text)); } } @@ -408,8 +406,8 @@ private void LoadLexEntries(Stratum stratum, ILexEntry entry, IList contexts = SplitEnvironment(env); hcAllo.Environments.Add(new AllomorphEnvironment(ConstraintType.Require, LoadEnvironmentPattern(contexts.Item1, true), - LoadEnvironmentPattern(contexts.Item2, false)) { Name = env.StringRepresentation.Text }); + LoadEnvironmentPattern(contexts.Item2, false)) + { Name = env.StringRepresentation.Text }); } else { @@ -627,7 +626,7 @@ private void LoadMorphologicalRules(Stratum stratum, ILexEntry entry, IList 0) s = null; mrule = LoadInflAffixProcessRule(entry, inflMsa, allos); break; case MoUnclassifiedAffixMsaTags.kClassId: - mrule = LoadUnclassifiedAffixProcessRule(entry, (IMoUnclassifiedAffixMsa) msa, allos); + mrule = LoadUnclassifiedAffixProcessRule(entry, (IMoUnclassifiedAffixMsa)msa, allos); break; case MoStemMsaTags.kClassId: - mrule = LoadCliticAffixProcessRule(entry, (IMoStemMsa) msa, allos); + mrule = LoadCliticAffixProcessRule(entry, (IMoStemMsa)msa, allos); break; } @@ -689,7 +688,7 @@ private void AddMorphologicalRule(Stratum stratum, AffixProcessRule rule, IMoMor private AffixProcessRule LoadDerivAffixProcessRule(ILexEntry entry, IMoDerivAffMsa msa, IList allos) { - var mrule = new AffixProcessRule {Name = entry.ShortName}; + var mrule = new AffixProcessRule { Name = entry.ShortName }; var requiredFS = new FeatureStruct(); if (msa.FromPartOfSpeechRA != null) @@ -793,7 +792,7 @@ private AffixProcessRule LoadUnclassifiedAffixProcessRule(ILexEntry entry, IMoUn private AffixProcessRule LoadCliticAffixProcessRule(ILexEntry entry, IMoStemMsa msa, IList allos) { - var mrule = new AffixProcessRule {Name = entry.ShortName}; + var mrule = new AffixProcessRule { Name = entry.ShortName }; var requiredFS = new FeatureStruct(); if (msa.FromPartsOfSpeechRC.Count > 0) @@ -851,7 +850,7 @@ private IEnumerable LoadAffixProcessAllomorphs(IMoMorphSy switch (allo.ClassID) { case MoAffixProcessTags.kClassId: - var affixProcess = (IMoAffixProcess) allo; + var affixProcess = (IMoAffixProcess)allo; AffixProcessAllomorph hcAffixProcessAllo = null; try { @@ -873,7 +872,7 @@ private IEnumerable LoadAffixProcessAllomorphs(IMoMorphSy break; case MoAffixAllomorphTags.kClassId: - var affixAllo = (IMoAffixAllomorph) allo; + var affixAllo = (IMoAffixAllomorph)allo; MprFeature[] requiredMprFeatures = null; if (msa is IMoInflAffMsa) requiredMprFeatures = LoadAllInflClasses(affixAllo.InflectionClassesRC).ToArray(); @@ -906,7 +905,7 @@ private IEnumerable LoadAffixProcessAllomorphs(IMoMorphSy break; case MoStemAllomorphTags.kClassId: - var stemAllo = (IMoStemAllomorph) allo; + var stemAllo = (IMoStemAllomorph)allo; foreach (IPhEnvironment env in GetStemAllomorphEnvironments(stemAllo, msa)) { AffixProcessAllomorph hcStemAllo = null; @@ -998,8 +997,8 @@ private bool IsValidEnvironment(string env, out string error) try { XElement errorElem = XElement.Parse(m_envValidator.ErrorMessage); - var status = (string) errorElem.Attribute("status"); - var pos = (int) errorElem.Attribute("pos") + 1; + var status = (string)errorElem.Attribute("status"); + var pos = (int)errorElem.Attribute("pos") + 1; switch (status) { case "class": @@ -1083,7 +1082,7 @@ private AffixProcessAllomorph LoadCircumfixAffixProcessAllomorph(IMoAffixAllomor name = suffixEnv.StringRepresentation.Text; else name = string.Format("{0}, {1}", prefixEnv.StringRepresentation.Text, suffixEnv.StringRepresentation.Text); - hcAllo.Environments.Add(new AllomorphEnvironment(ConstraintType.Require, leftEnvPattern, rightEnvPattern) {Name = name}); + hcAllo.Environments.Add(new AllomorphEnvironment(ConstraintType.Require, leftEnvPattern, rightEnvPattern) { Name = name }); } hcAllo.Properties[HCParser.FormID] = prefixAllo.Hvo; @@ -1111,7 +1110,7 @@ private AffixProcessAllomorph LoadAffixProcessAllomorph(IMoAffixProcess allo) else { PatternNode n; - if (LoadPatternNode((IPhPhonContext) ctxtOrVar, out n)) + if (LoadPatternNode((IPhPhonContext)ctxtOrVar, out n)) { var pattern = new Pattern(i.ToString(CultureInfo.InvariantCulture), n); pattern.Freeze(); @@ -1130,7 +1129,7 @@ private AffixProcessAllomorph LoadAffixProcessAllomorph(IMoAffixProcess allo) switch (mapping.ClassID) { case MoInsertNCTags.kClassId: - var insertNC = (IMoInsertNC) mapping; + var insertNC = (IMoInsertNC)mapping; if (insertNC.ContentRA != null) { SimpleContext ctxt; @@ -1141,7 +1140,7 @@ private AffixProcessAllomorph LoadAffixProcessAllomorph(IMoAffixProcess allo) break; case MoCopyFromInputTags.kClassId: - var copyFromInput = (IMoCopyFromInput) mapping; + var copyFromInput = (IMoCopyFromInput)mapping; if (copyFromInput.ContentRA != null) { string partName = (copyFromInput.ContentRA.IndexInOwner + 1).ToString(CultureInfo.InvariantCulture); @@ -1150,7 +1149,7 @@ private AffixProcessAllomorph LoadAffixProcessAllomorph(IMoAffixProcess allo) break; case MoInsertPhonesTags.kClassId: - var insertPhones = (IMoInsertPhones) mapping; + var insertPhones = (IMoInsertPhones)mapping; if (insertPhones.ContentRS.Count > 0) { var sb = new StringBuilder(); @@ -1170,7 +1169,7 @@ private AffixProcessAllomorph LoadAffixProcessAllomorph(IMoAffixProcess allo) break; case MoModifyFromInputTags.kClassId: - var modifyFromInput = (IMoModifyFromInput) mapping; + var modifyFromInput = (IMoModifyFromInput)mapping; if (modifyFromInput.ContentRA != null && modifyFromInput.ModificationRA != null) { SimpleContext ctxt; @@ -1335,7 +1334,7 @@ private AffixProcessAllomorph LoadFormAffixProcessAllomorph(IMoForm allo, IPhEnv hcAllo.Rhs.Add(new InsertSegments(Segments("+" + form))); if (!string.IsNullOrEmpty(contexts.Item2)) - hcAllo.Environments.Add(new AllomorphEnvironment(ConstraintType.Require, null, LoadEnvironmentPattern(contexts.Item2, false)) {Name = env.StringRepresentation.Text}); + hcAllo.Environments.Add(new AllomorphEnvironment(ConstraintType.Require, null, LoadEnvironmentPattern(contexts.Item2, false)) { Name = env.StringRepresentation.Text }); break; case MoMorphTypeTags.kMorphPrefix: @@ -1362,7 +1361,7 @@ private AffixProcessAllomorph LoadFormAffixProcessAllomorph(IMoForm allo, IPhEnv hcAllo.Rhs.Add(new CopyFromInput("stem")); if (!string.IsNullOrEmpty(contexts.Item1)) - hcAllo.Environments.Add(new AllomorphEnvironment(ConstraintType.Require, LoadEnvironmentPattern(contexts.Item1, true), null) {Name = env.StringRepresentation.Text}); + hcAllo.Environments.Add(new AllomorphEnvironment(ConstraintType.Require, LoadEnvironmentPattern(contexts.Item1, true), null) { Name = env.StringRepresentation.Text }); break; } } @@ -1384,7 +1383,7 @@ private IEnumerable> LoadReduplicationPatterns(string p IPhNaturalClass naturalClass = m_naturalClassLookup[ncAbbr]; SimpleContext ctxt; TryLoadSimpleContext(naturalClass, out ctxt); - var pattern = new Pattern(XmlConvert.EncodeName(token.Substring(1, token.Length - 2).Trim()), new Constraint(ctxt.FeatureStruct) {Tag = ctxt}); + var pattern = new Pattern(XmlConvert.EncodeName(token.Substring(1, token.Length - 2).Trim()), new Constraint(ctxt.FeatureStruct) { Tag = ctxt }); pattern.Freeze(); yield return pattern; } @@ -1459,7 +1458,7 @@ private AffixTemplate LoadAffixTemplate(IMoInflAffixTemplate template, IList LoadExoCompoundingRule(IMoExoCompound compo nonheadPattern.Freeze(); var hcRightCompoundRule = new CompoundingRule - { - Name = compoundRule.Name.BestAnalysisAlternative.Text, - HeadRequiredSyntacticFeatureStruct = rightRequiredFS, - NonHeadRequiredSyntacticFeatureStruct = leftRequiredFS, - OutSyntacticFeatureStruct = outFS, - Properties = {{HCParser.CRuleID, compoundRule.Hvo}} - }; + { + Name = compoundRule.Name.BestAnalysisAlternative.Text, + HeadRequiredSyntacticFeatureStruct = rightRequiredFS, + NonHeadRequiredSyntacticFeatureStruct = leftRequiredFS, + OutSyntacticFeatureStruct = outFS, + Properties = { { HCParser.CRuleID, compoundRule.Hvo } } + }; var rightSubrule = new CompoundingSubrule(); @@ -1630,13 +1629,13 @@ private IEnumerable LoadExoCompoundingRule(IMoExoCompound compo yield return hcRightCompoundRule; var hcLeftCompoundRule = new CompoundingRule - { - Name = compoundRule.Name.BestAnalysisAlternative.Text, - HeadRequiredSyntacticFeatureStruct = leftRequiredFS, - NonHeadRequiredSyntacticFeatureStruct = rightRequiredFS, - OutSyntacticFeatureStruct = outFS, - Properties = {{HCParser.CRuleID, compoundRule.Hvo}} - }; + { + Name = compoundRule.Name.BestAnalysisAlternative.Text, + HeadRequiredSyntacticFeatureStruct = leftRequiredFS, + NonHeadRequiredSyntacticFeatureStruct = rightRequiredFS, + OutSyntacticFeatureStruct = outFS, + Properties = { { HCParser.CRuleID, compoundRule.Hvo } } + }; var leftSubrule = new CompoundingSubrule(); @@ -1665,7 +1664,7 @@ private RewriteRule LoadRewriteRule(IPhRegularRule prule) i++; } - var hcPrule = new RewriteRule {Name = prule.Name.BestAnalysisAlternative.Text}; + var hcPrule = new RewriteRule { Name = prule.Name.BestAnalysisAlternative.Text }; switch (prule.Direction) { @@ -1757,7 +1756,7 @@ private RewriteRule LoadRewriteRule(IPhRegularRule prule) private MetathesisRule LoadMetathesisRule(IPhMetathesisRule prule) { - var hcPrule = new MetathesisRule {Name = prule.Name.BestAnalysisAlternative.Text}; + var hcPrule = new MetathesisRule { Name = prule.Name.BestAnalysisAlternative.Text }; switch (prule.Direction) { @@ -1798,8 +1797,8 @@ private MetathesisRule LoadMetathesisRule(IPhMetathesisRule prule) name = "middle"; else { - // Need a unique, non-null name as Hermit Crab uses a dictionary with unique keys - // in AnalysisMetathesisRuleSpec() constructor + // Need a unique, non-null name as Hermit Crab uses a dictionary with unique keys + // in AnalysisMetathesisRuleSpec() constructor name = i.ToString(); } pattern.Children.Add(new Group(name, node)); @@ -1939,29 +1938,29 @@ private PatternNode PrefixNull() { return new Quantifier(0, -1, new Group( - new Constraint(m_null.FeatureStruct) {Tag = m_null}, - new Constraint(m_morphBdry.FeatureStruct) {Tag = m_morphBdry})); + new Constraint(m_null.FeatureStruct) { Tag = m_null }, + new Constraint(m_morphBdry.FeatureStruct) { Tag = m_morphBdry })); } private PatternNode SuffixNull() { return new Quantifier(0, -1, new Group( - new Constraint(m_morphBdry.FeatureStruct) {Tag = m_morphBdry}, - new Constraint(m_null.FeatureStruct) {Tag = m_null})); + new Constraint(m_morphBdry.FeatureStruct) { Tag = m_morphBdry }, + new Constraint(m_null.FeatureStruct) { Tag = m_null })); } private IEnumerable> AnyPlus() { yield return PrefixNull(); - yield return new Quantifier(1, -1, new Constraint(m_any.FeatureStruct) {Tag = m_any}); + yield return new Quantifier(1, -1, new Constraint(m_any.FeatureStruct) { Tag = m_any }); yield return SuffixNull(); } private IEnumerable> AnyStar() { yield return PrefixNull(); - yield return new Quantifier(0, -1, new Constraint(m_any.FeatureStruct) {Tag = m_any}); + yield return new Quantifier(0, -1, new Constraint(m_any.FeatureStruct) { Tag = m_any }); yield return SuffixNull(); } @@ -1975,7 +1974,7 @@ private bool LoadPatternNode(IPhPhonContext ctxt, Dictionary>(); foreach (IPhPhonContext member in seqCtxt.MembersRS) { @@ -1991,7 +1990,7 @@ private bool LoadPatternNode(IPhPhonContext ctxt, Dictionary childNode; if (LoadPatternNode(iterCtxt.MemberRA, variables, out childNode)) { @@ -2001,39 +2000,39 @@ private bool LoadPatternNode(IPhPhonContext ctxt, Dictionary(cd.FeatureStruct) {Tag = cd}; + node = new Constraint(cd.FeatureStruct) { Tag = cd }; return true; } } break; case PhSimpleContextSegTags.kClassId: - var segCtxt = (IPhSimpleContextSeg) ctxt; + var segCtxt = (IPhSimpleContextSeg)ctxt; IPhPhoneme phoneme = segCtxt.FeatureStructureRA; if (phoneme != null) { CharacterDefinition cd; if (m_charDefs.TryGetValue(phoneme, out cd)) { - node = new Constraint(cd.FeatureStruct) {Tag = cd}; + node = new Constraint(cd.FeatureStruct) { Tag = cd }; return true; } } break; case PhSimpleContextNCTags.kClassId: - var ncCtxt = (IPhSimpleContextNC) ctxt; + var ncCtxt = (IPhSimpleContextNC)ctxt; SimpleContext hcCtxt; if (TryLoadSimpleContext(ncCtxt, variables, out hcCtxt)) { - node = new Constraint(hcCtxt.FeatureStruct) {Tag = hcCtxt}; + node = new Constraint(hcCtxt.FeatureStruct) { Tag = hcCtxt }; return true; } break; @@ -2056,7 +2055,7 @@ private IEnumerable> LoadPatternNodes(string patter IPhNaturalClass nc = m_naturalClassLookup[token.Substring(1, token.Length - 2).Trim()]; SimpleContext ctxt; TryLoadSimpleContext(nc, out ctxt); - yield return new Constraint(ctxt.FeatureStruct) {Tag = ctxt}; + yield return new Constraint(ctxt.FeatureStruct) { Tag = ctxt }; break; case '(': @@ -2066,7 +2065,7 @@ private IEnumerable> LoadPatternNodes(string patter default: string representation = token.Trim(); Segments segments = Segments(representation); - yield return new Group(segments.Shape.Select(n => new Constraint(n.Annotation.FeatureStruct))) {Tag = segments}; + yield return new Group(segments.Shape.Select(n => new Constraint(n.Annotation.FeatureStruct))) { Tag = segments }; break; } } @@ -2169,9 +2168,9 @@ private FeatureStruct LoadFeatureStruct(IFsFeatStruc fs, FeatureSystem featSys) } else { - var complexValue = (IFsComplexValue) value; + var complexValue = (IFsComplexValue)value; var hcFeature = featSys.GetFeature("feat" + complexValue.FeatureRA.Hvo); - hcFS.AddValue(hcFeature, LoadFeatureStruct((IFsFeatStruc) complexValue.ValueOA, featSys)); + hcFS.AddValue(hcFeature, LoadFeatureStruct((IFsFeatStruc)complexValue.ValueOA, featSys)); } } } @@ -2252,7 +2251,7 @@ private IEnumerable LoadMprFeatures(IPhPhonRuleFeat ruleFeat) switch (ruleFeat.ItemRA.ClassID) { case MoInflClassTags.kClassId: - foreach (MprFeature mprFeat in LoadAllInflClasses((IMoInflClass) ruleFeat.ItemRA)) + foreach (MprFeature mprFeat in LoadAllInflClasses((IMoInflClass)ruleFeat.ItemRA)) yield return mprFeat; break; @@ -2295,12 +2294,12 @@ private static void LoadFeatureSystem(IFsFeatureSystem featSys, FeatureSystem hc if (closedFeature != null) { hcFeatSys.Add(new SymbolicFeature("feat" + closedFeature.Hvo, - closedFeature.ValuesOC.Select(sfv => new FeatureSymbol("sym" + sfv.Hvo) {Description = sfv.Abbreviation.BestAnalysisAlternative.Text})) + closedFeature.ValuesOC.Select(sfv => new FeatureSymbol("sym" + sfv.Hvo) { Description = sfv.Abbreviation.BestAnalysisAlternative.Text })) { Description = feature.Abbreviation.BestAnalysisAlternative.Text }); } else { - hcFeatSys.Add(new ComplexFeature("feat" + feature.Hvo) {Description = feature.Abbreviation.BestAnalysisAlternative.Text}); + hcFeatSys.Add(new ComplexFeature("feat" + feature.Hvo) { Description = feature.Abbreviation.BestAnalysisAlternative.Text }); } } hcFeatSys.Freeze(); @@ -2308,7 +2307,7 @@ private static void LoadFeatureSystem(IFsFeatureSystem featSys, FeatureSystem hc private void LoadCharacterDefinitionTable(IPhPhonemeSet phonemeSet) { - m_table = new CharacterDefinitionTable {Name = phonemeSet.Name.BestAnalysisAlternative.Text}; + m_table = new CharacterDefinitionTable { Name = phonemeSet.Name.BestAnalysisAlternative.Text }; foreach (IPhPhoneme phoneme in phonemeSet.PhonemesOC) { FeatureStruct fs = null; @@ -2345,7 +2344,7 @@ private void LoadCharacterDefinitionTable(IPhPhonemeSet phonemeSet) } } - m_null = m_table.AddBoundary(new[] {"^0", "*0", "&0", "∅"}); + m_null = m_table.AddBoundary(new[] { "^0", "*0", "&0", "∅" }); m_table.AddBoundary("."); m_morphBdry = m_table["+"]; @@ -2445,7 +2444,7 @@ private bool TryLoadNaturalClass(IPhNaturalClass naturalClass, out NaturalClass } else { - var featNC = (IPhNCFeatures) naturalClass; + var featNC = (IPhNCFeatures)naturalClass; FeatureStruct fs = LoadFeatureStruct(featNC.FeaturesOA, m_language.PhonologicalFeatureSystem); hcNaturalClass = new NaturalClass(fs); } diff --git a/Src/LexText/ParserCore/ParserCoreTests/HCLoaderTests.cs b/Src/LexText/ParserCore/ParserCoreTests/HCLoaderTests.cs index 43e0770597..e9c2adbe57 100644 --- a/Src/LexText/ParserCore/ParserCoreTests/HCLoaderTests.cs +++ b/Src/LexText/ParserCore/ParserCoreTests/HCLoaderTests.cs @@ -1266,16 +1266,22 @@ public void IrregularInflectionVariantWithNonemptyAffixTemplate() [Test] public void VariantStem() { - ILexEntry entry = AddEntry(MoMorphTypeTags.kguidMorphStem, "sag", "gloss", new SandboxGenericMSA {MsaType = MsaType.kStem, MainPOS = m_verb}); + ILexEntry entry = AddEntry(MoMorphTypeTags.kguidMorphStem, "sag", "gloss", new SandboxGenericMSA { MsaType = MsaType.kStem, MainPOS = m_verb }); ILexEntryInflType type = Cache.ServiceLocator.GetInstance().GetObject(LexEntryTypeTags.kguidLexTypPluralVar); type.GlossAppend.SetAnalysisDefaultWritingSystem(".pl"); type.InflFeatsOA = Cache.ServiceLocator.GetInstance().Create(); - CreateFeatStruc(Cache.LanguageProject.MsFeatureSystemOA, m_inflType, type.InflFeatsOA, new FS {{"nounAgr", new FS {{"num", "pl"}}}}); + CreateFeatStruc(Cache.LanguageProject.MsFeatureSystemOA, m_inflType, type.InflFeatsOA, new FS { { "nounAgr", new FS { { "num", "pl" } } } }); ILexEntryRef entryRef = entry.CreateVariantEntryAndBackRef(type, TsStringUtils.MakeString("sau", Cache.DefaultVernWs)); entryRef.VariantEntryTypesRS.Add(Cache.ServiceLocator.GetInstance().GetObject(LexEntryTypeTags.kguidLexTypFreeVar)); + + ILexEntryInflType type3 = Cache.ServiceLocator.GetInstance().GetObject(LexEntryTypeTags.kguidLexTypIrregInflectionVar); + type3.GlossAppend.SetAnalysisDefaultWritingSystem(".sg"); + type3.InflFeatsOA = Cache.ServiceLocator.GetInstance().Create(); + CreateFeatStruc(Cache.LanguageProject.MsFeatureSystemOA, m_inflType, type3.InflFeatsOA, new FS { { "nounAgr", new FS { { "num", "sg" } } } }); + ILexEntryRef entryRef3 = entry.CreateVariantEntryAndBackRef(type3, TsStringUtils.MakeString("sai", Cache.DefaultVernWs)); LoadLanguage(); - Assert.That(m_lang.Strata[0].Entries.Count, Is.EqualTo(3)); + Assert.That(m_lang.Strata[0].Entries.Count, Is.EqualTo(4)); LexEntry hcEntry = m_lang.Strata[0].Entries.ElementAt(0); Assert.That(hcEntry.Gloss, Is.EqualTo("gloss")); Assert.That(hcEntry.Allomorphs.Count, Is.EqualTo(1)); @@ -1286,7 +1292,7 @@ public void VariantStem() Assert.That(hcEntry.Allomorphs.Count, Is.EqualTo(1)); Assert.That(hcEntry.PrimaryAllomorph.Segments.ToString(), Is.EqualTo("sau")); Assert.That(hcEntry.SyntacticFeatureStruct.ToString(), Is.EqualTo("[Head:[nounAgr:[num:pl]], POS:V]")); - Assert.That(hcEntry.MprFeatures.Select(mf => mf.ToString()), Is.EquivalentTo(new[] {"Plural Variant"})); + Assert.That(hcEntry.MprFeatures.Select(mf => mf.ToString()), Is.EquivalentTo(new[] { "Plural Variant" })); hcEntry = m_lang.Strata[0].Entries.ElementAt(2); Assert.That(hcEntry.Gloss, Is.EqualTo("gloss")); @@ -1294,6 +1300,13 @@ public void VariantStem() Assert.That(hcEntry.PrimaryAllomorph.Segments.ToString(), Is.EqualTo("sau")); Assert.That(hcEntry.SyntacticFeatureStruct.ToString(), Is.EqualTo("[POS:V]")); Assert.That(hcEntry.MprFeatures, Is.Empty); + + hcEntry = m_lang.Strata[0].Entries.ElementAt(3); + Assert.That(hcEntry.Gloss, Is.EqualTo("gloss.sg")); + Assert.That(hcEntry.Allomorphs.Count, Is.EqualTo(1)); + Assert.That(hcEntry.PrimaryAllomorph.Segments.ToString(), Is.EqualTo("sai")); + Assert.That(hcEntry.SyntacticFeatureStruct.ToString(), Is.EqualTo("[Head:[nounAgr:[num:sg]], POS:V]")); + Assert.That(hcEntry.MprFeatures.Select(mf => mf.ToString()), Is.EquivalentTo(new[] { "Irregular Inflectional Variant" })); } [Test]