Created
November 23, 2014 14:53
-
-
Save jamessdixon/6581ea9bbb252508d34a to your computer and use it in GitHub Desktop.
Consuming IBM's Watson QA Service Using F#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #r @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Net.Http.dll" | |
| #r @"..\packages\Microsoft.AspNet.WebApi.Client.5.2.2\lib\net45\System.Net.Http.Formatting.dll" | |
| #r @"..\packages\FSharp.Data.2.1.0\lib\net40\FSharp.Data.dll" | |
| open System | |
| open FSharp.Data | |
| open System.Net.Http | |
| open System.Net.Http.Headers | |
| open System.Net.Http.Formatting | |
| open System.Collections.Generic | |
| let baseUrl = "http://wex-qa.mybluemix.net/resources/question" | |
| let userName = "youName@aol.com" | |
| let password = "xxxxxx" | |
| let authKey = userName + ":" + password | |
| let client = new HttpClient() | |
| client.DefaultRequestHeaders.Authorization <- new AuthenticationHeaderValue("Basic",authKey) | |
| let input = new Dictionary<string,string>() | |
| input.Add("question","How can I quit smoking") | |
| let content = new FormUrlEncodedContent(input) | |
| let result = client.PostAsync(baseUrl,content).Result | |
| let resultContent = result.Content.ReadAsStringAsync().Result | |
| type qaResponse = JsonProvider<".\QAResponseJson.json"> | |
| let qaAnswer = qaResponse.Parse(resultContent) | |
| qaAnswer.Question.Answers | |
| |> Seq.ofArray | |
| |> Seq.iter(fun a -> printfn "(%s)" a.Text) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "question": { | |
| "qclasslist": [ { "value": "DESCRIPTIVE" }, { "value": "FACTOID" } ], | |
| "focuslist": [ { "value": "what time" } ], | |
| "latlist": [ { "value": "time" } ], | |
| "evidencelist": [ | |
| { | |
| "value": "0.10443799197673798", | |
| "text": "Although many time zones have descriptive names used by people in them, they are least ambiguously identified by their relationship to UTC (Universal Time, Co-ordinated). UTC used to be called GMT (Greenwich Mean Time), after the Royal Observatory located in the Greenwich area of London. UTC is also sometimes called Z or Zulu time. A time may be written as e.g. 21:45Z with the Z indicating UTC. The \"Z\" is for \"zero\", and \"Zulu\" is the two-way radio pronunciation of \"Z\".", | |
| "id": "PB_EA3B3E98A364AE577C46164E0C1A7485", | |
| "title": "Time zones : Time zones", | |
| "document": "/instance/65/deepqa/v1/question/document/PB_EA3B3E98A364AE577C46164E0C1A7485/249/723", | |
| "copyright": "No copyright specified for this supporting passage or document.", | |
| "termsOfUse": "No license specified for this supporting passage or document.", | |
| "metadataMap": { | |
| "originalfile": "Time zones.html", | |
| "title": "Time zones : Time zones", | |
| "corpusName": "PB", | |
| "deepqaid": "34352728", | |
| "fileName": "/watsondata/ingestion/201411071855/eng/di/output/trec/intermediate/xml-splitTrecTrim/34352728.xml", | |
| "DOCNO": "EA3B3E98A364AE577C46164E0C1A7485" | |
| } | |
| }, | |
| { | |
| "value": "0.09459152072668076", | |
| "text": "Choose between formats by following predominant local usag.", | |
| "id": "PB_4565F1D34CFCD1C6196D5FC381209B7B", | |
| "title": "Tdf_updated : Times", | |
| "document": "/instance/65/deepqa/v1/question/document/PB_4565F1D34CFCD1C6196D5FC381209B7B/264/529", | |
| "copyright": "No copyright specified for this supporting passage or document.", | |
| "termsOfUse": "No license specified for this supporting passage or document.", | |
| "metadataMap": { | |
| "originalfile": "Tdf_updated.html", | |
| "title": "Tdf_updated : Times", | |
| "corpusName": "PB", | |
| "deepqaid": "34272125", | |
| "fileName": "/watsondata/ingestion/201411071855/eng/di/output/trec/intermediate/xml-splitTrecTrim/34272125.xml", | |
| "DOCNO": "4565F1D34CFCD1C6196D5FC381209B7B" | |
| } | |
| }, | |
| { | |
| "value": "0.08801141381263733", | |
| "text": "What time is it? Be ne na yee toe bi le? It is nine in the morning.", | |
| "id": "PB_EC2AAB2FFB4613EC6C261A99158E7062", | |
| "title": "Burmese phrasebook : Phrase list : Time : Clock time", | |
| "document": "/instance/65/deepqa/v1/question/document/PB_EC2AAB2FFB4613EC6C261A99158E7062/160/228", | |
| "copyright": "No copyright specified for this supporting passage or document.", | |
| "termsOfUse": "No license specified for this supporting passage or document.", | |
| "metadataMap": { | |
| "originalfile": "Burmese_phrasebook_updated.html", | |
| "title": "Burmese phrasebook : Phrase list : Time : Clock time", | |
| "corpusName": "PB", | |
| "deepqaid": "34314648", | |
| "fileName": "/watsondata/ingestion/201411071855/eng/di/output/trec/intermediate/xml-splitTrecTrim/34314648.xml", | |
| "DOCNO": "EC2AAB2FFB4613EC6C261A99158E7062" | |
| } | |
| }, | |
| { | |
| "value": "0.07061268389225006", | |
| "text": "What time is it? (ubani/sithini isikhathi.). one o'clock (when AM/PM is obvious) (ihora lokuqala.). two o'clock (when AM/PM is obvious) (ihora lesibili.). one o'clock AM (ihora lokuqala ekuseni.).", | |
| "id": "PB_B76943E8E78D75E5D3691E3900A8015", | |
| "title": "Zulu phrasebook : Phrase list : Time : Clock time", | |
| "document": "/instance/65/deepqa/v1/question/document/PB_B76943E8E78D75E5D3691E3900A8015/156/352", | |
| "copyright": "No copyright specified for this supporting passage or document.", | |
| "termsOfUse": "No license specified for this supporting passage or document.", | |
| "metadataMap": { | |
| "originalfile": "Zulu_phrasebook_updated.html", | |
| "title": "Zulu phrasebook : Phrase list : Time : Clock time", | |
| "corpusName": "PB", | |
| "deepqaid": "34264810", | |
| "fileName": "/watsondata/ingestion/201411071855/eng/di/output/trec/intermediate/xml-splitTrecTrim/34264810.xml", | |
| "DOCNO": "B76943E8E78D75E5D3691E3900A8015" | |
| } | |
| }, | |
| { | |
| "value": "0.06876388937234879", | |
| "text": "For English two o'clock PM,Kannada is ಮದà³à²¯à²¾à²¨à³à²¨ à²à²°à²¡à³ à²à²à²à³, and Transliteration is madyAnna eraDu gaNTe! For English midnight,Kannada is ನಡೠರಾತà³à²°à³, ಮದà³à²¯ ರಾತà³à²°à²¿, and Transliteration is naDu rAtre, madya rAtri! For English at and Transliteration is rAtre hottu, rAtri hottu! For English during day time,Kannada is, and Transliteration is beLagina hottu, beLigge!", | |
| "id": "PB_AE15B0AFC2FD3B55FBB5373F02252943", | |
| "title": "Kannada phrasebook : Kannada Phrases : Time : Clock time", | |
| "document": "/instance/65/deepqa/v1/question/document/PB_AE15B0AFC2FD3B55FBB5373F02252943/1011/1441", | |
| "copyright": "No copyright specified for this supporting passage or document.", | |
| "termsOfUse": "No license specified for this supporting passage or document.", | |
| "metadataMap": { | |
| "originalfile": "Kannada_phrasebook_updated.html", | |
| "title": "Kannada phrasebook : Kannada Phrases : Time : Clock time", | |
| "corpusName": "PB", | |
| "deepqaid": "34297639", | |
| "fileName": "/watsondata/ingestion/201411071855/eng/di/output/trec/intermediate/xml-splitTrecTrim/34297639.xml", | |
| "DOCNO": "AE15B0AFC2FD3B55FBB5373F02252943" | |
| } | |
| } | |
| ], | |
| "synonymList": [ | |
| { | |
| "partOfSpeech": "noun", | |
| "value": "time", | |
| "lemma": "time", | |
| "synSet": [ | |
| { | |
| "name": "STRICT_NORMALIZED_Aggressive_Synonym_TARGET", | |
| "synonym": [ { "isChosen": true, "value": "time3", "weight": 1.0 } ] | |
| }, | |
| { | |
| "name": "Wordnet_time-noun-1", | |
| "synonym": [ { "isChosen": true, "value": "clip", "weight": 1.0 } ] | |
| } | |
| ] | |
| }, | |
| { | |
| "partOfSpeech": "verb", | |
| "value": "is", | |
| "lemma": "be", | |
| "synSet": [ | |
| { | |
| "name": "Lemma_Expansion", | |
| "synonym": [ { "isChosen": true, "value": "be", "weight": 1.0 } ] | |
| } | |
| ] | |
| } | |
| ], | |
| "pipelineid": "1504632411", | |
| "formattedAnswer": true, | |
| "category": "", | |
| "items": 5, | |
| "status": "Complete", | |
| "id": "6DAEB445BB40402DBBC2CA121859F4F5", | |
| "questionText": "what time is it", | |
| "evidenceRequest": { "items": 1, "profile": "Yes" }, | |
| "answers": [ | |
| { | |
| "id": 0, | |
| "text": "Although many time zones have descriptive names used by people in them, they are least ambiguously identified by their relationship to UTC (Universal Time, Co-ordinated). UTC used to be called GMT (Greenwich Mean Time), after the Royal Observatory located in the Greenwich area of London. UTC is also sometimes called Z or Zulu time. A time may be written as e.g. 21:45Z with the Z indicating UTC. The \"Z\" is for \"zero\", and \"Zulu\" is the two-way radio pronunciation of \"Z\".", | |
| "pipeline": "Descriptive", | |
| "formattedText": " Although many time zones have descriptive names used by people in them, they are least ambiguously identified by their relationship to UTC (Universal Time, Co-ordinated). UTC used to be called GMT (Greenwich Mean Time), after the Royal Observatory located in the Greenwich area of London. UTC is also sometimes called Z or Zulu time. A time may be written as e.g. 21:45Z with the Z indicating UTC. The "Z" is for "zero", and "Zulu" is the two-way radio pronunciation of "Z".", | |
| "confidence": 0.10444 | |
| }, | |
| { | |
| "id": 1, | |
| "text": "Choose between formats by following predominant local usage. Ask yourself which format visitors will see in timetables, on shop doors and in newspapers. It can be assumed that time is in the local time zone. For establishments that don't close, use: 24 hours daily.", | |
| "pipeline": "Descriptive", | |
| "formattedText": "<li>Use one of these formats: <b>09:30 - 17:00</b> or <b>9:30AM - 5PM</b>. Do not use both 24- and 12-hour formats within one article. Choose between formats by following predominant local usage. Ask yourself which format visitors will see in timetables, on shop doors and in newspapers.</li>\n<li>It can be assumed that time is in the local time zone.</li>\n<li>For establishments that don't close, use: <b>24 hours daily</b>.</li>", | |
| "confidence": 0.09459 | |
| }, | |
| { | |
| "id": 2, | |
| "text": "What time is it? Be ne na yee toe bi le? It is nine in the morning.", | |
| "pipeline": "Descriptive", | |
| "formattedText": " <dfn><null>What time is it? </null><null>Be ne na yee toe bi le?\n</null><null>It is nine in the morning. </null><null>Ko nai toe bi.\n</null><null>Three-thirty PM. </null><null>Thoun na yee kwe.\n</null></dfn>", | |
| "confidence": 0.08801 | |
| }, | |
| { | |
| "id": 3, | |
| "text": "What time is it? (ubani/sithini isikhathi.). one o'clock (when AM/PM is obvious) (ihora lokuqala.). two o'clock (when AM/PM is obvious) (ihora lesibili.). one o'clock AM (ihora lokuqala ekuseni.).", | |
| "pipeline": "Descriptive", | |
| "formattedText": " <dfn><null>What time is it? </null><null>(ubani/sithini isikhathi.).</null>\n<null>one o'clock (when AM/PM is obvious) </null><null>(ihora lokuqala.).</null>\n<null>two o'clock (when AM/PM is obvious) </null><null>(ihora lesibili.).</null>\n<null>one o'clock AM </null><null>(ihora lokuqala ekuseni.).</null>\n<null>two o'clock AM </null><null>(ihora lesibili ekuseni.).</null>\n<null>noon </null><null>(ntambama.).</null>\n<null>one o'clock PM </null><null>(ihora lokuqala ntambama.).</null>\n<null>two o'clock PM </null><null>(ihora lesibili ntambama.).</null>\n<null>midnight </null><null>(phakathi kwamabili.).</null>\n</dfn>", | |
| "confidence": 0.07061 | |
| }, | |
| { "id": 4, "text": "For English two o'clock PM,Kand Transliteration is madyAnna eraDu gaNTe! For English midnight,Ka and Transliteration is naDu rAtre, madya rAtri! For English at night,Kannada , and Transliteration is rAtre hottu, rAtri hottu! For English during day time,Kannada is, and Transliteration is beLagina hottu, beu, beLigge\n</td></tr></table>", "confidence": 0.06876 } | |
| ], | |
| "errorNotifications": [ ], | |
| "passthru": "" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment