diff --git a/CHANGELOG.md b/CHANGELOG.md index 2dd1b8b9c..54fa143c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ Change Log ========== +## Version 0.12.0 +_2016_10_27_ +* New: Added streaming `SpeechToText` example. +* New: Abstraction for `Personality Insights V3` + ## Version 0.11.0 _2016_10_27_ * New: Abstracted `Speech to Text` customization methods. diff --git a/Examples/ServiceExamples/Scripts/ExamplePersonalityInsights.cs b/Examples/ServiceExamples/Scripts/ExamplePersonalityInsightsV2.cs old mode 100755 new mode 100644 similarity index 97% rename from Examples/ServiceExamples/Scripts/ExamplePersonalityInsights.cs rename to Examples/ServiceExamples/Scripts/ExamplePersonalityInsightsV2.cs index ef83935b1..dbcca7b34 --- a/Examples/ServiceExamples/Scripts/ExamplePersonalityInsights.cs +++ b/Examples/ServiceExamples/Scripts/ExamplePersonalityInsightsV2.cs @@ -16,11 +16,11 @@ */ using UnityEngine; -using System.Collections; using IBM.Watson.DeveloperCloud.Services.PersonalityInsights.v2; using IBM.Watson.DeveloperCloud.Logging; -public class ExamplePersonalityInsights : MonoBehaviour { +public class ExamplePersonalityInsightsV2 : MonoBehaviour +{ PersonalityInsights m_personalityInsights = new PersonalityInsights(); void Start () diff --git a/Examples/ServiceExamples/Scripts/ExamplePersonalityInsights.cs.meta b/Examples/ServiceExamples/Scripts/ExamplePersonalityInsightsV2.cs.meta similarity index 100% rename from Examples/ServiceExamples/Scripts/ExamplePersonalityInsights.cs.meta rename to Examples/ServiceExamples/Scripts/ExamplePersonalityInsightsV2.cs.meta diff --git a/Examples/ServiceExamples/Scripts/ExamplePersonalityInsightsV3.cs b/Examples/ServiceExamples/Scripts/ExamplePersonalityInsightsV3.cs new file mode 100644 index 000000000..1199f8069 --- /dev/null +++ b/Examples/ServiceExamples/Scripts/ExamplePersonalityInsightsV3.cs @@ -0,0 +1,174 @@ +/** +* Copyright 2015 IBM Corp. All Rights Reserved. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ + +using UnityEngine; +using IBM.Watson.DeveloperCloud.Services.PersonalityInsights.v3; +using IBM.Watson.DeveloperCloud.Logging; + +public class ExamplePersonalityInsightsV3 : MonoBehaviour +{ + PersonalityInsights m_personalityInsights = new PersonalityInsights(); + private string testString = ""; + private string dataPath; + + void Start() + { + LogSystem.InstallDefaultReactors(); + + dataPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/personalityInsights.json"; + + if (!m_personalityInsights.GetProfile(OnGetProfileJson, dataPath, ContentType.TEXT_HTML, ContentLanguage.ENGLISH, ContentType.APPLICATION_JSON, AcceptLanguage.ENGLISH, true, true, true)) + Log.Debug("ExamplePersonalityInsights", "Failed to get profile!"); + + if (!m_personalityInsights.GetProfile(OnGetProfileText, testString, ContentType.TEXT_HTML, ContentLanguage.ENGLISH, ContentType.APPLICATION_JSON, AcceptLanguage.ENGLISH, true, true, true)) + Log.Debug("ExamplePersonalityInsights", "Failed to get profile!"); + } + private void OnGetProfileText(Profile profile, string data) + { + if (profile != null) + { + if (!string.IsNullOrEmpty(profile.processed_language)) + Log.Debug("TestPersonalityInsightsV3", "processed_language: {0}", profile.processed_language); + + Log.Debug("TestPersonalityInsightsV3", "word_count: {0}", profile.word_count); + + if (!string.IsNullOrEmpty(profile.word_count_message)) + Log.Debug("TestPersonalityInsightsV3", "word_count_message: {0}", profile.word_count_message); + + if (profile.personality != null && profile.personality.Length > 0) + { + Log.Debug("TestPersonalityInsightsV3", "Personality trait tree"); + foreach (TraitTreeNode node in profile.personality) + LogTraitTree(node); + } + + if (profile.values != null && profile.values.Length > 0) + { + Log.Debug("TestPersonalityInsightsV3", "Values trait tree"); + foreach (TraitTreeNode node in profile.values) + LogTraitTree(node); + } + + if (profile.needs != null && profile.personality.Length > 0) + { + Log.Debug("TestPersonalityInsightsV3", "Needs trait tree"); + foreach (TraitTreeNode node in profile.needs) + LogTraitTree(node); + } + + if (profile.behavior != null && profile.behavior.Length > 0) + { + Log.Debug("TestPersonalityInsightsV3", "Behavior tree"); + foreach (BehaviorNode behavior in profile.behavior) + { + Log.Debug("TestPersonalityInsightsV3", "trait_id: {0}", behavior.trait_id); + Log.Debug("TestPersonalityInsightsV3", "name: {0}", behavior.name); + Log.Debug("TestPersonalityInsightsV3", "category: {0}", behavior.category); + Log.Debug("TestPersonalityInsightsV3", "percentage: {0}", behavior.percentage.ToString()); + Log.Debug("TestPersonalityInsightsV3", "----------------"); + } + } + + if (profile.consumption_preferences != null && profile.consumption_preferences.Length > 0) + { + Log.Debug("TestPersonalityInsightsV3", "ConsumptionPreferencesCategories"); + foreach (ConsumptionPreferencesCategoryNode categoryNode in profile.consumption_preferences) + LogConsumptionPreferencesCategory(categoryNode); + } + } + } + + private void OnGetProfileJson(Profile profile, string data) + { + if (profile != null) + { + if (!string.IsNullOrEmpty(profile.processed_language)) + Log.Debug("TestPersonalityInsightsV3", "processed_language: {0}", profile.processed_language); + + Log.Debug("TestPersonalityInsightsV3", "word_count: {0}", profile.word_count); + + if (!string.IsNullOrEmpty(profile.word_count_message)) + Log.Debug("TestPersonalityInsightsV3", "word_count_message: {0}", profile.word_count_message); + + if (profile.personality != null && profile.personality.Length > 0) + { + Log.Debug("TestPersonalityInsightsV3", "Personality trait tree"); + foreach (TraitTreeNode node in profile.personality) + LogTraitTree(node); + } + + if (profile.values != null && profile.values.Length > 0) + { + Log.Debug("TestPersonalityInsightsV3", "Values trait tree"); + foreach (TraitTreeNode node in profile.values) + LogTraitTree(node); + } + + if (profile.needs != null && profile.personality.Length > 0) + { + Log.Debug("TestPersonalityInsightsV3", "Needs trait tree"); + foreach (TraitTreeNode node in profile.needs) + LogTraitTree(node); + } + + if (profile.behavior != null && profile.behavior.Length > 0) + { + Log.Debug("TestPersonalityInsightsV3", "Behavior tree"); + foreach (BehaviorNode behavior in profile.behavior) + { + Log.Debug("TestPersonalityInsightsV3", "trait_id: {0}", behavior.trait_id); + Log.Debug("TestPersonalityInsightsV3", "name: {0}", behavior.name); + Log.Debug("TestPersonalityInsightsV3", "category: {0}", behavior.category); + Log.Debug("TestPersonalityInsightsV3", "percentage: {0}", behavior.percentage.ToString()); + Log.Debug("TestPersonalityInsightsV3", "----------------"); + } + } + + if (profile.consumption_preferences != null && profile.consumption_preferences.Length > 0) + { + Log.Debug("TestPersonalityInsightsV3", "ConsumptionPreferencesCategories"); + foreach (ConsumptionPreferencesCategoryNode categoryNode in profile.consumption_preferences) + LogConsumptionPreferencesCategory(categoryNode); + } + } + } + + private void LogTraitTree(TraitTreeNode traitTreeNode) + { + Log.Debug("TestPersonalityInsightsV3", "trait_id: {0} | name: {1} | category: {2} | percentile: {3} | raw_score: {4}", + string.IsNullOrEmpty(traitTreeNode.trait_id) ? "null" : traitTreeNode.trait_id, + string.IsNullOrEmpty(traitTreeNode.name) ? "null" : traitTreeNode.name, + string.IsNullOrEmpty(traitTreeNode.category) ? "null" : traitTreeNode.category, + string.IsNullOrEmpty(traitTreeNode.percentile.ToString()) ? "null" : traitTreeNode.percentile.ToString(), + string.IsNullOrEmpty(traitTreeNode.raw_score.ToString()) ? "null" : traitTreeNode.raw_score.ToString()); + + if (traitTreeNode.children != null && traitTreeNode.children.Length > 0) + foreach (TraitTreeNode childNode in traitTreeNode.children) + LogTraitTree(childNode); + } + + private void LogConsumptionPreferencesCategory(ConsumptionPreferencesCategoryNode categoryNode) + { + Log.Debug("TestPersonalityInsightsV3", "consumption_preference_category_id: {0} | name: {1}", categoryNode.consumption_preference_category_id, categoryNode.name); + + foreach (ConsumptionPreferencesNode preferencesNode in categoryNode.consumption_preferences) + Log.Debug("TestPersonalityInsightsV3", "\t consumption_preference_id: {0} | name: {1} | score: {2}", + string.IsNullOrEmpty(preferencesNode.consumption_preference_id) ? "null" : preferencesNode.consumption_preference_id, + string.IsNullOrEmpty(preferencesNode.name) ? "null" : preferencesNode.name, + string.IsNullOrEmpty(preferencesNode.score.ToString()) ? "null" : preferencesNode.score.ToString()); + } +} diff --git a/Examples/ServiceExamples/Scripts/ExamplePersonalityInsightsV3.cs.meta b/Examples/ServiceExamples/Scripts/ExamplePersonalityInsightsV3.cs.meta new file mode 100644 index 000000000..129390801 --- /dev/null +++ b/Examples/ServiceExamples/Scripts/ExamplePersonalityInsightsV3.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: cd2e3d3910ea1bd46b55eb5943a057f7 +timeCreated: 1477416788 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Examples/ServiceExamples/ServiceExamples.unity b/Examples/ServiceExamples/ServiceExamples.unity index 2b1a02976..1f3ae00de 100755 --- a/Examples/ServiceExamples/ServiceExamples.unity +++ b/Examples/ServiceExamples/ServiceExamples.unity @@ -37,7 +37,7 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {fileID: 0} m_Sun: {fileID: 0} - m_IndirectSpecularColor: {r: 0.3735645, g: 0.38112062, b: 0.35887584, a: 1} + m_IndirectSpecularColor: {r: 0.3735644, g: 0.38112032, b: 0.35887682, a: 1} --- !u!157 &3 LightmapSettings: m_ObjectHideFlags: 0 @@ -209,7 +209,7 @@ Transform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 11 + m_RootOrder: 12 --- !u!1 &725710367 GameObject: m_ObjectHideFlags: 0 @@ -336,6 +336,46 @@ Transform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_Children: [] m_Father: {fileID: 0} + m_RootOrder: 11 +--- !u!1 &854511683 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 4 + m_Component: + - 4: {fileID: 854511685} + - 114: {fileID: 854511684} + m_Layer: 0 + m_Name: ExamplePersonalityInsightsV3 + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 0 +--- !u!114 &854511684 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 854511683} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: cd2e3d3910ea1bd46b55eb5943a057f7, type: 3} + m_Name: + m_EditorClassIdentifier: +--- !u!4 &854511685 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 854511683} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_Children: [] + m_Father: {fileID: 0} m_RootOrder: 10 --- !u!1 &859102722 GameObject: @@ -416,7 +456,7 @@ Transform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 12 + m_RootOrder: 13 --- !u!1 &1073418922 GameObject: m_ObjectHideFlags: 0 @@ -472,7 +512,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!114 &1160237479 MonoBehaviour: m_ObjectHideFlags: 0 @@ -577,7 +617,7 @@ Transform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 13 + m_RootOrder: 14 --- !u!1 &1713392457 GameObject: m_ObjectHideFlags: 0 @@ -668,7 +708,7 @@ GameObject: - 4: {fileID: 2004886373} - 114: {fileID: 2004886372} m_Layer: 0 - m_Name: ExamplePersonalityInsights + m_Name: ExamplePersonalityInsightsV2 m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 diff --git a/README.md b/README.md index 4b418dd80..a6070c4a6 100644 --- a/README.md +++ b/README.md @@ -1563,61 +1563,154 @@ The IBM Watson™ [Personality Insights][personality_insights] service enables a ```cs PersonalityInsights m_personalityInsights = new PersonalityInsights(); + private string testString = """; + private string dataPath; -void Start () { - string dataPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/personalityInsights.json"; + void Start () { + LogSystem.InstallDefaultReactors(); - if(!m_personalityInsights.GetProfile(OnGetProfile, dataPath, DataModels.ContentType.TEXT_PLAIN, DataModels.Language.ENGLISH)) - Log.Debug("ExamplePersonalityInsights", "Failed to get profile!"); -} + dataPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/personalityInsights.json"; -private void OnGetProfile(DataModels.Profile profile, string data) -{ - Log.Debug("ExamplePersonalityInsights", "data: {0}", data); - if(profile != null) - { - if(!string.IsNullOrEmpty(profile.id)) - Log.Debug("ExamplePersonalityInsights", "id: {0}", profile.id); - if(!string.IsNullOrEmpty(profile.source)) - Log.Debug("ExamplePersonalityInsights", "source: {0}", profile.source); - if(!string.IsNullOrEmpty(profile.processed_lang)) - Log.Debug("ExamplePersonalityInsights", "proccessed_lang: {0}", profile.processed_lang); - if(!string.IsNullOrEmpty(profile.word_count)) - Log.Debug("ExamplePersonalityInsights", "word_count: {0}", profile.word_count); - if(!string.IsNullOrEmpty(profile.word_count_message)) - Log.Debug("ExamplePersonalityInsights", "word_count_message: {0}", profile.word_count_message); + if(!m_personalityInsights.GetProfile(OnGetProfileJson, dataPath, ContentType.TEXT_HTML, ContentLanguage.ENGLISH, ContentType.APPLICATION_JSON, AcceptLanguage.ENGLISH, true, true, true)) + Log.Debug("ExamplePersonalityInsights", "Failed to get profile!"); - if(profile.tree != null) - { - LogTraitTree(profile.tree); - } - } - else - { - Log.Debug("ExamplePersonalityInsights", "Failed to get profile!"); - } -} + if (!m_personalityInsights.GetProfile(OnGetProfileText, testString, ContentType.TEXT_HTML, ContentLanguage.ENGLISH, ContentType.APPLICATION_JSON, AcceptLanguage.ENGLISH, true, true, true)) + Log.Debug("ExamplePersonalityInsights", "Failed to get profile!"); + } + private void OnGetProfileText(Profile profile, string data) + { + if (profile != null) + { + if (!string.IsNullOrEmpty(profile.processed_language)) + Log.Debug("TestPersonalityInsightsV3", "processed_language: {0}", profile.processed_language); -private void LogTraitTree(DataModels.TraitTreeNode traitTreeNode) -{ - if(!string.IsNullOrEmpty(traitTreeNode.id)) - Log.Debug("ExamplePersonalityInsights", "id: {0}", traitTreeNode.id); - if(!string.IsNullOrEmpty(traitTreeNode.name)) - Log.Debug("ExamplePersonalityInsights", "name: {0}", traitTreeNode.name); - if(!string.IsNullOrEmpty(traitTreeNode.category)) - Log.Debug("ExamplePersonalityInsights", "category: {0}", traitTreeNode.category); - if(!string.IsNullOrEmpty(traitTreeNode.percentage)) - Log.Debug("ExamplePersonalityInsights", "percentage: {0}", traitTreeNode.percentage); - if(!string.IsNullOrEmpty(traitTreeNode.sampling_error)) - Log.Debug("ExamplePersonalityInsights", "sampling_error: {0}", traitTreeNode.sampling_error); - if(!string.IsNullOrEmpty(traitTreeNode.raw_score)) - Log.Debug("ExamplePersonalityInsights", "raw_score: {0}", traitTreeNode.raw_score); - if(!string.IsNullOrEmpty(traitTreeNode.raw_sampling_error)) - Log.Debug("ExamplePersonalityInsights", "raw_sampling_error: {0}", traitTreeNode.raw_sampling_error); - if(traitTreeNode.children != null && traitTreeNode.children.Length > 0) - foreach(DataModels.TraitTreeNode childNode in traitTreeNode.children) - LogTraitTree(childNode); -} + Log.Debug("TestPersonalityInsightsV3", "word_count: {0}", profile.word_count); + + if (!string.IsNullOrEmpty(profile.word_count_message)) + Log.Debug("TestPersonalityInsightsV3", "word_count_message: {0}", profile.word_count_message); + + if (profile.personality != null && profile.personality.Length > 0) + { + Log.Debug("TestPersonalityInsightsV3", "Personality trait tree"); + foreach (TraitTreeNode node in profile.personality) + LogTraitTree(node); + } + + if (profile.values != null && profile.values.Length > 0) + { + Log.Debug("TestPersonalityInsightsV3", "Values trait tree"); + foreach (TraitTreeNode node in profile.values) + LogTraitTree(node); + } + + if (profile.needs != null && profile.personality.Length > 0) + { + Log.Debug("TestPersonalityInsightsV3", "Needs trait tree"); + foreach (TraitTreeNode node in profile.needs) + LogTraitTree(node); + } + + if (profile.behavior != null && profile.behavior.Length > 0) + { + Log.Debug("TestPersonalityInsightsV3", "Behavior tree"); + foreach (BehaviorNode behavior in profile.behavior) + { + Log.Debug("TestPersonalityInsightsV3", "trait_id: {0}", behavior.trait_id); + Log.Debug("TestPersonalityInsightsV3", "name: {0}", behavior.name); + Log.Debug("TestPersonalityInsightsV3", "category: {0}", behavior.category); + Log.Debug("TestPersonalityInsightsV3", "percentage: {0}", behavior.percentage.ToString()); + Log.Debug("TestPersonalityInsightsV3", "----------------"); + } + } + + if (profile.consumption_preferences != null && profile.consumption_preferences.Length > 0) + { + Log.Debug("TestPersonalityInsightsV3", "ConsumptionPreferencesCategories"); + foreach (ConsumptionPreferencesCategoryNode categoryNode in profile.consumption_preferences) + LogConsumptionPreferencesCategory(categoryNode); + } + } + } + + private void OnGetProfileJson(Profile profile, string data) + { + if (profile != null) + { + if (!string.IsNullOrEmpty(profile.processed_language)) + Log.Debug("TestPersonalityInsightsV3", "processed_language: {0}", profile.processed_language); + + Log.Debug("TestPersonalityInsightsV3", "word_count: {0}", profile.word_count); + + if (!string.IsNullOrEmpty(profile.word_count_message)) + Log.Debug("TestPersonalityInsightsV3", "word_count_message: {0}", profile.word_count_message); + + if (profile.personality != null && profile.personality.Length > 0) + { + Log.Debug("TestPersonalityInsightsV3", "Personality trait tree"); + foreach (TraitTreeNode node in profile.personality) + LogTraitTree(node); + } + + if (profile.values != null && profile.values.Length > 0) + { + Log.Debug("TestPersonalityInsightsV3", "Values trait tree"); + foreach (TraitTreeNode node in profile.values) + LogTraitTree(node); + } + + if (profile.needs != null && profile.personality.Length > 0) + { + Log.Debug("TestPersonalityInsightsV3", "Needs trait tree"); + foreach (TraitTreeNode node in profile.needs) + LogTraitTree(node); + } + + if (profile.behavior != null && profile.behavior.Length > 0) + { + Log.Debug("TestPersonalityInsightsV3", "Behavior tree"); + foreach (BehaviorNode behavior in profile.behavior) + { + Log.Debug("TestPersonalityInsightsV3", "trait_id: {0}", behavior.trait_id); + Log.Debug("TestPersonalityInsightsV3", "name: {0}", behavior.name); + Log.Debug("TestPersonalityInsightsV3", "category: {0}", behavior.category); + Log.Debug("TestPersonalityInsightsV3", "percentage: {0}", behavior.percentage.ToString()); + Log.Debug("TestPersonalityInsightsV3", "----------------"); + } + } + + if (profile.consumption_preferences != null && profile.consumption_preferences.Length > 0) + { + Log.Debug("TestPersonalityInsightsV3", "ConsumptionPreferencesCategories"); + foreach (ConsumptionPreferencesCategoryNode categoryNode in profile.consumption_preferences) + LogConsumptionPreferencesCategory(categoryNode); + } + } + } + + private void LogTraitTree(TraitTreeNode traitTreeNode) + { + Log.Debug("TestPersonalityInsightsV3", "trait_id: {0} | name: {1} | category: {2} | percentile: {3} | raw_score: {4}", + string.IsNullOrEmpty(traitTreeNode.trait_id) ? "null" : traitTreeNode.trait_id, + string.IsNullOrEmpty(traitTreeNode.name) ? "null" : traitTreeNode.name, + string.IsNullOrEmpty(traitTreeNode.category) ? "null" : traitTreeNode.category, + string.IsNullOrEmpty(traitTreeNode.percentile.ToString()) ? "null" : traitTreeNode.percentile.ToString(), + string.IsNullOrEmpty(traitTreeNode.raw_score.ToString()) ? "null" : traitTreeNode.raw_score.ToString()); + + if (traitTreeNode.children != null && traitTreeNode.children.Length > 0) + foreach (TraitTreeNode childNode in traitTreeNode.children) + LogTraitTree(childNode); + } + + private void LogConsumptionPreferencesCategory(ConsumptionPreferencesCategoryNode categoryNode) + { + Log.Debug("TestPersonalityInsightsV3", "consumption_preference_category_id: {0} | name: {1}", categoryNode.consumption_preference_category_id, categoryNode.name); + + foreach (ConsumptionPreferencesNode preferencesNode in categoryNode.consumption_preferences) + Log.Debug("TestPersonalityInsightsV3", "\t consumption_preference_id: {0} | name: {1} | score: {2}", + string.IsNullOrEmpty(preferencesNode.consumption_preference_id) ? "null" : preferencesNode.consumption_preference_id, + string.IsNullOrEmpty(preferencesNode.name) ? "null" : preferencesNode.name, + string.IsNullOrEmpty(preferencesNode.score.ToString()) ? "null" : preferencesNode.score.ToString()); + } ``` ### Document Conversion diff --git a/Scripts/Editor/ConfigEditor.cs b/Scripts/Editor/ConfigEditor.cs index 3cf935136..831f25853 100755 --- a/Scripts/Editor/ConfigEditor.cs +++ b/Scripts/Editor/ConfigEditor.cs @@ -57,14 +57,16 @@ private class ServiceSetup //new ServiceSetup() { ServiceName = "Language Translator", ServiceAPI = "language-translator/api", // URL ="https://console.ng.bluemix.net/catalog/services/language-translator/", ServiceID="LanguageTranslatorV1" }, new ServiceSetup() { ServiceName = "Natural Language Classifier", ServiceAPI = "natural-language-classifier/api", - URL ="https://console.ng.bluemix.net/catalog/natural-language-classifier/", ServiceID="NaturalLanguageClassifierV1" }, + URL ="https://console.ng.bluemix.net/catalog/natural-language-classifier/", ServiceID="NaturalLanguageClassifierV1" }, new ServiceSetup() { ServiceName = "Tone Analyzer", ServiceAPI = "tone-analyzer/api", URL ="https://console.ng.bluemix.net/catalog/services/tone-analyzer/", ServiceID="ToneAnalyzerV3" }, new ServiceSetup() { ServiceName = "Tradeoff Analytics", ServiceAPI = "tradeoff-analytics/api", URL ="https://console.ng.bluemix.net/catalog/services/tradeoff-analytics/", ServiceID="TradeoffAnalyticsV1" }, - new ServiceSetup() { ServiceName = "Personality Insights", ServiceAPI = "personality-insights/api", + new ServiceSetup() { ServiceName = "Personality Insights V2", ServiceAPI = "personality-insights/api", URL ="https://console.ng.bluemix.net/catalog/services/personality-insights/", ServiceID="PersonalityInsightsV2" }, - new ServiceSetup() { ServiceName = "Conversation", ServiceAPI = "conversation/api", + new ServiceSetup() { ServiceName = "Personality Insights V3", ServiceAPI = "personality-insights/api", + URL ="https://console.ng.bluemix.net/catalog/services/personality-insights/", ServiceID="PersonalityInsightsV3" }, + new ServiceSetup() { ServiceName = "Conversation", ServiceAPI = "conversation/api", URL ="https://console.ng.bluemix.net/catalog/services/conversation/", ServiceID="ConversationV1" }, new ServiceSetup() { ServiceName = "RetrieveAndRank", ServiceAPI = "retrieve-and-rank/api", URL ="https://console.ng.bluemix.net/catalog/services/retrieve-and-rank/", ServiceID="RetrieveAndRankV1" }, diff --git a/Scripts/Services/PersonalityInsights.meta b/Scripts/Services/PersonalityInsights.meta old mode 100644 new mode 100755 index 1cb0df67c..e0bf9a66e --- a/Scripts/Services/PersonalityInsights.meta +++ b/Scripts/Services/PersonalityInsights.meta @@ -1,7 +1,7 @@ fileFormatVersion: 2 -guid: 242af859faf584a358c9b61be5e6bec9 +guid: 0fa8368d9623dd540a2b4335cd54f1f2 folderAsset: yes -timeCreated: 1466518852 +timeCreated: 1477341989 licenseType: Pro DefaultImporter: userData: diff --git a/Scripts/Services/PersonalityInsights/v2.meta b/Scripts/Services/PersonalityInsights/v2.meta new file mode 100755 index 000000000..2385f7904 --- /dev/null +++ b/Scripts/Services/PersonalityInsights/v2.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: eab5726e71362cb4781cf8adc03abd4c +folderAsset: yes +timeCreated: 1477342154 +licenseType: Pro +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Services/PersonalityInsights/DataModels.cs b/Scripts/Services/PersonalityInsights/v2/DataModels.cs similarity index 100% rename from Scripts/Services/PersonalityInsights/DataModels.cs rename to Scripts/Services/PersonalityInsights/v2/DataModels.cs diff --git a/Scripts/Services/PersonalityInsights/DataModels.cs.meta b/Scripts/Services/PersonalityInsights/v2/DataModels.cs.meta similarity index 100% rename from Scripts/Services/PersonalityInsights/DataModels.cs.meta rename to Scripts/Services/PersonalityInsights/v2/DataModels.cs.meta diff --git a/Scripts/Services/PersonalityInsights/PersonalityInsights.cs b/Scripts/Services/PersonalityInsights/v2/PersonalityInsights.cs similarity index 99% rename from Scripts/Services/PersonalityInsights/PersonalityInsights.cs rename to Scripts/Services/PersonalityInsights/v2/PersonalityInsights.cs index 2ee6c8370..48b477c9a 100755 --- a/Scripts/Services/PersonalityInsights/PersonalityInsights.cs +++ b/Scripts/Services/PersonalityInsights/v2/PersonalityInsights.cs @@ -20,7 +20,6 @@ using System.Text; using IBM.Watson.DeveloperCloud.Utilities; using UnityEngine; -using System.Collections; using System; using IBM.Watson.DeveloperCloud.Logging; using System.IO; diff --git a/Scripts/Services/PersonalityInsights/PersonalityInsights.cs.meta b/Scripts/Services/PersonalityInsights/v2/PersonalityInsights.cs.meta similarity index 100% rename from Scripts/Services/PersonalityInsights/PersonalityInsights.cs.meta rename to Scripts/Services/PersonalityInsights/v2/PersonalityInsights.cs.meta diff --git a/Scripts/Services/PersonalityInsights/v3.meta b/Scripts/Services/PersonalityInsights/v3.meta new file mode 100755 index 000000000..10012734a --- /dev/null +++ b/Scripts/Services/PersonalityInsights/v3.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: d57285b561f6fb24d8e367fcb5f4ef79 +folderAsset: yes +timeCreated: 1477342161 +licenseType: Pro +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Services/PersonalityInsights/v3/DataModels.cs b/Scripts/Services/PersonalityInsights/v3/DataModels.cs new file mode 100755 index 000000000..7ad5a83a3 --- /dev/null +++ b/Scripts/Services/PersonalityInsights/v3/DataModels.cs @@ -0,0 +1,323 @@ +/** +* Copyright 2015 IBM Corp. All Rights Reserved. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ + +using UnityEngine; +using System.Collections; + +namespace IBM.Watson.DeveloperCloud.Services.PersonalityInsights.v3 +{ + /// + /// The Profile object. + /// + [SerializeField] + public class Profile + { + /// + /// The language model that was used to process the input; for example, en. + /// + public string processed_language { get; set; } + /// + /// The number of words that were found in the input. + /// + public int word_count { get; set; } + /// + /// When guidance is appropriate, a string that provides a message that indicates + /// the number of words found and where that value falls in the range of required + /// or suggested number of words. + /// + public string word_count_message { get; set; } + /// + /// Detailed results for the Big Five personality characteristics (dimensions and + /// facets) inferred from the input text. + /// + public TraitTreeNode[] personality { get; set; } + /// + /// Detailed results for the Needs characteristics inferred from the input text. + /// + public TraitTreeNode[] values { get; set; } + /// + /// Detailed results for the Values characteristics inferred from the input text. + /// + public TraitTreeNode[] needs { get; set; } + /// + /// For JSON content that is timestamped, detailed results about the social behavior + /// disclosed by the input in terms of temporal characteristics. The results include + /// information about the distribution of the content over the days of the week and + /// the hours of the day. + /// + public BehaviorNode[] behavior { get; set; } + /// + /// If the consumption_preferences query parameter is true, detailed results for + /// each category of `consumption preferences`. Each element of the array provides + /// information inferred from the input text for the individual preferences of that + /// category. + /// + public ConsumptionPreferencesCategoryNode[] consumption_preferences { get; set; } + /// + /// Warning messages associated with the input text submitted with the request. The + /// array is empty if the input generated no warnings. + /// + public Warning[] warning { get; set; } + } + + /// + /// The Trait Tree Node object. + /// + [SerializeField] + public class TraitTreeNode + { + /// + /// The unique identifier of the characteristic to which the results pertain. IDs + /// have the form `big5_` for Big Five personality characteristics, `need_` for Needs, + /// or `value_` for Values. + /// + public string trait_id { get; set; } + /// + /// The user-visible name of the characteristic. + /// + public string name { get; set; } + /// + /// The category of the characteristic: personality for Big Five `personality` + /// characteristics, `needs` for Needs, or `values` for Values. + /// + public string category { get; set; } + /// + /// The normalized percentile score for the characteristic. The range is 0 to 1. For + /// example, if the percentage for Openness is 0.60, the author scored in the 60th + /// percentile; the author is more open than 59 percent of the population and less open + /// than 39 percent of the population. + /// + public double percentile { get; set; } + /// + /// The raw score for the characteristic. A positive or negative score indicates more + /// or less of the characteristic; zero indicates neutrality or no evidence for a + /// score. The raw score is computed based on the input and the service model; it is + /// not normalized or compared with a sample population. The raw score enables + /// comparison of the results against a different sampling population and with a custom + /// normalization approach. + /// + public double raw_score { get; set; } + /// + /// For `personality` (Big Five) dimensions, more detailed results for the facets of + /// each dimension as inferred from the input text. + /// + public TraitTreeNode[] children { get; set; } + } + + /// + /// The Behavior Node object. + /// + [SerializeField] + public class BehaviorNode + { + /// + /// The unique identifier of the characteristic to which the results pertain. IDs have + /// the form `behavior_`. + /// + public string trait_id { get; set; } + /// + /// The user-visible name of the characteristic. + /// + public string name { get; set; } + /// + /// The category of the characteristic: behavior for temporal data. + /// + public string category { get; set; } + /// + /// For JSON content that is timestamped, the percentage of timestamped input data + /// that occurred during that day of the week or hour of the day. The range is 0 to 1. + /// + public double percentage { get; set; } + } + + /// + /// The Consumption Preferences Category Node object. + /// + [SerializeField] + public class ConsumptionPreferencesCategoryNode + { + /// + /// The unique identifier of the consumption preferences category to which the results + /// pertain. IDs have the form `consumption_preferences_`. + /// + public string consumption_preference_category_id { get; set; } + /// + /// The user-visible name of the consumption preferences category. + /// + public string name { get; set; } + /// + /// Detailed results inferred from the input text for the individual preferences of + /// the category. + /// + public ConsumptionPreferencesNode[] consumption_preferences { get; set; } + } + + /// + /// The Warning Object. + /// + [SerializeField] + public class Warning + { + /// + /// The identifier of the warning message, one of `WORD_COUNT_MESSAGE`, `JSON_AS_TEXT`, + /// or `PARTIAL_TEXT_USED`. + /// + public string warning_id { get; set; } + /// + /// The message associated with the `warning_id`. For `WORD_COUNT_MESSAGE`, "There were + /// words in the input. We need a minimum of 600, preferably 1,200 or more, to + /// compute statistically significant estimates."; for `JSON_AS_TEXT`, "Request input + /// was processed as text/plain as indicated, however detected a JSON input. Did you + /// mean application/json?"; and for `PARTIAL_TEXT_USED`, "The text provided to compute the + /// profile was trimmed for performance reasons. This action does not affect the accuracy + /// of the output, as not all of the input text was required." The `PARTIAL_TEXT_USED` + /// warning applies only when Arabic input text exceeds a threshold at which additional + /// words do not contribute to the accuracy of the profile. + /// + public string message { get; set; } + } + + /// + /// The Consumption Preferences Node object. + /// + [SerializeField] + public class ConsumptionPreferencesNode + { + /// + /// The unique identifier of the consumption preference to which the results pertain. + /// IDs have the form `consumption_preferences_`. + /// + public string consumption_preference_id { get; set; } + /// + /// The user-visible name of the consumption preference. + /// + public string name { get; set; } + /// + /// The score for the consumption preference: `0.0` indicates unlikely, `0.5` indicates + /// neutrality, and `1.0` indicates likely. The scores for some preferences are binary and + /// do not allow a neutral value. The score is an indication of preference based on the + /// results inferred from the input text, not a normalized percentile. + /// + public double score { get; set; } + } + + /// + /// The content type. Either text, html or json. + /// + public class ContentType + { + /// + /// Mime type for plain text. + /// + public const string TEXT_PLAIN = "text/plain"; + + /// + /// Mime type for HTML. + /// + public const string TEXT_HTML = "text/html"; + + /// + /// Mime type for json. + /// + public const string APPLICATION_JSON = "application/json"; + } + + /// + /// The content language. Either English, Arabic, Spanish or Japanese. + /// + public class ContentLanguage + { + /// + /// English. + /// + public const string ENGLISH = "en"; + /// + /// Arabic. + /// + public const string ARABIC = "ar"; + /// + /// Spanish. + /// + public const string SPANISH = "es"; + /// + /// Japanese + /// + public const string JAPANESE = "ja"; + } + + /// + /// The accepted languages. + /// + public class AcceptLanguage + { + /// + /// English. + /// + public const string ENGLISH = "en"; + /// + /// Arabic. + /// + public const string ARABIC = "ar"; + /// + /// Spanish. + /// + public const string SPANISH = "es"; + /// + /// Japanese. + /// + public const string JAPANESE = "ja"; + /// + /// German. + /// + public const string GERMAN = "de"; + /// + /// French. + /// + public const string FRENCH = "fr"; + /// + /// Italian. + /// + public const string ITALIAN = "it"; + /// + /// Korean. + /// + public const string KOREAN = "ko"; + /// + /// Brazilian Portuguese. + /// + public const string BRAZILIAN_PORTUGUESE = "pt-br"; + /// + /// Simplified Chinese. + /// + public const string SIMPLIFIED_CHINESE = "zh-cn"; + /// + /// Traditional Chinese. + /// + public const string TRADITIONAL_CHINESE = "zh-tw"; + } + + /// + /// The Personality Insights version. + /// + public class PersonalityInsightsVersion + { + /// + /// The version. + /// + public const string Version = "2016-10-20"; + } +} diff --git a/Scripts/Services/PersonalityInsights/v3/DataModels.cs.meta b/Scripts/Services/PersonalityInsights/v3/DataModels.cs.meta new file mode 100755 index 000000000..c6794e4c0 --- /dev/null +++ b/Scripts/Services/PersonalityInsights/v3/DataModels.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 4b008bf955ac4074f8bdd08d46ecd0c7 +timeCreated: 1477342206 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Services/PersonalityInsights/v3/PersonalityInsights.cs b/Scripts/Services/PersonalityInsights/v3/PersonalityInsights.cs new file mode 100644 index 000000000..d4a358898 --- /dev/null +++ b/Scripts/Services/PersonalityInsights/v3/PersonalityInsights.cs @@ -0,0 +1,179 @@ +/** +* Copyright 2015 IBM Corp. All Rights Reserved. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ + +using FullSerializer; +using IBM.Watson.DeveloperCloud.Connection; +using IBM.Watson.DeveloperCloud.Logging; +using IBM.Watson.DeveloperCloud.Utilities; +using System; +using System.IO; +using System.Text; +using UnityEngine; + +namespace IBM.Watson.DeveloperCloud.Services.PersonalityInsights.v3 +{ + /// + /// This class wraps the Personality Insights service. + /// Personality Insights Service + /// + public class PersonalityInsights : IWatsonService + { + #region Private Data + private const string SERVICE_ID = "PersonalityInsightsV3"; + private static fsSerializer sm_Serializer = new fsSerializer(); + #endregion + + #region Profile + private const string SERVICE_GET_PROFILE = "/v3/profile"; + + public delegate void OnGetProfile(Profile profile, string data); + + public bool GetProfile(OnGetProfile callback, string source, + string contentType = ContentType.TEXT_PLAIN, + string contentLanguage = ContentLanguage.ENGLISH, + string accept = ContentType.APPLICATION_JSON, + string acceptLanguage = AcceptLanguage.ENGLISH, + bool raw_scores = false, + bool csv_headers = false, + bool consumption_preferences = false, + string version = PersonalityInsightsVersion.Version, + string data = default(string)) + { + if (callback == null) + throw new ArgumentNullException("callback"); + if (string.IsNullOrEmpty(source)) + throw new ArgumentNullException("A JSON or Text source is required for GetProfile!"); + + RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, SERVICE_GET_PROFILE); + if (connector == null) + return false; + + GetProfileRequest req = new GetProfileRequest(); + req.Source = source; + req.Callback = callback; + req.Data = data; + req.OnResponse = GetProfileResponse; + + req.Parameters["raw_scores"] = raw_scores.ToString(); + req.Parameters["csv_headers"] = csv_headers.ToString(); + req.Parameters["consumption_preferences"] = consumption_preferences.ToString(); + req.Parameters["version"] = version; + + req.Headers["Content-Type"] = contentType; + req.Headers["Content-Language"] = contentLanguage; + req.Headers["Accept"] = accept; + req.Headers["Accept-Language"] = acceptLanguage; + + if (source.StartsWith(Application.dataPath)) + { + string jsonData = default(string); + jsonData = File.ReadAllText(source); + req.Send = System.Text.Encoding.UTF8.GetBytes(jsonData); + } + else + { + req.Send = System.Text.Encoding.UTF8.GetBytes(source); + } + + return connector.Send(req); + } + + /// + /// Get profile request. + /// + public class GetProfileRequest : RESTConnector.Request + { + /// + /// The source string. + /// + public string Source { get; set; } + /// + /// Custom data. + /// + public string Data { get; set; } + /// + /// The callback. + /// + public OnGetProfile Callback { get; set; } + } + + private void GetProfileResponse(RESTConnector.Request req, RESTConnector.Response resp) + { + Profile response = new Profile(); + if (resp.Success) + { + try + { + fsData data = null; + fsResult r = fsJsonParser.Parse(Encoding.UTF8.GetString(resp.Data), out data); + if (!r.Succeeded) + throw new WatsonException(r.FormattedMessages); + + object obj = response; + r = sm_Serializer.TryDeserialize(data, obj.GetType(), ref obj); + if (!r.Succeeded) + throw new WatsonException(r.FormattedMessages); + } + catch (Exception e) + { + Log.Error("PersonalityInsights", "GetProfileResponse Exception: {0}", e.ToString()); + resp.Success = false; + } + } + + if (((GetProfileRequest)req).Callback != null) + ((GetProfileRequest)req).Callback(resp.Success ? response : null, ((GetProfileRequest)req).Data); + } + #endregion + + #region IWatsonService implementation + public string GetServiceID() + { + return SERVICE_ID; + } + + public void GetServiceStatus(ServiceStatus callback) + { + if (Utilities.Config.Instance.FindCredentials(SERVICE_ID) != null) + new CheckServiceStatus(this, callback); + else + callback(SERVICE_ID, false); + } + + private class CheckServiceStatus + { + private PersonalityInsights m_Service = null; + private ServiceStatus m_Callback = null; + + public CheckServiceStatus(PersonalityInsights service, ServiceStatus callback) + { + m_Service = service; + m_Callback = callback; + string dataPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/personalityInsights.json"; + if (!m_Service.GetProfile(OnGetProfile, dataPath, ContentType.TEXT_PLAIN, ContentLanguage.ENGLISH)) + m_Callback(SERVICE_ID, false); + } + + private void OnGetProfile(Profile resp, string data) + { + if (m_Callback != null) + m_Callback(SERVICE_ID, resp != null); + } + } + #endregion + } +} \ No newline at end of file diff --git a/Scripts/Services/PersonalityInsights/v3/PersonalityInsights.cs.meta b/Scripts/Services/PersonalityInsights/v3/PersonalityInsights.cs.meta new file mode 100644 index 000000000..342fc5f5c --- /dev/null +++ b/Scripts/Services/PersonalityInsights/v3/PersonalityInsights.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: f3362ea0537127044a68045b63ebc260 +timeCreated: 1477407311 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/UnitTests/TestPersonalityInsights.cs b/Scripts/UnitTests/TestPersonalityInsightsV2.cs similarity index 85% rename from Scripts/UnitTests/TestPersonalityInsights.cs rename to Scripts/UnitTests/TestPersonalityInsightsV2.cs index c965a805f..3f53293f2 100644 --- a/Scripts/UnitTests/TestPersonalityInsights.cs +++ b/Scripts/UnitTests/TestPersonalityInsightsV2.cs @@ -23,7 +23,7 @@ namespace IBM.Watson.DeveloperCloud.UnitTests { - public class TestPersonalityInsights : UnitTest { + public class TestPersonalityInsightsV2 : UnitTest { PersonalityInsights m_personalityInsights = new PersonalityInsights(); private string testString = "Facing certain defeat at the hands of a room-size I.B.M. computer on Wednesday evening, Ken Jennings, famous for winning 74 games in a row on the TV quiz show, acknowledged the obvious. \"I, for one, welcome our new computer overlords,\" he wrote on his video screen, borrowing a line from a \"Simpsons\" episode.\n\nFrom now on, if the answer is \"the computer champion on \"Jeopardy!,\" the question will be, \"What is Watson?\"\n\nFor I.B.M., the showdown was not merely a well-publicized stunt and a $1 million prize, but proof that the company has taken a big step toward a world in which intelligent machines will understand and respond to humans, and perhaps inevitably, replace some of them.\n\nWatson, specifically, is a \"question answering machine\" of a type that artificial intelligence researchers have struggled with for decades — a computer akin to the one on \"Star Trek\" that can understand questions posed in natural language and answer them.\n\nWatson showed itself to be imperfect, but researchers at I.B.M. and other companies are already developing uses for Watson's technologies that could have a significant impact on the way doctors practice and consumers buy products.\n\n\"Cast your mind back 20 years and who would have thought this was possible?\" said Edward Feigenbaum, a Stanford University computer scientist and a pioneer in the field.\n\nIn its \"Jeopardy!\" project, I.B.M. researchers were tackling a game that requires not only encyclopedic recall, but also the ability to untangle convoluted and often opaque statements, a modicum of luck, and quick, strategic button pressing.\n\nThe contest, which was taped in January here at the company's T. J. Watson Research Laboratory before an audience of I.B.M. executives and company clients, played out in three televised episodes concluding Wednesday. At the end of the first day, Watson was in a tie with Brad Rutter, another ace human player, at $5,000 each, with Mr. Jennings trailing with $2,000.\n\nBut on the second day, Watson went on a tear. By night's end, Watson had a commanding lead with a total of $35,734, compared with Mr. Rutter's $10,400 and Mr. Jennings's $4,800.\n\nVictory was not cemented until late in the third match, when Watson was in Nonfiction. \"Same category for $1,200,\" it said in a manufactured tenor, and lucked into a Daily Double. Mr. Jennings grimaced.\n\nEven later in the match, however, had Mr. Jennings won another key Daily Double it might have come down to Final Jeopardy, I.B.M. researchers acknowledged.\n\nThe final tally was $77,147 to Mr. Jennings's $24,000 and Mr. Rutter's $21,600.\n\nMore than anything, the contest was a vindication for the academic field of artificial intelligence, which began with great promise in the 1960s with the vision of creating a thinking machine and which became the laughingstock of Silicon Valley in the 1980s, when a series of heavily financed start-up companies went bankrupt.\n\nDespite its intellectual prowess, Watson was by no means omniscient. On Tuesday evening during Final Jeopardy, the category was U.S. Cities and the clue was: \"Its largest airport is named for a World War II hero; its second largest for a World War II battle.\"\n\nWatson drew guffaws from many in the television audience when it responded \"What is Toronto?????\"\n\nThe string of question marks indicated that the system had very low confidence in its response, I.B.M. researchers said, but because it was Final Jeopardy, it was forced to give a response. The machine did not suffer much damage. It had wagered just $947 on its result. (The correct answer is, \"What is Chicago?\")\n\n\"We failed to deeply understand what was going on there,\" said David Ferrucci, an I.B.M. researcher who led the development of Watson. \"The reality is that there's lots of data where the title is U.S. cities and the answers are countries, European cities, people, mayors. Even though it says U.S. cities, we had very little confidence that that's the distinguishing feature.\"\n\nThe researchers also acknowledged that the machine had benefited from the \"buzzer factor.\"\n\nBoth Mr. Jennings and Mr. Rutter are accomplished at anticipating the light that signals it is possible to \"buzz in,\" and can sometimes get in with virtually zero lag time. The danger is to buzz too early, in which case the contestant is penalized and \"locked out\" for roughly a quarter of a second.\n\nWatson, on the other hand, does not anticipate the light, but has a weighted scheme that allows it, when it is highly confident, to hit the buzzer in as little as 10 milliseconds, making it very hard for humans to beat. When it was less confident, it took longer to buzz in. In the second round, Watson beat the others to the buzzer in 24 out of 30 Double Jeopardy questions.\n\n\"It sort of wants to get beaten when it doesn't have high confidence,\" Dr. Ferrucci said. \"It doesn't want to look stupid.\"\n\nBoth human players said that Watson's button pushing skill was not necessarily an unfair advantage. \"I beat Watson a couple of times,\" Mr. Rutter said.\n\nWhen Watson did buzz in, it made the most of it. Showing the ability to parse language, it responded to, \"A recent best seller by Muriel Barbery is called 'This of the Hedgehog,' \" with \"What is Elegance?\"\n\nIt showed its facility with medical diagnosis. With the answer: \"You just need a nap. You don't have this sleep disorder that can make sufferers nod off while standing up,\" Watson replied, \"What is narcolepsy?\"\n\nThe coup de grâce came with the answer, \"William Wilkenson's 'An Account of the Principalities of Wallachia and Moldavia' inspired this author's most famous novel.\" Mr. Jennings wrote, correctly, Bram Stoker, but realized that he could not catch up with Watson's winnings and wrote out his surrender.\n\nBoth players took the contest and its outcome philosophically.\n\n\"I had a great time and I would do it again in a heartbeat,\" said Mr. Jennings. \"It's not about the results; this is about being part of the future.\"\n\nFor I.B.M., the future will happen very quickly, company executives said. On Thursday it plans to announce that it will collaborate with Columbia University and the University of Maryland to create a physician's assistant service that will allow doctors to query a cybernetic assistant. The company also plans to work with Nuance Communications Inc. to add voice recognition to the physician's assistant, possibly making the service available in as little as 18 months.\n\n\"I have been in medical education for 40 years and we're still a very memory-based curriculum,\" said Dr. Herbert Chase, a professor of clinical medicine at Columbia University who is working with I.B.M. on the physician's assistant. \"The power of Watson- like tools will cause us to reconsider what it is we want students to do.\"\n\nI.B.M. executives also said they are in discussions with a major consumer electronics retailer to develop a version of Watson, named after I.B.M.'s founder, Thomas J. Watson, that would be able to interact with consumers on a variety of subjects like buying decisions and technical support.\n\nDr. Ferrucci sees none of the fears that have been expressed by theorists and science fiction writers about the potential of computers to usurp humans.\n\n\"People ask me if this is HAL,\" he said, referring to the computer in \"2001: A Space Odyssey.\" \"HAL's not the focus; the focus is on the computer on 'Star Trek,' where you have this intelligent information seek dialogue, where you can ask follow-up questions and the computer can look at all the evidence and tries to ask follow-up questions. That's very cool.\""; @@ -38,12 +38,12 @@ public override IEnumerator RunTest() if ( Utilities.Config.Instance.FindCredentials( m_personalityInsights.GetServiceID() ) == null ) yield break; - Log.Debug("TestPersonalityInsights", "Attempting GetProfile using Text!"); + Log.Debug("TestPersonalityInsightsV2", "Attempting GetProfile using Text!"); m_personalityInsights.GetProfile(OnGetProfileText, testString); while(!m_GetProfileTextTested) yield return null; - Log.Debug("TestPersonalityInsights", "Attempting GetProfile using Json!"); + Log.Debug("TestPersonalityInsightsV2", "Attempting GetProfile using Json!"); m_personalityInsights.GetProfile(OnGetProfileJson, dataPath); while(!m_GetProfileJsonTested) yield return null; @@ -58,15 +58,15 @@ private void OnGetProfileText(Profile profile, string data) if(profile != null) { if(!string.IsNullOrEmpty(profile.id)) - Log.Debug("ExamplePersonalityInsights", "id: {0}", profile.id); + Log.Debug("TestPersonalityInsightsV2", "id: {0}", profile.id); if(!string.IsNullOrEmpty(profile.source)) - Log.Debug("ExamplePersonalityInsights", "source: {0}", profile.source); + Log.Debug("TestPersonalityInsightsV2", "source: {0}", profile.source); if(!string.IsNullOrEmpty(profile.processed_lang)) - Log.Debug("ExamplePersonalityInsights", "proccessed_lang: {0}", profile.processed_lang); + Log.Debug("TestPersonalityInsightsV2", "proccessed_lang: {0}", profile.processed_lang); if(!string.IsNullOrEmpty(profile.word_count)) - Log.Debug("ExamplePersonalityInsights", "word_count: {0}", profile.word_count); + Log.Debug("TestPersonalityInsightsV2", "word_count: {0}", profile.word_count); if(!string.IsNullOrEmpty(profile.word_count_message)) - Log.Debug("ExamplePersonalityInsights", "word_count_message: {0}", profile.word_count_message); + Log.Debug("TestPersonalityInsightsV2", "word_count_message: {0}", profile.word_count_message); if(profile.tree != null) { @@ -84,15 +84,15 @@ private void OnGetProfileJson(Profile profile, string data) if(profile != null) { if(!string.IsNullOrEmpty(profile.id)) - Log.Debug("ExamplePersonalityInsights", "id: {0}", profile.id); + Log.Debug("TestPersonalityInsightsV2", "id: {0}", profile.id); if(!string.IsNullOrEmpty(profile.source)) - Log.Debug("ExamplePersonalityInsights", "source: {0}", profile.source); + Log.Debug("TestPersonalityInsightsV2", "source: {0}", profile.source); if(!string.IsNullOrEmpty(profile.processed_lang)) - Log.Debug("ExamplePersonalityInsights", "proccessed_lang: {0}", profile.processed_lang); + Log.Debug("TestPersonalityInsightsV2", "proccessed_lang: {0}", profile.processed_lang); if(!string.IsNullOrEmpty(profile.word_count)) - Log.Debug("ExamplePersonalityInsights", "word_count: {0}", profile.word_count); + Log.Debug("TestPersonalityInsightsV2", "word_count: {0}", profile.word_count); if(!string.IsNullOrEmpty(profile.word_count_message)) - Log.Debug("ExamplePersonalityInsights", "word_count_message: {0}", profile.word_count_message); + Log.Debug("TestPersonalityInsightsV2", "word_count_message: {0}", profile.word_count_message); if(profile.tree != null) { @@ -106,19 +106,19 @@ private void OnGetProfileJson(Profile profile, string data) private void LogTraitTree(TraitTreeNode traitTreeNode) { if(!string.IsNullOrEmpty(traitTreeNode.id)) - Log.Debug("ExamplePersonalityInsights", "id: {0}", traitTreeNode.id); + Log.Debug("TestPersonalityInsightsV2", "id: {0}", traitTreeNode.id); if(!string.IsNullOrEmpty(traitTreeNode.name)) - Log.Debug("ExamplePersonalityInsights", "name: {0}", traitTreeNode.name); + Log.Debug("TestPersonalityInsightsV2", "name: {0}", traitTreeNode.name); if(!string.IsNullOrEmpty(traitTreeNode.category)) - Log.Debug("ExamplePersonalityInsights", "category: {0}", traitTreeNode.category); + Log.Debug("TestPersonalityInsightsV2", "category: {0}", traitTreeNode.category); if(!string.IsNullOrEmpty(traitTreeNode.percentage)) - Log.Debug("ExamplePersonalityInsights", "percentage: {0}", traitTreeNode.percentage); + Log.Debug("TestPersonalityInsightsV2", "percentage: {0}", traitTreeNode.percentage); if(!string.IsNullOrEmpty(traitTreeNode.sampling_error)) - Log.Debug("ExamplePersonalityInsights", "sampling_error: {0}", traitTreeNode.sampling_error); + Log.Debug("TestPersonalityInsightsV2", "sampling_error: {0}", traitTreeNode.sampling_error); if(!string.IsNullOrEmpty(traitTreeNode.raw_score)) - Log.Debug("ExamplePersonalityInsights", "raw_score: {0}", traitTreeNode.raw_score); + Log.Debug("TestPersonalityInsightsV2", "raw_score: {0}", traitTreeNode.raw_score); if(!string.IsNullOrEmpty(traitTreeNode.raw_sampling_error)) - Log.Debug("ExamplePersonalityInsights", "raw_sampling_error: {0}", traitTreeNode.raw_sampling_error); + Log.Debug("TestPersonalityInsightsV2", "raw_sampling_error: {0}", traitTreeNode.raw_sampling_error); if(traitTreeNode.children != null && traitTreeNode.children.Length > 0) foreach(TraitTreeNode childNode in traitTreeNode.children) LogTraitTree(childNode); diff --git a/Scripts/UnitTests/TestPersonalityInsights.cs.meta b/Scripts/UnitTests/TestPersonalityInsightsV2.cs.meta similarity index 100% rename from Scripts/UnitTests/TestPersonalityInsights.cs.meta rename to Scripts/UnitTests/TestPersonalityInsightsV2.cs.meta diff --git a/Scripts/UnitTests/TestPersonalityInsightsV3.cs b/Scripts/UnitTests/TestPersonalityInsightsV3.cs new file mode 100644 index 000000000..97c743a79 --- /dev/null +++ b/Scripts/UnitTests/TestPersonalityInsightsV3.cs @@ -0,0 +1,198 @@ +/** +* Copyright 2015 IBM Corp. All Rights Reserved. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ + + +using UnityEngine; +using System.Collections; +using IBM.Watson.DeveloperCloud.Services.PersonalityInsights.v3; +using IBM.Watson.DeveloperCloud.Logging; + +namespace IBM.Watson.DeveloperCloud.UnitTests +{ + public class TestPersonalityInsightsV3 : UnitTest + { + PersonalityInsights m_personalityInsights = new PersonalityInsights(); + private string testString = "Facing certain defeat at the hands of a room-size I.B.M. computer on Wednesday evening, Ken Jennings, famous for winning 74 games in a row on the TV quiz show, acknowledged the obvious. \"I, for one, welcome our new computer overlords,\" he wrote on his video screen, borrowing a line from a \"Simpsons\" episode.\n\nFrom now on, if the answer is \"the computer champion on \"Jeopardy!,\" the question will be, \"What is Watson?\"\n\nFor I.B.M., the showdown was not merely a well-publicized stunt and a $1 million prize, but proof that the company has taken a big step toward a world in which intelligent machines will understand and respond to humans, and perhaps inevitably, replace some of them.\n\nWatson, specifically, is a \"question answering machine\" of a type that artificial intelligence researchers have struggled with for decades — a computer akin to the one on \"Star Trek\" that can understand questions posed in natural language and answer them.\n\nWatson showed itself to be imperfect, but researchers at I.B.M. and other companies are already developing uses for Watson's technologies that could have a significant impact on the way doctors practice and consumers buy products.\n\n\"Cast your mind back 20 years and who would have thought this was possible?\" said Edward Feigenbaum, a Stanford University computer scientist and a pioneer in the field.\n\nIn its \"Jeopardy!\" project, I.B.M. researchers were tackling a game that requires not only encyclopedic recall, but also the ability to untangle convoluted and often opaque statements, a modicum of luck, and quick, strategic button pressing.\n\nThe contest, which was taped in January here at the company's T. J. Watson Research Laboratory before an audience of I.B.M. executives and company clients, played out in three televised episodes concluding Wednesday. At the end of the first day, Watson was in a tie with Brad Rutter, another ace human player, at $5,000 each, with Mr. Jennings trailing with $2,000.\n\nBut on the second day, Watson went on a tear. By night's end, Watson had a commanding lead with a total of $35,734, compared with Mr. Rutter's $10,400 and Mr. Jennings's $4,800.\n\nVictory was not cemented until late in the third match, when Watson was in Nonfiction. \"Same category for $1,200,\" it said in a manufactured tenor, and lucked into a Daily Double. Mr. Jennings grimaced.\n\nEven later in the match, however, had Mr. Jennings won another key Daily Double it might have come down to Final Jeopardy, I.B.M. researchers acknowledged.\n\nThe final tally was $77,147 to Mr. Jennings's $24,000 and Mr. Rutter's $21,600.\n\nMore than anything, the contest was a vindication for the academic field of artificial intelligence, which began with great promise in the 1960s with the vision of creating a thinking machine and which became the laughingstock of Silicon Valley in the 1980s, when a series of heavily financed start-up companies went bankrupt.\n\nDespite its intellectual prowess, Watson was by no means omniscient. On Tuesday evening during Final Jeopardy, the category was U.S. Cities and the clue was: \"Its largest airport is named for a World War II hero; its second largest for a World War II battle.\"\n\nWatson drew guffaws from many in the television audience when it responded \"What is Toronto?????\"\n\nThe string of question marks indicated that the system had very low confidence in its response, I.B.M. researchers said, but because it was Final Jeopardy, it was forced to give a response. The machine did not suffer much damage. It had wagered just $947 on its result. (The correct answer is, \"What is Chicago?\")\n\n\"We failed to deeply understand what was going on there,\" said David Ferrucci, an I.B.M. researcher who led the development of Watson. \"The reality is that there's lots of data where the title is U.S. cities and the answers are countries, European cities, people, mayors. Even though it says U.S. cities, we had very little confidence that that's the distinguishing feature.\"\n\nThe researchers also acknowledged that the machine had benefited from the \"buzzer factor.\"\n\nBoth Mr. Jennings and Mr. Rutter are accomplished at anticipating the light that signals it is possible to \"buzz in,\" and can sometimes get in with virtually zero lag time. The danger is to buzz too early, in which case the contestant is penalized and \"locked out\" for roughly a quarter of a second.\n\nWatson, on the other hand, does not anticipate the light, but has a weighted scheme that allows it, when it is highly confident, to hit the buzzer in as little as 10 milliseconds, making it very hard for humans to beat. When it was less confident, it took longer to buzz in. In the second round, Watson beat the others to the buzzer in 24 out of 30 Double Jeopardy questions.\n\n\"It sort of wants to get beaten when it doesn't have high confidence,\" Dr. Ferrucci said. \"It doesn't want to look stupid.\"\n\nBoth human players said that Watson's button pushing skill was not necessarily an unfair advantage. \"I beat Watson a couple of times,\" Mr. Rutter said.\n\nWhen Watson did buzz in, it made the most of it. Showing the ability to parse language, it responded to, \"A recent best seller by Muriel Barbery is called 'This of the Hedgehog,' \" with \"What is Elegance?\"\n\nIt showed its facility with medical diagnosis. With the answer: \"You just need a nap. You don't have this sleep disorder that can make sufferers nod off while standing up,\" Watson replied, \"What is narcolepsy?\"\n\nThe coup de grâce came with the answer, \"William Wilkenson's 'An Account of the Principalities of Wallachia and Moldavia' inspired this author's most famous novel.\" Mr. Jennings wrote, correctly, Bram Stoker, but realized that he could not catch up with Watson's winnings and wrote out his surrender.\n\nBoth players took the contest and its outcome philosophically.\n\n\"I had a great time and I would do it again in a heartbeat,\" said Mr. Jennings. \"It's not about the results; this is about being part of the future.\"\n\nFor I.B.M., the future will happen very quickly, company executives said. On Thursday it plans to announce that it will collaborate with Columbia University and the University of Maryland to create a physician's assistant service that will allow doctors to query a cybernetic assistant. The company also plans to work with Nuance Communications Inc. to add voice recognition to the physician's assistant, possibly making the service available in as little as 18 months.\n\n\"I have been in medical education for 40 years and we're still a very memory-based curriculum,\" said Dr. Herbert Chase, a professor of clinical medicine at Columbia University who is working with I.B.M. on the physician's assistant. \"The power of Watson- like tools will cause us to reconsider what it is we want students to do.\"\n\nI.B.M. executives also said they are in discussions with a major consumer electronics retailer to develop a version of Watson, named after I.B.M.'s founder, Thomas J. Watson, that would be able to interact with consumers on a variety of subjects like buying decisions and technical support.\n\nDr. Ferrucci sees none of the fears that have been expressed by theorists and science fiction writers about the potential of computers to usurp humans.\n\n\"People ask me if this is HAL,\" he said, referring to the computer in \"2001: A Space Odyssey.\" \"HAL's not the focus; the focus is on the computer on 'Star Trek,' where you have this intelligent information seek dialogue, where you can ask follow-up questions and the computer can look at all the evidence and tries to ask follow-up questions. That's very cool.\""; + + + bool m_GetProfileTextTested = false; + bool m_GetProfileJsonTested = false; + + public override IEnumerator RunTest() + { + string dataPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/personalityInsights.json"; + + if (Utilities.Config.Instance.FindCredentials(m_personalityInsights.GetServiceID()) == null) + yield break; + + Log.Debug("TestPersonalityInsightsV3", "Attempting GetProfile using Text!"); + m_personalityInsights.GetProfile(OnGetProfileText, testString, ContentType.TEXT_HTML, ContentLanguage.ENGLISH, ContentType.APPLICATION_JSON, AcceptLanguage.ENGLISH, true, true, true); + while (!m_GetProfileTextTested) + yield return null; + + Log.Debug("TestPersonalityInsightsV3", "Attempting GetProfile using Json!"); + m_personalityInsights.GetProfile(OnGetProfileJson, dataPath, ContentType.TEXT_HTML, ContentLanguage.ENGLISH, ContentType.APPLICATION_JSON, AcceptLanguage.ENGLISH, true, true, true); + while (!m_GetProfileJsonTested) + yield return null; + + yield break; + } + + private void OnGetProfileText(Profile profile, string data) + { + Test(profile != null); + + if (profile != null) + { + if (!string.IsNullOrEmpty(profile.processed_language)) + Log.Debug("TestPersonalityInsightsV3", "processed_language: {0}", profile.processed_language); + + Log.Debug("TestPersonalityInsightsV3", "word_count: {0}", profile.word_count); + + if (!string.IsNullOrEmpty(profile.word_count_message)) + Log.Debug("TestPersonalityInsightsV3", "word_count_message: {0}", profile.word_count_message); + + if (profile.personality != null && profile.personality.Length > 0) + { + Log.Debug("TestPersonalityInsightsV3", "Personality trait tree"); + foreach (TraitTreeNode node in profile.personality) + LogTraitTree(node); + } + + if (profile.values != null && profile.values.Length > 0) + { + Log.Debug("TestPersonalityInsightsV3", "Values trait tree"); + foreach (TraitTreeNode node in profile.values) + LogTraitTree(node); + } + + if (profile.needs != null && profile.personality.Length > 0) + { + Log.Debug("TestPersonalityInsightsV3", "Needs trait tree"); + foreach (TraitTreeNode node in profile.needs) + LogTraitTree(node); + } + + if (profile.behavior != null && profile.behavior.Length > 0) + { + Log.Debug("TestPersonalityInsightsV3", "Behavior tree"); + foreach (BehaviorNode behavior in profile.behavior) + { + Log.Debug("TestPersonalityInsightsV3", "trait_id: {0}", behavior.trait_id); + Log.Debug("TestPersonalityInsightsV3", "name: {0}", behavior.name); + Log.Debug("TestPersonalityInsightsV3", "category: {0}", behavior.category); + Log.Debug("TestPersonalityInsightsV3", "percentage: {0}", behavior.percentage.ToString()); + Log.Debug("TestPersonalityInsightsV3", "----------------"); + } + } + + if (profile.consumption_preferences != null && profile.consumption_preferences.Length > 0) + { + Log.Debug("TestPersonalityInsightsV3", "ConsumptionPreferencesCategories"); + foreach (ConsumptionPreferencesCategoryNode categoryNode in profile.consumption_preferences) + LogConsumptionPreferencesCategory(categoryNode); + } + + m_GetProfileTextTested = true; + } + } + + private void OnGetProfileJson(Profile profile, string data) + { + Test(profile != null); + + if (profile != null) + { + if (!string.IsNullOrEmpty(profile.processed_language)) + Log.Debug("TestPersonalityInsightsV3", "processed_language: {0}", profile.processed_language); + + Log.Debug("TestPersonalityInsightsV3", "word_count: {0}", profile.word_count); + + if (!string.IsNullOrEmpty(profile.word_count_message)) + Log.Debug("TestPersonalityInsightsV3", "word_count_message: {0}", profile.word_count_message); + + if (profile.personality != null && profile.personality.Length > 0) + { + Log.Debug("TestPersonalityInsightsV3", "Personality trait tree"); + foreach (TraitTreeNode node in profile.personality) + LogTraitTree(node); + } + + if (profile.values != null && profile.values.Length > 0) + { + Log.Debug("TestPersonalityInsightsV3", "Values trait tree"); + foreach (TraitTreeNode node in profile.values) + LogTraitTree(node); + } + + if (profile.needs != null && profile.personality.Length > 0) + { + Log.Debug("TestPersonalityInsightsV3", "Needs trait tree"); + foreach (TraitTreeNode node in profile.needs) + LogTraitTree(node); + } + + if (profile.behavior != null && profile.behavior.Length > 0) + { + Log.Debug("TestPersonalityInsightsV3", "Behavior tree"); + foreach (BehaviorNode behavior in profile.behavior) + { + Log.Debug("TestPersonalityInsightsV3", "trait_id: {0}", behavior.trait_id); + Log.Debug("TestPersonalityInsightsV3", "name: {0}", behavior.name); + Log.Debug("TestPersonalityInsightsV3", "category: {0}", behavior.category); + Log.Debug("TestPersonalityInsightsV3", "percentage: {0}", behavior.percentage.ToString()); + Log.Debug("TestPersonalityInsightsV3", "----------------"); + } + } + + if (profile.consumption_preferences != null && profile.consumption_preferences.Length > 0) + { + Log.Debug("TestPersonalityInsightsV3", "ConsumptionPreferencesCategories"); + foreach (ConsumptionPreferencesCategoryNode categoryNode in profile.consumption_preferences) + LogConsumptionPreferencesCategory(categoryNode); + } + + m_GetProfileJsonTested = true; + } + } + + private void LogTraitTree(TraitTreeNode traitTreeNode) + { + Log.Debug("TestPersonalityInsightsV3", "trait_id: {0} | name: {1} | category: {2} | percentile: {3} | raw_score: {4}", + string.IsNullOrEmpty(traitTreeNode.trait_id) ? "null" : traitTreeNode.trait_id, + string.IsNullOrEmpty(traitTreeNode.name) ? "null" : traitTreeNode.name, + string.IsNullOrEmpty(traitTreeNode.category) ? "null" : traitTreeNode.category, + string.IsNullOrEmpty(traitTreeNode.percentile.ToString()) ? "null" : traitTreeNode.percentile.ToString(), + string.IsNullOrEmpty(traitTreeNode.raw_score.ToString()) ? "null" : traitTreeNode.raw_score.ToString()); + + if (traitTreeNode.children != null && traitTreeNode.children.Length > 0) + foreach (TraitTreeNode childNode in traitTreeNode.children) + LogTraitTree(childNode); + } + + private void LogConsumptionPreferencesCategory(ConsumptionPreferencesCategoryNode categoryNode) + { + Log.Debug("TestPersonalityInsightsV3", "consumption_preference_category_id: {0} | name: {1}", categoryNode.consumption_preference_category_id, categoryNode.name); + + foreach (ConsumptionPreferencesNode preferencesNode in categoryNode.consumption_preferences) + Log.Debug("TestPersonalityInsightsV3", "\t consumption_preference_id: {0} | name: {1} | score: {2}", + string.IsNullOrEmpty(preferencesNode.consumption_preference_id) ? "null" : preferencesNode.consumption_preference_id, + string.IsNullOrEmpty(preferencesNode.name) ? "null" : preferencesNode.name, + string.IsNullOrEmpty(preferencesNode.score.ToString()) ? "null" : preferencesNode.score.ToString()); + } + } +} diff --git a/Scripts/UnitTests/TestPersonalityInsightsV3.cs.meta b/Scripts/UnitTests/TestPersonalityInsightsV3.cs.meta new file mode 100644 index 000000000..9acc1edf6 --- /dev/null +++ b/Scripts/UnitTests/TestPersonalityInsightsV3.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 1a0853792d73c4947a77efa9a86c126b +timeCreated: 1477410596 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: