Skip to content

Commit 816d0df

Browse files
committed
catch entity build exceptions when testing models
Signed-off-by: Julien Buret <jburet@voyages-sncf.com>
1 parent 24efc79 commit 816d0df

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

nlp/core/service/src/main/kotlin/fr/vsct/tock/nlp/core/service/ModelCoreService.kt

+14-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ import fr.vsct.tock.nlp.core.sample.SampleExpression
3131
import fr.vsct.tock.nlp.model.EntityBuildContextForIntent
3232
import fr.vsct.tock.nlp.model.IntentContext
3333
import fr.vsct.tock.nlp.model.NlpClassifier
34+
import fr.vsct.tock.shared.error
3435
import fr.vsct.tock.shared.injector
36+
import mu.KotlinLogging
3537
import java.time.Duration
3638
import java.time.Instant
3739
import java.util.Collections
@@ -41,6 +43,8 @@ import java.util.Collections
4143
*/
4244
object ModelCoreService : ModelCore {
4345

46+
private val logger = KotlinLogging.logger {}
47+
4448
private val nlpClassifier: NlpClassifier by injector.instance()
4549

4650
override fun updateIntentModel(context: BuildContext, expressions: List<SampleExpression>) {
@@ -78,11 +82,17 @@ object ModelCoreService : ModelCore {
7882
val intentModel = nlpClassifier.buildIntentModel(intentContext, modelExpressions)
7983
val entityModels = modelExpressions
8084
.groupBy { it.intent }
81-
.map { (intent, expressions)
85+
.mapNotNull { (intent, expressions)
8286
->
83-
intent to nlpClassifier.buildEntityModel(
84-
EntityBuildContextForIntent(context, intent),
85-
expressions)
87+
try {
88+
intent to nlpClassifier.buildEntityModel(
89+
EntityBuildContextForIntent(context, intent),
90+
expressions)
91+
} catch (e: Exception) {
92+
logger.error { "entity model build fail for $intent " }
93+
logger.error(e)
94+
null
95+
}
8696
}
8797
.toMap()
8898

0 commit comments

Comments
 (0)