From eb763b037366256d77c1b31e79e785eaf97c36f6 Mon Sep 17 00:00:00 2001 From: Enkidu93 Date: Fri, 24 Jan 2025 14:01:59 -0500 Subject: [PATCH] Extend parsing of aligned word pairs to accommodate NULLs --- src/SIL.Machine/Corpora/AlignedWordPair.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/SIL.Machine/Corpora/AlignedWordPair.cs b/src/SIL.Machine/Corpora/AlignedWordPair.cs index 534b87f8..23c47112 100644 --- a/src/SIL.Machine/Corpora/AlignedWordPair.cs +++ b/src/SIL.Machine/Corpora/AlignedWordPair.cs @@ -12,11 +12,11 @@ public static IReadOnlyCollection 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)); } @@ -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; + } } }