├── lib ├── .gitignore ├── src │ └── main │ │ └── java │ │ ├── ai │ │ └── olami │ │ │ ├── ids │ │ │ ├── OpenWebData.java │ │ │ ├── JokeData.java │ │ │ ├── ExchangeRateData.java │ │ │ ├── KKBOXDataPhoto.java │ │ │ ├── CookingData.java │ │ │ ├── MathData.java │ │ │ ├── TVProgramData.java │ │ │ ├── MusicControlData.java │ │ │ ├── PoemData.java │ │ │ ├── UnitConvertData.java │ │ │ ├── NewsData.java │ │ │ ├── BaikeData.java │ │ │ ├── IDSResult.java │ │ │ ├── KKBOXData.java │ │ │ ├── WeatherData.java │ │ │ └── StockMarketData.java │ │ │ ├── cloudService │ │ │ ├── APIResponseBuilder.java │ │ │ ├── CookieSet.java │ │ │ ├── SpeechResult.java │ │ │ ├── APIResponseData.java │ │ │ ├── NLIConfig.java │ │ │ ├── APIRequestBase.java │ │ │ ├── APIResponse.java │ │ │ └── TextRecognizer.java │ │ │ ├── nli │ │ │ ├── slot │ │ │ │ ├── NumDetail.java │ │ │ │ ├── DateTime.java │ │ │ │ ├── RepeatRule.java │ │ │ │ ├── DateTimeData.java │ │ │ │ ├── ExtendInfo.java │ │ │ │ ├── TimeStruct.java │ │ │ │ └── Slot.java │ │ │ ├── Semantic.java │ │ │ ├── NLIResult.java │ │ │ └── DescObject.java │ │ │ └── util │ │ │ ├── GsonFactory.java │ │ │ └── HttpClient.java │ │ └── org │ │ └── xiph │ │ └── speex │ │ ├── Misc.java │ │ ├── RawWriter.java │ │ ├── Inband.java │ │ ├── CbSearch.java │ │ ├── OggCrc.java │ │ ├── NoiseSearch.java │ │ ├── LtpForcedPitch.java │ │ ├── HighLspQuant.java │ │ ├── Decoder.java │ │ └── SubMode.java └── pom.xml ├── examples ├── .gitignore ├── dump-nli-results-example │ ├── .gitignore │ ├── README.md │ ├── src │ │ └── main │ │ │ └── java │ │ │ └── ai │ │ │ └── olami │ │ │ └── example │ │ │ └── DumpNLIResultsExampleExecution.java │ └── pom.xml ├── speech-input-example │ ├── sample.pcm │ ├── sample.wav │ ├── README.md │ └── pom.xml ├── text-input-example │ ├── README.md │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── ai │ │ └── olami │ │ └── example │ │ └── TextInputExample.java ├── async-text-chatbot-example │ ├── README.md │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── ai │ │ └── olami │ │ └── example │ │ └── AsyncTextChatbotExample.java └── microphone-speech-input-example │ ├── README.md │ ├── src │ └── main │ │ └── java │ │ └── ai │ │ └── olami │ │ └── example │ │ └── ISpeechRecognizerListenerExample.java │ └── pom.xml ├── README.md ├── .gitignore └── pom.xml /lib/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.jar 3 | -------------------------------------------------------------------------------- /examples/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.jar 3 | -------------------------------------------------------------------------------- /examples/dump-nli-results-example/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /examples/speech-input-example/sample.pcm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/olami-developers/olami-java-client-sdk/HEAD/examples/speech-input-example/sample.pcm -------------------------------------------------------------------------------- /examples/speech-input-example/sample.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/olami-developers/olami-java-client-sdk/HEAD/examples/speech-input-example/sample.wav -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OLAMI Java Client SDK 2 | 3 | This is a repository that contains Java SDK and code examples for using OLAMI HTTP APIs, an offering within **OLAMI Open AI**. 4 | 5 | OLAMI website and documentation: [http://olami.ai](http://olami.ai) 6 | 7 | - [简体中文在线说明文档](http://cn.olami.ai/wiki/?mp=sdk&content=sdk/java/reference.html) 8 | 9 | - [繁體中文線上說明文件](http://tw.olami.ai/wiki/?mp=sdk&content=sdk/java/reference.html) 10 | -------------------------------------------------------------------------------- /examples/text-input-example/README.md: -------------------------------------------------------------------------------- 1 | # OLAMI Java Client SDK 2 | 3 | This is a repository that contains Java code examples for using OLAMI Java Client SDK, an offering within **OLAMI Open AI**. 4 | 5 | OLAMI website and documentation: [http://olami.ai](http://olami.ai) 6 | 7 | - [简体中文在线说明文档](http://cn.olami.ai/wiki/?mp=sdk&content=sdk/java/examples/text-input-example/reference.html) 8 | 9 | - [繁體中文線上說明文件](http://tw.olami.ai/wiki/?mp=sdk&content=sdk/java/examples/text-input-example/reference.html) 10 | -------------------------------------------------------------------------------- /examples/speech-input-example/README.md: -------------------------------------------------------------------------------- 1 | # OLAMI Java Client SDK 2 | 3 | This is a repository that contains Java code examples for using OLAMI Java Client SDK, an offering within **OLAMI Open AI**. 4 | 5 | OLAMI website and documentation: [http://olami.ai](http://olami.ai) 6 | 7 | - [简体中文在线说明文档](http://cn.olami.ai/wiki/?mp=sdk&content=sdk/java/examples/speech-input-example/reference.html) 8 | 9 | - [繁體中文線上說明文件](http://tw.olami.ai/wiki/?mp=sdk&content=sdk/java/examples/speech-input-example/reference.html) 10 | -------------------------------------------------------------------------------- /examples/dump-nli-results-example/README.md: -------------------------------------------------------------------------------- 1 | # OLAMI Java Client SDK 2 | 3 | This is a repository that contains Java code examples for using OLAMI Java Client SDK, an offering within **OLAMI Open AI**. 4 | 5 | OLAMI website and documentation: [http://olami.ai](http://olami.ai) 6 | 7 | - [简体中文在线说明文档](http://cn.olami.ai/wiki/?mp=sdk&content=sdk/java/examples/dump-nli-results-example/reference.html) 8 | 9 | - [繁體中文線上說明文件](http://tw.olami.ai/wiki/?mp=sdk&content=sdk/java/examples/dump-nli-results-example/reference.html) 10 | -------------------------------------------------------------------------------- /examples/async-text-chatbot-example/README.md: -------------------------------------------------------------------------------- 1 | # OLAMI Java Client SDK 2 | 3 | This is a repository that contains Java code examples for using OLAMI Java Client SDK, an offering within **OLAMI Open AI**. 4 | 5 | OLAMI website and documentation: [http://olami.ai](http://olami.ai) 6 | 7 | - [简体中文在线说明文档](http://cn.olami.ai/wiki/?mp=sdk&content=sdk/java/examples/async-text-chatbot-example/reference.html) 8 | 9 | - [繁體中文線上說明文件](http://tw.olami.ai/wiki/?mp=sdk&content=sdk/java/examples/async-text-chatbot-example/reference.html) 10 | -------------------------------------------------------------------------------- /examples/microphone-speech-input-example/README.md: -------------------------------------------------------------------------------- 1 | # OLAMI Java Client SDK 2 | 3 | This is a repository that contains Java code examples for using OLAMI Java Client SDK, an offering within **OLAMI Open AI**. 4 | 5 | OLAMI website and documentation: [http://olami.ai](http://olami.ai) 6 | 7 | - [简体中文在线说明文档](http://cn.olami.ai/wiki/?mp=sdk&content=sdk/java/examples/microphone-speech-input-example/reference.html) 8 | 9 | - [繁體中文線上說明文件](http://tw.olami.ai/wiki/?mp=sdk&content=sdk/java/examples/microphone-speech-input-example/reference.html) 10 | -------------------------------------------------------------------------------- /lib/src/main/java/ai/olami/ids/OpenWebData.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017, 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 OpenWebData { 25 | 26 | @Expose 27 | @SerializedName("url") 28 | private String mURL = null; 29 | 30 | /** 31 | * @return URL. 32 | */ 33 | public String getURL() { 34 | return (mURL == null) ? "" : mURL; 35 | } 36 | 37 | /** 38 | * @return TRUE if contains URL. 39 | */ 40 | public boolean hasURL() { 41 | return ((mURL != null) && (!mURL.equals(""))); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | bin 3 | 4 | # Mobile Tools for Java (J2ME) 5 | .mtj.tmp/ 6 | 7 | # Package Files # 8 | *.war 9 | *.ear 10 | 11 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 12 | hs_err_pid* 13 | 14 | # ========================= 15 | # Operating System Files 16 | # ========================= 17 | 18 | # OSX 19 | # ========================= 20 | 21 | .DS_Store 22 | .AppleDouble 23 | .LSOverride 24 | 25 | # Thumbnails 26 | ._* 27 | 28 | # Files that might appear in the root of a volume 29 | .DocumentRevisions-V100 30 | .fseventsd 31 | .Spotlight-V100 32 | .TemporaryItems 33 | .Trashes 34 | .VolumeIcon.icns 35 | 36 | # Directories potentially created on remote AFP share 37 | .AppleDB 38 | .AppleDesktop 39 | Network Trash Folder 40 | Temporary Items 41 | .apdisk 42 | 43 | # Windows 44 | # ========================= 45 | 46 | # Windows image file caches 47 | Thumbs.db 48 | ehthumbs.db 49 | 50 | # Folder config file 51 | Desktop.ini 52 | 53 | # Recycle Bin used on file shares 54 | $RECYCLE.BIN/ 55 | 56 | # Windows Installer files 57 | *.cab 58 | *.msi 59 | *.msm 60 | *.msp 61 | 62 | # Windows shortcuts 63 | *.lnk 64 | 65 | # Eclipse 66 | .project 67 | .settings 68 | .metadata 69 | RemoteSystemsTempFiles 70 | 71 | # Maven 72 | target 73 | .classpath 74 | -------------------------------------------------------------------------------- /lib/src/main/java/ai/olami/ids/JokeData.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017, 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 JokeData { 25 | 26 | @Expose 27 | @SerializedName("content") 28 | private String mContent = null; 29 | 30 | /** 31 | * @return Content. 32 | */ 33 | public String getContent() { 34 | return (mContent == null) ? "" : mContent; 35 | } 36 | 37 | /** 38 | * @return TRUE if contains content. 39 | */ 40 | public boolean hasContent() { 41 | return ((mContent != null) && (!mContent.equals(""))); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /examples/dump-nli-results-example/src/main/java/ai/olami/example/DumpNLIResultsExampleExecution.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017, 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.example; 20 | 21 | import ai.olami.cloudService.APIResponse; 22 | import ai.olami.cloudService.APIResponseBuilder; 23 | 24 | public class DumpNLIResultsExampleExecution { 25 | 26 | public static void main(String[] args) throws Exception { 27 | if (args.length == 1) { 28 | APIResponse response = APIResponseBuilder.create(args[0]); 29 | if (response.hasData() && response.getData().hasNLIResults()) { 30 | DumpNLIResultsExample.dumpNLIResults(response.getData().getNLIResults()); 31 | } else { 32 | System.out.println("Failed! Invalid Input String."); 33 | } 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /lib/src/main/java/ai/olami/ids/ExchangeRateData.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017, 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 ExchangeRateData { 25 | 26 | @Expose 27 | @SerializedName("target_currency") 28 | private String mTargetCurrency = null; 29 | 30 | /** 31 | * @return Target currency. 32 | */ 33 | public String getTargetCurrency() { 34 | return (mTargetCurrency == null) ? "" : mTargetCurrency; 35 | } 36 | 37 | /** 38 | * @return TRUE if contains target currency. 39 | */ 40 | public boolean hasTargetCurrency() { 41 | return ((mTargetCurrency != null) && (!mTargetCurrency.equals(""))); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /examples/microphone-speech-input-example/src/main/java/ai/olami/example/ISpeechRecognizerListenerExample.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017, 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 | package ai.olami.example; 19 | 20 | public interface ISpeechRecognizerListenerExample { 21 | 22 | /** 23 | * Callback when the recognize process state changes. 24 | */ 25 | void onRecognizeComplete(); 26 | 27 | /** 28 | * Callback when the results of speech recognition changes. 29 | * 30 | * @param recognitionTextResult - Speech-to-Text result. 31 | */ 32 | void onRecognizeResultChange(String recognitionTextResult); 33 | 34 | /** 35 | * Callback when the status of speech recognition changes. 36 | * 37 | * @param statusMessage - Status Message. 38 | */ 39 | void onRecognizeStatusChange(String statusMessage); 40 | 41 | /** 42 | * Callback when error occurs. 43 | * 44 | * @param errorMessage - Error Message. 45 | */ 46 | void onError(String errorMessage); 47 | 48 | } 49 | -------------------------------------------------------------------------------- /lib/src/main/java/ai/olami/cloudService/APIResponseBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017, 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.cloudService; 20 | 21 | import ai.olami.util.GsonFactory; 22 | 23 | public class APIResponseBuilder { 24 | 25 | /** 26 | * Create API response instance by the specified response JSON string. 27 | * 28 | * @param jsonString - API Response JSON string. 29 | * @return The instance mapped to the specified response JSON string. 30 | */ 31 | public static APIResponse create(String jsonString) { 32 | 33 | APIResponse response = null; 34 | 35 | try { 36 | response = (APIResponse) GsonFactory.getNormalGson().fromJson(jsonString, APIResponse.class); 37 | response.setJsonStringSource(jsonString); 38 | } catch (Exception e) { 39 | response.setInvalid("Invalid Response Content --> \n" + jsonString + "\n\n" + e.getMessage()); 40 | e.printStackTrace(); 41 | } 42 | 43 | return response; 44 | 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /lib/src/main/java/ai/olami/ids/KKBOXDataPhoto.java: -------------------------------------------------------------------------------- 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 KKBOXDataPhoto { 25 | 26 | @Expose 27 | @SerializedName("width") 28 | private int mWidth = 0; 29 | 30 | /** 31 | * @return Width. 32 | */ 33 | public int getWidth() { 34 | return mWidth; 35 | } 36 | 37 | @Expose 38 | @SerializedName("height") 39 | private int mHeight = 0; 40 | 41 | /** 42 | * @return Height. 43 | */ 44 | public int getHeight() { 45 | return mHeight; 46 | } 47 | 48 | @Expose 49 | @SerializedName("url") 50 | private String mURL = null; 51 | 52 | /** 53 | * @return URL. 54 | */ 55 | public String getURL() { 56 | return (mURL == null) ? "" : mURL; 57 | } 58 | 59 | /** 60 | * @return TRUE if contains URL. 61 | */ 62 | public boolean hasURL() { 63 | return ((mURL != null) && (!mURL.equals(""))); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /lib/src/main/java/ai/olami/cloudService/CookieSet.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017, 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.cloudService; 20 | 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | import java.util.UUID; 24 | 25 | public class CookieSet { 26 | 27 | private String mUniqueId = UUID.randomUUID().toString(); 28 | private List mMainCookies = null; 29 | 30 | /** 31 | * List of cookies. 32 | */ 33 | public CookieSet() { 34 | mMainCookies = new ArrayList(); 35 | } 36 | 37 | /** 38 | * Get unique ID. 39 | * 40 | * @return The unique ID of this CookieSet. 41 | */ 42 | public String getUniqueID() { 43 | return mUniqueId; 44 | } 45 | 46 | /** 47 | * Set cookies 48 | * 49 | * @param contents - Cookies. 50 | */ 51 | public void setContents(List contents) { 52 | mMainCookies = contents; 53 | } 54 | 55 | /** 56 | * Get cookies 57 | * 58 | * @return Cookies. 59 | */ 60 | public List getContents() { 61 | return mMainCookies; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /lib/src/main/java/ai/olami/ids/CookingData.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017, 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 CookingData { 25 | 26 | @Expose 27 | @SerializedName("content") 28 | private String mContent = null; 29 | 30 | /** 31 | * @return Content. 32 | */ 33 | public String getContent() { 34 | return (mContent == null) ? "" : mContent; 35 | } 36 | 37 | /** 38 | * @return TRUE if contains content information. 39 | */ 40 | public boolean hasContent() { 41 | return ((mContent != null) && (!mContent.equals(""))); 42 | } 43 | 44 | @Expose 45 | @SerializedName("name") 46 | private String mName = null; 47 | 48 | /** 49 | * @return Name. 50 | */ 51 | public String getName() { 52 | return (mName == null) ? "" : mName; 53 | } 54 | 55 | /** 56 | * @return TRUE if contains name information. 57 | */ 58 | public boolean hasName() { 59 | return ((mName != null) && (!mName.equals(""))); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /lib/src/main/java/ai/olami/ids/MathData.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017, 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 MathData { 25 | 26 | @Expose 27 | @SerializedName("content") 28 | private String mContent = null; 29 | 30 | /** 31 | * @return Reply content. 32 | */ 33 | public String getContent() { 34 | return (mContent == null) ? "" : mContent; 35 | } 36 | 37 | /** 38 | * @return TRUE if contains reply content information. 39 | */ 40 | public boolean hasContent() { 41 | return ((mContent != null) && (!mContent.equals(""))); 42 | } 43 | 44 | @Expose 45 | @SerializedName("result") 46 | private String mResult = null; 47 | 48 | /** 49 | * @return Result. 50 | */ 51 | public String getResult() { 52 | return (mResult == null) ? "" : mResult; 53 | } 54 | 55 | /** 56 | * @return TRUE if contains result. 57 | */ 58 | public boolean hasResult() { 59 | return ((mResult != null) && (!mResult.equals(""))); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /lib/src/main/java/ai/olami/nli/slot/NumDetail.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017, 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.nli.slot; 20 | 21 | import com.google.gson.annotations.Expose; 22 | import com.google.gson.annotations.SerializedName; 23 | 24 | public class NumDetail { 25 | 26 | public static final String TYPE_NUMBER = "number"; 27 | public static final String TYPE_FLOAT = "float"; 28 | 29 | @Expose 30 | @SerializedName("recommend_value") 31 | private String mRecommendValue = null; 32 | 33 | /** 34 | * @return Recommend value. 35 | */ 36 | public String getRecommendValue() { 37 | return mRecommendValue; 38 | } 39 | 40 | /** 41 | * @return TRUE if contains RecommendValue information. 42 | */ 43 | public boolean hasRecommendValue() { 44 | return ((mRecommendValue != null) && (!mRecommendValue.equals(""))); 45 | } 46 | 47 | @Expose 48 | @SerializedName("type") 49 | private String mType = null; 50 | 51 | /** 52 | * @return The type of the number. 53 | */ 54 | public String getType() { 55 | return mType.toLowerCase(); 56 | } 57 | 58 | /** 59 | * @return TRUE if contains Type information. 60 | */ 61 | public boolean hasType() { 62 | return ((mType != null) && (!mType.equals(""))); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /lib/src/main/java/ai/olami/util/GsonFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017, 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.util; 20 | 21 | import com.google.gson.Gson; 22 | import com.google.gson.GsonBuilder; 23 | 24 | public class GsonFactory { 25 | 26 | private static Gson mDefaultGson = new GsonBuilder() 27 | .excludeFieldsWithoutExposeAnnotation().create(); 28 | 29 | private static Gson mDebugGson = new GsonBuilder() 30 | .setPrettyPrinting() 31 | .create(); 32 | 33 | private static Gson mDebugGsonWithoutEA = new GsonBuilder() 34 | .setPrettyPrinting() 35 | .excludeFieldsWithoutExposeAnnotation() 36 | .create(); 37 | 38 | /** 39 | * Create a new Gson instance with excludeFieldsWithoutExposeAnnotation(). 40 | * 41 | * @return GsonBuilder. 42 | */ 43 | public static Gson getNormalGson() { 44 | return mDefaultGson; 45 | } 46 | 47 | /** 48 | * Create a new Gson instance with PrettyPrinting. 49 | * 50 | * @param exposeAll - TRUE to create without excludeFieldsWithoutExposeAnnotation(). 51 | * @return Gson 52 | */ 53 | public static Gson getDebugGson(boolean exposeAll) { 54 | 55 | if (exposeAll) { 56 | return mDebugGson; 57 | } 58 | 59 | return mDebugGsonWithoutEA; 60 | } 61 | 62 | } 63 | 64 | 65 | -------------------------------------------------------------------------------- /lib/src/main/java/ai/olami/nli/slot/DateTime.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017, 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.nli.slot; 20 | 21 | import com.google.gson.annotations.Expose; 22 | import com.google.gson.annotations.SerializedName; 23 | 24 | public class DateTime { 25 | 26 | public static final String TYPE_TIME_RECOMMEND = "time_recommend"; 27 | public static final String TYPE_SEMANTIC = "time_semantic"; 28 | public static final String TYPE_INVALID = "invalid"; 29 | 30 | @Expose 31 | @SerializedName("type") 32 | private String mType = null; 33 | 34 | /** 35 | * @return Date time type. 36 | */ 37 | public String getType() { 38 | return mType.toLowerCase(); 39 | } 40 | 41 | /** 42 | * @return TRUE if contains Type information. 43 | */ 44 | public boolean hasType() { 45 | return ((mType != null) && (!mType.equals(""))); 46 | } 47 | 48 | @Expose 49 | @SerializedName("data") 50 | private DateTimeData mDatetimeData = null; 51 | 52 | /** 53 | * @return Detailed information. 54 | */ 55 | public DateTimeData getData() { 56 | return mDatetimeData; 57 | } 58 | 59 | /** 60 | * @return TRUE if contains Data information. 61 | */ 62 | public boolean hasData() { 63 | return (mDatetimeData != null); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /lib/src/main/java/ai/olami/ids/TVProgramData.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017, 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 TVProgramData { 25 | 26 | @Expose 27 | @SerializedName("name") 28 | private String mName = null; 29 | 30 | /** 31 | * @return TV program name. 32 | */ 33 | public String getName() { 34 | return (mName == null) ? "" : mName; 35 | } 36 | 37 | /** 38 | * @return TRUE if contains TV program name. 39 | */ 40 | public boolean hasName() { 41 | return ((mName != null) && (!mName.equals(""))); 42 | } 43 | 44 | @Expose 45 | @SerializedName("time") 46 | private String mTime = null; 47 | 48 | /** 49 | * @return Date-time information. 50 | */ 51 | public String getTime() { 52 | return (mTime == null) ? "" : mTime; 53 | } 54 | 55 | /** 56 | * @return TRUE if contains date-time information. 57 | */ 58 | public boolean hasTime() { 59 | return ((mTime != null) && (!mTime.equals(""))); 60 | } 61 | 62 | @Expose 63 | @SerializedName("highlight") 64 | private int mHighlight = 0; 65 | 66 | /** 67 | * @return TRUE if this content is matches the search condition. 68 | */ 69 | public boolean isHighlight() { 70 | return (mHighlight == 1); 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /lib/src/main/java/ai/olami/nli/slot/RepeatRule.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017, 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.nli.slot; 20 | 21 | import com.google.gson.annotations.Expose; 22 | import com.google.gson.annotations.SerializedName; 23 | 24 | public class RepeatRule { 25 | 26 | public static final String INTERVAL_UNIT_YEAR = "Year"; 27 | public static final String INTERVAL_UNIT_MONTH = "Month"; 28 | public static final String INTERVAL_UNIT_DAY = "Day"; 29 | public static final String INTERVAL_UNIT_HOUR = "Hour"; 30 | public static final String INTERVAL_UNIT_MINUTE = "Minute"; 31 | public static final String INTERVAL_UNIT_SECOND = "Second"; 32 | public static final String INTERVAL_UNIT_WEEK = "Week"; 33 | public static final String INTERVAL_UNIT_INVALID = "Invalid"; 34 | 35 | @Expose 36 | @SerializedName("IntervalUnit") 37 | private String mIntervalUnit = null; 38 | 39 | /** 40 | * @return The unit of the repetition. 41 | */ 42 | public String getIntervalUnit() { 43 | return mIntervalUnit; 44 | } 45 | 46 | /** 47 | * @return TRUE if contains IntervalUnit information. 48 | */ 49 | public boolean hasIntervalUnit() { 50 | return ((mIntervalUnit != null) && (!mIntervalUnit.equals(""))); 51 | } 52 | 53 | @Expose 54 | @SerializedName("IntervalValue") 55 | private int mIntervalValue = -1; 56 | 57 | /** 58 | * @return The value of the repetition. 59 | */ 60 | public int getIntervalValue() { 61 | return mIntervalValue; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /lib/src/main/java/ai/olami/ids/MusicControlData.java: -------------------------------------------------------------------------------- 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 MusicControlData { 25 | 26 | public static final String NEXT = "next"; 27 | public static final String PREVIOUS = "prev"; 28 | public static final String PAUSE = "pause"; 29 | public static final String PLAY = "play"; 30 | public static final String RANDOM = "random"; 31 | public static final String LOOP = "loop"; 32 | public static final String ORDER = "order"; 33 | public static final String MUTE = "mute"; 34 | public static final String VOLUME_DOWN = "volume_down"; 35 | public static final String VOLUME_UP = "volume_up"; 36 | 37 | @Expose 38 | @SerializedName("index") 39 | private String mIndex = null; 40 | 41 | /** 42 | * @return Index. 43 | */ 44 | public String getIndex() { 45 | return (mIndex == null) ? "" : mIndex; 46 | } 47 | 48 | /** 49 | * @return TRUE if contains Index. 50 | */ 51 | public boolean hasIndex() { 52 | return ((mIndex != null) && (!mIndex.equals(""))); 53 | } 54 | 55 | @Expose 56 | @SerializedName("command") 57 | private String mCommand = null; 58 | 59 | /** 60 | * @return Command. 61 | */ 62 | public String getCommand() { 63 | return (mCommand == null) ? "" : mCommand; 64 | } 65 | 66 | /** 67 | * @return TRUE if contains command. 68 | */ 69 | public boolean hasCommand() { 70 | return ((mCommand != null) && (!mCommand.equals(""))); 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /lib/src/main/java/ai/olami/nli/slot/DateTimeData.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017, 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.nli.slot; 20 | 21 | import com.google.gson.annotations.Expose; 22 | import com.google.gson.annotations.SerializedName; 23 | 24 | public class DateTimeData { 25 | 26 | public static final String SUB_TYPE_DURATION = "duration"; 27 | public static final String SUB_TYPE_REPEAT = "repeat"; 28 | 29 | @Expose 30 | @SerializedName("start_time") 31 | private long mStartTime = -1; 32 | 33 | /** 34 | * @return Start time. 35 | */ 36 | public long getStartTime() { 37 | return mStartTime; 38 | } 39 | 40 | @Expose 41 | @SerializedName("end_time") 42 | private long mEndTime = -1; 43 | 44 | /** 45 | * @return End time. 46 | */ 47 | public long getEndTime() { 48 | return mEndTime; 49 | } 50 | 51 | @Expose 52 | @SerializedName("sub_type") 53 | private String mSubType = null; 54 | 55 | /** 56 | * @return Sub type. 57 | */ 58 | public String getSubType() { 59 | return mSubType.toLowerCase(); 60 | } 61 | 62 | /** 63 | * @return TRUE if contains SubType information. 64 | */ 65 | public boolean hasSubType() { 66 | return ((mSubType != null) && (!mSubType.equals(""))); 67 | } 68 | 69 | @Expose 70 | @SerializedName("time_struct") 71 | private TimeStruct mTimeStruct = null; 72 | 73 | /** 74 | * @return The structure that describes the time period or the repetition. 75 | */ 76 | public TimeStruct getTimeStruct() { 77 | return mTimeStruct; 78 | } 79 | 80 | /** 81 | * @return TRUE if contains TimeStruct information. 82 | */ 83 | public boolean hasTimeStruct() { 84 | return (mTimeStruct != null); 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /lib/src/main/java/ai/olami/cloudService/SpeechResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017, 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.cloudService; 20 | 21 | import com.google.gson.annotations.Expose; 22 | import com.google.gson.annotations.SerializedName; 23 | 24 | public class SpeechResult { 25 | 26 | public static final int STATUS_RECOGNIZE_OK = 0; 27 | public static final int STATUS_RESULT_NOT_CHANGE = 1; 28 | 29 | public static final int SPEECH_STATUS_GOOD_QUALITY = 0; 30 | public static final int SPEECH_STATUS_WITH_NOISE = 1; 31 | 32 | @Expose 33 | @SerializedName("result") 34 | private String mResult = null; 35 | 36 | @Expose 37 | @SerializedName("speech_status") 38 | private int mSpeechStatus = -1; 39 | 40 | @Expose 41 | @SerializedName("final") 42 | private boolean mIsFinalResult = false; 43 | 44 | @Expose 45 | @SerializedName("status") 46 | private int mStatus = -1; 47 | 48 | /** 49 | * Get Speech-To-Text recognition result. 50 | * 51 | * @return Text result. 52 | */ 53 | public String getResult() { 54 | return (mResult == null) ? "" : mResult; 55 | } 56 | 57 | /** 58 | * Get quality and status of the speech source. 59 | * 60 | * @return 0 for good, or others for noise and issues. 61 | */ 62 | public int getSpeechStatus() { 63 | return mSpeechStatus; 64 | } 65 | 66 | /** 67 | * Check whether the recognition is completed. 68 | * 69 | * @return TRUE if recognition is completed, or FALSE means this is not final result. 70 | */ 71 | public boolean complete() { 72 | return mIsFinalResult; 73 | } 74 | 75 | /** 76 | * Get the processing status of audio uploading or recognition. 77 | * 78 | * @return 0 for the processing is fine, 1 for result not change, or others for something wrong. 79 | */ 80 | public int getStatus() { 81 | return mStatus; 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /lib/src/main/java/ai/olami/ids/PoemData.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017, 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 PoemData { 25 | 26 | @Expose 27 | @SerializedName("title") 28 | private String mTitle = null; 29 | 30 | /** 31 | * @return Title. 32 | */ 33 | public String getTitle() { 34 | return (mTitle == null) ? "" : mTitle; 35 | } 36 | 37 | /** 38 | * @return TRUE if contains title. 39 | */ 40 | public boolean hasTitle() { 41 | return ((mTitle != null) && (!mTitle.equals(""))); 42 | } 43 | 44 | @Expose 45 | @SerializedName("author") 46 | private String mAuthor = null; 47 | 48 | /** 49 | * @return Author. 50 | */ 51 | public String getAuthor() { 52 | return (mAuthor == null) ? "" : mAuthor; 53 | } 54 | 55 | /** 56 | * @return TRUE if contains author information. 57 | */ 58 | public boolean hasAuthor() { 59 | return ((mAuthor != null) && (!mAuthor.equals(""))); 60 | } 61 | 62 | @Expose 63 | @SerializedName("content") 64 | private String mContent = null; 65 | 66 | /** 67 | * @return Content. 68 | */ 69 | public String getContent() { 70 | return (mContent == null) ? "" : mContent; 71 | } 72 | 73 | /** 74 | * @return TRUE if contains content. 75 | */ 76 | public boolean hasContent() { 77 | return ((mContent != null) && (!mContent.equals(""))); 78 | } 79 | 80 | @Expose 81 | @SerializedName("poem_name") 82 | private String mPoemName = null; 83 | 84 | /** 85 | * @return Poem name. 86 | */ 87 | public String getPoemName() { 88 | return (mPoemName == null) ? "" : mPoemName; 89 | } 90 | 91 | /** 92 | * @return TRUE if contains poem name. 93 | */ 94 | public boolean hasPoemName() { 95 | return ((mPoemName != null) && (!mPoemName.equals(""))); 96 | } 97 | 98 | } 99 | -------------------------------------------------------------------------------- /lib/src/main/java/ai/olami/nli/slot/ExtendInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017, 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.nli.slot; 20 | 21 | import com.google.gson.annotations.Expose; 22 | import com.google.gson.annotations.SerializedName; 23 | 24 | public class ExtendInfo { 25 | 26 | @Expose 27 | @SerializedName("Month") 28 | private int mMonth = -1; 29 | 30 | public int getMonth() { 31 | return mMonth; 32 | } 33 | 34 | @Expose 35 | @SerializedName("Day") 36 | private int mDay = -1; 37 | 38 | public int getDay() { 39 | return mDay; 40 | } 41 | 42 | @Expose 43 | @SerializedName("Hour") 44 | private int mHour = -1; 45 | 46 | public int getHour() { 47 | return mHour; 48 | } 49 | 50 | @Expose 51 | @SerializedName("Minute") 52 | private int mMinute = -1; 53 | 54 | public int getMinute() { 55 | return mMinute; 56 | } 57 | 58 | @Expose 59 | @SerializedName("Second") 60 | private int mSecond = -1; 61 | 62 | public int getSecond() { 63 | return mSecond; 64 | } 65 | 66 | @Expose 67 | @SerializedName("DayOfWeek") 68 | private int mDayOfWeek = -1; 69 | 70 | public int getDayOfWeek() { 71 | return mDayOfWeek; 72 | } 73 | 74 | @Expose 75 | @SerializedName("festival") 76 | private String mFestival = null; 77 | 78 | /** 79 | * @return Festival or holiday name. 80 | */ 81 | public String getFestival() { 82 | return mFestival; 83 | } 84 | 85 | /** 86 | * @return TRUE if contains Festival information. 87 | */ 88 | public boolean hasFestival() { 89 | return ((mFestival != null) && (!mFestival.equals(""))); 90 | } 91 | 92 | @Expose 93 | @SerializedName("jieqi") 94 | private String mJieqi = null; 95 | 96 | /** 97 | * @return Name of the Solar Terms. 98 | */ 99 | public String getJieqi() { 100 | return mJieqi; 101 | } 102 | 103 | /** 104 | * @return TRUE if contains Jieqi information. 105 | */ 106 | public boolean hasJieqi() { 107 | return ((mJieqi != null) && (!mJieqi.equals(""))); 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /lib/src/main/java/ai/olami/cloudService/APIResponseData.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017, 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.cloudService; 20 | 21 | import ai.olami.nli.NLIResult; 22 | 23 | import com.google.gson.annotations.Expose; 24 | import com.google.gson.annotations.SerializedName; 25 | 26 | public class APIResponseData { 27 | 28 | @Expose 29 | @SerializedName("seg") 30 | private String mSegResult = null; 31 | 32 | @Expose 33 | @SerializedName("nli") 34 | private NLIResult[] mNLIResults = null; 35 | 36 | @Expose 37 | @SerializedName("asr") 38 | private SpeechResult mSpeechResult = null; 39 | 40 | /** 41 | * Get word segments from the word segmentation analyzer. 42 | * 43 | * @return Word segments array. 44 | */ 45 | public String[] getWordSegmentation() { 46 | return mSegResult.split("\\s+"); 47 | } 48 | 49 | /** 50 | * @return TRUE if contains word segmentation information. 51 | */ 52 | public boolean hasWordSegmentation() { 53 | return (mSegResult != null); 54 | } 55 | 56 | /** 57 | * Get word segmentation results from the Natural Language Understanding API. 58 | * 59 | * @return Word segments string, separated by empty space. 60 | */ 61 | public String getWordSegmentationSingleString() { 62 | return mSegResult; 63 | } 64 | 65 | /** 66 | * Get NLI result from the Natural Language Understanding API. 67 | * 68 | * @return NLI result containers array. 69 | */ 70 | public NLIResult[] getNLIResults() { 71 | return mNLIResults; 72 | } 73 | 74 | /** 75 | * @return TRUE if contains NLIResult information. 76 | */ 77 | public boolean hasNLIResults() { 78 | return (mNLIResults != null); 79 | } 80 | 81 | /** 82 | * Get the Speech-To-Text results from the Cloud Speech Recognition API. 83 | * 84 | * @return Speech-To-Text container. 85 | */ 86 | public SpeechResult getSpeechResult() { 87 | return mSpeechResult; 88 | } 89 | 90 | /** 91 | * @return TRUE if contains SpeechResult information. 92 | */ 93 | public boolean hasSpeechResult() { 94 | return (mSpeechResult != null); 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /lib/src/main/java/ai/olami/nli/Semantic.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017, 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.nli; 20 | 21 | import ai.olami.nli.slot.Slot; 22 | 23 | import com.google.gson.annotations.Expose; 24 | import com.google.gson.annotations.SerializedName; 25 | 26 | public class Semantic { 27 | 28 | @Expose 29 | @SerializedName("modifier") 30 | private String[] mGlobalModifiers = null; 31 | 32 | /** 33 | * @return Global modifiers 34 | */ 35 | public String[] getGlobalModifiers() { 36 | return mGlobalModifiers; 37 | } 38 | 39 | /** 40 | * @return TRUE if contains GlobalModifier information. 41 | */ 42 | public boolean hasGlobalModifiers() { 43 | return ((mGlobalModifiers != null) && (mGlobalModifiers.length > 0)); 44 | } 45 | 46 | @Expose 47 | @SerializedName("app") 48 | private String mAppModule = null; 49 | 50 | /** 51 | * Get the grammar module name. (Usually defined on the NLI system) 52 | * 53 | * @return Module name. 54 | */ 55 | public String getAppModule() { 56 | return mAppModule; 57 | } 58 | 59 | /** 60 | * @return TRUE if contains AppModule information. 61 | */ 62 | public boolean hasAppModule() { 63 | return ((mAppModule != null) && (!mAppModule.equals(""))); 64 | } 65 | 66 | @Expose 67 | @SerializedName("input") 68 | private String mInput = null; 69 | 70 | /** 71 | * @return The original input text. 72 | */ 73 | public String getInput() { 74 | return mInput; 75 | } 76 | 77 | /** 78 | * @return TRUE if contains Input information. 79 | */ 80 | public boolean hasInput() { 81 | return ((mInput != null) && (!mInput.equals(""))); 82 | } 83 | 84 | @Expose 85 | @SerializedName("slots") 86 | private Slot[] mSlots = null; 87 | 88 | /** 89 | * @return Slot array. 90 | */ 91 | public Slot[] getSlots() { 92 | return mSlots; 93 | } 94 | 95 | /** 96 | * @return TRUE if contains Slots information. 97 | */ 98 | public boolean hasSlots() { 99 | return ((mSlots != null) && (mSlots.length > 0)); 100 | } 101 | 102 | } 103 | -------------------------------------------------------------------------------- /lib/src/main/java/ai/olami/nli/slot/TimeStruct.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017, 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.nli.slot; 20 | 21 | import com.google.gson.annotations.Expose; 22 | import com.google.gson.annotations.SerializedName; 23 | 24 | public class TimeStruct { 25 | 26 | @Expose 27 | @SerializedName("Year") 28 | private int mYear = -1; 29 | 30 | public int getYear() { 31 | return mYear; 32 | } 33 | 34 | @Expose 35 | @SerializedName("Month") 36 | private int mMonth = -1; 37 | 38 | public int getMonth() { 39 | return mMonth; 40 | } 41 | 42 | @Expose 43 | @SerializedName("Day") 44 | private int mDay = -1; 45 | 46 | public int getDay() { 47 | return mDay; 48 | } 49 | 50 | @Expose 51 | @SerializedName("Hour") 52 | private int mHour = -1; 53 | 54 | public int getHour() { 55 | return mHour; 56 | } 57 | 58 | @Expose 59 | @SerializedName("Minute") 60 | private int mMinute = -1; 61 | 62 | public int getMinute() { 63 | return mMinute; 64 | } 65 | 66 | @Expose 67 | @SerializedName("Second") 68 | private int mSecond = -1; 69 | 70 | public int getSecond() { 71 | return mSecond; 72 | } 73 | 74 | @Expose 75 | @SerializedName("Week") 76 | private int mWeek = -1; 77 | 78 | public int getWeek() { 79 | return mWeek; 80 | } 81 | 82 | @Expose 83 | @SerializedName("repeat_rule") 84 | private RepeatRule mRepeatRule = null; 85 | 86 | /** 87 | * @return The structure that describes repetition rule. 88 | */ 89 | public RepeatRule getRepeatRule() { 90 | return mRepeatRule; 91 | } 92 | 93 | /** 94 | * @return TRUE if contains RepeatRule information. 95 | */ 96 | public boolean hasRepeatRule() { 97 | return (mRepeatRule != null); 98 | } 99 | 100 | @Expose 101 | @SerializedName("extend_info") 102 | private ExtendInfo mExtendInfo = null; 103 | 104 | /** 105 | * @return Extra information. 106 | */ 107 | public ExtendInfo getExtendInfo() { 108 | return mExtendInfo; 109 | } 110 | 111 | /** 112 | * @return TRUE if contains ExtendInfo information. 113 | */ 114 | public boolean hasExtendInfo() { 115 | return (mExtendInfo != null); 116 | } 117 | 118 | } 119 | -------------------------------------------------------------------------------- /lib/src/main/java/ai/olami/nli/slot/Slot.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017, 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.nli.slot; 20 | 21 | import com.google.gson.annotations.Expose; 22 | import com.google.gson.annotations.SerializedName; 23 | 24 | public class Slot { 25 | 26 | @Expose 27 | @SerializedName("name") 28 | private String mName = null; 29 | 30 | /** 31 | * @return Slot name. 32 | */ 33 | public String getName() { 34 | return mName; 35 | } 36 | 37 | /** 38 | * @return TRUE if contains Name information. 39 | */ 40 | public boolean hasName() { 41 | return ((mName != null) && (!mName.equals(""))); 42 | } 43 | 44 | @Expose 45 | @SerializedName("value") 46 | private String mValue = null; 47 | 48 | /** 49 | * @return Slot value. 50 | */ 51 | public String getValue() { 52 | return mValue; 53 | } 54 | 55 | /** 56 | * @return TRUE if contains Value information. 57 | */ 58 | public boolean hasValue() { 59 | return ((mValue != null) && (!mValue.equals(""))); 60 | } 61 | 62 | @Expose 63 | @SerializedName("modifier") 64 | private String[] mModifiers = null; 65 | 66 | /** 67 | * @return Slot modifier. 68 | */ 69 | public String[] getModifiers() { 70 | return mModifiers; 71 | } 72 | 73 | /** 74 | * @return TRUE if contains Modifier information. 75 | */ 76 | public boolean hasModifiers() { 77 | return ((mModifiers != null) && (mModifiers.length > 0)); 78 | } 79 | 80 | @Expose 81 | @SerializedName("datetime") 82 | private DateTime mDateTime = null; 83 | 84 | /** 85 | * @return Date time analysis results. 86 | */ 87 | public DateTime getDateTime() { 88 | return mDateTime; 89 | } 90 | 91 | /** 92 | * @return TRUE if contains DateTime information. 93 | */ 94 | public boolean hasDateTime() { 95 | return (mDateTime != null); 96 | } 97 | 98 | @Expose 99 | @SerializedName("num_detail") 100 | private NumDetail mNumDetail = null; 101 | 102 | /** 103 | * @return The detailed information of the number slot. 104 | */ 105 | public NumDetail getNumDetail() { 106 | return mNumDetail; 107 | } 108 | 109 | /** 110 | * @return TRUE if contains NumDetail information. 111 | */ 112 | public boolean hasNumDetail() { 113 | return (mNumDetail != null); 114 | } 115 | 116 | } 117 | -------------------------------------------------------------------------------- /lib/src/main/java/ai/olami/cloudService/NLIConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017, 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.cloudService; 20 | 21 | import com.google.gson.Gson; 22 | import com.google.gson.JsonElement; 23 | import com.google.gson.annotations.Expose; 24 | import com.google.gson.annotations.SerializedName; 25 | 26 | import ai.olami.util.GsonFactory; 27 | 28 | public class NLIConfig { 29 | 30 | @Expose(serialize = false, deserialize = false) 31 | private Gson mGson = GsonFactory.getNormalGson(); 32 | 33 | // Members ------------------------------------------------------------------------------------------ 34 | 35 | @Expose 36 | @SerializedName("slotname") 37 | private String mSlotName = null; 38 | 39 | @Expose 40 | @SerializedName("clear_talk_history") 41 | private String mClearTalkHistory = null; 42 | 43 | /** 44 | * Set slot name. 45 | */ 46 | public void setSlotName(String name) { 47 | mSlotName = name; 48 | } 49 | 50 | /** 51 | * @return Slot Name. 52 | */ 53 | public String getSlotName() { 54 | return mSlotName; 55 | } 56 | 57 | /** 58 | * @return TRUE if contains slot name. 59 | */ 60 | public boolean hasSlotName() { 61 | return ((mSlotName != null) && (!mSlotName.equals(""))); 62 | } 63 | 64 | /** 65 | * set clear_talk_history value 66 | */ 67 | public void setClearTalkHistory(String value) { 68 | mClearTalkHistory = value; 69 | } 70 | 71 | /** 72 | * @return clear_talk_history value 73 | */ 74 | public String getClearTalkHistory() { 75 | return mClearTalkHistory; 76 | } 77 | 78 | /** 79 | * @return TRUE if contains clear_talk_history. 80 | */ 81 | public boolean hasClearTalkHistory() { 82 | return ((mClearTalkHistory != null) && (!mClearTalkHistory.equals(""))); 83 | } 84 | 85 | // Common Methods ------------------------------------------------------------------------------------ 86 | 87 | /** 88 | * Reset all members. 89 | */ 90 | public void reset() { 91 | mSlotName = null; 92 | mClearTalkHistory = null; 93 | } 94 | 95 | /** 96 | * @return GSON Json Element. 97 | */ 98 | public JsonElement toJsonElement() { 99 | return mGson.fromJson(toString(), JsonElement.class); 100 | } 101 | 102 | @Override 103 | public String toString() { 104 | return mGson.toJson(this); 105 | } 106 | 107 | } 108 | -------------------------------------------------------------------------------- /lib/src/main/java/ai/olami/cloudService/APIRequestBase.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017, 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.cloudService; 20 | 21 | import java.util.UUID; 22 | 23 | public abstract class APIRequestBase { 24 | 25 | private APIConfiguration mConfiguration = null; 26 | private String mCusId = "Undefined"; 27 | private int mConnectionTimeoutMilliseconds = 5000; 28 | 29 | /** 30 | * A base class to issue OLAMI HTTP API requests. 31 | * 32 | * @param configuration - API configurations. 33 | */ 34 | public APIRequestBase(APIConfiguration configuration) { 35 | mConfiguration = configuration; 36 | mCusId = UUID.randomUUID().toString(); 37 | } 38 | 39 | /** 40 | * @param configuration - API configurations. 41 | */ 42 | public void setConfiguration(APIConfiguration configuration) { 43 | mConfiguration = configuration; 44 | } 45 | 46 | /** 47 | * @return The given API configurations 48 | */ 49 | public APIConfiguration getConfiguration() { 50 | return mConfiguration; 51 | } 52 | 53 | /** 54 | * @param type - SDK type. 55 | */ 56 | public void setSdkType(String type) { 57 | if (mConfiguration != null) { 58 | mConfiguration.setSdkType(type); 59 | } 60 | } 61 | 62 | /** 63 | * @return The given SDK type string. 64 | */ 65 | public String getSdkType() { 66 | if (mConfiguration != null) { 67 | return mConfiguration.getSdkType(); 68 | } 69 | return ""; 70 | } 71 | 72 | /** 73 | * Set the identification to identify the End-user. 74 | * This is helpful in some of NLU/NLI functions, such as context support. 75 | * 76 | * @param cusId - End-user identifier. 77 | */ 78 | public void setEndUserIdentifier(final String cusId) { 79 | mCusId = cusId; 80 | } 81 | 82 | /** 83 | * @return The given End-user identifier. 84 | */ 85 | public String getEndUserIdentifier() { 86 | return mCusId; 87 | } 88 | 89 | /** 90 | * Get the timeout setting of the HTTP API request. 91 | * 92 | * @return milliseconds. 93 | */ 94 | public int getTimeout() { 95 | return mConnectionTimeoutMilliseconds; 96 | } 97 | 98 | /** 99 | * Set timeout in milliseconds to the HTTP API request. 100 | * 101 | * @param milliseconds - Timeout in milliseconds. 102 | */ 103 | public void setTimeout(int milliseconds) { 104 | mConnectionTimeoutMilliseconds = milliseconds; 105 | } 106 | 107 | } 108 | -------------------------------------------------------------------------------- /lib/src/main/java/ai/olami/ids/UnitConvertData.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017, 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 UnitConvertData { 25 | 26 | @Expose 27 | @SerializedName("content") 28 | private String mContent = null; 29 | 30 | /** 31 | * @return Reply content. 32 | */ 33 | public String getContent() { 34 | return (mContent == null) ? "" : mContent; 35 | } 36 | 37 | /** 38 | * @return TRUE if contains reply content information. 39 | */ 40 | public boolean hasContent() { 41 | return ((mContent != null) && (!mContent.equals(""))); 42 | } 43 | 44 | @Expose 45 | @SerializedName("src_value") 46 | private String mSourceValue = null; 47 | 48 | /** 49 | * @return Source value. 50 | */ 51 | public String getSourceValue() { 52 | return (mSourceValue == null) ? "" : mSourceValue; 53 | } 54 | 55 | /** 56 | * @return TRUE if contains source value. 57 | */ 58 | public boolean hasSourceValue() { 59 | return ((mSourceValue != null) && (!mSourceValue.equals(""))); 60 | } 61 | 62 | @Expose 63 | @SerializedName("src_unit") 64 | private String mSourceUnit = null; 65 | 66 | /** 67 | * @return Source unit. 68 | */ 69 | public String getSourceUnit() { 70 | return (mSourceUnit == null) ? "" : mSourceUnit; 71 | } 72 | 73 | /** 74 | * @return TRUE if contains source unit. 75 | */ 76 | public boolean hasSourceUnit() { 77 | return ((mSourceUnit != null) && (!mSourceUnit.equals(""))); 78 | } 79 | 80 | @Expose 81 | @SerializedName("dst_value") 82 | private String mDestinationValue = null; 83 | 84 | /** 85 | * @return Destination value. 86 | */ 87 | public String getDestinationValue() { 88 | return (mDestinationValue == null) ? "" : mDestinationValue; 89 | } 90 | 91 | /** 92 | * @return TRUE if contains destination value. 93 | */ 94 | public boolean hasDestinationValue() { 95 | return ((mDestinationValue != null) && (!mDestinationValue.equals(""))); 96 | } 97 | 98 | @Expose 99 | @SerializedName("dst_unit") 100 | private String mDestinationUnit = null; 101 | 102 | /** 103 | * @return Destination unit. 104 | */ 105 | public String getDestinationUnit() { 106 | return (mDestinationUnit == null) ? "" : mDestinationUnit; 107 | } 108 | 109 | /** 110 | * @return TRUE if contains destination unit. 111 | */ 112 | public boolean hasDestinationUnit() { 113 | return ((mDestinationUnit != null) && (!mDestinationUnit.equals(""))); 114 | } 115 | 116 | } 117 | -------------------------------------------------------------------------------- /lib/src/main/java/ai/olami/ids/NewsData.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017, 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 NewsData { 25 | 26 | @Expose 27 | @SerializedName("title") 28 | private String mTitle = null; 29 | 30 | /** 31 | * @return Title. 32 | */ 33 | public String getTitle() { 34 | return (mTitle == null) ? "" : mTitle; 35 | } 36 | 37 | /** 38 | * @return TRUE if contains title. 39 | */ 40 | public boolean hasTitle() { 41 | return ((mTitle != null) && (!mTitle.equals(""))); 42 | } 43 | 44 | @Expose 45 | @SerializedName("time") 46 | private String mTime = null; 47 | 48 | /** 49 | * @return Date-time information. 50 | */ 51 | public String getTime() { 52 | return (mTime == null) ? "" : mTime; 53 | } 54 | 55 | /** 56 | * @return TRUE if contains date-time information. 57 | */ 58 | public boolean hasTime() { 59 | return ((mTime != null) && (!mTime.equals(""))); 60 | } 61 | 62 | @Expose 63 | @SerializedName("image_url") 64 | private String mImageURL = null; 65 | 66 | /** 67 | * @return Image URL. 68 | */ 69 | public String getImageURL() { 70 | return (mImageURL == null) ? "" : mImageURL; 71 | } 72 | 73 | /** 74 | * @return TRUE if contains image URL. 75 | */ 76 | public boolean hasImageURL() { 77 | return ((mImageURL != null) && (!mImageURL.equals(""))); 78 | } 79 | 80 | @Expose 81 | @SerializedName("detail") 82 | private String mDetail = null; 83 | 84 | /** 85 | * @return News detail. 86 | */ 87 | public String getDetail() { 88 | return (mDetail == null) ? "" : mDetail; 89 | } 90 | 91 | /** 92 | * @return TRUE if contains news detail. 93 | */ 94 | public boolean hasDetail() { 95 | return ((mDetail != null) && (!mDetail.equals(""))); 96 | } 97 | 98 | @Expose 99 | @SerializedName("ref_url") 100 | private String mRefURL = null; 101 | 102 | /** 103 | * @return Source URL of the news. 104 | */ 105 | public String getSourceURL() { 106 | return (mRefURL == null) ? "" : mRefURL; 107 | } 108 | 109 | /** 110 | * @return TRUE if contains source URL. 111 | */ 112 | public boolean hasSourceURL() { 113 | return ((mRefURL != null) && (!mRefURL.equals(""))); 114 | } 115 | 116 | @Expose 117 | @SerializedName("source") 118 | private String mSource = null; 119 | 120 | /** 121 | * @return Name of the source. 122 | */ 123 | public String getSourceName() { 124 | return (mSource == null) ? "" : mSource; 125 | } 126 | 127 | /** 128 | * @return TRUE if contains name of the source. 129 | */ 130 | public boolean hasSourceName() { 131 | return ((mSource != null) && (!mSource.equals(""))); 132 | } 133 | 134 | } 135 | -------------------------------------------------------------------------------- /lib/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | olami-java-client 6 | jar 7 | 8 | OLAMI Java Client Library 9 | OLAMI APIs Java client library 10 | http://olami.ai 11 | 12 | 13 | ai.olami 14 | olami-java-client-sdk 15 | 1.5.1 16 | 17 | 18 | 19 | UTF-8 20 | 21 | 22 | 23 | 24 | junit 25 | junit 26 | 27 | 28 | com.google.code.gson 29 | gson 30 | 31 | 32 | 33 | 34 | 35 | all 36 | 37 | 38 | 39 | org.apache.maven.plugins 40 | maven-shade-plugin 41 | 2.4.3 42 | 43 | 44 | package 45 | 46 | shade 47 | 48 | 49 | 50 | 51 | com.google.code.gson:gson 52 | 53 | 54 | true 55 | full 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | org.apache.maven.plugins 69 | maven-compiler-plugin 70 | 71 | 72 | org.apache.maven.plugins 73 | maven-jar-plugin 74 | 75 | ${project.artifactId}-${project.version} 76 | 77 | 78 | 79 | 80 | org.apache.maven.plugins 81 | maven-antrun-plugin 82 | 83 | 84 | install 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | run 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /lib/src/main/java/ai/olami/nli/NLIResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017, 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.nli; 20 | 21 | import java.util.ArrayList; 22 | 23 | import ai.olami.ids.IDSResult; 24 | import ai.olami.util.GsonFactory; 25 | 26 | import com.google.gson.Gson; 27 | import com.google.gson.JsonElement; 28 | import com.google.gson.annotations.Expose; 29 | import com.google.gson.annotations.SerializedName; 30 | import com.google.gson.reflect.TypeToken; 31 | 32 | public class NLIResult { 33 | 34 | private Gson mGson = GsonFactory.getNormalGson(); 35 | 36 | @Expose 37 | @SerializedName("desc_obj") 38 | private DescObject mDescObject = null; 39 | 40 | /** 41 | * @return Description of the analysis results. 42 | */ 43 | public DescObject getDescObject() { 44 | return mDescObject; 45 | } 46 | 47 | /** 48 | * @return TRUE if contains description information. 49 | */ 50 | public boolean hasDescObject() { 51 | return (mDescObject != null); 52 | } 53 | 54 | @Expose 55 | @SerializedName("semantic") 56 | private Semantic[] mSemantics = null; 57 | 58 | /** 59 | * Get the semantics of input text. 60 | * 61 | * @return Semantic array 62 | */ 63 | public Semantic[] getSemantics() { 64 | return mSemantics; 65 | } 66 | 67 | /** 68 | * @return TRUE if contains semantics information. 69 | */ 70 | public boolean hasSemantics() { 71 | return ((mSemantics != null) && (mSemantics.length > 0)); 72 | } 73 | 74 | @Expose 75 | @SerializedName("type") 76 | private String mType = null; 77 | 78 | /** 79 | * @return Type information. 80 | */ 81 | public String getType() { 82 | return mType; 83 | } 84 | 85 | /** 86 | * @return TRUE if contains type information. 87 | */ 88 | public boolean hasType() { 89 | return ((mType != null) && (!mType.equals(""))); 90 | } 91 | 92 | /** 93 | * Check if this result is actually a IDS response. 94 | * 95 | * @return TRUE if this result is provided by the IDS. 96 | */ 97 | public boolean isFromIDS() { 98 | return (IDSResult.Types.contains(mType)); 99 | } 100 | 101 | @Expose 102 | @SerializedName("data_obj") 103 | private JsonElement mDataObjs = null; 104 | 105 | /** 106 | * @return List of data object 107 | * or list of JsonElement if the object type is not defined. 108 | */ 109 | public ArrayList getDataObjects() { 110 | if (isFromIDS()) { 111 | String typeName = mType; 112 | switch (IDSResult.Types.getByName(mType)) { 113 | case QUESTION: 114 | typeName = this.getDescObject().getType(); 115 | break; 116 | case CONFIRMATION: 117 | typeName = this.getDescObject().getType(); 118 | break; 119 | case SELECTION: 120 | typeName = this.getDescObject().getType(); 121 | break; 122 | default: 123 | break; 124 | } 125 | return mGson.fromJson(mDataObjs, 126 | IDSResult.Types.getDataArrayListType(typeName)); 127 | } else if (hasDataObjects()) { 128 | return mGson.fromJson(mDataObjs, 129 | new TypeToken>() {}.getType()); 130 | } 131 | return null; 132 | } 133 | 134 | /** 135 | * @return TRUE if contains data contents. 136 | */ 137 | public boolean hasDataObjects() { 138 | return (mDataObjs != null); 139 | } 140 | 141 | } 142 | -------------------------------------------------------------------------------- /lib/src/main/java/org/xiph/speex/Misc.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * Copyright (c) 1999-2003 Wimba S.A., All Rights Reserved. * 4 | * * 5 | * COPYRIGHT: * 6 | * This software is the property of Wimba S.A. * 7 | * This software is redistributed under the Xiph.org variant of * 8 | * the BSD license. * 9 | * Redistribution and use in source and binary forms, with or without * 10 | * modification, are permitted provided that the following conditions * 11 | * are met: * 12 | * - Redistributions of source code must retain the above copyright * 13 | * notice, this list of conditions and the following disclaimer. * 14 | * - Redistributions in binary form must reproduce the above copyright * 15 | * notice, this list of conditions and the following disclaimer in the * 16 | * documentation and/or other materials provided with the distribution. * 17 | * - Neither the name of Wimba, the Xiph.org Foundation nor the names of * 18 | * its contributors may be used to endorse or promote products derived * 19 | * from this software without specific prior written permission. * 20 | * * 21 | * WARRANTIES: * 22 | * This software is made available by the authors in the hope * 23 | * that it will be useful, but without any warranty. * 24 | * Wimba S.A. is not liable for any consequence related to the * 25 | * use of the provided software. * 26 | * * 27 | * Class: Misc.java * 28 | * * 29 | * Author: Marc GIMPEL * 30 | * * 31 | * Date: 14th July 2003 * 32 | * * 33 | ******************************************************************************/ 34 | 35 | /* $Id: Misc.java,v 1.2 2004/10/21 16:21:57 mgimpel Exp $ */ 36 | 37 | package org.xiph.speex; 38 | 39 | /** 40 | * Miscellaneous functions 41 | * 42 | * @author Marc Gimpel, Wimba S.A. (mgimpel@horizonwimba.com) 43 | * @version $Revision: 1.2 $ 44 | */ 45 | public class Misc 46 | { 47 | /** 48 | * Builds an Asymmetric "pseudo-Hamming" window. 49 | * @param windowSize 50 | * @param subFrameSize 51 | * @return an Asymmetric "pseudo-Hamming" window. 52 | */ 53 | public static float[] window(final int windowSize, final int subFrameSize) 54 | { 55 | int i; 56 | int part1 = subFrameSize * 7 / 2; 57 | int part2 = subFrameSize * 5 / 2; 58 | float[] window = new float[windowSize]; 59 | for (i=0; i mFieldNameValues = null; 38 | 39 | private void initFieldNameValues() { 40 | if (mFieldNameValues == null) { 41 | mFieldNameValues = new HashMap(); 42 | for (int i = 0; i < mFieldNames.length; i++) { 43 | mFieldNameValues.put(mFieldNames[i], mFieldValues[i]); 44 | } 45 | } 46 | } 47 | 48 | /** 49 | * Get number of fields. 50 | * 51 | * @return Number of fields. 52 | */ 53 | public int getNumberOfFields() { 54 | initFieldNameValues(); 55 | return mFieldNameValues.size(); 56 | } 57 | 58 | /** 59 | * Get name-value contents of all fields. 60 | * 61 | * @return The name-value contents. 62 | */ 63 | public Map getFieldNameValues() { 64 | initFieldNameValues(); 65 | return mFieldNameValues; 66 | } 67 | 68 | @Expose 69 | @SerializedName("photo_url") 70 | private String mPhotoURL = null; 71 | 72 | /** 73 | * @return Photo URL. 74 | */ 75 | public String getPhotoURL() { 76 | return (mPhotoURL == null) ? "" : mPhotoURL; 77 | } 78 | 79 | /** 80 | * @return TRUE if contains photo URL. 81 | */ 82 | public boolean hasPhotoURL() { 83 | return ((mPhotoURL != null) && (!mPhotoURL.equals(""))); 84 | } 85 | 86 | @Expose 87 | @SerializedName("type") 88 | private String mType = null; 89 | 90 | /** 91 | * @return Content type. 92 | */ 93 | public String getType() { 94 | return (mType == null) ? "" : mType; 95 | } 96 | 97 | /** 98 | * @return TRUE if contains type information. 99 | */ 100 | public boolean hasType() { 101 | return ((mType != null) && (!mType.equals(""))); 102 | } 103 | 104 | @Expose 105 | @SerializedName("description") 106 | private String mDescription = null; 107 | 108 | /** 109 | * @return Content description. 110 | */ 111 | public String getDescription() { 112 | return (mDescription == null) ? "" : mDescription; 113 | } 114 | 115 | /** 116 | * @return TRUE if contains description. 117 | */ 118 | public boolean hasDescription() { 119 | return ((mDescription != null) && (!mDescription.equals(""))); 120 | } 121 | 122 | @Expose 123 | @SerializedName("categorylist") 124 | private String[] mCategoryList = null; 125 | 126 | /** 127 | * @return Category list of the result. 128 | */ 129 | public String[] getCategoryList() { 130 | return (mCategoryList == null) ? new String[]{""} : mCategoryList; 131 | } 132 | 133 | /** 134 | * @return TRUE if contains category list of the result. 135 | */ 136 | public boolean hasCategoryList() { 137 | return ((mCategoryList != null) && (mCategoryList.length > 0)); 138 | } 139 | 140 | @Expose 141 | @SerializedName("highlight") 142 | private int[] mHighlights = null; 143 | 144 | /** 145 | * @return Category list of the result. 146 | */ 147 | public int[] getHighlights() { 148 | return (mHighlights == null) ? new int[]{0} : mHighlights; 149 | } 150 | 151 | /** 152 | * @return TRUE if contains category list of the result. 153 | */ 154 | public boolean hasHighlights() { 155 | return ((mHighlights != null) && (mHighlights.length > 0)); 156 | } 157 | 158 | } 159 | -------------------------------------------------------------------------------- /examples/dump-nli-results-example/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | ai.olami.example 6 | dump-nli-results-example 7 | 20180522 8 | jar 9 | 10 | OLAMI Java Client Examples: Dump NLI Results 11 | http://olami.ai 12 | 13 | 14 | ai.olami 15 | olami-java-client-sdk 16 | 1.5.1 17 | ../../pom.xml 18 | 19 | 20 | 21 | UTF-8 22 | 23 | 24 | 25 | 26 | junit 27 | junit 28 | 29 | 30 | ai.olami 31 | olami-java-client 32 | ${project.parent.version} 33 | 34 | 35 | 36 | 37 | 38 | 39 | org.apache.maven.plugins 40 | maven-compiler-plugin 41 | 42 | 43 | org.apache.maven.plugins 44 | maven-jar-plugin 45 | 46 | 47 | org.apache.maven.plugins 48 | maven-assembly-plugin 49 | 50 | 51 | 52 | org.apache.maven.plugins 53 | maven-antrun-plugin 54 | 55 | 56 | install 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | run 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | org.apache.maven.plugins 79 | maven-assembly-plugin 80 | 81 | ${project.artifactId} 82 | 83 | 84 | ai.olami.example.DumpNLIResultsExampleExecution 85 | 86 | 87 | 88 | 89 | 90 | make-assembly 91 | package 92 | 93 | single 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /lib/src/main/java/ai/olami/ids/IDSResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017, 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 java.lang.reflect.Type; 22 | import java.util.ArrayList; 23 | 24 | 25 | import com.google.gson.reflect.TypeToken; 26 | 27 | public class IDSResult { 28 | 29 | /** 30 | * IDS Modules 31 | */ 32 | public static enum Types { 33 | QUESTION ("question", null), 34 | CONFIRMATION ("confirmation", null), 35 | SELECTION ("selection", null), 36 | DATE ("date", null), 37 | NONSENSE ("nonsense", null), 38 | ZIP_CODE ("zipcode", null), 39 | MATH_24 ("math24", null), 40 | WEATHER ("weather", (new TypeToken>() {}).getType()), 41 | BAIKE ("baike", (new TypeToken>() {}).getType()), 42 | NEWS ("news", (new TypeToken>() {}).getType()), 43 | KKBOX ("kkbox", (new TypeToken>() {}).getType()), 44 | MUSIC_CONTROL ("MusicControl", (new TypeToken>() {}).getType()), 45 | TV_PROGRAM ("tvprogram", (new TypeToken>() {}).getType()), 46 | POEM ("poem", (new TypeToken>() {}).getType()), 47 | JOKE ("joke", (new TypeToken>() {}).getType()), 48 | STOCK_MARKET ("stock", (new TypeToken>() {}).getType()), 49 | MATH ("math", (new TypeToken>() {}).getType()), 50 | UNIT_CONVERT ("unitconvert", (new TypeToken>() {}).getType()), 51 | EXCHANGE_RATE ("exchangerate", (new TypeToken>() {}).getType()), 52 | COOKING ("cooking", (new TypeToken>() {}).getType()), 53 | OPEN_WEB ("openweb", (new TypeToken>() {}).getType()); 54 | 55 | private String name; 56 | private Type dataObjArrayListType; 57 | 58 | private Types( 59 | String name, 60 | Type dataObjArrayListType 61 | ) { 62 | this.name = name; 63 | this.dataObjArrayListType = dataObjArrayListType; 64 | } 65 | 66 | /** 67 | * @return Module name 68 | */ 69 | public String getName() { 70 | return this.name; 71 | } 72 | 73 | /** 74 | * @return Type of the DataObject ArrayList. 75 | */ 76 | public Type getDataArrayListType() { 77 | return this.dataObjArrayListType; 78 | } 79 | 80 | /** 81 | * Check if the given name exists in module type list. 82 | * 83 | * @param moduleName - Module name you want to check. 84 | * @return TRUE if the given name exists in module type list. 85 | */ 86 | public static boolean contains(String moduleName) { 87 | Object[] list = Types.class.getEnumConstants(); 88 | for (Object t : list) { 89 | if (((Types) t).getName().equals(moduleName)) { 90 | return true; 91 | } 92 | } 93 | return false; 94 | } 95 | 96 | /** 97 | * Get enum by mdoule name. 98 | * @param moduleName - Module name you want to find. 99 | * @return Module enum. 100 | */ 101 | public static Types getByName(String moduleName) { 102 | Object[] list = Types.class.getEnumConstants(); 103 | for (Object t : list) { 104 | if (((Types) t).getName().equals(moduleName)) { 105 | return ((Types) t); 106 | } 107 | } 108 | return null; 109 | } 110 | 111 | /** 112 | * Get DataObject array type by the specified module name. 113 | * 114 | * @param moduleName - Module name you want to find. 115 | * @return Type of the DataObject ArrayList. 116 | */ 117 | public static Type getDataArrayListType(String moduleName) { 118 | Object[] list = Types.class.getEnumConstants(); 119 | for (Object t : list) { 120 | if (((Types) t).getName().equals(moduleName)) { 121 | return ((Types) t).getDataArrayListType(); 122 | } 123 | } 124 | return null; 125 | } 126 | } 127 | 128 | } 129 | -------------------------------------------------------------------------------- /examples/text-input-example/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | ai.olami.example 6 | text-input-example 7 | 20180413 8 | jar 9 | 10 | OLAMI Java Client Examples: Text Input 11 | http://olami.ai 12 | 13 | 14 | ai.olami 15 | olami-java-client-sdk 16 | 1.5.1 17 | ../../pom.xml 18 | 19 | 20 | 21 | UTF-8 22 | 23 | 24 | 25 | 26 | junit 27 | junit 28 | 29 | 30 | ai.olami 31 | olami-java-client 32 | ${project.parent.version} 33 | 34 | 35 | ai.olami.example 36 | dump-nli-results-example 37 | 20180522 38 | 39 | 40 | 41 | 42 | 43 | 44 | org.apache.maven.plugins 45 | maven-compiler-plugin 46 | 47 | 48 | org.apache.maven.plugins 49 | maven-jar-plugin 50 | 51 | 52 | org.apache.maven.plugins 53 | maven-assembly-plugin 54 | 55 | 56 | 57 | org.apache.maven.plugins 58 | maven-antrun-plugin 59 | 60 | 61 | install 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | run 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | org.apache.maven.plugins 84 | maven-assembly-plugin 85 | 86 | ${project.artifactId} 87 | 88 | 89 | ai.olami.example.TextInputExample 90 | 91 | 92 | 93 | 94 | 95 | make-assembly 96 | package 97 | 98 | single 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /lib/src/main/java/ai/olami/ids/KKBOXData.java: -------------------------------------------------------------------------------- 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 | } 189 | -------------------------------------------------------------------------------- /lib/src/main/java/ai/olami/cloudService/APIResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017, 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.cloudService; 20 | 21 | import ai.olami.util.GsonFactory; 22 | 23 | import com.google.gson.Gson; 24 | import com.google.gson.annotations.Expose; 25 | import com.google.gson.annotations.SerializedName; 26 | 27 | public class APIResponse { 28 | 29 | public static final String STATUS_OK = "ok"; 30 | public static final String STATUS_ERROR = "error"; 31 | 32 | public static final int ERROR_CODE_INVALID_CONTENT = -1000000; 33 | 34 | @Expose(serialize = false, deserialize = false) 35 | @SerializedName("original_json_string_for_debug") 36 | private String mSourceJsonString = null; 37 | 38 | @Expose(serialize = false, deserialize = false) 39 | private Gson mGson = GsonFactory.getNormalGson(); 40 | 41 | @Expose 42 | @SerializedName("status") 43 | private String mStatus = STATUS_OK; 44 | 45 | @Expose 46 | @SerializedName("code") 47 | private int mCode; 48 | 49 | @Expose 50 | @SerializedName("msg") 51 | private String mMessage; 52 | 53 | @Expose 54 | @SerializedName("data") 55 | private APIResponseData mResponseData = null; 56 | 57 | @Override 58 | public String toString() { 59 | 60 | if (mSourceJsonString == null) { 61 | return mGson.toJson(this); 62 | } else { 63 | return mSourceJsonString; 64 | } 65 | 66 | } 67 | 68 | /** 69 | * Set the original JSON string. 70 | * This is helpful for debugging or to get other undefined members of this JSON string. 71 | * Use toString() method to get the original JSON string. 72 | * 73 | * @param jsonString - The original JSON string. 74 | */ 75 | public void setJsonStringSource(String jsonString) { 76 | mSourceJsonString = jsonString; 77 | } 78 | 79 | /** 80 | * Set as a invalid response. 81 | * 82 | * @param message - Error message to explain why this is an invalid result. 83 | */ 84 | public void setInvalid(String message) { 85 | setError(ERROR_CODE_INVALID_CONTENT, message); 86 | } 87 | 88 | /** 89 | * Set as a error response. 90 | * 91 | * @param errorCode - The error code. 92 | * @param errorMessage - Error message. 93 | */ 94 | public void setError(int errorCode, String errorMessage) { 95 | setStatus(STATUS_ERROR); 96 | setErrorCode(errorCode); 97 | setErrorMessage(errorMessage); 98 | } 99 | 100 | /** 101 | * Check whether the response status is OK (= STATUS_OK) or not. 102 | * 103 | * @return TRUE if the response status is OK. 104 | */ 105 | public boolean ok() { 106 | return getStatus().equals(STATUS_OK); 107 | } 108 | 109 | /** 110 | * Check whether the response status is OK (= STATUS_OK) or not. 111 | * 112 | * @return TRUE if something wrong, or FALSE if the response status is OK. 113 | */ 114 | public boolean hasError() { 115 | return (!ok()); 116 | } 117 | 118 | /** 119 | * @return Status 120 | */ 121 | public String getStatus() { 122 | return mStatus; 123 | } 124 | 125 | /** 126 | * Set status value. 127 | * 128 | * @param status - Status value string. 129 | */ 130 | public void setStatus(String status) { 131 | mStatus = status; 132 | } 133 | 134 | /** 135 | * @return Error code. 136 | */ 137 | public int getErrorCode() { 138 | return mCode; 139 | } 140 | 141 | /** 142 | * Set error code. 143 | * 144 | * @param errorEode - Error code. 145 | */ 146 | public void setErrorCode(int errorEode) { 147 | mCode = errorEode; 148 | } 149 | 150 | /** 151 | * @return Error message. 152 | */ 153 | public String getErrorMessage() { 154 | return mMessage; 155 | } 156 | 157 | /** 158 | * Set error message. 159 | * 160 | * @param errorMessage - Error message. 161 | */ 162 | public void setErrorMessage(String errorMessage) { 163 | mMessage = errorMessage; 164 | } 165 | 166 | /** 167 | * Get the response data. 168 | * Map to the member "data" of the JSON string. 169 | * 170 | * @return The response data object. 171 | */ 172 | public APIResponseData getData() { 173 | return mResponseData; 174 | } 175 | 176 | /** 177 | * @return TRUE if contains Data information. 178 | */ 179 | public boolean hasData() { 180 | return (mResponseData != null); 181 | } 182 | 183 | } 184 | -------------------------------------------------------------------------------- /examples/async-text-chatbot-example/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | ai.olami.example 6 | async-text-chatbot-example 7 | 20180413 8 | jar 9 | 10 | OLAMI Java Client Examples: Async Text Chatbot 11 | http://olami.ai 12 | 13 | 14 | ai.olami 15 | olami-java-client-sdk 16 | 1.5.1 17 | ../../pom.xml 18 | 19 | 20 | 21 | UTF-8 22 | 1.8 23 | 24 | 25 | 26 | 27 | junit 28 | junit 29 | 30 | 31 | ai.olami 32 | olami-java-client 33 | ${project.parent.version} 34 | 35 | 36 | ai.olami.example 37 | dump-nli-results-example 38 | 20180522 39 | 40 | 41 | 42 | 43 | 44 | 45 | org.apache.maven.plugins 46 | maven-compiler-plugin 47 | 48 | 49 | org.apache.maven.plugins 50 | maven-jar-plugin 51 | 52 | 53 | org.apache.maven.plugins 54 | maven-assembly-plugin 55 | 56 | 57 | 58 | org.apache.maven.plugins 59 | maven-antrun-plugin 60 | 61 | 62 | install 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | run 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | org.apache.maven.plugins 85 | maven-compiler-plugin 86 | 3.6.1 87 | 88 | 1.8 89 | 1.8 90 | 91 | 92 | 93 | org.apache.maven.plugins 94 | maven-assembly-plugin 95 | 96 | ${project.artifactId} 97 | 98 | 99 | ai.olami.example.AsyncTextChatbotExample 100 | 101 | 102 | 103 | 104 | 105 | make-assembly 106 | package 107 | 108 | single 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | -------------------------------------------------------------------------------- /examples/async-text-chatbot-example/src/main/java/ai/olami/example/AsyncTextChatbotExample.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017, 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.example; 20 | 21 | import java.util.Scanner; 22 | import java.util.concurrent.CompletableFuture; 23 | 24 | import ai.olami.cloudService.APIConfiguration; 25 | import ai.olami.cloudService.TextRecognizer; 26 | import ai.olami.nli.NLIResult; 27 | 28 | public class AsyncTextChatbotExample { 29 | 30 | // * Replace your APP KEY with this variable. 31 | private static String appKey = "*****your-app-key*****"; 32 | 33 | // * Replace your APP SECRET with this variable. 34 | private static String appSecret = "*****your-app-secret*****"; 35 | 36 | // * Replace the localize option you want with this variable. 37 | // * - Use LOCALIZE_OPTION_SIMPLIFIED_CHINESE for China 38 | // * - Use LOCALIZE_OPTION_TRADITIONAL_CHINESE for Taiwan 39 | private static int localizeOption = APIConfiguration.LOCALIZE_OPTION_SIMPLIFIED_CHINESE; 40 | // private static int localizeOption = APIConfiguration.LOCALIZE_OPTION_TRADITIONAL_CHINESE; 41 | 42 | public static void main(String[] args) throws Exception { 43 | if (args.length == 3) { 44 | initByInputArgs(args); 45 | } else if (args.length > 0) { 46 | printUsageAndExit(); 47 | } 48 | 49 | // * Step 1: Configure your key and localize option. 50 | APIConfiguration config = new APIConfiguration(appKey, appSecret, localizeOption); 51 | 52 | // * Step 2: Create the text recognizer. 53 | TextRecognizer recoginzer = new TextRecognizer(config); 54 | 55 | System.out.format("\nTell me your name: "); 56 | Scanner reader = new Scanner(System.in); 57 | 58 | boolean fristTalk = true; 59 | while (reader.hasNext()) { 60 | if (fristTalk) { 61 | String userName = reader.nextLine(); 62 | if (userName.isEmpty()) { 63 | userName = " YOU "; 64 | } 65 | // Setup end user information. 66 | recoginzer.setEndUserIdentifier(userName); 67 | 68 | fristTalk = false; 69 | System.out.format("\nHi! %s\n", userName); 70 | System.out.format("\nType to say something or 'bye' to exit:\n"); 71 | } 72 | 73 | String whatUserSays = reader.nextLine(); 74 | if (whatUserSays.toLowerCase().equals("bye")) { 75 | System.out.format("\n[ OLAMI Robot ] Says: Bye!\n\n"); 76 | reader.close(); 77 | break; 78 | } else { 79 | System.out.format("\n[ %s ] Says: %s\n", 80 | recoginzer.getEndUserIdentifier(), 81 | whatUserSays); 82 | } 83 | 84 | // Create async task to request OLAMI API. 85 | CompletableFuture.supplyAsync(() -> { 86 | // Send text to the recognizer. 87 | try { 88 | return recoginzer.requestNLI(whatUserSays); 89 | } catch (Exception e) { 90 | throw new RuntimeException(e); 91 | } 92 | }).whenComplete((response, exception) -> { 93 | // Get results to see the conversation reply. 94 | if (response.ok() && response.hasData()) { 95 | NLIResult[] nliResults = response.getData().getNLIResults(); 96 | // Get the reply content. 97 | if (nliResults[0].hasDescObject()) { 98 | String reply = nliResults[0].getDescObject().getReplyAnswer(); 99 | if (reply.isEmpty()) { 100 | System.out.format("\n[ OLAMI Robot ] Says: ...\n"); 101 | } else { 102 | // Show the reply. 103 | System.out.format( 104 | "\n[ OLAMI Robot ] Says: %s", reply); 105 | // Show IDS data. 106 | if (nliResults[0].isFromIDS() 107 | && nliResults[0].hasDataObjects()) { 108 | System.out.println("\n"); 109 | DumpIDSDataExample.dumpIDSData(nliResults[0]); 110 | System.out.println("\n"); 111 | } 112 | } 113 | System.out.format(" (Say 'bye' to exit)\n"); 114 | } 115 | } 116 | }); 117 | } 118 | } 119 | 120 | private static void printUsageAndExit() { 121 | System.out.println("\n Usage:"); 122 | System.out.println("\t args[0]: your_app_key"); 123 | System.out.println("\t args[1]: your_app_secret"); 124 | System.out.println("\t args[2]: localize_option=[0|1]"); 125 | System.out.println("\n"); 126 | System.exit(0); 127 | } 128 | 129 | private static void initByInputArgs(String[] args) { 130 | appKey = args[0]; 131 | appSecret = args[1]; 132 | localizeOption = Integer.parseInt(args[2]); 133 | } 134 | 135 | } 136 | -------------------------------------------------------------------------------- /lib/src/main/java/org/xiph/speex/RawWriter.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * Copyright (c) 1999-2004 Wimba S.A., All Rights Reserved. * 4 | * * 5 | * COPYRIGHT: * 6 | * This software is the property of Wimba S.A. * 7 | * This software is redistributed under the Xiph.org variant of * 8 | * the BSD license. * 9 | * Redistribution and use in source and binary forms, with or without * 10 | * modification, are permitted provided that the following conditions * 11 | * are met: * 12 | * - Redistributions of source code must retain the above copyright * 13 | * notice, this list of conditions and the following disclaimer. * 14 | * - Redistributions in binary form must reproduce the above copyright * 15 | * notice, this list of conditions and the following disclaimer in the * 16 | * documentation and/or other materials provided with the distribution. * 17 | * - Neither the name of Wimba, the Xiph.org Foundation nor the names of * 18 | * its contributors may be used to endorse or promote products derived * 19 | * from this software without specific prior written permission. * 20 | * * 21 | * WARRANTIES: * 22 | * This software is made available by the authors in the hope * 23 | * that it will be useful, but without any warranty. * 24 | * Wimba S.A. is not liable for any consequence related to the * 25 | * use of the provided software. * 26 | * * 27 | * Class: RawWriter.java * 28 | * * 29 | * Author: Marc GIMPEL * 30 | * * 31 | * Date: 6th January 2004 * 32 | * * 33 | ******************************************************************************/ 34 | 35 | /* $Id: RawWriter.java,v 1.2 2004/10/21 16:21:57 mgimpel Exp $ */ 36 | 37 | package org.xiph.speex; 38 | 39 | import java.io.File; 40 | import java.io.IOException; 41 | import java.io.OutputStream; 42 | import java.io.FileOutputStream; 43 | 44 | /** 45 | * Raw Audio File Writer. 46 | * 47 | * @author Marc Gimpel, Wimba S.A. (mgimpel@horizonwimba.com) 48 | * @version $Revision: 1.2 $ 49 | */ 50 | public class RawWriter 51 | extends AudioFileWriter 52 | { 53 | private OutputStream out; 54 | 55 | /** 56 | * Closes the output file. 57 | * @exception IOException if there was an exception closing the Audio Writer. 58 | */ 59 | public void close() 60 | throws IOException 61 | { 62 | out.close(); 63 | } 64 | 65 | /** 66 | * Open the output file. 67 | * @param file - file to open. 68 | * @exception IOException if there was an exception opening the Audio Writer. 69 | */ 70 | public void open(final File file) 71 | throws IOException 72 | { 73 | file.delete(); 74 | out = new FileOutputStream(file); 75 | } 76 | 77 | /** 78 | * Open the output file. 79 | * @param filename - file to open. 80 | * @exception IOException if there was an exception opening the Audio Writer. 81 | */ 82 | public void open(final String filename) 83 | throws IOException 84 | { 85 | open(new File(filename)); 86 | } 87 | 88 | /** 89 | * Writes the header pages that start the Ogg Speex file. 90 | * Prepares file for data to be written. 91 | * @param comment description to be included in the header. 92 | * @exception IOException 93 | */ 94 | public void writeHeader(final String comment) 95 | throws IOException 96 | { 97 | // a raw audio file has no header 98 | } 99 | 100 | /** 101 | * Writes a packet of audio. 102 | * @param data audio data 103 | * @param offset the offset from which to start reading the data. 104 | * @param len the length of data to read. 105 | * @exception IOException 106 | */ 107 | public void writePacket(final byte[] data, 108 | final int offset, 109 | final int len) 110 | throws IOException 111 | { 112 | out.write(data, offset, len); 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /lib/src/main/java/ai/olami/nli/DescObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017, 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.nli; 20 | 21 | import ai.olami.ids.IDSResult; 22 | 23 | import com.google.gson.annotations.Expose; 24 | import com.google.gson.annotations.SerializedName; 25 | 26 | public class DescObject { 27 | 28 | public static final int STATUS_SUCCESS = 0; 29 | public static final int STATUS_SELECTION_OVERFLOW = 1001; 30 | public static final int STATUS_NO_MATCHED_GRAMMAR = 1003; 31 | public static final int STATUS_INPUT_LENGTH_TOO_LONG = 1005; 32 | public static final int STATUS_TIMEOUT = 3001; 33 | public static final int STATUS_SERVER_ERROR= 3003; 34 | public static final int STATUS_EXCEPTION= 3004; 35 | 36 | public static final String TYPE_WEATHER = IDSResult.Types.WEATHER.getName(); 37 | public static final String TYPE_BAIKE = IDSResult.Types.BAIKE.getName(); 38 | public static final String TYPE_NEWS = IDSResult.Types.NEWS.getName(); 39 | public static final String TYPE_TV_PROGRAM = IDSResult.Types.TV_PROGRAM.getName(); 40 | public static final String TYPE_POEM = IDSResult.Types.POEM.getName(); 41 | public static final String TYPE_JOKE = IDSResult.Types.JOKE.getName(); 42 | public static final String TYPE_STORY = "story"; 43 | public static final String TYPE_STOCK_MARKET = IDSResult.Types.STOCK_MARKET.getName(); 44 | public static final String TYPE_MATH = IDSResult.Types.MATH.getName(); 45 | public static final String TYPE_UNIT_CONVERT = IDSResult.Types.UNIT_CONVERT.getName(); 46 | public static final String TYPE_EXCHANGE_RATE = IDSResult.Types.EXCHANGE_RATE.getName(); 47 | public static final String TYPE_COOKING = IDSResult.Types.COOKING.getName(); 48 | public static final String TYPE_SEARCH = "search"; 49 | public static final String TYPE_SHOPPING = "shopping"; 50 | 51 | @Expose 52 | @SerializedName("result") 53 | protected String mResult = null; 54 | 55 | /** 56 | * Get a chat reply, the answer to the conversation text input. 57 | * If the input text not matches any grammar you configured on the NLI system, 58 | * the result will be automatically generated by OLAMI intelligent dialogue system. 59 | * 60 | * @return Chat reply text. 61 | */ 62 | public String getReplyAnswer() { 63 | return (mResult == null) ? "" : mResult; 64 | } 65 | 66 | /** 67 | * @return TRUE if contains chat reply. 68 | */ 69 | public boolean hasReplyAnswer() { 70 | return ((mResult != null) && (!mResult.equals(""))); 71 | } 72 | 73 | @Expose 74 | @SerializedName("status") 75 | protected int mStatus = 0; 76 | 77 | /** 78 | * Get the status of grammar analysis. 79 | * 80 | * @return 0 if system has understood the input statements, or others for other issues. 81 | */ 82 | public int getStatus() { 83 | return mStatus; 84 | } 85 | 86 | @Expose 87 | @SerializedName("type") 88 | protected String mType = null; 89 | 90 | /** 91 | * Get type name, it usually refers to the IDS module name. 92 | * 93 | * @return Type name. 94 | */ 95 | public String getType() { 96 | return (mType == null) ? "" : mType; 97 | } 98 | 99 | /** 100 | * @return TRUE if contains type information. 101 | */ 102 | public boolean hasType() { 103 | return ((mType != null) && (!mType.equals(""))); 104 | } 105 | 106 | @Expose 107 | @SerializedName("url") 108 | protected String mURL = null; 109 | 110 | /** 111 | * Get URL, it usually used in the IDS module. 112 | * 113 | * @return URL. 114 | */ 115 | public String getURL() { 116 | return (mURL == null) ? "" : mURL; 117 | } 118 | 119 | /** 120 | * @return TRUE if contains URL information. 121 | */ 122 | public boolean hasURL() { 123 | return ((mURL != null) && (!mURL.equals(""))); 124 | } 125 | 126 | @Expose 127 | @SerializedName("name") 128 | protected String mName = null; 129 | 130 | /** 131 | * Get Name information, it usually used in the IDS module. 132 | * 133 | * @return Name information. 134 | */ 135 | public String getName() { 136 | return (mName == null) ? "" : mName; 137 | } 138 | 139 | /** 140 | * @return TRUE if contains name information. 141 | */ 142 | public boolean hasName() { 143 | return ((mName != null) && (!mName.equals(""))); 144 | } 145 | 146 | @Expose 147 | @SerializedName("source_currency") 148 | protected String mSourceCurrency = null; 149 | 150 | /** 151 | * Get source currency information, it usually used in the IDS module. 152 | * 153 | * @return Name information. 154 | */ 155 | public String getSourceCurrency() { 156 | return (mSourceCurrency == null) ? "" : mSourceCurrency; 157 | } 158 | 159 | /** 160 | * @return TRUE if contains source currency information. 161 | */ 162 | public boolean hasSourceCurrency() { 163 | return ((mSourceCurrency != null) && (!mSourceCurrency.equals(""))); 164 | } 165 | 166 | } 167 | -------------------------------------------------------------------------------- /lib/src/main/java/ai/olami/cloudService/TextRecognizer.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017, 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.cloudService; 20 | 21 | import ai.olami.util.GsonFactory; 22 | import ai.olami.util.HttpClient; 23 | 24 | import java.io.IOException; 25 | import java.net.HttpURLConnection; 26 | import java.net.URL; 27 | import java.security.NoSuchAlgorithmException; 28 | 29 | import com.google.gson.Gson; 30 | import com.google.gson.JsonObject; 31 | 32 | public class TextRecognizer extends APIRequestBase { 33 | 34 | public static final String RQ_DATA_TYPE_STT = "stt"; 35 | 36 | public static final int RQ_DATA_INPUT_TYPE_FROM_SPEECH = 0; 37 | public static final int RQ_DATA_INPUT_TYPE_FROM_TEXT = 1; 38 | 39 | private int mRqDataInputType = RQ_DATA_INPUT_TYPE_FROM_SPEECH; 40 | private Gson mGson = GsonFactory.getNormalGson(); 41 | 42 | /** 43 | * Text Recognizer to issue Natural Language Understanding API requests. 44 | * 45 | * @param configuration - API configurations. 46 | */ 47 | public TextRecognizer(APIConfiguration configuration) { 48 | super(configuration); 49 | } 50 | 51 | /** 52 | * Set NLI data input type. 53 | * 54 | * @param inputType 0 for speech source, or 1 for text source. 55 | */ 56 | public void setNLIDataInputType(int inputType) { 57 | mRqDataInputType = inputType; 58 | } 59 | 60 | /** 61 | * Request word segmentation analyze service by specified input text. 62 | * 63 | * @param text - The text to be analyzed. 64 | * @return API response with analysis results. 65 | * @throws NoSuchAlgorithmException Failed to create signature. 66 | * @throws IOException HTTP connection failed, or other exceptions. 67 | */ 68 | public APIResponse requestWordSegmentation(String text) 69 | throws NoSuchAlgorithmException, IOException { 70 | return sendRequest(APIConfiguration.API_NAME_SEG, text, null); 71 | } 72 | 73 | /** 74 | * Request Natural Language Interaction service by specified input text. 75 | * 76 | * @param text - The text to be recognized. 77 | * @return API response with Natural Language Interaction results. 78 | * @throws NoSuchAlgorithmException Failed to create signature. 79 | * @throws IOException HTTP connection failed, or other exceptions. 80 | */ 81 | public APIResponse requestNLI(String text) 82 | throws NoSuchAlgorithmException, IOException { 83 | return requestNLI(text, null); 84 | } 85 | 86 | /** 87 | * Request Natural Language Interaction service by specified input text. 88 | * 89 | * @param text - The text to be recognized. 90 | * @param nliConfig - NLIConfig object. 91 | * @return API response with Natural Language Interaction results. 92 | * @throws NoSuchAlgorithmException Failed to create signature. 93 | * @throws IOException HTTP connection failed, or other exceptions. 94 | */ 95 | public APIResponse requestNLI( 96 | String text, 97 | NLIConfig nliConfig 98 | ) throws NoSuchAlgorithmException, IOException { 99 | return sendRequest(APIConfiguration.API_NAME_NLI, text, nliConfig); 100 | } 101 | 102 | private APIResponse sendRequest( 103 | String apiName, 104 | String text, 105 | NLIConfig nliConfig 106 | ) throws NoSuchAlgorithmException, IOException { 107 | 108 | StringBuffer httpQueryStringBuffer = new StringBuffer(); 109 | 110 | if (apiName == APIConfiguration.API_NAME_SEG) { 111 | httpQueryStringBuffer.append("rq="); 112 | httpQueryStringBuffer.append(text); 113 | } else if (apiName == APIConfiguration.API_NAME_NLI) { 114 | JsonObject data = new JsonObject(); 115 | data.addProperty("input_type", mRqDataInputType); 116 | data.addProperty("text", text); 117 | JsonObject rq = new JsonObject(); 118 | rq.addProperty("data_type", "stt"); 119 | rq.add("data", data); 120 | if (nliConfig != null) { 121 | rq.add("nli_config", nliConfig.toJsonElement()); 122 | } 123 | httpQueryStringBuffer.append("rq="); 124 | httpQueryStringBuffer.append(mGson.toJson(rq)); 125 | } 126 | 127 | final URL url = new URL(getConfiguration().getBaseRequestURL(apiName)); 128 | final HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection(); 129 | httpConnection.setRequestMethod("POST"); 130 | httpConnection.setRequestProperty("contentType", "utf-8"); 131 | httpConnection.setConnectTimeout(getTimeout()); 132 | 133 | HttpClient httpClient = null; 134 | String response = null; 135 | 136 | try { 137 | httpClient = new HttpClient(httpConnection); 138 | httpClient.postQueryConnect(httpQueryStringBuffer.toString()); 139 | if(httpClient.getResponseCode() == HttpURLConnection.HTTP_OK) { 140 | response = httpClient.getResponseContent(); 141 | } else { 142 | throw new IOException(httpClient.getResponseMessage()); 143 | } 144 | } finally { 145 | httpClient.close(); 146 | } 147 | 148 | return APIResponseBuilder.create(response); 149 | } 150 | 151 | } 152 | -------------------------------------------------------------------------------- /examples/microphone-speech-input-example/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | ai.olami.example 6 | microphone-speech-input-example 7 | 20180413 8 | jar 9 | 10 | OLAMI Java Client Examples: Microphone Speech Input 11 | http://olami.ai 12 | 13 | 14 | ai.olami 15 | olami-java-client-sdk 16 | 1.5.1 17 | ../../pom.xml 18 | 19 | 20 | 21 | UTF-8 22 | 23 | 24 | 25 | 26 | junit 27 | junit 28 | 29 | 30 | ai.olami 31 | olami-java-client 32 | ${project.parent.version} 33 | 34 | 35 | 36 | 37 | 38 | 39 | org.apache.maven.plugins 40 | maven-compiler-plugin 41 | 42 | 43 | org.apache.maven.plugins 44 | maven-jar-plugin 45 | 46 | 47 | org.apache.maven.plugins 48 | maven-assembly-plugin 49 | 50 | 51 | 52 | com.akathist.maven.plugins.launch4j 53 | launch4j-maven-plugin 54 | 1.7.21 55 | 56 | 57 | l4j-clui 58 | install 59 | launch4j 60 | 61 | console 62 | target/${project.artifactId}.exe 63 | target/${project.artifactId}.jar 64 | encc 65 | 66 | ai.olami.example.MicrophoneSpeechGUIExample 67 | true 68 | anything 69 | 70 | 71 | 1.7.0 72 | 73 | -Djava.endorsed.dirs=./endorsed 74 | -Dfile.encoding=UTF-8 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | org.apache.maven.plugins 85 | maven-antrun-plugin 86 | 87 | 88 | install 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | run 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | org.apache.maven.plugins 112 | maven-assembly-plugin 113 | 114 | ${project.artifactId} 115 | 116 | 117 | ai.olami.example.MicrophoneSpeechGUIExample 118 | 119 | 120 | 121 | 122 | 123 | make-assembly 124 | package 125 | 126 | single 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | -------------------------------------------------------------------------------- /lib/src/main/java/ai/olami/ids/WeatherData.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017, 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 WeatherData { 25 | 26 | @Expose 27 | @SerializedName("city") 28 | private String mCity = null; 29 | 30 | /** 31 | * @return City name. 32 | */ 33 | public String getCity() { 34 | return (mCity == null) ? "" : mCity; 35 | } 36 | 37 | /** 38 | * @return TRUE if contains city name. 39 | */ 40 | public boolean hasCity() { 41 | return ((mCity != null) && (!mCity.equals(""))); 42 | } 43 | 44 | @Expose 45 | @SerializedName("real_date") 46 | private long mRealDate = -1; 47 | 48 | /** 49 | * @return Date since 1970. 50 | */ 51 | public long getRealDate() { 52 | return mRealDate; 53 | } 54 | 55 | @Expose 56 | @SerializedName("date") 57 | private int mDate = -1; 58 | 59 | /** 60 | * Date description. 61 | * 62 | * @return 0 means the day, 1 means tomorrow, and so on. 63 | */ 64 | public int getDate() { 65 | return mDate; 66 | } 67 | 68 | @Expose 69 | @SerializedName("weather_start") 70 | private int mWeatherStart = -1; 71 | 72 | /** 73 | * Get the weather type code for the morning. 74 | * 75 | * @return Weather type code. 76 | */ 77 | public int getWeatherStart() { 78 | return mWeatherStart; 79 | } 80 | 81 | @Expose 82 | @SerializedName("weather_end") 83 | private int mWeatherEnd = -1; 84 | 85 | /** 86 | * Get the weather type code for the evening. 87 | * 88 | * @return Weather type code. 89 | */ 90 | public int getWeatherEnd() { 91 | return mWeatherEnd; 92 | } 93 | 94 | @Expose 95 | @SerializedName("wind") 96 | private String mWind = null; 97 | 98 | /** 99 | * @return Wind direction. 100 | */ 101 | public String getWind() { 102 | return (mWind == null) ? "" : mWind; 103 | } 104 | 105 | /** 106 | * @return TRUE if contains wind direction. 107 | */ 108 | public boolean hasWind() { 109 | return ((mWind != null) && (!mWind.equals(""))); 110 | } 111 | 112 | @Expose 113 | @SerializedName("temperature_high") 114 | private String mTemperatureHigh = null; 115 | 116 | /** 117 | * @return Maximum temperature. 118 | */ 119 | public String getMaxTemperature() { 120 | return (mTemperatureHigh == null) ? "" : mTemperatureHigh; 121 | } 122 | 123 | /** 124 | * @return TRUE if contains maximum temperature. 125 | */ 126 | public boolean hasMaxTemperature() { 127 | return ((mTemperatureHigh != null) && (!mTemperatureHigh.equals(""))); 128 | } 129 | 130 | @Expose 131 | @SerializedName("temperature_low") 132 | private String mTemperatureLow = null; 133 | 134 | /** 135 | * @return Minimum temperature. 136 | */ 137 | public String getMinTemperature() { 138 | return (mTemperatureLow == null) ? "" : mTemperatureLow; 139 | } 140 | 141 | /** 142 | * @return TRUE if contains minimum temperature. 143 | */ 144 | public boolean hasMinTemperature() { 145 | return ((mTemperatureLow != null) && (!mTemperatureLow.equals(""))); 146 | } 147 | 148 | @Expose 149 | @SerializedName("description") 150 | private String mDescription = null; 151 | 152 | /** 153 | * @return Description. 154 | */ 155 | public String getDescription() { 156 | return (mDescription == null) ? "" : mDescription; 157 | } 158 | 159 | /** 160 | * @return TRUE if contains description. 161 | */ 162 | public boolean hasDescription() { 163 | return ((mDescription != null) && (!mDescription.equals(""))); 164 | } 165 | 166 | @Expose 167 | @SerializedName("exponent_type") 168 | private String[] mExponentType = null; 169 | 170 | /** 171 | * @return Exponent type. 172 | */ 173 | public String[] getExponentType() { 174 | return (mExponentType == null) ? new String[]{""} : mExponentType; 175 | } 176 | 177 | /** 178 | * @return TRUE if contains exponent type. 179 | */ 180 | public boolean hasExponentType() { 181 | return ((mExponentType != null) && (mExponentType.length > 0)); 182 | } 183 | 184 | @Expose 185 | @SerializedName("exponent_value") 186 | private String[] mExponentValue = null; 187 | 188 | /** 189 | * @return Exponent value. 190 | */ 191 | public String[] getExponentValue() { 192 | return (mExponentValue == null) ? new String[]{""} : mExponentValue; 193 | } 194 | 195 | /** 196 | * @return TRUE if contains exponent value. 197 | */ 198 | public boolean hasExponentValue() { 199 | return ((mExponentValue != null) && (mExponentValue.length > 0)); 200 | } 201 | 202 | @Expose 203 | @SerializedName("is_querying") 204 | private int mIsQuering = 0; 205 | 206 | /** 207 | * @return TRUE if this data is for the main query target. 208 | */ 209 | public boolean isQueryTarget() { 210 | return (mIsQuering == 1); 211 | } 212 | 213 | @Expose 214 | @SerializedName("pm25") 215 | private int mPM25 = -1; 216 | 217 | /** 218 | * @return PM 2.5. 219 | */ 220 | public int getPM25() { 221 | return mPM25; 222 | } 223 | 224 | } 225 | -------------------------------------------------------------------------------- /examples/speech-input-example/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | ai.olami.example 6 | speech-input-example 7 | 20180413 8 | jar 9 | 10 | OLAMI Java Client Examples: Speech Input 11 | http://olami.ai 12 | 13 | 14 | ai.olami 15 | olami-java-client-sdk 16 | 1.5.1 17 | ../../pom.xml 18 | 19 | 20 | 21 | UTF-8 22 | 23 | 24 | 25 | 26 | junit 27 | junit 28 | 29 | 30 | ai.olami 31 | olami-java-client 32 | ${project.parent.version} 33 | 34 | 35 | ai.olami.example 36 | dump-nli-results-example 37 | 20180522 38 | 39 | 40 | 41 | 42 | 43 | 44 | org.apache.maven.plugins 45 | maven-compiler-plugin 46 | 47 | 48 | org.apache.maven.plugins 49 | maven-jar-plugin 50 | 51 | 52 | org.apache.maven.plugins 53 | maven-assembly-plugin 54 | 55 | 56 | 57 | org.apache.maven.plugins 58 | maven-antrun-plugin 59 | 60 | 61 | package 62 | package 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | run 77 | 78 | 79 | 80 | install 81 | install 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | run 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | org.apache.maven.plugins 110 | maven-assembly-plugin 111 | 112 | ${project.artifactId} 113 | 114 | 115 | ai.olami.example.SpeechInputExample 116 | 117 | 118 | 119 | 120 | 121 | make-assembly 122 | package 123 | 124 | single 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | -------------------------------------------------------------------------------- /lib/src/main/java/org/xiph/speex/Inband.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * Copyright (c) 1999-2003 Wimba S.A., All Rights Reserved. * 4 | * * 5 | * COPYRIGHT: * 6 | * This software is the property of Wimba S.A. * 7 | * This software is redistributed under the Xiph.org variant of * 8 | * the BSD license. * 9 | * Redistribution and use in source and binary forms, with or without * 10 | * modification, are permitted provided that the following conditions * 11 | * are met: * 12 | * - Redistributions of source code must retain the above copyright * 13 | * notice, this list of conditions and the following disclaimer. * 14 | * - Redistributions in binary form must reproduce the above copyright * 15 | * notice, this list of conditions and the following disclaimer in the * 16 | * documentation and/or other materials provided with the distribution. * 17 | * - Neither the name of Wimba, the Xiph.org Foundation nor the names of * 18 | * its contributors may be used to endorse or promote products derived * 19 | * from this software without specific prior written permission. * 20 | * * 21 | * WARRANTIES: * 22 | * This software is made available by the authors in the hope * 23 | * that it will be useful, but without any warranty. * 24 | * Wimba S.A. is not liable for any consequence related to the * 25 | * use of the provided software. * 26 | * * 27 | * Class: Inband.java * 28 | * * 29 | * Author: Marc GIMPEL * 30 | * * 31 | * Date: 14th July 2003 * 32 | * * 33 | ******************************************************************************/ 34 | 35 | /* $Id: Inband.java,v 1.2 2004/10/21 16:21:57 mgimpel Exp $ */ 36 | 37 | package org.xiph.speex; 38 | 39 | import java.io.StreamCorruptedException; 40 | 41 | /** 42 | * Speex in-band and User in-band controls. 43 | * 44 | * @author Marc Gimpel, Wimba S.A. (mgimpel@horizonwimba.com) 45 | * @version $Revision: 1.2 $ 46 | */ 47 | public class Inband 48 | { 49 | private Stereo stereo; 50 | 51 | /** 52 | * Constructor. 53 | * @param stereo 54 | */ 55 | public Inband (final Stereo stereo) 56 | { 57 | this.stereo = stereo; 58 | } 59 | 60 | /** 61 | * Speex in-band request (submode=14). 62 | * @param bits - Speex bits buffer. 63 | * @throws StreamCorruptedException If stream seems corrupted. 64 | */ 65 | public void speexInbandRequest(final Bits bits) 66 | throws StreamCorruptedException 67 | { 68 | int code = bits.unpack(4); 69 | switch (code) { 70 | case 0: // asks the decoder to set perceptual enhancment off (0) or on (1) 71 | bits.advance(1); 72 | break; 73 | case 1: // asks (if 1) the encoder to be less "aggressive" due to high packet loss 74 | bits.advance(1); 75 | break; 76 | case 2: // asks the encoder to switch to mode N 77 | bits.advance(4); 78 | break; 79 | case 3: // asks the encoder to switch to mode N for low-band 80 | bits.advance(4); 81 | break; 82 | case 4: // asks the encoder to switch to mode N for high-band 83 | bits.advance(4); 84 | break; 85 | case 5: // asks the encoder to switch to quality N for VBR 86 | bits.advance(4); 87 | break; 88 | case 6: // request acknowledgement (0=no, 1=all, 2=only for inband data) 89 | bits.advance(4); 90 | break; 91 | case 7: // asks the encoder to set CBR(0), VAD(1), DTX(3), VBR(5), VBR+DTX(7) 92 | bits.advance(4); 93 | break; 94 | case 8: // transmit (8-bit) character to the other end 95 | bits.advance(8); 96 | break; 97 | case 9: // intensity stereo information 98 | // setup the stereo decoder; to skip: tmp = bits.unpack(8); break; 99 | stereo.init(bits); // read 8 bits 100 | break; 101 | case 10: // announce maximum bit-rate acceptable (N in byets/second) 102 | bits.advance(16); 103 | break; 104 | case 11: // reserved 105 | bits.advance(16); 106 | break; 107 | case 12: // Acknowledge receiving packet N 108 | bits.advance(32); 109 | break; 110 | case 13: // reserved 111 | bits.advance(32); 112 | break; 113 | case 14: // reserved 114 | bits.advance(64); 115 | break; 116 | case 15: // reserved 117 | bits.advance(64); 118 | break; 119 | default: 120 | } 121 | } 122 | 123 | /** 124 | * User in-band request (submode=13). 125 | * @param bits - Speex bits buffer. 126 | * @throws StreamCorruptedException If stream seems corrupted. 127 | */ 128 | public void userInbandRequest(final Bits bits) 129 | throws StreamCorruptedException 130 | { 131 | int req_size = bits.unpack(4); 132 | bits.advance(5+8*req_size); 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /lib/src/main/java/ai/olami/util/HttpClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017, 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.util; 20 | 21 | import java.io.BufferedReader; 22 | import java.io.IOException; 23 | import java.io.InputStreamReader; 24 | import java.io.OutputStream; 25 | import java.net.HttpURLConnection; 26 | import java.nio.charset.StandardCharsets; 27 | import java.util.List; 28 | import java.util.Map; 29 | 30 | public class HttpClient { 31 | 32 | private final HttpURLConnection mHttpConnection; 33 | private OutputStream mOutStream = null; 34 | 35 | /** 36 | * HTTP connection utility. 37 | * 38 | * @param httpConnection - HttpURLConnection target. 39 | */ 40 | public HttpClient(final HttpURLConnection httpConnection) { 41 | 42 | if (httpConnection == null) { 43 | throw new IllegalArgumentException("HttpURLConnection is null."); 44 | } 45 | 46 | mHttpConnection = httpConnection; 47 | 48 | } 49 | 50 | /** 51 | * Connect without stream data output. 52 | * 53 | * @throws IOException HTTP connection failed. 54 | */ 55 | public void normalConnect() throws IOException { 56 | mHttpConnection.connect(); 57 | } 58 | 59 | /** 60 | * Connect with stream data output and send queries by a string. 61 | * 62 | * @param queryParams - A string that contains query parameters. 63 | * @throws IOException HTTP connection failed. 64 | */ 65 | public void postQueryConnect(final String queryParams) throws IOException { 66 | 67 | mHttpConnection.setDoOutput(true); 68 | 69 | mOutStream = mHttpConnection.getOutputStream(); 70 | if (!queryParams.startsWith("&")) { 71 | mOutStream.write("&".getBytes("utf-8")); 72 | } 73 | mOutStream.write(queryParams.getBytes("utf-8")); 74 | mOutStream.flush(); 75 | mOutStream.close(); 76 | 77 | } 78 | 79 | /** 80 | * Connect with stream data output and send queries. 81 | * 82 | * @param queryParams - Key-Value query parameters. 83 | * @throws IOException HTTP connection failed. 84 | */ 85 | public void postQueryConnect(Map queryParams) 86 | throws IOException { 87 | 88 | StringBuffer queryParamsStringBuffer = new StringBuffer(); 89 | if (queryParams != null) { 90 | for (Object key : queryParams.keySet()) { 91 | queryParamsStringBuffer.append("&"); 92 | queryParamsStringBuffer.append(key.toString()); 93 | queryParamsStringBuffer.append("="); 94 | queryParamsStringBuffer.append(queryParams.get(key)); 95 | } 96 | } 97 | 98 | postQueryConnect(queryParamsStringBuffer.toString()); 99 | 100 | } 101 | 102 | /** 103 | * Connect and send data by "Content-Type: application/octet-stream". 104 | * 105 | * @param streamBuffer - The buffer that contains data you want to send. 106 | * @param writeBytes - How many bytes you want to send in this buffer. 107 | * @throws IOException HTTP connection failed. 108 | */ 109 | public void octetStreamConnect( 110 | final byte[] streamBuffer, 111 | final int writeBytes 112 | ) throws IOException { 113 | 114 | mHttpConnection.setDoOutput(true); 115 | mHttpConnection.setRequestProperty("Connection", "Keep-Alive"); 116 | mHttpConnection.setRequestProperty("Content-Type", "application/octet-stream"); 117 | 118 | mOutStream = mHttpConnection.getOutputStream(); 119 | mOutStream.write(streamBuffer, 0, writeBytes); 120 | mOutStream.flush(); 121 | mOutStream.close(); 122 | 123 | } 124 | 125 | /** 126 | * Get the response content after the connection. 127 | * 128 | * @return Response content. 129 | * @throws IOException - HTTP connection failed. 130 | */ 131 | public String getResponseContent() throws IOException { 132 | 133 | BufferedReader inputReader = null; 134 | StringBuffer inputStringBuffer = new StringBuffer(); 135 | 136 | try { 137 | inputReader = new BufferedReader(new InputStreamReader( 138 | mHttpConnection.getInputStream(), StandardCharsets.UTF_8)); 139 | String inputLine; 140 | while ((inputLine = inputReader.readLine()) != null) { 141 | inputStringBuffer.append(inputLine); 142 | } 143 | inputReader.close(); 144 | } finally { 145 | if (inputReader != null) { 146 | inputReader.close(); 147 | } 148 | } 149 | 150 | return inputStringBuffer.toString(); 151 | 152 | } 153 | 154 | /** 155 | * Get the response code after the connection. 156 | * 157 | * @return Response Code. 158 | * @throws IOException - HTTP connection failed. 159 | */ 160 | public int getResponseCode() throws IOException { 161 | return mHttpConnection.getResponseCode(); 162 | } 163 | 164 | /** 165 | * Get the response message after the connection. 166 | * 167 | * @return Response message. 168 | * @throws IOException - HTTP connection failed. 169 | */ 170 | public String getResponseMessage() throws IOException { 171 | return mHttpConnection.getResponseMessage(); 172 | } 173 | 174 | /** 175 | * Get the Cookies after the connection. 176 | * 177 | * @return Cookies. 178 | */ 179 | public List getCookies() { 180 | return mHttpConnection.getHeaderFields().get("Set-Cookie"); 181 | } 182 | 183 | /** 184 | * Close connection and all possible resources. 185 | * 186 | * @throws IOException - HTTP connection failed. 187 | */ 188 | public void close() throws IOException { 189 | 190 | if (mOutStream != null) { 191 | mOutStream.close(); 192 | } 193 | 194 | if (mHttpConnection != null) { 195 | mHttpConnection.disconnect(); 196 | } 197 | 198 | } 199 | 200 | } 201 | -------------------------------------------------------------------------------- /lib/src/main/java/org/xiph/speex/CbSearch.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * Copyright (c) 1999-2003 Wimba S.A., All Rights Reserved. * 4 | * * 5 | * COPYRIGHT: * 6 | * This software is the property of Wimba S.A. * 7 | * This software is redistributed under the Xiph.org variant of * 8 | * the BSD license. * 9 | * Redistribution and use in source and binary forms, with or without * 10 | * modification, are permitted provided that the following conditions * 11 | * are met: * 12 | * - Redistributions of source code must retain the above copyright * 13 | * notice, this list of conditions and the following disclaimer. * 14 | * - Redistributions in binary form must reproduce the above copyright * 15 | * notice, this list of conditions and the following disclaimer in the * 16 | * documentation and/or other materials provided with the distribution. * 17 | * - Neither the name of Wimba, the Xiph.org Foundation nor the names of * 18 | * its contributors may be used to endorse or promote products derived * 19 | * from this software without specific prior written permission. * 20 | * * 21 | * WARRANTIES: * 22 | * This software is made available by the authors in the hope * 23 | * that it will be useful, but without any warranty. * 24 | * Wimba S.A. is not liable for any consequence related to the * 25 | * use of the provided software. * 26 | * * 27 | * Class: CbSearch.java * 28 | * * 29 | * Author: James LAWRENCE * 30 | * Modified by: Marc GIMPEL * 31 | * Based on code by: Jean-Marc VALIN * 32 | * * 33 | * Date: March 2003 * 34 | * * 35 | ******************************************************************************/ 36 | 37 | /* $Id: CbSearch.java,v 1.2 2004/10/21 16:21:57 mgimpel Exp $ */ 38 | 39 | /* Copyright (C) 2002 Jean-Marc Valin 40 | 41 | Redistribution and use in source and binary forms, with or without 42 | modification, are permitted provided that the following conditions 43 | are met: 44 | 45 | - Redistributions of source code must retain the above copyright 46 | notice, this list of conditions and the following disclaimer. 47 | 48 | - Redistributions in binary form must reproduce the above copyright 49 | notice, this list of conditions and the following disclaimer in the 50 | documentation and/or other materials provided with the distribution. 51 | 52 | - Neither the name of the Xiph.org Foundation nor the names of its 53 | contributors may be used to endorse or promote products derived from 54 | this software without specific prior written permission. 55 | 56 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 57 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 58 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 59 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 60 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 61 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 62 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 63 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 64 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 65 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 66 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 67 | */ 68 | 69 | package org.xiph.speex; 70 | 71 | /** 72 | * Abstract class that is the base for the various Codebook search methods. 73 | * 74 | * @author Jim Lawrence, helloNetwork.com 75 | * @author Marc Gimpel, Wimba S.A. (mgimpel@horizonwimba.com) 76 | * @version $Revision: 1.2 $ 77 | */ 78 | public abstract class CbSearch 79 | { 80 | /** 81 | * Codebook Search Quantification. 82 | * @param target target vector 83 | * @param ak LPCs for this subframe 84 | * @param awk1 Weighted LPCs for this subframe 85 | * @param awk2 Weighted LPCs for this subframe 86 | * @param p number of LPC coeffs 87 | * @param nsf number of samples in subframe 88 | * @param exc excitation array. 89 | * @param es position in excitation array. 90 | * @param r 91 | * @param bits Speex bits buffer. 92 | * @param complexity 93 | */ 94 | public abstract void quant(float[] target, float[] ak, float[] awk1, float[] awk2, 95 | int p, int nsf, float[] exc, int es, float[] r, 96 | Bits bits, int complexity); 97 | 98 | /** 99 | * Codebook Search Unquantification. 100 | * @param exc - excitation array. 101 | * @param es - position in excitation array. 102 | * @param nsf - number of samples in subframe. 103 | * @param bits - Speex bits buffer. 104 | */ 105 | public abstract void unquant(float[] exc, int es, int nsf, Bits bits); 106 | } 107 | -------------------------------------------------------------------------------- /examples/text-input-example/src/main/java/ai/olami/example/TextInputExample.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017, 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.example; 20 | 21 | import com.google.gson.Gson; 22 | 23 | import ai.olami.cloudService.APIConfiguration; 24 | import ai.olami.cloudService.APIResponse; 25 | import ai.olami.cloudService.NLIConfig; 26 | import ai.olami.cloudService.TextRecognizer; 27 | import ai.olami.nli.NLIResult; 28 | import ai.olami.util.GsonFactory; 29 | 30 | public class TextInputExample { 31 | 32 | // * Replace your APP KEY with this variable. 33 | private static String appKey = "*****your-app-key*****"; 34 | 35 | // * Replace your APP SECRET with this variable. 36 | private static String appSecret = "*****your-app-secret*****"; 37 | 38 | // * Replace the text you want to analyze with this variable. 39 | private static String inputText = "我要唱歌"; 40 | 41 | // * Replace the localize option you want with this variable. 42 | // * - Use LOCALIZE_OPTION_SIMPLIFIED_CHINESE for China 43 | // * - Use LOCALIZE_OPTION_TRADITIONAL_CHINESE for Taiwan 44 | private static int localizeOption = APIConfiguration.LOCALIZE_OPTION_SIMPLIFIED_CHINESE; 45 | // private static int localizeOption = APIConfiguration.LOCALIZE_OPTION_TRADITIONAL_CHINESE; 46 | 47 | public static void main(String[] args) throws Exception { 48 | if (args.length == 4) { 49 | initByInputArgs(args); 50 | } else if (args.length > 0) { 51 | printUsageAndExit(); 52 | } 53 | 54 | Gson jsonDump = GsonFactory.getDebugGson(false); 55 | 56 | // * Step 1: Configure your key and localize option. 57 | APIConfiguration config = new APIConfiguration(appKey, appSecret, localizeOption); 58 | 59 | // * Step 2: Create the text recognizer. 60 | TextRecognizer recoginzer = new TextRecognizer(config); 61 | 62 | // * Optional steps: Setup some other configurations. 63 | recoginzer.setEndUserIdentifier("Someone"); 64 | recoginzer.setTimeout(10000); 65 | 66 | // EXAMPLE 1: Request word segmentation analysis. 67 | System.out.println("\n[Example 1] ================================"); 68 | System.out.println("\nRequest word segmentation for : " + inputText); 69 | // * Send text 70 | APIResponse wsResponse = recoginzer.requestWordSegmentation(inputText); 71 | System.out.println("\nOriginal Response : " + wsResponse.toString()); 72 | System.out.println("\n---------- dump ----------\n"); 73 | System.out.println(jsonDump.toJson(wsResponse)); 74 | System.out.println("\n--------------------------\n"); 75 | // Check request status. 76 | if (wsResponse.ok() && wsResponse.hasData()) { 77 | // * Get word segmentation results. 78 | String[] ws = wsResponse.getData().getWordSegmentation(); 79 | for (int i = 0; i < ws.length; i++) { 80 | System.out.println("Word[" + i + "] " + ws[i]); 81 | } 82 | } else { 83 | // Error 84 | System.out.println("* Error! Code : " + wsResponse.getErrorCode()); 85 | System.out.println(wsResponse.getErrorMessage()); 86 | } 87 | 88 | // EXAMPLE 2: Request NLI analysis. 89 | System.out.println("\n[Example 2] ================================"); 90 | System.out.println("\nRequest NLI analysis for : " + inputText); 91 | // * Send text 92 | APIResponse nliResponse = recoginzer.requestNLI(inputText); 93 | // 94 | // You can also send text with NLIConfig to append "nli_config" JSON object. 95 | // 96 | // For Example, try to replace 'requestNLI(inputText)' with the following sample code: 97 | // =================================================================== 98 | // NLIConfig nliConfig = new NLIConfig(); 99 | // nliConfig.setSlotName("myslot"); 100 | // APIResponse nliResponse = recoginzer.requestNLI(inputText, nliConfig); 101 | // =================================================================== 102 | // 103 | System.out.println("\nOriginal Response : " + nliResponse.toString()); 104 | System.out.println("\n---------- dump ----------\n"); 105 | System.out.println(jsonDump.toJson(nliResponse)); 106 | System.out.println("\n--------------------------\n"); 107 | // Check request status. 108 | if (nliResponse.ok() && nliResponse.hasData()) { 109 | // * Get NLI results. 110 | NLIResult[] nliResults = nliResponse.getData().getNLIResults(); 111 | // 112 | // You can parse NLI results here and do something. 113 | // 114 | // ================================================ 115 | // In this example, we will dump NLI results. 116 | // 117 | DumpNLIResultsExample.dumpNLIResults(nliResults); 118 | // 119 | // See also: /examples/dump-nli-results-example/ 120 | // ================================================ 121 | } else { 122 | // Error 123 | System.out.println("* Error! Code : " + nliResponse.getErrorCode()); 124 | System.out.println(nliResponse.getErrorMessage()); 125 | } 126 | 127 | System.out.println("\n===========================================\n"); 128 | } 129 | 130 | private static void printUsageAndExit() { 131 | System.out.println("\n Usage:"); 132 | System.out.println("\t args[0]: your_app_key"); 133 | System.out.println("\t args[1]: your_app_secret"); 134 | System.out.println("\t args[2]: localize_option=[0|1]"); 135 | System.out.println("\t args[3]: the_text_you_want_to_test"); 136 | System.out.println("\n"); 137 | System.exit(0); 138 | } 139 | 140 | private static void initByInputArgs(String[] args) { 141 | appKey = args[0]; 142 | appSecret = args[1]; 143 | localizeOption = Integer.parseInt(args[2]); 144 | inputText = args[3]; 145 | } 146 | 147 | } 148 | -------------------------------------------------------------------------------- /lib/src/main/java/org/xiph/speex/OggCrc.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * Copyright (c) 1999-2003 Wimba S.A., All Rights Reserved. * 4 | * * 5 | * COPYRIGHT: * 6 | * This software is the property of Wimba S.A. * 7 | * This software is redistributed under the Xiph.org variant of * 8 | * the BSD license. * 9 | * Redistribution and use in source and binary forms, with or without * 10 | * modification, are permitted provided that the following conditions * 11 | * are met: * 12 | * - Redistributions of source code must retain the above copyright * 13 | * notice, this list of conditions and the following disclaimer. * 14 | * - Redistributions in binary form must reproduce the above copyright * 15 | * notice, this list of conditions and the following disclaimer in the * 16 | * documentation and/or other materials provided with the distribution. * 17 | * - Neither the name of Wimba, the Xiph.org Foundation nor the names of * 18 | * its contributors may be used to endorse or promote products derived * 19 | * from this software without specific prior written permission. * 20 | * * 21 | * WARRANTIES: * 22 | * This software is made available by the authors in the hope * 23 | * that it will be useful, but without any warranty. * 24 | * Wimba S.A. is not liable for any consequence related to the * 25 | * use of the provided software. * 26 | * * 27 | * Class: OggCrc.java * 28 | * * 29 | * Author: Marc GIMPEL * 30 | * Based on code by: Ross WILLIAMS * 31 | * * 32 | * Date: 20th April 2003 * 33 | * * 34 | ******************************************************************************/ 35 | 36 | /* $Id: OggCrc.java,v 1.2 2004/10/21 16:21:57 mgimpel Exp $ */ 37 | 38 | /******************************************************************** 39 | * * 40 | * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * 41 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * 42 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * 43 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * 44 | * * 45 | * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002 * 46 | * by the Xiph.Org Foundation http://www.xiph.org/ * 47 | * * 48 | ******************************************************************** 49 | 50 | function: code raw [Vorbis] packets into framed OggSquish stream and 51 | decode Ogg streams back into raw packets 52 | last mod: $Id: OggCrc.java,v 1.2 2004/10/21 16:21:57 mgimpel Exp $ 53 | 54 | note: The CRC code is directly derived from public domain code by 55 | Ross Williams (ross@guest.adelaide.edu.au). See docs/framing.html 56 | for details. 57 | 58 | ********************************************************************/ 59 | 60 | package org.xiph.speex; 61 | 62 | /** 63 | * Calculates the CRC checksum for Ogg packets. 64 | * 65 | *

Ogg uses the same generator polynomial as ethernet, although with an 66 | * unreflected alg and an init/final of 0, not 0xffffffff. 67 | * 68 | * @author Jim Lawrence, helloNetwork.com 69 | * @author Marc Gimpel, Wimba S.A. (mgimpel@horizonwimba.com) 70 | * @version $Revision: 1.2 $ 71 | */ 72 | public class OggCrc 73 | { 74 | // TODO - implement java.util.zip.Checksum 75 | 76 | /** 77 | * CRC checksum lookup table 78 | */ 79 | private static int[] crc_lookup; 80 | 81 | static { 82 | crc_lookup = new int[256]; 83 | for (int i=0; i>>24)&0xff)^(data[offset]&0xff)]; 120 | } 121 | return crc; 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /lib/src/main/java/org/xiph/speex/NoiseSearch.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * Copyright (c) 1999-2003 Wimba S.A., All Rights Reserved. * 4 | * * 5 | * COPYRIGHT: * 6 | * This software is the property of Wimba S.A. * 7 | * This software is redistributed under the Xiph.org variant of * 8 | * the BSD license. * 9 | * Redistribution and use in source and binary forms, with or without * 10 | * modification, are permitted provided that the following conditions * 11 | * are met: * 12 | * - Redistributions of source code must retain the above copyright * 13 | * notice, this list of conditions and the following disclaimer. * 14 | * - Redistributions in binary form must reproduce the above copyright * 15 | * notice, this list of conditions and the following disclaimer in the * 16 | * documentation and/or other materials provided with the distribution. * 17 | * - Neither the name of Wimba, the Xiph.org Foundation nor the names of * 18 | * its contributors may be used to endorse or promote products derived * 19 | * from this software without specific prior written permission. * 20 | * * 21 | * WARRANTIES: * 22 | * This software is made available by the authors in the hope * 23 | * that it will be useful, but without any warranty. * 24 | * Wimba S.A. is not liable for any consequence related to the * 25 | * use of the provided software. * 26 | * * 27 | * Class: NoiseSearch.java * 28 | * * 29 | * Author: James LAWRENCE * 30 | * Modified by: Marc GIMPEL * 31 | * Based on code by: Jean-Marc VALIN * 32 | * * 33 | * Date: March 2003 * 34 | * * 35 | ******************************************************************************/ 36 | 37 | /* $Id: NoiseSearch.java,v 1.2 2004/10/21 16:21:57 mgimpel Exp $ */ 38 | 39 | /* Copyright (C) 2002 Jean-Marc Valin 40 | 41 | Redistribution and use in source and binary forms, with or without 42 | modification, are permitted provided that the following conditions 43 | are met: 44 | 45 | - Redistributions of source code must retain the above copyright 46 | notice, this list of conditions and the following disclaimer. 47 | 48 | - Redistributions in binary form must reproduce the above copyright 49 | notice, this list of conditions and the following disclaimer in the 50 | documentation and/or other materials provided with the distribution. 51 | 52 | - Neither the name of the Xiph.org Foundation nor the names of its 53 | contributors may be used to endorse or promote products derived from 54 | this software without specific prior written permission. 55 | 56 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 57 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 58 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 59 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 60 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 61 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 62 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 63 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 64 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 65 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 66 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 67 | */ 68 | 69 | package org.xiph.speex; 70 | 71 | /** 72 | * Noise codebook search 73 | * 74 | * @author Jim Lawrence, helloNetwork.com 75 | * @author Marc Gimpel, Wimba S.A. (mgimpel@horizonwimba.com) 76 | * @version $Revision: 1.2 $ 77 | */ 78 | public class NoiseSearch 79 | extends CbSearch 80 | { 81 | /** 82 | * Codebook Search Quantification (Noise). 83 | * @param target target vector 84 | * @param ak LPCs for this subframe 85 | * @param awk1 Weighted LPCs for this subframe 86 | * @param awk2 Weighted LPCs for this subframe 87 | * @param p number of LPC coeffs 88 | * @param nsf number of samples in subframe 89 | * @param exc excitation array. 90 | * @param es position in excitation array. 91 | * @param r 92 | * @param bits Speex bits buffer. 93 | * @param complexity 94 | */ 95 | public final void quant(float[] target, float[] ak, float[] awk1, float[] awk2, 96 | int p, int nsf, float[] exc, int es, float[] r, 97 | Bits bits, int complexity) 98 | { 99 | int i; 100 | float[] tmp=new float[nsf]; 101 | Filters.residue_percep_zero(target, 0, ak, awk1, awk2, tmp, nsf, p); 102 | 103 | for (i=0;i.99f) 91 | pitch_coef=.99f; 92 | for (i=0;i.99f) { 118 | pitch_coef=.99f; 119 | } 120 | for (i=0;i 2 | 3 | 4.0.0 4 | 5 | ai.olami 6 | olami-java-client-sdk 7 | 1.5.1 8 | pom 9 | 10 | OLAMI Java Client SDK 11 | http://olami.ai 12 | OLAMI APIs Java client library and samples 13 | 14 | 15 | UTF-8 16 | 1.7 17 | 18 | 19 | 20 | 21 | The Apache Software License, Version 2.0 22 | http://www.apache.org/licenses/LICENSE-2.0.txt 23 | 24 | 25 | 26 | 27 | olami 28 | olami.ai@viatech.com 29 | 30 | 31 | 32 | scm:git@github.com:olami-developers/olami-java-client-sdk.git 33 | scm:git@github.com:olami-developers/olami-java-client-sdk.git 34 | https://github.com/olami-developers/olami-java-client-sdk 35 | 36 | 37 | 38 | 39 | 40 | junit 41 | junit 42 | 3.8.1 43 | test 44 | 45 | 46 | com.google.code.gson 47 | gson 48 | 2.8.0 49 | 50 | 51 | 52 | 53 | 54 | lib 55 | 56 | 57 | 58 | 59 | all 60 | 61 | examples/text-input-example 62 | examples/speech-input-example 63 | examples/microphone-speech-input-example 64 | examples/dump-nli-results-example 65 | examples/async-text-chatbot-example 66 | 67 | 68 | 69 | 70 | release-sign-bintray 71 | 72 | 73 | bintray-olami-developers-api-client 74 | olami-developers-api-client 75 | https://api.bintray.com/maven/olami-developers/api-client/olami-java-client-sdk/;publish=1 76 | 77 | 78 | 79 | 80 | 96 | 97 | org.apache.maven.plugins 98 | maven-source-plugin 99 | 3.0.1 100 | 101 | 102 | attach-sources 103 | 104 | jar-no-fork 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | org.apache.maven.plugins 119 | maven-compiler-plugin 120 | 3.6.1 121 | 122 | 1.7 123 | 1.7 124 | 125 | 126 | 127 | org.apache.maven.plugins 128 | maven-antrun-plugin 129 | 1.8 130 | 131 | 132 | org.apache.maven.plugins 133 | maven-jar-plugin 134 | 3.0.2 135 | 136 | 137 | org.apache.maven.plugins 138 | maven-assembly-plugin 139 | 3.0.0 140 | 141 | 142 | jar-with-dependencies 143 | 144 | false 145 | 146 | 147 | 148 | 149 | 150 | 151 | org.apache.maven.plugins 152 | maven-antrun-plugin 153 | 154 | 155 | clean 156 | 157 | 158 | 159 | 160 | 161 | 162 | run 163 | 164 | 165 | 166 | 167 | 168 | org.apache.maven.plugins 169 | maven-javadoc-plugin 170 | 2.10.4 171 | 172 | org.* 173 | -Xdoclint:none 174 | ${chartset.UTF8} 175 | true 176 | ${chartset.UTF8} 177 | ${chartset.UTF8} 178 | 179 | 180 | 181 | attach-javadocs 182 | 183 | jar 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | -------------------------------------------------------------------------------- /lib/src/main/java/org/xiph/speex/HighLspQuant.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * Copyright (c) 1999-2003 Wimba S.A., All Rights Reserved. * 4 | * * 5 | * COPYRIGHT: * 6 | * This software is the property of Wimba S.A. * 7 | * This software is redistributed under the Xiph.org variant of * 8 | * the BSD license. * 9 | * Redistribution and use in source and binary forms, with or without * 10 | * modification, are permitted provided that the following conditions * 11 | * are met: * 12 | * - Redistributions of source code must retain the above copyright * 13 | * notice, this list of conditions and the following disclaimer. * 14 | * - Redistributions in binary form must reproduce the above copyright * 15 | * notice, this list of conditions and the following disclaimer in the * 16 | * documentation and/or other materials provided with the distribution. * 17 | * - Neither the name of Wimba, the Xiph.org Foundation nor the names of * 18 | * its contributors may be used to endorse or promote products derived * 19 | * from this software without specific prior written permission. * 20 | * * 21 | * WARRANTIES: * 22 | * This software is made available by the authors in the hope * 23 | * that it will be useful, but without any warranty. * 24 | * Wimba S.A. is not liable for any consequence related to the * 25 | * use of the provided software. * 26 | * * 27 | * Class: HighLu.java * 28 | * * 29 | * Author: James LAWRENCE * 30 | * Modified by: Marc GIMPEL * 31 | * Based on code by: Jean-Marc VALIN * 32 | * * 33 | * Date: March 2003 * 34 | * * 35 | ******************************************************************************/ 36 | 37 | /* $Id: HighLspQuant.java,v 1.2 2004/10/21 16:21:57 mgimpel Exp $ */ 38 | 39 | /* Copyright (C) 2002 Jean-Marc Valin 40 | 41 | Redistribution and use in source and binary forms, with or without 42 | modification, are permitted provided that the following conditions 43 | are met: 44 | 45 | - Redistributions of source code must retain the above copyright 46 | notice, this list of conditions and the following disclaimer. 47 | 48 | - Redistributions in binary form must reproduce the above copyright 49 | notice, this list of conditions and the following disclaimer in the 50 | documentation and/or other materials provided with the distribution. 51 | 52 | - Neither the name of the Xiph.org Foundation nor the names of its 53 | contributors may be used to endorse or promote products derived from 54 | this software without specific prior written permission. 55 | 56 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 57 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 58 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 59 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 60 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 61 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 62 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 63 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 64 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 65 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 66 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 67 | */ 68 | 69 | package org.xiph.speex; 70 | 71 | /** 72 | * LSP Quantisation and Unquantisation (high) 73 | * 74 | * @author Jim Lawrence, helloNetwork.com 75 | * @author Marc Gimpel, Wimba S.A. (mgimpel@horizonwimba.com) 76 | * @version $Revision: 1.2 $ 77 | */ 78 | public class HighLspQuant 79 | extends LspQuant 80 | { 81 | /** 82 | * Line Spectral Pair Quantification (high). 83 | * @param lsp - Line Spectral Pairs table. 84 | * @param qlsp - Quantified Line Spectral Pairs table. 85 | * @param order 86 | * @param bits - Speex bits buffer. 87 | */ 88 | public final void quant(final float[] lsp, 89 | final float[] qlsp, 90 | final int order, 91 | final Bits bits) 92 | { 93 | int i; 94 | float tmp1, tmp2; 95 | int id; 96 | float[] quant_weight = new float[MAX_LSP_SIZE]; 97 | 98 | for (i=0;i tmp2 ? tmp1 : tmp2; 107 | } 108 | 109 | for (i=0;i