public override PatternNode<ComplexConcParagraphData, ShapeNode> GeneratePattern(FeatureSystem featSys) { var fs = new FeatureStruct(); var typeFeat = featSys.GetFeature<SymbolicFeature>("type"); fs.AddValue(typeFeat, typeFeat.PossibleSymbols["word"]); AddStringValue(featSys, fs, Form, "form"); AddStringValue(featSys, fs, Gloss, "gloss"); if (Category != null) { var catFeat = featSys.GetFeature<SymbolicFeature>("cat"); IEnumerable<FeatureSymbol> symbols = Category.ReallyReallyAllPossibilities.Concat(Category).Select(pos => catFeat.PossibleSymbols[pos.Hvo.ToString(CultureInfo.InvariantCulture)]); if (NegateCategory) symbols = catFeat.PossibleSymbols.Except(symbols); fs.AddValue(catFeat, symbols); } if (m_inflFeatures.Count > 0) { var inflFeat = featSys.GetFeature<ComplexFeature>("infl"); fs.AddValue(inflFeat, GetFeatureStruct(featSys, m_inflFeatures)); } var wordBdryFS = FeatureStruct.New(featSys).Symbol("bdry").Symbol("wordBdry").Value; var group = new Group<ComplexConcParagraphData, ShapeNode>(); group.Children.Add(new Quantifier<ComplexConcParagraphData, ShapeNode>(0, 1, new Constraint<ComplexConcParagraphData, ShapeNode>(wordBdryFS)) {IsGreedy = false}); group.Children.Add(new Constraint<ComplexConcParagraphData, ShapeNode>(fs)); group.Children.Add(new Quantifier<ComplexConcParagraphData, ShapeNode>(0, 1, new Constraint<ComplexConcParagraphData, ShapeNode>(wordBdryFS)) {IsGreedy = false}); return AddQuantifier(group); }
private static FeatureStruct GetFeatureStruct(FeatureSystem featSys, IFsFeatStruc fs) { var featStruct = new FeatureStruct(); foreach (IFsFeatureSpecification featSpec in fs.FeatureSpecsOC) { var complexVal = featSpec as IFsComplexValue; if (complexVal != null) { var cfs = complexVal.ValueOA as IFsFeatStruc; if (complexVal.FeatureRA != null && cfs != null && !cfs.IsEmpty) { featStruct.AddValue(featSys.GetFeature(complexVal.FeatureRA.Hvo.ToString(CultureInfo.InvariantCulture)), GetFeatureStruct(featSys, cfs)); } } else { var closedVal = featSpec as IFsClosedValue; if (closedVal != null && closedVal.FeatureRA != null) { var symFeat = featSys.GetFeature <SymbolicFeature>(closedVal.FeatureRA.Hvo.ToString(CultureInfo.InvariantCulture)); FeatureSymbol symbol; if (symFeat.PossibleSymbols.TryGetValue(closedVal.ValueRA.Hvo.ToString(CultureInfo.InvariantCulture), out symbol)) { featStruct.AddValue(symFeat, symbol); } } } } return(featStruct); }
public override PatternNode <ComplexConcParagraphData, ShapeNode> GeneratePattern(FeatureSystem featSys) { var fs = new FeatureStruct(); var typeFeat = featSys.GetFeature <SymbolicFeature>("type"); fs.AddValue(typeFeat, typeFeat.PossibleSymbols["morph"]); AddStringValue(featSys, fs, Form, "form"); AddStringValue(featSys, fs, Gloss, "gloss"); AddStringValue(featSys, fs, Entry, "entry"); if (Category != null) { var catFeat = featSys.GetFeature <SymbolicFeature>("cat"); IEnumerable <FeatureSymbol> symbols = Category.ReallyReallyAllPossibilities.Concat(Category).Select(pos => catFeat.PossibleSymbols[pos.Hvo.ToString(CultureInfo.InvariantCulture)]); if (NegateCategory) { symbols = catFeat.PossibleSymbols.Except(symbols); } fs.AddValue(catFeat, symbols); } if (m_inflFeatures.Count > 0) { var inflFeat = featSys.GetFeature <ComplexFeature>("infl"); fs.AddValue(inflFeat, GetFeatureStruct(featSys, m_inflFeatures)); } return(AddQuantifier(new Constraint <ComplexConcParagraphData, ShapeNode>(fs))); }
public override PatternNode<ComplexConcParagraphData, ShapeNode> GeneratePattern(FeatureSystem featSys) { var fs = new FeatureStruct(); var typeFeat = featSys.GetFeature<SymbolicFeature>("type"); fs.AddValue(typeFeat, typeFeat.PossibleSymbols["ttag"]); if (Tag != null) { var tagFeat = featSys.GetFeature<SymbolicFeature>("tag"); fs.AddValue(tagFeat, tagFeat.PossibleSymbols[Tag.Hvo.ToString(CultureInfo.InvariantCulture)]); } return AddQuantifier(new Constraint<ComplexConcParagraphData, ShapeNode>(fs)); }
public override PatternNode <ComplexConcParagraphData, ShapeNode> GeneratePattern(FeatureSystem featSys) { var fs = new FeatureStruct(); var typeFeat = featSys.GetFeature <SymbolicFeature>("type"); fs.AddValue(typeFeat, typeFeat.PossibleSymbols["ttag"]); if (Tag != null) { var tagFeat = featSys.GetFeature <SymbolicFeature>("tag"); fs.AddValue(tagFeat, tagFeat.PossibleSymbols[Tag.Hvo.ToString(CultureInfo.InvariantCulture)]); } return(AddQuantifier(new Constraint <ComplexConcParagraphData, ShapeNode>(fs))); }
/// <summary> /// Adds the character definition. /// </summary> private CharacterDefinition Add(IEnumerable <string> strReps, FeatureSymbol type, FeatureStruct fs) { string[] strRepsArray = strReps.ToArray(); string[] normalizedStrRepsArray = strRepsArray.Select(s => s.Normalize(NormalizationForm.FormD)).ToArray(); if (normalizedStrRepsArray.Any(s => _charDefLookup.ContainsKey(s))) { throw new ArgumentException( "The table already contains a character definition with one of the specified representations.", "strReps"); } if (fs == null) { fs = FeatureStruct.New().Symbol(type).Feature(HCFeatureSystem.StrRep) .EqualTo(normalizedStrRepsArray).Value; } else { fs.AddValue(HCFeatureSystem.Type, type); fs.Freeze(); } var cd = new CharacterDefinition(strRepsArray, fs); _charDefs.Add(cd); foreach (string rep in normalizedStrRepsArray) { _charDefLookup[rep] = cd; } cd.CharacterDefinitionTable = this; return(cd); }
protected void AddStringValue(FeatureSystem featSys, FeatureStruct fs, ITsString tss, string id) { if (tss != null) { var feat = featSys.GetFeature <StringFeature>(string.Format("{0}-{1}", id, tss.get_WritingSystemAt(0).ToString(CultureInfo.InvariantCulture))); fs.AddValue(feat, tss.Text); } }
public NaturalClass(FeatureStruct fs) { if (!fs.IsFrozen) { fs.AddValue(HCFeatureSystem.Type, HCFeatureSystem.Segment); fs.Freeze(); } FeatureStruct = fs; }
public SimpleContext(NaturalClass nc, IEnumerable<SymbolicFeatureValue> variables) { _nc = nc; _variables = new ReadOnlyCollection<SymbolicFeatureValue>(variables.ToArray()); _fs = _nc.FeatureStruct.DeepClone(); foreach (SymbolicFeatureValue var in _variables) _fs.AddValue(var.Feature, var); _fs.Freeze(); }
private void NewNaturalClass() { var vm = new EditNaturalClassViewModel(_projectService.Project.FeatureSystem, _soundClasses.Select(nc => nc.DomainSoundClass)); if (_dialogService.ShowModalDialog(this, vm) == true) { var fs = new FeatureStruct(); fs.AddValue(CogFeatureSystem.Type, vm.Type == SoundType.Consonant ? CogFeatureSystem.ConsonantType : CogFeatureSystem.VowelType); foreach (FeatureViewModel feature in vm.ActiveFeatures) { fs.AddValue(feature.DomainFeature, feature.SelectedValue.DomainSymbol); } var newNaturalClass = new SoundClassViewModel(new NaturalClass(vm.Name, fs), _displaySonority ? 0 : -1); IsChanged = true; _soundClasses.Add(newNaturalClass); SelectedSoundClass = newNaturalClass; } }
private static void AddValue(SymbolCollection symbols, Symbol symbol, FeatureSymbol value) { FeatureStruct fs = symbol.FeatureStruct.DeepClone(); fs.AddValue(value.Feature, value); fs.Freeze(); symbols.Remove(symbol); symbols.Add(symbol.StrRep, fs, symbol.Overwrite); }
private void AddSegDef(CharacterDefinitionTable table, FeatureSystem phoneticFeatSys, string strRep, params string[] symbols) { var fs = new FeatureStruct(); foreach (string symbolID in symbols) { FeatureSymbol symbol = phoneticFeatSys.GetSymbol(symbolID); fs.AddValue(symbol.Feature, new SymbolicFeatureValue(symbol)); } table.AddSegment(strRep, fs); }
public SimpleContext(NaturalClass nc, IEnumerable <SymbolicFeatureValue> variables) { _nc = nc; _variables = new ReadOnlyCollection <SymbolicFeatureValue>(variables.ToArray()); _fs = _nc.FeatureStruct.Clone(); foreach (SymbolicFeatureValue var in _variables) { _fs.AddValue(var.Feature, var); } _fs.Freeze(); }
private static FeatureStruct LoadFeatureStruct(FeatureSystem featSys, XElement elem) { var fs = new FeatureStruct(); foreach (XElement featureValueElem in elem.Elements(Cog + "FeatureValue")) { var feature = (SymbolicFeature)featSys.GetFeature((string)featureValueElem.Attribute("feature")); fs.AddValue(feature, ((string)featureValueElem.Attribute("value")).Split(' ').Select(featSys.GetSymbol)); } return(fs); }
private void EditSoundClass() { var currentNC = _selectedSoundClass.DomainSoundClass as NaturalClass; if (currentNC != null) { var vm = new EditNaturalClassViewModel(_projectService.Project.FeatureSystem, _soundClasses.Select(nc => nc.DomainSoundClass), currentNC); if (_dialogService.ShowModalDialog(this, vm) == true) { var fs = new FeatureStruct(); fs.AddValue(CogFeatureSystem.Type, vm.Type == SoundType.Consonant ? CogFeatureSystem.ConsonantType : CogFeatureSystem.VowelType); foreach (FeatureViewModel feature in vm.ActiveFeatures) { fs.AddValue(feature.DomainFeature, feature.SelectedValue.DomainSymbol); } var newNaturalClass = new SoundClassViewModel(new NaturalClass(vm.Name, fs), _selectedSoundClass.Sonority); int index = _soundClasses.IndexOf(_selectedSoundClass); IsChanged = true; _soundClasses[index] = newNaturalClass; SelectedSoundClass = newNaturalClass; } } else { var currentUnc = _selectedSoundClass.DomainSoundClass as UnnaturalClass; if (currentUnc != null) { var vm = new EditUnnaturalClassViewModel(_dialogService, _projectService.Project.Segmenter, _soundClasses.Select(nc => nc.DomainSoundClass), currentUnc); if (_dialogService.ShowModalDialog(this, vm) == true) { var newUnnaturalClass = new SoundClassViewModel(new UnnaturalClass(vm.Name, vm.Segments, vm.IgnoreModifiers, _projectService.Project.Segmenter), _selectedSoundClass.Sonority); int index = _soundClasses.IndexOf(_selectedSoundClass); IsChanged = true; _soundClasses[index] = newUnnaturalClass; SelectedSoundClass = newUnnaturalClass; } } } }
public override PatternNode <ComplexConcParagraphData, ShapeNode> GeneratePattern(FeatureSystem featSys) { var fs = new FeatureStruct(); var typeFeat = featSys.GetFeature <SymbolicFeature>("type"); fs.AddValue(typeFeat, typeFeat.PossibleSymbols["word"]); AddStringValue(featSys, fs, Form, "form"); AddStringValue(featSys, fs, Gloss, "gloss"); if (Category != null) { var catFeat = featSys.GetFeature <SymbolicFeature>("cat"); IEnumerable <FeatureSymbol> symbols = Category.ReallyReallyAllPossibilities.Concat(Category).Select(pos => catFeat.PossibleSymbols[pos.Hvo.ToString(CultureInfo.InvariantCulture)]); if (NegateCategory) { symbols = catFeat.PossibleSymbols.Except(symbols); } fs.AddValue(catFeat, symbols); } if (m_inflFeatures.Count > 0) { var inflFeat = featSys.GetFeature <ComplexFeature>("infl"); fs.AddValue(inflFeat, GetFeatureStruct(featSys, m_inflFeatures)); } var wordBdryFS = FeatureStruct.New(featSys).Symbol("bdry").Symbol("wordBdry").Value; var group = new Group <ComplexConcParagraphData, ShapeNode>(); group.Children.Add(new Quantifier <ComplexConcParagraphData, ShapeNode>(0, 1, new Constraint <ComplexConcParagraphData, ShapeNode>(wordBdryFS)) { IsGreedy = false }); group.Children.Add(new Constraint <ComplexConcParagraphData, ShapeNode>(fs)); group.Children.Add(new Quantifier <ComplexConcParagraphData, ShapeNode>(0, 1, new Constraint <ComplexConcParagraphData, ShapeNode>(wordBdryFS)) { IsGreedy = false }); return(AddQuantifier(group)); }
protected FeatureStruct GetFeatureStruct(FeatureSystem featSys, IDictionary <IFsFeatDefn, object> values) { var fs = new FeatureStruct(); foreach (KeyValuePair <IFsFeatDefn, object> kvp in values) { if (kvp.Key is IFsComplexFeature) { var childValues = (IDictionary <IFsFeatDefn, object>)kvp.Value; fs.AddValue(featSys.GetFeature(kvp.Key.Hvo.ToString(CultureInfo.InvariantCulture)), GetFeatureStruct(featSys, childValues)); } else if (kvp.Key is IFsClosedFeature) { var value = (ClosedFeatureValue)kvp.Value; var symFeat = featSys.GetFeature <SymbolicFeature>(kvp.Key.Hvo.ToString(CultureInfo.InvariantCulture)); FeatureSymbol symbol = symFeat.PossibleSymbols[value.Symbol.Hvo.ToString(CultureInfo.InvariantCulture)]; fs.AddValue(symFeat, value.Negate ? new SymbolicFeatureValue(symFeat.PossibleSymbols.Except(symbol.ToEnumerable())) : new SymbolicFeatureValue(symbol)); } } return(fs); }
public override PatternNode<ComplexConcParagraphData, ShapeNode> GeneratePattern(FeatureSystem featSys) { var fs = new FeatureStruct(); var typeFeat = featSys.GetFeature<SymbolicFeature>("type"); fs.AddValue(typeFeat, typeFeat.PossibleSymbols["morph"]); AddStringValue(featSys, fs, Form, "form"); AddStringValue(featSys, fs, Gloss, "gloss"); AddStringValue(featSys, fs, Entry, "entry"); if (Category != null) { var catFeat = featSys.GetFeature<SymbolicFeature>("cat"); IEnumerable<FeatureSymbol> symbols = Category.ReallyReallyAllPossibilities.Concat(Category).Select(pos => catFeat.PossibleSymbols[pos.Hvo.ToString(CultureInfo.InvariantCulture)]); if (NegateCategory) symbols = catFeat.PossibleSymbols.Except(symbols); fs.AddValue(catFeat, symbols); } if (m_inflFeatures.Count > 0) { var inflFeat = featSys.GetFeature<ComplexFeature>("infl"); fs.AddValue(inflFeat, GetFeatureStruct(featSys, m_inflFeatures)); } return AddQuantifier(new Constraint<ComplexConcParagraphData, ShapeNode>(fs)); }
public static void AddSymbolBasedOn(this SymbolCollection symbols, string strRep, string basedOnStrRep, params FeatureSymbol[] values) { Symbol basedOnSymbol; if (!symbols.Contains(strRep) && symbols.TryGetValue(basedOnStrRep, out basedOnSymbol)) { FeatureStruct fs = basedOnSymbol.FeatureStruct.DeepClone(); foreach (FeatureSymbol value in values) { fs.AddValue(value.Feature, value); } fs.Freeze(); symbols.Add(strRep, fs); } }
private void CombineWith(ShapeNode node, ShapeNode start, ShapeNode end) { if ((CombineVowels && node.Type() == CogFeatureSystem.VowelType) || (CombineConsonants && node.Type() == CogFeatureSystem.ConsonantType)) { var strRep = new StringBuilder(); var origStrRep = new StringBuilder(); strRep.Append(node.StrRep()); origStrRep.Append(node.OriginalStrRep()); ShapeNode n = start; while (n != end.Next) { strRep.Append(n.StrRep()); origStrRep.Append(n.OriginalStrRep()); node.Annotation.FeatureStruct.Add(n.Annotation.FeatureStruct); n = n.Next; } node.Annotation.FeatureStruct.AddValue(CogFeatureSystem.StrRep, strRep.ToString()); node.Annotation.FeatureStruct.AddValue(CogFeatureSystem.OriginalStrRep, origStrRep.ToString()); node.Annotation.FeatureStruct.AddValue(CogFeatureSystem.SegmentType, CogFeatureSystem.Complex); FeatureStruct firstFS; if (start.IsComplex()) { firstFS = start.Annotation.FeatureStruct.GetValue(CogFeatureSystem.First); } else { firstFS = new FeatureStruct(); foreach (Feature feature in start.Annotation.FeatureStruct.Features.Where(f => !CogFeatureSystem.Instance.ContainsFeature(f))) { firstFS.AddValue(feature, start.Annotation.FeatureStruct.GetValue(feature)); } } node.Annotation.FeatureStruct.AddValue(CogFeatureSystem.First, firstFS); } else { ShapeNode n = start; while (n != end.Next) { var newNode = n.Clone(); node.AddAfter(newNode); node = newNode; n = n.Next; } } }
public FeatureAnalysisRewriteRuleSpec(MatcherSettings <ShapeNode> matcherSettings, Pattern <Word, ShapeNode> lhs, RewriteSubrule subrule) : base(false) { var rhsAntiFSs = new List <FeatureStruct>(); foreach (Constraint <Word, ShapeNode> constraint in subrule.Rhs.Children .OfType <Constraint <Word, ShapeNode> >().Where(c => c.Type() == HCFeatureSystem.Segment)) { rhsAntiFSs.Add(constraint.FeatureStruct.AntiFeatureStruct()); } Pattern.Acceptable = match => IsUnapplicationNonvacuous(match, rhsAntiFSs); _analysisRhs = new Pattern <Word, ShapeNode>(); int i = 0; foreach (Tuple <PatternNode <Word, ShapeNode>, PatternNode <Word, ShapeNode> > tuple in lhs.Children .Zip(subrule.Rhs.Children)) { var lhsConstraint = (Constraint <Word, ShapeNode>)tuple.Item1; var rhsConstraint = (Constraint <Word, ShapeNode>)tuple.Item2; if (lhsConstraint.Type() == HCFeatureSystem.Segment && rhsConstraint.Type() == HCFeatureSystem.Segment) { Constraint <Word, ShapeNode> targetConstraint = lhsConstraint.Clone(); targetConstraint.FeatureStruct.PriorityUnion(rhsConstraint.FeatureStruct); targetConstraint.FeatureStruct.AddValue(HCFeatureSystem.Modified, HCFeatureSystem.Clean); Pattern.Children.Add(new Group <Word, ShapeNode>("target" + i) { Children = { targetConstraint } }); FeatureStruct fs = rhsConstraint.FeatureStruct.AntiFeatureStruct(); fs.Subtract(lhsConstraint.FeatureStruct.AntiFeatureStruct()); fs.AddValue(HCFeatureSystem.Type, HCFeatureSystem.Segment); _analysisRhs.Children.Add(new Constraint <Word, ShapeNode>(fs)); i++; } } Pattern.Freeze(); SubruleSpecs.Add(new AnalysisRewriteSubruleSpec(matcherSettings, subrule, Unapply)); }
internal static SoundClass LoadSoundClass(Segmenter segmenter, FeatureSystem featSys, XElement elem) { var name = (string)elem.Attribute("name"); if (elem.Name == Cog + "NaturalClass") { FeatureStruct fs = LoadFeatureStruct(featSys, elem); fs.AddValue(CogFeatureSystem.Type, ((string)elem.Attribute("type")) == "vowel" ? CogFeatureSystem.VowelType : CogFeatureSystem.ConsonantType); return(new NaturalClass(name, fs)); } if (elem.Name == Cog + "UnnaturalClass") { IEnumerable <string> segments = elem.Elements(Cog + "Segment").Select(segElem => (string)segElem); var ignoreModifiers = (bool?)elem.Attribute("ignoreModifiers") ?? false; return(new UnnaturalClass(name, segments, ignoreModifiers, segmenter)); } return(null); }
private bool Add(string[] strings, int id) { if (_lastFeature is StringFeature) { var value = new StringFeatureValue(strings, _not); _fs.AddValue(_lastFeature, value); _not = false; if (id > -1) { _ids[id] = value; } } else if (_lastFeature is SymbolicFeature) { if (!AddSymbols(_lastFeature, strings, id)) { return(false); } } return(true); }
internal static FeatureStruct AntiFeatureStruct(this FeatureStruct fs) { // TODO: handle reentrancy properly var result = new FeatureStruct(); foreach (Feature feature in fs.Features) { FeatureValue value = fs.GetValue(feature); var childFS = value as FeatureStruct; FeatureValue newValue; if (childFS != null) { newValue = HCFeatureSystem.Instance.ContainsFeature(feature) ? childFS.Clone() : childFS.AntiFeatureStruct(); } else { var childSfv = (SimpleFeatureValue)value; newValue = HCFeatureSystem.Instance.ContainsFeature(feature) ? childSfv.Clone() : childSfv.Negation(); } result.AddValue(feature, newValue); } return(result); }
private void EditSoundClass() { var currentNC = _selectedSoundClass.DomainSoundClass as NaturalClass; if (currentNC != null) { var vm = new EditNaturalClassViewModel(_projectService.Project.FeatureSystem, _soundClasses.Select(nc => nc.DomainSoundClass), currentNC); if (_dialogService.ShowModalDialog(this, vm) == true) { var fs = new FeatureStruct(); fs.AddValue(CogFeatureSystem.Type, vm.Type == SoundType.Consonant ? CogFeatureSystem.ConsonantType : CogFeatureSystem.VowelType); foreach (FeatureViewModel feature in vm.ActiveFeatures) fs.AddValue(feature.DomainFeature, feature.SelectedValue.DomainSymbol); var newNaturalClass = new SoundClassViewModel(new NaturalClass(vm.Name, fs), _selectedSoundClass.Sonority); int index = _soundClasses.IndexOf(_selectedSoundClass); IsChanged = true; _soundClasses[index] = newNaturalClass; SelectedSoundClass = newNaturalClass; } } else { var currentUnc = _selectedSoundClass.DomainSoundClass as UnnaturalClass; if (currentUnc != null) { var vm = new EditUnnaturalClassViewModel(_dialogService, _projectService.Project.Segmenter, _soundClasses.Select(nc => nc.DomainSoundClass), currentUnc); if (_dialogService.ShowModalDialog(this, vm) == true) { var newUnnaturalClass = new SoundClassViewModel(new UnnaturalClass(vm.Name, vm.Segments, vm.IgnoreModifiers, _projectService.Project.Segmenter), _selectedSoundClass.Sonority); int index = _soundClasses.IndexOf(_selectedSoundClass); IsChanged = true; _soundClasses[index] = newUnnaturalClass; SelectedSoundClass = newUnnaturalClass; } } } }
protected ShapeNode Combine(FeatureSymbol syllablePosition, Shape newShape, ShapeNode start, ShapeNode end) { ShapeNode newStart = null; if (start == end) { newStart = start.DeepClone(); newStart.Annotation.FeatureStruct.AddValue(CogFeatureSystem.SyllablePosition, syllablePosition); newShape.Add(newStart); } else if ((_combineVowels && syllablePosition == CogFeatureSystem.Nucleus) || (_combineConsonants && syllablePosition != CogFeatureSystem.Nucleus)) { var fs = start.Annotation.FeatureStruct.DeepClone(); var strRep = new StringBuilder(); var origStrRep = new StringBuilder(); strRep.Append(start.StrRep()); origStrRep.Append(start.OriginalStrRep()); ShapeNode node = start.Next; bool isComplex = false; while (node != end.Next) { strRep.Append(node.StrRep()); origStrRep.Append(node.OriginalStrRep()); fs.Add(node.Annotation.FeatureStruct); node = node.Next; isComplex = true; } fs.AddValue(CogFeatureSystem.StrRep, strRep.ToString()); fs.AddValue(CogFeatureSystem.OriginalStrRep, origStrRep.ToString()); fs.AddValue(CogFeatureSystem.SegmentType, isComplex ? CogFeatureSystem.Complex : CogFeatureSystem.Simple); fs.AddValue(CogFeatureSystem.SyllablePosition, syllablePosition); if (isComplex) { FeatureStruct firstFS; if (start.IsComplex()) { firstFS = start.Annotation.FeatureStruct.GetValue(CogFeatureSystem.First); } else { firstFS = new FeatureStruct(); foreach (Feature feature in start.Annotation.FeatureStruct.Features.Where(f => !CogFeatureSystem.Instance.ContainsFeature(f))) { firstFS.AddValue(feature, start.Annotation.FeatureStruct.GetValue(feature)); } } fs.AddValue(CogFeatureSystem.First, firstFS); } newStart = newShape.Add(fs); } else { ShapeNode node = start; while (node != end.Next) { var newNode = node.DeepClone(); newNode.Annotation.FeatureStruct.AddValue(CogFeatureSystem.SyllablePosition, syllablePosition); newShape.Add(newNode); if (newStart == null) { newStart = newNode; } node = node.Next; } } Debug.Assert(newStart != null); return(newStart); }
private AffixProcessAllomorph LoadAffixProcessAllomorph(XElement msubruleElem, CharacterDefinitionTable defaultTable) { var allomorph = new AffixProcessAllomorph(); allomorph.Environments.AddRange(LoadAllomorphEnvironments(msubruleElem.Element("RequiredEnvironments"), ConstraintType.Require, defaultTable)); allomorph.Environments.AddRange(LoadAllomorphEnvironments(msubruleElem.Element("ExcludedEnvironments"), ConstraintType.Exclude, defaultTable)); var fs = new FeatureStruct(); XElement requiredHeadFeatElem = msubruleElem.Element("RequiredHeadFeatures"); if (requiredHeadFeatElem != null) fs.AddValue(_headFeature, LoadFeatureStruct(requiredHeadFeatElem, _language.SyntacticFeatureSystem)); XElement requiredFootFeatElem = msubruleElem.Element("RequiredFootFeatures"); if (requiredFootFeatElem != null) fs.AddValue(_footFeature, LoadFeatureStruct(requiredFootFeatElem, _language.SyntacticFeatureSystem)); fs.Freeze(); allomorph.RequiredSyntacticFeatureStruct = fs; LoadProperties(msubruleElem.Element("Properties"), allomorph.Properties); Dictionary<string, Tuple<string, SymbolicFeature>> variables = LoadVariables(msubruleElem.Element("VariableFeatures")); XElement inputElem = msubruleElem.Element("MorphologicalInput"); Debug.Assert(inputElem != null); allomorph.RequiredMprFeatures.UnionWith(LoadMprFeatures((string) inputElem.Attribute("requiredMPRFeatures"))); allomorph.ExcludedMprFeatures.UnionWith(LoadMprFeatures((string) inputElem.Attribute("excludedMPRFeatures"))); var partNames = new Dictionary<string, string>(); LoadMorphologicalLhs(inputElem, variables, partNames, allomorph.Lhs, defaultTable); XElement outputElem = msubruleElem.Element("MorphologicalOutput"); Debug.Assert(outputElem != null); allomorph.OutMprFeatures.UnionWith(LoadMprFeatures((string) outputElem.Attribute("MPRFeatures"))); allomorph.ReduplicationHint = GetReduplicationHint((string) outputElem.Attribute("redupMorphType")); LoadMorphologicalRhs(outputElem, variables, partNames, allomorph.Rhs, defaultTable); return allomorph; }
private FeatureStruct LoadFeatureStruct(XElement elem, FeatureSystem featSys) { var fs = new FeatureStruct(); foreach (XElement featValElem in elem.Elements("FeatureValue").Where(IsActive)) { Feature feature = featSys.GetFeature((string) featValElem.Attribute("feature")); var valueIDsStr = (string) featValElem.Attribute("symbolValues"); if (!string.IsNullOrEmpty(valueIDsStr)) { var sf = (SymbolicFeature) feature; fs.AddValue(sf, valueIDsStr.Split(' ').Select(id => sf.PossibleSymbols[id])); } else { var cf = (ComplexFeature) feature; fs.AddValue(cf, LoadFeatureStruct(featValElem, featSys)); } } return fs; }
private void LoadStemName(XElement stemNameElem) { var posIDs = (string) stemNameElem.Attribute("partsOfSpeech"); FeatureSymbol[] pos = posIDs.Split(' ').Select(id => _posFeature.PossibleSymbols[id]).ToArray(); var regions = new List<FeatureStruct>(); foreach (XElement regionElem in stemNameElem.Elements("Regions").Elements("Region")) { var fs = new FeatureStruct(); fs.AddValue(_posFeature, pos); XElement headFeatElem = regionElem.Element("AssignedHeadFeatures"); if (headFeatElem != null) fs.AddValue(_headFeature, LoadFeatureStruct(headFeatElem, _language.SyntacticFeatureSystem)); XElement footFeatElem = regionElem.Element("AssignedFootFeatures"); if (footFeatElem != null) fs.AddValue(_footFeature, LoadFeatureStruct(footFeatElem, _language.SyntacticFeatureSystem)); fs.Freeze(); regions.Add(fs); } var stemName = new StemName(regions) {Name = (string) stemNameElem.Element("Name")}; _language.StemNames.Add(stemName); _stemNames[(string) stemNameElem.Attribute("id")] = stemName; }
protected void AddStringValue(FeatureSystem featSys, FeatureStruct fs, ITsString tss, string id) { if (tss != null) { var feat = featSys.GetFeature<StringFeature>(string.Format("{0}-{1}", id, tss.get_WritingSystemAt(0).ToString(CultureInfo.InvariantCulture))); fs.AddValue(feat, tss.Text); } }
private bool GenerateShape(SpanFactory <ShapeNode> spanFactory, FeatureSystem featSys) { m_shape.Add(FeatureStruct.New(featSys).Symbol("bdry").Symbol("wordBdry").Value); var typeFeat = featSys.GetFeature <SymbolicFeature>("type"); var catFeat = featSys.GetFeature <SymbolicFeature>("cat"); var inflFeat = featSys.GetFeature <ComplexFeature>("infl"); var segments = new Dictionary <ISegment, List <Annotation <ShapeNode> > >(); foreach (ISegment segment in m_para.SegmentsOS) { var annotations = new List <Annotation <ShapeNode> >(); foreach (Tuple <IAnalysis, int, int> analysis in segment.GetAnalysesAndOffsets()) { // check if analyses are out-of-sync with the baseline ITsString baselineStr = m_para.Contents.GetSubstring(analysis.Item2, analysis.Item3); ITsString formStr = analysis.Item1.GetForm(baselineStr.get_WritingSystemAt(0)); if (!baselineStr.Text.Equals(formStr.Text, StringComparison.InvariantCultureIgnoreCase)) { return(false); } var wordform = analysis.Item1 as IWfiWordform; if (wordform != null) { var wordFS = new FeatureStruct(); wordFS.AddValue(typeFeat, typeFeat.PossibleSymbols["word"]); foreach (int ws in wordform.Form.AvailableWritingSystemIds) { StringFeature strFeat; if (featSys.TryGetFeature(string.Format("form-{0}", ws), out strFeat)) { wordFS.AddValue(strFeat, wordform.Form.get_String(ws).Text); } } ShapeNode node = m_shape.Add(wordFS); node.Annotation.Data = analysis; annotations.Add(node.Annotation); } else { if (analysis.Item1 is IPunctuationForm) { annotations.Add(null); continue; } FeatureStruct wordInflFS = null; IWfiAnalysis wanalysis = analysis.Item1.Analysis; ShapeNode analysisStart = null; foreach (IWfiMorphBundle mb in wanalysis.MorphBundlesOS) { var morphFS = new FeatureStruct(); morphFS.AddValue(typeFeat, typeFeat.PossibleSymbols["morph"]); foreach (int ws in mb.Form.AvailableWritingSystemIds.Union(mb.MorphRA == null ? Enumerable.Empty <int>() : mb.MorphRA.Form.AvailableWritingSystemIds)) { StringFeature strFeat; if (!featSys.TryGetFeature(string.Format("form-{0}", ws), out strFeat)) { continue; } IEnumerable <string> forms = Enumerable.Empty <string>(); ITsString mbForm = mb.Form.StringOrNull(ws); if (mbForm != null) { forms = forms.Concat(mbForm.Text); } if (mb.MorphRA != null) { ITsString morphForm = mb.MorphRA.Form.StringOrNull(ws); if (morphForm != null) { forms = forms.Concat(morphForm.Text); } } morphFS.AddValue(strFeat, forms.Distinct()); } if (mb.SenseRA != null) { foreach (int ws in mb.SenseRA.Gloss.AvailableWritingSystemIds) { StringFeature strFeat; if (featSys.TryGetFeature(string.Format("gloss-{0}", ws), out strFeat)) { morphFS.AddValue(strFeat, mb.SenseRA.Gloss.get_String(ws).Text); } } } if (mb.MorphRA != null) { var entry = (ILexEntry)mb.MorphRA.Owner; foreach (int ws in entry.LexemeFormOA.Form.AvailableWritingSystemIds) { StringFeature strFeat; if (featSys.TryGetFeature(string.Format("entry-{0}", ws), out strFeat)) { morphFS.AddValue(strFeat, entry.LexemeFormOA.Form.get_String(ws).Text); } } } if (mb.MsaRA != null && mb.MsaRA.ComponentsRS != null) { FeatureSymbol[] catSymbols = GetHvoOfMsaPartOfSpeech(mb.MsaRA).Select(hvo => catFeat.PossibleSymbols[hvo.ToString(CultureInfo.InvariantCulture)]).ToArray(); if (catSymbols.Length > 0) { morphFS.AddValue(catFeat, catSymbols); } var inflFS = GetFeatureStruct(featSys, mb.MsaRA); if (inflFS != null) { morphFS.AddValue(inflFeat, inflFS); if (wordInflFS == null) { wordInflFS = inflFS.DeepClone(); } else { wordInflFS.Union(inflFS); } } } ShapeNode node = m_shape.Add(morphFS); if (analysisStart == null) { analysisStart = node; } } var wordFS = new FeatureStruct(); wordFS.AddValue(typeFeat, typeFeat.PossibleSymbols["word"]); if (wanalysis.CategoryRA != null) { wordFS.AddValue(catFeat, catFeat.PossibleSymbols[wanalysis.CategoryRA.Hvo.ToString(CultureInfo.InvariantCulture)]); } if (wordInflFS != null && !wordInflFS.IsEmpty) { wordFS.AddValue(inflFeat, wordInflFS); } wordform = wanalysis.Wordform; foreach (int ws in wordform.Form.AvailableWritingSystemIds) { StringFeature strFeat; if (featSys.TryGetFeature(string.Format("form-{0}", ws), out strFeat)) { wordFS.AddValue(strFeat, wordform.Form.get_String(ws).Text); } } var gloss = analysis.Item1 as IWfiGloss; if (gloss != null) { foreach (int ws in gloss.Form.AvailableWritingSystemIds) { StringFeature strFeat; if (featSys.TryGetFeature(string.Format("gloss-{0}", ws), out strFeat)) { wordFS.AddValue(strFeat, gloss.Form.get_String(ws).Text); } } } Annotation <ShapeNode> ann; if (analysisStart != null) { ann = m_shape.Annotations.Add(analysisStart, m_shape.Last, wordFS); m_shape.Add(FeatureStruct.New(featSys).Symbol("bdry").Symbol("wordBdry").Value); } else { ShapeNode node = m_shape.Add(wordFS); ann = node.Annotation; } ann.Data = analysis; annotations.Add(ann); } } segments[segment] = annotations; m_shape.Add(FeatureStruct.New(featSys).Symbol("bdry").Symbol("segBdry").Value); } foreach (ITextTag tag in m_para.OwnerOfClass <IStText>().TagsOC) { // skip invalid tags // TODO: should these tags be cleaned up somewhere? if (tag.BeginAnalysisIndex >= tag.BeginSegmentRA.AnalysesRS.Count || tag.EndAnalysisIndex >= tag.EndSegmentRA.AnalysesRS.Count || tag.BeginAnalysisIndex > tag.EndAnalysisIndex) { continue; } List <Annotation <ShapeNode> > beginSegment, endSegment; if (!segments.TryGetValue(tag.BeginSegmentRA, out beginSegment) || !segments.TryGetValue(tag.EndSegmentRA, out endSegment)) { continue; } Annotation <ShapeNode> beginAnnotation = beginSegment[tag.BeginAnalysisIndex]; Annotation <ShapeNode> endAnnotation = endSegment[tag.EndAnalysisIndex]; ICmPossibility tagType = tag.TagRA; if (tagType == null || beginAnnotation == null || endAnnotation == null) { continue; // guard against LT-14549 crash } Annotation <ShapeNode> tagAnn = new Annotation <ShapeNode>(spanFactory.Create(beginAnnotation.Span.Start, endAnnotation.Span.End), FeatureStruct.New(featSys).Symbol("ttag").Symbol(tagType.Hvo.ToString(CultureInfo.InvariantCulture)).Value) { Data = tag }; m_shape.Annotations.Add(tagAnn, false); } return(true); }
protected FeatureStruct GetFeatureStruct(FeatureSystem featSys, IDictionary<IFsFeatDefn, object> values) { var fs = new FeatureStruct(); foreach (KeyValuePair<IFsFeatDefn, object> kvp in values) { if (kvp.Key is IFsComplexFeature) { var childValues = (IDictionary<IFsFeatDefn, object>) kvp.Value; fs.AddValue(featSys.GetFeature(kvp.Key.Hvo.ToString(CultureInfo.InvariantCulture)), GetFeatureStruct(featSys, childValues)); } else if (kvp.Key is IFsClosedFeature) { var value = (ClosedFeatureValue) kvp.Value; var symFeat = featSys.GetFeature<SymbolicFeature>(kvp.Key.Hvo.ToString(CultureInfo.InvariantCulture)); FeatureSymbol symbol = symFeat.PossibleSymbols[value.Symbol.Hvo.ToString(CultureInfo.InvariantCulture)]; fs.AddValue(symFeat, value.Negate ? new SymbolicFeatureValue(symFeat.PossibleSymbols.Except(symbol.ToEnumerable())) : new SymbolicFeatureValue(symbol)); } } return fs; }
private bool TryLoadLexEntry(XElement entryElem, CharacterDefinitionTable table, out LexEntry entry) { var id = (string) entryElem.Attribute("id"); entry = new LexEntry {Gloss = (string) entryElem.Element("Gloss")}; var fs = new FeatureStruct(); var pos = (string) entryElem.Attribute("partOfSpeech"); if (!string.IsNullOrEmpty(pos)) fs.AddValue(_posFeature, ParsePartsOfSpeech(pos)); XElement headFeatElem = entryElem.Element("AssignedHeadFeatures"); if (headFeatElem != null) fs.AddValue(_headFeature, LoadFeatureStruct(headFeatElem, _language.SyntacticFeatureSystem)); XElement footFeatElem = entryElem.Element("AssignedFootFeatures"); if (footFeatElem != null) fs.AddValue(_footFeature, LoadFeatureStruct(footFeatElem, _language.SyntacticFeatureSystem)); fs.Freeze(); entry.SyntacticFeatureStruct = fs; entry.MprFeatures.UnionWith(LoadMprFeatures((string) entryElem.Attribute("ruleFeatures"))); var familyID = (string) entryElem.Attribute("family"); if (!string.IsNullOrEmpty(familyID)) { LexFamily family = _families[familyID]; family.Entries.Add(entry); } entry.IsPartial = (bool?) entryElem.Attribute("partial") ?? false; LoadProperties(entryElem.Element("Properties"), entry.Properties); foreach (XElement alloElem in entryElem.Elements("Allomorphs").Elements("Allomorph").Where(IsActive)) { try { RootAllomorph allomorph = LoadRootAllomorph(alloElem, table); entry.Allomorphs.Add(allomorph); _allomorphs[(string) alloElem.Attribute("id")] = allomorph; } catch (Exception e) { if (_errorHandler != null) _errorHandler(e, id); else throw; } } if (entry.Allomorphs.Count > 0) { _morphemes[id] = entry; return true; } entry = null; return false; }
private void NewNaturalClass() { var vm = new EditNaturalClassViewModel(_projectService.Project.FeatureSystem, _soundClasses.Select(nc => nc.DomainSoundClass)); if (_dialogService.ShowModalDialog(this, vm) == true) { var fs = new FeatureStruct(); fs.AddValue(CogFeatureSystem.Type, vm.Type == SoundType.Consonant ? CogFeatureSystem.ConsonantType : CogFeatureSystem.VowelType); foreach (FeatureViewModel feature in vm.ActiveFeatures) fs.AddValue(feature.DomainFeature, feature.SelectedValue.DomainSymbol); var newNaturalClass = new SoundClassViewModel(new NaturalClass(vm.Name, fs), _displaySonority ? 0 : -1); IsChanged = true; _soundClasses.Add(newNaturalClass); SelectedSoundClass = newNaturalClass; } }
internal static FeatureStruct AntiFeatureStruct(this FeatureStruct fs) { // TODO: handle reentrancy properly var result = new FeatureStruct(); foreach (Feature feature in fs.Features) { FeatureValue value = fs.GetValue(feature); var childFS = value as FeatureStruct; FeatureValue newValue; if (childFS != null) { newValue = HCFeatureSystem.Instance.ContainsFeature(feature) ? childFS.DeepClone() : childFS.AntiFeatureStruct(); } else { var childSfv = (SimpleFeatureValue) value; newValue = HCFeatureSystem.Instance.ContainsFeature(feature) ? childSfv.DeepClone() : childSfv.Negation(); } result.AddValue(feature, newValue); } return result; }
private bool TryLoadRealizationalRule(XElement realRuleElem, CharacterDefinitionTable defaultTable, out IMorphologicalRule mrule) { var realRuleID = (string) realRuleElem.Attribute("id"); var realRule = new RealizationalAffixProcessRule { Name = (string) realRuleElem.Element("Name"), Gloss = (string) realRuleElem.Element("Gloss"), Blockable = (bool?) realRuleElem.Attribute("blockable") ?? true }; var fs = new FeatureStruct(); XElement requiredHeadFeatElem = realRuleElem.Element("RequiredHeadFeatures"); if (requiredHeadFeatElem != null) fs.AddValue(_headFeature, LoadFeatureStruct(requiredHeadFeatElem, _language.SyntacticFeatureSystem)); XElement requiredFootFeatElem = realRuleElem.Element("RequiredFootFeatures"); if (requiredFootFeatElem != null) fs.AddValue(_footFeature, LoadFeatureStruct(requiredFootFeatElem, _language.SyntacticFeatureSystem)); fs.Freeze(); realRule.RequiredSyntacticFeatureStruct = fs; XElement realFeatElem = realRuleElem.Element("RealizationalFeatures"); if (realFeatElem != null) realRule.RealizationalFeatureStruct = FeatureStruct.New().Feature(_headFeature).EqualTo(LoadFeatureStruct(realFeatElem, _language.SyntacticFeatureSystem)).Value; LoadProperties(realRuleElem.Element("Properties"), realRule.Properties); foreach (XElement subruleElem in realRuleElem.Elements("MorphologicalSubrules").Elements("MorphologicalSubrule").Where(IsActive)) { try { AffixProcessAllomorph allomorph = LoadAffixProcessAllomorph(subruleElem, defaultTable); realRule.Allomorphs.Add(allomorph); _allomorphs[(string) subruleElem.Attribute("id")] = allomorph; } catch (Exception e) { if (_errorHandler != null) _errorHandler(e, (string) realRuleElem.Attribute("id")); else throw; } } if (realRule.Allomorphs.Count > 0) { _morphemes[realRuleID] = realRule; mrule = realRule; return true; } mrule = null; return false; }
private void CombineWith(ShapeNode node, ShapeNode start, ShapeNode end) { if ((CombineVowels && node.Type() == CogFeatureSystem.VowelType) || (CombineConsonants && node.Type() == CogFeatureSystem.ConsonantType)) { var strRep = new StringBuilder(); var origStrRep = new StringBuilder(); strRep.Append(node.StrRep()); origStrRep.Append(node.OriginalStrRep()); ShapeNode n = start; while (n != end.Next) { strRep.Append(n.StrRep()); origStrRep.Append(n.OriginalStrRep()); node.Annotation.FeatureStruct.Add(n.Annotation.FeatureStruct); n = n.Next; } node.Annotation.FeatureStruct.AddValue(CogFeatureSystem.StrRep, strRep.ToString()); node.Annotation.FeatureStruct.AddValue(CogFeatureSystem.OriginalStrRep, origStrRep.ToString()); node.Annotation.FeatureStruct.AddValue(CogFeatureSystem.SegmentType, CogFeatureSystem.Complex); FeatureStruct firstFS; if (start.IsComplex()) { firstFS = start.Annotation.FeatureStruct.GetValue(CogFeatureSystem.First); } else { firstFS = new FeatureStruct(); foreach (Feature feature in start.Annotation.FeatureStruct.Features.Where(f => !CogFeatureSystem.Instance.ContainsFeature(f))) firstFS.AddValue(feature, start.Annotation.FeatureStruct.GetValue(feature)); } node.Annotation.FeatureStruct.AddValue(CogFeatureSystem.First, firstFS); } else { ShapeNode n = start; while (n != end.Next) { var newNode = n.DeepClone(); node.AddAfter(newNode); node = newNode; n = n.Next; } } }
private bool TryLoadCompoundingRule(XElement compRuleElem, CharacterDefinitionTable defaultTable, out IMorphologicalRule mrule) { var compRuleID = (string) compRuleElem.Attribute("id"); var compRule = new CompoundingRule { Name = (string) compRuleElem.Element("Name"), Blockable = (bool?) compRuleElem.Attribute("blockable") ?? true }; var multApp = (string) compRuleElem.Attribute("multipleApplication"); if (!string.IsNullOrEmpty(multApp)) compRule.MaxApplicationCount = int.Parse(multApp); var fs = new FeatureStruct(); var headRequiredPos = (string) compRuleElem.Attribute("headPartsOfSpeech"); if (!string.IsNullOrEmpty(headRequiredPos)) fs.AddValue(_posFeature, ParsePartsOfSpeech(headRequiredPos)); XElement headRequiredHeadFeatElem = compRuleElem.Element("HeadRequiredHeadFeatures"); if (headRequiredHeadFeatElem != null) fs.AddValue(_headFeature, LoadFeatureStruct(headRequiredHeadFeatElem, _language.SyntacticFeatureSystem)); XElement headRequiredFootFeatElem = compRuleElem.Element("HeadRequiredFootFeatures"); if (headRequiredFootFeatElem != null) fs.AddValue(_footFeature, LoadFeatureStruct(headRequiredFootFeatElem, _language.SyntacticFeatureSystem)); fs.Freeze(); compRule.HeadRequiredSyntacticFeatureStruct = fs; fs = new FeatureStruct(); var nonHeadRequiredPos = (string) compRuleElem.Attribute("nonHeadPartsOfSpeech"); if (!string.IsNullOrEmpty(nonHeadRequiredPos)) fs.AddValue(_posFeature, ParsePartsOfSpeech(nonHeadRequiredPos)); XElement nonHeadRequiredHeadFeatElem = compRuleElem.Element("NonHeadRequiredHeadFeatures"); if (nonHeadRequiredHeadFeatElem != null) fs.AddValue(_headFeature, LoadFeatureStruct(nonHeadRequiredHeadFeatElem, _language.SyntacticFeatureSystem)); XElement nonHeadRequiredFootFeatElem = compRuleElem.Element("NonHeadRequiredFootFeatures"); if (nonHeadRequiredFootFeatElem != null) fs.AddValue(_footFeature, LoadFeatureStruct(nonHeadRequiredFootFeatElem, _language.SyntacticFeatureSystem)); fs.Freeze(); compRule.NonHeadRequiredSyntacticFeatureStruct = fs; fs = new FeatureStruct(); var outPos = (string) compRuleElem.Attribute("outputPartOfSpeech"); if (!string.IsNullOrEmpty(outPos)) fs.AddValue(_posFeature, ParsePartsOfSpeech(outPos)); XElement outHeadFeatElem = compRuleElem.Element("OutputHeadFeatures"); if (outHeadFeatElem != null) fs.AddValue(_headFeature, LoadFeatureStruct(outHeadFeatElem, _language.SyntacticFeatureSystem)); XElement outFootFeatElem = compRuleElem.Element("OutputFootFeatures"); if (outFootFeatElem != null) fs.AddValue(_footFeature, LoadFeatureStruct(outFootFeatElem, _language.SyntacticFeatureSystem)); fs.Freeze(); compRule.OutSyntacticFeatureStruct = fs; var obligHeadIDsStr = (string) compRuleElem.Attribute("outputObligatoryFeatures"); if (!string.IsNullOrEmpty(obligHeadIDsStr)) { foreach (string obligHeadID in obligHeadIDsStr.Split(' ')) compRule.ObligatorySyntacticFeatures.Add(_language.SyntacticFeatureSystem.GetFeature(obligHeadID)); } foreach (XElement subruleElem in compRuleElem.Elements("CompoundingSubrules").Elements("CompoundingSubrule").Where(IsActive)) { try { compRule.Subrules.Add(LoadCompoundingSubrule(subruleElem, defaultTable)); } catch (Exception e) { if (_errorHandler != null) _errorHandler(e, compRuleID); else throw; } } if (compRule.Subrules.Count > 0) { mrule = compRule; return true; } mrule = null; return false; }
private bool TryLoadAffixProcessRule(XElement mruleElem, CharacterDefinitionTable defaultTable, out IMorphologicalRule mrule) { var id = (string) mruleElem.Attribute("id"); var affixProcessRule = new AffixProcessRule { Name = (string) mruleElem.Element("Name"), Gloss = (string) mruleElem.Element("Gloss"), Blockable = (bool?) mruleElem.Attribute("blockable") ?? true, IsPartial = (bool?) mruleElem.Attribute("partial") ?? false }; var multApp = (string) mruleElem.Attribute("multipleApplication"); if (!string.IsNullOrEmpty(multApp)) affixProcessRule.MaxApplicationCount = int.Parse(multApp); var fs = new FeatureStruct(); var requiredPos = (string) mruleElem.Attribute("requiredPartsOfSpeech"); if (!string.IsNullOrEmpty(requiredPos)) fs.AddValue(_posFeature, ParsePartsOfSpeech(requiredPos)); XElement requiredHeadFeatElem = mruleElem.Element("RequiredHeadFeatures"); if (requiredHeadFeatElem != null) fs.AddValue(_headFeature, LoadFeatureStruct(requiredHeadFeatElem, _language.SyntacticFeatureSystem)); XElement requiredFootFeatElem = mruleElem.Element("RequiredFootFeatures"); if (requiredFootFeatElem != null) fs.AddValue(_footFeature, LoadFeatureStruct(requiredFootFeatElem, _language.SyntacticFeatureSystem)); fs.Freeze(); affixProcessRule.RequiredSyntacticFeatureStruct = fs; fs = new FeatureStruct(); var outPos = (string) mruleElem.Attribute("outputPartOfSpeech"); if (!string.IsNullOrEmpty(outPos)) fs.AddValue(_posFeature, ParsePartsOfSpeech(outPos)); XElement outHeadFeatElem = mruleElem.Element("OutputHeadFeatures"); if (outHeadFeatElem != null) fs.AddValue(_headFeature, LoadFeatureStruct(outHeadFeatElem, _language.SyntacticFeatureSystem)); XElement outFootFeatElem = mruleElem.Element("OutputFootFeatures"); if (outFootFeatElem != null) fs.AddValue(_footFeature, LoadFeatureStruct(outFootFeatElem, _language.SyntacticFeatureSystem)); fs.Freeze(); affixProcessRule.OutSyntacticFeatureStruct = fs; var obligHeadIDsStr = (string) mruleElem.Attribute("outputObligatoryFeatures"); if (!string.IsNullOrEmpty(obligHeadIDsStr)) { foreach (string obligHeadID in obligHeadIDsStr.Split(' ')) affixProcessRule.ObligatorySyntacticFeatures.Add(_language.SyntacticFeatureSystem.GetFeature(obligHeadID)); } var stemNameIDStr = (string) mruleElem.Attribute("requiredStemName"); if (!string.IsNullOrEmpty(stemNameIDStr)) affixProcessRule.RequiredStemName = _stemNames[stemNameIDStr]; LoadProperties(mruleElem.Element("Properties"), affixProcessRule.Properties); foreach (XElement subruleElem in mruleElem.Elements("MorphologicalSubrules").Elements("MorphologicalSubrule").Where(IsActive)) { try { AffixProcessAllomorph allomorph = LoadAffixProcessAllomorph(subruleElem, defaultTable); affixProcessRule.Allomorphs.Add(allomorph); _allomorphs[(string) subruleElem.Attribute("id")] = allomorph; } catch (Exception e) { if (_errorHandler != null) _errorHandler(e, id); else throw; } } if (affixProcessRule.Allomorphs.Count > 0) { _morphemes[id] = affixProcessRule; mrule = affixProcessRule; return true; } mrule = null; return false; }