Source

Repustate Clients / c# / TestRepustateClient.cs

Full commit
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
using System.Drawing;

namespace RepustateApplication
{
    class RepustateClientTest
    {
        static void Main(string[] args)
        {
            runTests();
        }        

        public static void runTests()
        {
            try
            {
                //sentimentTest();
                //sentimentBulkTest();
                //adjectivesTest();
                //verbsTest();
                //cleanHTMLTest();
                //ngramsTest();
                //dateExtractTest();
                powerpointTest();

            } 
		    catch (WebException e)
            {
                Console.WriteLine("WebException raised!");
                Console.WriteLine("\n{0}", e.Message);
                Console.WriteLine("\n{0}", e.Status);
                Console.Read();
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception raised!");
                Console.WriteLine("Source :{0} ", e.Source);
                Console.WriteLine("Message :{0} ", e.Message);
                Console.Read();
            }
        }

	    public static void powerpointTest() 
	    {
		    Dictionary<string, string> powerpointMap = new Dictionary<string, string>();
		    powerpointMap.Add("title", "ReportSample");
		    powerpointMap.Add("author", "TestAuthor");		    

		    powerpointMap.Add("slide_1_title", "Title1");
		    powerpointMap.Add("slide_1_notes", "Slide 1's Notes Data");
            powerpointMap.Add("slide_1_image", ImageToBase64String(Image.FromFile("test_image.jpg")));            
		
    		powerpointMap.Add("slide_2_title", "Slide Title Number 2");
    		powerpointMap.Add("slide_2_notes", "This is slide number two's notes section");
    		powerpointMap.Add("slide_2_image", ImageToBase64String(Image.FromFile("test_image.jpg")));
    		
    		powerpointMap.Add("slide_3_title", "Slide Title Number 3");
    		powerpointMap.Add("slide_3_notes", "This is slide number three's notes section");
    		powerpointMap.Add("slide_3_image", ImageToBase64String(Image.FromFile("test_image.jpg")));
    		
            RepustateClient.savePowerpointSlides(powerpointMap, "acsharp.ppt");
	    }

        public static string ImageToBase64String(Image image)
        {
            using (MemoryStream stream = new MemoryStream())
            {
                image.Save(stream, image.RawFormat);
                return Convert.ToBase64String(stream.ToArray());
            }
        }
	
	    public static void dateExtractTest() 
	    {
		    Dictionary<string, string> dateDataMap = new Dictionary<string, string>();
		    dateDataMap.Add("relative_date", "2011-11-11");
		    dateDataMap.Add("text", "I can't wait to go to school tomorrow");
		    string sentimentOutputXML = RepustateClient.getExtractedDates(RepustateClient.FORMAT_XML, dateDataMap);
		    Console.WriteLine(sentimentOutputXML);            

		    string sentimentOutputJSON = RepustateClient.getExtractedDates(RepustateClient.FORMAT_JSON, dateDataMap);
		    Console.WriteLine(sentimentOutputJSON);

            Console.Read();
	    }
	
	    public static void ngramsTest() 
	    {
		    Dictionary<string, string> ngramsDataMap = new Dictionary<string, string>();
		    ngramsDataMap.Add("max", "4");
		    ngramsDataMap.Add("min", "2");
		    ngramsDataMap.Add("freq", "2");
		    ngramsDataMap.Add("stopwords", "1");
    		string sentimentOutputXML = RepustateClient.getNgrams(RepustateClient.FORMAT_XML, ngramsDataMap, "http://techcrunch.com/2010/05/07/oneriot/");
    		Console.WriteLine(sentimentOutputXML);
    		string sentimentOutputJSON = RepustateClient.getNgrams(RepustateClient.FORMAT_JSON, ngramsDataMap, "http://techcrunch.com/2010/05/07/oneriot/");
    		Console.WriteLine(sentimentOutputJSON);
		
		    //Test 2 : No url, but text only
		/*    ngramsDataMap.Add("text", "Today, OneRiot is rolling out a major revamp of both its site and some of its underlying architecture. T" +
									    "he site itself looks much nicer and is better organized (sort of like a realtime Techmeme, in a way), but" +
									    " OneRiot’s site is just a fraction of what they do. That’s why the underlying architecture elements are much " +
									    "more interesting. In particular, OneRiot is today launching a new Trending Topics Engine, which it says is " +
									    "the fastest and most complete way to find the best things being shared on the web.");
		
		    string sentimentOutputXML = RepustateClient.getNgrams(RepustateClient.FORMAT_XML, ngramsDataMap, null);
		    Console.WriteLine(sentimentOutputXML);
		    string sentimentOutputJSON = RepustateClient.getNgrams(RepustateClient.FORMAT_JSON, ngramsDataMap, null);
		    Console.WriteLine(sentimentOutputJSON);
	    */
            Console.Read();
        }
		
	    public static void cleanHTMLTest() 
	    {
		    string sentimentOutputXML = RepustateClient.getCleanHTML(RepustateClient.FORMAT_XML, null,  "http://techcrunch.com/2010/05/07/oneriot/");
		    Console.WriteLine(sentimentOutputXML);
		    string sentimentOutputJSON = RepustateClient.getCleanHTML(RepustateClient.FORMAT_JSON, null,  "http://techcrunch.com/2010/05/07/oneriot/");
		    Console.WriteLine(sentimentOutputJSON);

            Console.Read();
	    }
	
	    public static void verbsTest() 
	    {
		    Dictionary<string, string> verbDataMap = new Dictionary<string, string>();
    //		verbDataMap.Add("text", "This man is buying iPads.");
		    verbDataMap.Add("cloud", "0");
		    verbDataMap.Add("url", "http://techcrunch.com/2010/05/07/oneriot/");
		    string sentimentOutputXML = RepustateClient.getVerbs(RepustateClient.FORMAT_XML, verbDataMap);
		    Console.WriteLine(sentimentOutputXML);
		    string sentimentOutputJSON = RepustateClient.getVerbs(RepustateClient.FORMAT_JSON, verbDataMap);
		    Console.WriteLine(sentimentOutputJSON);
	    
            Console.Read();
        }
	
	    public static void adjectivesTest() 
	    {
		    Dictionary<string, string> adjDataMap = new Dictionary<string, string>();
    //		adjDataMap.Add("text", "This is a big block of new text");
		    adjDataMap.Add("cloud", "1");
		    adjDataMap.Add("url", "http://techcrunch.com/2010/05/07/oneriot/");
		    string sentimentOutputXML = RepustateClient.getAdjectives(RepustateClient.FORMAT_XML, adjDataMap);
		    Console.WriteLine(sentimentOutputXML);
		    string sentimentOutputJSON = RepustateClient.getAdjectives(RepustateClient.FORMAT_JSON, adjDataMap);
		    Console.WriteLine(sentimentOutputJSON);

            Console.Read();
	    }
	
	    public static void sentimentBulkTest() 
	    {
		    Dictionary<string, string> sentimentDataMap = new Dictionary<string, string>();
		    sentimentDataMap.Add("text1", "read");
		    sentimentDataMap.Add("text2", "ever");
		    string sentimentOutputXML = RepustateClient.getSentimentBulk(RepustateClient.FORMAT_XML, sentimentDataMap);
		    Console.WriteLine(sentimentOutputXML);
		    string sentimentOutputJSON = RepustateClient.getSentimentBulk(RepustateClient.FORMAT_JSON, sentimentDataMap);
		    Console.WriteLine(sentimentOutputJSON);
	        
            Console.Read();
        }
	
	    public static void sentimentTest() 
	    {
		    Dictionary<string, string> scoreDataMap = new Dictionary<string, string>();
		    scoreDataMap.Add("text", "read");
		    scoreDataMap.Add("url", "http://techcrunch.com/2010/05/07/oneriot/");
		    string scoreOutputXML = RepustateClient.getSentiment(RepustateClient.FORMAT_XML, scoreDataMap);
		    Console.WriteLine(scoreOutputXML);
		
		    string scoreOutputJSON = RepustateClient.getSentiment(RepustateClient.FORMAT_JSON, scoreDataMap);
		    Console.WriteLine(scoreOutputJSON);

            Console.Read();
	    }
    }
}