Skip to content

Feature code formatting #167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
; Top-most EditorConfig file
root = true

; Unix-style newlines
[*]
end_of_line = LF

; 2-column space indentation
[*.cs]
indent_style = space
indent_size = 2
37 changes: 19 additions & 18 deletions Examples/ServiceExamples/Scripts/ExampleAlchemyDataNews.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,31 @@
*/

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using IBM.Watson.DeveloperCloud.Services.AlchemyAPI.v1;
using IBM.Watson.DeveloperCloud.Logging;
using System;

public class ExampleAlchemyDataNews : MonoBehaviour {
private AlchemyAPI m_AlchemyAPI = new AlchemyAPI();

void Start () {
LogSystem.InstallDefaultReactors();
public class ExampleAlchemyDataNews : MonoBehaviour
{
private AlchemyAPI m_AlchemyAPI = new AlchemyAPI();

string[] returnFields = {Fields.ENRICHED_URL_ENTITIES, Fields.ENRICHED_URL_KEYWORDS};
Dictionary<string, string> queryFields = new Dictionary<string, string>();
queryFields.Add(Fields.ENRICHED_URL_RELATIONS_RELATION_SUBJECT_TEXT, "Obama");
queryFields.Add(Fields.ENRICHED_URL_CLEANEDTITLE, "Washington");
void Start()
{
LogSystem.InstallDefaultReactors();

if (!m_AlchemyAPI.GetNews(OnGetNews, returnFields, queryFields))
Log.Debug("ExampleAlchemyData", "Failed to get news!");
}
string[] returnFields = { Fields.ENRICHED_URL_ENTITIES, Fields.ENRICHED_URL_KEYWORDS };
Dictionary<string, string> queryFields = new Dictionary<string, string>();
queryFields.Add(Fields.ENRICHED_URL_RELATIONS_RELATION_SUBJECT_TEXT, "Obama");
queryFields.Add(Fields.ENRICHED_URL_CLEANEDTITLE, "Washington");

private void OnGetNews(NewsResponse newsData, string data)
{
if(newsData != null)
Log.Debug("ExampleAlchemyData", "status: {0}", newsData.status);
}
if (!m_AlchemyAPI.GetNews(OnGetNews, returnFields, queryFields))
Log.Debug("ExampleAlchemyData", "Failed to get news!");
}

private void OnGetNews(NewsResponse newsData, string data)
{
if (newsData != null)
Log.Debug("ExampleAlchemyData", "status: {0}", newsData.status);
}
}
1,139 changes: 569 additions & 570 deletions Examples/ServiceExamples/Scripts/ExampleAlchemyLanguage.cs

Large diffs are not rendered by default.

93 changes: 47 additions & 46 deletions Examples/ServiceExamples/Scripts/ExampleConversation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,59 +23,60 @@

public class ExampleConversation : MonoBehaviour
{
private Conversation m_Conversation = new Conversation();
private string m_WorkspaceID;
private bool m_UseAlternateIntents = true;
private string[] questionArray = { "can you turn up the AC", "can you turn on the wipers", "can you turn off the wipers", "can you turn down the ac", "can you unlock the door"};
private Conversation m_Conversation = new Conversation();
private string m_WorkspaceID;
private bool m_UseAlternateIntents = true;
private string[] questionArray = { "can you turn up the AC", "can you turn on the wipers", "can you turn off the wipers", "can you turn down the ac", "can you unlock the door" };

void Start () {
LogSystem.InstallDefaultReactors();
m_WorkspaceID = Config.Instance.GetVariableValue("ConversationV1_ID");
void Start()
{
LogSystem.InstallDefaultReactors();
m_WorkspaceID = Config.Instance.GetVariableValue("ConversationV1_ID");

Debug.Log("**********User: Hello!");
MessageWithOnlyInput("Hello!");
}
Debug.Log("**********User: Hello!");
MessageWithOnlyInput("Hello!");
}

private void MessageWithOnlyInput(string input)
{
if (string.IsNullOrEmpty(input))
throw new ArgumentNullException("input");

m_Conversation.Message(OnMessageWithOnlyInput, m_WorkspaceID, input);
}

private void MessageWithOnlyInput(string input)
{
if (string.IsNullOrEmpty(input))
throw new ArgumentNullException("input");

m_Conversation.Message(OnMessageWithOnlyInput, m_WorkspaceID, input);
}


private void OnMessageWithOnlyInput(MessageResponse resp, string customData)
{
if (resp != null)
{
foreach (Intent mi in resp.intents)
Debug.Log("intent: " + mi.intent + ", confidence: " + mi.confidence);
private void OnMessageWithOnlyInput(MessageResponse resp, string customData)
{
if (resp != null)
{
foreach (Intent mi in resp.intents)
Debug.Log("intent: " + mi.intent + ", confidence: " + mi.confidence);

if (resp.output != null && resp.output.text.Length > 0)
foreach (string txt in resp.output.text)
Debug.Log("output: " + txt);
if (resp.output != null && resp.output.text.Length > 0)
foreach (string txt in resp.output.text)
Debug.Log("output: " + txt);

string questionStr = questionArray[UnityEngine.Random.Range(0, questionArray.Length - 1)];
Debug.Log(string.Format("**********User: {0}", questionStr));
string questionStr = questionArray[UnityEngine.Random.Range(0, questionArray.Length - 1)];
Debug.Log(string.Format("**********User: {0}", questionStr));

MessageRequest messageRequest = new MessageRequest();
messageRequest.InputText = questionStr;
messageRequest.alternate_intents = m_UseAlternateIntents;
messageRequest.ContextData = resp.context;
MessageRequest messageRequest = new MessageRequest();
messageRequest.InputText = questionStr;
messageRequest.alternate_intents = m_UseAlternateIntents;
messageRequest.ContextData = resp.context;

MessageWithFullMessageRequest(messageRequest);
}
else
{
Debug.Log("Failed to invoke Message();");
}
}
MessageWithFullMessageRequest(messageRequest);
}
else
{
Debug.Log("Failed to invoke Message();");
}
}

private void MessageWithFullMessageRequest(MessageRequest messageRequest)
{
if (messageRequest == null)
throw new ArgumentNullException("messageRequest");
m_Conversation.Message(OnMessageWithOnlyInput, m_WorkspaceID, messageRequest);
}
private void MessageWithFullMessageRequest(MessageRequest messageRequest)
{
if (messageRequest == null)
throw new ArgumentNullException("messageRequest");
m_Conversation.Message(OnMessageWithOnlyInput, m_WorkspaceID, messageRequest);
}
}
49 changes: 25 additions & 24 deletions Examples/ServiceExamples/Scripts/ExampleConversationExperimental.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,32 @@

public class ExampleConversationExperimental : MonoBehaviour
{
private ConversationExperimental m_Conversation = new ConversationExperimental();
private string m_WorkspaceID;
private string m_Input = "Can you unlock the door?";
private ConversationExperimental m_Conversation = new ConversationExperimental();
private string m_WorkspaceID;
private string m_Input = "Can you unlock the door?";

void Start () {
LogSystem.InstallDefaultReactors();
m_WorkspaceID = Config.Instance.GetVariableValue("ConversationExperimentalV1_ID");
Debug.Log("User: " + m_Input);
void Start()
{
LogSystem.InstallDefaultReactors();
m_WorkspaceID = Config.Instance.GetVariableValue("ConversationExperimentalV1_ID");
Debug.Log("User: " + m_Input);

m_Conversation.Message(m_WorkspaceID, m_Input, OnMessage);
}
m_Conversation.Message(m_WorkspaceID, m_Input, OnMessage);
}

void OnMessage (MessageResponse resp)
{
if(resp != null)
{
foreach(MessageIntent mi in resp.intents)
Debug.Log("intent: " + mi.intent + ", confidence: " + mi.confidence);
if(resp.output != null && !string.IsNullOrEmpty(resp.output.text))
Debug.Log("response: " + resp.output.text);
}
else
{
Debug.Log("Failed to invoke Message();");
}
}
void OnMessage(MessageResponse resp)
{
if (resp != null)
{
foreach (MessageIntent mi in resp.intents)
Debug.Log("intent: " + mi.intent + ", confidence: " + mi.confidence);

if (resp.output != null && !string.IsNullOrEmpty(resp.output.text))
Debug.Log("response: " + resp.output.text);
}
else
{
Debug.Log("Failed to invoke Message();");
}
}
}
78 changes: 39 additions & 39 deletions Examples/ServiceExamples/Scripts/ExampleDocumentConversion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,49 +22,49 @@

public class ExampleDocumentConversion : MonoBehaviour
{
private DocumentConversion m_DocumentConversion = new DocumentConversion();

void Start ()
{
LogSystem.InstallDefaultReactors(); LogSystem.InstallDefaultReactors();
string examplePath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/watson_beats_jeopardy.html";
private DocumentConversion m_DocumentConversion = new DocumentConversion();

if (!m_DocumentConversion.ConvertDocument(OnConvertDocument, examplePath, ConversionTarget.NORMALIZED_TEXT))
Log.Debug("ExampleDocumentConversion", "Document conversion failed!");
}
void Start()
{
LogSystem.InstallDefaultReactors(); LogSystem.InstallDefaultReactors();
string examplePath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/watson_beats_jeopardy.html";

if (!m_DocumentConversion.ConvertDocument(OnConvertDocument, examplePath, ConversionTarget.NORMALIZED_TEXT))
Log.Debug("ExampleDocumentConversion", "Document conversion failed!");
}

private void OnConvertDocument(ConvertedDocument documentConversionResponse, string data)
private void OnConvertDocument(ConvertedDocument documentConversionResponse, string data)
{
if (documentConversionResponse != null)
{
if (documentConversionResponse != null)
if (!string.IsNullOrEmpty(documentConversionResponse.media_type_detected))
Log.Debug("ExampleDocumentConversion", "mediaTypeDetected: {0}", documentConversionResponse.media_type_detected);
if (!string.IsNullOrEmpty(documentConversionResponse.source_document_id))
Log.Debug("ExampleDocumentConversion", "mediaTypeDetected: {0}", documentConversionResponse.source_document_id);
if (!string.IsNullOrEmpty(documentConversionResponse.timestamp))
Log.Debug("ExampleDocumentConversion", "mediaTypeDetected: {0}", documentConversionResponse.timestamp);
if (documentConversionResponse.metadata != null && documentConversionResponse.metadata.Length > 0)
{
Log.Debug("ExampleDocumentConversion", "mediaTypeDetected: {0}", documentConversionResponse.metadata.Length);
foreach (Metadata metadata in documentConversionResponse.metadata)
Log.Debug("ExampleDocumentConversion", "metadata | name: {0}, content: {1}", metadata.name, metadata.content);
}
if (documentConversionResponse.answer_units != null && documentConversionResponse.answer_units.Length > 0)
{
Log.Debug("ExampleDocumentConversion", "mediaTypeDetected: {0}", documentConversionResponse.answer_units.Length);
foreach (AnswerUnit answerUnit in documentConversionResponse.answer_units)
{
if(!string.IsNullOrEmpty(documentConversionResponse.media_type_detected))
Log.Debug("ExampleDocumentConversion", "mediaTypeDetected: {0}", documentConversionResponse.media_type_detected);
if (!string.IsNullOrEmpty(documentConversionResponse.source_document_id))
Log.Debug("ExampleDocumentConversion", "mediaTypeDetected: {0}", documentConversionResponse.source_document_id);
if(!string.IsNullOrEmpty(documentConversionResponse.timestamp))
Log.Debug("ExampleDocumentConversion", "mediaTypeDetected: {0}", documentConversionResponse.timestamp);
if (documentConversionResponse.metadata != null && documentConversionResponse.metadata.Length > 0)
{
Log.Debug("ExampleDocumentConversion", "mediaTypeDetected: {0}", documentConversionResponse.metadata.Length);
foreach (Metadata metadata in documentConversionResponse.metadata)
Log.Debug("ExampleDocumentConversion", "metadata | name: {0}, content: {1}", metadata.name, metadata.content);
}
if (documentConversionResponse.answer_units != null && documentConversionResponse.answer_units.Length > 0)
{
Log.Debug("ExampleDocumentConversion", "mediaTypeDetected: {0}", documentConversionResponse.answer_units.Length);
foreach (AnswerUnit answerUnit in documentConversionResponse.answer_units)
{
Log.Debug("ExampleDocumentConversion", "answerUnit | type: {0}, title: {1}, parent_id: {2}, id: {3}, direction: {4}", answerUnit.type, answerUnit.title, answerUnit.parent_id, answerUnit.id, answerUnit.direction);
if (answerUnit.content != null && answerUnit.content.Length > 0)
foreach (Content content in answerUnit.content)
Log.Debug("ExampleDocumentConversion", "content | mediaType: {0}, text: {1}", content.media_type, content.text);
}
}

if (!string.IsNullOrEmpty(documentConversionResponse.htmlContent))
Log.Debug("ExampleDocumentConversion", "HTMLContent: {0}", documentConversionResponse.htmlContent);
if (!string.IsNullOrEmpty(documentConversionResponse.textContent))
Log.Debug("ExampleDocumentConversion", "TextContent: {0}", documentConversionResponse.textContent);
Log.Debug("ExampleDocumentConversion", "answerUnit | type: {0}, title: {1}, parent_id: {2}, id: {3}, direction: {4}", answerUnit.type, answerUnit.title, answerUnit.parent_id, answerUnit.id, answerUnit.direction);
if (answerUnit.content != null && answerUnit.content.Length > 0)
foreach (Content content in answerUnit.content)
Log.Debug("ExampleDocumentConversion", "content | mediaType: {0}, text: {1}", content.media_type, content.text);
}
}

if (!string.IsNullOrEmpty(documentConversionResponse.htmlContent))
Log.Debug("ExampleDocumentConversion", "HTMLContent: {0}", documentConversionResponse.htmlContent);
if (!string.IsNullOrEmpty(documentConversionResponse.textContent))
Log.Debug("ExampleDocumentConversion", "TextContent: {0}", documentConversionResponse.textContent);
}
}
}
27 changes: 14 additions & 13 deletions Examples/ServiceExamples/Scripts/ExampleLanguageTranslation.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,20 @@
using UnityEngine;
using IBM.Watson.DeveloperCloud.Services.LanguageTranslation.v1;

public class ExampleLanguageTranslation : MonoBehaviour {
private LanguageTranslation m_Translate = new LanguageTranslation();
private string m_PharseToTranslate = "How do I get to the disco?";
public class ExampleLanguageTranslation : MonoBehaviour
{
private LanguageTranslation m_Translate = new LanguageTranslation();
private string m_PharseToTranslate = "How do I get to the disco?";

void Start ()
{
Debug.Log("English Phrase to translate: " + m_PharseToTranslate);
m_Translate.GetTranslation(m_PharseToTranslate, "en", "es", OnGetTranslation);
}
void Start()
{
Debug.Log("English Phrase to translate: " + m_PharseToTranslate);
m_Translate.GetTranslation(m_PharseToTranslate, "en", "es", OnGetTranslation);
}

private void OnGetTranslation(Translations translation)
{
if (translation != null && translation.translations.Length > 0)
Debug.Log("Spanish Translation: " + translation.translations[0].translation);
}
private void OnGetTranslation(Translations translation)
{
if (translation != null && translation.translations.Length > 0)
Debug.Log("Spanish Translation: " + translation.translations[0].translation);
}
}
29 changes: 15 additions & 14 deletions Examples/ServiceExamples/Scripts/ExampleLanguageTranslator.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,20 @@
using UnityEngine;
using IBM.Watson.DeveloperCloud.Services.LanguageTranslator.v1;

public class ExampleLanguageTranslator : MonoBehaviour {
private LanguageTranslator m_Translate = new LanguageTranslator();
private string m_PharseToTranslate = "How do I get to the disco?";

void Start ()
{
Debug.Log("English Phrase to translate: " + m_PharseToTranslate);
m_Translate.GetTranslation(m_PharseToTranslate, "en", "es", OnGetTranslation);
}
public class ExampleLanguageTranslator : MonoBehaviour
{
private LanguageTranslator m_Translate = new LanguageTranslator();
private string m_PharseToTranslate = "How do I get to the disco?";

private void OnGetTranslation(Translations translation)
{
if (translation != null && translation.translations.Length > 0)
Debug.Log("Spanish Translation: " + translation.translations[0].translation);
}
void Start()
{
Debug.Log("English Phrase to translate: " + m_PharseToTranslate);
m_Translate.GetTranslation(m_PharseToTranslate, "en", "es", OnGetTranslation);
}

private void OnGetTranslation(Translations translation)
{
if (translation != null && translation.translations.Length > 0)
Debug.Log("Spanish Translation: " + translation.translations[0].translation);
}
}
Loading