Skip to content

Commit

Permalink
Fixed suggestions document language issues
Browse files Browse the repository at this point in the history
  • Loading branch information
grafitto committed Mar 30, 2022
1 parent 84c33b7 commit 830c908
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
15 changes: 11 additions & 4 deletions app/api/services/informationextraction/InformationExtraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,19 @@ class InformationExtraction {
if (!entity) {
return Promise.resolve();
}

const [segmentation] = await SegmentationModel.get({
xmlname: rawSuggestion.xml_file_name,
});

if (!segmentation) {
return Promise.resolve();
}

const [currentSuggestion] = await IXSuggestionsModel.get({
entityId: entity.sharedId,
propertyName: rawSuggestion.property_name,
fileId: segmentation.fileID,
});

let status: 'ready' | 'failed' = 'ready';
Expand All @@ -207,9 +217,6 @@ class InformationExtraction {

const suggestion: IXSuggestionType = {
...currentSuggestion,
entityId: entity.sharedId!,
language: entity.language!,
propertyName: rawSuggestion.property_name,
suggestedValue,
segment: rawSuggestion.segment_text,
status,
Expand All @@ -234,7 +241,7 @@ class InformationExtraction {
...existingSuggestions,
entityId: entity.sharedId!,
fileId: file._id,
language: entity.language!,
language: languages.get(file.language, 'ISO639_1') || 'other',
propertyName,
status: 'processing',
date: new Date().getTime(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ describe('InformationExtraction', () => {
it('should create the suggestions placeholder with status processing', async () => {
await informationExtraction.getSuggestions('property1');
const suggestions = await IXSuggestionsModel.get();
expect(suggestions.length).toBe(4);
expect(suggestions.length).toBe(6);
expect(suggestions.find(s => s.entityId === 'A1')).toEqual(
expect.objectContaining({
entityId: 'A1',
Expand Down Expand Up @@ -339,7 +339,7 @@ describe('InformationExtraction', () => {
status: 'ready',
propertyName: 'property1',
});
expect(suggestionsText.length).toBe(1);
expect(suggestionsText.length).toBe(2);

const suggestionsMarkdown = await IXSuggestionsModel.get({
status: 'ready',
Expand Down
23 changes: 23 additions & 0 deletions app/api/services/informationextraction/specs/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ const fixtures: DBFixture = {
],
ixsuggestions: [
{
fileId: factory.id('F1'),
entityId: 'A1',
language: 'en',
propertyName: 'property1',
Expand All @@ -171,6 +172,28 @@ const fixtures: DBFixture = {
page: 1,
date: 100,
},
{
fileId: factory.id('F3'),
entityId: 'A1',
language: 'en',
propertyName: 'property1',
suggestedValue: 'suggestion_text_2',
segment: 'segment_text_2',
status: 'ready',
page: 1,
date: 100,
},
{
fileId: factory.id('F1'),
entityId: 'A1',
language: 'en',
propertyName: 'property4',
suggestedValue: 'suggestion_text_2',
segment: 'segment_text_2',
status: 'ready',
page: 1,
date: 100,
},
],
ixmodels: [
{ propertyName: 'property1', creationDate: 200, status: 'ready' },
Expand Down
2 changes: 1 addition & 1 deletion app/api/suggestions/IXSuggestionsModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const mongoSchema = new mongoose.Schema(props, {
strict: false,
});

mongoSchema.index({ propertyName: 'text' });
mongoSchema.index({ propertyName: 'text' }, { language_override: '_text' });

const IXSuggestionsModel = instanceModel<IXSuggestionType>('ixsuggestions', mongoSchema);

Expand Down

0 comments on commit 830c908

Please sign in to comment.