diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..64b7d729c --- /dev/null +++ b/.editorconfig @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 2dd1b8b9c..bd219781c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,14 +1,19 @@ Change Log ========== +## Version 0.12.0 +_2016-11-4_ +* New: Added streaming `SpeechToText` example. +* New: Abstraction for `Personality Insights V3` + ## Version 0.11.0 -_2016_10_27_ +_2016-10-27_ * New: Abstracted `Speech to Text` customization methods. ## Version 0.10.0 -_2016_09_23_ +_2016-09-23_ * New: Added `similarity search` to the `Visual Recognition` service. -* Fix: `Touch Widget` improvmements. +* Fix: `Touch Widget` improvements. * Fix: Disabled 3rd Party plugin warnings. * Fix: Removed `Conversation` Message overload method that takes only input and conversationID. * Fix: Rewrote `Conversation` example script to show how to create MessageRequest object. diff --git a/Examples/ServiceExamples/ExampleStreaming.unity b/Examples/ServiceExamples/ExampleStreaming.unity new file mode 100755 index 000000000..2d5d7cffd --- /dev/null +++ b/Examples/ServiceExamples/ExampleStreaming.unity @@ -0,0 +1,282 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!29 &1 +SceneSettings: + m_ObjectHideFlags: 0 + m_PVSData: + m_PVSObjectsArray: [] + m_PVSPortalsArray: [] + m_OcclusionBakeSettings: + smallestOccluder: 5 + smallestHole: 0.25 + backfaceThreshold: 100 +--- !u!104 &2 +RenderSettings: + m_ObjectHideFlags: 0 + serializedVersion: 7 + m_Fog: 0 + m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} + m_FogMode: 3 + m_FogDensity: 0.01 + m_LinearFogStart: 0 + m_LinearFogEnd: 300 + m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1} + m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1} + m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1} + m_AmbientIntensity: 1 + m_AmbientMode: 0 + m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0} + m_HaloStrength: 0.5 + m_FlareStrength: 1 + m_FlareFadeSpeed: 3 + m_HaloTexture: {fileID: 0} + m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0} + m_DefaultReflectionMode: 0 + m_DefaultReflectionResolution: 128 + m_ReflectionBounces: 1 + m_ReflectionIntensity: 1 + m_CustomReflection: {fileID: 0} + m_Sun: {fileID: 0} + m_IndirectSpecularColor: {r: 0.4469244, g: 0.4967847, b: 0.575083, a: 1} +--- !u!157 &3 +LightmapSettings: + m_ObjectHideFlags: 0 + serializedVersion: 7 + m_GIWorkflowMode: 0 + m_GISettings: + serializedVersion: 2 + m_BounceScale: 1 + m_IndirectOutputScale: 1 + m_AlbedoBoost: 1 + m_TemporalCoherenceThreshold: 1 + m_EnvironmentLightingMode: 0 + m_EnableBakedLightmaps: 1 + m_EnableRealtimeLightmaps: 1 + m_LightmapEditorSettings: + serializedVersion: 4 + m_Resolution: 2 + m_BakeResolution: 40 + m_TextureWidth: 1024 + m_TextureHeight: 1024 + m_AO: 0 + m_AOMaxDistance: 1 + m_CompAOExponent: 1 + m_CompAOExponentDirect: 0 + m_Padding: 2 + m_LightmapParameters: {fileID: 0} + m_LightmapsBakeMode: 1 + m_TextureCompression: 1 + m_DirectLightInLightProbes: 1 + m_FinalGather: 0 + m_FinalGatherFiltering: 1 + m_FinalGatherRayCount: 256 + m_ReflectionCompression: 2 + m_LightingDataAsset: {fileID: 0} + m_RuntimeCPUUsage: 25 +--- !u!196 &4 +NavMeshSettings: + serializedVersion: 2 + m_ObjectHideFlags: 0 + m_BuildSettings: + serializedVersion: 2 + agentRadius: 0.5 + agentHeight: 2 + agentSlope: 45 + agentClimb: 0.4 + ledgeDropHeight: 0 + maxJumpAcrossDistance: 0 + accuratePlacement: 0 + minRegionArea: 2 + cellSize: 0.16666667 + manualCellSize: 0 + m_NavMeshData: {fileID: 0} +--- !u!1 &1159842907 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 4 + m_Component: + - 4: {fileID: 1159842909} + - 108: {fileID: 1159842908} + m_Layer: 0 + m_Name: Directional Light + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!108 &1159842908 +Light: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1159842907} + m_Enabled: 1 + serializedVersion: 7 + m_Type: 1 + m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1} + m_Intensity: 1 + m_Range: 10 + m_SpotAngle: 30 + m_CookieSize: 10 + m_Shadows: + m_Type: 2 + m_Resolution: -1 + m_CustomResolution: -1 + m_Strength: 1 + m_Bias: 0.05 + m_NormalBias: 0.4 + m_NearPlane: 0.2 + m_Cookie: {fileID: 0} + m_DrawHalo: 0 + m_Flare: {fileID: 0} + m_RenderMode: 0 + m_CullingMask: + serializedVersion: 2 + m_Bits: 4294967295 + m_Lightmapping: 4 + m_AreaSize: {x: 1, y: 1} + m_BounceIntensity: 1 + m_ShadowRadius: 0 + m_ShadowAngle: 0 +--- !u!4 &1159842909 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1159842907} + m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261} + m_LocalPosition: {x: 0, y: 3, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 1 +--- !u!1 &1391086061 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 4 + m_Component: + - 4: {fileID: 1391086066} + - 20: {fileID: 1391086065} + - 92: {fileID: 1391086064} + - 124: {fileID: 1391086063} + - 81: {fileID: 1391086062} + m_Layer: 0 + m_Name: Main Camera + m_TagString: MainCamera + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!81 &1391086062 +AudioListener: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1391086061} + m_Enabled: 1 +--- !u!124 &1391086063 +Behaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1391086061} + m_Enabled: 1 +--- !u!92 &1391086064 +Behaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1391086061} + m_Enabled: 1 +--- !u!20 &1391086065 +Camera: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1391086061} + m_Enabled: 1 + serializedVersion: 2 + m_ClearFlags: 1 + m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0} + m_NormalizedViewPortRect: + serializedVersion: 2 + x: 0 + y: 0 + width: 1 + height: 1 + near clip plane: 0.3 + far clip plane: 1000 + field of view: 60 + orthographic: 0 + orthographic size: 5 + m_Depth: -1 + m_CullingMask: + serializedVersion: 2 + m_Bits: 4294967295 + m_RenderingPath: -1 + m_TargetTexture: {fileID: 0} + m_TargetDisplay: 0 + m_TargetEye: 3 + m_HDR: 0 + m_OcclusionCulling: 1 + m_StereoConvergence: 10 + m_StereoSeparation: 0.022 + m_StereoMirrorMode: 0 +--- !u!4 &1391086066 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1391086061} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 1, z: -10} + m_LocalScale: {x: 1, y: 1, z: 1} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 +--- !u!1 &1646685149 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 4 + m_Component: + - 4: {fileID: 1646685151} + - 114: {fileID: 1646685150} + m_Layer: 0 + m_Name: ExampleStreaming + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &1646685150 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1646685149} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 6c5299c1c838a8c44b49ecc9254704e0, type: 3} + m_Name: + m_EditorClassIdentifier: +--- !u!4 &1646685151 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1646685149} + 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: 2 diff --git a/Examples/ServiceExamples/ExampleStreaming.unity.meta b/Examples/ServiceExamples/ExampleStreaming.unity.meta new file mode 100755 index 000000000..7873c0333 --- /dev/null +++ b/Examples/ServiceExamples/ExampleStreaming.unity.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 57c7b454bb032a34fa0f938231dba758 +timeCreated: 1477325083 +licenseType: Pro +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Examples/ServiceExamples/Scripts/ExampleAlchemyDataNews.cs b/Examples/ServiceExamples/Scripts/ExampleAlchemyDataNews.cs index 834e451d3..960b0efcb 100755 --- a/Examples/ServiceExamples/Scripts/ExampleAlchemyDataNews.cs +++ b/Examples/ServiceExamples/Scripts/ExampleAlchemyDataNews.cs @@ -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 queryFields = new Dictionary(); - 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 queryFields = new Dictionary(); + 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); + } } diff --git a/Examples/ServiceExamples/Scripts/ExampleAlchemyLanguage.cs b/Examples/ServiceExamples/Scripts/ExampleAlchemyLanguage.cs index e87375f9a..44a4109c5 100755 --- a/Examples/ServiceExamples/Scripts/ExampleAlchemyLanguage.cs +++ b/Examples/ServiceExamples/Scripts/ExampleAlchemyLanguage.cs @@ -16,7 +16,6 @@ */ using UnityEngine; -using System.Collections; using IBM.Watson.DeveloperCloud.Services.AlchemyAPI.v1; using IBM.Watson.DeveloperCloud.Logging; @@ -24,584 +23,584 @@ #pragma warning disable 0414 public class ExampleAlchemyLanguage : MonoBehaviour { - private AlchemyAPI m_AlchemyAPI = new AlchemyAPI(); - private string m_ExampleURL_unitySDK = "https://developer.ibm.com/open/2016/01/21/introducing-watson-unity-sdk/"; - private string m_ExampleURL_watsonJeopardy = "http://www.nytimes.com/2011/02/17/science/17jeopardy-watson.html"; - private string m_ExampleURL_microformats = "http://microformats.org/wiki/hcard"; - private string m_ExampleText_unitySDK = "Game on! Introducing Watson Unity SDK, \nRICHARD LYLE / JANUARY 21, 2016 \nAfter several months of work we are happy to present the Watson Unity SDK, an SDK to enable the Unity community to access the Watson Developer Cloud and build a cognitive application in Unity.\n\nI’ve been involved in the game industry for 22+ years now, but I can tell you in all honestly working in the Watson Innovation Labs and on this project has been the highlight of my career. This SDK really represents the first phase in what we plan to bring to the community, which in the end will be a framework for building a full cognitive application.\n\nYou as a developer will find very simple C# service abstractions for accessing Dialog, Speech To Text, Text to Speech, Language Translation, and Natural Language Classification services. Additionally, we’ve implemented something we are calling a Widget, which has inputs and outputs and performs some basic function.\n\nThese widgets can be connected together to form a graph for the data that’s routed for a given cognitive application. The widgets will attempt to automatically connect to each other, or you as a developer can override that behavior and manually take control of the process. We’ve implemented widgets for all of the basic services and provide a couple of example applications showing how they can work together.\n\nWe plan to continue to expand and build on the Watson Unity SDK. We invite you to join us in contributing to and using the SDK, or by simply giving us your feedback. We’d love to have you on board for this ride!"; - private string m_ExampleText_watsonJeopardy = "Computer Wins on 'Jeopardy!': Trivial, It's Not\nBy JOHN MARKOFF\nYORKTOWN HEIGHTS, N.Y. — In the end, the humans on \"Jeopardy!\" surrendered meekly.\n\nFacing 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.\"\n\nThis article has been revised to reflect the following correction:\n\nCorrection: February 24, 2011\n\n\nAn article last Thursday about the I.B.M. computer Watson misidentified the academic field vindicated by Watson's besting of two human opponents on \"Jeopardy!\" It is artificial intelligence — not computer science, a broader field that includes artificial intelligence."; - void Start() - { - LogSystem.InstallDefaultReactors(); - string unitySDK_release_html = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/unitySDK_release.html"; - string watson_beats_jeopardy_html = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/watson_beats_jeopardy.html"; - string microformats_html = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/microformats.html"; - string ycombinator_html = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/ycombinator_news.html"; - //// Get Author URL POST - //if (!m_AlchemyAPI.GetAuthors(OnGetAuthors, m_ExampleURL_watsonJeopardy)) - // Log.Debug("ExampleAlchemyLanguage", "Failed to get authors URL POST!"); - - ////Get Author HTML POST - //if (!m_AlchemyAPI.GetAuthors(OnGetAuthors, watson_beats_jeopardy_html)) - // Log.Debug("ExampleAlchemyLanguage", "Failed to get authors HTML POST!"); - - ////Get Concepts Text POST - if (!m_AlchemyAPI.GetRankedConcepts(OnGetConcepts, m_ExampleText_watsonJeopardy)) - Log.Debug("ExampleAlchemyLanguage", "Failed to get concepts Text POST!"); - - ////Get Concepts HTML POST - //if (!m_AlchemyAPI.GetRankedConcepts(OnGetConcepts, watson_beats_jeopardy_html)) - // Log.Debug("ExampleAlchemyLanguage", "Failed to get concepts HTML POST!"); - - ////Get Concepts URL POST - //if (!m_AlchemyAPI.GetRankedConcepts(OnGetCzoncepts, m_ExampleURL_watsonJeopardy)) - // Log.Debug("ExampleAlchemyLanguage", "Failed to get concepts HTML POST!"); - - ////Get Date URL POST - //if (!m_AlchemyAPI.GetDates(OnGetDates, m_ExampleURL_watsonJeopardy)) - // Log.Debug("ExampleAlchemyLanguage", "Failed to get dates by URL POST"); - - ////Get Date Text POST - //if (!m_AlchemyAPI.GetDates(OnGetDates, m_ExampleText_watsonJeopardy)) - // Log.Debug("ExampleAlchemyLanguage", "Failed to get dates by text POST"); - - ////Get Date HTML POST - //if (!m_AlchemyAPI.GetDates(OnGetDates, watson_beats_jeopardy_html)) - // Log.Debug("ExampleAlchemyLanguage", "Failed to get dates by HTML POST"); - - ////Get Emotions URL POST - //if (!m_AlchemyAPI.GetEmotions(OnGetEmotions, m_ExampleURL_watsonJeopardy, true)) - // Log.Debug("ExampleAlchemyLanguage", "Failed to get emotions by URL POST"); - - ////Get Emotions Text POST - //if (!m_AlchemyAPI.GetEmotions(OnGetEmotions, m_ExampleText_watsonJeopardy, true)) - // Log.Debug("ExampleAlchemyLanguage", "Failed to get emotions by text POST"); - - ////Get Emotions HTML POST - //if (!m_AlchemyAPI.GetEmotions(OnGetEmotions, watson_beats_jeopardy_html, true)) - // Log.Debug("ExampleAlchemyLanguage", "Failed to get emotions by HTML POST"); - - ////Extract Entities URL POST - //if (!m_AlchemyAPI.ExtractEntities(OnExtractEntities, m_ExampleURL_watsonJeopardy)) - // Log.Debug("ExampleAlchemyLanguage", "Failed to get entities by URL POST"); - - ////Extract Entities Text POST - //if (!m_AlchemyAPI.ExtractEntities(OnExtractEntities, m_ExampleText_watsonJeopardy)) - // Log.Debug("ExampleAlchemyLanguage", "Failed to get entities by text POST"); - - ////Extract Entities HTML POST - //if (!m_AlchemyAPI.ExtractEntities(OnExtractEntities, watson_beats_jeopardy_html)) - // Log.Debug("ExampleAlchemyLanguage", "Failed to get entities by HTML POST"); - - ////Detect Feeds URL POST - //if (!m_AlchemyAPI.DetectFeeds(OnDetectFeeds, "http://time.com/newsfeed/")) - // Log.Debug("ExampleAlchemyLanguage", "Failed to get feeds by URL POST"); - - ////Detect Feeds HTML POST - ////if (!m_AlchemyAPI.DetectFeeds(OnDetectFeeds, ycombinator_html)) - //// Log.Debug("ExampleAlchemyLanguage", "Failed to get feeds by URL POST"); - - ////Extract Keywords URL POST - //if (!m_AlchemyAPI.ExtractKeywords(OnExtractKeywords, m_ExampleURL_watsonJeopardy)) - // Log.Debug("ExampleAlchemyLanguage", "Failed to get keywords by URL POST"); - - ////Extract Keywords Text POST - //if (!m_AlchemyAPI.ExtractKeywords(OnExtractKeywords, m_ExampleText_watsonJeopardy)) - // Log.Debug("ExampleAlchemyLanguage", "Failed to get keywords by text POST"); - - ////Extract Keywords HTML POST - //if (!m_AlchemyAPI.ExtractKeywords(OnExtractKeywords, watson_beats_jeopardy_html)) - // Log.Debug("ExampleAlchemyLanguage", "Failed to get keywords by HTML POST"); - - ////Extract Languages URL POST - //if (!m_AlchemyAPI.GetLanguages(OnGetLanguages, m_ExampleURL_watsonJeopardy)) - // Log.Debug("ExampleAlchemyLanguage", "Failed to get languages by text POST"); - - ////Extract Languages Text POST - //if (!m_AlchemyAPI.GetLanguages(OnGetLanguages, m_ExampleText_watsonJeopardy)) - // Log.Debug("ExampleAlchemyLanguage", "Failed to get languages by text POST"); - - ////Extract Languages HTML POST - //if (!m_AlchemyAPI.GetLanguages(OnGetLanguages, watson_beats_jeopardy_html)) - // Log.Debug("ExampleAlchemyLanguage", "Failed to get languages by HTML POST"); - - ////Get Microformats URL POST - //if (!m_AlchemyAPI.GetMicroformats(OnGetMicroformats, m_ExampleURL_microformats)) - // Log.Debug("ExampleAlchemyLanguage", "Failed to get microformats by text POST"); + private AlchemyAPI m_AlchemyAPI = new AlchemyAPI(); + private string m_ExampleURL_unitySDK = "https://developer.ibm.com/open/2016/01/21/introducing-watson-unity-sdk/"; + private string m_ExampleURL_watsonJeopardy = "http://www.nytimes.com/2011/02/17/science/17jeopardy-watson.html"; + private string m_ExampleURL_microformats = "http://microformats.org/wiki/hcard"; + private string m_ExampleText_unitySDK = "Game on! Introducing Watson Unity SDK, \nRICHARD LYLE / JANUARY 21, 2016 \nAfter several months of work we are happy to present the Watson Unity SDK, an SDK to enable the Unity community to access the Watson Developer Cloud and build a cognitive application in Unity.\n\nI’ve been involved in the game industry for 22+ years now, but I can tell you in all honestly working in the Watson Innovation Labs and on this project has been the highlight of my career. This SDK really represents the first phase in what we plan to bring to the community, which in the end will be a framework for building a full cognitive application.\n\nYou as a developer will find very simple C# service abstractions for accessing Dialog, Speech To Text, Text to Speech, Language Translation, and Natural Language Classification services. Additionally, we’ve implemented something we are calling a Widget, which has inputs and outputs and performs some basic function.\n\nThese widgets can be connected together to form a graph for the data that’s routed for a given cognitive application. The widgets will attempt to automatically connect to each other, or you as a developer can override that behavior and manually take control of the process. We’ve implemented widgets for all of the basic services and provide a couple of example applications showing how they can work together.\n\nWe plan to continue to expand and build on the Watson Unity SDK. We invite you to join us in contributing to and using the SDK, or by simply giving us your feedback. We’d love to have you on board for this ride!"; + private string m_ExampleText_watsonJeopardy = "Computer Wins on 'Jeopardy!': Trivial, It's Not\nBy JOHN MARKOFF\nYORKTOWN HEIGHTS, N.Y. — In the end, the humans on \"Jeopardy!\" surrendered meekly.\n\nFacing 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.\"\n\nThis article has been revised to reflect the following correction:\n\nCorrection: February 24, 2011\n\n\nAn article last Thursday about the I.B.M. computer Watson misidentified the academic field vindicated by Watson's besting of two human opponents on \"Jeopardy!\" It is artificial intelligence — not computer science, a broader field that includes artificial intelligence."; + void Start() + { + LogSystem.InstallDefaultReactors(); + string unitySDK_release_html = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/unitySDK_release.html"; + string watson_beats_jeopardy_html = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/watson_beats_jeopardy.html"; + string microformats_html = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/microformats.html"; + string ycombinator_html = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/ycombinator_news.html"; + //// Get Author URL POST + //if (!m_AlchemyAPI.GetAuthors(OnGetAuthors, m_ExampleURL_watsonJeopardy)) + // Log.Debug("ExampleAlchemyLanguage", "Failed to get authors URL POST!"); + + ////Get Author HTML POST + //if (!m_AlchemyAPI.GetAuthors(OnGetAuthors, watson_beats_jeopardy_html)) + // Log.Debug("ExampleAlchemyLanguage", "Failed to get authors HTML POST!"); + + ////Get Concepts Text POST + if (!m_AlchemyAPI.GetRankedConcepts(OnGetConcepts, m_ExampleText_watsonJeopardy)) + Log.Debug("ExampleAlchemyLanguage", "Failed to get concepts Text POST!"); + + ////Get Concepts HTML POST + //if (!m_AlchemyAPI.GetRankedConcepts(OnGetConcepts, watson_beats_jeopardy_html)) + // Log.Debug("ExampleAlchemyLanguage", "Failed to get concepts HTML POST!"); + + ////Get Concepts URL POST + //if (!m_AlchemyAPI.GetRankedConcepts(OnGetCzoncepts, m_ExampleURL_watsonJeopardy)) + // Log.Debug("ExampleAlchemyLanguage", "Failed to get concepts HTML POST!"); + + ////Get Date URL POST + //if (!m_AlchemyAPI.GetDates(OnGetDates, m_ExampleURL_watsonJeopardy)) + // Log.Debug("ExampleAlchemyLanguage", "Failed to get dates by URL POST"); + + ////Get Date Text POST + //if (!m_AlchemyAPI.GetDates(OnGetDates, m_ExampleText_watsonJeopardy)) + // Log.Debug("ExampleAlchemyLanguage", "Failed to get dates by text POST"); + + ////Get Date HTML POST + //if (!m_AlchemyAPI.GetDates(OnGetDates, watson_beats_jeopardy_html)) + // Log.Debug("ExampleAlchemyLanguage", "Failed to get dates by HTML POST"); + + ////Get Emotions URL POST + //if (!m_AlchemyAPI.GetEmotions(OnGetEmotions, m_ExampleURL_watsonJeopardy, true)) + // Log.Debug("ExampleAlchemyLanguage", "Failed to get emotions by URL POST"); + + ////Get Emotions Text POST + //if (!m_AlchemyAPI.GetEmotions(OnGetEmotions, m_ExampleText_watsonJeopardy, true)) + // Log.Debug("ExampleAlchemyLanguage", "Failed to get emotions by text POST"); + + ////Get Emotions HTML POST + //if (!m_AlchemyAPI.GetEmotions(OnGetEmotions, watson_beats_jeopardy_html, true)) + // Log.Debug("ExampleAlchemyLanguage", "Failed to get emotions by HTML POST"); + + ////Extract Entities URL POST + //if (!m_AlchemyAPI.ExtractEntities(OnExtractEntities, m_ExampleURL_watsonJeopardy)) + // Log.Debug("ExampleAlchemyLanguage", "Failed to get entities by URL POST"); + + ////Extract Entities Text POST + //if (!m_AlchemyAPI.ExtractEntities(OnExtractEntities, m_ExampleText_watsonJeopardy)) + // Log.Debug("ExampleAlchemyLanguage", "Failed to get entities by text POST"); + + ////Extract Entities HTML POST + //if (!m_AlchemyAPI.ExtractEntities(OnExtractEntities, watson_beats_jeopardy_html)) + // Log.Debug("ExampleAlchemyLanguage", "Failed to get entities by HTML POST"); + + ////Detect Feeds URL POST + //if (!m_AlchemyAPI.DetectFeeds(OnDetectFeeds, "http://time.com/newsfeed/")) + // Log.Debug("ExampleAlchemyLanguage", "Failed to get feeds by URL POST"); + + ////Detect Feeds HTML POST + ////if (!m_AlchemyAPI.DetectFeeds(OnDetectFeeds, ycombinator_html)) + //// Log.Debug("ExampleAlchemyLanguage", "Failed to get feeds by URL POST"); + + ////Extract Keywords URL POST + //if (!m_AlchemyAPI.ExtractKeywords(OnExtractKeywords, m_ExampleURL_watsonJeopardy)) + // Log.Debug("ExampleAlchemyLanguage", "Failed to get keywords by URL POST"); + + ////Extract Keywords Text POST + //if (!m_AlchemyAPI.ExtractKeywords(OnExtractKeywords, m_ExampleText_watsonJeopardy)) + // Log.Debug("ExampleAlchemyLanguage", "Failed to get keywords by text POST"); + + ////Extract Keywords HTML POST + //if (!m_AlchemyAPI.ExtractKeywords(OnExtractKeywords, watson_beats_jeopardy_html)) + // Log.Debug("ExampleAlchemyLanguage", "Failed to get keywords by HTML POST"); + + ////Extract Languages URL POST + //if (!m_AlchemyAPI.GetLanguages(OnGetLanguages, m_ExampleURL_watsonJeopardy)) + // Log.Debug("ExampleAlchemyLanguage", "Failed to get languages by text POST"); + + ////Extract Languages Text POST + //if (!m_AlchemyAPI.GetLanguages(OnGetLanguages, m_ExampleText_watsonJeopardy)) + // Log.Debug("ExampleAlchemyLanguage", "Failed to get languages by text POST"); + + ////Extract Languages HTML POST + //if (!m_AlchemyAPI.GetLanguages(OnGetLanguages, watson_beats_jeopardy_html)) + // Log.Debug("ExampleAlchemyLanguage", "Failed to get languages by HTML POST"); + + ////Get Microformats URL POST + //if (!m_AlchemyAPI.GetMicroformats(OnGetMicroformats, m_ExampleURL_microformats)) + // Log.Debug("ExampleAlchemyLanguage", "Failed to get microformats by text POST"); + + ////Get Microformats HTML POST + ////if (!m_AlchemyAPI.GetMicroformats(OnGetMicroformats, microformats_html)) + //// Log.Debug("ExampleAlchemyLanguage", "Failed to get microformats by text POST"); + + ////Get PublicationDate URL POST + //if (!m_AlchemyAPI.GetPublicationDate(OnGetPublicationDate, m_ExampleURL_watsonJeopardy)) + // Log.Debug("ExampleAlchemyLanguage", "Failed to get publication dates by url POST"); + + ////Get PublicationDate HTML POST + //if (!m_AlchemyAPI.GetPublicationDate(OnGetPublicationDate, watson_beats_jeopardy_html)) + // Log.Debug("ExampleAlchemyLanguage", "Failed to get publication dates by html POST"); - ////Get Microformats HTML POST - ////if (!m_AlchemyAPI.GetMicroformats(OnGetMicroformats, microformats_html)) - //// Log.Debug("ExampleAlchemyLanguage", "Failed to get microformats by text POST"); - - ////Get PublicationDate URL POST - //if (!m_AlchemyAPI.GetPublicationDate(OnGetPublicationDate, m_ExampleURL_watsonJeopardy)) - // Log.Debug("ExampleAlchemyLanguage", "Failed to get publication dates by url POST"); + ////Get Relations URL POST + //if (!m_AlchemyAPI.GetRelations(OnGetRelations, m_ExampleURL_watsonJeopardy)) + // Log.Debug("ExampleAlchemyLanguage", "Failed to get relations by text POST"); - ////Get PublicationDate HTML POST - //if (!m_AlchemyAPI.GetPublicationDate(OnGetPublicationDate, watson_beats_jeopardy_html)) - // Log.Debug("ExampleAlchemyLanguage", "Failed to get publication dates by html POST"); + ////Get Relations Text POST + //if (!m_AlchemyAPI.GetRelations(OnGetRelations, m_ExampleText_watsonJeopardy)) + // Log.Debug("ExampleAlchemyLanguage", "Failed to get relations by text POST"); - ////Get Relations URL POST - //if (!m_AlchemyAPI.GetRelations(OnGetRelations, m_ExampleURL_watsonJeopardy)) - // Log.Debug("ExampleAlchemyLanguage", "Failed to get relations by text POST"); + ////Get Relations HTML POST + //if (!m_AlchemyAPI.GetRelations(OnGetRelations, watson_beats_jeopardy_html)) + // Log.Debug("ExampleAlchemyLanguage", "Failed to get relations by HTML POST"); - ////Get Relations Text POST - //if (!m_AlchemyAPI.GetRelations(OnGetRelations, m_ExampleText_watsonJeopardy)) - // Log.Debug("ExampleAlchemyLanguage", "Failed to get relations by text POST"); + ////Get Sentiment URL POST + //if (!m_AlchemyAPI.GetTextSentiment(OnGetTextSentiment, m_ExampleURL_watsonJeopardy)) + // Log.Debug("ExampleAlchemyLanguage", "Failed to get sentiment by text POST"); - ////Get Relations HTML POST - //if (!m_AlchemyAPI.GetRelations(OnGetRelations, watson_beats_jeopardy_html)) - // Log.Debug("ExampleAlchemyLanguage", "Failed to get relations by HTML POST"); + ////Get Sentiment Text POST + //if (!m_AlchemyAPI.GetTextSentiment(OnGetTextSentiment, m_ExampleText_watsonJeopardy)) + // Log.Debug("ExampleAlchemyLanguage", "Failed to get sentiment by text POST"); - ////Get Sentiment URL POST - //if (!m_AlchemyAPI.GetTextSentiment(OnGetTextSentiment, m_ExampleURL_watsonJeopardy)) - // Log.Debug("ExampleAlchemyLanguage", "Failed to get sentiment by text POST"); + ////Get Sentiment HTML POST + //if (!m_AlchemyAPI.GetTextSentiment(OnGetTextSentiment, watson_beats_jeopardy_html)) + // Log.Debug("ExampleAlchemyLanguage", "Failed to get sentiment by HTML POST"); - ////Get Sentiment Text POST - //if (!m_AlchemyAPI.GetTextSentiment(OnGetTextSentiment, m_ExampleText_watsonJeopardy)) - // Log.Debug("ExampleAlchemyLanguage", "Failed to get sentiment by text POST"); + ////Get Targeted Sentiment URL POST + //if (!m_AlchemyAPI.GetTargetedSentiment(OnGetTargetedSentiment, m_ExampleURL_watsonJeopardy, "Jeopardy|Jennings|Watson")) + // Log.Debug("ExampleAlchemyLanguage", "Failed to get targeted sentiment by text POST"); - ////Get Sentiment HTML POST - //if (!m_AlchemyAPI.GetTextSentiment(OnGetTextSentiment, watson_beats_jeopardy_html)) - // Log.Debug("ExampleAlchemyLanguage", "Failed to get sentiment by HTML POST"); + ////Get Targeted Sentiment Text POST + //if (!m_AlchemyAPI.GetTargetedSentiment(OnGetTargetedSentiment, m_ExampleText_watsonJeopardy, "Jeopardy|Jennings|Watson")) + // Log.Debug("ExampleAlchemyLanguage", "Failed to get targeted sentiment by text POST"); - ////Get Targeted Sentiment URL POST - //if (!m_AlchemyAPI.GetTargetedSentiment(OnGetTargetedSentiment, m_ExampleURL_watsonJeopardy, "Jeopardy|Jennings|Watson")) - // Log.Debug("ExampleAlchemyLanguage", "Failed to get targeted sentiment by text POST"); + ////Get Targeted Sentiment HTML POST + //if (!m_AlchemyAPI.GetTargetedSentiment(OnGetTargetedSentiment, watson_beats_jeopardy_html, "Jeopardy|Jennings|Watson")) + // Log.Debug("ExampleAlchemyLanguage", "Failed to get targeted sentiment by HTML POST"); - ////Get Targeted Sentiment Text POST - //if (!m_AlchemyAPI.GetTargetedSentiment(OnGetTargetedSentiment, m_ExampleText_watsonJeopardy, "Jeopardy|Jennings|Watson")) - // Log.Debug("ExampleAlchemyLanguage", "Failed to get targeted sentiment by text POST"); - - ////Get Targeted Sentiment HTML POST - //if (!m_AlchemyAPI.GetTargetedSentiment(OnGetTargetedSentiment, watson_beats_jeopardy_html, "Jeopardy|Jennings|Watson")) - // Log.Debug("ExampleAlchemyLanguage", "Failed to get targeted sentiment by HTML POST"); - - ////Get Taxonomy URL POST - //if (!m_AlchemyAPI.GetRankedTaxonomy(OnGetRankedTaxonomy, m_ExampleURL_watsonJeopardy)) - // Log.Debug("ExampleAlchemyLanguage", "Failed to get ranked taxonomy by text POST"); - - ////Get Taxonomy Text POST - //if (!m_AlchemyAPI.GetRankedTaxonomy(OnGetRankedTaxonomy, m_ExampleText_watsonJeopardy)) - // Log.Debug("ExampleAlchemyLanguage", "Failed to get ranked taxonomy by text POST"); - - ////Get Taxonomy HTML POST - //if (!m_AlchemyAPI.GetRankedTaxonomy(OnGetRankedTaxonomy, watson_beats_jeopardy_html)) - // Log.Debug("ExampleAlchemyLanguage", "Failed to get ranked taxonomy by HTML POST"); - - ////Get Text HTML POST - //if (!m_AlchemyAPI.GetText(OnGetText, watson_beats_jeopardy_html)) - // Log.Debug("ExampleAlchemyLanguage", "Failed to get text by text POST"); - - ////Get Text URL POST - //if (!m_AlchemyAPI.GetText(OnGetText, m_ExampleURL_watsonJeopardy)) - // Log.Debug("ExampleAlchemyLanguage", "Failed to get text by text POST"); - - ////Get Raw Text HTML POST - //if (!m_AlchemyAPI.GetRawText(OnGetText, watson_beats_jeopardy_html)) - // Log.Debug("ExampleAlchemyLanguage", "Failed to get raw text by text POST"); - - ////Get Raw Text URL POST - //if (!m_AlchemyAPI.GetRawText(OnGetText, m_ExampleURL_watsonJeopardy)) - // Log.Debug("ExampleAlchemyLanguage", "Failed to get raw text by text POST"); - - ////Get Title HTML POST - //if (!m_AlchemyAPI.GetTitle(OnGetTitle, watson_beats_jeopardy_html)) - // Log.Debug("ExampleAlchemyLanguage", "Failed to get title by text POST"); - - ////Get Title URL POST - //if (!m_AlchemyAPI.GetTitle(OnGetTitle, m_ExampleURL_watsonJeopardy)) - // Log.Debug("ExampleAlchemyLanguage", "Failed to get title by text POST"); - - //// Get Combined Data URL POST - //if (!m_AlchemyAPI.GetCombinedData(OnGetCombinedData, m_ExampleURL_watsonJeopardy, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true)) - // Log.Debug("ExampleAlchemyLanguage", "Failed to get combined data by text POST"); - - ////Get Combined Data Text POST - //if (!m_AlchemyAPI.GetCombinedData(OnGetCombinedData, m_ExampleText_watsonJeopardy, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true)) - // Log.Debug("ExampleAlchemyLanguage", "Failed to get combined data by text POST"); - - ////Get Combined Data HTML POST - //if (!m_AlchemyAPI.GetCombinedData(OnGetCombinedData, watson_beats_jeopardy_html, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true)) - // Log.Debug("ExampleAlchemyLanguage", "Failed to get combined data by HTML POST"); - } - - private void OnGetAuthors(AuthorsData authors, string data) - { - if (authors != null) - { - Log.Debug("ExampleAlchemyLanguage", "data: {0}", data); - if (authors.authors.names.Length == 0) - Log.Debug("ExampleAlchemyLanguage", "No authors found!"); - - foreach (string name in authors.authors.names) - Log.Debug("ExampleAlchemyLanguage", "Author " + name + " found!"); - } - else - { - Log.Debug("ExampleAlchemyLanguage", "Failed to find Author!"); - } - } - - private void OnGetConcepts(ConceptsData concepts, string data) - { - if (concepts != null) - { - Log.Debug("ExampleAlchemyLanguage", "status: {0}", concepts.status); - Log.Debug("ExampleAlchemyLanguage", "url: {0}", concepts.url); - Log.Debug("ExampleAlchemyLanguage", "language: {0}", concepts.language); - if (concepts.concepts.Length == 0) - Log.Debug("ExampleAlchemyLanguage", "No concepts found!"); - - foreach (Concept concept in concepts.concepts) - Log.Debug("ExampleAlchemyLanguage", "Concept: {0}, Relevance: {1}", concept.text, concept.relevance); - } - else - { - Log.Debug("ExampleAlchemyLanguage", "Failed to find Concepts!"); - } - } - - private void OnGetDates(DateData dates, string data) - { - if (dates != null) - { - Log.Debug("ExampleAlchemyLanguage", "status: {0}", dates.status); - Log.Debug("ExampleAlchemyLanguage", "language: {0}", dates.language); - Log.Debug("ExampleAlchemyLanguage", "url: {0}", dates.url); - if (dates.dates == null || dates.dates.Length == 0) - Log.Debug("ExampleAlchemyLanguage", "No dates found!"); - else - foreach (Date date in dates.dates) - Log.Debug("ExampleAlchemyLanguage", "Text: {0}, Date: {1}", date.text, date.date); - } - else - { - Log.Debug("ExampleAlchemyLanguage", "Failed to find Dates!"); - } - } - - private void OnGetEmotions(EmotionData emotions, string data) - { - if (emotions != null) - { - Log.Debug("ExampleAlchemyLanguage", "status: {0}", emotions.status); - Log.Debug("ExampleAlchemyLanguage", "url: {0}", emotions.url); - Log.Debug("ExampleAlchemyLanguage", "language: {0}", emotions.language); - Log.Debug("ExampleAlchemyLanguage", "text: {0}", emotions.text); - if (emotions.docEmotions == null) - Log.Debug("ExampleAlchemyLanguage", "No emotions found!"); - else - { - Log.Debug("ExampleAlchemyLanguage", "anger: {0}", emotions.docEmotions.anger); - Log.Debug("ExampleAlchemyLanguage", "disgust: {0}", emotions.docEmotions.disgust); - Log.Debug("ExampleAlchemyLanguage", "fear: {0}", emotions.docEmotions.fear); - Log.Debug("ExampleAlchemyLanguage", "joy: {0}", emotions.docEmotions.joy); - Log.Debug("ExampleAlchemyLanguage", "sadness: {0}", emotions.docEmotions.sadness); - } - } - else - { - Log.Debug("ExampleAlchemyLanguage", "Failed to find Emotions!"); - } - } - - private void OnExtractEntities(EntityData entityData, string data) - { - if (entityData != null) - { - Log.Debug("ExampleAlchemyLanguage", "status: {0}", entityData.status); - Log.Debug("ExampleAlchemyLanguage", "url: {0}", entityData.url); - Log.Debug("ExampleAlchemyLanguage", "language: {0}", entityData.language); - Log.Debug("ExampleAlchemyLanguage", "text: {0}", entityData.text); - if (entityData == null || entityData.entities.Length == 0) - Log.Debug("ExampleAlchemyLanguage", "No entities found!"); - else - foreach (Entity entity in entityData.entities) - Log.Debug("ExampleAlchemyLanguage", "text: {0}, type: {1}", entity.text, entity.type); - } - else - { - Log.Debug("ExampleAlchemyLanguage", "Failed to find Emotions!"); - } - } - - private void OnDetectFeeds(FeedData feedData, string data) - { - if (feedData != null) - { - Log.Debug("ExampleAlchemyLanguage", "status: {0}", feedData.status); - if (feedData == null || feedData.feeds.Length == 0) - Log.Debug("ExampleAlchemyLanguage", "No feeds found!"); - else - foreach (Feed feed in feedData.feeds) - Log.Debug("ExampleAlchemyLanguage", "text: {0}", feed.feed); - } - else - { - Log.Debug("ExampleAlchemyLanguage", "Failed to find Feeds!"); - } - } - - private void OnExtractKeywords(KeywordData keywordData, string data) - { - if (keywordData != null) - { - Log.Debug("ExampleAlchemyLanguage", "status: {0}", keywordData.status); - Log.Debug("ExampleAlchemyLanguage", "url: {0}", keywordData.url); - Log.Debug("ExampleAlchemyLanguage", "language: {0}", keywordData.language); - Log.Debug("ExampleAlchemyLanguage", "text: {0}", keywordData.text); - if (keywordData == null || keywordData.keywords.Length == 0) - Log.Debug("ExampleAlchemyLanguage", "No keywords found!"); - else - foreach (Keyword keyword in keywordData.keywords) - Log.Debug("ExampleAlchemyLanguage", "text: {0}, relevance: {1}", keyword.text, keyword.relevance); - } - else - { - Log.Debug("ExampleAlchemyLanguage", "Failed to find Keywords!"); - } - } - - private void OnGetLanguages(LanguageData languages, string data) - { - if (languages != null) - { - if (string.IsNullOrEmpty(languages.language)) - Log.Debug("ExampleAlchemyLanguage", "No languages detected!"); - else - { - Log.Debug("ExampleAlchemyLanguage", "status: {0}", languages.status); - Log.Debug("ExampleAlchemyLanguage", "url: {0}", languages.url); - Log.Debug("ExampleAlchemyLanguage", "language: {0}", languages.language); - Log.Debug("ExampleAlchemyLanguage", "ethnologue: {0}", languages.ethnologue); - Log.Debug("ExampleAlchemyLanguage", "iso_639_1: {0}", languages.iso_639_1); - Log.Debug("ExampleAlchemyLanguage", "iso_639_2: {0}", languages.iso_639_2); - Log.Debug("ExampleAlchemyLanguage", "iso_639_3: {0}", languages.iso_639_3); - Log.Debug("ExampleAlchemyLanguage", "native_speakers: {0}", languages.native_speakers); - Log.Debug("ExampleAlchemyLanguage", "wikipedia: {0}", languages.wikipedia); - } - } - else - { - Log.Debug("ExampleAlchemyLanguage", "Failed to find Dates!"); - } - } - - private void OnGetMicroformats(MicroformatData microformats, string data) - { - if (microformats != null) - { - Log.Debug("ExampleAlchemyLanguage", "status: {0}", microformats.status); - Log.Debug("ExampleAlchemyLanguage", "url: {0}", microformats.url); - if (microformats.microformats.Length == 0) - Log.Warning("ExampleAlchemyLanguage", "No microformats found!"); - else - { - foreach (Microformat microformat in microformats.microformats) - Log.Debug("ExampleAlchemyLanguage", "field: {0}, data: {1}.", microformat.field, microformat.data); - } - } - else - { - Log.Debug("ExampleAlchemyLanguage", "Failed to find Microformats!"); - } - } - - private void OnGetPublicationDate(PubDateData pubDates, string data) - { - if (pubDates != null) - { - Log.Debug("ExampleAlchemyLanguage", "status: {0}", pubDates.status); - Log.Debug("ExampleAlchemyLanguage", "url: {0}", pubDates.url); - Log.Debug("ExampleAlchemyLanguage", "language: {0}", pubDates.language); - if (pubDates.publicationDate != null) - Log.Debug("ExampleAlchemyLanguage", "date: {0}, confident: {1}", pubDates.publicationDate.date, pubDates.publicationDate.confident); - else - Log.Debug("ExampleAlchemyLanguage", "Failed to find Publication Dates!"); - } - else - { - Log.Debug("ExampleAlchemyLanguage", "Failed to find Publication Dates!"); - } - } - - private void OnGetRelations(RelationsData relationsData, string data) - { - if (relationsData != null) - { - Log.Debug("ExampleAlchemyLanguage", "status: {0}", relationsData.status); - Log.Debug("ExampleAlchemyLanguage", "url: {0}", relationsData.url); - Log.Debug("ExampleAlchemyLanguage", "language: {0}", relationsData.language); - Log.Debug("ExampleAlchemyLanguage", "text: {0}", relationsData.text); - if (relationsData.relations == null || relationsData.relations.Length == 0) - Log.Debug("ExampleAlchemyLanguage", "No relations found!"); - else - foreach (Relation relation in relationsData.relations) - if (relation.subject != null && !string.IsNullOrEmpty(relation.subject.text)) - Log.Debug("ExampleAlchemyLanguage", "Text: {0}, Date: {1}", relation.sentence, relation.subject.text); - } - else - { - Log.Debug("ExampleAlchemyLanguage", "Failed to find Relations!"); - } - } - - private void OnGetTextSentiment(SentimentData sentimentData, string data) - { - if (sentimentData != null) - { - Log.Debug("ExampleAlchemyLanguage", "status: {0}", sentimentData.status); - Log.Debug("ExampleAlchemyLanguage", "url: {0}", sentimentData.url); - Log.Debug("ExampleAlchemyLanguage", "language: {0}", sentimentData.language); - Log.Debug("ExampleAlchemyLanguage", "text: {0}", sentimentData.text); - if (sentimentData.docSentiment == null) - Log.Debug("ExampleAlchemyLanguage", "No sentiment found!"); - else - if (sentimentData.docSentiment != null && !string.IsNullOrEmpty(sentimentData.docSentiment.type)) - Log.Debug("ExampleAlchemyLanguage", "Sentiment: {0}, Score: {1}", sentimentData.docSentiment.type, sentimentData.docSentiment.score); - } - else - { - Log.Debug("ExampleAlchemyLanguage", "Failed to find Relations!"); - } - } - - private void OnGetTargetedSentiment(TargetedSentimentData sentimentData, string data) - { - if (sentimentData != null) - { - Log.Debug("ExampleAlchemyLanguage", "status: {0}", sentimentData.status); - Log.Debug("ExampleAlchemyLanguage", "url: {0}", sentimentData.url); - Log.Debug("ExampleAlchemyLanguage", "language: {0}", sentimentData.language); - Log.Debug("ExampleAlchemyLanguage", "text: {0}", sentimentData.text); - if (sentimentData.results == null) - Log.Debug("ExampleAlchemyLanguage", "No sentiment found!"); - else - if (sentimentData.results == null || sentimentData.results.Length == 0) - Log.Warning("ExampleAlchemyLanguage", "No sentiment results!"); - else - foreach (TargetedSentiment result in sentimentData.results) - Log.Debug("ExampleAlchemyLanguage", "text: {0}, sentiment: {1}, score: {2}", result.text, result.sentiment.score, result.sentiment.type); - } - else - { - Log.Debug("ExampleAlchemyLanguage", "Failed to find Relations!"); - } - } - - private void OnGetRankedTaxonomy(TaxonomyData taxonomyData, string data) - { - if (taxonomyData != null) - { - Log.Debug("ExampleAlchemyLanguage", "status: {0}", taxonomyData.status); - Log.Debug("ExampleAlchemyLanguage", "url: {0}", taxonomyData.url); - Log.Debug("ExampleAlchemyLanguage", "language: {0}", taxonomyData.language); - Log.Debug("ExampleAlchemyLanguage", "text: {0}", taxonomyData.text); - if (taxonomyData.taxonomy == null) - Log.Debug("ExampleAlchemyLanguage", "No taxonomy found!"); - else - if (taxonomyData.taxonomy == null || taxonomyData.taxonomy.Length == 0) - Log.Warning("ExampleAlchemyLanguage", "No taxonomy results!"); - else - foreach (Taxonomy taxonomy in taxonomyData.taxonomy) - Log.Debug("ExampleAlchemyLanguage", "label: {0}, score: {1}", taxonomy.label, taxonomy.score); - } - else - { - Log.Debug("ExampleAlchemyLanguage", "Failed to find Relations!"); - } - } - - private void OnGetText(TextData textData, string data) - { - if (textData != null) - { - Log.Debug("ExampleAlchemyLanuguage", "status: {0}", textData.status); - Log.Debug("ExampleAlchemyLanuguage", "url: {0}", textData.url); - Log.Debug("ExampleAlchemyLanuguage", "text: {0}", textData.text); - } - else - { - Log.Debug("ExampleAlchemyLanguage", "Failed to find text!"); - } - - } - - private void OnGetTitle(Title titleData, string data) - { - if (titleData != null) - { - Log.Debug("ExampleAlchemyLanuguage", "status: {0}", titleData.status); - Log.Debug("ExampleAlchemyLanuguage", "url: {0}", titleData.url); - Log.Debug("ExampleAlchemyLanuguage", "text: {0}", titleData.title); - } - else - { - Log.Debug("ExampleAlchemyLanguage", "Failed to find title!"); - } - - } - - private void OnGetCombinedData(CombinedCallData combinedData, string data) - { - if (combinedData != null) - { - Log.Debug("ExampleAlchemyLanguage", "status: {0}", combinedData.status); - Log.Debug("ExampleAlchemyLanguage", "url: {0}", combinedData.url); - Log.Debug("ExampleAlchemyLanguage", "language: {0}", combinedData.language); - Log.Debug("ExampleAlchemyLanguage", "text: {0}", combinedData.text); - Log.Debug("ExampleAlchemyLanguage", "image: {0}", combinedData.image); - - if (combinedData.imageKeywords != null && combinedData.imageKeywords.Length > 0) - foreach (ImageKeyword imageKeyword in combinedData.imageKeywords) - Log.Debug("ExampleAlchemyLanguage", "ImageKeyword: {0}, Score: {1}", imageKeyword.text, imageKeyword.score); - - if (combinedData.publicationDate != null) - Log.Debug("ExampleAlchemyLanguage", "publicationDate: {0}, Score: {1}", combinedData.publicationDate.date, combinedData.publicationDate.confident); - - if (combinedData.authors != null && combinedData.authors.names.Length > 0) - foreach (string authors in combinedData.authors.names) - Log.Debug("ExampleAlchemyLanguage", "Authors: {0}", authors); - - if (combinedData.docSentiment != null) - Log.Debug("ExampleAlchemyLanguage", "DocSentiment: {0}, Score: {1}, Mixed: {2}", combinedData.docSentiment.type, combinedData.docSentiment.score, combinedData.docSentiment.mixed); - - if (combinedData.feeds != null && combinedData.feeds.Length > 0) - foreach (Feed feed in combinedData.feeds) - Log.Debug("ExampleAlchemyLanguage", "Feeds: {0}", feed.feed); - - if (combinedData.keywords != null && combinedData.keywords.Length > 0) - foreach (Keyword keyword in combinedData.keywords) - Log.Debug("ExampleAlchemyLanguage", "Keyword: {0}, relevance: {1}", keyword.text, keyword.relevance); - - if (combinedData.concepts != null && combinedData.concepts.Length > 0) - foreach (Concept concept in combinedData.concepts) - Log.Debug("ExampleAlchemyLanguage", "Concept: {0}, Relevance: {1}", concept.text, concept.relevance); - - if (combinedData.entities != null && combinedData.entities.Length > 0) - foreach (Entity entity in combinedData.entities) - Log.Debug("ExampleAlchemyLanguage", "Entity: {0}, Type: {1}, Relevance: {2}", entity.text, entity.type, entity.relevance); - - if (combinedData.relations != null && combinedData.relations.Length > 0) - foreach (Relation relation in combinedData.relations) - Log.Debug("ExampleAlchemyLanguage", "Relations: {0}", relation.subject.text); - - if (combinedData.taxonomy != null && combinedData.taxonomy.Length > 0) - foreach (Taxonomy taxonomy in combinedData.taxonomy) - Log.Debug("ExampleAlchemyLanguage", "Taxonomy: {0}, Score: {1}, Confident: {2}", taxonomy.label, taxonomy.score, taxonomy.confident); - - if (combinedData.dates != null && combinedData.dates.Length > 0) - foreach (Date date in combinedData.dates) - Log.Debug("ExampleAlchemyLanguage", "Dates", date.text, date.date); - - if (combinedData.docEmotions != null && combinedData.docEmotions.Length > 0) - foreach (DocEmotions emotions in combinedData.docEmotions) - Log.Debug("ExampleAlchemyLanguage", "Doc Emotions: anger: {0}, disgust: {1}, fear: {2}, joy: {3}, sadness: {4}", emotions.anger, emotions.disgust, emotions.fear, emotions.joy, emotions.sadness); - } - else - { - Log.Debug("ExampleAlchemyLanguage", "Failed to get combined data!"); - } + ////Get Taxonomy URL POST + //if (!m_AlchemyAPI.GetRankedTaxonomy(OnGetRankedTaxonomy, m_ExampleURL_watsonJeopardy)) + // Log.Debug("ExampleAlchemyLanguage", "Failed to get ranked taxonomy by text POST"); + + ////Get Taxonomy Text POST + //if (!m_AlchemyAPI.GetRankedTaxonomy(OnGetRankedTaxonomy, m_ExampleText_watsonJeopardy)) + // Log.Debug("ExampleAlchemyLanguage", "Failed to get ranked taxonomy by text POST"); + + ////Get Taxonomy HTML POST + //if (!m_AlchemyAPI.GetRankedTaxonomy(OnGetRankedTaxonomy, watson_beats_jeopardy_html)) + // Log.Debug("ExampleAlchemyLanguage", "Failed to get ranked taxonomy by HTML POST"); + + ////Get Text HTML POST + //if (!m_AlchemyAPI.GetText(OnGetText, watson_beats_jeopardy_html)) + // Log.Debug("ExampleAlchemyLanguage", "Failed to get text by text POST"); + + ////Get Text URL POST + //if (!m_AlchemyAPI.GetText(OnGetText, m_ExampleURL_watsonJeopardy)) + // Log.Debug("ExampleAlchemyLanguage", "Failed to get text by text POST"); + + ////Get Raw Text HTML POST + //if (!m_AlchemyAPI.GetRawText(OnGetText, watson_beats_jeopardy_html)) + // Log.Debug("ExampleAlchemyLanguage", "Failed to get raw text by text POST"); + + ////Get Raw Text URL POST + //if (!m_AlchemyAPI.GetRawText(OnGetText, m_ExampleURL_watsonJeopardy)) + // Log.Debug("ExampleAlchemyLanguage", "Failed to get raw text by text POST"); + + ////Get Title HTML POST + //if (!m_AlchemyAPI.GetTitle(OnGetTitle, watson_beats_jeopardy_html)) + // Log.Debug("ExampleAlchemyLanguage", "Failed to get title by text POST"); + + ////Get Title URL POST + //if (!m_AlchemyAPI.GetTitle(OnGetTitle, m_ExampleURL_watsonJeopardy)) + // Log.Debug("ExampleAlchemyLanguage", "Failed to get title by text POST"); + + //// Get Combined Data URL POST + //if (!m_AlchemyAPI.GetCombinedData(OnGetCombinedData, m_ExampleURL_watsonJeopardy, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true)) + // Log.Debug("ExampleAlchemyLanguage", "Failed to get combined data by text POST"); + + ////Get Combined Data Text POST + //if (!m_AlchemyAPI.GetCombinedData(OnGetCombinedData, m_ExampleText_watsonJeopardy, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true)) + // Log.Debug("ExampleAlchemyLanguage", "Failed to get combined data by text POST"); + + ////Get Combined Data HTML POST + //if (!m_AlchemyAPI.GetCombinedData(OnGetCombinedData, watson_beats_jeopardy_html, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true)) + // Log.Debug("ExampleAlchemyLanguage", "Failed to get combined data by HTML POST"); + } + + private void OnGetAuthors(AuthorsData authors, string data) + { + if (authors != null) + { + Log.Debug("ExampleAlchemyLanguage", "data: {0}", data); + if (authors.authors.names.Length == 0) + Log.Debug("ExampleAlchemyLanguage", "No authors found!"); + + foreach (string name in authors.authors.names) + Log.Debug("ExampleAlchemyLanguage", "Author " + name + " found!"); + } + else + { + Log.Debug("ExampleAlchemyLanguage", "Failed to find Author!"); + } + } + + private void OnGetConcepts(ConceptsData concepts, string data) + { + if (concepts != null) + { + Log.Debug("ExampleAlchemyLanguage", "status: {0}", concepts.status); + Log.Debug("ExampleAlchemyLanguage", "url: {0}", concepts.url); + Log.Debug("ExampleAlchemyLanguage", "language: {0}", concepts.language); + if (concepts.concepts.Length == 0) + Log.Debug("ExampleAlchemyLanguage", "No concepts found!"); + + foreach (Concept concept in concepts.concepts) + Log.Debug("ExampleAlchemyLanguage", "Concept: {0}, Relevance: {1}", concept.text, concept.relevance); + } + else + { + Log.Debug("ExampleAlchemyLanguage", "Failed to find Concepts!"); + } + } + + private void OnGetDates(DateData dates, string data) + { + if (dates != null) + { + Log.Debug("ExampleAlchemyLanguage", "status: {0}", dates.status); + Log.Debug("ExampleAlchemyLanguage", "language: {0}", dates.language); + Log.Debug("ExampleAlchemyLanguage", "url: {0}", dates.url); + if (dates.dates == null || dates.dates.Length == 0) + Log.Debug("ExampleAlchemyLanguage", "No dates found!"); + else + foreach (Date date in dates.dates) + Log.Debug("ExampleAlchemyLanguage", "Text: {0}, Date: {1}", date.text, date.date); + } + else + { + Log.Debug("ExampleAlchemyLanguage", "Failed to find Dates!"); + } + } + + private void OnGetEmotions(EmotionData emotions, string data) + { + if (emotions != null) + { + Log.Debug("ExampleAlchemyLanguage", "status: {0}", emotions.status); + Log.Debug("ExampleAlchemyLanguage", "url: {0}", emotions.url); + Log.Debug("ExampleAlchemyLanguage", "language: {0}", emotions.language); + Log.Debug("ExampleAlchemyLanguage", "text: {0}", emotions.text); + if (emotions.docEmotions == null) + Log.Debug("ExampleAlchemyLanguage", "No emotions found!"); + else + { + Log.Debug("ExampleAlchemyLanguage", "anger: {0}", emotions.docEmotions.anger); + Log.Debug("ExampleAlchemyLanguage", "disgust: {0}", emotions.docEmotions.disgust); + Log.Debug("ExampleAlchemyLanguage", "fear: {0}", emotions.docEmotions.fear); + Log.Debug("ExampleAlchemyLanguage", "joy: {0}", emotions.docEmotions.joy); + Log.Debug("ExampleAlchemyLanguage", "sadness: {0}", emotions.docEmotions.sadness); + } + } + else + { + Log.Debug("ExampleAlchemyLanguage", "Failed to find Emotions!"); + } + } + + private void OnExtractEntities(EntityData entityData, string data) + { + if (entityData != null) + { + Log.Debug("ExampleAlchemyLanguage", "status: {0}", entityData.status); + Log.Debug("ExampleAlchemyLanguage", "url: {0}", entityData.url); + Log.Debug("ExampleAlchemyLanguage", "language: {0}", entityData.language); + Log.Debug("ExampleAlchemyLanguage", "text: {0}", entityData.text); + if (entityData == null || entityData.entities.Length == 0) + Log.Debug("ExampleAlchemyLanguage", "No entities found!"); + else + foreach (Entity entity in entityData.entities) + Log.Debug("ExampleAlchemyLanguage", "text: {0}, type: {1}", entity.text, entity.type); + } + else + { + Log.Debug("ExampleAlchemyLanguage", "Failed to find Emotions!"); + } + } + + private void OnDetectFeeds(FeedData feedData, string data) + { + if (feedData != null) + { + Log.Debug("ExampleAlchemyLanguage", "status: {0}", feedData.status); + if (feedData == null || feedData.feeds.Length == 0) + Log.Debug("ExampleAlchemyLanguage", "No feeds found!"); + else + foreach (Feed feed in feedData.feeds) + Log.Debug("ExampleAlchemyLanguage", "text: {0}", feed.feed); + } + else + { + Log.Debug("ExampleAlchemyLanguage", "Failed to find Feeds!"); + } + } + + private void OnExtractKeywords(KeywordData keywordData, string data) + { + if (keywordData != null) + { + Log.Debug("ExampleAlchemyLanguage", "status: {0}", keywordData.status); + Log.Debug("ExampleAlchemyLanguage", "url: {0}", keywordData.url); + Log.Debug("ExampleAlchemyLanguage", "language: {0}", keywordData.language); + Log.Debug("ExampleAlchemyLanguage", "text: {0}", keywordData.text); + if (keywordData == null || keywordData.keywords.Length == 0) + Log.Debug("ExampleAlchemyLanguage", "No keywords found!"); + else + foreach (Keyword keyword in keywordData.keywords) + Log.Debug("ExampleAlchemyLanguage", "text: {0}, relevance: {1}", keyword.text, keyword.relevance); + } + else + { + Log.Debug("ExampleAlchemyLanguage", "Failed to find Keywords!"); + } + } + + private void OnGetLanguages(LanguageData languages, string data) + { + if (languages != null) + { + if (string.IsNullOrEmpty(languages.language)) + Log.Debug("ExampleAlchemyLanguage", "No languages detected!"); + else + { + Log.Debug("ExampleAlchemyLanguage", "status: {0}", languages.status); + Log.Debug("ExampleAlchemyLanguage", "url: {0}", languages.url); + Log.Debug("ExampleAlchemyLanguage", "language: {0}", languages.language); + Log.Debug("ExampleAlchemyLanguage", "ethnologue: {0}", languages.ethnologue); + Log.Debug("ExampleAlchemyLanguage", "iso_639_1: {0}", languages.iso_639_1); + Log.Debug("ExampleAlchemyLanguage", "iso_639_2: {0}", languages.iso_639_2); + Log.Debug("ExampleAlchemyLanguage", "iso_639_3: {0}", languages.iso_639_3); + Log.Debug("ExampleAlchemyLanguage", "native_speakers: {0}", languages.native_speakers); + Log.Debug("ExampleAlchemyLanguage", "wikipedia: {0}", languages.wikipedia); + } + } + else + { + Log.Debug("ExampleAlchemyLanguage", "Failed to find Dates!"); + } + } + + private void OnGetMicroformats(MicroformatData microformats, string data) + { + if (microformats != null) + { + Log.Debug("ExampleAlchemyLanguage", "status: {0}", microformats.status); + Log.Debug("ExampleAlchemyLanguage", "url: {0}", microformats.url); + if (microformats.microformats.Length == 0) + Log.Warning("ExampleAlchemyLanguage", "No microformats found!"); + else + { + foreach (Microformat microformat in microformats.microformats) + Log.Debug("ExampleAlchemyLanguage", "field: {0}, data: {1}.", microformat.field, microformat.data); + } + } + else + { + Log.Debug("ExampleAlchemyLanguage", "Failed to find Microformats!"); + } + } + + private void OnGetPublicationDate(PubDateData pubDates, string data) + { + if (pubDates != null) + { + Log.Debug("ExampleAlchemyLanguage", "status: {0}", pubDates.status); + Log.Debug("ExampleAlchemyLanguage", "url: {0}", pubDates.url); + Log.Debug("ExampleAlchemyLanguage", "language: {0}", pubDates.language); + if (pubDates.publicationDate != null) + Log.Debug("ExampleAlchemyLanguage", "date: {0}, confident: {1}", pubDates.publicationDate.date, pubDates.publicationDate.confident); + else + Log.Debug("ExampleAlchemyLanguage", "Failed to find Publication Dates!"); + } + else + { + Log.Debug("ExampleAlchemyLanguage", "Failed to find Publication Dates!"); + } + } + + private void OnGetRelations(RelationsData relationsData, string data) + { + if (relationsData != null) + { + Log.Debug("ExampleAlchemyLanguage", "status: {0}", relationsData.status); + Log.Debug("ExampleAlchemyLanguage", "url: {0}", relationsData.url); + Log.Debug("ExampleAlchemyLanguage", "language: {0}", relationsData.language); + Log.Debug("ExampleAlchemyLanguage", "text: {0}", relationsData.text); + if (relationsData.relations == null || relationsData.relations.Length == 0) + Log.Debug("ExampleAlchemyLanguage", "No relations found!"); + else + foreach (Relation relation in relationsData.relations) + if (relation.subject != null && !string.IsNullOrEmpty(relation.subject.text)) + Log.Debug("ExampleAlchemyLanguage", "Text: {0}, Date: {1}", relation.sentence, relation.subject.text); + } + else + { + Log.Debug("ExampleAlchemyLanguage", "Failed to find Relations!"); + } + } + + private void OnGetTextSentiment(SentimentData sentimentData, string data) + { + if (sentimentData != null) + { + Log.Debug("ExampleAlchemyLanguage", "status: {0}", sentimentData.status); + Log.Debug("ExampleAlchemyLanguage", "url: {0}", sentimentData.url); + Log.Debug("ExampleAlchemyLanguage", "language: {0}", sentimentData.language); + Log.Debug("ExampleAlchemyLanguage", "text: {0}", sentimentData.text); + if (sentimentData.docSentiment == null) + Log.Debug("ExampleAlchemyLanguage", "No sentiment found!"); + else + if (sentimentData.docSentiment != null && !string.IsNullOrEmpty(sentimentData.docSentiment.type)) + Log.Debug("ExampleAlchemyLanguage", "Sentiment: {0}, Score: {1}", sentimentData.docSentiment.type, sentimentData.docSentiment.score); + } + else + { + Log.Debug("ExampleAlchemyLanguage", "Failed to find Relations!"); + } + } + + private void OnGetTargetedSentiment(TargetedSentimentData sentimentData, string data) + { + if (sentimentData != null) + { + Log.Debug("ExampleAlchemyLanguage", "status: {0}", sentimentData.status); + Log.Debug("ExampleAlchemyLanguage", "url: {0}", sentimentData.url); + Log.Debug("ExampleAlchemyLanguage", "language: {0}", sentimentData.language); + Log.Debug("ExampleAlchemyLanguage", "text: {0}", sentimentData.text); + if (sentimentData.results == null) + Log.Debug("ExampleAlchemyLanguage", "No sentiment found!"); + else + if (sentimentData.results == null || sentimentData.results.Length == 0) + Log.Warning("ExampleAlchemyLanguage", "No sentiment results!"); + else + foreach (TargetedSentiment result in sentimentData.results) + Log.Debug("ExampleAlchemyLanguage", "text: {0}, sentiment: {1}, score: {2}", result.text, result.sentiment.score, result.sentiment.type); + } + else + { + Log.Debug("ExampleAlchemyLanguage", "Failed to find Relations!"); + } + } + + private void OnGetRankedTaxonomy(TaxonomyData taxonomyData, string data) + { + if (taxonomyData != null) + { + Log.Debug("ExampleAlchemyLanguage", "status: {0}", taxonomyData.status); + Log.Debug("ExampleAlchemyLanguage", "url: {0}", taxonomyData.url); + Log.Debug("ExampleAlchemyLanguage", "language: {0}", taxonomyData.language); + Log.Debug("ExampleAlchemyLanguage", "text: {0}", taxonomyData.text); + if (taxonomyData.taxonomy == null) + Log.Debug("ExampleAlchemyLanguage", "No taxonomy found!"); + else + if (taxonomyData.taxonomy == null || taxonomyData.taxonomy.Length == 0) + Log.Warning("ExampleAlchemyLanguage", "No taxonomy results!"); + else + foreach (Taxonomy taxonomy in taxonomyData.taxonomy) + Log.Debug("ExampleAlchemyLanguage", "label: {0}, score: {1}", taxonomy.label, taxonomy.score); + } + else + { + Log.Debug("ExampleAlchemyLanguage", "Failed to find Relations!"); + } + } + + private void OnGetText(TextData textData, string data) + { + if (textData != null) + { + Log.Debug("ExampleAlchemyLanuguage", "status: {0}", textData.status); + Log.Debug("ExampleAlchemyLanuguage", "url: {0}", textData.url); + Log.Debug("ExampleAlchemyLanuguage", "text: {0}", textData.text); + } + else + { + Log.Debug("ExampleAlchemyLanguage", "Failed to find text!"); + } + + } + + private void OnGetTitle(Title titleData, string data) + { + if (titleData != null) + { + Log.Debug("ExampleAlchemyLanuguage", "status: {0}", titleData.status); + Log.Debug("ExampleAlchemyLanuguage", "url: {0}", titleData.url); + Log.Debug("ExampleAlchemyLanuguage", "text: {0}", titleData.title); + } + else + { + Log.Debug("ExampleAlchemyLanguage", "Failed to find title!"); + } + + } + + private void OnGetCombinedData(CombinedCallData combinedData, string data) + { + if (combinedData != null) + { + Log.Debug("ExampleAlchemyLanguage", "status: {0}", combinedData.status); + Log.Debug("ExampleAlchemyLanguage", "url: {0}", combinedData.url); + Log.Debug("ExampleAlchemyLanguage", "language: {0}", combinedData.language); + Log.Debug("ExampleAlchemyLanguage", "text: {0}", combinedData.text); + Log.Debug("ExampleAlchemyLanguage", "image: {0}", combinedData.image); + + if (combinedData.imageKeywords != null && combinedData.imageKeywords.Length > 0) + foreach (ImageKeyword imageKeyword in combinedData.imageKeywords) + Log.Debug("ExampleAlchemyLanguage", "ImageKeyword: {0}, Score: {1}", imageKeyword.text, imageKeyword.score); + + if (combinedData.publicationDate != null) + Log.Debug("ExampleAlchemyLanguage", "publicationDate: {0}, Score: {1}", combinedData.publicationDate.date, combinedData.publicationDate.confident); + + if (combinedData.authors != null && combinedData.authors.names.Length > 0) + foreach (string authors in combinedData.authors.names) + Log.Debug("ExampleAlchemyLanguage", "Authors: {0}", authors); + + if (combinedData.docSentiment != null) + Log.Debug("ExampleAlchemyLanguage", "DocSentiment: {0}, Score: {1}, Mixed: {2}", combinedData.docSentiment.type, combinedData.docSentiment.score, combinedData.docSentiment.mixed); + + if (combinedData.feeds != null && combinedData.feeds.Length > 0) + foreach (Feed feed in combinedData.feeds) + Log.Debug("ExampleAlchemyLanguage", "Feeds: {0}", feed.feed); + + if (combinedData.keywords != null && combinedData.keywords.Length > 0) + foreach (Keyword keyword in combinedData.keywords) + Log.Debug("ExampleAlchemyLanguage", "Keyword: {0}, relevance: {1}", keyword.text, keyword.relevance); + + if (combinedData.concepts != null && combinedData.concepts.Length > 0) + foreach (Concept concept in combinedData.concepts) + Log.Debug("ExampleAlchemyLanguage", "Concept: {0}, Relevance: {1}", concept.text, concept.relevance); + + if (combinedData.entities != null && combinedData.entities.Length > 0) + foreach (Entity entity in combinedData.entities) + Log.Debug("ExampleAlchemyLanguage", "Entity: {0}, Type: {1}, Relevance: {2}", entity.text, entity.type, entity.relevance); + + if (combinedData.relations != null && combinedData.relations.Length > 0) + foreach (Relation relation in combinedData.relations) + Log.Debug("ExampleAlchemyLanguage", "Relations: {0}", relation.subject.text); + + if (combinedData.taxonomy != null && combinedData.taxonomy.Length > 0) + foreach (Taxonomy taxonomy in combinedData.taxonomy) + Log.Debug("ExampleAlchemyLanguage", "Taxonomy: {0}, Score: {1}, Confident: {2}", taxonomy.label, taxonomy.score, taxonomy.confident); + + if (combinedData.dates != null && combinedData.dates.Length > 0) + foreach (Date date in combinedData.dates) + Log.Debug("ExampleAlchemyLanguage", "Dates", date.text, date.date); + + if (combinedData.docEmotions != null && combinedData.docEmotions.Length > 0) + foreach (DocEmotions emotions in combinedData.docEmotions) + Log.Debug("ExampleAlchemyLanguage", "Doc Emotions: anger: {0}, disgust: {1}, fear: {2}, joy: {3}, sadness: {4}", emotions.anger, emotions.disgust, emotions.fear, emotions.joy, emotions.sadness); + } + else + { + Log.Debug("ExampleAlchemyLanguage", "Failed to get combined data!"); } + } } diff --git a/Examples/ServiceExamples/Scripts/ExampleConversation.cs b/Examples/ServiceExamples/Scripts/ExampleConversation.cs index 00c5cf156..307075f0a 100755 --- a/Examples/ServiceExamples/Scripts/ExampleConversation.cs +++ b/Examples/ServiceExamples/Scripts/ExampleConversation.cs @@ -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); + } } diff --git a/Examples/ServiceExamples/Scripts/ExampleConversationExperimental.cs b/Examples/ServiceExamples/Scripts/ExampleConversationExperimental.cs index 5bb64d1e2..a5fc5bcc1 100755 --- a/Examples/ServiceExamples/Scripts/ExampleConversationExperimental.cs +++ b/Examples/ServiceExamples/Scripts/ExampleConversationExperimental.cs @@ -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();"); + } + } } diff --git a/Examples/ServiceExamples/Scripts/ExampleDocumentConversion.cs b/Examples/ServiceExamples/Scripts/ExampleDocumentConversion.cs index edbd21852..a385cdc44 100755 --- a/Examples/ServiceExamples/Scripts/ExampleDocumentConversion.cs +++ b/Examples/ServiceExamples/Scripts/ExampleDocumentConversion.cs @@ -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); } + } } diff --git a/Examples/ServiceExamples/Scripts/ExampleLanguageTranslation.cs b/Examples/ServiceExamples/Scripts/ExampleLanguageTranslation.cs old mode 100644 new mode 100755 index 408afb152..7b3d3754b --- a/Examples/ServiceExamples/Scripts/ExampleLanguageTranslation.cs +++ b/Examples/ServiceExamples/Scripts/ExampleLanguageTranslation.cs @@ -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); + } } diff --git a/Examples/ServiceExamples/Scripts/ExampleLanguageTranslator.cs b/Examples/ServiceExamples/Scripts/ExampleLanguageTranslator.cs old mode 100644 new mode 100755 index 562a4a423..47d420eed --- a/Examples/ServiceExamples/Scripts/ExampleLanguageTranslator.cs +++ b/Examples/ServiceExamples/Scripts/ExampleLanguageTranslator.cs @@ -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); + } } diff --git a/Examples/ServiceExamples/Scripts/ExampleNaturalLanguageClassifier.cs b/Examples/ServiceExamples/Scripts/ExampleNaturalLanguageClassifier.cs old mode 100644 new mode 100755 index 0ff4dabcf..73d8f12cf --- a/Examples/ServiceExamples/Scripts/ExampleNaturalLanguageClassifier.cs +++ b/Examples/ServiceExamples/Scripts/ExampleNaturalLanguageClassifier.cs @@ -20,21 +20,21 @@ public class ExampleNaturalLanguageClassifier : MonoBehaviour { - private NaturalLanguageClassifier m_NaturalLanguageClassifier = new NaturalLanguageClassifier(); - private string m_ClassifierId = "3a84d1x62-nlc-768"; - private string m_InputString = "Is it hot outside?"; + private NaturalLanguageClassifier m_NaturalLanguageClassifier = new NaturalLanguageClassifier(); + private string m_ClassifierId = "3a84d1x62-nlc-768"; + private string m_InputString = "Is it hot outside?"; - void Start () - { - Debug.Log("Input String: " + m_InputString); - m_NaturalLanguageClassifier.Classify(m_ClassifierId, m_InputString, OnClassify); - } + void Start() + { + Debug.Log("Input String: " + m_InputString); + m_NaturalLanguageClassifier.Classify(m_ClassifierId, m_InputString, OnClassify); + } - private void OnClassify(ClassifyResult result) - { - if (result != null) - { - Debug.Log("Classify Result: " + result.top_class); - } - } + private void OnClassify(ClassifyResult result) + { + if (result != null) + { + Debug.Log("Classify Result: " + result.top_class); + } + } } diff --git a/Examples/ServiceExamples/Scripts/ExamplePersonalityInsights.cs b/Examples/ServiceExamples/Scripts/ExamplePersonalityInsights.cs deleted file mode 100755 index ef83935b1..000000000 --- a/Examples/ServiceExamples/Scripts/ExamplePersonalityInsights.cs +++ /dev/null @@ -1,82 +0,0 @@ -/** -* 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.v2; -using IBM.Watson.DeveloperCloud.Logging; - -public class ExamplePersonalityInsights : MonoBehaviour { - PersonalityInsights m_personalityInsights = new PersonalityInsights(); - - void Start () - { - LogSystem.InstallDefaultReactors(); - string dataPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/personalityInsights.json"; - - if(!m_personalityInsights.GetProfile(OnGetProfile, dataPath, ContentType.TEXT_PLAIN, Language.ENGLISH)) - Log.Debug("ExamplePersonalityInsights", "Failed to get profile!"); - } - - private void OnGetProfile(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(profile.tree != null) - { - LogTraitTree(profile.tree); - } - } - else - { - Log.Debug("ExamplePersonalityInsights", "Failed to get profile!"); - } - } - - private void LogTraitTree(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(TraitTreeNode childNode in traitTreeNode.children) - LogTraitTree(childNode); - } -} diff --git a/Examples/ServiceExamples/Scripts/ExamplePersonalityInsightsV2.cs b/Examples/ServiceExamples/Scripts/ExamplePersonalityInsightsV2.cs new file mode 100755 index 000000000..89ca1fc10 --- /dev/null +++ b/Examples/ServiceExamples/Scripts/ExamplePersonalityInsightsV2.cs @@ -0,0 +1,82 @@ +/** +* 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.v2; +using IBM.Watson.DeveloperCloud.Logging; + +public class ExamplePersonalityInsightsV2 : MonoBehaviour +{ + PersonalityInsights m_personalityInsights = new PersonalityInsights(); + + void Start() + { + LogSystem.InstallDefaultReactors(); + string dataPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/personalityInsights.json"; + + if (!m_personalityInsights.GetProfile(OnGetProfile, dataPath, ContentType.TEXT_PLAIN, Language.ENGLISH)) + Log.Debug("ExamplePersonalityInsights", "Failed to get profile!"); + } + + private void OnGetProfile(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 (profile.tree != null) + { + LogTraitTree(profile.tree); + } + } + else + { + Log.Debug("ExamplePersonalityInsights", "Failed to get profile!"); + } + } + + private void LogTraitTree(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 (TraitTreeNode childNode in traitTreeNode.children) + LogTraitTree(childNode); + } +} 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 100755 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/Scripts/ExampleRetrieveAndRank.cs b/Examples/ServiceExamples/Scripts/ExampleRetrieveAndRank.cs index 4f3111225..5d2a6ef2b 100755 --- a/Examples/ServiceExamples/Scripts/ExampleRetrieveAndRank.cs +++ b/Examples/ServiceExamples/Scripts/ExampleRetrieveAndRank.cs @@ -28,446 +28,446 @@ #pragma warning disable 219 public class ExampleRetrieveAndRank : MonoBehaviour { - private RetrieveAndRank m_RetrieveAndRank = new RetrieveAndRank(); - - void Start() + private RetrieveAndRank m_RetrieveAndRank = new RetrieveAndRank(); + + void Start() + { + LogSystem.InstallDefaultReactors(); + + string testClusterID = Config.Instance.GetVariableValue("RetrieveAndRank_IntegrationTestClusterID"); + string testClusterConfigName = "cranfield_solr_config"; + string testClusterConfigPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/RetrieveAndRank/cranfield_solr_config.zip"; + string testRankerTrainingPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/RetrieveAndRank/ranker_training_data.csv"; + string testAnswerDataPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/RetrieveAndRank/ranker_answer_data.csv"; + string testRankerID = "3b140ax15-rank-10035"; + string rankerToDelete = "3b140ax14-rank-10015"; + string indexDataPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/RetrieveAndRank/cranfield_data.json"; + string testCollectionName = "test-collection"; + string testQuery = "What is the basic mechanisim of the transonic aileron buzz"; + + //// Get clusters + //Log.Debug("ExampleRetrieveAndRank", "Attempting to get clusters!"); + //if (!m_RetrieveAndRank.GetClusters(OnGetClusters)) + // Log.Debug("ExampleRetrieveAndRank", "Failed to get clusters!"); + + //// Create cluster + //Log.Debug("ExampleRetrieveAndRank", "Attempting to create cluster!"); + //if (!m_RetrieveAndRank.CreateCluster(OnCreateCluster, "unity-test-cluster", "1")) + // Log.Debug("ExampleRetrieveAndRank", "Failed to create cluster!"); + + //// Delete cluster + //string clusterToDelete = "scabeadb4c_cd5a_4745_b1b9_156c6292687c"; + //Log.Debug("ExampleRetrieveAndRank", "Attempting to delete cluster {0}!", clusterToDelete); + //if (!m_RetrieveAndRank.DeleteCluster(OnDeleteCluster, clusterToDelete)) + // Log.Debug("ExampleRetrieveAndRank", "Failed to delete cluster!"); + + //// Get cluster + //Log.Debug("ExampleRetrieveAndRank", "Attempting to get cluster {0}!", testClusterID); + //if (!m_RetrieveAndRank.GetCluster(OnGetCluster, testClusterID)) + // Log.Debug("ExampleRetrieveAndRank", "Failed to get cluster!"); + + //// List cluster configs + //Log.Debug("ExampleRetrieveAndRank", "Attempting to get cluster configs for {0}!", testClusterID); + //if (!m_RetrieveAndRank.GetClusterConfigs(OnGetClusterConfigs, testClusterID)) + // Log.Debug("ExampleRetrieveAndRank", "Failed to get cluster configs!"); + + //// Delete cluster config + //string clusterConfigToDelete = "test-config"; + //Log.Debug("ExampleRetrieveAndRank", "Attempting to delete cluster {0} config {1}!", testClusterID, clusterConfigToDelete); + //if (!m_RetrieveAndRank.DeleteClusterConfig(OnDeleteClusterConfig, testClusterID, clusterConfigToDelete)) + // Log.Debug("ExampleRetriveAndRank", "Failed to delete cluster config {0}", clusterConfigToDelete); + + //// Get cluster config + //Log.Debug("ExampleRetrieveAndRank", "Attempting to get cluster {0} config {1}!", testClusterID, testClusterConfigName); + //if (!m_RetrieveAndRank.GetClusterConfig(OnGetClusterConfig, testClusterID, testClusterConfigName)) + // Log.Debug("ExampleRetrieveAndRank", "Failed to get cluster config {0}!", testClusterConfigName); + + //// Upload cluster config + //Log.Debug("ExampleRetrieveAndRank", "Attempting to upload cluster {0} config {1}!", testClusterID, testClusterConfigName); + //if (!m_RetrieveAndRank.UploadClusterConfig(OnUploadClusterConfig, testClusterID, testClusterConfigName, testClusterConfigPath)) + // Log.Debug("ExampleRetrieveAndRank", "Failed to upload cluster config {0}!", testClusterConfigPath); + + //// List Collection request + //Log.Debug("ExampleRetrieveAndRank", "Attempting to list collections!"); + //if (!m_RetrieveAndRank.ForwardCollectionRequest(OnGetCollections, testClusterID, CollectionsAction.LIST)) + // Log.Debug("ExampleRetrieveAndRank", "Failed to get collections!"); + + //// Create Collection request + //Log.Debug("ExampleRetrieveAndRank", "Attempting to create collection!"); + //if (!m_RetrieveAndRank.ForwardCollectionRequest(OnGetCollections, testClusterID, CollectionsAction.CREATE, "TestCollectionToDelete", testClusterConfigName)) + // Log.Debug("ExampleRetrieveAndRank", "Failed to create collections!"); + + //// Delete Collection request + //Log.Debug("ExampleRetrieveAndRank", "Attempting to delete collection!"); + //if (!m_RetrieveAndRank.ForwardCollectionRequest(OnGetCollections, testClusterID, CollectionsAction.DELETE, "TestCollectionToDelete")) + // Log.Debug("ExampleRetrieveAndRank", "Failed to delete collections!"); + + //// Index documents + //Log.Debug("ExampleRetrieveAndRank", "Attempting to index documents!"); + //if (!m_RetrieveAndRank.IndexDocuments(OnIndexDocuments, indexDataPath, testClusterID, testCollectionName)) + // Log.Debug("ExampleRetrieveAndRank", "Failed to index documents!"); + + //// Standard Search + //Log.Debug("ExampleRetrieveAndRank", "Attempting to search!"); + //string[] fl = { "title", "id", "body", "author", "bibliography" }; + //if (!m_RetrieveAndRank.Search(OnSearch, testClusterID, testCollectionName, testQuery, fl)) + // Log.Debug("ExampleRetrieveAndRank", "Failed to search!"); + + //// Ranked Search + //Log.Debug("ExampleRetrieveAndRank", "Attempting to search!"); + //string[] fl = { "title", "id", "body", "author", "bibliography" }; + //if (!m_RetrieveAndRank.Search(OnSearch, testClusterID, testCollectionName, testQuery, fl, true)) + // Log.Debug("ExampleRetrieveAndRank", "Failed to search!"); + + //// Get rankers + //Log.Debug("ExampleRetrieveAndRank", "Attempting to get rankers!"); + //if (!m_RetrieveAndRank.GetRankers(OnGetRankers)) + // Log.Debug("ExampleRetrieveAndRank", "Failed to get rankers!"); + + //// Create ranker + //Log.Debug("ExampleRetrieveAndRank", "Attempting to create rankers!"); + //if (!m_RetrieveAndRank.CreateRanker(OnCreateRanker, testRankerTrainingPath, "testRanker")) + // Log.Debug("ExampleRetrieveAndRank", "Failed to create ranker!"); + + // Rank + Log.Debug("ExampleRetrieveAndRank", "Attempting to rank!"); + if (!m_RetrieveAndRank.Rank(OnRank, testRankerID, testAnswerDataPath)) + Log.Debug("ExampleRetriveAndRank", "Failed to rank!"); + + //// Delete rankers + //Log.Debug("ExampleRetriveAndRank", "Attempting to delete ranker {0}!", rankerToDelete); + //if (!m_RetrieveAndRank.DeleteRanker(OnDeleteRanker, rankerToDelete)) + // Log.Debug("ExampleRetrieveAndRank", "Failed to delete ranker {0}!", rankerToDelete); + + //// Get ranker info + //Log.Debug("ExampleRetrieveAndRank", "Attempting to get Ranker Info!"); + //if (!m_RetrieveAndRank.GetRanker(OnGetRanker, testRankerID)) + // Log.Debug("ExampleRetrieveAndRank", "Failed to get ranker!"); + } + + private void OnGetClusters(SolrClusterListResponse resp, string data) + { + if (resp != null) { - LogSystem.InstallDefaultReactors(); - - string testClusterID = Config.Instance.GetVariableValue("RetrieveAndRank_IntegrationTestClusterID"); - string testClusterConfigName = "cranfield_solr_config"; - string testClusterConfigPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/RetrieveAndRank/cranfield_solr_config.zip"; - string testRankerTrainingPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/RetrieveAndRank/ranker_training_data.csv"; - string testAnswerDataPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/RetrieveAndRank/ranker_answer_data.csv"; - string testRankerID = "3b140ax15-rank-10035"; - string rankerToDelete = "3b140ax14-rank-10015"; - string indexDataPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/RetrieveAndRank/cranfield_data.json"; - string testCollectionName = "test-collection"; - string testQuery = "What is the basic mechanisim of the transonic aileron buzz"; - - //// Get clusters - //Log.Debug("ExampleRetrieveAndRank", "Attempting to get clusters!"); - //if (!m_RetrieveAndRank.GetClusters(OnGetClusters)) - // Log.Debug("ExampleRetrieveAndRank", "Failed to get clusters!"); - - //// Create cluster - //Log.Debug("ExampleRetrieveAndRank", "Attempting to create cluster!"); - //if (!m_RetrieveAndRank.CreateCluster(OnCreateCluster, "unity-test-cluster", "1")) - // Log.Debug("ExampleRetrieveAndRank", "Failed to create cluster!"); - - //// Delete cluster - //string clusterToDelete = "scabeadb4c_cd5a_4745_b1b9_156c6292687c"; - //Log.Debug("ExampleRetrieveAndRank", "Attempting to delete cluster {0}!", clusterToDelete); - //if (!m_RetrieveAndRank.DeleteCluster(OnDeleteCluster, clusterToDelete)) - // Log.Debug("ExampleRetrieveAndRank", "Failed to delete cluster!"); - - //// Get cluster - //Log.Debug("ExampleRetrieveAndRank", "Attempting to get cluster {0}!", testClusterID); - //if (!m_RetrieveAndRank.GetCluster(OnGetCluster, testClusterID)) - // Log.Debug("ExampleRetrieveAndRank", "Failed to get cluster!"); - - //// List cluster configs - //Log.Debug("ExampleRetrieveAndRank", "Attempting to get cluster configs for {0}!", testClusterID); - //if (!m_RetrieveAndRank.GetClusterConfigs(OnGetClusterConfigs, testClusterID)) - // Log.Debug("ExampleRetrieveAndRank", "Failed to get cluster configs!"); - - //// Delete cluster config - //string clusterConfigToDelete = "test-config"; - //Log.Debug("ExampleRetrieveAndRank", "Attempting to delete cluster {0} config {1}!", testClusterID, clusterConfigToDelete); - //if (!m_RetrieveAndRank.DeleteClusterConfig(OnDeleteClusterConfig, testClusterID, clusterConfigToDelete)) - // Log.Debug("ExampleRetriveAndRank", "Failed to delete cluster config {0}", clusterConfigToDelete); - - //// Get cluster config - //Log.Debug("ExampleRetrieveAndRank", "Attempting to get cluster {0} config {1}!", testClusterID, testClusterConfigName); - //if (!m_RetrieveAndRank.GetClusterConfig(OnGetClusterConfig, testClusterID, testClusterConfigName)) - // Log.Debug("ExampleRetrieveAndRank", "Failed to get cluster config {0}!", testClusterConfigName); - - //// Upload cluster config - //Log.Debug("ExampleRetrieveAndRank", "Attempting to upload cluster {0} config {1}!", testClusterID, testClusterConfigName); - //if (!m_RetrieveAndRank.UploadClusterConfig(OnUploadClusterConfig, testClusterID, testClusterConfigName, testClusterConfigPath)) - // Log.Debug("ExampleRetrieveAndRank", "Failed to upload cluster config {0}!", testClusterConfigPath); - - //// List Collection request - //Log.Debug("ExampleRetrieveAndRank", "Attempting to list collections!"); - //if (!m_RetrieveAndRank.ForwardCollectionRequest(OnGetCollections, testClusterID, CollectionsAction.LIST)) - // Log.Debug("ExampleRetrieveAndRank", "Failed to get collections!"); - - //// Create Collection request - //Log.Debug("ExampleRetrieveAndRank", "Attempting to create collection!"); - //if (!m_RetrieveAndRank.ForwardCollectionRequest(OnGetCollections, testClusterID, CollectionsAction.CREATE, "TestCollectionToDelete", testClusterConfigName)) - // Log.Debug("ExampleRetrieveAndRank", "Failed to create collections!"); - - //// Delete Collection request - //Log.Debug("ExampleRetrieveAndRank", "Attempting to delete collection!"); - //if (!m_RetrieveAndRank.ForwardCollectionRequest(OnGetCollections, testClusterID, CollectionsAction.DELETE, "TestCollectionToDelete")) - // Log.Debug("ExampleRetrieveAndRank", "Failed to delete collections!"); - - //// Index documents - //Log.Debug("ExampleRetrieveAndRank", "Attempting to index documents!"); - //if (!m_RetrieveAndRank.IndexDocuments(OnIndexDocuments, indexDataPath, testClusterID, testCollectionName)) - // Log.Debug("ExampleRetrieveAndRank", "Failed to index documents!"); - - //// Standard Search - //Log.Debug("ExampleRetrieveAndRank", "Attempting to search!"); - //string[] fl = { "title", "id", "body", "author", "bibliography" }; - //if (!m_RetrieveAndRank.Search(OnSearch, testClusterID, testCollectionName, testQuery, fl)) - // Log.Debug("ExampleRetrieveAndRank", "Failed to search!"); - - //// Ranked Search - //Log.Debug("ExampleRetrieveAndRank", "Attempting to search!"); - //string[] fl = { "title", "id", "body", "author", "bibliography" }; - //if (!m_RetrieveAndRank.Search(OnSearch, testClusterID, testCollectionName, testQuery, fl, true)) - // Log.Debug("ExampleRetrieveAndRank", "Failed to search!"); - - //// Get rankers - //Log.Debug("ExampleRetrieveAndRank", "Attempting to get rankers!"); - //if (!m_RetrieveAndRank.GetRankers(OnGetRankers)) - // Log.Debug("ExampleRetrieveAndRank", "Failed to get rankers!"); - - //// Create ranker - //Log.Debug("ExampleRetrieveAndRank", "Attempting to create rankers!"); - //if (!m_RetrieveAndRank.CreateRanker(OnCreateRanker, testRankerTrainingPath, "testRanker")) - // Log.Debug("ExampleRetrieveAndRank", "Failed to create ranker!"); - - // Rank - Log.Debug("ExampleRetrieveAndRank", "Attempting to rank!"); - if (!m_RetrieveAndRank.Rank(OnRank, testRankerID, testAnswerDataPath)) - Log.Debug("ExampleRetriveAndRank", "Failed to rank!"); - - //// Delete rankers - //Log.Debug("ExampleRetriveAndRank", "Attempting to delete ranker {0}!", rankerToDelete); - //if (!m_RetrieveAndRank.DeleteRanker(OnDeleteRanker, rankerToDelete)) - // Log.Debug("ExampleRetrieveAndRank", "Failed to delete ranker {0}!", rankerToDelete); - - //// Get ranker info - //Log.Debug("ExampleRetrieveAndRank", "Attempting to get Ranker Info!"); - //if (!m_RetrieveAndRank.GetRanker(OnGetRanker, testRankerID)) - // Log.Debug("ExampleRetrieveAndRank", "Failed to get ranker!"); + foreach (SolrClusterResponse cluster in resp.clusters) + Log.Debug("ExampleRetrieveAndRank", "OnGetClusters | cluster name: {0}, size: {1}, ID: {2}, status: {3}.", cluster.cluster_name, cluster.cluster_size, cluster.solr_cluster_id, cluster.solr_cluster_status); } - - private void OnGetClusters(SolrClusterListResponse resp, string data) + else { - if (resp != null) - { - foreach (SolrClusterResponse cluster in resp.clusters) - Log.Debug("ExampleRetrieveAndRank", "OnGetClusters | cluster name: {0}, size: {1}, ID: {2}, status: {3}.", cluster.cluster_name, cluster.cluster_size, cluster.solr_cluster_id, cluster.solr_cluster_status); - } - else - { - Log.Debug("ExampleRetrieveAndRank", "OnGetClusters | Get Cluster Response is null!"); - } + Log.Debug("ExampleRetrieveAndRank", "OnGetClusters | Get Cluster Response is null!"); } + } - private void OnCreateCluster(SolrClusterResponse resp, string data) + private void OnCreateCluster(SolrClusterResponse resp, string data) + { + if (resp != null) { - if (resp != null) - { - Log.Debug("ExampleRetrieveAndRank", "OnCreateClusters | name: {0}, size: {1}, ID: {2}, status: {3}.", resp.cluster_name, resp.cluster_size, resp.solr_cluster_id, resp.solr_cluster_status); - } - else - { - Log.Debug("ExampleRetrieveAndRank", "OnCreateClusters | Get Cluster Response is null!"); - } + Log.Debug("ExampleRetrieveAndRank", "OnCreateClusters | name: {0}, size: {1}, ID: {2}, status: {3}.", resp.cluster_name, resp.cluster_size, resp.solr_cluster_id, resp.solr_cluster_status); + } + else + { + Log.Debug("ExampleRetrieveAndRank", "OnCreateClusters | Get Cluster Response is null!"); } + } - private void OnDeleteCluster(bool success, string data) + private void OnDeleteCluster(bool success, string data) + { + if (success) { - if (success) - { - Log.Debug("ExampleRetrieveAndRank", "OnDeleteCluster | Success!"); - } - else - { - Log.Debug("ExampleRetrieveAndRank", "OnDeleteCluster | Failure!"); - } + Log.Debug("ExampleRetrieveAndRank", "OnDeleteCluster | Success!"); + } + else + { + Log.Debug("ExampleRetrieveAndRank", "OnDeleteCluster | Failure!"); } + } - private void OnGetCluster(SolrClusterResponse resp, string data) + private void OnGetCluster(SolrClusterResponse resp, string data) + { + if (resp != null) { - if (resp != null) - { - Log.Debug("ExampleRetrieveAndRank", "OnGetClusters | name: {0}, size: {1}, ID: {2}, status: {3}.", resp.cluster_name, resp.cluster_size, resp.solr_cluster_id, resp.solr_cluster_status); - } - else - { - Log.Debug("ExampleRetrieveAndRank", "OnGetClusters | Get Cluster Response is null!"); - } + Log.Debug("ExampleRetrieveAndRank", "OnGetClusters | name: {0}, size: {1}, ID: {2}, status: {3}.", resp.cluster_name, resp.cluster_size, resp.solr_cluster_id, resp.solr_cluster_status); } + else + { + Log.Debug("ExampleRetrieveAndRank", "OnGetClusters | Get Cluster Response is null!"); + } + } - private void OnGetClusterConfigs(SolrConfigList resp, string data) + private void OnGetClusterConfigs(SolrConfigList resp, string data) + { + if (resp != null) { - if (resp != null) - { - if (resp.solr_configs.Length == 0) - Log.Debug("ExampleRetrieveAndRank", "OnGetClusterConfigs | no cluster configs!"); + if (resp.solr_configs.Length == 0) + Log.Debug("ExampleRetrieveAndRank", "OnGetClusterConfigs | no cluster configs!"); - foreach (string config in resp.solr_configs) - Log.Debug("ExampleRetrieveAndRank", "OnGetClusterConfigs | solr_config: " + config); - } - else - { - Log.Debug("ExampleRetrieveAndRank", "OnGetClustersConfigs | Get Cluster Configs Response is null!"); - } + foreach (string config in resp.solr_configs) + Log.Debug("ExampleRetrieveAndRank", "OnGetClusterConfigs | solr_config: " + config); } - - private void OnDeleteClusterConfig(bool success, string data) + else { - if (success) - { - Log.Debug("ExampleRetrieveAndRank", "OnDeleteClusterConfig | Success!"); - } - else - { - Log.Debug("ExampleRetrieveAndRank", "OnDeleteClusterConfig | Failure!"); - } + Log.Debug("ExampleRetrieveAndRank", "OnGetClustersConfigs | Get Cluster Configs Response is null!"); } + } - - private void OnGetClusterConfig(byte[] respData, string data) + private void OnDeleteClusterConfig(bool success, string data) + { + if (success) + { + Log.Debug("ExampleRetrieveAndRank", "OnDeleteClusterConfig | Success!"); + } + else { + Log.Debug("ExampleRetrieveAndRank", "OnDeleteClusterConfig | Failure!"); + } + } + + + private void OnGetClusterConfig(byte[] respData, string data) + { #if UNITY_EDITOR - if (respData != null) - { - Log.Debug("ExampleRetrieveAndRank", "OnGetClusterConfig | success!"); - string currentDirectory = Application.dataPath; - var path = EditorUtility.SaveFilePanel("Save Config", currentDirectory, "config", "zip"); - if (!string.IsNullOrEmpty(path)) - { - currentDirectory = Path.GetDirectoryName(path); - m_RetrieveAndRank.SaveConfig(OnSaveConfig, respData, path, data); - } - } - else - Log.Debug("ExampleRetrieveAndRank", "OnGetClusterConfig | respData is null!"); + if (respData != null) + { + Log.Debug("ExampleRetrieveAndRank", "OnGetClusterConfig | success!"); + string currentDirectory = Application.dataPath; + var path = EditorUtility.SaveFilePanel("Save Config", currentDirectory, "config", "zip"); + if (!string.IsNullOrEmpty(path)) + { + currentDirectory = Path.GetDirectoryName(path); + m_RetrieveAndRank.SaveConfig(OnSaveConfig, respData, path, data); + } + } + else + Log.Debug("ExampleRetrieveAndRank", "OnGetClusterConfig | respData is null!"); #else Log.Debug("ExampleRetrieveAndRank", "Not in editor - skipping download."); #endif - } + } + + private void OnSaveConfig(bool success, string data) + { + if (success) + Log.Debug("ExampleRetrieveAndRank", "OnSaveConfig | success!"); + else + Log.Debug("ExampleRetrieveAndRank", "OnSaveConfig | fail!"); + } + + private void OnUploadClusterConfig(UploadResponse resp, string data) + { + if (resp != null) + { + Log.Debug("ExampleRetrieveAndRank", "OnUploadClusterConfig | Success! {0}, {1}", resp.message, resp.statusCode); + } + else + { + Log.Debug("ExampleRetrieveAndRank", "OnUploadClusterConfig | Failure!"); + } + } - private void OnSaveConfig(bool success, string data) + private void OnGetCollections(CollectionsResponse resp, string data) + { + if (resp != null) { - if (success) - Log.Debug("ExampleRetrieveAndRank", "OnSaveConfig | success!"); + if (resp.responseHeader != null) + Log.Debug("ExampleRetrieveAndRank", "OnGetCollections | status: {0}, QTime: {1}.", resp.responseHeader.status, resp.responseHeader.QTime); + if (resp.collections != null) + { + if (resp.collections.Length == 0) + Log.Debug("ExampleRetrieveAndRank", "OnGetCollections | There are no collections!"); else - Log.Debug("ExampleRetrieveAndRank", "OnSaveConfig | fail!"); + foreach (string collection in resp.collections) + Log.Debug("ExampleRetrieveAndRank", "\tOnGetCollections | collection: {0}", collection); + } + } + else + { + Log.Debug("ExampleRetrieveAndRank", "OnGetCollections | GetCollections Response is null!"); } + } - private void OnUploadClusterConfig(UploadResponse resp, string data) + private void OnIndexDocuments(IndexResponse resp, string data) + { + if (resp != null) { - if (resp != null) - { - Log.Debug("ExampleRetrieveAndRank", "OnUploadClusterConfig | Success! {0}, {1}", resp.message, resp.statusCode); - } - else - { - Log.Debug("ExampleRetrieveAndRank", "OnUploadClusterConfig | Failure!"); - } + if (resp.responseHeader != null) + Log.Debug("ExampleRetrieveAndRank", "OnIndexDocuments | status: {0}, QTime: {1}", resp.responseHeader.status, resp.responseHeader.QTime); + else + Log.Debug("ExampleRetrieveAndRank", "OnIndexDocuments | Response header is null!"); + } + else + { + Log.Debug("ExampleRetrieveAndRank", "OnIndexDocuments | response is null!"); } + } - private void OnGetCollections(CollectionsResponse resp, string data) + private void OnGetRankers(ListRankersPayload resp, string data) + { + if (resp != null) { - if(resp != null) - { - if(resp.responseHeader != null) - Log.Debug("ExampleRetrieveAndRank", "OnGetCollections | status: {0}, QTime: {1}.", resp.responseHeader.status, resp.responseHeader.QTime); - if(resp.collections != null) - { - if (resp.collections.Length == 0) - Log.Debug("ExampleRetrieveAndRank", "OnGetCollections | There are no collections!"); - else - foreach (string collection in resp.collections) - Log.Debug("ExampleRetrieveAndRank", "\tOnGetCollections | collection: {0}", collection); - } - } - else - { - Log.Debug("ExampleRetrieveAndRank", "OnGetCollections | GetCollections Response is null!"); - } + if (resp.rankers.Length == 0) + Log.Debug("ExampleRetrieveAndRank", "OnGetRankers | no rankers!"); + foreach (RankerInfoPayload ranker in resp.rankers) + Log.Debug("ExampleRetrieveAndRank", "OnGetRankers | ranker name: {0}, ID: {1}, created: {2}, url: {3}.", ranker.name, ranker.ranker_id, ranker.created, ranker.url); + } + else + { + Log.Debug("ExampleRetrieveAndRank", "OnGetRankers | Get Ranker Response is null!"); } + } - private void OnIndexDocuments(IndexResponse resp, string data) + private void OnCreateRanker(RankerStatusPayload resp, string data) + { + if (resp != null) { - if(resp != null) - { - if (resp.responseHeader != null) - Log.Debug("ExampleRetrieveAndRank", "OnIndexDocuments | status: {0}, QTime: {1}", resp.responseHeader.status, resp.responseHeader.QTime); - else - Log.Debug("ExampleRetrieveAndRank", "OnIndexDocuments | Response header is null!"); - } - else - { - Log.Debug("ExampleRetrieveAndRank", "OnIndexDocuments | response is null!"); - } + Log.Debug("ExampleRetrieveAndRank", "OnCreateRanker | ID: {0}, url: {1}, name: {2}, created: {3}, status: {4}, statusDescription: {5}.", resp.ranker_id, resp.url, resp.name, resp.created, resp.status, resp.status_description); } + else + { + Log.Debug("ExampleRetrieveAndRank", "OnCreateRanker | Get Cluster Response is null!"); + } + } - private void OnGetRankers(ListRankersPayload resp, string data) + private void OnRank(RankerOutputPayload resp, string data) + { + if (resp != null) { - if (resp != null) + Log.Debug("ExampleRetrieveAndRank", "OnRank | ID: {0}, url: {1}, top_answer: {2}.", resp.ranker_id, resp.url, resp.top_answer); + if (resp.answers != null) + if (resp.answers.Length == 0) { - if (resp.rankers.Length == 0) - Log.Debug("ExampleRetrieveAndRank", "OnGetRankers | no rankers!"); - foreach (RankerInfoPayload ranker in resp.rankers) - Log.Debug("ExampleRetrieveAndRank", "OnGetRankers | ranker name: {0}, ID: {1}, created: {2}, url: {3}.", ranker.name, ranker.ranker_id, ranker.created, ranker.url); + Log.Debug("ExampleRetrieveAndRank", "\tThere are no answers!"); } else { - Log.Debug("ExampleRetrieveAndRank", "OnGetRankers | Get Ranker Response is null!"); + foreach (RankedAnswer answer in resp.answers) + Log.Debug("ExampleRetrieveAndRank", "\tOnRank | answerID: {0}, score: {1}, confidence: {2}.", answer.answer_id, answer.score, answer.confidence); } } + else + { + Log.Debug("ExampleRetrieveAndRank", "OnRank | Rank response is null!"); + } + } + + private void OnGetRanker(RankerStatusPayload resp, string data) + { + if (resp != null) + { + Log.Debug("ExampleRetrieveAndRank", "GetRanker | ranker_id: {0}, url: {1}, name: {2}, created: {3}, status: {4}, status_description: {5}.", resp.ranker_id, resp.url, resp.name, resp.created, resp.status, resp.status_description); + } + else + { + Log.Debug("ExampleRetrieveAndRank", "GetRanker | GetRanker response is null!"); + } + } + + private void OnDeleteRanker(bool success, string data) + { + if (success) + { + Log.Debug("ExampleRetrieveAndRank", "OnDeleteRanker | Success!"); + } + else + { + Log.Debug("ExampleRetrieveAndRank", "OnDeleteRanker | Failure!"); + } + } - private void OnCreateRanker(RankerStatusPayload resp, string data) - { - if (resp != null) - { - Log.Debug("ExampleRetrieveAndRank", "OnCreateRanker | ID: {0}, url: {1}, name: {2}, created: {3}, status: {4}, statusDescription: {5}.", resp.ranker_id, resp.url, resp.name, resp.created, resp.status, resp.status_description); - } - else - { - Log.Debug("ExampleRetrieveAndRank", "OnCreateRanker | Get Cluster Response is null!"); - } - } - - private void OnRank(RankerOutputPayload resp, string data) - { - if (resp != null) - { - Log.Debug("ExampleRetrieveAndRank", "OnRank | ID: {0}, url: {1}, top_answer: {2}.", resp.ranker_id, resp.url, resp.top_answer); - if (resp.answers != null) - if (resp.answers.Length == 0) - { - Log.Debug("ExampleRetrieveAndRank", "\tThere are no answers!"); - } - else - { - foreach (RankedAnswer answer in resp.answers) - Log.Debug("ExampleRetrieveAndRank", "\tOnRank | answerID: {0}, score: {1}, confidence: {2}.", answer.answer_id, answer.score, answer.confidence); - } - } - else - { - Log.Debug("ExampleRetrieveAndRank", "OnRank | Rank response is null!"); - } - } - - private void OnGetRanker(RankerStatusPayload resp, string data) - { - if(resp != null) - { - Log.Debug("ExampleRetrieveAndRank", "GetRanker | ranker_id: {0}, url: {1}, name: {2}, created: {3}, status: {4}, status_description: {5}.", resp.ranker_id, resp.url, resp.name, resp.created, resp.status, resp.status_description); - } - else - { - Log.Debug("ExampleRetrieveAndRank", "GetRanker | GetRanker response is null!"); - } - } - - private void OnDeleteRanker(bool success, string data) - { - if (success) - { - Log.Debug("ExampleRetrieveAndRank", "OnDeleteRanker | Success!"); - } - else - { - Log.Debug("ExampleRetrieveAndRank", "OnDeleteRanker | Failure!"); - } - } - - private void OnSearch(SearchResponse resp, string data) + private void OnSearch(SearchResponse resp, string data) + { + if (resp != null) { - if(resp != null) + if (resp.responseHeader != null) + { + Log.Debug("ExampleRetrieveAndRank", "Search | status: {0}, QTime: {1}.", resp.responseHeader.status, resp.responseHeader.QTime); + if (resp.responseHeader._params != null) + Log.Debug("ExampleRetrieveAndRank", "\tSearch | params.q: {0}, params.fl: {1}, params.wt: {2}.", resp.responseHeader._params.q, resp.responseHeader._params.fl, resp.responseHeader._params.wt); + else + Log.Debug("ExampleRetrieveAndRank", "Search | responseHeader.params is null!"); + } + else + { + Log.Debug("ExampleRetrieveAndRank", "Search | response header is null!"); + } + + if (resp.response != null) + { + Log.Debug("ExampleRetrieveAndRank", "Search | numFound: {0}, start: {1}.", resp.response.numFound, resp.response.start); + if (resp.response.docs != null) { - if(resp.responseHeader != null) - { - Log.Debug("ExampleRetrieveAndRank", "Search | status: {0}, QTime: {1}.", resp.responseHeader.status, resp.responseHeader.QTime); - if (resp.responseHeader._params != null) - Log.Debug("ExampleRetrieveAndRank", "\tSearch | params.q: {0}, params.fl: {1}, params.wt: {2}.", resp.responseHeader._params.q, resp.responseHeader._params.fl, resp.responseHeader._params.wt); - else - Log.Debug("ExampleRetrieveAndRank", "Search | responseHeader.params is null!"); - } - else + if (resp.response.docs.Length == 0) + Log.Debug("ExampleRetrieveAndRank", "Search | There are no docs!"); + else + foreach (Doc doc in resp.response.docs) { - Log.Debug("ExampleRetrieveAndRank", "Search | response header is null!"); - } + Log.Debug("ExampleRetrieveAndRank", "\tSearch | id: {0}.", doc.id); - if (resp.response != null) - { - Log.Debug("ExampleRetrieveAndRank", "Search | numFound: {0}, start: {1}.", resp.response.numFound, resp.response.start); - if(resp.response.docs != null) - { - if (resp.response.docs.Length == 0) - Log.Debug("ExampleRetrieveAndRank", "Search | There are no docs!"); - else - foreach (Doc doc in resp.response.docs) - { - Log.Debug("ExampleRetrieveAndRank", "\tSearch | id: {0}.", doc.id); - - if (doc.title != null) - { - if (doc.title.Length == 0) - Log.Debug("ExampleRetrieveAndRank", "Search | There are no title"); - else - foreach (string s in doc.title) - Log.Debug("ExampleRetrieveAndRank", "\tSearch | title: {0}.", s); - } - else - { - Log.Debug("ExampleRetrieveAndRank", "Search | title is null"); - } - - if (doc.author != null) - { - if (doc.author.Length == 0) - Log.Debug("ExampleRetrieveAndRank", "Search | There are no authors"); - else - foreach (string s in doc.author) - Log.Debug("ExampleRetrieveAndRank", "\tSearch | Author: {0}.", s); - } - else - { - Log.Debug("ExampleRetrieveAndRank", "Search | Authors is null"); - } - - if (doc.body != null) - { - if (doc.body.Length == 0) - Log.Debug("ExampleRetrieveAndRank", "Search | There are no body"); - else - foreach (string s in doc.body) - Log.Debug("ExampleRetrieveAndRank", "\tSearch | body: {0}.", s); - } - else - { - Log.Debug("ExampleRetrieveAndRank", "Search | Body is null"); - } - - if (doc.bibliography != null) - { - if (doc.bibliography.Length == 0) - Log.Debug("ExampleRetrieveAndRank", "Search | There are no bibliographies"); - else - foreach (string s in doc.bibliography) - Log.Debug("ExampleRetrieveAndRank", "\tSearch | bibliography: {0}.", s); - } - else - { - Log.Debug("ExampleRetrieveAndRank", "Search | Bibliography is null"); - } - } - } + if (doc.title != null) + { + if (doc.title.Length == 0) + Log.Debug("ExampleRetrieveAndRank", "Search | There are no title"); else - { - Log.Debug("ExampleRetrieveAndRank", "Search | docs are null!"); - } - } - else - { - Log.Debug("ExampleRetrieveAndRank", "Search | response is null!"); + foreach (string s in doc.title) + Log.Debug("ExampleRetrieveAndRank", "\tSearch | title: {0}.", s); + } + else + { + Log.Debug("ExampleRetrieveAndRank", "Search | title is null"); + } + + if (doc.author != null) + { + if (doc.author.Length == 0) + Log.Debug("ExampleRetrieveAndRank", "Search | There are no authors"); + else + foreach (string s in doc.author) + Log.Debug("ExampleRetrieveAndRank", "\tSearch | Author: {0}.", s); + } + else + { + Log.Debug("ExampleRetrieveAndRank", "Search | Authors is null"); + } + + if (doc.body != null) + { + if (doc.body.Length == 0) + Log.Debug("ExampleRetrieveAndRank", "Search | There are no body"); + else + foreach (string s in doc.body) + Log.Debug("ExampleRetrieveAndRank", "\tSearch | body: {0}.", s); + } + else + { + Log.Debug("ExampleRetrieveAndRank", "Search | Body is null"); + } + + if (doc.bibliography != null) + { + if (doc.bibliography.Length == 0) + Log.Debug("ExampleRetrieveAndRank", "Search | There are no bibliographies"); + else + foreach (string s in doc.bibliography) + Log.Debug("ExampleRetrieveAndRank", "\tSearch | bibliography: {0}.", s); + } + else + { + Log.Debug("ExampleRetrieveAndRank", "Search | Bibliography is null"); + } } } else { - Log.Debug("ExampleRetrieveAndRank", "Search response is null!"); + Log.Debug("ExampleRetrieveAndRank", "Search | docs are null!"); } + } + else + { + Log.Debug("ExampleRetrieveAndRank", "Search | response is null!"); + } + } + else + { + Log.Debug("ExampleRetrieveAndRank", "Search response is null!"); } + } } diff --git a/Examples/ServiceExamples/Scripts/ExampleSpeechToText.cs b/Examples/ServiceExamples/Scripts/ExampleSpeechToText.cs index 83af8506f..292efa554 100755 --- a/Examples/ServiceExamples/Scripts/ExampleSpeechToText.cs +++ b/Examples/ServiceExamples/Scripts/ExampleSpeechToText.cs @@ -22,447 +22,447 @@ public class ExampleSpeechToText : MonoBehaviour { - [SerializeField] - private AudioClip m_AudioClip = new AudioClip(); - private SpeechToText m_SpeechToText = new SpeechToText(); + [SerializeField] + private AudioClip m_AudioClip = new AudioClip(); + private SpeechToText m_SpeechToText = new SpeechToText(); + + private string m_CreatedCustomizationID; + private string m_CreatedCorpusName = "unity-corpus"; + private string m_CustomCorpusFilePath; + + void Start() + { + //m_SpeechToText.Recognize(m_AudioClip, HandleOnRecognize); + LogSystem.InstallDefaultReactors(); + + m_CustomCorpusFilePath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/test-stt-corpus.txt"; + + // test GetModels and GetModel + //TestGetModels(); + + // test CreateSession + //TestCreateSession("en-US_BroadbandModel"); + + // test GetCustomizations + //TestGetCustomizations(); + + // test create, get and delete customizations + //TestCreateCustomization(); + } + + private void TestGetModels() + { + Log.Debug("ExampleSpeechToText", "Attempting to get models"); + m_SpeechToText.GetModels(HandleGetModels); + } + + private void TestGetModel(string modelID) + { + Log.Debug("ExampleSpeechToText", "Attempting to get model {0}", modelID); + m_SpeechToText.GetModel(HandleGetModel, modelID); + } + + private void TestGetCustomizations() + { + Log.Debug("ExampleSpeechToText", "Attempting to get customizations"); + m_SpeechToText.GetCustomizations(HandleGetCustomizations); + } + + private void TestCreateCustomization() + { + Log.Debug("ExampleSpeechToText", "Attempting create customization"); + m_SpeechToText.CreateCustomization(HandleCreateCustomization, "unity-test-customization", "en-US_BroadbandModel", "Testing customization unity"); + } + + private void TestDeleteCustomization(string customizationID) + { + Log.Debug("ExampleSpeechToText", "Attempting to delete customization {0}", customizationID); + m_SpeechToText.DeleteCustomization(HandleDeleteCustomization, customizationID); + } + + private void TestGetCustomization(string customizationID) + { + Log.Debug("ExampleSpeechToText", "Attempting to get customization {0}", customizationID); + m_SpeechToText.GetCustomization(HandleGetCustomization, customizationID); + } + + private void TestTrainCustomization(string customizationID) + { + Log.Debug("ExampleSpeechToText", "Attempting to train customization {0}", customizationID); + m_SpeechToText.TrainCustomization(HandleTrainCustomization, customizationID); + } + + private void TestUpgradeCustomization(string customizationID) + { + Log.Debug("ExampleSpeechToText", "Attempting to upgrade customization {0}", customizationID); + m_SpeechToText.UpgradeCustomization(HandleUpgradeCustomization, customizationID); + } + + private void TestResetCustomization(string customizationID) + { + Log.Debug("ExampleSpeechToText", "Attempting to reset customization {0}", customizationID); + m_SpeechToText.ResetCustomization(HandleResetCustomization, customizationID); + } + + private void TestGetCustomCorpora(string customizationID) + { + Log.Debug("ExampleSpeechToText", "Attempting to get custom corpora for {0}", customizationID); + m_SpeechToText.GetCustomCorpora(HandleGetCustomCorpora, customizationID); + } + + private void TestDeleteCustomCorpus(string customizationID, string corpusName) + { + Log.Debug("ExampleSpeechToText", "Attempting to delete custom corpus {1} in customization {0}", customizationID, corpusName); + m_SpeechToText.DeleteCustomCorpus(HandleDeleteCustomCorpus, customizationID, corpusName); + } + + private void TestAddCustomCorpus(string customizationID, string corpusName, bool allowOverwrite, string trainingDataPath) + { + Log.Debug("ExampleSpeechToText", "Attempting to add custom corpus {1} in customization {0}", customizationID, corpusName); + m_SpeechToText.AddCustomCorpus(HandleAddCustomCorpus, customizationID, corpusName, allowOverwrite, trainingDataPath); + } + + private void TestGetCustomWords() + { + Log.Debug("ExampleSpeechToText", "Attempting to get custom words."); + m_SpeechToText.GetCustomWords(HandleGetCustomWords, m_CreatedCustomizationID); + } + + private void TestAddCustomWordsPath(string customizationID, string wordsJsonPath) + { + Log.Debug("ExampleSpeechToText", "Attempting to add custom words in customization {0} using Words json path {1}", customizationID, wordsJsonPath); + m_SpeechToText.AddCustomWords(HandleAddCustomWords, customizationID, wordsJsonPath); + } + + private void TestAddCustomWordsWordsObject(string customizationID, Words words) + { + Log.Debug("ExampleSpeechToText", "Attempting to add custom words in customization {0} using Words object", customizationID); + m_SpeechToText.AddCustomWords(HandleAddCustomWords, customizationID, words); + } + + private void TestDeleteCustomWord(string customizationID, string word) + { + Log.Debug("ExampleSpeechToText", "Attempting to delete custom word {1} in customization {0}", customizationID, word); + m_SpeechToText.DeleteCustomWord(HandleDeleteCustomWord, customizationID, word); + } + + private void TestGetCustomWord(string customizationID, string word) + { + Log.Debug("ExampleSpeechToText", "Attempting to get custom word {1} in customization {0}", customizationID, word); + m_SpeechToText.GetCustomWord(HandleGetCustomWord, customizationID, word); + } + + + + private void HandleGetModels(Model[] models) + { + if (models != null) + { + if (models != null) + { + if (models.Length == 0) + { + Log.Warning("ExampleSpeedchToText", "There are no custom models!"); + } + else + { + foreach (Model model in models) + { + Log.Debug("ExampleSpeechToText", "Model: {0}", model.name); + } + + TestGetModel((models[Random.Range(0, models.Length - 1)] as Model).name); + } + } + } + else + { + Log.Warning("ExampleSpeechToText", "Failed to get models!"); + } + } + + private void HandleGetModel(Model model) + { + if (model != null) + { + Log.Debug("ExampleSpeechToText", "Model - name: {0} | description: {1} | language:{2} | rate: {3} | sessions: {4} | url: {5} | customLanguageModel: {6}", + model.name, model.description, model.language, model.rate, model.sessions, model.url, model.supported_features.custom_language_model); + } + else + { + Log.Warning("ExampleSpeechToText", "Failed to get model!"); + } + } + + private void HandleOnRecognize(SpeechRecognitionEvent result) + { + if (result != null && result.results.Length > 0) + { + foreach (var res in result.results) + { + foreach (var alt in res.alternatives) + { + string text = alt.transcript; + Log.Debug("ExampleSpeechToText", string.Format("{0} ({1}, {2:0.00})\n", text, res.final ? "Final" : "Interim", alt.confidence)); + } + } + } + } + + private void HandleGetCustomizations(Customizations customizations, string customData) + { + if (!string.IsNullOrEmpty(customData)) + Log.Debug("ExampleSpeechToText", "custom data: {0}", customData); + + if (customizations != null) + { + if (customizations.customizations.Length > 0) + { + foreach (Customization customization in customizations.customizations) + Log.Debug("ExampleSpeechToText", "Customization - name: {0} | description: {1} | status: {2}", customization.name, customization.description, customization.status); + + Log.Debug("ExampleSpeechToText", "GetCustomizations() succeeded!"); + } + else + { + Log.Debug("ExampleSpeechToText", "There are no customizations!"); + } + } + else + { + Log.Debug("ExampleSpeechToText", "Failed to get customizations!"); + } + } + + private void HandleCreateCustomization(CustomizationID customizationID, string customData) + { + if (customizationID != null) + { + Log.Debug("ExampleSpeechToText", "Customization created: {0}", customizationID.customization_id); + Log.Debug("ExampleSpeechToText", "CreateCustomization() succeeded!"); + + m_CreatedCustomizationID = customizationID.customization_id; + TestGetCustomization(m_CreatedCustomizationID); + } + else + { + Log.Debug("ExampleSpeechToText", "Failed to create customization!"); + } + } + + private void HandleDeleteCustomization(bool success, string customData) + { + if (success) + { + Log.Debug("ExampleSpeechToText", "Deleted customization {0}!", m_CreatedCustomizationID); + Log.Debug("ExampleSpeechToText", "DeletedCustomization() succeeded!"); + m_CreatedCustomizationID = default(string); + } + else + { + Log.Debug("ExampleSpeechToText", "Failed to delete customization!"); + } + } + + private void HandleGetCustomization(Customization customization, string customData) + { + if (!string.IsNullOrEmpty(customData)) + Log.Debug("ExampleSpeechToText", "custom data: {0}", customData); + + if (customization != null) + { + Log.Debug("ExampleSpeechToText", "Customization - name: {0} | description: {1} | status: {2}", customization.name, customization.description, customization.status); + Log.Debug("ExampleSpeechToText", "GetCustomization() succeeded!"); + + // test add custom corpora + //TestAddCustomCorpus(m_CreatedCustomizationID, m_CreatedCorpusName, true, m_CustomCorpusFilePath); + TestDeleteCustomization(m_CreatedCustomizationID); + } + else + { + Log.Debug("ExampleSpeechToText", "Failed to get customization {0}!", m_CreatedCustomizationID); + } + } + + private void HandleTrainCustomization(bool success, string customData) + { + if (!string.IsNullOrEmpty(customData)) + Log.Debug("ExampleSpeechToText", "custom data: {0}", customData); + + if (success) + { + Log.Debug("ExampleSpeechToText", "Train customization {0}!", m_CreatedCustomizationID); + Log.Debug("ExampleSpeechToText", "TrainCustomization() succeeded!"); + + TestResetCustomization(m_CreatedCustomizationID); + } + else + { + Log.Debug("ExampleSpeechToText", "Failed to train customization!"); + } + } + + private void HandleUpgradeCustomization(bool success, string customData) + { + if (!string.IsNullOrEmpty(customData)) + Log.Debug("ExampleSpeechToText", "custom data: {0}", customData); + + if (success) + { + Log.Debug("ExampleSpeechToText", "Upgrade customization {0}!", m_CreatedCustomizationID); + Log.Debug("ExampleSpeechToText", "UpgradeCustomization() succeeded!"); + + } + else + { + Log.Debug("ExampleSpeechToText", "Failed to upgrade customization!"); + } + } - private string m_CreatedCustomizationID; - private string m_CreatedCorpusName = "unity-corpus"; - private string m_CustomCorpusFilePath; + private void HandleResetCustomization(bool success, string customData) + { + if (!string.IsNullOrEmpty(customData)) + Log.Debug("ExampleSpeechToText", "custom data: {0}", customData); - void Start() + if (success) { - //m_SpeechToText.Recognize(m_AudioClip, HandleOnRecognize); - LogSystem.InstallDefaultReactors(); + Log.Debug("ExampleSpeechToText", "Reset customization {0}!", m_CreatedCustomizationID); + Log.Debug("ExampleSpeechToText", "ResetCustomization() succeeded!"); - m_CustomCorpusFilePath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/test-stt-corpus.txt"; - - // test GetModels and GetModel - //TestGetModels(); + // test delete custom corpus + TestDeleteCustomCorpus(m_CreatedCustomizationID, m_CreatedCorpusName); + } + else + { + Log.Debug("ExampleSpeechToText", "Failed to reset customization!"); + } + } - // test CreateSession - //TestCreateSession("en-US_BroadbandModel"); + private void HandleGetCustomCorpora(Corpora corpora, string customData) + { + if (!string.IsNullOrEmpty(customData)) + Log.Debug("ExampleSpeechToText", "CustomData: {0}", customData); - // test GetCustomizations - //TestGetCustomizations(); + if (corpora != null) + { + if (corpora.corpora.Length > 0) + { + foreach (Corpus corpus in corpora.corpora) + Log.Debug("ExampleSpeechToText", "Corpus - name: {0} | total_words: {1} | out_of_vocabulary_words: {2} | staus: {3}", + corpus.name, corpus.total_words, corpus.out_of_vocabulary_words, corpus.status); + + //TestUpgradeCustomization(m_CreatedCustomizationID); + TestTrainCustomization(m_CreatedCustomizationID); + } + else + { + Log.Debug("ExampleSpeechToText", "There are no custom corpora!"); + } + + Log.Debug("ExampleSpeechToText", "GetCustomCorpora() succeeded!"); + TestDeleteCustomization(m_CreatedCustomizationID); + } + else + { + Log.Debug("ExampleSpeechToText", "Failed to get custom corpora!"); + } + } + + private void HandleDeleteCustomCorpus(bool success, string customData) + { + if (!string.IsNullOrEmpty(customData)) + Log.Debug("ExampleSpeechToText", "custom data: {0}", customData); + + if (success) + { + Log.Debug("ExampleSpeechToText", "DeleteCustomCorpus() succeeded!"); - // test create, get and delete customizations - //TestCreateCustomization(); } + else + { + Log.Debug("ExampleSpeechToText", "Failed to delete custom corpus!"); + } + } + + private void HandleAddCustomCorpus(bool success, string customData) + { + if (!string.IsNullOrEmpty(customData)) + Log.Debug("ExampleSpeechToText", "custom data: {0}", customData); + + if (success) + { + Log.Debug("ExampleSpeechToText", "AddCustomCorpus() succeeded!"); + + // test get custom corpora + TestGetCustomCorpora(m_CreatedCustomizationID); + } + else + { + Log.Debug("ExampleSpeechToText", "Failed to delete custom corpus!"); + } + } + + private void HandleGetCustomWords(WordsList wordList, string customData) + { + if (!string.IsNullOrEmpty(customData)) + Log.Debug("ExampleSpeechToText", "custom data: {0}", customData); + + if (wordList != null) + { + if (wordList.words != null && wordList.words.Length > 0) + { + foreach (WordData word in wordList.words) + Log.Debug("ExampleSpeechToText", "WordData - word: {0} | sounds like: {1} | display as: {2}", word.word, word.sounds_like, word.display_as); + } + else + { + Log.Debug("ExampleSpeechToText", "No custom words found!"); + } + } + else + { + Log.Debug("ExampleSpeechToText", "Failed to get custom words!"); + } + } + + private void HandleAddCustomWords(bool success, string customData) + { + if (!string.IsNullOrEmpty(customData)) + Log.Debug("ExampleSpeechToText", "custom data: {0}", customData); + + if (success) + { + Log.Debug("ExampleSpeechToText", "AddCustomWOrds() succeeded!"); + + } + else + { + Log.Debug("ExampleSpeechToText", "Failed to add custom words!"); + } + } + + private void HandleDeleteCustomWord(bool success, string customData) + { + if (!string.IsNullOrEmpty(customData)) + Log.Debug("ExampleSpeechToText", "custom data: {0}", customData); + + if (success) + { + Log.Debug("ExampleSpeechToText", "DeleteCustomWord() succeeded!"); + + } + else + { + Log.Debug("ExampleSpeechToText", "Failed to delete custom word!"); + } + } + + private void HandleGetCustomWord(WordData word, string customData) + { + if (!string.IsNullOrEmpty(customData)) + Log.Debug("ExampleSpeechToText", "custom data: {0}", customData); - private void TestGetModels() - { - Log.Debug("ExampleSpeechToText", "Attempting to get models"); - m_SpeechToText.GetModels(HandleGetModels); - } - - private void TestGetModel(string modelID) - { - Log.Debug("ExampleSpeechToText", "Attempting to get model {0}", modelID); - m_SpeechToText.GetModel(HandleGetModel, modelID); - } - - private void TestGetCustomizations() - { - Log.Debug("ExampleSpeechToText", "Attempting to get customizations"); - m_SpeechToText.GetCustomizations(HandleGetCustomizations); - } - - private void TestCreateCustomization() - { - Log.Debug("ExampleSpeechToText", "Attempting create customization"); - m_SpeechToText.CreateCustomization(HandleCreateCustomization, "unity-test-customization", "en-US_BroadbandModel", "Testing customization unity"); - } - - private void TestDeleteCustomization(string customizationID) - { - Log.Debug("ExampleSpeechToText", "Attempting to delete customization {0}", customizationID); - m_SpeechToText.DeleteCustomization(HandleDeleteCustomization, customizationID); - } - - private void TestGetCustomization(string customizationID) - { - Log.Debug("ExampleSpeechToText", "Attempting to get customization {0}", customizationID); - m_SpeechToText.GetCustomization(HandleGetCustomization, customizationID); - } - - private void TestTrainCustomization(string customizationID) - { - Log.Debug("ExampleSpeechToText", "Attempting to train customization {0}", customizationID); - m_SpeechToText.TrainCustomization(HandleTrainCustomization, customizationID); - } - - private void TestUpgradeCustomization(string customizationID) - { - Log.Debug("ExampleSpeechToText", "Attempting to upgrade customization {0}", customizationID); - m_SpeechToText.UpgradeCustomization(HandleUpgradeCustomization, customizationID); - } - - private void TestResetCustomization(string customizationID) - { - Log.Debug("ExampleSpeechToText", "Attempting to reset customization {0}", customizationID); - m_SpeechToText.ResetCustomization(HandleResetCustomization, customizationID); - } - - private void TestGetCustomCorpora(string customizationID) - { - Log.Debug("ExampleSpeechToText", "Attempting to get custom corpora for {0}", customizationID); - m_SpeechToText.GetCustomCorpora(HandleGetCustomCorpora, customizationID); - } - - private void TestDeleteCustomCorpus(string customizationID, string corpusName) - { - Log.Debug("ExampleSpeechToText", "Attempting to delete custom corpus {1} in customization {0}", customizationID, corpusName); - m_SpeechToText.DeleteCustomCorpus(HandleDeleteCustomCorpus, customizationID, corpusName); - } - - private void TestAddCustomCorpus(string customizationID, string corpusName, bool allowOverwrite, string trainingDataPath) - { - Log.Debug("ExampleSpeechToText", "Attempting to add custom corpus {1} in customization {0}", customizationID, corpusName); - m_SpeechToText.AddCustomCorpus(HandleAddCustomCorpus, customizationID, corpusName, allowOverwrite, trainingDataPath); - } - - private void TestGetCustomWords() - { - Log.Debug("ExampleSpeechToText", "Attempting to get custom words."); - m_SpeechToText.GetCustomWords(HandleGetCustomWords, m_CreatedCustomizationID); - } - - private void TestAddCustomWordsPath(string customizationID, string wordsJsonPath) - { - Log.Debug("ExampleSpeechToText", "Attempting to add custom words in customization {0} using Words json path {1}", customizationID, wordsJsonPath); - m_SpeechToText.AddCustomWords(HandleAddCustomWords, customizationID, wordsJsonPath); - } - - private void TestAddCustomWordsWordsObject(string customizationID, Words words) - { - Log.Debug("ExampleSpeechToText", "Attempting to add custom words in customization {0} using Words object", customizationID); - m_SpeechToText.AddCustomWords(HandleAddCustomWords, customizationID, words); - } - - private void TestDeleteCustomWord(string customizationID, string word) - { - Log.Debug("ExampleSpeechToText", "Attempting to delete custom word {1} in customization {0}", customizationID, word); - m_SpeechToText.DeleteCustomWord(HandleDeleteCustomWord, customizationID, word); - } - - private void TestGetCustomWord(string customizationID, string word) - { - Log.Debug("ExampleSpeechToText", "Attempting to get custom word {1} in customization {0}", customizationID, word); - m_SpeechToText.GetCustomWord(HandleGetCustomWord, customizationID, word); - } - - - - private void HandleGetModels(Model[] models) - { - if (models != null) - { - if (models != null) - { - if (models.Length == 0) - { - Log.Warning("ExampleSpeedchToText", "There are no custom models!"); - } - else - { - foreach (Model model in models) - { - Log.Debug("ExampleSpeechToText", "Model: {0}", model.name); - } - - TestGetModel((models[Random.Range(0, models.Length - 1)] as Model).name); - } - } - } - else - { - Log.Warning("ExampleSpeechToText", "Failed to get models!"); - } - } - - private void HandleGetModel(Model model) - { - if(model != null) - { - Log.Debug("ExampleSpeechToText", "Model - name: {0} | description: {1} | language:{2} | rate: {3} | sessions: {4} | url: {5} | customLanguageModel: {6}", - model.name, model.description, model.language, model.rate, model.sessions, model.url, model.supported_features.custom_language_model); - } - else - { - Log.Warning("ExampleSpeechToText", "Failed to get model!"); - } - } - - private void HandleOnRecognize (SpeechRecognitionEvent result) - { - if (result != null && result.results.Length > 0) - { - foreach( var res in result.results ) - { - foreach( var alt in res.alternatives ) - { - string text = alt.transcript; - Log.Debug("ExampleSpeechToText", string.Format( "{0} ({1}, {2:0.00})\n", text, res.final ? "Final" : "Interim", alt.confidence)); - } - } - } - } - - private void HandleGetCustomizations(Customizations customizations, string customData) - { - if (!string.IsNullOrEmpty(customData)) - Log.Debug("ExampleSpeechToText", "custom data: {0}", customData); - - if (customizations != null) - { - if(customizations.customizations.Length > 0) - { - foreach (Customization customization in customizations.customizations) - Log.Debug("ExampleSpeechToText", "Customization - name: {0} | description: {1} | status: {2}", customization.name, customization.description, customization.status); - - Log.Debug("ExampleSpeechToText", "GetCustomizations() succeeded!"); - } - else - { - Log.Debug("ExampleSpeechToText", "There are no customizations!"); - } - } - else - { - Log.Debug("ExampleSpeechToText", "Failed to get customizations!"); - } - } - - private void HandleCreateCustomization(CustomizationID customizationID, string customData) - { - if(customizationID != null) - { - Log.Debug("ExampleSpeechToText", "Customization created: {0}", customizationID.customization_id); - Log.Debug("ExampleSpeechToText", "CreateCustomization() succeeded!"); - - m_CreatedCustomizationID = customizationID.customization_id; - TestGetCustomization(m_CreatedCustomizationID); - } - else - { - Log.Debug("ExampleSpeechToText", "Failed to create customization!"); - } - } - - private void HandleDeleteCustomization(bool success, string customData) - { - if (success) - { - Log.Debug("ExampleSpeechToText", "Deleted customization {0}!", m_CreatedCustomizationID); - Log.Debug("ExampleSpeechToText", "DeletedCustomization() succeeded!"); - m_CreatedCustomizationID = default(string); - } - else - { - Log.Debug("ExampleSpeechToText", "Failed to delete customization!"); - } - } - - private void HandleGetCustomization(Customization customization, string customData) - { - if (!string.IsNullOrEmpty(customData)) - Log.Debug("ExampleSpeechToText", "custom data: {0}", customData); - - if(customization != null) - { - Log.Debug("ExampleSpeechToText", "Customization - name: {0} | description: {1} | status: {2}", customization.name, customization.description, customization.status); - Log.Debug("ExampleSpeechToText", "GetCustomization() succeeded!"); - - // test add custom corpora - //TestAddCustomCorpus(m_CreatedCustomizationID, m_CreatedCorpusName, true, m_CustomCorpusFilePath); - TestDeleteCustomization(m_CreatedCustomizationID); - } - else - { - Log.Debug("ExampleSpeechToText", "Failed to get customization {0}!", m_CreatedCustomizationID); - } - } - - private void HandleTrainCustomization(bool success, string customData) - { - if (!string.IsNullOrEmpty(customData)) - Log.Debug("ExampleSpeechToText", "custom data: {0}", customData); - - if (success) - { - Log.Debug("ExampleSpeechToText", "Train customization {0}!", m_CreatedCustomizationID); - Log.Debug("ExampleSpeechToText", "TrainCustomization() succeeded!"); - - TestResetCustomization(m_CreatedCustomizationID); - } - else - { - Log.Debug("ExampleSpeechToText", "Failed to train customization!"); - } - } - - private void HandleUpgradeCustomization(bool success, string customData) - { - if (!string.IsNullOrEmpty(customData)) - Log.Debug("ExampleSpeechToText", "custom data: {0}", customData); - - if (success) - { - Log.Debug("ExampleSpeechToText", "Upgrade customization {0}!", m_CreatedCustomizationID); - Log.Debug("ExampleSpeechToText", "UpgradeCustomization() succeeded!"); - - } - else - { - Log.Debug("ExampleSpeechToText", "Failed to upgrade customization!"); - } - } - - private void HandleResetCustomization(bool success, string customData) - { - if (!string.IsNullOrEmpty(customData)) - Log.Debug("ExampleSpeechToText", "custom data: {0}", customData); - - if (success) - { - Log.Debug("ExampleSpeechToText", "Reset customization {0}!", m_CreatedCustomizationID); - Log.Debug("ExampleSpeechToText", "ResetCustomization() succeeded!"); - - // test delete custom corpus - TestDeleteCustomCorpus(m_CreatedCustomizationID, m_CreatedCorpusName); - } - else - { - Log.Debug("ExampleSpeechToText", "Failed to reset customization!"); - } - } - - private void HandleGetCustomCorpora(Corpora corpora, string customData) - { - if (!string.IsNullOrEmpty(customData)) - Log.Debug("ExampleSpeechToText", "CustomData: {0}", customData); - - if(corpora != null) - { - if(corpora.corpora.Length > 0) - { - foreach (Corpus corpus in corpora.corpora) - Log.Debug("ExampleSpeechToText", "Corpus - name: {0} | total_words: {1} | out_of_vocabulary_words: {2} | staus: {3}", - corpus.name, corpus.total_words, corpus.out_of_vocabulary_words, corpus.status); - - //TestUpgradeCustomization(m_CreatedCustomizationID); - TestTrainCustomization(m_CreatedCustomizationID); - } - else - { - Log.Debug("ExampleSpeechToText", "There are no custom corpora!"); - } - - Log.Debug("ExampleSpeechToText", "GetCustomCorpora() succeeded!"); - TestDeleteCustomization(m_CreatedCustomizationID); - } - else - { - Log.Debug("ExampleSpeechToText", "Failed to get custom corpora!"); - } - } - - private void HandleDeleteCustomCorpus(bool success, string customData) - { - if (!string.IsNullOrEmpty(customData)) - Log.Debug("ExampleSpeechToText", "custom data: {0}", customData); - - if (success) - { - Log.Debug("ExampleSpeechToText", "DeleteCustomCorpus() succeeded!"); - - } - else - { - Log.Debug("ExampleSpeechToText", "Failed to delete custom corpus!"); - } - } - - private void HandleAddCustomCorpus(bool success, string customData) - { - if (!string.IsNullOrEmpty(customData)) - Log.Debug("ExampleSpeechToText", "custom data: {0}", customData); - - if (success) - { - Log.Debug("ExampleSpeechToText", "AddCustomCorpus() succeeded!"); - - // test get custom corpora - TestGetCustomCorpora(m_CreatedCustomizationID); - } - else - { - Log.Debug("ExampleSpeechToText", "Failed to delete custom corpus!"); - } - } - - private void HandleGetCustomWords(WordsList wordList, string customData) - { - if (!string.IsNullOrEmpty(customData)) - Log.Debug("ExampleSpeechToText", "custom data: {0}", customData); - - if(wordList != null) - { - if (wordList.words != null && wordList.words.Length > 0) - { - foreach (WordData word in wordList.words) - Log.Debug("ExampleSpeechToText", "WordData - word: {0} | sounds like: {1} | display as: {2}", word.word, word.sounds_like, word.display_as); - } - else - { - Log.Debug("ExampleSpeechToText", "No custom words found!"); - } - } - else - { - Log.Debug("ExampleSpeechToText", "Failed to get custom words!"); - } - } - - private void HandleAddCustomWords(bool success, string customData) - { - if (!string.IsNullOrEmpty(customData)) - Log.Debug("ExampleSpeechToText", "custom data: {0}", customData); - - if (success) - { - Log.Debug("ExampleSpeechToText", "AddCustomWOrds() succeeded!"); - - } - else - { - Log.Debug("ExampleSpeechToText", "Failed to add custom words!"); - } - } - - private void HandleDeleteCustomWord(bool success, string customData) - { - if (!string.IsNullOrEmpty(customData)) - Log.Debug("ExampleSpeechToText", "custom data: {0}", customData); - - if (success) - { - Log.Debug("ExampleSpeechToText", "DeleteCustomWord() succeeded!"); - - } - else - { - Log.Debug("ExampleSpeechToText", "Failed to delete custom word!"); - } - } - - private void HandleGetCustomWord(WordData word, string customData) - { - if (!string.IsNullOrEmpty(customData)) - Log.Debug("ExampleSpeechToText", "custom data: {0}", customData); - - if(word != null) - Log.Debug("ExampleSpeechToText", "WordData - word: {0} | sounds like: {1} | display as: {2}", word.word, word.sounds_like, word.display_as); - } + if (word != null) + Log.Debug("ExampleSpeechToText", "WordData - word: {0} | sounds like: {1} | display as: {2}", word.word, word.sounds_like, word.display_as); + } } \ No newline at end of file diff --git a/Examples/ServiceExamples/Scripts/ExampleStreaming.cs b/Examples/ServiceExamples/Scripts/ExampleStreaming.cs new file mode 100755 index 000000000..59ee303e9 --- /dev/null +++ b/Examples/ServiceExamples/Scripts/ExampleStreaming.cs @@ -0,0 +1,167 @@ +/** +* 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.Logging; +using IBM.Watson.DeveloperCloud.Services.SpeechToText.v1; +using IBM.Watson.DeveloperCloud.Utilities; +using IBM.Watson.DeveloperCloud.DataTypes; + +public class ExampleStreaming : MonoBehaviour +{ + private int m_RecordingRoutine = 0; + private string m_MicrophoneID = null; + private AudioClip m_Recording = null; + private int m_RecordingBufferSize = 2; + private int m_RecordingHZ = 22050; + + private SpeechToText m_SpeechToText = new SpeechToText(); + + void Start() + { + LogSystem.InstallDefaultReactors(); + Log.Debug("ExampleStreaming", "Start();"); + + Active = true; + + StartRecording(); + } + + public bool Active + { + get { return m_SpeechToText.IsListening; } + set + { + if (value && !m_SpeechToText.IsListening) + { + m_SpeechToText.DetectSilence = true; + m_SpeechToText.EnableWordConfidence = false; + m_SpeechToText.EnableTimestamps = false; + m_SpeechToText.SilenceThreshold = 0.03f; + m_SpeechToText.MaxAlternatives = 1; + m_SpeechToText.EnableContinousRecognition = true; + m_SpeechToText.EnableInterimResults = true; + m_SpeechToText.OnError = OnError; + m_SpeechToText.StartListening(OnRecognize); + } + else if (!value && m_SpeechToText.IsListening) + { + m_SpeechToText.StopListening(); + } + } + } + + private void StartRecording() + { + if (m_RecordingRoutine == 0) + { + UnityObjectUtil.StartDestroyQueue(); + m_RecordingRoutine = Runnable.Run(RecordingHandler()); + } + } + + private void StopRecording() + { + if (m_RecordingRoutine != 0) + { + Microphone.End(m_MicrophoneID); + Runnable.Stop(m_RecordingRoutine); + m_RecordingRoutine = 0; + } + } + + private void OnError(string error) + { + Active = false; + + Log.Debug("ExampleStreaming", "Error! {0}", error); + } + + private IEnumerator RecordingHandler() + { + Log.Debug("ExampleStreaming", "devices: {0}", Microphone.devices); + m_Recording = Microphone.Start(m_MicrophoneID, true, m_RecordingBufferSize, m_RecordingHZ); + yield return null; // let m_RecordingRoutine get set.. + + if (m_Recording == null) + { + StopRecording(); + yield break; + } + + bool bFirstBlock = true; + int midPoint = m_Recording.samples / 2; + float[] samples = null; + + while (m_RecordingRoutine != 0 && m_Recording != null) + { + int writePos = Microphone.GetPosition(m_MicrophoneID); + if (writePos > m_Recording.samples || !Microphone.IsRecording(m_MicrophoneID)) + { + Log.Error("MicrophoneWidget", "Microphone disconnected."); + + StopRecording(); + yield break; + } + + if ((bFirstBlock && writePos >= midPoint) + || (!bFirstBlock && writePos < midPoint)) + { + // front block is recorded, make a RecordClip and pass it onto our callback. + samples = new float[midPoint]; + m_Recording.GetData(samples, bFirstBlock ? 0 : midPoint); + + AudioData record = new AudioData(); + record.MaxLevel = Mathf.Max(samples); + record.Clip = AudioClip.Create("Recording", midPoint, m_Recording.channels, m_RecordingHZ, false); + record.Clip.SetData(samples, 0); + + m_SpeechToText.OnListen(record); + + bFirstBlock = !bFirstBlock; + } + else + { + // calculate the number of samples remaining until we ready for a block of audio, + // and wait that amount of time it will take to record. + int remaining = bFirstBlock ? (midPoint - writePos) : (m_Recording.samples - writePos); + float timeRemaining = (float)remaining / (float)m_RecordingHZ; + + yield return new WaitForSeconds(timeRemaining); + } + + } + + yield break; + } + + private void OnRecognize(SpeechRecognitionEvent result) + { + if (result != null && result.results.Length > 0) + { + foreach (var res in result.results) + { + foreach (var alt in res.alternatives) + { + string text = alt.transcript; + Log.Debug("ExampleStreaming", string.Format("{0} ({1}, {2:0.00})\n", text, res.final ? "Final" : "Interim", alt.confidence)); + } + } + } + } +} \ No newline at end of file diff --git a/Examples/ServiceExamples/Scripts/ExampleStreaming.cs.meta b/Examples/ServiceExamples/Scripts/ExampleStreaming.cs.meta new file mode 100755 index 000000000..a7a574279 --- /dev/null +++ b/Examples/ServiceExamples/Scripts/ExampleStreaming.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 6c5299c1c838a8c44b49ecc9254704e0 +timeCreated: 1477325099 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Examples/ServiceExamples/Scripts/ExampleTextToSpeech.cs b/Examples/ServiceExamples/Scripts/ExampleTextToSpeech.cs index 0222d75ae..8086396a5 100755 --- a/Examples/ServiceExamples/Scripts/ExampleTextToSpeech.cs +++ b/Examples/ServiceExamples/Scripts/ExampleTextToSpeech.cs @@ -22,254 +22,254 @@ public class ExampleTextToSpeech : MonoBehaviour { - TextToSpeech m_TextToSpeech = new TextToSpeech(); - string m_TestString = "I'm sorry. This is Text to Speech!I'm sorry. This is Text to Speech!"; - - - void Start () - { - LogSystem.InstallDefaultReactors(); - - //// Get Voices - //Log.Debug("ExampleTextToSpeech", "Attempting to get voices."); - //m_TextToSpeech.GetVoices(OnGetVoices); - - //// Get Voice - ////string selectedVoice = "en-US_AllisonVoice"; - //Log.Debug("ExampleTextToSpeech", "Attempting to get voice {0}.", VoiceType.en_US_Allison); - //m_TextToSpeech.GetVoice(OnGetVoice, VoiceType.en_US_Allison); - - //// Get Pronunciation - //string testWord = "Watson"; - //Log.Debug("ExampleTextToSpeech", "Attempting to get pronunciation of {0}", testWord); - //m_TextToSpeech.GetPronunciation(OnGetPronunciation, testWord, VoiceType.en_US_Allison); - - // Get Customizations - //Log.Debug("ExampleTextToSpeech", "Attempting to get a list of customizations"); - //m_TextToSpeech.GetCustomizations(OnGetCustomizations); - - // Create Customization - //Log.Debug("ExampleTextToSpeech", "Attempting to create a customization"); - //string customizationName = "unity-example-customization"; - //string customizationLanguage = "en-US"; - //string customizationDescription = "A text to speech voice customization created within Unity."; - //m_TextToSpeech.CreateCustomization(OnCreateCustomization, customizationName, customizationLanguage, customizationDescription); - - // Delete Customization - //Log.Debug("ExampleTextToSpeech", "Attempting to delete a customization"); - //string customizationIdentifierToDelete = "1476ea80-5355-4911-ac99-ba39162a2d34"; - //if (!m_TextToSpeech.DeleteCustomization(OnDeleteCustomization, customizationIdentifierToDelete)) - // Log.Debug("ExampleTextToSpeech", "Failed to delete custom voice model!"); - - // Get Customization - //Log.Debug("ExampleTextToSpeech", "Attempting to get a customization"); - //string customizationIdentifierToGet = "1476ea80-5355-4911-ac99-ba39162a2d34"; - //if (!m_TextToSpeech.GetCustomization(OnGetCustomization, customizationIdentifierToGet)) - // Log.Debug("ExampleTextToSpeech", "Failed to get custom voice model!"); - - // Update Customization - Log.Debug("ExampleTextToSpeech", "Attempting to update a customization"); - Word word0 = new Word(); - word0.word = "hello"; - word0.translation = "hullo"; - Word word1 = new Word(); - word1.word = "goodbye"; - word1.translation = "gbye"; - Word word2 = new Word(); - word2.word = "hi"; - word2.translation = "ohiooo"; - Word[] words = { word0, word1, word2 }; - CustomVoiceUpdate customVoiceUpdate = new CustomVoiceUpdate(); - customVoiceUpdate.words = words; - customVoiceUpdate.description = "My updated description"; - customVoiceUpdate.name = "My updated name"; - string customizationIdToUpdate = "1476ea80-5355-4911-ac99-ba39162a2d34"; - if (!m_TextToSpeech.UpdateCustomization(OnUpdateCustomization, customizationIdToUpdate, customVoiceUpdate)) - Log.Debug("ExampleTextToSpeech", "Failed to update customization!"); - - // Get Customization Words - //Log.Debug("ExampleTextToSpeech", "Attempting to get a customization's words"); - //string customIdentifierToGetWords = "1476ea80-5355-4911-ac99-ba39162a2d34"; - //if (!m_TextToSpeech.GetCustomizationWords(OnGetCustomizationWords, customIdentifierToGetWords)) - // Log.Debug("ExampleTextToSpeech", "Failed to get {0} words!", customIdentifierToGetWords); - - // Add Customization Words - //Log.Debug("ExampleTextToSpeech", "Attempting to add words to a customization"); - //string customIdentifierToAddWords = "1476ea80-5355-4911-ac99-ba39162a2d34"; - //Words words = new Words(); - //Word word0 = new Word(); - //word0.word = "bananna"; - //word0.translation = "bunanna"; - //Word word1 = new Word(); - //word1.word = "orange"; - //word1.translation = "arange"; - //Word word2 = new Word(); - //word2.word = "tomato"; - //word2.translation = "tomahto"; - //Word[] wordArray = { word0, word1, word2 }; - //words.words = wordArray; - //if (!m_TextToSpeech.AddCustomizationWords(OnAddCustomizationWords, customIdentifierToAddWords, words)) - // Log.Debug("ExampleTextToSpeech", "Failed to add words to {0}!", customIdentifierToAddWords); - - // Delete Customization Word - //Log.Debug("ExampleTextToSpeech", "Attempting to delete customization word from custom voice model."); - //string customIdentifierToDeleteWord = "1476ea80-5355-4911-ac99-ba39162a2d34"; - //string wordToDelete = "goodbye"; - //if (!m_TextToSpeech.DeleteCustomizationWord(OnDeleteCustomizationWord, customIdentifierToDeleteWord, wordToDelete)) - // Log.Debug("ExampleTextToSpeech", "Failed to delete {0} from {1}!", wordToDelete, customIdentifierToDeleteWord); - - // Get Customization Word - //Log.Debug("ExampleTextToSpeech", "Attempting to get the translation of a custom voice model's word."); - //string customIdentifierToGetWord = "1476ea80-5355-4911-ac99-ba39162a2d34"; - //string customIdentifierWord = "hello"; - //if (!m_TextToSpeech.GetCustomizationWord(OnGetCustomizationWord, customIdentifierToGetWord, customIdentifierWord)) - // Log.Debug("ExampleTextToSpeech", "Failed to get the translation of {0} from {1}!", customIdentifierWord, customIdentifierToGetWord); - - // Add Customization Word - This is not working. The PUT method is not supported by Unity. - //Log.Debug("ExampleTextToSpeech", "Attempting to add a single word and translation to a custom voice model."); - //string customIdentifierToAddWordAndTranslation = "1476ea80-5355-4911-ac99-ba39162a2d34"; - //string word = "grasshopper"; - //string translation = "guhrasshoppe"; - //if (!m_TextToSpeech.AddCustomizationWord(OnAddCustomizationWord, customIdentifierToAddWordAndTranslation, word, translation)) - // Log.Debug("ExampleTextToSpeech", "Failed to add {0}/{1} to {2}!", word, translation, customIdentifierToAddWordAndTranslation); - - - //m_TextToSpeech.Voice = VoiceType.en_US_Allison; - //m_TextToSpeech.ToSpeech(m_TestString, HandleToSpeechCallback, true); - + TextToSpeech m_TextToSpeech = new TextToSpeech(); + string m_TestString = "I'm sorry. This is Text to Speech!I'm sorry. This is Text to Speech!"; + + + void Start() + { + LogSystem.InstallDefaultReactors(); + + //// Get Voices + //Log.Debug("ExampleTextToSpeech", "Attempting to get voices."); + //m_TextToSpeech.GetVoices(OnGetVoices); + + //// Get Voice + ////string selectedVoice = "en-US_AllisonVoice"; + //Log.Debug("ExampleTextToSpeech", "Attempting to get voice {0}.", VoiceType.en_US_Allison); + //m_TextToSpeech.GetVoice(OnGetVoice, VoiceType.en_US_Allison); + + //// Get Pronunciation + //string testWord = "Watson"; + //Log.Debug("ExampleTextToSpeech", "Attempting to get pronunciation of {0}", testWord); + //m_TextToSpeech.GetPronunciation(OnGetPronunciation, testWord, VoiceType.en_US_Allison); + + // Get Customizations + //Log.Debug("ExampleTextToSpeech", "Attempting to get a list of customizations"); + //m_TextToSpeech.GetCustomizations(OnGetCustomizations); + + // Create Customization + //Log.Debug("ExampleTextToSpeech", "Attempting to create a customization"); + //string customizationName = "unity-example-customization"; + //string customizationLanguage = "en-US"; + //string customizationDescription = "A text to speech voice customization created within Unity."; + //m_TextToSpeech.CreateCustomization(OnCreateCustomization, customizationName, customizationLanguage, customizationDescription); + + // Delete Customization + //Log.Debug("ExampleTextToSpeech", "Attempting to delete a customization"); + //string customizationIdentifierToDelete = "1476ea80-5355-4911-ac99-ba39162a2d34"; + //if (!m_TextToSpeech.DeleteCustomization(OnDeleteCustomization, customizationIdentifierToDelete)) + // Log.Debug("ExampleTextToSpeech", "Failed to delete custom voice model!"); + + // Get Customization + //Log.Debug("ExampleTextToSpeech", "Attempting to get a customization"); + //string customizationIdentifierToGet = "1476ea80-5355-4911-ac99-ba39162a2d34"; + //if (!m_TextToSpeech.GetCustomization(OnGetCustomization, customizationIdentifierToGet)) + // Log.Debug("ExampleTextToSpeech", "Failed to get custom voice model!"); + + // Update Customization + Log.Debug("ExampleTextToSpeech", "Attempting to update a customization"); + Word word0 = new Word(); + word0.word = "hello"; + word0.translation = "hullo"; + Word word1 = new Word(); + word1.word = "goodbye"; + word1.translation = "gbye"; + Word word2 = new Word(); + word2.word = "hi"; + word2.translation = "ohiooo"; + Word[] words = { word0, word1, word2 }; + CustomVoiceUpdate customVoiceUpdate = new CustomVoiceUpdate(); + customVoiceUpdate.words = words; + customVoiceUpdate.description = "My updated description"; + customVoiceUpdate.name = "My updated name"; + string customizationIdToUpdate = "1476ea80-5355-4911-ac99-ba39162a2d34"; + if (!m_TextToSpeech.UpdateCustomization(OnUpdateCustomization, customizationIdToUpdate, customVoiceUpdate)) + Log.Debug("ExampleTextToSpeech", "Failed to update customization!"); + + // Get Customization Words + //Log.Debug("ExampleTextToSpeech", "Attempting to get a customization's words"); + //string customIdentifierToGetWords = "1476ea80-5355-4911-ac99-ba39162a2d34"; + //if (!m_TextToSpeech.GetCustomizationWords(OnGetCustomizationWords, customIdentifierToGetWords)) + // Log.Debug("ExampleTextToSpeech", "Failed to get {0} words!", customIdentifierToGetWords); + + // Add Customization Words + //Log.Debug("ExampleTextToSpeech", "Attempting to add words to a customization"); + //string customIdentifierToAddWords = "1476ea80-5355-4911-ac99-ba39162a2d34"; + //Words words = new Words(); + //Word word0 = new Word(); + //word0.word = "bananna"; + //word0.translation = "bunanna"; + //Word word1 = new Word(); + //word1.word = "orange"; + //word1.translation = "arange"; + //Word word2 = new Word(); + //word2.word = "tomato"; + //word2.translation = "tomahto"; + //Word[] wordArray = { word0, word1, word2 }; + //words.words = wordArray; + //if (!m_TextToSpeech.AddCustomizationWords(OnAddCustomizationWords, customIdentifierToAddWords, words)) + // Log.Debug("ExampleTextToSpeech", "Failed to add words to {0}!", customIdentifierToAddWords); + + // Delete Customization Word + //Log.Debug("ExampleTextToSpeech", "Attempting to delete customization word from custom voice model."); + //string customIdentifierToDeleteWord = "1476ea80-5355-4911-ac99-ba39162a2d34"; + //string wordToDelete = "goodbye"; + //if (!m_TextToSpeech.DeleteCustomizationWord(OnDeleteCustomizationWord, customIdentifierToDeleteWord, wordToDelete)) + // Log.Debug("ExampleTextToSpeech", "Failed to delete {0} from {1}!", wordToDelete, customIdentifierToDeleteWord); + + // Get Customization Word + //Log.Debug("ExampleTextToSpeech", "Attempting to get the translation of a custom voice model's word."); + //string customIdentifierToGetWord = "1476ea80-5355-4911-ac99-ba39162a2d34"; + //string customIdentifierWord = "hello"; + //if (!m_TextToSpeech.GetCustomizationWord(OnGetCustomizationWord, customIdentifierToGetWord, customIdentifierWord)) + // Log.Debug("ExampleTextToSpeech", "Failed to get the translation of {0} from {1}!", customIdentifierWord, customIdentifierToGetWord); + + // Add Customization Word - This is not working. The PUT method is not supported by Unity. + //Log.Debug("ExampleTextToSpeech", "Attempting to add a single word and translation to a custom voice model."); + //string customIdentifierToAddWordAndTranslation = "1476ea80-5355-4911-ac99-ba39162a2d34"; + //string word = "grasshopper"; + //string translation = "guhrasshoppe"; + //if (!m_TextToSpeech.AddCustomizationWord(OnAddCustomizationWord, customIdentifierToAddWordAndTranslation, word, translation)) + // Log.Debug("ExampleTextToSpeech", "Failed to add {0}/{1} to {2}!", word, translation, customIdentifierToAddWordAndTranslation); + + + //m_TextToSpeech.Voice = VoiceType.en_US_Allison; + //m_TextToSpeech.ToSpeech(m_TestString, HandleToSpeechCallback, true); + + } + + void HandleToSpeechCallback(AudioClip clip) + { + PlayClip(clip); + } + + private void PlayClip(AudioClip clip) + { + if (Application.isPlaying && clip != null) + { + GameObject audioObject = new GameObject("AudioObject"); + AudioSource source = audioObject.AddComponent(); + source.spatialBlend = 0.0f; + source.loop = false; + source.clip = clip; + source.Play(); + + GameObject.Destroy(audioObject, clip.length); } - - void HandleToSpeechCallback (AudioClip clip) - { - PlayClip(clip); - } - - private void PlayClip(AudioClip clip) - { - if (Application.isPlaying && clip != null) - { - GameObject audioObject = new GameObject("AudioObject"); - AudioSource source = audioObject.AddComponent(); - source.spatialBlend = 0.0f; - source.loop = false; - source.clip = clip; - source.Play(); - - GameObject.Destroy(audioObject, clip.length); - } - } - - private void OnGetVoices(Voices voices) - { - Log.Debug("ExampleTextToSpeech", "-----OnGetVoices-----"); - foreach (Voice voice in voices.voices) - Log.Debug("ExampleTextToSpeech", "Voice | name: {0} | gender: {1} | language: {2} | customizable: {3} | description: {4}.", voice.name, voice.gender, voice.language, voice.customizable, voice.description); - Log.Debug("ExampleTextToSpeech", "-----OnGetVoices-----"); - } - - private void OnGetVoice(Voice voice) - { - Log.Debug("ExampleTextToSpeech", "-----OnGetVoice-----"); - Log.Debug("ExampleTextToSpeech", "Voice | name: {0} | gender: {1} | language: {2} | customizable: {3} | description: {4}", voice.name, voice.gender, voice.language, voice.customizable, voice.description); - Log.Debug("ExampleTextToSpeech", "-----OnGetVoice-----"); - } - - private void OnGetPronunciation(Pronunciation pronunciation) - { - Log.Debug("ExampleTextToSpeech", "-----OnGetPronunciation-----"); - Log.Debug("ExampleTextToSpeech", "Pronunciation: {0}.", pronunciation.pronunciation); - Log.Debug("ExampleTextToSpeech", "-----OnGetPronunciation-----"); - } - - private void OnGetCustomizations(Customizations customizations, string data) - { - Log.Debug("ExampleTextToSpeech", "-----OnGetCustomizations-----"); - if(data != default(string)) - Log.Debug("ExampleTextToSpeech", "data: {0}", data); - foreach (Customization customization in customizations.customizations) - Log.Debug("ExampleTextToSpeech", "Customization: name: {0} | customization_id: {1} | language: {2} | description: {3} | owner: {4} | created: {5} | last modified: {6}", customization.name, customization.customization_id, customization.language, customization.description, customization.owner, customization.created, customization.last_modified); - Log.Debug("ExampleTextToSpeech", "-----OnGetCustomizations-----"); - } - - private void OnCreateCustomization(CustomizationID customizationID, string data) - { - Log.Debug("ExampleTextToSpeech", "-----OnCreateCustomization-----"); - if (data != default(string)) - Log.Debug("ExampleTextToSpeech", "data: {0}", data); - Log.Debug("ExampleTextToSpeech", "CustomizationID: id: {0}.", customizationID.customization_id); - Log.Debug("ExampleTextToSpeech", "-----OnCreateCustomization-----"); - } - - private void OnDeleteCustomization(bool success, string data) - { - Log.Debug("ExampleTextToSpeech", "-----OnDeleteCustomization-----"); - if (data != default(string)) - Log.Debug("ExampleTextToSpeech", "data: {0}", data); - Log.Debug("ExampleTextToSpeech", "Success: {0}.", success); - Log.Debug("ExampleTextToSpeech", "-----OnDeleteCustomization-----"); - } - - private void OnGetCustomization(Customization customization, string data) - { - Log.Debug("ExampleTextToSpeech", "-----OnGetCustomization-----"); - if (data != default(string)) - Log.Debug("ExampleTextToSpeech", "data: {0}", data); - Log.Debug("ExampleTextToSpeech", "Customization: name: {0} | customization_id: {1} | language: {2} | description: {3} | owner: {4} | created: {5} | last modified: {6}", customization.name, customization.customization_id, customization.language, customization.description, customization.owner, customization.created, customization.last_modified); - Log.Debug("ExampleTextToSpeech", "-----OnGetCustomization-----"); - } - - private void OnUpdateCustomization(bool success, string data) - { - Log.Debug("ExampleTextToSpeech", "-----OnUpdateCustomization-----"); - if (data != default(string)) - Log.Debug("ExampleTextToSpeech", "data: {0}", data); - Log.Debug("ExampleTextToSpeech", "Success: {0}.", success); - Log.Debug("ExampleTextToSpeech", "-----OnUpdateCustomization-----"); - } - - private void OnGetCustomizationWords(Words words, string data) - { - Log.Debug("ExampleTextToSpeech", "-----OnGetCustomizationWords-----"); - if (data != default(string)) - Log.Debug("ExampleTextToSpeech", "data: {0}", data); - foreach (Word word in words.words) - Log.Debug("ExampleTextToSpeech", "Word: {0} | Translation: {1}.", word.word, word.translation); - Log.Debug("ExampleTextToSpeech", "-----OnGetCustomizationWords-----"); - } - - private void OnAddCustomizationWords(bool success, string data) - { - Log.Debug("ExampleTextToSpeech", "-----OnAddCustomizationWords-----"); - if (data != default(string)) - Log.Debug("ExampleTextToSpeech", "data: {0}", data); - Log.Debug("ExampleTextToSpeech", "Success: {0}.", success); - Log.Debug("ExampleTextToSpeech", "-----OnAddCustomizationWords-----"); - } - - private void OnDeleteCustomizationWord(bool success, string data) - { - Log.Debug("ExampleTextToSpeech", "-----OnDeleteCustomizationWord-----"); - if (data != default(string)) - Log.Debug("ExampleTextToSpeech", "data: {0}", data); - Log.Debug("ExampleTextToSpeech", "Success: {0}.", success); - Log.Debug("ExampleTextToSpeech", "-----OnDeleteCustomizationWord-----"); - } - - private void OnGetCustomizationWord(Translation translation, string data) - { - Log.Debug("ExampleTextToSpeech", "-----OnGetCustomizationWord-----"); - if (data != default(string)) - Log.Debug("ExampleTextToSpeech", "data: {0}", data); - Log.Debug("ExampleTextToSpeech", "Translation: {0}.", translation.translation); - Log.Debug("ExampleTextToSpeech", "-----OnGetCustomizationWord-----"); - } - - private void OnAddCustomizationWord(bool success, string data) - { - Log.Debug("ExampleTextToSpeech", "-----OnAddCustomizationWord-----"); - if (data != default(string)) - Log.Debug("ExampleTextToSpeech", "data: {0}", data); - Log.Debug("ExampleTextToSpeech", "Success: {0}.", success); - Log.Debug("ExampleTextToSpeech", "-----OnAddCustomizationWord-----"); - } + } + + private void OnGetVoices(Voices voices) + { + Log.Debug("ExampleTextToSpeech", "-----OnGetVoices-----"); + foreach (Voice voice in voices.voices) + Log.Debug("ExampleTextToSpeech", "Voice | name: {0} | gender: {1} | language: {2} | customizable: {3} | description: {4}.", voice.name, voice.gender, voice.language, voice.customizable, voice.description); + Log.Debug("ExampleTextToSpeech", "-----OnGetVoices-----"); + } + + private void OnGetVoice(Voice voice) + { + Log.Debug("ExampleTextToSpeech", "-----OnGetVoice-----"); + Log.Debug("ExampleTextToSpeech", "Voice | name: {0} | gender: {1} | language: {2} | customizable: {3} | description: {4}", voice.name, voice.gender, voice.language, voice.customizable, voice.description); + Log.Debug("ExampleTextToSpeech", "-----OnGetVoice-----"); + } + + private void OnGetPronunciation(Pronunciation pronunciation) + { + Log.Debug("ExampleTextToSpeech", "-----OnGetPronunciation-----"); + Log.Debug("ExampleTextToSpeech", "Pronunciation: {0}.", pronunciation.pronunciation); + Log.Debug("ExampleTextToSpeech", "-----OnGetPronunciation-----"); + } + + private void OnGetCustomizations(Customizations customizations, string data) + { + Log.Debug("ExampleTextToSpeech", "-----OnGetCustomizations-----"); + if (data != default(string)) + Log.Debug("ExampleTextToSpeech", "data: {0}", data); + foreach (Customization customization in customizations.customizations) + Log.Debug("ExampleTextToSpeech", "Customization: name: {0} | customization_id: {1} | language: {2} | description: {3} | owner: {4} | created: {5} | last modified: {6}", customization.name, customization.customization_id, customization.language, customization.description, customization.owner, customization.created, customization.last_modified); + Log.Debug("ExampleTextToSpeech", "-----OnGetCustomizations-----"); + } + + private void OnCreateCustomization(CustomizationID customizationID, string data) + { + Log.Debug("ExampleTextToSpeech", "-----OnCreateCustomization-----"); + if (data != default(string)) + Log.Debug("ExampleTextToSpeech", "data: {0}", data); + Log.Debug("ExampleTextToSpeech", "CustomizationID: id: {0}.", customizationID.customization_id); + Log.Debug("ExampleTextToSpeech", "-----OnCreateCustomization-----"); + } + + private void OnDeleteCustomization(bool success, string data) + { + Log.Debug("ExampleTextToSpeech", "-----OnDeleteCustomization-----"); + if (data != default(string)) + Log.Debug("ExampleTextToSpeech", "data: {0}", data); + Log.Debug("ExampleTextToSpeech", "Success: {0}.", success); + Log.Debug("ExampleTextToSpeech", "-----OnDeleteCustomization-----"); + } + + private void OnGetCustomization(Customization customization, string data) + { + Log.Debug("ExampleTextToSpeech", "-----OnGetCustomization-----"); + if (data != default(string)) + Log.Debug("ExampleTextToSpeech", "data: {0}", data); + Log.Debug("ExampleTextToSpeech", "Customization: name: {0} | customization_id: {1} | language: {2} | description: {3} | owner: {4} | created: {5} | last modified: {6}", customization.name, customization.customization_id, customization.language, customization.description, customization.owner, customization.created, customization.last_modified); + Log.Debug("ExampleTextToSpeech", "-----OnGetCustomization-----"); + } + + private void OnUpdateCustomization(bool success, string data) + { + Log.Debug("ExampleTextToSpeech", "-----OnUpdateCustomization-----"); + if (data != default(string)) + Log.Debug("ExampleTextToSpeech", "data: {0}", data); + Log.Debug("ExampleTextToSpeech", "Success: {0}.", success); + Log.Debug("ExampleTextToSpeech", "-----OnUpdateCustomization-----"); + } + + private void OnGetCustomizationWords(Words words, string data) + { + Log.Debug("ExampleTextToSpeech", "-----OnGetCustomizationWords-----"); + if (data != default(string)) + Log.Debug("ExampleTextToSpeech", "data: {0}", data); + foreach (Word word in words.words) + Log.Debug("ExampleTextToSpeech", "Word: {0} | Translation: {1}.", word.word, word.translation); + Log.Debug("ExampleTextToSpeech", "-----OnGetCustomizationWords-----"); + } + + private void OnAddCustomizationWords(bool success, string data) + { + Log.Debug("ExampleTextToSpeech", "-----OnAddCustomizationWords-----"); + if (data != default(string)) + Log.Debug("ExampleTextToSpeech", "data: {0}", data); + Log.Debug("ExampleTextToSpeech", "Success: {0}.", success); + Log.Debug("ExampleTextToSpeech", "-----OnAddCustomizationWords-----"); + } + + private void OnDeleteCustomizationWord(bool success, string data) + { + Log.Debug("ExampleTextToSpeech", "-----OnDeleteCustomizationWord-----"); + if (data != default(string)) + Log.Debug("ExampleTextToSpeech", "data: {0}", data); + Log.Debug("ExampleTextToSpeech", "Success: {0}.", success); + Log.Debug("ExampleTextToSpeech", "-----OnDeleteCustomizationWord-----"); + } + + private void OnGetCustomizationWord(Translation translation, string data) + { + Log.Debug("ExampleTextToSpeech", "-----OnGetCustomizationWord-----"); + if (data != default(string)) + Log.Debug("ExampleTextToSpeech", "data: {0}", data); + Log.Debug("ExampleTextToSpeech", "Translation: {0}.", translation.translation); + Log.Debug("ExampleTextToSpeech", "-----OnGetCustomizationWord-----"); + } + + private void OnAddCustomizationWord(bool success, string data) + { + Log.Debug("ExampleTextToSpeech", "-----OnAddCustomizationWord-----"); + if (data != default(string)) + Log.Debug("ExampleTextToSpeech", "data: {0}", data); + Log.Debug("ExampleTextToSpeech", "Success: {0}.", success); + Log.Debug("ExampleTextToSpeech", "-----OnAddCustomizationWord-----"); + } } diff --git a/Examples/ServiceExamples/Scripts/ExampleToneAnalyzer.cs b/Examples/ServiceExamples/Scripts/ExampleToneAnalyzer.cs old mode 100644 new mode 100755 index 1bf2c5c2c..f155b835d --- a/Examples/ServiceExamples/Scripts/ExampleToneAnalyzer.cs +++ b/Examples/ServiceExamples/Scripts/ExampleToneAnalyzer.cs @@ -19,16 +19,18 @@ using System.Collections; using IBM.Watson.DeveloperCloud.Services.ToneAnalyzer.v3; -public class ExampleToneAnalyzer : MonoBehaviour { - ToneAnalyzer m_ToneAnalyzer = new ToneAnalyzer(); - string m_StringToTestTone = "This service enables people to discover and understand, and revise the impact of tone in their content. It uses linguistic analysis to detect and interpret emotional, social, and language cues found in text."; +public class ExampleToneAnalyzer : MonoBehaviour +{ + ToneAnalyzer m_ToneAnalyzer = new ToneAnalyzer(); + string m_StringToTestTone = "This service enables people to discover and understand, and revise the impact of tone in their content. It uses linguistic analysis to detect and interpret emotional, social, and language cues found in text."; - void Start () { - m_ToneAnalyzer.GetToneAnalyze( OnGetToneAnalyze, m_StringToTestTone, "TEST"); - } - - private void OnGetToneAnalyze( ToneAnalyzerResponse resp , string data) - { - Debug.Log("Response: " +resp + " - " + data); - } + void Start() + { + m_ToneAnalyzer.GetToneAnalyze(OnGetToneAnalyze, m_StringToTestTone, "TEST"); + } + + private void OnGetToneAnalyze(ToneAnalyzerResponse resp, string data) + { + Debug.Log("Response: " + resp + " - " + data); + } } diff --git a/Examples/ServiceExamples/Scripts/ExampleTradeoffAnalytics.cs b/Examples/ServiceExamples/Scripts/ExampleTradeoffAnalytics.cs old mode 100644 new mode 100755 index 335af4aa0..0ca8b04e5 --- a/Examples/ServiceExamples/Scripts/ExampleTradeoffAnalytics.cs +++ b/Examples/ServiceExamples/Scripts/ExampleTradeoffAnalytics.cs @@ -20,107 +20,109 @@ using System.Collections.Generic; using IBM.Watson.DeveloperCloud.Services.TradeoffAnalytics.v1; -public class ExampleTradeoffAnalytics : MonoBehaviour { - TradeoffAnalytics m_TradeoffAnalytics = new TradeoffAnalytics(); - - void Start () { - Problem problemToSolve = new Problem(); - problemToSolve.subject = "Test Subject"; - - List listColumn = new List(); - Column columnPrice = new Column(); - columnPrice.description = "Price Column to minimize"; - columnPrice.range = new ValueRange(); - ((ValueRange)columnPrice.range).high = 600; - ((ValueRange)columnPrice.range).low = 0; - columnPrice.type = "numeric"; - columnPrice.key = "price"; - columnPrice.full_name = "Price"; - columnPrice.goal = "min"; - columnPrice.is_objective = true; - columnPrice.format = "$####0.00"; - - Column columnWeight = new Column(); - columnWeight.description = "Weight Column to minimize"; - columnWeight.type = "numeric"; - columnWeight.key = "weight"; - columnWeight.full_name = "Weight"; - columnWeight.goal = "min"; - columnWeight.is_objective = true; - columnWeight.format = "####0 g"; - - Column columnBrandName = new Column(); - columnBrandName.description = "All Brand Names"; - columnBrandName.type = "categorical"; - columnBrandName.key = "brand"; - columnBrandName.full_name = "Brand"; - columnBrandName.goal = "max"; - columnBrandName.is_objective = true; - columnBrandName.preference = new string[]{"Samsung", "Apple", "HTC"}; - columnBrandName.range = new CategoricalRange(); - ((CategoricalRange)columnBrandName.range).keys = new string[]{"Samsung", "Apple", "HTC"}; - - listColumn.Add(columnPrice); - listColumn.Add(columnWeight); - // listColumn.Add(columnBrandName); - - problemToSolve.columns = listColumn.ToArray(); - - - List