Skip to content

Commit

Permalink
Extend parsing of aligned word pairs to accommodate NULLs
Browse files Browse the repository at this point in the history
  • Loading branch information
Enkidu93 committed Jan 24, 2025
1 parent fa1d6c7 commit eb763b0
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/SIL.Machine/Corpora/AlignedWordPair.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ public static IReadOnlyCollection<AlignedWordPair> Parse(string alignments, bool
foreach (string token in alignments.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries))
{
int dashIndex = token.IndexOf('-');
int i = int.Parse(token.Substring(0, dashIndex));
int i = ParseIndex(token.Substring(0, dashIndex));

int colonIndex = token.IndexOf(':', dashIndex + 1);
int length = (colonIndex == -1 ? token.Length : colonIndex) - (dashIndex + 1);
int j = int.Parse(token.Substring(dashIndex + 1, length));
int j = ParseIndex(token.Substring(dashIndex + 1, length));

result.Add(invert ? new AlignedWordPair(j, i) : new AlignedWordPair(i, j));
}
Expand Down Expand Up @@ -91,5 +91,10 @@ public override string ToString()
}
return sb.ToString();
}

private static int ParseIndex(string indexString)
{
return int.TryParse(indexString, out int index) ? index : -1;
}
}
}

0 comments on commit eb763b0

Please sign in to comment.