diff --git a/server/src/core/nlp/nlu/ner.ts b/server/src/core/nlp/nlu/ner.ts index 13de00dd..402199b6 100644 --- a/server/src/core/nlp/nlu/ner.ts +++ b/server/src/core/nlp/nlu/ner.ts @@ -169,14 +169,15 @@ export default class NER { if (spacyEntities.length > 0) { spacyEntities.forEach(({ entity, resolution }) => { + const value = StringHelper.ucFirst(resolution.value) const spacyEntity = { [entity]: { options: { - [resolution.value]: [StringHelper.ucFirst(resolution.value)] + [resolution.value]: [value] } } } - this.spacyData.set(`${entity}-${resolution.value}`, resolution) + this.spacyData.set(`${entity}-${value}`, resolution) MODEL_LOADER.mainNLPContainer.addEntities(spacyEntity, BRAIN.lang) }) diff --git a/server/src/core/nlp/types.ts b/server/src/core/nlp/types.ts index 4c0927d2..1489ccf9 100644 --- a/server/src/core/nlp/types.ts +++ b/server/src/core/nlp/types.ts @@ -386,26 +386,27 @@ interface SpacyEntity< entity: T } +interface SpacyLocationCountryData { + name: string + iso: string + iso3: string + isonumeric: number + continentcode: string + capital: string + population: number + tld: string + currencycode: string + currencyname: string + phone: string + languages: string + neighbours: string +} export interface SpacyLocationCountryEntity extends SpacyEntity< 'location:country', { value: string - data: { - name: string - iso: string - iso3: string - isonumeric: number - continentcode: string - capital: string - population: number - tld: string - currencycode: string - currencyname: string - phone: string - languages: string - neighbours: string - } + data: SpacyLocationCountryData } > {} export interface SpacyLocationCityEntity @@ -419,6 +420,7 @@ export interface SpacyLocationCityEntity latitude: number longitude: number countrycode: string + country: SpacyLocationCountryData population: number alternatenames: string[] time_zone: { diff --git a/skills/utilities/date_time/src/actions/current_date_time_with_time_zone.ts b/skills/utilities/date_time/src/actions/current_date_time_with_time_zone.ts index ef6ece93..d5bc0995 100644 --- a/skills/utilities/date_time/src/actions/current_date_time_with_time_zone.ts +++ b/skills/utilities/date_time/src/actions/current_date_time_with_time_zone.ts @@ -12,7 +12,7 @@ export const run: ActionFunction = async function (params) { } } - if (cityEntity == null) { + if (cityEntity == null || cityEntity.resolution.data == null) { return await leon.answer({ key: 'city_not_found' }) @@ -33,7 +33,7 @@ export const run: ActionFunction = async function (params) { minutes: zeroPad(currentDate.getMinutes()), seconds: zeroPad(currentDate.getSeconds()), city: cityEntity.resolution.data.name, - country: time_zone.country_code + country: cityEntity.resolution.data.country.name } }) } diff --git a/tcp_server/src/lib/nlp.py b/tcp_server/src/lib/nlp.py index 5724f600..b92b8b99 100644 --- a/tcp_server/src/lib/nlp.py +++ b/tcp_server/src/lib/nlp.py @@ -104,6 +104,12 @@ def extract_spacy_entities(utterance): entity += ':city' resolution['data'] = cities[city] resolution['data']['time_zone'] = get_time_zone_data(cities[city]['timezone']) + + for country in countries: + if countries[country]['iso'] == cities[city]['countrycode']: + resolution['data']['country'] = countries[country] + break + break entities.append({