Click here to Skip to main content
Click here to Skip to main content

Zemanta text analysis

, 29 Aug 2013
Rate this:
Please Sign up or sign in to vote.
Zemanta API is state of the art in text analysis.

Introduction

One may be interested in analyzing a text; say for a given text input, you are interested in getting the entities, related images, articles, hyperlinks, and tags. In such cases you can make use of a simple and effective text analysis service named Zemanta.  

Zemanta allows developers to query for contextual metadata about a given text. It gives us back with articles, keywords, images, in-text links, and optional component categories. All we need to do from the application side is submit either as HTML or plain text and you will receive back various suggestions. 

Using the code

Below is the code block which makes an HTTP POST request , passing in the following parameters:

  1. method - zemanta.suggest
  2. api_key - need to pass in the valid Zemanta API key. Developers need to register for the API key. Please follow the registration by navigating the URL - http://developer.zemanta.com/ 
  3. text - The input text, either plain or HTML content. Note:  Do not send full HTML pages since navigational elements will be considered part of content.
public class ZemantaService
{
    public delegate void ZementaDelegate(string response);
    public event ZementaDelegate ZementaEvent;

    public void GetZementa(string contnet, string zemantaApiKey)
    {
        Uri address = new Uri("http://api.zemanta.com/services/rest/0.0/");
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.Append("method=" + HttpUtility.UrlEncode("zemanta.suggest"));
        stringBuilder.Append("&api_key=" + HttpUtility.UrlEncode(zemantaApiKey));
        stringBuilder.Append("&text=" + HttpUtility.UrlEncode(contnet));
        stringBuilder.Append("&format=" + HttpUtility.UrlEncode("JSON"));

        try
        {
            WebClient wc = new WebClient();
            wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
            wc.UploadStringCompleted += new UploadStringCompletedEventHandler(wc_UploadStringCompleted);
            wc.UploadStringAsync(address, stringBuilder.ToString());
        }
        catch (Exception ex)
        {
            var we = ex.InnerException as WebException;
            if (we != null)
            {
                var resp = we.Response as HttpWebResponse;
                var code = resp.StatusCode;
                throw new Exception(string.Format(
                  "Response Callback Exception raised! Message:{0}" + we.Message));
            }
            else
                throw;
        }
    }

    void wc_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
    {
        if (ZementaEvent != null)
            ZementaEvent(e.Result);
    }
}

Points of Interest

I saved lot of time by using the Zemanta service for text analysis. I hope it might help other developers too as we need not worry about querying the related contents for a give text input. For more information about Zemanta, here you go - http://developer.zemanta.com/.

History

  • Version 1.0 - 08/22/2013.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Ranjan.D
Web Developer
United States United States
Profile
 
Around 9 years of professional software development experience in analysis, design, development, testing and implementation of enterprise web applications for healthcare domain with good exposure to object-oriented design, software architectures, design patterns, test-driven development and agile practices.
 
In Brief
 
Analyse and create High Level , Detailed Design documents.
Use UML Modelling and create Use Cases , Class Diagram , Component Model , Deployment Diagram, Sequence Diagram in HLD.
 
Area of Working : Dedicated to Microsoft .NET Technologies
Experience with : C# , J2EE , J2ME, Windows Phone 8, Windows Store App
Proficient in: C# , XML , XHTML, XML, HTML5, Javascript, Jquery, CSS, SQL, LINQ, EF
 
Software Development
 
Database: Microsoft SQL Server, FoxPro
Development Frameworks: Microsoft .NET 1.1, 2.0, 3.5, 4.5
UI: Windows Forms, Windows Presentation Foundation, ASP.NET Web Forms and ASP.NET MVC3, MVC4
Coding: WinForm , Web Development, Windows Phone, WinRT Programming, WCF, WebAPI
 
Healthcare Domain Experience
 
CCD, CCR, QRDA, HIE, HL7 V3, Healthcare Interoperability
 
Others:
 
TTD, BDD
 
Education
 
B.E (Computer Science)
 
CodeProject Contest So Far:
 
1. Windows Azure Developer Contest - HealthReunion - A Windows Azure based healthcare product , link - http://www.codeproject.com/Articles/582535/HealthReunion-A-Windows-Azure-based-healthcare-pro
 
2. DnB Developer Contest - DNB Business Lookup and Analytics , link - http://www.codeproject.com/Articles/618344/DNB-Business-Lookup-and-Analytics
 
3. Intel Ultrabook Contest - Journey from development, code signing to publishing my App to Intel AppUp , link - http://www.codeproject.com/Articles/517482/Journey-from-development-code-signing-to-publishin
 
4. Intel App Innovation Contest 2013 - eHealthCare - http://www.codeproject.com/Articles/635815/eHealthCare
 
5. Grand Prize Winner of CodeProject HTML5 &CSS3 Article Content 2014

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 29 Aug 2013
Article Copyright 2013 by Ranjan.D
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid