-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
89 additions
and
5 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
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
2 changes: 1 addition & 1 deletion
2
...nnel/yandexalice/api/model/AliceIntent.kt → .../jaicf/channel/yandexalice/AliceIntent.kt
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
33 changes: 33 additions & 0 deletions
33
...ce/src/main/kotlin/com/justai/jaicf/channel/yandexalice/activator/AliceIntentActivator.kt
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,33 @@ | ||
package com.justai.jaicf.channel.yandexalice.activator | ||
|
||
import com.justai.jaicf.activator.Activator | ||
import com.justai.jaicf.activator.ActivatorFactory | ||
import com.justai.jaicf.activator.intent.BaseIntentActivator | ||
import com.justai.jaicf.activator.intent.IntentActivatorContext | ||
import com.justai.jaicf.api.BotRequest | ||
import com.justai.jaicf.channel.yandexalice.api.AliceBotRequest | ||
import com.justai.jaicf.context.BotContext | ||
import com.justai.jaicf.model.scenario.ScenarioModel | ||
|
||
class AliceIntentActivator(model: ScenarioModel): BaseIntentActivator(model) { | ||
|
||
override fun canHandle(request: BotRequest) = request is AliceBotRequest | ||
|
||
override fun recogniseIntent(botContext: BotContext, request: BotRequest): IntentActivatorContext? { | ||
val aliceRequest = request as? AliceBotRequest ?: return null | ||
|
||
val intent = aliceRequest.request?.let { req -> | ||
req.nlu.intents.map { entry -> | ||
findState(entry.key, botContext) to entry | ||
}.maxBy { it.first?.count { c -> c == '/'} ?: 0 }?.second | ||
} | ||
|
||
return intent?.let { | ||
AliceIntentActivatorContext(it.key, it.value) | ||
} | ||
} | ||
|
||
companion object : ActivatorFactory { | ||
override fun create(model: ScenarioModel) = AliceIntentActivator(model) | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...main/kotlin/com/justai/jaicf/channel/yandexalice/activator/AliceIntentActivatorContext.kt
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,18 @@ | ||
package com.justai.jaicf.channel.yandexalice.activator | ||
|
||
import com.justai.jaicf.activator.intent.IntentActivatorContext | ||
import com.justai.jaicf.channel.yandexalice.api.Request | ||
import com.justai.jaicf.context.ActivatorContext | ||
|
||
class AliceIntentActivatorContext( | ||
intentName: String, | ||
intentSlots: Request.Nlu.Intent | ||
): IntentActivatorContext( | ||
confidence = 1f, | ||
intent = intentName | ||
) { | ||
val slots = intentSlots.slots | ||
} | ||
|
||
val ActivatorContext.alice | ||
get() = this as? AliceIntentActivatorContext |
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