Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ _2016-07-15_

## Version 0.5.0

_2016-06-24_

* New: Added `AlchemyData News` abstraction

## Version 0.5.0

_2016-06-24_

* New: Added `Alchemy Language` abstraction
Expand Down
Binary file modified Config.json.enc
Binary file not shown.
45 changes: 45 additions & 0 deletions Examples/ServiceExamples/Scripts/ExampleAlchemyDataNews.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* 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 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();

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

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);
}
}
12 changes: 12 additions & 0 deletions Examples/ServiceExamples/Scripts/ExampleAlchemyDataNews.cs.meta

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

456 changes: 229 additions & 227 deletions Examples/ServiceExamples/Scripts/ExampleAlchemyLanguage.cs
100644 → 100755

Large diffs are not rendered by default.

93 changes: 47 additions & 46 deletions Examples/ServiceExamples/Scripts/ExampleVisualRecognition.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -21,77 +21,78 @@
using IBM.Watson.DeveloperCloud.Logging;
using IBM.Watson.DeveloperCloud.Utilities;

public class ExampleVisualRecognition : MonoBehaviour {
public class ExampleVisualRecognition : MonoBehaviour
{
private VisualRecognition m_VisualRecognition = new VisualRecognition();
private string m_classifierName = "Apples_OptionalParams";
private string m_classifierID = "ApplesClassifierNameWithSpaces_73100404";
private string m_classifierToDelete = "unitytestclassifier2b_37849361";
private string m_imageURL = "https://upload.wikimedia.org/wikipedia/commons/e/e9/Official_portrait_of_Barack_Obama.jpg";
private string m_imageTextURL = "http://i.stack.imgur.com/ZS6nH.png";
void Start ()

void Start()
{
LogSystem.InstallDefaultReactors();

// Get all classifiers
if(!m_VisualRecognition.GetClassifiers(OnGetClassifiers))
// Get all classifiers
if (!m_VisualRecognition.GetClassifiers(OnGetClassifiers))
Log.Debug("ExampleVisualRecognition", "Getting classifiers failed!");
//
// Find classifier by name
//
// Find classifier by name
m_VisualRecognition.FindClassifier(m_classifierName, OnFindClassifier);

// Find classifier by ID
if(!m_VisualRecognition.GetClassifier(m_classifierID, OnGetClassifier))
// Find classifier by ID
if (!m_VisualRecognition.GetClassifier(m_classifierID, OnGetClassifier))
Log.Debug("ExampleVisualRecognition", "Getting classifier failed!");

// Delete classifier by ID
if(!m_VisualRecognition.DeleteClassifier(m_classifierToDelete, OnDeleteClassifier))
// Delete classifier by ID
if (!m_VisualRecognition.DeleteClassifier(m_classifierToDelete, OnDeleteClassifier))
Log.Debug("ExampleVisualRecognition", "Deleting classifier failed!");

// Train classifier
// Train classifier
string m_positiveExamplesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/giraffe_positive_examples.zip";
string m_negativeExamplesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/negative_examples.zip";
if(!m_VisualRecognition.TrainClassifier("unity-test-classifier5", "giraffe", m_positiveExamplesPath, m_negativeExamplesPath, OnTrainClassifier))
if (!m_VisualRecognition.TrainClassifier("unity-test-classifier5", "giraffe", m_positiveExamplesPath, m_negativeExamplesPath, OnTrainClassifier))
Log.Debug("ExampleVisualRecognition", "Train classifier failed!");

// Classify get
if(!m_VisualRecognition.Classify(m_imageURL, OnClassify))
// Classify get
if (!m_VisualRecognition.Classify(m_imageURL, OnClassify))
Log.Debug("ExampleVisualRecognition", "Classify image failed!");

// Classify post image
// Classify post image
string m_imagesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/obama.jpg";
string[] m_owners = {"IBM", "me"};
string[] m_classifierIDs = {"default"};
if(!m_VisualRecognition.Classify(OnClassify, m_imagesPath, m_owners, m_classifierIDs, 0.5f))
string[] m_owners = { "IBM", "me" };
string[] m_classifierIDs = { "default" };
if (!m_VisualRecognition.Classify(OnClassify, m_imagesPath, m_owners, m_classifierIDs, 0.5f))
Log.Debug("ExampleVisualRecognition", "Classify image failed!");


// Detect faces get
if(!m_VisualRecognition.DetectFaces(m_imageURL, OnDetectFaces))
// Detect faces get
if (!m_VisualRecognition.DetectFaces(m_imageURL, OnDetectFaces))
Log.Debug("ExampleVisualRecogntiion", "Detect faces failed!");

// Detect faces post image
// Detect faces post image
string m_faceExamplePath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/obama.jpg";
if(!m_VisualRecognition.DetectFaces(OnDetectFaces, m_faceExamplePath))
if (!m_VisualRecognition.DetectFaces(OnDetectFaces, m_faceExamplePath))
Log.Debug("ExampleVisualRecognition", "Detect faces failed!");



// Recognize text get
if(!m_VisualRecognition.RecognizeText(m_imageTextURL, OnRecognizeText))
// Recognize text get
if (!m_VisualRecognition.RecognizeText(m_imageTextURL, OnRecognizeText))
Log.Debug("ExampleVisualRecognition", "Recognize text failed!");

// Recognize text post image
// Recognize text post image
string m_textExamplePath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/from_platos_apology.png";
if(!m_VisualRecognition.RecognizeText(OnRecognizeText, m_textExamplePath))
if (!m_VisualRecognition.RecognizeText(OnRecognizeText, m_textExamplePath))
Log.Debug("ExampleVisualRecognition", "Recognize text failed!");
}
}

private void OnGetClassifiers (GetClassifiersTopLevelBrief classifiers)
private void OnGetClassifiers(GetClassifiersTopLevelBrief classifiers)
{
if(classifiers != null && classifiers.classifiers.Length > 0)
if (classifiers != null && classifiers.classifiers.Length > 0)
{
foreach(GetClassifiersPerClassifierBrief classifier in classifiers.classifiers)
foreach (GetClassifiersPerClassifierBrief classifier in classifiers.classifiers)
{
Log.Debug("ExampleVisualRecognition", "Classifier: " + classifier.name + ", " + classifier.classifier_id);
}
Expand All @@ -104,7 +105,7 @@ private void OnGetClassifiers (GetClassifiersTopLevelBrief classifiers)

private void OnFindClassifier(GetClassifiersPerClassifierVerbose classifier)
{
if(classifier != null)
if (classifier != null)
{
Log.Debug("ExampleVisualRecognition", "Classifier " + m_classifierName + " found! ClassifierID: " + classifier.classifier_id);
}
Expand All @@ -116,7 +117,7 @@ private void OnFindClassifier(GetClassifiersPerClassifierVerbose classifier)

private void OnGetClassifier(GetClassifiersPerClassifierVerbose classifier)
{
if(classifier != null)
if (classifier != null)
{
Log.Debug("ExampleVisualRecognition", "Classifier " + m_classifierID + " found! Classifier name: " + classifier.name);
}
Expand All @@ -128,7 +129,7 @@ private void OnGetClassifier(GetClassifiersPerClassifierVerbose classifier)

private void OnDeleteClassifier(bool success)
{
if(success)
if (success)
{
Log.Debug("ExampleVisualRecognition", "Deleted classifier " + m_classifierToDelete);
}
Expand All @@ -137,10 +138,10 @@ private void OnDeleteClassifier(bool success)
Log.Debug("ExampleVisualRecognition", "Failed to delete classifier by ID!");
}
}

private void OnTrainClassifier(GetClassifiersPerClassifierVerbose classifier)
{
if(classifier != null)
if (classifier != null)
{
Log.Debug("ExampleVisualRecognition", "Classifier is training! " + classifier);
}
Expand All @@ -152,16 +153,16 @@ private void OnTrainClassifier(GetClassifiersPerClassifierVerbose classifier)

private void OnClassify(ClassifyTopLevelMultiple classify)
{
if(classify != null)
if (classify != null)
{
Log.Debug("ExampleVisualRecognition", "images processed: " + classify.images_processed);
foreach(ClassifyTopLevelSingle image in classify.images)
foreach (ClassifyTopLevelSingle image in classify.images)
{
Log.Debug("ExampleVisualRecognition", "\tsource_url: " + image.source_url + ", resolved_url: " + image.resolved_url);
foreach(ClassifyPerClassifier classifier in image.classifiers)
foreach (ClassifyPerClassifier classifier in image.classifiers)
{
Log.Debug("ExampleVisualRecognition", "\t\tclassifier_id: " + classifier.classifier_id + ", name: " + classifier.name);
foreach(ClassResult classResult in classifier.classes)
foreach (ClassResult classResult in classifier.classes)
Log.Debug("ExampleVisualRecognition", "\t\t\tclass: " + classResult.m_class + ", score: " + classResult.score + ", type_hierarchy: " + classResult.type_hierarchy);
}
}
Expand All @@ -174,13 +175,13 @@ private void OnClassify(ClassifyTopLevelMultiple classify)

private void OnDetectFaces(FacesTopLevelMultiple multipleImages)
{
if(multipleImages != null)
if (multipleImages != null)
{
Log.Debug("ExampleVisualRecognition", "images processed: {0}", multipleImages.images_processed);
foreach(FacesTopLevelSingle faces in multipleImages.images)
foreach (FacesTopLevelSingle faces in multipleImages.images)
{
Log.Debug("ExampleVisualRecognition", "\tsource_url: {0}, resolved_url: {1}", faces.source_url, faces.resolved_url);
foreach(OneFaceResult face in faces.faces)
foreach (OneFaceResult face in faces.faces)
{
Log.Debug("ExampleVisulaRecognition", "\t\tFace location: {0}, {1}, {2}, {3}", face.face_location.left, face.face_location.top, face.face_location.width, face.face_location.height);
Log.Debug("ExampleVisulaRecognition", "\t\tGender: {0}, Score: {1}", face.gender.gender, face.gender.score);
Expand All @@ -197,14 +198,14 @@ private void OnDetectFaces(FacesTopLevelMultiple multipleImages)

private void OnRecognizeText(TextRecogTopLevelMultiple multipleImages)
{
if(multipleImages != null)
if (multipleImages != null)
{
Log.Debug("ExampleVisualRecognition", "images processed: {0}", multipleImages.images_processed);
foreach(TextRecogTopLevelSingle texts in multipleImages.images)
foreach (TextRecogTopLevelSingle texts in multipleImages.images)
{
Log.Debug("ExampleVisualRecognition", "\tsource_url: {0}, resolved_url: {1}", texts.source_url, texts.resolved_url);
Log.Debug("ExampleVisualRecognition", "\ttext: {0}", texts.text);
foreach(TextRecogOneWord text in texts.words)
foreach (TextRecogOneWord text in texts.words)
{
Log.Debug("ExampleVisulaRecognition", "\t\ttext location: {0}, {1}, {2}, {3}", text.location.left, text.location.top, text.location.width, text.location.height);
Log.Debug("ExampleVisulaRecognition", "\t\tLine number: {0}", text.line_number);
Expand Down
40 changes: 40 additions & 0 deletions Examples/ServiceExamples/ServiceExamples.unity
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,46 @@ Transform:
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 4
--- !u!1 &1310649318
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 4
m_Component:
- 4: {fileID: 1310649320}
- 114: {fileID: 1310649319}
m_Layer: 0
m_Name: ExampleAlchemyDataNews
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1310649319
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1310649318}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c46efb6361e73cf47b69febdae951658, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!4 &1310649320
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1310649318}
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: 12
--- !u!1 &1713392457
GameObject:
m_ObjectHideFlags: 0
Expand Down
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Use this SDK to build Watson-powered applications in Unity. It comes with a set
* [Conversation](#conversation)
* [Visual Recognition](#visual-recognition)
* [Alchemy Language](#alchemy-language)
* [AlchemyData News](#alchemy-data-news)
* [Personality Insights](#personality-insights)
* [Document Conversion](#document-conversion)
* [Developing a basic application in one minute](#developing-a-basic-application-in-one-minute)
Expand Down Expand Up @@ -1365,6 +1366,7 @@ The IBM Watson™ [Document conversion][document_conversion] service converts a

#### Converting Documents
Convert a single document

```cs
private DocumentConversion m_DocumentConversion = new DocumentConversion();

Expand Down Expand Up @@ -1413,6 +1415,34 @@ private DocumentConversion m_DocumentConversion = new DocumentConversion();
}
```

### AlchemyData News
Use the [AlchemyData News][alchemyData_news] service to provide news and blog content enriched with natural language processing to allow for highly targeted search and trend analysis. Now you can query the world's news sources and blogs like a database.

#### Getting News
AlchemyData News indexes 250k to 300k English language news and blog articles every day with historical search available for the past 60 days. You can query the News API directly with no need to acquire, enrich and store the data yourself - enabling you to go beyond simple keyword-based searches. You can request which fields to return and filter fields by string. All available fields can be accessed using Fields constants in the AlchemyData News Data Model.

```
private AlchemyAPI m_AlchemyAPI = new AlchemyAPI();

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

if (!m_AlchemyAPI.GetNews(OnGetNews, returnFields, queryFields))
Log.Debug("ExampleAlchemyData", "Failed to get news!");
}

void OnGetNews(NewsResponse newsData, string data)
{
// Access requested fields
if(newsData != null)
Log.Debug("ExampleAlchemyData", "status: {0}", newsData.status);
}
```

## Developing a basic application in one minute
You can quickly develop a basic application that uses the Speech to Text service and the Natural Language Classifier service by using the prefabs that come with the SDK. Ensure that you prepare the test data before you complete the the following steps:

Expand Down Expand Up @@ -1460,6 +1490,7 @@ See [CONTRIBUTING.md](.github/CONTRIBUTING.md).
[natural_language_classifier]: http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/doc/nl-classifier/

[alchemy_language]: http://www.alchemyapi.com/products/alchemylanguage
[alchemyData_news]: http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/alchemy-data-news.html
[sentiment_analysis]: http://www.alchemyapi.com/products/alchemylanguage/sentiment-analysis
[tone_analyzer]: http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/doc/tone-analyzer/
[tradeoff_analytics]: http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/doc/tradeoff-analytics/
Expand Down
Loading