Skip to content

Commit

Permalink
Revert "correct blank suggestions for extractor creation and update"
Browse files Browse the repository at this point in the history
This reverts commit 505909e.
  • Loading branch information
LaszloKecskes committed Jun 19, 2024
1 parent 21ff31f commit 1694551
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 134 deletions.
7 changes: 0 additions & 7 deletions app/api/services/informationextraction/getFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,12 @@ const propertiesWithoutExtractedMetadata: Set<string> = new Set([
...Array.from(selectProperties),
propertyTypes.relationship,
]);
const multiValuedProperties: Set<string> = new Set([
propertyTypes.multiselect,
propertyTypes.relationship,
]);

const propertyTypeIsSelectOrMultiSelect = (type: string) => selectProperties.has(type);

const propertyTypeIsWithoutExtractedMetadata = (type: string) =>
propertiesWithoutExtractedMetadata.has(type);

const propertyTypeIsMultiValued = (type: string) => multiValuedProperties.has(type);

async function getFilesWithAggregations(files: (FileType & FileEnforcedNotUndefined)[]) {
const filesNames = files.filter(x => x.filename).map(x => x.filename);

Expand Down Expand Up @@ -237,6 +231,5 @@ export {
getSegmentedFilesIds,
propertyTypeIsSelectOrMultiSelect,
propertyTypeIsWithoutExtractedMetadata,
propertyTypeIsMultiValued,
};
export type { FileWithAggregation };
119 changes: 0 additions & 119 deletions app/api/services/informationextraction/specs/ixextractors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,11 @@ const fixtures: DBFixture = {
},
},
],
relationtypes: [fixtureFactory.relationType('owns')],
templates: [
fixtureFactory.template('personTemplate', [
fixtureFactory.property('age', 'numeric'),
fixtureFactory.property('enemy', 'text'),
fixtureFactory.property('location', 'geolocation'),
fixtureFactory.property('occupation', 'select', { content: fixtureFactory.idString('Jobs') }),
fixtureFactory.property('spoken_languages', 'multiselect', {
content: fixtureFactory.idString('Languages'),
}),
fixtureFactory.property('pets', 'relationship', {
content: fixtureFactory.idString('animalTemplate'),
relationType: fixtureFactory.idString('owns'),
}),
]),
fixtureFactory.template('animalTemplate', [fixtureFactory.property('kind', 'text')]),
fixtureFactory.template('plantTemplate', [fixtureFactory.property('kind', 'text')]),
Expand Down Expand Up @@ -136,10 +127,6 @@ const fixtures: DBFixture = {
{ language: 'es' }
),
],
dictionaries: [
fixtureFactory.thesauri('Jobs', ['Developer', 'Tester']),
fixtureFactory.thesauri('Languages', ['English', 'Spanish']),
],
};

const emptyState: IXSuggestionStateType = {
Expand All @@ -162,16 +149,6 @@ const expectedStates: Record<string, IXSuggestionStateType> = {
...emptyState,
withValue: true,
},
onlyContext: {
...emptyState,
hasContext: true,
},
defaultForMultiValued: {
...emptyState,
hasContext: true,
withSuggestion: true,
match: true,
},
};

