Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/SIL.Machine/Corpora/CorporaExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ public static (IEnumerable<(T, bool)>, int, int) InterleavedSplit<T>(
return (splitCorpus, corpusSize - splitIndices.Count, splitIndices.Count);
}

public static ArgumentException AlignmentException<T>(
this ICorpus<T> _,
string[] refs,
Exception innerException = null
)
where T : IRow =>
new ArgumentException(
$"Invalid format in {string.Join(", ", refs)}. Mismatched key formats. There may be an extraneous tab, missing ref, or inconsistent use of user-defined refs.",
innerException
);

#endregion

#region ITextCorpus operations
Expand Down
19 changes: 0 additions & 19 deletions src/SIL.Machine/Corpora/CorpusAlignmentException.cs

This file was deleted.

8 changes: 3 additions & 5 deletions src/SIL.Machine/Corpora/NParallelTextCorpus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private IEnumerable<NParallelTextRow> GetRows(IList<IEnumerator<TextRow>> enumer
}
catch (ArgumentException e)
{
throw new CorpusAlignmentException(
throw this.AlignmentException(
currentRows.Where(r => r != null).Select(r => r.Ref.ToString()).ToArray(),
e
);
Expand Down Expand Up @@ -264,9 +264,7 @@ NParallelTextRow row in CreateRows(
}
else
{
throw new CorpusAlignmentException(
minRefIndexes.Select(i => currentRows[i].Ref.ToString()).ToArray()
);
throw this.AlignmentException(minRefIndexes.Select(i => currentRows[i].Ref.ToString()).ToArray());
}
}

Expand Down Expand Up @@ -400,7 +398,7 @@ private bool CheckSameRefRows(IList<TextRow> sameRefRows, TextRow otherRow)
}
catch (ArgumentException e)
{
throw new CorpusAlignmentException(sameRefRows[0].Ref.ToString(), otherRow.Ref.ToString(), e);
throw this.AlignmentException(new[] { sameRefRows[0].Ref.ToString(), otherRow.Ref.ToString() }, e);
}
return sameRefRows.Count > 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/SIL.Machine/Corpora/ParallelTextCorpus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public override IEnumerable<ParallelTextRow> GetRows(IEnumerable<string> textIds
}
catch (ArgumentException e)
{
throw new CorpusAlignmentException(nRow.NRefs.Select(r => r.ToString()).ToArray(), e);
throw this.AlignmentException(nRow.NRefs.Select(r => r.ToString()).ToArray(), e);
}
} while (compareAlignmentCorpus < 0);
}
Expand Down
Loading