Skip to content

Commit a7caa09

Browse files
authored
Merge pull request #100 from watson-developer-cloud/feature-95-alchemyDataNews
Feature 95 alchemy data news
2 parents 02d8767 + 6b8ed30 commit a7caa09

File tree

14 files changed

+1824
-891
lines changed

14 files changed

+1824
-891
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ _2016-07-15_
77

88
## Version 0.5.0
99

10+
_2016-06-24_
11+
12+
* New: Added `AlchemyData News` abstraction
13+
14+
## Version 0.5.0
15+
1016
_2016-06-24_
1117

1218
* New: Added `Alchemy Language` abstraction

Config.json.enc

0 Bytes
Binary file not shown.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* Copyright 2015 IBM Corp. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
using UnityEngine;
19+
using System.Collections;
20+
using System.Collections.Generic;
21+
using IBM.Watson.DeveloperCloud.Services.AlchemyAPI.v1;
22+
using IBM.Watson.DeveloperCloud.Logging;
23+
using System;
24+
25+
public class ExampleAlchemyDataNews : MonoBehaviour {
26+
private AlchemyAPI m_AlchemyAPI = new AlchemyAPI();
27+
28+
void Start () {
29+
LogSystem.InstallDefaultReactors();
30+
31+
string[] returnFields = {Fields.ENRICHED_URL_ENTITIES, Fields.ENRICHED_URL_KEYWORDS};
32+
Dictionary<string, string> queryFields = new Dictionary<string, string>();
33+
queryFields.Add(Fields.ENRICHED_URL_RELATIONS_RELATION_SUBJECT_TEXT, "Obama");
34+
queryFields.Add(Fields.ENRICHED_URL_CLEANEDTITLE, "Washington");
35+
36+
if (!m_AlchemyAPI.GetNews(OnGetNews, returnFields, queryFields))
37+
Log.Debug("ExampleAlchemyData", "Failed to get news!");
38+
}
39+
40+
private void OnGetNews(NewsResponse newsData, string data)
41+
{
42+
if(newsData != null)
43+
Log.Debug("ExampleAlchemyData", "status: {0}", newsData.status);
44+
}
45+
}

Examples/ServiceExamples/Scripts/ExampleAlchemyDataNews.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Examples/ServiceExamples/Scripts/ExampleAlchemyLanguage.cs

100644100755
Lines changed: 229 additions & 227 deletions
Large diffs are not rendered by default.

Examples/ServiceExamples/Scripts/ExampleVisualRecognition.cs

100644100755
Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -21,77 +21,78 @@
2121
using IBM.Watson.DeveloperCloud.Logging;
2222
using IBM.Watson.DeveloperCloud.Utilities;
2323

24-
public class ExampleVisualRecognition : MonoBehaviour {
24+
public class ExampleVisualRecognition : MonoBehaviour
25+
{
2526
private VisualRecognition m_VisualRecognition = new VisualRecognition();
2627
private string m_classifierName = "Apples_OptionalParams";
2728
private string m_classifierID = "ApplesClassifierNameWithSpaces_73100404";
2829
private string m_classifierToDelete = "unitytestclassifier2b_37849361";
2930
private string m_imageURL = "https://upload.wikimedia.org/wikipedia/commons/e/e9/Official_portrait_of_Barack_Obama.jpg";
3031
private string m_imageTextURL = "http://i.stack.imgur.com/ZS6nH.png";
31-
32-
void Start ()
32+
33+
void Start()
3334
{
3435
LogSystem.InstallDefaultReactors();
3536

36-
// Get all classifiers
37-
if(!m_VisualRecognition.GetClassifiers(OnGetClassifiers))
37+
// Get all classifiers
38+
if (!m_VisualRecognition.GetClassifiers(OnGetClassifiers))
3839
Log.Debug("ExampleVisualRecognition", "Getting classifiers failed!");
39-
//
40-
// Find classifier by name
40+
//
41+
// Find classifier by name
4142
m_VisualRecognition.FindClassifier(m_classifierName, OnFindClassifier);
4243

43-
// Find classifier by ID
44-
if(!m_VisualRecognition.GetClassifier(m_classifierID, OnGetClassifier))
44+
// Find classifier by ID
45+
if (!m_VisualRecognition.GetClassifier(m_classifierID, OnGetClassifier))
4546
Log.Debug("ExampleVisualRecognition", "Getting classifier failed!");
4647

47-
// Delete classifier by ID
48-
if(!m_VisualRecognition.DeleteClassifier(m_classifierToDelete, OnDeleteClassifier))
48+
// Delete classifier by ID
49+
if (!m_VisualRecognition.DeleteClassifier(m_classifierToDelete, OnDeleteClassifier))
4950
Log.Debug("ExampleVisualRecognition", "Deleting classifier failed!");
5051

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

57-
// Classify get
58-
if(!m_VisualRecognition.Classify(m_imageURL, OnClassify))
58+
// Classify get
59+
if (!m_VisualRecognition.Classify(m_imageURL, OnClassify))
5960
Log.Debug("ExampleVisualRecognition", "Classify image failed!");
6061

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

6869

69-
// Detect faces get
70-
if(!m_VisualRecognition.DetectFaces(m_imageURL, OnDetectFaces))
70+
// Detect faces get
71+
if (!m_VisualRecognition.DetectFaces(m_imageURL, OnDetectFaces))
7172
Log.Debug("ExampleVisualRecogntiion", "Detect faces failed!");
7273

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

7879

7980

80-
// Recognize text get
81-
if(!m_VisualRecognition.RecognizeText(m_imageTextURL, OnRecognizeText))
81+
// Recognize text get
82+
if (!m_VisualRecognition.RecognizeText(m_imageTextURL, OnRecognizeText))
8283
Log.Debug("ExampleVisualRecognition", "Recognize text failed!");
8384

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

90-
private void OnGetClassifiers (GetClassifiersTopLevelBrief classifiers)
91+
private void OnGetClassifiers(GetClassifiersTopLevelBrief classifiers)
9192
{
92-
if(classifiers != null && classifiers.classifiers.Length > 0)
93+
if (classifiers != null && classifiers.classifiers.Length > 0)
9394
{
94-
foreach(GetClassifiersPerClassifierBrief classifier in classifiers.classifiers)
95+
foreach (GetClassifiersPerClassifierBrief classifier in classifiers.classifiers)
9596
{
9697
Log.Debug("ExampleVisualRecognition", "Classifier: " + classifier.name + ", " + classifier.classifier_id);
9798
}
@@ -104,7 +105,7 @@ private void OnGetClassifiers (GetClassifiersTopLevelBrief classifiers)
104105

105106
private void OnFindClassifier(GetClassifiersPerClassifierVerbose classifier)
106107
{
107-
if(classifier != null)
108+
if (classifier != null)
108109
{
109110
Log.Debug("ExampleVisualRecognition", "Classifier " + m_classifierName + " found! ClassifierID: " + classifier.classifier_id);
110111
}
@@ -116,7 +117,7 @@ private void OnFindClassifier(GetClassifiersPerClassifierVerbose classifier)
116117

117118
private void OnGetClassifier(GetClassifiersPerClassifierVerbose classifier)
118119
{
119-
if(classifier != null)
120+
if (classifier != null)
120121
{
121122
Log.Debug("ExampleVisualRecognition", "Classifier " + m_classifierID + " found! Classifier name: " + classifier.name);
122123
}
@@ -128,7 +129,7 @@ private void OnGetClassifier(GetClassifiersPerClassifierVerbose classifier)
128129

129130
private void OnDeleteClassifier(bool success)
130131
{
131-
if(success)
132+
if (success)
132133
{
133134
Log.Debug("ExampleVisualRecognition", "Deleted classifier " + m_classifierToDelete);
134135
}
@@ -137,10 +138,10 @@ private void OnDeleteClassifier(bool success)
137138
Log.Debug("ExampleVisualRecognition", "Failed to delete classifier by ID!");
138139
}
139140
}
140-
141+
141142
private void OnTrainClassifier(GetClassifiersPerClassifierVerbose classifier)
142143
{
143-
if(classifier != null)
144+
if (classifier != null)
144145
{
145146
Log.Debug("ExampleVisualRecognition", "Classifier is training! " + classifier);
146147
}
@@ -152,16 +153,16 @@ private void OnTrainClassifier(GetClassifiersPerClassifierVerbose classifier)
152153

153154
private void OnClassify(ClassifyTopLevelMultiple classify)
154155
{
155-
if(classify != null)
156+
if (classify != null)
156157
{
157158
Log.Debug("ExampleVisualRecognition", "images processed: " + classify.images_processed);
158-
foreach(ClassifyTopLevelSingle image in classify.images)
159+
foreach (ClassifyTopLevelSingle image in classify.images)
159160
{
160161
Log.Debug("ExampleVisualRecognition", "\tsource_url: " + image.source_url + ", resolved_url: " + image.resolved_url);
161-
foreach(ClassifyPerClassifier classifier in image.classifiers)
162+
foreach (ClassifyPerClassifier classifier in image.classifiers)
162163
{
163164
Log.Debug("ExampleVisualRecognition", "\t\tclassifier_id: " + classifier.classifier_id + ", name: " + classifier.name);
164-
foreach(ClassResult classResult in classifier.classes)
165+
foreach (ClassResult classResult in classifier.classes)
165166
Log.Debug("ExampleVisualRecognition", "\t\t\tclass: " + classResult.m_class + ", score: " + classResult.score + ", type_hierarchy: " + classResult.type_hierarchy);
166167
}
167168
}
@@ -174,13 +175,13 @@ private void OnClassify(ClassifyTopLevelMultiple classify)
174175

175176
private void OnDetectFaces(FacesTopLevelMultiple multipleImages)
176177
{
177-
if(multipleImages != null)
178+
if (multipleImages != null)
178179
{
179180
Log.Debug("ExampleVisualRecognition", "images processed: {0}", multipleImages.images_processed);
180-
foreach(FacesTopLevelSingle faces in multipleImages.images)
181+
foreach (FacesTopLevelSingle faces in multipleImages.images)
181182
{
182183
Log.Debug("ExampleVisualRecognition", "\tsource_url: {0}, resolved_url: {1}", faces.source_url, faces.resolved_url);
183-
foreach(OneFaceResult face in faces.faces)
184+
foreach (OneFaceResult face in faces.faces)
184185
{
185186
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);
186187
Log.Debug("ExampleVisulaRecognition", "\t\tGender: {0}, Score: {1}", face.gender.gender, face.gender.score);
@@ -197,14 +198,14 @@ private void OnDetectFaces(FacesTopLevelMultiple multipleImages)
197198

198199
private void OnRecognizeText(TextRecogTopLevelMultiple multipleImages)
199200
{
200-
if(multipleImages != null)
201+
if (multipleImages != null)
201202
{
202203
Log.Debug("ExampleVisualRecognition", "images processed: {0}", multipleImages.images_processed);
203-
foreach(TextRecogTopLevelSingle texts in multipleImages.images)
204+
foreach (TextRecogTopLevelSingle texts in multipleImages.images)
204205
{
205206
Log.Debug("ExampleVisualRecognition", "\tsource_url: {0}, resolved_url: {1}", texts.source_url, texts.resolved_url);
206207
Log.Debug("ExampleVisualRecognition", "\ttext: {0}", texts.text);
207-
foreach(TextRecogOneWord text in texts.words)
208+
foreach (TextRecogOneWord text in texts.words)
208209
{
209210
Log.Debug("ExampleVisulaRecognition", "\t\ttext location: {0}, {1}, {2}, {3}", text.location.left, text.location.top, text.location.width, text.location.height);
210211
Log.Debug("ExampleVisulaRecognition", "\t\tLine number: {0}", text.line_number);

Examples/ServiceExamples/ServiceExamples.unity

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,46 @@ Transform:
493493
m_Children: []
494494
m_Father: {fileID: 0}
495495
m_RootOrder: 4
496+
--- !u!1 &1310649318
497+
GameObject:
498+
m_ObjectHideFlags: 0
499+
m_PrefabParentObject: {fileID: 0}
500+
m_PrefabInternal: {fileID: 0}
501+
serializedVersion: 4
502+
m_Component:
503+
- 4: {fileID: 1310649320}
504+
- 114: {fileID: 1310649319}
505+
m_Layer: 0
506+
m_Name: ExampleAlchemyDataNews
507+
m_TagString: Untagged
508+
m_Icon: {fileID: 0}
509+
m_NavMeshLayer: 0
510+
m_StaticEditorFlags: 0
511+
m_IsActive: 1
512+
--- !u!114 &1310649319
513+
MonoBehaviour:
514+
m_ObjectHideFlags: 0
515+
m_PrefabParentObject: {fileID: 0}
516+
m_PrefabInternal: {fileID: 0}
517+
m_GameObject: {fileID: 1310649318}
518+
m_Enabled: 1
519+
m_EditorHideFlags: 0
520+
m_Script: {fileID: 11500000, guid: c46efb6361e73cf47b69febdae951658, type: 3}
521+
m_Name:
522+
m_EditorClassIdentifier:
523+
--- !u!4 &1310649320
524+
Transform:
525+
m_ObjectHideFlags: 0
526+
m_PrefabParentObject: {fileID: 0}
527+
m_PrefabInternal: {fileID: 0}
528+
m_GameObject: {fileID: 1310649318}
529+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
530+
m_LocalPosition: {x: 0, y: 0, z: 0}
531+
m_LocalScale: {x: 1, y: 1, z: 1}
532+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
533+
m_Children: []
534+
m_Father: {fileID: 0}
535+
m_RootOrder: 12
496536
--- !u!1 &1713392457
497537
GameObject:
498538
m_ObjectHideFlags: 0

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Use this SDK to build Watson-powered applications in Unity. It comes with a set
1919
* [Conversation](#conversation)
2020
* [Visual Recognition](#visual-recognition)
2121
* [Alchemy Language](#alchemy-language)
22+
* [AlchemyData News](#alchemy-data-news)
2223
* [Personality Insights](#personality-insights)
2324
* [Document Conversion](#document-conversion)
2425
* [Developing a basic application in one minute](#developing-a-basic-application-in-one-minute)
@@ -1365,6 +1366,7 @@ The IBM Watson™ [Document conversion][document_conversion] service converts a
13651366

13661367
#### Converting Documents
13671368
Convert a single document
1369+
13681370
```cs
13691371
private DocumentConversion m_DocumentConversion = new DocumentConversion();
13701372

@@ -1413,6 +1415,34 @@ private DocumentConversion m_DocumentConversion = new DocumentConversion();
14131415
}
14141416
```
14151417

1418+
### AlchemyData News
1419+
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.
1420+
1421+
#### Getting News
1422+
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.
1423+
1424+
```
1425+
private AlchemyAPI m_AlchemyAPI = new AlchemyAPI();
1426+
1427+
void Start()
1428+
{
1429+
string[] returnFields = {Fields.ENRICHED_URL_ENTITIES, Fields.ENRICHED_URL_KEYWORDS};
1430+
Dictionary<string, string> queryFields = new Dictionary<string, string>();
1431+
queryFields.Add(Fields.ENRICHED_URL_RELATIONS_RELATION_SUBJECT_TEXT, "Obama");
1432+
queryFields.Add(Fields.ENRICHED_URL_CLEANEDTITLE, "Washington");
1433+
1434+
if (!m_AlchemyAPI.GetNews(OnGetNews, returnFields, queryFields))
1435+
Log.Debug("ExampleAlchemyData", "Failed to get news!");
1436+
}
1437+
1438+
void OnGetNews(NewsResponse newsData, string data)
1439+
{
1440+
// Access requested fields
1441+
if(newsData != null)
1442+
Log.Debug("ExampleAlchemyData", "status: {0}", newsData.status);
1443+
}
1444+
```
1445+
14161446
## Developing a basic application in one minute
14171447
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:
14181448

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

14621492
[alchemy_language]: http://www.alchemyapi.com/products/alchemylanguage
1493+
[alchemyData_news]: http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/alchemy-data-news.html
14631494
[sentiment_analysis]: http://www.alchemyapi.com/products/alchemylanguage/sentiment-analysis
14641495
[tone_analyzer]: http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/doc/tone-analyzer/
14651496
[tradeoff_analytics]: http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/doc/tradeoff-analytics/

0 commit comments

Comments
 (0)