Skip to content

Commit a75184f

Browse files
author
Dogukan Erenel
committed
* Added date extraction to AlchemyAPI ( to combined call)
1 parent b7d65a6 commit a75184f

File tree

3 files changed

+55
-3
lines changed

3 files changed

+55
-3
lines changed

Scripts/Services/AlchemyAPI/AlchemyAPI.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ private void OnGetEntityExtractionResponse(RESTConnector.Request req, RESTConnec
135135
public bool GetCombinedCall(OnGetCombinedCall callback, string text,
136136
bool includeEntity = true,
137137
bool includeKeywoard = true,
138+
bool includeDate = true,
138139
bool includeTaxonomy = false,
139140
bool includeConcept = false,
140141
bool includeFeed = false,
@@ -155,6 +156,7 @@ public bool GetCombinedCall(OnGetCombinedCall callback, string text,
155156
throw new WatsonException("GetCombinedCall - ALCHEMY_API_KEY needs to be defined in config.json");
156157
if( !includeEntity
157158
&& !includeKeywoard
159+
&& !includeDate
158160
&& !includeTaxonomy
159161
&& !includeConcept
160162
&& !includeFeed
@@ -178,6 +180,8 @@ public bool GetCombinedCall(OnGetCombinedCall callback, string text,
178180
requestServices.Add("entity");
179181
if(includeKeywoard)
180182
requestServices.Add("keyword");
183+
if(includeKeywoard)
184+
requestServices.Add("dates");
181185
if(includeTaxonomy)
182186
requestServices.Add("taxonomy");
183187
if(includeConcept)

Scripts/Services/AlchemyAPI/DataModels.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,7 @@ public class CombinedCallData
757757
public Relation[] relations{ get; set; }
758758
public Taxonomy[] taxonomy{ get; set; }
759759
public DocEmotions[] docEmotions{ get; set; }
760+
public DateData[] dates{ get; set; }
760761

761762
public bool HasData
762763
{
@@ -801,6 +802,26 @@ public string EntityCombinedCommaSeperated
801802
return "";
802803
}
803804
}
805+
806+
public string ToLongString()
807+
{
808+
StringBuilder stringBuilder = new StringBuilder( string.Format("[CombinedCallData: status={0}, totalTransactions={1}, language={2}, text={3}", status, totalTransactions, language, text));
809+
810+
stringBuilder.Append(EntityCombinedCommaSeperated);
811+
for (int i = 0; dates != null && i < dates.Length; i++)
812+
{
813+
stringBuilder.Append(" Date: " + dates[i].DateValue.ToString());
814+
}
815+
816+
return stringBuilder.ToString();
817+
}
818+
819+
public override string ToString()
820+
{
821+
return string.Format("[CombinedCallData: status={0}, totalTransactions={1}, language={2}, text={3}, keywords={4}, entities={5}, docSentiment={6}, concepts={7}, " +
822+
"relations={8}, taxonomy={9}, docEmotions={10}, dates={11}, HasData={12}, " +
823+
"EntityCombined={13}, EntityCombinedCommaSeperated={14}]", status, totalTransactions, language, text, keywords, entities, docSentiment, concepts, relations, taxonomy, docEmotions, dates, HasData, EntityCombined, EntityCombinedCommaSeperated);
824+
}
804825
};
805826

806827

@@ -814,6 +835,32 @@ public class Keyword
814835

815836
};
816837

838+
[fsObject]
839+
public class DateData
840+
{
841+
public string text { get; set; }
842+
public string date { get; set; }
843+
844+
private System.DateTime m_dateValue = default(System.DateTime);
845+
public System.DateTime DateValue
846+
{
847+
get
848+
{
849+
if (m_dateValue == default(System.DateTime) && !string.IsNullOrEmpty(date) && date.Length > 8)
850+
{
851+
//19840101T000000
852+
System.DateTime.TryParseExact(date.Remove(8),
853+
"yyyyddMM",
854+
System.Globalization.CultureInfo.InvariantCulture,
855+
System.Globalization.DateTimeStyles.None,
856+
out m_dateValue);
857+
858+
}
859+
return m_dateValue;
860+
}
861+
}
862+
};
863+
817864
[fsObject]
818865
public class Concept
819866
{

Scripts/UnitTests/TestAlchemyAPI.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class TestAlchemyAPI : UnitTest
2828

2929
AlchemyAPI m_AlchemnyAPI = new AlchemyAPI();
3030
bool m_EntityExtractionTested = false;
31-
int m_NumberOfTestEntityExtraction = 6;
31+
int m_NumberOfTestEntityExtraction = -1;
3232

3333
public override IEnumerator RunTest()
3434
{
@@ -40,13 +40,14 @@ public override IEnumerator RunTest()
4040

4141
Log.Status("TestAlchemyAPI", "Test Started");
4242

43-
m_NumberOfTestEntityExtraction = 6;
43+
m_NumberOfTestEntityExtraction = 7;
4444
m_AlchemnyAPI.GetCombinedCall(OnGetCombinedCall, "How are you Watson?");
4545
m_AlchemnyAPI.GetCombinedCall(OnGetCombinedCall, "How can Watson help patients?");
4646
m_AlchemnyAPI.GetCombinedCall(OnGetCombinedCall, "Where is Watson?"); //Name
4747
m_AlchemnyAPI.GetCombinedCall(OnGetCombinedCall, "Where is Paris?"); //Location
4848
m_AlchemnyAPI.GetCombinedCall(OnGetCombinedCall, "Which ships are close to Karratha"); //location with name
4949
m_AlchemnyAPI.GetCombinedCall(OnGetCombinedCall, "Are you artifical intelligence?");
50+
m_AlchemnyAPI.GetCombinedCall(OnGetCombinedCall, "What happened in NewYork in december 1913 and February 1975");
5051

5152
while(! m_EntityExtractionTested )
5253
yield return null;
@@ -59,7 +60,7 @@ public override IEnumerator RunTest()
5960
private void OnGetCombinedCall(CombinedCallData combinedCallData, string data)
6061
{
6162
m_NumberOfTestEntityExtraction--;
62-
Log.Status("TestAlchemyAPI", "Remaining: {0}, original text:{1}, OnGetCombinedCall: {2}", m_NumberOfTestEntityExtraction, data, combinedCallData.EntityCombinedCommaSeperated);
63+
Log.Status("TestAlchemyAPI", "Remaining: {0}, original text:{1}, OnGetCombinedCall: {2}, OnLongResult: {3}", m_NumberOfTestEntityExtraction, data, combinedCallData.EntityCombinedCommaSeperated, combinedCallData.ToLongString());
6364

6465
if(m_NumberOfTestEntityExtraction <= 0){
6566
Test( true );

0 commit comments

Comments
 (0)