Skip to content
Merged
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
10 changes: 5 additions & 5 deletions src/SIL.Machine/Corpora/NParallelTextCorpus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,11 @@ NParallelTextRow row in CreateMinRefRows(
minRefIndexes.ToArray(),
nonMinRefIndexes.ToArray(),
sameRefRows,
forceInRange: minRefIndexes
forceInRange: Enumerable
.Range(0, N)
.Select(i =>
anyNonMinEnumeratorsMidRange
minRefIndexes.Contains(i)
&& anyNonMinEnumeratorsMidRange
&& nonMinRefIndexes.All(j =>
!completed[j] && currentRows[j].TextId == currentRows[i].TextId
) //All non-min rows have the same textId as the given min row
Expand Down Expand Up @@ -357,18 +359,16 @@ NParallelTextRow row in CreateRows(rangeInfo, textRows, forceInRange: forceInRan
}
}
textRows = new TextRow[N];
var forceCurrentInRange = new bool[N];
bool rowsHaveContent = false;
foreach (int i in minRefIndexes.Where(i => AllRows[i]).Except(alreadyYielded))
{
TextRow textRow = currentRows[i];
textRows[i] = textRow;
forceCurrentInRange[i] = forceCurrentInRange[i];
rowsHaveContent = true;
}
if (rowsHaveContent)
{
foreach (NParallelTextRow row in CreateRows(rangeInfo, textRows, forceCurrentInRange))
foreach (NParallelTextRow row in CreateRows(rangeInfo, textRows, forceInRange))
{
yield return row;
}
Expand Down
27 changes: 27 additions & 0 deletions tests/SIL.Machine.Tests/Corpora/NParallelTextCorpusTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,33 @@ public void GetRows_ThreeCorpora_SameRefManyToMany()
Assert.That(rows.Length, Is.EqualTo(10));
}

[Test]
public void GetRows_ThreeCorpora_SameRefCorporaOfDifferentSizes()
{
var corpus1 = new DictionaryTextCorpus(
new MemoryText("text1", new[] { TextRow("text1", 2, "source segment 2 .") })
);
var corpus2 = new DictionaryTextCorpus(
new MemoryText(
"text1",
new[]
{
TextRow("text1", 1, "source segment 1 ."),
TextRow("text1", 2, "source segment 2-1 ."),
TextRow("text1", 2, "source segment 2-2 ."),
TextRow("text1", 3, "source segment 3 . ")
}
)
);
var corpus3 = new DictionaryTextCorpus(
new MemoryText("text1", new[] { TextRow("text1", 1, "source segment 1 .") })
);
var nParallelCorpus = new NParallelTextCorpus([corpus1, corpus2, corpus3]) { AllRows = [true, true, true] };
NParallelTextRow[] rows = nParallelCorpus.ToArray();
Assert.That(rows.Length, Is.EqualTo(4), JsonSerializer.Serialize(rows));
Assert.That(rows[0].NRefs[1], Is.EquivalentTo(new object[] { 1 }));
}

private static TextRow TextRow(
string textId,
object rowRef,
Expand Down
Loading