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
6 changes: 3 additions & 3 deletions src/SIL.Machine/Corpora/NParallelTextCorpus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ public override IEnumerable<NParallelTextRow> GetRows(IEnumerable<string> textId
}
}

private static bool AllInRangeHaveSegments(IList<TextRow> rows)
private static bool AllRangesAreNewRanges(IList<TextRow> rows)
{
return rows.All(r => (r.IsInRange && !r.IsEmpty) || (!r.IsInRange));
return rows.All(r => r.IsRangeStart || !r.IsInRange);
}

private IList<int> MinRefIndexes(IList<object> refs)
Expand Down Expand Up @@ -211,7 +211,7 @@ NParallelTextRow row in CreateMinRefRows(
{
if (
rangeInfo.IsInRange
&& AllInRangeHaveSegments(currentRows.Where((r, i) => !completed[i]).ToArray())
&& AllRangesAreNewRanges(currentRows.Where((r, i) => !completed[i]).ToArray())
)
{
yield return rangeInfo.CreateRow();
Expand Down
55 changes: 55 additions & 0 deletions tests/SIL.Machine.Tests/Corpora/ParallelTextCorpusTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,61 @@ public void GetRows_AdjacentRangesDifferentTexts()
Assert.That(rows[1].TargetSegment, Is.EqualTo("target segment 3 . target segment 4 .".Split()));
}

[Test]
public void GetRows_AdjacentRangesBothTexts_EmptyTargetSegments()
{
var sourceCorpus = new DictionaryTextCorpus(
new MemoryText(
"text1",
new[]
{
TextRow(
"text1",
1,
"source segment 1 . source segment 2 .",
TextRowFlags.InRange | TextRowFlags.RangeStart
),
TextRow("text1", 2, flags: TextRowFlags.InRange),
TextRow(
"text1",
3,
"source segment 3 . source segment 4 .",
TextRowFlags.InRange | TextRowFlags.RangeStart
),
TextRow("text1", 4, flags: TextRowFlags.InRange)
}
)
);
var targetCorpus = new DictionaryTextCorpus(
new MemoryText(
"text1",
new[]
{
TextRow("text1", 1, flags: TextRowFlags.InRange | TextRowFlags.RangeStart),
TextRow("text1", 2, flags: TextRowFlags.InRange),
TextRow("text1", 3, flags: TextRowFlags.InRange | TextRowFlags.RangeStart),
TextRow("text1", 4, flags: TextRowFlags.InRange)
}
)
);

var parallelCorpus = new ParallelTextCorpus(sourceCorpus, targetCorpus)
{
AllSourceRows = true,
AllTargetRows = false
};
ParallelTextRow[] rows = parallelCorpus.ToArray();
Assert.That(rows.Length, Is.EqualTo(2));
Assert.That(rows[0].SourceRefs, Is.EqualTo(new[] { 1, 2 }));
Assert.That(rows[0].TargetRefs, Is.EqualTo(new[] { 1, 2 }));
Assert.That(rows[0].SourceSegment, Is.EqualTo("source segment 1 . source segment 2 .".Split()));
Assert.That(rows[0].TargetSegment, Is.Empty);
Assert.That(rows[1].SourceRefs, Is.EqualTo(new[] { 3, 4 }));
Assert.That(rows[1].TargetRefs, Is.EqualTo(new[] { 3, 4 }));
Assert.That(rows[1].SourceSegment, Is.EqualTo("source segment 3 . source segment 4 .".Split()));
Assert.That(rows[1].TargetSegment, Is.Empty);
}

[Test]
public void GetRows_AllSourceRows()
{
Expand Down
Loading