예제 #1
0
    public static void Main()
    {
        // Create an AlchemyAPI object.
        AlchemyAPI.AlchemyAPI alchemyObj = new AlchemyAPI.AlchemyAPI();
        AlchemyAPI_KeywordParams keywordParams = new AlchemyAPI_KeywordParams();
        AlchemyAPI_EntityParams entityParams = new AlchemyAPI_EntityParams();

        // Load an API key from disk.
        alchemyObj.LoadAPIKey("api_key.txt");
        keywordParams.setMaxRetrieve(1);
        keywordParams.setShowSourceText(true);
        keywordParams.setSourceText(AlchemyAPI_KeywordParams.SourceTextMode.RAW);
        keywordParams.setSentiment(true);
        // Extract a ranked list of named entities from a web URL with parameters.
        string xml = alchemyObj.URLGetRankedKeywords("http://www.techcrunch.com/", keywordParams);
        Console.WriteLine (xml);

        // Load a HTML document to analyze.
        StreamReader streamReader = new StreamReader("data/example.html");
        string htmlDoc = streamReader.ReadToEnd();
        streamReader.Close();

        entityParams.setMaxRetrieve(3);
        entityParams.setDisambiguate(true);
        entityParams.setOutputMode(AlchemyAPI_BaseParams.OutputMode.RDF);
        entityParams.setSentiment(true);
        // Extract a ranked list of named entities from a HTML document with parameters.
        xml = alchemyObj.HTMLGetRankedNamedEntities(htmlDoc, "http://www.test.com/", entityParams);
        Console.WriteLine (xml);
    }
예제 #2
0
        public void Initialize()
        {
            alchemyObj = new AlchemyAPI.AlchemyAPI();
            alchemyObj.LoadAPIKey("alchemyapikey.txt");

            eparams = new AlchemyAPI_EntityParams();
            eparams.setMaxRetrieve(250);

            kparams = new AlchemyAPI_KeywordParams();
            kparams.setMaxRetrieve(250);

            cparams = new AlchemyAPI_ConceptParams();
            cparams.setMaxRetrieve(250);
        }
예제 #3
0
파일: Alchemy.cs 프로젝트: keithshort/HOPE
		protected DataSet GetKeywords(string url)
		{
			DataSet dsKeywords = new DataSet();

#if TEST
			// Using previously captured dataset
			dsKeywords.ReadXml("alchemyKeywordsTestResponse.xml");
#else
			if (!Cached("Keyword", url, ref dsKeywords))
			{
				AlchemyAPI_KeywordParams eparams = new AlchemyAPI_KeywordParams();
				eparams.setMaxRetrieve(250);
				string xml = alchemyObj.URLGetRankedKeywords(url);
				TextReader tr = new StringReader(xml);
				XmlReader xr = XmlReader.Create(tr);
				dsKeywords.ReadXml(xr);
				xr.Close();
				tr.Close();
				Cache("Keyword", url, dsKeywords);
			}
#endif
			return dsKeywords;
		}