Skip to content

Commit

Permalink
Replace Iterative with IsIterative and SetIterative
Browse files Browse the repository at this point in the history
  • Loading branch information
jtmaxwell3 authored and ddaspit committed Sep 30, 2024
1 parent fc3c939 commit 2dc7d71
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ private bool GetShapeNodes(string str, bool allowPattern, out IEnumerable<ShapeN
// Example: [Seg]*.
// Make the last node Kleene star.
nodesList[nodesList.Count - 1].Annotation.Optional = true;
nodesList[nodesList.Count - 1].Iterative = true;
nodesList[nodesList.Count - 1].SetIterative(true);
i++;
continue;
}
Expand Down
13 changes: 13 additions & 0 deletions src/SIL.Machine.Morphology.HermitCrab/HermitCrabExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,19 @@ internal static void SetDeleted(this ShapeNode node, bool deleted)
);
}

internal static bool IsIterative(this ShapeNode node)
{
return node.Annotation.Data != null;
}

internal static void SetIterative(this ShapeNode node, bool iterative)
{
if (iterative)
node.Annotation.Data = iterative;
else
node.Annotation.Data = null;
}

private static readonly IEqualityComparer<ShapeNode> NodeComparer = new ProjectionEqualityComparer<
ShapeNode,
FeatureStruct
Expand Down
2 changes: 1 addition & 1 deletion src/SIL.Machine.Morphology.HermitCrab/Morpher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ public IEnumerable<List<ShapeNode>> MatchNodesWithPattern(
return results;
// Make a copy of prefix to avoid crosstalk and add newNode.
prefix = new List<ShapeNode>(prefix) { newNode };
if (pattern[p].Iterative)
if (pattern[p].IsIterative())
// Try using this item in the pattern again.
results.AddRange(MatchNodesWithPattern(nodes, pattern, n + 1, p, true, prefix));
// Try the remainder of the nodes against the remainder of the pattern.
Expand Down
2 changes: 1 addition & 1 deletion src/SIL.Machine.Morphology.HermitCrab/RootAllomorph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public RootAllomorph(Segments segments)
_segments = segments;
foreach (ShapeNode node in _segments.Shape.GetNodes(_segments.Shape.Range))
{
if (node.Iterative || (node.Annotation.Optional && node.Annotation.Type() != HCFeatureSystem.Boundary))
if (node.IsIterative() || (node.Annotation.Optional && node.Annotation.Type() != HCFeatureSystem.Boundary))
{
IsPattern = true;
}
Expand Down
15 changes: 0 additions & 15 deletions src/SIL.Machine/Annotations/ShapeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,6 @@ public Annotation<ShapeNode> Annotation
get { return _ann; }
}

/// <summary>
/// Whether this is an iterative node in a lexical pattern.
/// </summary>
public bool Iterative
{
get { return Annotation.Data != null; }
set
{
if (value)
Annotation.Data = value;
else
Annotation.Data = null;
}
}

public int CompareTo(ShapeNode other)
{
if (other.List != List)
Expand Down

0 comments on commit 2dc7d71

Please sign in to comment.