Bixby development center의 Quick Start Guide를 따라하며 정리한 글이다.
여기에서는 빅스비 캡슐 샘플인 주사위 굴리기 캡슐을 이용하여 진행한다.
Concept
과 Action
은 캡슐의 구성 요소이다.
Concept
: 빅스비가 알아야 할 것들(input 라고 생각하면 됨)
Action
: 빅스비가 할 수 있는 행동들을 정의(method 라고 생각하면 됨)
얘네들은 ~/models/
안에 정의되어 있는데, models 폴더 구성은 다음과 같다.
primitives
primitives는 integers, booleans, decimals, text와 같은 simple type variable들을 나타낸다.
아래의 코드는 NumDiceConcpet라는 변수가 integer type이며, 이 변수에 대한 설명은 description에 나와 있는 바와 같다. 이 코드처럼 변수를 설정할 수 있다.
//NumDice.model.bxb
integer (NumDiceConcept) {
description (The number of dice to throw.)
}
structures
structures는 multiple primitives를 가지는 record이다.
아래의 코드와 같이 integer type의 SumConcept
와 RollConcept
primitive가 ~/models/primitives
에 정의되어 있다고 하자.
//Sum.model.bxb
integer (SumConcept) {
description (The total sum of all the dice rolled.)
}
//Roll.model.bxb
integer (RollConcept) {
description (The result of a dice roll.)
}
~/models/structures
에서는 SumConcept
와 RollConcept
모두를 가진 structure를 선언할 수 있는데, 이 방법은 다음과 같다.
//RollResult.model.bxb
structure (RollResultConcept) {
description (The result object produced by the RollDice action.)
property (sum) {
type (SumConcept)
min (Required)
max (One)
}
property (roll) {
description (The list of results for each dice roll.)
type (RollConcept)
min (Required)
max (Many)
}
}
이 예제에서는 RollResult
가 action
의 결과물 역할을 할 것이기 때문에 안에 정의되어있는 sum
과 roll
property는 hold되어야 한다. 따라서, 각 property마다 min (Required)
라는 조건이 붙었다. 또한, 주사위를 굴리면서 나온 눈의 합을 담는 sum
property는 하나만 존재하면 되므로 max (One)
옵션이 붙었고, 주사위를 굴리면서 나온 눈의 모든 경우를 저장하는 roll
property는 여러개가 존재해야 하므로 max (Many)
옵션이 붙었다.
이제 위의 예제를 돌려보자. 시뮬레이터가 아주 쌈빡하다.
왼쪽의 input panel에 다음의 스크립트를 넣고, 실행시킨다.
// Give two values (number of dice and number of sides) with the
// goal of rolling dice
intent {
goal: example.dice.RollResultConcept
value: example.dice.NumSidesConcept (6)
value: example.dice.NumDiceConcept (2)
}
입력값으로 하나의 goal(RollResultConcept)과 두 개의 입력(주사위 면의 개수, 주사위를 굴릴 개수)를 주었고, 이를 실행시키면 다음과 같은 결과를 얻는다.
이와 같이 주사위를 두번 굴려서 5, 2를 얻었고 주사위 눈의 합은 7인 것을 얻을 수 있다.
Debug console을 열어보면 다음과 같다. 이 예제에서는 RollDice라는 action 1개만을 이용하였지만, 비행기 티켓을 사는 것과 같은 케이스에서는 여러 개의 action이 순차적으로 진행될 수도 있다.
모르겠고 일단 필요해 보이는거 적음
(캡슐이 이해하고 처리할 발화를 입력) - 문자열을 다루는 방식
enum
enum (Plant) {
description(리스트를 한정할 수 있는 경우)
symbol (Venus)
symbol (Earth)
}
name
name (SearchCriterion) {
description(어쩌구저쩌구)
}
text
text (Input) {
description(어쩌구저쩌구)
}
Vocab
resources > 각 언어의 training이 있는 곳에 생성 권유
training 우클릭 > New > Vocabulary
// concept
enum (Planet) {
description(리스트를 나열할 수 있는 경우)
symbol (Mercury)
symbol (Venus)
symbol (Earth)
symbol (Mars)
}
// vocab(필수)
// key {Vocab}
vocab (Planet) {
"Mercury" {"수성"}
"Venus " {"금성"}
"Earth" {"지구"}
"Mars" {"Mars"}
}
응, 네, 아니오 같은 일반적인 발화는 예약 발화로 빅스비 플랫폼에서 제공함
//concept
boolean (Confirmation) {
extends(common.Confirmation)
}
//vocab(선택)
vocab (Confirmation) {
"true" {
"예약" "예약해" "결제" "결제해" "승인" "주문"
}
"false" {
"안 할래" "결제 취소"
}
}
vocab에 포함된 단어는 학습을 따로 하지 않아도 concept을 알아서 찾음
학습을 할 때 vocab에 포함된 단어로도 일부 학습을 하고, 포함되지 않은 단어들로도 일부 학습을 하면 알아서 찾아줌.
//concept
name (SearchCriteria) {
description(어느 정도 나열은 할 수 있지만, 개수가 한정되지 않은 것)
}
//vocab(선택)
vocab (SearchCriteria) {
"카지노"
"유아 동반"
"키즈룸"
"애완동물"
}
(입력한 발화에 대해 어떤 기능을 수행할지를 결정)
각 발화에 대한 결과를 말함.
bixby developer center에서 library capsule이라고 검색하면 나옴
// capsule.bxb
capsule {
...
capsule-imports {
import(viv.core) {
as (core)
}
import(viv.geo) {
as (geo)
version (9.17.4)
}
}
permissions {
// 이 캡슐이 user-profile에 접근할 때, 팝업을 통해 사용자의 동의를 받는 것
// viv.geo를 사용할 때는 반드시 permissions > user-profile-access를 필수로 넣어야 함
user-profile-access
}
}