/// <summary> /// Initializes a new instance of the <see cref="RootAllomorph"/> class. /// </summary> public RootAllomorph(Segments segments) { _segments = segments; }
private RootAllomorph LoadRootAllomorph(XElement alloElem, CharacterDefinitionTable table) { var shapeStr = (string) alloElem.Element("PhoneticShape"); Segments segments = new Segments(table, shapeStr); if (segments.Shape.All(n => n.Type() == HCFeatureSystem.Boundary)) throw new InvalidShapeException(shapeStr, 0); var allomorph = new RootAllomorph(segments) { IsBound = (bool?) alloElem.Attribute("isBound") ?? false }; allomorph.Environments.AddRange(LoadAllomorphEnvironments(alloElem.Element("RequiredEnvironments"), ConstraintType.Require, table)); allomorph.Environments.AddRange(LoadAllomorphEnvironments(alloElem.Element("ExcludedEnvironments"), ConstraintType.Exclude, table)); var stemNameIDStr = (string) alloElem.Attribute("stemName"); if (!string.IsNullOrEmpty(stemNameIDStr)) allomorph.StemName = _stemNames[stemNameIDStr]; LoadProperties(alloElem.Element("Properties"), allomorph.Properties); return allomorph; }
private IEnumerable<PatternNode<Word, ShapeNode>> LoadPatternNodes(XElement pseqElem, Dictionary<string, Tuple<string, SymbolicFeature>> variables, CharacterDefinitionTable defaultTable, Dictionary<string, string> groupNames) { foreach (XElement recElem in pseqElem.Elements()) { PatternNode<Word, ShapeNode> node = null; switch (recElem.Name.LocalName) { case "SimpleContext": SimpleContext simpleCtxt = LoadSimpleContext(recElem, variables); node = new Constraint<Word, ShapeNode>(simpleCtxt.FeatureStruct) {Tag = simpleCtxt}; break; case "Segment": case "BoundaryMarker": CharacterDefinition cd = _charDefs[(string) recElem.Attribute(recElem.Name.LocalName == "Segment" ? "segment" : "boundary")]; node = new Constraint<Word, ShapeNode>(cd.FeatureStruct) {Tag = cd}; break; case "OptionalSegmentSequence": var minStr = (string) recElem.Attribute("min"); int min = string.IsNullOrEmpty(minStr) ? 0 : int.Parse(minStr); var maxStr = (string) recElem.Attribute("max"); int max = string.IsNullOrEmpty(maxStr) ? -1 : int.Parse(maxStr); node = new Quantifier<Word, ShapeNode>(min, max, new Group<Word, ShapeNode>(LoadPatternNodes(recElem, variables, defaultTable, groupNames))); break; case "Segments": CharacterDefinitionTable segsTable = GetTable(recElem, defaultTable); var shapeStr = (string) recElem.Element("PhoneticShape"); var segments = new Segments(segsTable, shapeStr); node = new Group<Word, ShapeNode>(segments.Shape.Select(n => new Constraint<Word, ShapeNode>(n.Annotation.FeatureStruct))) {Tag = segments}; break; } Debug.Assert(node != null); var id = (string) recElem.Attribute("id"); string groupName; if (groupNames == null || string.IsNullOrEmpty(id) || !groupNames.TryGetValue(id, out groupName)) yield return node; else yield return new Group<Word, ShapeNode>(groupName, node); } }