Skip to content
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand Down
174 changes: 174 additions & 0 deletions Examples/ServiceExamples/Scripts/ExamplePersonalityInsightsV3.cs
Original file line number Diff line number Diff line change
@@ -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 = "<text-here>";
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());
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 46 additions & 6 deletions Examples/ServiceExamples/ServiceExamples.unity
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading