/// <summary> /// Do a Bing search for Web spelling or alternative search suggestions. /// </summary> /// <param name="search">The search text.</param> /// <returns>An array of spelling or alternative suggestions or "" if no suggestions found.</returns> public static Primitive GetSpelling(Primitive search) { try { if (bNewAPI) { JsonWeb jsonWeb = cognitive.SearchRequest(search); string result = ""; int i = 1; if (null != jsonWeb.spellSuggestions) { foreach (var site in jsonWeb.spellSuggestions.value) { result += (i++).ToString() + "=" + Utilities.ArrayParse(site.text) + ";"; } } if (null != jsonWeb.relatedSearches) { foreach (var site in jsonWeb.relatedSearches.value) { result += (i++).ToString() + "=" + Utilities.ArrayParse(site.text) + ";"; } } return(Utilities.CreateArrayMap(result)); } else { var query = bing.SpellingSuggestions(search, null, cognitive.mkt, null, null, null); var sites = query.Execute(); string result = ""; int i = 1; foreach (var site in sites) { result += (i++).ToString() + "=" + Utilities.ArrayParse(site.Value) + ";"; } return(Utilities.CreateArrayMap(result)); } } catch (Exception ex) { Utilities.OnError(Utilities.GetCurrentMethod(), ex); return(""); } }
/// <summary> /// Do a Bing search for Web sites. /// </summary> /// <param name="search">The search text.</param> /// <returns>An array (up to 50) of results, index url and value description.</returns> public static Primitive GetWeb(Primitive search) { try { if (bNewAPI) { JsonWeb jsonWeb = cognitive.SearchRequest(search); if (null == jsonWeb.webPages) { return(""); } string result = ""; foreach (var site in jsonWeb.webPages.value) { result += Utilities.ArrayParse(site.url) + "=" + Utilities.ArrayParse(site.name) + ";"; } return(Utilities.CreateArrayMap(result)); } else { var query = bing.Web(search, null, null, cognitive.mkt, null, null, null, null); var sites = query.Execute(); string result = ""; foreach (var site in sites) { result += Utilities.ArrayParse(site.Url) + "=" + Utilities.ArrayParse(site.Description) + ";"; } return(Utilities.CreateArrayMap(result)); } } catch (Exception ex) { Utilities.OnError(Utilities.GetCurrentMethod(), ex); return(""); } }
/// <summary> /// Do a text spell check (proof). This is for longer text with more detailed information like in Word. /// </summary> /// <param name="text">The text to proof.</param> /// <param name="mode">A mode "Proof" (default for longer text) or "Spell" (for short or single word checks).</param> /// <returns>An array of spelling and other suggestions or "" if no suggestions found.</returns> public static Primitive GetProof(Primitive text, Primitive mode) { try { eSpellMode spellMode = ((string)mode).ToLower() == "spell" ? eSpellMode.spell : eSpellMode.proof; JsonWeb jsonWeb = cognitive.SpellRequest(text, spellMode); Primitive result = ""; int i = 1; if (null != jsonWeb.flaggedTokens) { foreach (var token in jsonWeb.flaggedTokens) { Primitive check = ""; check["token"] = token.token; check["type"] = token.type; check["offset"] = token.offset + 1; if (null != token.suggestions) { Primitive suggestions = ""; int j = 1; foreach (var suggestion in token.suggestions) { suggestions[j++] = suggestion.suggestion; } check["suggestions"] = suggestions; } result[i++] = check; } } return(Utilities.CreateArrayMap(result)); } catch (Exception ex) { Utilities.OnError(Utilities.GetCurrentMethod(), ex); return(""); } }