-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(server): introduce main NLP model and resolvers NLP model
- Loading branch information
Showing
13 changed files
with
379 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import path from 'path' | ||
import fs from 'fs' | ||
|
||
import log from '@/helpers/log' | ||
|
||
/** | ||
* Train global entities | ||
*/ | ||
export default (lang, nlp) => new Promise((resolve) => { | ||
log.title('Global entities training') | ||
|
||
const globalEntitiesPath = path.join(process.cwd(), 'core/data', lang, 'global-entities') | ||
const globalEntityFiles = fs.readdirSync(globalEntitiesPath) | ||
const newEntitiesObj = { } | ||
|
||
// Add global entities annotations (@...) | ||
for (let i = 0; i < globalEntityFiles.length; i += 1) { | ||
const globalEntityFileName = globalEntityFiles[i] | ||
const [entityName] = globalEntityFileName.split('.') | ||
const globalEntityPath = path.join(globalEntitiesPath, globalEntityFileName) | ||
const { options } = JSON.parse(fs.readFileSync(globalEntityPath, 'utf8')) | ||
const optionKeys = Object.keys(options) | ||
const optionsObj = { } | ||
|
||
log.info(`[${lang}] Adding "${entityName}" global entity...`) | ||
|
||
optionKeys.forEach((optionKey) => { | ||
const { synonyms } = options[optionKey] | ||
|
||
optionsObj[optionKey] = synonyms | ||
}) | ||
|
||
newEntitiesObj[entityName] = { options: optionsObj } | ||
log.success(`[${lang}] "${entityName}" global entity added`) | ||
} | ||
|
||
nlp.addEntities(newEntitiesObj, lang) | ||
|
||
resolve() | ||
}) |
Oops, something went wrong.