Skip to content

Commit eb763b0

Browse files
committed
Extend parsing of aligned word pairs to accommodate NULLs
1 parent fa1d6c7 commit eb763b0

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/SIL.Machine/Corpora/AlignedWordPair.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ public static IReadOnlyCollection<AlignedWordPair> Parse(string alignments, bool
1212
foreach (string token in alignments.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries))
1313
{
1414
int dashIndex = token.IndexOf('-');
15-
int i = int.Parse(token.Substring(0, dashIndex));
15+
int i = ParseIndex(token.Substring(0, dashIndex));
1616

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

2121
result.Add(invert ? new AlignedWordPair(j, i) : new AlignedWordPair(i, j));
2222
}
@@ -91,5 +91,10 @@ public override string ToString()
9191
}
9292
return sb.ToString();
9393
}
94+
95+
private static int ParseIndex(string indexString)
96+
{
97+
return int.TryParse(indexString, out int index) ? index : -1;
98+
}
9499
}
95100
}

0 commit comments

Comments
 (0)