Skip to content

Commit 20a70a3

Browse files
olami-developersolami-developers
authored andcommitted
support kkbox music query
1 parent 3a49871 commit 20a70a3

12 files changed

Lines changed: 430 additions & 11 deletions

File tree

examples/async-text-chatbot-example/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<parent>
1414
<groupId>ai.olami</groupId>
1515
<artifactId>olami-java-client-sdk</artifactId>
16-
<version>1.4.0</version>
16+
<version>1.5.0</version>
1717
<relativePath>../../pom.xml</relativePath>
1818
</parent>
1919

@@ -35,7 +35,7 @@
3535
<dependency>
3636
<groupId>ai.olami.example</groupId>
3737
<artifactId>dump-nli-results-example</artifactId>
38-
<version>20180413</version>
38+
<version>20180522</version>
3939
</dependency>
4040
</dependencies>
4141

examples/dump-nli-results-example/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>ai.olami.example</groupId>
66
<artifactId>dump-nli-results-example</artifactId>
7-
<version>20180413</version>
7+
<version>20180522</version>
88
<packaging>jar</packaging>
99

1010
<name>OLAMI Java Client Examples: Dump NLI Results</name>
@@ -13,7 +13,7 @@
1313
<parent>
1414
<groupId>ai.olami</groupId>
1515
<artifactId>olami-java-client-sdk</artifactId>
16-
<version>1.4.0</version>
16+
<version>1.5.0</version>
1717
<relativePath>../../pom.xml</relativePath>
1818
</parent>
1919

examples/dump-nli-results-example/src/main/java/ai/olami/example/DumpIDSDataExample.java

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@
2626
import ai.olami.ids.IDSResult;
2727
import ai.olami.ids.JokeData;
2828
import ai.olami.ids.MathData;
29+
import ai.olami.ids.MusicControlData;
2930
import ai.olami.ids.NewsData;
31+
import ai.olami.ids.KKBOXData;
32+
import ai.olami.ids.KKBOXDataPhoto;
3033
import ai.olami.ids.OpenWebData;
3134
import ai.olami.ids.PoemData;
3235
import ai.olami.ids.StockMarketData;
@@ -144,6 +147,93 @@ public static void dumpIDSData(NLIResult nliResult) {
144147
}
145148
}
146149

150+
// ********************************************************************
151+
// * KKBOX EXAMPLE
152+
// *-------------------------------------------------------------------
153+
// * Simplified Chinese (China): ** 简体中文服务地区尚不支持此模块 **
154+
// * Traditional Chinese (Taiwan): 我要聽音樂
155+
// ********************************************************************
156+
// * Check to see if contains IDS KKBOX data
157+
if (nliResult.getType().equals(IDSResult.Types.KKBOX.getName())) {
158+
// Get all of KKBOXData into ArrayList.
159+
ArrayList<KKBOXData> dataArray = nliResult.getDataObjects();
160+
for (int x = 0; x < dataArray.size(); x++) {
161+
System.out.format("|\t- IDS KKBOX Data[%s] :\n", x);
162+
System.out.format("|\t\t- ID: %s\n",
163+
dataArray.get(x).getID());
164+
System.out.format("|\t\t- Duration: %s\n",
165+
dataArray.get(x).getDuration());
166+
System.out.format("|\t\t- Title: %s\n",
167+
dataArray.get(x).getTitle());
168+
System.out.format("|\t\t- Artist: [ID=%s], %s\n",
169+
dataArray.get(x).getArtistID(), dataArray.get(x).getArtist());
170+
System.out.format("|\t\t- Album: [ID=%s], %s\n",
171+
dataArray.get(x).getAlbumID(), dataArray.get(x).getAlbum());
172+
System.out.format("|\t\t- URL: %s\n",
173+
dataArray.get(x).getURL());
174+
// List photos
175+
if (dataArray.get(x).hasPhotos()) {
176+
KKBOXDataPhoto[] photoArray = dataArray.get(x).getPhotos();
177+
for (int i = 0; i < photoArray.length; i++) {
178+
System.out.format("|\t\t- Photo[%s]:\n", i);
179+
System.out.format("|\t\t\t- Width:%s , Hight:%s\n",
180+
photoArray[i].getWidth(), photoArray[i].getHeight());
181+
System.out.format("|\t\t\t- URL:%s\n",
182+
photoArray[i].getURL());
183+
}
184+
}
185+
}
186+
}
187+
188+
// ********************************************************************
189+
// * MUSIC CONTROL EXAMPLE
190+
// *-------------------------------------------------------------------
191+
// * Simplified Chinese (China): 下一首
192+
// * Traditional Chinese (Taiwan): 下一首
193+
// ********************************************************************
194+
// * Check to see if contains IDS MusicControl data
195+
if (nliResult.getType().equals(IDSResult.Types.MUSIC_CONTROL.getName())) {
196+
// Get all of MusicControlData into ArrayList.
197+
ArrayList<MusicControlData> dataArray = nliResult.getDataObjects();
198+
for (int x = 0; x < dataArray.size(); x++) {
199+
System.out.format("|\t- IDS MusicControl Data[%s] :\n", x);
200+
System.out.format("|\t\t- Index: %s\n",
201+
(dataArray.get(x).hasIndex() ? dataArray.get(x).getIndex() : "NO INDEX, [It means based on current/previous index] "));
202+
System.out.format("|\t\t- Command: %s \n",
203+
dataArray.get(x).getCommand());
204+
if (dataArray.get(x).getCommand().equals(MusicControlData.NEXT)) {
205+
System.out.println("|\t\t <播放下一首 / 播放下一首>");
206+
}
207+
if (dataArray.get(x).getCommand().equals(MusicControlData.PREVIOUS)) {
208+
System.out.println("|\t\t <播放上一首 / 播放上一首>");
209+
}
210+
if (dataArray.get(x).getCommand().equals(MusicControlData.PAUSE)) {
211+
System.out.println("|\t\t <暂停播放 / 暫停播放>");
212+
}
213+
if (dataArray.get(x).getCommand().equals(MusicControlData.PLAY)) {
214+
System.out.println("|\t\t <开始播放 / 開始播放>");
215+
}
216+
if (dataArray.get(x).getCommand().equals(MusicControlData.RANDOM)) {
217+
System.out.println("|\t\t <随机播放模式 / 隨機播放模式>");
218+
}
219+
if (dataArray.get(x).getCommand().equals(MusicControlData.LOOP)) {
220+
System.out.println("|\t\t <循环播放模式 / 循環播放模式>");
221+
}
222+
if (dataArray.get(x).getCommand().equals(MusicControlData.ORDER)) {
223+
System.out.println("|\t\t <顺序播放模式 / 順序播放模式>");
224+
}
225+
if (dataArray.get(x).getCommand().equals(MusicControlData.MUTE)) {
226+
System.out.println("|\t\t <设置为静音 / 設置為靜音>");
227+
}
228+
if (dataArray.get(x).getCommand().equals(MusicControlData.VOLUME_UP)) {
229+
System.out.println("|\t\t <音量增大 / 音量增大>");
230+
}
231+
if (dataArray.get(x).getCommand().equals(MusicControlData.VOLUME_DOWN)) {
232+
System.out.println("|\t\t <音量减小 / 音量減小>");
233+
}
234+
}
235+
}
236+
147237
// ********************************************************************
148238
// * TV PROGRAM EXAMPLE
149239
// *-------------------------------------------------------------------

examples/microphone-speech-input-example/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<parent>
1414
<groupId>ai.olami</groupId>
1515
<artifactId>olami-java-client-sdk</artifactId>
16-
<version>1.4.0</version>
16+
<version>1.5.0</version>
1717
<relativePath>../../pom.xml</relativePath>
1818
</parent>
1919

examples/speech-input-example/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<parent>
1414
<groupId>ai.olami</groupId>
1515
<artifactId>olami-java-client-sdk</artifactId>
16-
<version>1.4.0</version>
16+
<version>1.5.0</version>
1717
<relativePath>../../pom.xml</relativePath>
1818
</parent>
1919

@@ -34,7 +34,7 @@
3434
<dependency>
3535
<groupId>ai.olami.example</groupId>
3636
<artifactId>dump-nli-results-example</artifactId>
37-
<version>20180413</version>
37+
<version>20180522</version>
3838
</dependency>
3939
</dependencies>
4040

examples/text-input-example/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<parent>
1414
<groupId>ai.olami</groupId>
1515
<artifactId>olami-java-client-sdk</artifactId>
16-
<version>1.4.0</version>
16+
<version>1.5.0</version>
1717
<relativePath>../../pom.xml</relativePath>
1818
</parent>
1919

@@ -34,7 +34,7 @@
3434
<dependency>
3535
<groupId>ai.olami.example</groupId>
3636
<artifactId>dump-nli-results-example</artifactId>
37-
<version>20180413</version>
37+
<version>20180522</version>
3838
</dependency>
3939
</dependencies>
4040

lib/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<parent>
1313
<groupId>ai.olami</groupId>
1414
<artifactId>olami-java-client-sdk</artifactId>
15-
<version>1.4.0</version>
15+
<version>1.5.0</version>
1616
</parent>
1717

1818
<properties>

