2. Get ranked keywords from some text
One of the things Alchemy API is very good at is analyzing a body of text.
This first example will show you how to leverage this capability to extract topic keywords from some text,
ranked by their relevance as perceived by the Alchemy service. Note, Alchemy responses are in XML format.
For brevity, the RankedKeywords class that is used to bind to the deserialized response is not included,
but you can construct your own class from the resources provided by Alchemy on this page (scroll to the bottom Response Format (XML) section)
I’ve also excluded the TopFiveKeywords method, this simply string-ifies the text field of the first five keywords.
public RankedKeywords.Response GetRankedKeywords(String text)
RankedKeywords.Response status = new RankedKeywords.Response();
if (alchemyAPI != null)
RankedKeywords.results response = new RankedKeywords.results();
XmlSerializer serializer = new XmlSerializer(response.GetType());
var xml = alchemyAPI.TextGetRankedKeywords(text);
object deserialized = serializer.Deserialize(ToStream(alchemyAPI.TextGetRankedKeywords(conversationText)));
response = (RankedKeywords.results)deserialized;
status.Result = response;
status.Status = "SUCCESS";
Console.WriteLine("Ranked Keyword Count: " + status.Result.keywords.Count());
Console.WriteLine("Top 5 Keywords: " + TopFiveKeyWords(status.Result.keywords));
catch (Exception ex)
status.Result = null;
status.Status = "ERROR: " + ex.ToString();