describe('ixextractors', () => {
Expand Down Expand Up @@ -286,102 +263,6 @@ describe('ixextractors', () => {
},
],
},
{
case: 'selects',
name: 'occupation_test',
property: 'occupation',
templates: [fixtureFactory.id('personTemplate').toString()],
expectedSuggestions: [
{
status: 'ready',
entityId: 'shared2',
language: 'en',
fileId: fixtureFactory.id('F1'),
propertyName: 'occupation',
error: '',
segment: '',
suggestedValue: '',
state: expectedStates.onlyContext,
entityTemplate: fixtureFactory.id('personTemplate').toString(),
},
{
status: 'ready',
entityId: 'shared2',
language: 'es',
fileId: fixtureFactory.id('F2'),
propertyName: 'occupation',
error: '',
segment: '',
suggestedValue: '',
state: expectedStates.onlyContext,
entityTemplate: fixtureFactory.id('personTemplate').toString(),
},
],
},
{
case: 'multiselects',
name: 'spoken_languages_test',
property: 'spoken_languages',
templates: [fixtureFactory.id('personTemplate').toString()],
expectedSuggestions: [
{
status: 'ready',
entityId: 'shared2',
language: 'en',
fileId: fixtureFactory.id('F1'),
propertyName: 'spoken_languages',
error: '',
segment: '',
suggestedValue: [],
state: expectedStates.defaultForMultiValued,
entityTemplate: fixtureFactory.id('personTemplate').toString(),
},
{
status: 'ready',
entityId: 'shared2',
language: 'es',
fileId: fixtureFactory.id('F2'),
propertyName: 'spoken_languages',
error: '',
segment: '',
suggestedValue: [],
state: expectedStates.defaultForMultiValued,
entityTemplate: fixtureFactory.id('personTemplate').toString(),
},
],
},
{
case: 'relationships',
name: 'pets_test',
property: 'pets',
templates: [fixtureFactory.id('personTemplate').toString()],
expectedSuggestions: [
{
status: 'ready',
entityId: 'shared2',
language: 'en',
fileId: fixtureFactory.id('F1'),
propertyName: 'pets',
error: '',
segment: '',
suggestedValue: [],
state: expectedStates.defaultForMultiValued,
entityTemplate: fixtureFactory.id('personTemplate').toString(),
},
{
status: 'ready',
entityId: 'shared2',
language: 'es',
fileId: fixtureFactory.id('F2'),
propertyName: 'pets',
error: '',
segment: '',
suggestedValue: [],
state: expectedStates.defaultForMultiValued,
entityTemplate: fixtureFactory.id('personTemplate').toString(),
},
],
},
])(
'should create empty suggestions for $case',
async ({ name, property, templates, expectedSuggestions }) => {
Expand Down
10 changes: 2 additions & 8 deletions app/api/suggestions/blankSuggestions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ import entitiesModel from 'api/entities/entitiesModel';
import { files } from 'api/files';
import { EnforcedWithId } from 'api/odm';
import settings from 'api/settings';
import { propertyTypeIsMultiValued } from 'api/services/informationextraction/getFiles';
import languages from 'shared/languages';
import { ObjectIdSchema } from 'shared/types/commonTypes';
import { IXExtractorType } from 'shared/types/extractorType';
import { FileType } from 'shared/types/fileType';
import { IXSuggestionType } from 'shared/types/suggestionType';
import { Suggestions } from './suggestions';
import templates from 'api/templates';

const fetchEntitiesBatch = async (query: any, limit: number = 100) =>
entitiesModel.db.find(query).select('sharedId').limit(limit).sort({ _id: 1 }).lean();
Expand Down Expand Up @@ -45,7 +43,6 @@ export const getBlankSuggestion = (
file: EnforcedWithId<FileType>,
{ _id: extractorId, property: propertyName }: { _id: ObjectIdSchema; property: string },
template: ObjectIdSchema,
propertyType: string,
defaultLanguage: string
) => ({
language: file.language
Expand All @@ -59,7 +56,7 @@ export const getBlankSuggestion = (
status: 'ready' as 'ready',
error: '',
segment: '',
suggestedValue: propertyTypeIsMultiValued(propertyType) ? [] : '',
suggestedValue: '',
date: new Date().getTime(),
});

Expand All @@ -70,7 +67,6 @@ export const createBlankSuggestionsForPartialExtractor = async (
) => {
const defaultLanguage = (await settings.getDefaultLanguage()).key;
const extractorTemplates = new Set(extractor.templates.map(t => t.toString()));
const exampleProperty = await templates.getPropertyByName(extractor.property);

const templatesPromises = selectedTemplates
.filter(template => extractorTemplates.has(template.toString()))
Expand All @@ -84,9 +80,7 @@ export const createBlankSuggestionsForPartialExtractor = async (

const suggestionsToSave: IXSuggestionType[] = fetchedFiles
.filter(file => file.entity)
.map(file =>
getBlankSuggestion(file, extractor, template, exampleProperty.type, defaultLanguage)
);
.map(file => getBlankSuggestion(file, extractor, template, defaultLanguage));
await Suggestions.saveMultiple(suggestionsToSave);
});

Expand Down

0 comments on commit 1694551

Please sign in to comment.