Skip to content

Commit 25d07c7

Browse files
authored
Fix example sentence filter (#1667)
* tweak the example sentence filters so they match any sense, rather than requiring all senses to have no examples * fix some failing tests, add a test for entries that have senses
1 parent bc88edf commit 25d07c7

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed

backend/FwLite/FwDataMiniLcmBridge/LexEntryFilterMapProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class LexEntryFilterMapProvider : EntryFilterMapProvider<ILexEntry>
1717
// ReSharper disable once ConvertClosureToMethodGroup
1818
.Select(domain => LcmHelpers.GetSemanticDomainCode(domain));
1919
public override Func<string, object>? EntrySensesSemanticDomainsConverter => EntryFilter.NormalizeEmptyToNullString<ICmSemanticDomain>;
20-
public override Expression<Func<ILexEntry, object?>> EntrySensesExampleSentences => e => EmptyToNull(e.AllSenses.SelectMany(s => s.ExamplesOS));
20+
public override Expression<Func<ILexEntry, object?>> EntrySensesExampleSentences => e => e.AllSenses.Select(s => EmptyToNull(s.ExamplesOS));
2121
public override Expression<Func<ILexEntry, string, object?>> EntrySensesExampleSentencesSentence => (entry, ws) =>
2222
entry.AllSenses.SelectMany(s => s.ExamplesOS).Select(example => example.PickText(example.Example, ws));
2323

backend/FwLite/LcmCrdt/EntryFilterMapProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class EntryFilterMapProvider : EntryFilterMapProvider<Entry>
1313
public override Func<string, object>? EntrySensesSemanticDomainsConverter =>
1414
//linq2db treats Sense.SemanticDomains as a table, if we use "null" then it'll write the query we want
1515
EntryFilter.NormalizeEmptyToNullString<SemanticDomain>;
16-
public override Expression<Func<Entry, object?>> EntrySensesExampleSentences => e => e.Senses.SelectMany(s => s.ExampleSentences);
16+
public override Expression<Func<Entry, object?>> EntrySensesExampleSentences => e => e.Senses.Select(s => s.ExampleSentences);
1717
public override Expression<Func<Entry, string, object?>> EntrySensesExampleSentencesSentence =>
1818
(e, ws) => e.Senses.SelectMany(s => s.ExampleSentences).Select(example => Json.Value(example.Sentence, ms => ms[ws]));
1919
public override Expression<Func<Entry, object?>> EntrySensesPartOfSpeechId => e => e.Senses.Select(s => s.PartOfSpeechId);

backend/FwLite/MiniLcm.Tests/QueryEntryTestsBase.cs

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ public abstract class QueryEntryTestsBase : MiniLcmTestBase
55
private readonly string Apple = "Apple";
66
private readonly string Peach = "Peach";
77
private readonly string Banana = "Banana";
8+
private readonly string Kiwi = "Kiwi";
89

910
public override async Task InitializeAsync()
1011
{
@@ -59,6 +60,27 @@ await Api.CreateEntry(new Entry()
5960
}
6061
]
6162
});
63+
await Api.CreateEntry(new Entry()
64+
{
65+
LexemeForm = { { "en", Kiwi } },
66+
Senses =
67+
[
68+
new()
69+
{
70+
Gloss = { { "en", "Fruit" } },
71+
Definition = { { "en", "Fruit, fuzzy with green flesh" } },
72+
PartOfSpeechId = nounPos.Id,
73+
SemanticDomains = [semanticDomain],
74+
ExampleSentences =
75+
[
76+
new ExampleSentence()
77+
{
78+
Sentence = { { "en", "I like eating Kiwis, they taste good" } }
79+
},
80+
]
81+
}
82+
]
83+
});
6284
}
6385

6486
[Fact]
@@ -68,18 +90,28 @@ public async Task CanFilterToMissingSenses()
6890
results.Select(e => e.LexemeForm["en"]).Should().BeEquivalentTo(Apple);
6991
}
7092

93+
[Fact]
94+
public async Task CanFilterToNotMissingSenses()
95+
{
96+
var results = await Api.GetEntries(new(Filter: new() { GridifyFilter = "Senses!=null" })).ToArrayAsync();
97+
results.Select(e => e.LexemeForm["en"]).Should().BeEquivalentTo(Kiwi, Peach, Banana);
98+
}
99+
71100
[Fact]
72101
public async Task CanFilterToMissingPartOfSpeech()
73102
{
74103
var results = await Api.GetEntries(new(Filter: new() { GridifyFilter = "Senses.PartOfSpeechId=null" })).ToArrayAsync();
104+
//does not include entries with no senses
75105
results.Select(e => e.LexemeForm["en"]).Should().BeEquivalentTo(Peach);
76106
}
77107

78108
[Fact]
79109
public async Task CanFilterToMissingExamples()
80110
{
81111
var results = await Api.GetEntries(new(Filter: new() { GridifyFilter = "Senses.ExampleSentences=null" })).ToArrayAsync();
82-
results.Select(e => e.LexemeForm["en"]).Should().BeEquivalentTo([Apple, Peach]);
112+
//Senses.ExampleSentences=null matches entries which have senses but no examples
113+
//it does not include Apple because it has no senses, to include it a filter Senses=null is needed
114+
results.Select(e => e.LexemeForm["en"]).Should().BeEquivalentTo(Peach, Banana);
83115
}
84116

85117
[Fact]
@@ -100,21 +132,21 @@ public async Task CanFilterToMissingSemanticDomainsWithEmptyArray()
100132
public async Task CanFilterSemanticDomainCodeContains()
101133
{
102134
var results = await Api.GetEntries(new(Filter: new() { GridifyFilter = "Senses.SemanticDomains.Code=*Fruit" })).ToArrayAsync();
103-
results.Select(e => e.LexemeForm["en"]).Should().BeEquivalentTo(Banana);
135+
results.Select(e => e.LexemeForm["en"]).Should().BeEquivalentTo(Banana, Kiwi);
104136
}
105137

106138
[Fact]
107139
public async Task CanFilterToMissingComplexFormTypes()
108140
{
109141
var results = await Api.GetEntries(new(Filter: new() { GridifyFilter = "ComplexFormTypes=null" })).ToArrayAsync();
110-
results.Select(e => e.LexemeForm["en"]).Should().BeEquivalentTo(Apple, Banana);
142+
results.Select(e => e.LexemeForm["en"]).Should().BeEquivalentTo(Apple, Banana, Kiwi);
111143
}
112144

113145
[Fact]
114146
public async Task CanFilterToMissingComplexFormTypesWithEmptyArray()
115147
{
116148
var results = await Api.GetEntries(new(Filter: new() { GridifyFilter = "ComplexFormTypes=[]" })).ToArrayAsync();
117-
results.Select(e => e.LexemeForm["en"]).Should().BeEquivalentTo(Apple, Banana);
149+
results.Select(e => e.LexemeForm["en"]).Should().BeEquivalentTo(Apple, Banana, Kiwi);
118150
}
119151

120152
[Fact]
@@ -163,7 +195,7 @@ public async Task CanFilterGlossEmpty()
163195
public async Task CanFilterGlossEqualsFruit()
164196
{
165197
var results = await Api.GetEntries(new(Filter: new() { GridifyFilter = "Senses.Gloss[en]=Fruit" })).ToArrayAsync();
166-
results.Select(e => e.LexemeForm["en"]).Should().BeEquivalentTo(Banana);
198+
results.Select(e => e.LexemeForm["en"]).Should().BeEquivalentTo(Banana, Kiwi);
167199
}
168200

169201
[Fact]

0 commit comments

Comments
 (0)