-
Notifications
You must be signed in to change notification settings - Fork 1
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
Данила Беляков
authored and
Данила Беляков
committed
Nov 19, 2024
1 parent
c41d16e
commit e33fa1d
Showing
75 changed files
with
740 additions
and
265 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,4 +39,7 @@ bin/ | |
.vscode/ | ||
|
||
### Mac OS ### | ||
.DS_Store | ||
.DS_Store | ||
|
||
.idea | ||
.kotlin |
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
79 changes: 79 additions & 0 deletions
79
alice-ktx/src/main/kotlin/com/github/alice/ktx/common/serializers/NluEntitySerializer.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,79 @@ | ||
package com.github.alice.ktx.common.serializers | ||
|
||
import com.github.alice.ktx.models.request.nlu.NluEntity | ||
import com.github.alice.ktx.models.request.nlu.NluEntityToken | ||
import com.github.alice.ktx.models.request.nlu.NluEntityType | ||
import com.github.alice.ktx.models.request.nlu.NluValue | ||
import kotlinx.serialization.KSerializer | ||
import kotlinx.serialization.descriptors.SerialDescriptor | ||
import kotlinx.serialization.descriptors.buildClassSerialDescriptor | ||
import kotlinx.serialization.descriptors.element | ||
import kotlinx.serialization.encoding.Decoder | ||
import kotlinx.serialization.encoding.Encoder | ||
import kotlinx.serialization.json.* | ||
|
||
internal object NluEntitySerializer : KSerializer<NluEntity> { | ||
override val descriptor: SerialDescriptor = buildClassSerialDescriptor("NluEntity") { | ||
element<NluEntityToken>("tokens") | ||
element<NluEntityType>("type") | ||
element<JsonElement>("value") | ||
} | ||
|
||
override fun serialize(encoder: Encoder, value: NluEntity) { | ||
val jsonEncoder = encoder as? JsonEncoder ?: error("Only Json is supported") | ||
val json = buildJsonObject { | ||
put("tokens", jsonEncoder.json.encodeToJsonElement(value.tokens)) | ||
put("type", value.type.serialName()) | ||
put( | ||
"value", | ||
when (val nluValue = value.value) { | ||
is NluValue.GeoValue -> jsonEncoder.json.encodeToJsonElement(nluValue) | ||
is NluValue.FioValue -> jsonEncoder.json.encodeToJsonElement(nluValue) | ||
is NluValue.DateTimeValue -> jsonEncoder.json.encodeToJsonElement(nluValue) | ||
is NluValue.NumberValue -> JsonPrimitive(nluValue.number) | ||
} | ||
) | ||
} | ||
jsonEncoder.encodeJsonElement(json) | ||
} | ||
|
||
override fun deserialize(decoder: Decoder): NluEntity { | ||
val jsonDecoder = decoder as? JsonDecoder ?: error("Only Json is supported") | ||
val jsonObject = jsonDecoder.decodeJsonElement().jsonObject | ||
|
||
val tokensJson = jsonObject["tokens"] ?: error("Missing 'tokens'") | ||
val typeJson = jsonObject["type"]?.jsonPrimitive?.content ?: error("Missing 'type'") | ||
val valueJson = jsonObject["value"] ?: error("Missing 'value'") | ||
|
||
val nluEntityToken = jsonDecoder.json.decodeFromJsonElement<NluEntityToken>(tokensJson) | ||
val type = fromSerialName(typeJson) | ||
|
||
val nluValue: NluValue = when (type) { | ||
NluEntityType.GEO -> jsonDecoder.json.decodeFromJsonElement<NluValue.GeoValue>(valueJson) | ||
NluEntityType.FIO -> jsonDecoder.json.decodeFromJsonElement<NluValue.FioValue>(valueJson) | ||
NluEntityType.DATETIME -> jsonDecoder.json.decodeFromJsonElement<NluValue.DateTimeValue>(valueJson) | ||
NluEntityType.NUMBER -> NluValue.NumberValue(valueJson.jsonPrimitive.float) | ||
} | ||
|
||
return NluEntity(nluEntityToken, type, nluValue) | ||
} | ||
} | ||
|
||
private fun NluEntityType.serialName(): String { | ||
return when (this) { | ||
NluEntityType.FIO -> "YANDEX.FIO" | ||
NluEntityType.GEO -> "YANDEX.GEO" | ||
NluEntityType.DATETIME -> "YANDEX.DATETIME" | ||
NluEntityType.NUMBER -> "YANDEX.NUMBER" | ||
} | ||
} | ||
|
||
private fun fromSerialName(serialName: String): NluEntityType { | ||
return when (serialName) { | ||
"YANDEX.FIO" -> NluEntityType.FIO | ||
"YANDEX.GEO" -> NluEntityType.GEO | ||
"YANDEX.DATETIME" -> NluEntityType.DATETIME | ||
"YANDEX.NUMBER" -> NluEntityType.NUMBER | ||
else -> throw IllegalArgumentException("Unknown type: $serialName") | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
alice-ktx/src/main/kotlin/com/github/alice/ktx/fsm/MutableFSMContext.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
2 changes: 1 addition & 1 deletion
2
alice-ktx/src/main/kotlin/com/github/alice/ktx/fsm/ReadOnlyFSMContext.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
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
...om/github/alice/ktx/models/FSMStrategy.kt → ...ithub/alice/ktx/fsm/models/FSMStrategy.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
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
alice-ktx/src/main/kotlin/com/github/alice/ktx/handlers/filters/Filter.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
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
6 changes: 0 additions & 6 deletions
6
alice-ktx/src/main/kotlin/com/github/alice/ktx/models/audioPlayer/AudioPlayerAction.kt
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
alice-ktx/src/main/kotlin/com/github/alice/ktx/models/audioPlayer/AudioPlayerItem.kt
This file was deleted.
Oops, something went wrong.
24 changes: 0 additions & 24 deletions
24
alice-ktx/src/main/kotlin/com/github/alice/ktx/models/audioPlayer/AudioPlayerMetadata.kt
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
alice-ktx/src/main/kotlin/com/github/alice/ktx/models/audioPlayer/AudioPlayerStream.kt
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
alice-ktx/src/main/kotlin/com/github/alice/ktx/models/card/CardHeader.kt
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
alice-ktx/src/main/kotlin/com/github/alice/ktx/models/request/Application.kt
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
alice-ktx/src/main/kotlin/com/github/alice/ktx/models/request/Markup.kt
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
alice-ktx/src/main/kotlin/com/github/alice/ktx/models/request/MessageRequest.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
13 changes: 0 additions & 13 deletions
13
alice-ktx/src/main/kotlin/com/github/alice/ktx/models/request/Metadata.kt
This file was deleted.
Oops, something went wrong.
26 changes: 0 additions & 26 deletions
26
alice-ktx/src/main/kotlin/com/github/alice/ktx/models/request/MetadataInterfaces.kt
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
alice-ktx/src/main/kotlin/com/github/alice/ktx/models/request/Nlu.kt
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
alice-ktx/src/main/kotlin/com/github/alice/ktx/models/request/RequestContent.kt
This file was deleted.
Oops, something went wrong.
19 changes: 0 additions & 19 deletions
19
alice-ktx/src/main/kotlin/com/github/alice/ktx/models/request/Session.kt
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
alice-ktx/src/main/kotlin/com/github/alice/ktx/models/request/User.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.