lib/src/main/java/ai/olami/ids/IDSResult.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public static enum Types {
4040
WEATHER ("weather", (new TypeToken<ArrayList<WeatherData>>() {}).getType()),
4141
BAIKE ("baike", (new TypeToken<ArrayList<BaikeData>>() {}).getType()),
4242
NEWS ("news", (new TypeToken<ArrayList<NewsData>>() {}).getType()),
43+
KKBOX ("kkbox", (new TypeToken<ArrayList<KKBOXData>>() {}).getType()),
44+
MUSIC_CONTROL ("MusicControl", (new TypeToken<ArrayList<MusicControlData>>() {}).getType()),
4345
TV_PROGRAM ("tvprogram", (new TypeToken<ArrayList<TVProgramData>>() {}).getType()),
4446
POEM ("poem", (new TypeToken<ArrayList<PoemData>>() {}).getType()),
4547
JOKE ("joke", (new TypeToken<ArrayList<JokeData>>() {}).getType()),
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
/*
2+
Copyright 2018, VIA Technologies, Inc. & OLAMI Team.
3+
4+
http://olami.ai
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
package ai.olami.ids;
20+
21+
import com.google.gson.annotations.Expose;
22+
import com.google.gson.annotations.SerializedName;
23+
24+
public class KKBOXData {
25+
26+
@Expose
27+
@SerializedName("id")
28+
private String mID = null;
29+
30+
/**
31+
* @return ID.
32+
*/
33+
public String getID() {
34+
return (mID == null) ? "" : mID;
35+
}
36+
37+
/**
38+
* @return TRUE if contains ID.
39+
*/
40+
public boolean hasID() {
41+
return ((mID != null) && (!mID.equals("")));
42+
}
43+
44+
@Expose
45+
@SerializedName("title")
46+
private String mTitle = null;
47+
48+
/**
49+
* @return Title.
50+
*/
51+
public String getTitle() {
52+
return (mTitle == null) ? "" : mTitle;
53+
}
54+
55+
/**
56+
* @return TRUE if contains title.
57+
*/
58+
public boolean hasTitle() {
59+
return ((mTitle != null) && (!mTitle.equals("")));
60+
}
61+
62+
@Expose
63+
@SerializedName("artist")
64+
private String mArtist = null;
65+
66+
/**
67+
* @return Artist.
68+
*/
69+
public String getArtist() {
70+
return (mArtist == null) ? "" : mArtist;
71+
}
72+
73+
/**
74+
* @return TRUE if contains artist.
75+
*/
76+
public boolean hasArtist() {
77+
return ((mArtist != null) && (!mArtist.equals("")));
78+
}
79+
80+
@Expose
81+
@SerializedName("artistId")
82+
private String mArtistID = null;
83+
84+
/**
85+
* @return Artist ID.
86+
*/
87+
public String getArtistID() {
88+
return (mArtistID == null) ? "" : mArtistID;
89+
}
90+
91+
/**
92+
* @return TRUE if contains artist ID.
93+
*/
94+
public boolean hasArtistID() {
95+
return ((mArtistID != null) && (!mArtistID.equals("")));
96+
}
97+
98+
@Expose
99+
@SerializedName("album")
100+
private String mAlbum = null;
101+
102+
/**
103+
* @return Album.
104+
*/
105+
public String getAlbum() {
106+
return (mAlbum == null) ? "" : mAlbum;
107+
}
108+
109+
/**
110+
* @return TRUE if contains album.
111+
*/
112+
public boolean hasAlbum() {
113+
return ((mAlbum != null) && (!mAlbum.equals("")));
114+
}
115+
116+
@Expose
117+
@SerializedName("albumId")
118+
private String mAlbumID = null;
119+
120+
/**
121+
* @return Album ID.
122+
*/
123+
public String getAlbumID() {
124+
return (mAlbumID == null) ? "" : mAlbumID;
125+
}
126+
127+
/**
128+
* @return TRUE if contains album ID.
129+
*/
130+
public boolean hasAlbumID() {
131+
return ((mAlbumID != null) && (!mAlbumID.equals("")));
132+
}
133+
134+
@Expose
135+
@SerializedName("time")
136+
private String mDurationTime = null;
137+
138+
/**
139+
* @return Duration of time in milliseconds.
140+
*/
141+
public long getDuration() {
142+
return (hasDuration() ? Long.parseLong(mDurationTime) : 0);
143+
}
144+
145+
/**
146+
* @return TRUE if contains duration.
147+
*/
148+
public boolean hasDuration() {
149+
return ((mDurationTime != null) && (!mDurationTime.equals("")));
150+
}
151+
152+
@Expose
153+
@SerializedName("url")
154+
private String mURL = null;
155+
156+
/**
157+
* @return URL.
158+
*/
159+
public String getURL() {
160+
return (mURL == null) ? "" : mURL;
161+
}
162+
163+
/**
164+
* @return TRUE if contains URL.
165+
*/
166+
public boolean hasURL() {
167+
return ((mURL != null) && (!mURL.equals("")));
168+
}
169+
170+
@Expose
171+
@SerializedName("photo")
172+
private KKBOXDataPhoto[] mKKBOXDataPhotos = null;
173+
174+
/**
175+
* @return Photo information array.
176+
*/
177+
public KKBOXDataPhoto[] getPhotos() {
178+
return mKKBOXDataPhotos;
179+
}
180+
181+
/**
182+
* @return TRUE if contains photo information.
183+
*/
184+
public boolean hasPhotos() {
185+
return ((mKKBOXDataPhotos != null) && (mKKBOXDataPhotos.length > 0));
186+
}
187+
188+
}

0 commit comments

Comments
 (0)