@@ -29,6 +29,7 @@ import {
2929 FileWithAggregation ,
3030 getFilesForTraining ,
3131 getFilesForSuggestions ,
32+ propertyTypeIsWithoutExtractedMetadata ,
3233 propertyTypeIsSelectOrMultiSelect ,
3334} from 'api/services/informationextraction/getFiles' ;
3435import { Suggestions } from 'api/suggestions/suggestions' ;
@@ -95,6 +96,16 @@ type MaterialsData =
9596 | TextSelectionMaterialsData
9697 | ValuesSelectionMaterialsData ;
9798
99+ async function fetchCandidates ( property : PropertySchema ) {
100+ const defaultLanguageKey = ( await settings . getDefaultLanguage ( ) ) . key ;
101+ const query : { template ?: ObjectId ; language : string } = {
102+ language : defaultLanguageKey ,
103+ } ;
104+ if ( property . content !== '' ) query . template = new ObjectId ( property . content ) ;
105+ const candidates = await entities . getUnrestricted ( query , [ 'title' , 'sharedId' ] ) ;
106+ return candidates ;
107+ }
108+
98109class InformationExtraction {
99110 static SERVICE_NAME = 'information_extraction' ;
100111
@@ -142,9 +153,9 @@ class InformationExtraction {
142153
143154 let data : MaterialsData = { ..._data , language_iso } ;
144155
145- const isSelect = propertyTypeIsSelectOrMultiSelect ( propertyType ) ;
156+ const noExtractedData = propertyTypeIsWithoutExtractedMetadata ( propertyType ) ;
146157
147- if ( ! isSelect && propertyLabeledData ) {
158+ if ( ! noExtractedData && propertyLabeledData ) {
148159 data = {
149160 ...data ,
150161 label_text : propertyValue || propertyLabeledData ?. selection ?. text ,
@@ -155,7 +166,7 @@ class InformationExtraction {
155166 } ;
156167 }
157168
158- if ( isSelect ) {
169+ if ( noExtractedData ) {
159170 if ( ! Array . isArray ( propertyValue ) ) {
160171 throw new Error ( 'Property value should be an array' ) ;
161172 }
@@ -184,7 +195,7 @@ class InformationExtraction {
184195 ) ;
185196 const { propertyValue, propertyType } = file ;
186197
187- const missingData = propertyTypeIsSelectOrMultiSelect ( propertyType )
198+ const missingData = propertyTypeIsWithoutExtractedMetadata ( propertyType )
188199 ? ! propertyValue
189200 : type === 'labeled_data' && ! propertyLabeledData ;
190201
@@ -383,15 +394,22 @@ class InformationExtraction {
383394
384395 const params : TaskParameters = {
385396 id : extractorId . toString ( ) ,
386- multi_value : property . type === 'multiselect' ,
397+ multi_value : property . type === 'multiselect' || property . type === 'relationship' ,
387398 } ;
388399
389- if ( property . type === 'select' || property . type === 'multiselect' ) {
400+ if ( propertyTypeIsSelectOrMultiSelect ( property . type ) ) {
390401 const thesauri = await dictionatiesModel . getById ( property . content ) ;
391402
392403 params . options =
393404 thesauri ?. values ?. map ( value => ( { label : value . label , id : value . id as string } ) ) || [ ] ;
394405 }
406+ if ( property . type === 'relationship' ) {
407+ const candidates = await fetchCandidates ( property ) ;
408+ params . options = candidates . map ( candidate => ( {
409+ label : candidate . title || '' ,
410+ id : candidate . sharedId || '' ,
411+ } ) ) ;
412+ }
395413
396414 await this . taskManager . startTask ( {
397415 task : 'create_model' ,
0 commit comments