Skip to content

Commit

Permalink
feat(server): add regex entity type
Browse files Browse the repository at this point in the history
  • Loading branch information
louistiti committed May 11, 2019
1 parent 27c323a commit 3fda352
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/calendar/data/expressions/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"entities": [
{
"type": "regex",
"name": "",
"regex": ""
"name": "color",
"regex": "red|blue|green"
},
{
"type": "trim",
Expand Down
16 changes: 14 additions & 2 deletions server/src/core/ner.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Ner {
if (!this.supportedEntityTypes.includes(entity.type)) {
reject({ type: 'warning', obj: new Error(`"${entity.type}" action entity type not supported`), code: 'random_ner_type_not_supported', data: { '%entity_type%': entity.type } })
} else if (entity.type === 'regex') {
// TODO: regex case
promises.push(this.injectRegexEntity(lang, entity))
} else if (entity.type === 'trim') {
promises.push(this.injectTrimEntity(lang, entity))
}
Expand Down Expand Up @@ -83,7 +83,6 @@ class Ner {
*/
injectTrimEntity (lang, entity) {
return new Promise((resolve) => {
console.log('addnamedentity', entity.name, entity.type)
const e = this.nerManager.addNamedEntity(entity.name, entity.type)

for (let j = 0; j < entity.conditions.length; j += 1) {
Expand All @@ -103,6 +102,19 @@ class Ner {
resolve()
})
}

/**
* Inject regex type entities
*/
injectRegexEntity (lang, entity) {
return new Promise((resolve) => {
const e = this.nerManager.addNamedEntity(entity.name, entity.type)

e.addRegex(lang, new RegExp(entity.regex, 'g'))

resolve()
})
}
}

export default Ner

0 comments on commit 3fda352

Please sign in to comment.