diff --git a/.gitignore b/.gitignore index 3497551..c170c9f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ bin -dist \ No newline at end of file +dist +testdir/api_key.txt \ No newline at end of file diff --git a/src/com/alchemyapi/api/AlchemyAPI.java b/src/com/alchemyapi/api/AlchemyAPI.java index 876138a..e5069e6 100644 --- a/src/com/alchemyapi/api/AlchemyAPI.java +++ b/src/com/alchemyapi/api/AlchemyAPI.java @@ -80,14 +80,14 @@ public void SetAPIHost(String apiHost) { _requestUri = "http://" + apiHost + ".alchemyapi.com/calls/"; } - public Document URLGetAuthor(String url) + public String URLGetAuthor(String url) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { return URLGetAuthor(url, new AlchemyAPI_Params()); } - public Document URLGetAuthor(String url, AlchemyAPI_Params params) + public String URLGetAuthor(String url, AlchemyAPI_Params params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { @@ -98,14 +98,14 @@ public Document URLGetAuthor(String url, AlchemyAPI_Params params) return GET("URLGetAuthor", "url", params); } - public Document HTMLGetAuthor(String html, String url) + public String HTMLGetAuthor(String html, String url) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { return HTMLGetAuthor(html, url, new AlchemyAPI_Params()); } - public Document HTMLGetAuthor(String html, String url, + public String HTMLGetAuthor(String html, String url, AlchemyAPI_Params params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException @@ -118,14 +118,14 @@ public Document HTMLGetAuthor(String html, String url, return POST("HTMLGetAuthor", "html", params); } - public Document URLGetRankedNamedEntities(String url) + public String URLGetRankedNamedEntities(String url) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { return URLGetRankedNamedEntities(url, new AlchemyAPI_NamedEntityParams()); } - public Document URLGetRankedNamedEntities(String url, AlchemyAPI_NamedEntityParams params) + public String URLGetRankedNamedEntities(String url, AlchemyAPI_NamedEntityParams params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { @@ -136,7 +136,7 @@ public Document URLGetRankedNamedEntities(String url, AlchemyAPI_NamedEntityPara return GET("URLGetRankedNamedEntities", "url", params); } - public Document HTMLGetRankedNamedEntities(String html, String url) + public String HTMLGetRankedNamedEntities(String html, String url) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { @@ -144,7 +144,7 @@ public Document HTMLGetRankedNamedEntities(String html, String url) } - public Document HTMLGetRankedNamedEntities(String html, String url, AlchemyAPI_NamedEntityParams params) + public String HTMLGetRankedNamedEntities(String html, String url, AlchemyAPI_NamedEntityParams params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { @@ -156,14 +156,14 @@ public Document HTMLGetRankedNamedEntities(String html, String url, AlchemyAPI_N return POST("HTMLGetRankedNamedEntities", "html", params); } - public Document TextGetRankedNamedEntities(String text) + public String TextGetRankedNamedEntities(String text) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { return TextGetRankedNamedEntities(text, new AlchemyAPI_NamedEntityParams()); } - public Document TextGetRankedNamedEntities(String text, AlchemyAPI_NamedEntityParams params) + public String TextGetRankedNamedEntities(String text, AlchemyAPI_NamedEntityParams params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { @@ -176,14 +176,14 @@ public Document TextGetRankedNamedEntities(String text, AlchemyAPI_NamedEntityPa - public Document URLGetRankedConcepts(String url) + public String URLGetRankedConcepts(String url) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { return URLGetRankedConcepts(url, new AlchemyAPI_ConceptParams()); } - public Document URLGetRankedConcepts(String url, AlchemyAPI_ConceptParams params) + public String URLGetRankedConcepts(String url, AlchemyAPI_ConceptParams params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { @@ -195,14 +195,14 @@ public Document URLGetRankedConcepts(String url, AlchemyAPI_ConceptParams params } - public Document HTMLGetRankedConcepts(String html, String url) + public String HTMLGetRankedConcepts(String html, String url) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { return HTMLGetRankedConcepts(html, url, new AlchemyAPI_ConceptParams()); } - public Document HTMLGetRankedConcepts(String html, String url, AlchemyAPI_ConceptParams params) + public String HTMLGetRankedConcepts(String html, String url, AlchemyAPI_ConceptParams params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { @@ -214,12 +214,12 @@ public Document HTMLGetRankedConcepts(String html, String url, AlchemyAPI_Concep return POST("HTMLGetRankedConcepts", "html", params); } - public Document TextGetRankedConcepts(String text) throws IOException, SAXException, + public String TextGetRankedConcepts(String text) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { return TextGetRankedConcepts(text, new AlchemyAPI_ConceptParams()); } - public Document TextGetRankedConcepts(String text, AlchemyAPI_ConceptParams params) throws IOException, SAXException, + public String TextGetRankedConcepts(String text, AlchemyAPI_ConceptParams params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { CheckText(text); @@ -231,14 +231,14 @@ public Document TextGetRankedConcepts(String text, AlchemyAPI_ConceptParams para - public Document URLGetRankedKeywords(String url) + public String URLGetRankedKeywords(String url) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { return URLGetRankedKeywords(url, new AlchemyAPI_KeywordParams()); } - public Document URLGetRankedKeywords(String url, AlchemyAPI_KeywordParams params) + public String URLGetRankedKeywords(String url, AlchemyAPI_KeywordParams params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { @@ -250,14 +250,14 @@ public Document URLGetRankedKeywords(String url, AlchemyAPI_KeywordParams params } - public Document HTMLGetRankedKeywords(String html, String url) + public String HTMLGetRankedKeywords(String html, String url) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { return HTMLGetRankedKeywords(html, url, new AlchemyAPI_KeywordParams()); } - public Document HTMLGetRankedKeywords(String html, String url, AlchemyAPI_KeywordParams params) + public String HTMLGetRankedKeywords(String html, String url, AlchemyAPI_KeywordParams params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { @@ -269,12 +269,12 @@ public Document HTMLGetRankedKeywords(String html, String url, AlchemyAPI_Keywor return POST("HTMLGetRankedKeywords", "html", params); } - public Document TextGetRankedKeywords(String text) throws IOException, SAXException, + public String TextGetRankedKeywords(String text) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { return TextGetRankedKeywords(text, new AlchemyAPI_KeywordParams()); } - public Document TextGetRankedKeywords(String text, AlchemyAPI_KeywordParams params) throws IOException, SAXException, + public String TextGetRankedKeywords(String text, AlchemyAPI_KeywordParams params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { CheckText(text); @@ -284,14 +284,14 @@ public Document TextGetRankedKeywords(String text, AlchemyAPI_KeywordParams para return POST("TextGetRankedKeywords", "text", params); } - public Document URLGetLanguage(String url) + public String URLGetLanguage(String url) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { return URLGetLanguage(url, new AlchemyAPI_LanguageParams()); } - public Document URLGetLanguage(String url, AlchemyAPI_LanguageParams params) + public String URLGetLanguage(String url, AlchemyAPI_LanguageParams params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { @@ -302,14 +302,14 @@ public Document URLGetLanguage(String url, AlchemyAPI_LanguageParams params) return GET("URLGetLanguage", "url", params); } - public Document HTMLGetLanguage(String html, String url) + public String HTMLGetLanguage(String html, String url) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { return HTMLGetLanguage(html, url, new AlchemyAPI_LanguageParams()); } - public Document HTMLGetLanguage(String html, String url, AlchemyAPI_LanguageParams params) + public String HTMLGetLanguage(String html, String url, AlchemyAPI_LanguageParams params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { @@ -321,14 +321,14 @@ public Document HTMLGetLanguage(String html, String url, AlchemyAPI_LanguagePara return POST("HTMLGetLanguage", "html", params); } - public Document TextGetLanguage(String text) + public String TextGetLanguage(String text) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { return TextGetLanguage(text, new AlchemyAPI_LanguageParams()); } - public Document TextGetLanguage(String text, AlchemyAPI_LanguageParams params) + public String TextGetLanguage(String text, AlchemyAPI_LanguageParams params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { @@ -339,14 +339,14 @@ public Document TextGetLanguage(String text, AlchemyAPI_LanguageParams params) return POST("TextGetLanguage", "text", params); } - public Document URLGetCategory(String url) + public String URLGetCategory(String url) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { return URLGetCategory(url, new AlchemyAPI_CategoryParams()); } - public Document URLGetCategory(String url, AlchemyAPI_CategoryParams params) + public String URLGetCategory(String url, AlchemyAPI_CategoryParams params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { @@ -357,14 +357,14 @@ public Document URLGetCategory(String url, AlchemyAPI_CategoryParams params) return GET("URLGetCategory", "url", params); } - public Document HTMLGetCategory(String html, String url) + public String HTMLGetCategory(String html, String url) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { return HTMLGetCategory(html, url, new AlchemyAPI_CategoryParams()); } - public Document HTMLGetCategory(String html, String url, AlchemyAPI_CategoryParams params) + public String HTMLGetCategory(String html, String url, AlchemyAPI_CategoryParams params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { @@ -376,14 +376,14 @@ public Document HTMLGetCategory(String html, String url, AlchemyAPI_CategoryPara return POST("HTMLGetCategory", "html", params); } - public Document TextGetCategory(String text) + public String TextGetCategory(String text) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { return TextGetCategory(text, new AlchemyAPI_TextParams()); } - public Document TextGetCategory(String text, AlchemyAPI_TextParams params) + public String TextGetCategory(String text, AlchemyAPI_TextParams params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { @@ -394,14 +394,14 @@ public Document TextGetCategory(String text, AlchemyAPI_TextParams params) return POST("TextGetCategory", "text", params); } - public Document URLGetText(String url) + public String URLGetText(String url) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { return URLGetText(url, new AlchemyAPI_TextParams()); } - public Document URLGetText(String url, AlchemyAPI_TextParams params) + public String URLGetText(String url, AlchemyAPI_TextParams params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { @@ -412,14 +412,14 @@ public Document URLGetText(String url, AlchemyAPI_TextParams params) return GET("URLGetText", "url", params); } - public Document HTMLGetText(String html, String url) + public String HTMLGetText(String html, String url) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { return HTMLGetText(html, url, new AlchemyAPI_TextParams()); } - public Document HTMLGetText(String html, String url, AlchemyAPI_TextParams params) + public String HTMLGetText(String html, String url, AlchemyAPI_TextParams params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { @@ -431,14 +431,14 @@ public Document HTMLGetText(String html, String url, AlchemyAPI_TextParams param return POST("HTMLGetText", "html", params); } - public Document URLGetRawText(String url) + public String URLGetRawText(String url) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { return URLGetRawText(url, new AlchemyAPI_Params()); } - public Document URLGetRawText(String url, AlchemyAPI_Params params) + public String URLGetRawText(String url, AlchemyAPI_Params params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { @@ -449,14 +449,14 @@ public Document URLGetRawText(String url, AlchemyAPI_Params params) return GET("URLGetRawText", "url", params); } - public Document HTMLGetRawText(String html, String url) + public String HTMLGetRawText(String html, String url) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { return HTMLGetRawText(html, url, new AlchemyAPI_Params()); } - public Document HTMLGetRawText(String html, String url, AlchemyAPI_Params params) + public String HTMLGetRawText(String html, String url, AlchemyAPI_Params params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { @@ -468,14 +468,14 @@ public Document HTMLGetRawText(String html, String url, AlchemyAPI_Params params return POST("HTMLGetRawText", "html", params); } - public Document URLGetTitle(String url) + public String URLGetTitle(String url) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { return URLGetTitle(url, new AlchemyAPI_Params()); } - public Document URLGetTitle(String url, AlchemyAPI_Params params) + public String URLGetTitle(String url, AlchemyAPI_Params params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { @@ -486,14 +486,14 @@ public Document URLGetTitle(String url, AlchemyAPI_Params params) return GET("URLGetTitle", "url", params); } - public Document HTMLGetTitle(String html, String url) + public String HTMLGetTitle(String html, String url) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { return HTMLGetTitle(html, url, new AlchemyAPI_Params()); } - public Document HTMLGetTitle(String html, String url, AlchemyAPI_Params params) + public String HTMLGetTitle(String html, String url, AlchemyAPI_Params params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { @@ -505,14 +505,14 @@ public Document HTMLGetTitle(String html, String url, AlchemyAPI_Params params) return POST("HTMLGetTitle", "html", params); } - public Document URLGetFeedLinks(String url) + public String URLGetFeedLinks(String url) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { return URLGetFeedLinks(url, new AlchemyAPI_Params()); } - public Document URLGetFeedLinks(String url, AlchemyAPI_Params params) + public String URLGetFeedLinks(String url, AlchemyAPI_Params params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { @@ -523,14 +523,14 @@ public Document URLGetFeedLinks(String url, AlchemyAPI_Params params) return GET("URLGetFeedLinks", "url", params); } - public Document HTMLGetFeedLinks(String html, String url) + public String HTMLGetFeedLinks(String html, String url) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { return HTMLGetFeedLinks(html, url, new AlchemyAPI_Params()); } - public Document HTMLGetFeedLinks(String html, String url, AlchemyAPI_Params params) + public String HTMLGetFeedLinks(String html, String url, AlchemyAPI_Params params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { @@ -542,14 +542,14 @@ public Document HTMLGetFeedLinks(String html, String url, AlchemyAPI_Params para return POST("HTMLGetFeedLinks", "html", params); } - public Document URLGetMicroformats(String url) + public String URLGetMicroformats(String url) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { return URLGetMicroformats(url, new AlchemyAPI_Params()); } - public Document URLGetMicroformats(String url, AlchemyAPI_Params params) + public String URLGetMicroformats(String url, AlchemyAPI_Params params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { @@ -560,14 +560,14 @@ public Document URLGetMicroformats(String url, AlchemyAPI_Params params) return GET("URLGetMicroformatData", "url", params); } - public Document HTMLGetMicroformats(String html, String url) + public String HTMLGetMicroformats(String html, String url) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { return HTMLGetMicroformats(html, url, new AlchemyAPI_Params()); } - public Document HTMLGetMicroformats(String html, String url, AlchemyAPI_Params params) + public String HTMLGetMicroformats(String html, String url, AlchemyAPI_Params params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { @@ -579,14 +579,14 @@ public Document HTMLGetMicroformats(String html, String url, AlchemyAPI_Params p return POST("HTMLGetMicroformatData", "html", params); } - public Document URLGetConstraintQuery(String url, String query) + public String URLGetConstraintQuery(String url, String query) throws IOException, XPathExpressionException, SAXException, ParserConfigurationException { return URLGetConstraintQuery(url, query, new AlchemyAPI_ConstraintQueryParams()); } - public Document URLGetConstraintQuery(String url, String query, AlchemyAPI_ConstraintQueryParams params) + public String URLGetConstraintQuery(String url, String query, AlchemyAPI_ConstraintQueryParams params) throws IOException, XPathExpressionException, SAXException, ParserConfigurationException { @@ -601,14 +601,14 @@ public Document URLGetConstraintQuery(String url, String query, AlchemyAPI_Const } - public Document HTMLGetConstraintQuery(String html, String url, String query) + public String HTMLGetConstraintQuery(String html, String url, String query) throws IOException, XPathExpressionException, SAXException, ParserConfigurationException { return HTMLGetConstraintQuery(html, url, query, new AlchemyAPI_ConstraintQueryParams()); } - public Document HTMLGetConstraintQuery(String html, String url, String query, AlchemyAPI_ConstraintQueryParams params) + public String HTMLGetConstraintQuery(String html, String url, String query, AlchemyAPI_ConstraintQueryParams params) throws IOException, XPathExpressionException, SAXException, ParserConfigurationException { @@ -623,14 +623,14 @@ public Document HTMLGetConstraintQuery(String html, String url, String query, Al return POST("HTMLGetConstraintQuery", "html", params); } - public Document URLGetTextSentiment(String url) + public String URLGetTextSentiment(String url) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { return URLGetTextSentiment(url, new AlchemyAPI_Params()); } - public Document URLGetTextSentiment(String url, AlchemyAPI_Params params) + public String URLGetTextSentiment(String url, AlchemyAPI_Params params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { @@ -642,14 +642,14 @@ public Document URLGetTextSentiment(String url, AlchemyAPI_Params params) } - public Document HTMLGetTextSentiment(String html, String url) + public String HTMLGetTextSentiment(String html, String url) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { return HTMLGetTextSentiment(html, url, new AlchemyAPI_Params()); } - public Document HTMLGetTextSentiment(String html, String url, AlchemyAPI_Params params) + public String HTMLGetTextSentiment(String html, String url, AlchemyAPI_Params params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { @@ -661,14 +661,14 @@ public Document HTMLGetTextSentiment(String html, String url, AlchemyAPI_Params return POST("HTMLGetTextSentiment", "html", params); } - public Document TextGetTextSentiment(String text) + public String TextGetTextSentiment(String text) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { return TextGetTextSentiment(text, new AlchemyAPI_Params()); } - public Document TextGetTextSentiment(String text, AlchemyAPI_Params params) + public String TextGetTextSentiment(String text, AlchemyAPI_Params params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { @@ -681,7 +681,7 @@ public Document TextGetTextSentiment(String text, AlchemyAPI_Params params) //------------------ - public Document URLGetTargetedSentiment(String url, String target) + public String URLGetTargetedSentiment(String url, String target) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { @@ -689,7 +689,7 @@ public Document URLGetTargetedSentiment(String url, String target) new AlchemyAPI_TargetedSentimentParams()); } - public Document URLGetTargetedSentiment(String url, String target, + public String URLGetTargetedSentiment(String url, String target, AlchemyAPI_TargetedSentimentParams params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException @@ -703,7 +703,7 @@ public Document URLGetTargetedSentiment(String url, String target, return GET("URLGetTargetedSentiment", "url", params); } - public Document HTMLGetTargetedSentiment(String html, String url, String target) + public String HTMLGetTargetedSentiment(String html, String url, String target) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { @@ -711,7 +711,7 @@ public Document HTMLGetTargetedSentiment(String html, String url, String target) new AlchemyAPI_TargetedSentimentParams()); } - public Document HTMLGetTargetedSentiment(String html, String url, String target, + public String HTMLGetTargetedSentiment(String html, String url, String target, AlchemyAPI_TargetedSentimentParams params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException @@ -726,7 +726,7 @@ public Document HTMLGetTargetedSentiment(String html, String url, String target, return POST("HTMLGetTargetedSentiment", "html", params); } - public Document TextGetTargetedSentiment(String text, String target) + public String TextGetTargetedSentiment(String text, String target) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { @@ -734,7 +734,7 @@ public Document TextGetTargetedSentiment(String text, String target) new AlchemyAPI_TargetedSentimentParams()); } - public Document TextGetTargetedSentiment(String text, String target, + public String TextGetTargetedSentiment(String text, String target, AlchemyAPI_TargetedSentimentParams params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException @@ -750,13 +750,13 @@ public Document TextGetTargetedSentiment(String text, String target, //------------------ - public Document URLGetRelations(String url) throws IOException, SAXException, + public String URLGetRelations(String url) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { return URLGetRelations(url, new AlchemyAPI_RelationParams()); } - public Document URLGetRelations(String url, AlchemyAPI_RelationParams params) + public String URLGetRelations(String url, AlchemyAPI_RelationParams params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { @@ -767,14 +767,14 @@ public Document URLGetRelations(String url, AlchemyAPI_RelationParams params) return GET("URLGetRelations", "url", params); } - public Document HTMLGetRelations(String html, String url) + public String HTMLGetRelations(String html, String url) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { return HTMLGetRelations(html, url, new AlchemyAPI_RelationParams()); } - public Document HTMLGetRelations(String html, String url, AlchemyAPI_RelationParams params) + public String HTMLGetRelations(String html, String url, AlchemyAPI_RelationParams params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { @@ -786,14 +786,14 @@ public Document HTMLGetRelations(String html, String url, AlchemyAPI_RelationPar return POST("HTMLGetRelations", "html", params); } - public Document TextGetRelations(String text) + public String TextGetRelations(String text) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { return TextGetRelations(text, new AlchemyAPI_RelationParams()); } - public Document TextGetRelations(String text, AlchemyAPI_RelationParams params) + public String TextGetRelations(String text, AlchemyAPI_RelationParams params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { @@ -806,7 +806,7 @@ public Document TextGetRelations(String text, AlchemyAPI_RelationParams params) //------------------ - public Document URLGetCombined(String url) throws IOException, SAXException, + public String URLGetCombined(String url) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { AlchemyAPI_CombinedParams params = new AlchemyAPI_CombinedParams(); @@ -814,7 +814,7 @@ public Document URLGetCombined(String url) throws IOException, SAXException, return URLGetCombined(url, params); } - public Document URLGetCombined(String url, AlchemyAPI_CombinedParams params) + public String URLGetCombined(String url, AlchemyAPI_CombinedParams params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { @@ -825,7 +825,7 @@ public Document URLGetCombined(String url, AlchemyAPI_CombinedParams params) return GET("URLGetCombinedData", "url", params); } - public Document TextGetCombined(String text) + public String TextGetCombined(String text) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { @@ -834,7 +834,7 @@ public Document TextGetCombined(String text) return TextGetCombined(text, params); } - public Document TextGetCombined(String text, AlchemyAPI_CombinedParams params) + public String TextGetCombined(String text, AlchemyAPI_CombinedParams params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { @@ -847,13 +847,13 @@ public Document TextGetCombined(String text, AlchemyAPI_CombinedParams params) //------------------ - public Document URLGetTaxonomy(String url) throws IOException, SAXException, + public String URLGetTaxonomy(String url) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { return URLGetTaxonomy(url, new AlchemyAPI_TaxonomyParams()); } - public Document URLGetTaxonomy(String url, AlchemyAPI_TaxonomyParams params) + public String URLGetTaxonomy(String url, AlchemyAPI_TaxonomyParams params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { @@ -864,14 +864,14 @@ public Document URLGetTaxonomy(String url, AlchemyAPI_TaxonomyParams params) return GET("URLGetRankedTaxonomy", "url", params); } - public Document HTMLGetTaxonomy(String html, String url) + public String HTMLGetTaxonomy(String html, String url) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { return HTMLGetTaxonomy(html, url, new AlchemyAPI_TaxonomyParams()); } - public Document HTMLGetTaxonomy(String html, String url, AlchemyAPI_TaxonomyParams params) + public String HTMLGetTaxonomy(String html, String url, AlchemyAPI_TaxonomyParams params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { @@ -883,14 +883,14 @@ public Document HTMLGetTaxonomy(String html, String url, AlchemyAPI_TaxonomyPara return POST("HTMLGetRankedTaxonomy", "html", params); } - public Document TextGetTaxonomy(String text) + public String TextGetTaxonomy(String text) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { return TextGetTaxonomy(text, new AlchemyAPI_TaxonomyParams()); } - public Document TextGetTaxonomy(String text, AlchemyAPI_TaxonomyParams params) + public String TextGetTaxonomy(String text, AlchemyAPI_TaxonomyParams params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { @@ -903,13 +903,13 @@ public Document TextGetTaxonomy(String text, AlchemyAPI_TaxonomyParams params) //------------------ - public Document URLGetImage(String url) throws IOException, SAXException, + public String URLGetImage(String url) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { return URLGetImage(url, new AlchemyAPI_ImageParams()); } - public Document URLGetImage(String url, AlchemyAPI_ImageParams params) + public String URLGetImage(String url, AlchemyAPI_ImageParams params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { @@ -920,13 +920,13 @@ public Document URLGetImage(String url, AlchemyAPI_ImageParams params) return GET("URLGetImage", "url", params); } - public Document URLGetRankedImageKeywords(String url) throws IOException, SAXException, + public String URLGetRankedImageKeywords(String url) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { return URLGetRankedImageKeywords(url, new AlchemyAPI_ImageParams()); } - public Document URLGetRankedImageKeywords(String url, AlchemyAPI_ImageParams params) + public String URLGetRankedImageKeywords(String url, AlchemyAPI_ImageParams params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { @@ -937,7 +937,7 @@ public Document URLGetRankedImageKeywords(String url, AlchemyAPI_ImageParams par return GET("URLGetRankedImageKeywords", "url", params); } - public Document ImageGetRankedImageKeywords(AlchemyAPI_ImageParams params) + public String ImageGetRankedImageKeywords(AlchemyAPI_ImageParams params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { @@ -967,7 +967,7 @@ private void CheckHTML(String html, String url) { } private void CheckText(String text) { - if (null == text || text.length() < 5) + if (null == text) throw new IllegalArgumentException("Enter some text to analyze."); } @@ -976,23 +976,23 @@ private void CheckURL(String url) { throw new IllegalArgumentException("Enter an URL to analyze."); } - private Document GET(String callName, String callPrefix, AlchemyAPI_Params params) + private String GET(String callName, String callPrefix, AlchemyAPI_Params params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException - { - StringBuilder uri = new StringBuilder(); - uri.append(_requestUri).append(callPrefix).append('/').append(callName) - .append('?').append("apikey=").append(this._apiKey); - uri.append(params.getParameterString()); - - URL url = new URL(uri.toString()); - HttpURLConnection handle = (HttpURLConnection) url.openConnection(); - handle.setDoOutput(true); - - return doRequest(handle, params.getOutputMode()); - } + { + StringBuilder uri = new StringBuilder(); + uri.append(_requestUri).append(callPrefix).append('/').append(callName) + .append('?').append("apikey=").append(this._apiKey); + uri.append(params.getParameterString()); + + URL url = new URL(uri.toString()); + HttpURLConnection handle = (HttpURLConnection) url.openConnection(); + handle.setDoOutput(true); + + return doRequest(handle, params.getOutputMode()); + } - private Document POST(String callName, String callPrefix, AlchemyAPI_Params params) + private String POST(String callName, String callPrefix, AlchemyAPI_Params params) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { @@ -1015,53 +1015,20 @@ private Document POST(String callName, String callPrefix, AlchemyAPI_Params para return doRequest(handle, params.getOutputMode()); } - private Document doRequest(HttpURLConnection handle, String outputMode) + private String doRequest(HttpURLConnection handle, String outputMode) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { - DataInputStream istream = new DataInputStream(handle.getInputStream()); - Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(istream); - - istream.close(); - handle.disconnect(); - - XPathFactory factory = XPathFactory.newInstance(); - - if(AlchemyAPI_Params.OUTPUT_XML.equals(outputMode)) { - String statusStr = getNodeValue(factory, doc, "/results/status/text()"); - if (null == statusStr || !statusStr.equals("OK")) { - String statusInfoStr = getNodeValue(factory, doc, "/results/statusInfo/text()"); - if (null != statusInfoStr && statusInfoStr.length() > 0) - throw new IOException("Error making API call: " + statusInfoStr + '.'); - - throw new IOException("Error making API call: " + statusStr + '.'); - } - } - else if(AlchemyAPI_Params.OUTPUT_RDF.equals(outputMode)) { - String statusStr = getNodeValue(factory, doc, "//RDF/Description/ResultStatus/text()"); - if (null == statusStr || !statusStr.equals("OK")) { - String statusInfoStr = getNodeValue(factory, doc, "//RDF/Description/ResultStatus/text()"); - if (null != statusInfoStr && statusInfoStr.length() > 0) - throw new IOException("Error making API call: " + statusInfoStr + '.'); - - throw new IOException("Error making API call: " + statusStr + '.'); - } + String doc = ""; + BufferedReader in = new BufferedReader(new InputStreamReader(handle.getInputStream())); + String inputLine; + while ((inputLine = in.readLine()) != null){ + doc += inputLine + "\n"; } + in.close(); + handle.disconnect(); return doc; } - private String getNodeValue(XPathFactory factory, Document doc, String xpathStr) - throws XPathExpressionException - { - XPath xpath = factory.newXPath(); - XPathExpression expr = xpath.compile(xpathStr); - Object result = expr.evaluate(doc, XPathConstants.NODESET); - NodeList results = (NodeList) result; - - if (results.getLength() > 0 && null != results.item(0)) - return results.item(0).getNodeValue(); - - return null; - } } diff --git a/src/com/alchemyapi/api/AlchemyAPI_Params.java b/src/com/alchemyapi/api/AlchemyAPI_Params.java index 3e1f8d3..c41d3c1 100644 --- a/src/com/alchemyapi/api/AlchemyAPI_Params.java +++ b/src/com/alchemyapi/api/AlchemyAPI_Params.java @@ -8,6 +8,7 @@ public class AlchemyAPI_Params { public static final String OUTPUT_XML = "xml"; public static final String OUTPUT_RDF = "rdf"; + public static final String OUTPUT_JSON = "json"; private String url; private String html; @@ -37,7 +38,7 @@ public String getOutputMode() { return outputMode; } public void setOutputMode(String outputMode) { - if( !outputMode.equals(AlchemyAPI_Params.OUTPUT_XML) && !outputMode.equals(OUTPUT_RDF) ) + if( !outputMode.equals(AlchemyAPI_Params.OUTPUT_XML) && !outputMode.equals(AlchemyAPI_Params.OUTPUT_RDF) && !outputMode.equals(AlchemyAPI_Params.OUTPUT_JSON)) { throw new RuntimeException("Invalid setting " + outputMode + " for parameter outputMode"); } diff --git a/src/com/alchemyapi/test/AuthorTest.java b/src/com/alchemyapi/test/AuthorTest.java index 832535a..8897dfe 100644 --- a/src/com/alchemyapi/test/AuthorTest.java +++ b/src/com/alchemyapi/test/AuthorTest.java @@ -27,11 +27,11 @@ public static void main(String[] args) // Load a HTML document to analyze. String htmlDoc = getFileContents("data/example.html"); - Document doc = alchemyObj.URLGetAuthor("http://www.politico.com/blogs/media/2012/02/detroit-news-ed-upset-over-romney-edit-115247.html"); - System.out.println(getStringFromDocument(doc)); + String doc = alchemyObj.URLGetAuthor("http://www.politico.com/blogs/media/2012/02/detroit-news-ed-upset-over-romney-edit-115247.html"); + System.out.println(doc); doc = alchemyObj.HTMLGetAuthor(htmlDoc, "http://www.test.com/"); - System.out.println(getStringFromDocument(doc)); + System.out.println(doc); } // utility function diff --git a/src/com/alchemyapi/test/CategoryTest.java b/src/com/alchemyapi/test/CategoryTest.java index 9be3605..7a872c8 100644 --- a/src/com/alchemyapi/test/CategoryTest.java +++ b/src/com/alchemyapi/test/CategoryTest.java @@ -22,24 +22,24 @@ public static void main(String[] args) AlchemyAPI alchemyObj = AlchemyAPI.GetInstanceFromFile("api_key.txt"); // Categorize a web URL by topic. - Document doc = alchemyObj.URLGetCategory("http://www.techcrunch.com/"); - System.out.println(getStringFromDocument(doc)); + String doc = alchemyObj.URLGetCategory("http://www.techcrunch.com/"); + System.out.println(doc); // Categorize some text. doc = alchemyObj.TextGetCategory("Latest on the War in Iraq."); - System.out.println(getStringFromDocument(doc)); + System.out.println(doc); // Load a HTML document to analyze. String htmlDoc = getFileContents("data/example.html"); // Categorize a HTML document by topic. doc = alchemyObj.HTMLGetCategory(htmlDoc, "http://www.test.com/"); - System.out.println(getStringFromDocument(doc)); + System.out.println(doc); AlchemyAPI_CategoryParams categoryParams = new AlchemyAPI_CategoryParams(); categoryParams.setOutputMode(AlchemyAPI_Params.OUTPUT_RDF); doc = alchemyObj.HTMLGetCategory(htmlDoc, "http://www.test.com/", categoryParams); - System.out.println(getStringFromDocument(doc)); + System.out.println(doc); } // utility function diff --git a/src/com/alchemyapi/test/CombinedTest.java b/src/com/alchemyapi/test/CombinedTest.java index 7b68e5f..b548f28 100644 --- a/src/com/alchemyapi/test/CombinedTest.java +++ b/src/com/alchemyapi/test/CombinedTest.java @@ -22,14 +22,14 @@ public static void main(String[] args) AlchemyAPI alchemyObj = AlchemyAPI.GetInstanceFromFile("api_key.txt"); // Extract combined data for a web URL. - Document doc = alchemyObj.URLGetCombined("http://www.techcrunch.com/"); - System.out.println(getStringFromDocument(doc)); + String doc = alchemyObj.URLGetCombined("http://www.techcrunch.com/"); + System.out.println(doc); // Extract combined data from a text string. doc = alchemyObj.TextGetCombined( "Hello there, my name is Bob Jones. I live in the United States of America. " + "Where do you live, Fred?"); - System.out.println(getStringFromDocument(doc)); + System.out.println(doc); // Only extract entities & keywords AlchemyAPI_CombinedParams combinedParams = new AlchemyAPI_CombinedParams(); @@ -37,7 +37,7 @@ public static void main(String[] args) combinedParams.setExtract("entity"); combinedParams.setExtract("keyword"); doc = alchemyObj.TextGetCombined("Madonna enjoys tasty Pepsi. I love her style.", combinedParams); - System.out.println(getStringFromDocument(doc)); + System.out.println(doc); } // utility function diff --git a/src/com/alchemyapi/test/ConceptTest.java b/src/com/alchemyapi/test/ConceptTest.java index 69f71b8..108aeb5 100644 --- a/src/com/alchemyapi/test/ConceptTest.java +++ b/src/com/alchemyapi/test/ConceptTest.java @@ -20,20 +20,20 @@ public static void main(String[] args) throws IOException, SAXException, AlchemyAPI alchemyObj = AlchemyAPI.GetInstanceFromFile("api_key.txt"); // Extract concept tags for a web URL. - Document doc = alchemyObj.URLGetRankedConcepts("http://www.techcrunch.com/"); - System.out.println(getStringFromDocument(doc)); + String doc = alchemyObj.URLGetRankedConcepts("http://www.techcrunch.com/"); + System.out.println(doc); // Extract concept tags for a text string. doc = alchemyObj.TextGetRankedConcepts( "This thing has a steering wheel, tires, and an engine. Do you know what it is?"); - System.out.println(getStringFromDocument(doc)); + System.out.println(doc); // Load a HTML document to analyze. String htmlDoc = getFileContents("data/example.html"); // Extract concept tags for a HTML document. doc = alchemyObj.HTMLGetRankedConcepts(htmlDoc, "http://www.test.com/"); - System.out.println(getStringFromDocument(doc)); + System.out.println(doc); } // utility function diff --git a/src/com/alchemyapi/test/ConstraintQueryTest.java b/src/com/alchemyapi/test/ConstraintQueryTest.java index fd6f4f3..e5f78ef 100644 --- a/src/com/alchemyapi/test/ConstraintQueryTest.java +++ b/src/com/alchemyapi/test/ConstraintQueryTest.java @@ -22,14 +22,14 @@ public static void main(String[] args) AlchemyAPI alchemyObj = AlchemyAPI.GetInstanceFromFile("api_key.txt"); // Extract first link from an URL. - Document doc = alchemyObj.URLGetConstraintQuery("http://microformats.org/wiki/hcard", + String doc = alchemyObj.URLGetConstraintQuery("http://microformats.org/wiki/hcard", "1st link"); - System.out.println(getStringFromDocument(doc)); + System.out.println(doc); // Extract first link from a HTML. String htmlDoc = getFileContents("data/example.html"); doc = alchemyObj.HTMLGetConstraintQuery(htmlDoc, "http://www.test.com/", "1st link"); - System.out.println(getStringFromDocument(doc)); + System.out.println(doc); } // utility function diff --git a/src/com/alchemyapi/test/EntityTest.java b/src/com/alchemyapi/test/EntityTest.java index c9d5a41..1bdde66 100644 --- a/src/com/alchemyapi/test/EntityTest.java +++ b/src/com/alchemyapi/test/EntityTest.java @@ -1,6 +1,8 @@ package com.alchemyapi.test; import com.alchemyapi.api.AlchemyAPI; +import com.alchemyapi.api.AlchemyAPI_NamedEntityParams; +import com.alchemyapi.api.AlchemyAPI_Params; import org.xml.sax.SAXException; import org.w3c.dom.Document; @@ -21,22 +23,25 @@ public static void main(String[] args) // Create an AlchemyAPI object. AlchemyAPI alchemyObj = AlchemyAPI.GetInstanceFromFile("api_key.txt"); + AlchemyAPI_NamedEntityParams entityParams = new AlchemyAPI_NamedEntityParams(); + entityParams.setOutputMode(AlchemyAPI_Params.OUTPUT_JSON); + // Extract a ranked list of named entities for a web URL. - Document doc = alchemyObj.URLGetRankedNamedEntities("http://www.techcrunch.com/"); - System.out.println(getStringFromDocument(doc)); + String doc = alchemyObj.URLGetRankedNamedEntities("http://www.techcrunch.com/",entityParams); + System.out.println(doc); // Extract a ranked list of named entities from a text string. doc = alchemyObj.TextGetRankedNamedEntities( "Hello there, my name is Bob Jones. I live in the United States of America. " + - "Where do you live, Fred?"); - System.out.println(getStringFromDocument(doc)); + "Where do you live, Fred?",entityParams); + System.out.println(doc); // Load a HTML document to analyze. String htmlDoc = getFileContents("data/example.html"); // Extract a ranked list of named entities from a HTML document. - doc = alchemyObj.HTMLGetRankedNamedEntities(htmlDoc, "http://www.test.com/"); - System.out.println(getStringFromDocument(doc)); + doc = alchemyObj.HTMLGetRankedNamedEntities(htmlDoc, "http://www.test.com/",entityParams); + System.out.println(doc); } // utility function diff --git a/src/com/alchemyapi/test/FeedLinksTest.java b/src/com/alchemyapi/test/FeedLinksTest.java index 1d0563f..f7d46c3 100644 --- a/src/com/alchemyapi/test/FeedLinksTest.java +++ b/src/com/alchemyapi/test/FeedLinksTest.java @@ -22,15 +22,15 @@ public static void main(String[] args) AlchemyAPI alchemyObj = AlchemyAPI.GetInstanceFromFile("api_key.txt"); // Extract RSS / ATOM feed links from a web URL. - Document doc = alchemyObj.URLGetFeedLinks("http://www.techcrunch.com/"); - System.out.println(getStringFromDocument(doc)); + String doc = alchemyObj.URLGetFeedLinks("http://www.techcrunch.com/"); + System.out.println(doc); // Load a HTML document to analyze. String htmlDoc = getFileContents("data/example.html"); // Extract RSS / ATOM feed links from a HTML document. doc = alchemyObj.HTMLGetFeedLinks(htmlDoc, "http://www.test.com/"); - System.out.println(getStringFromDocument(doc)); + System.out.println(doc); } // utility function diff --git a/src/com/alchemyapi/test/ImageTest.java b/src/com/alchemyapi/test/ImageTest.java index af474b4..98c939b 100644 --- a/src/com/alchemyapi/test/ImageTest.java +++ b/src/com/alchemyapi/test/ImageTest.java @@ -23,12 +23,12 @@ public static void main(String[] args) AlchemyAPI alchemyObj = AlchemyAPI.GetInstanceFromFile("api_key.txt"); // Extract image for a web URL. - Document doc = alchemyObj.URLGetImage("http://www.techcrunch.com/"); - System.out.println(getStringFromDocument(doc)); + String doc = alchemyObj.URLGetImage("http://www.techcrunch.com/"); + System.out.println(doc); doc = alchemyObj.URLGetRankedImageKeywords( "http://farm4.staticflickr.com/3726/11043305726_fdcb7785ec_m.jpg"); - System.out.println(getStringFromDocument(doc)); + System.out.println(doc); byte[] imageByteArray = readFile("data/cat.jpg"); @@ -36,7 +36,7 @@ public static void main(String[] args) imageParams.setImage(imageByteArray); imageParams.setImagePostMode(AlchemyAPI_ImageParams.RAW); doc = alchemyObj.ImageGetRankedImageKeywords(imageParams); - System.out.println(getStringFromDocument(doc)); + System.out.println(doc); } // utility function diff --git a/src/com/alchemyapi/test/KeywordTest.java b/src/com/alchemyapi/test/KeywordTest.java index 6338548..0a5325a 100644 --- a/src/com/alchemyapi/test/KeywordTest.java +++ b/src/com/alchemyapi/test/KeywordTest.java @@ -20,21 +20,21 @@ public static void main(String[] args) throws IOException, SAXException, AlchemyAPI alchemyObj = AlchemyAPI.GetInstanceFromFile("api_key.txt"); // Extract topic keywords for a web URL. - Document doc = alchemyObj.URLGetRankedKeywords("http://www.techcrunch.com/"); - System.out.println(getStringFromDocument(doc)); + String doc = alchemyObj.URLGetRankedKeywords("http://www.techcrunch.com/"); + System.out.println(doc); // Extract topic keywords for a text string. doc = alchemyObj.TextGetRankedKeywords( "Hello there, my name is Bob Jones. I live in the United States of America. " + "Where do you live, Fred?"); - System.out.println(getStringFromDocument(doc)); + System.out.println(doc); // Load a HTML document to analyze. String htmlDoc = getFileContents("data/example.html"); // Extract topic keywords for a HTML document. doc = alchemyObj.HTMLGetRankedKeywords(htmlDoc, "http://www.test.com/"); - System.out.println(getStringFromDocument(doc)); + System.out.println(doc); } // utility function diff --git a/src/com/alchemyapi/test/LanguageTest.java b/src/com/alchemyapi/test/LanguageTest.java index 29f5063..95f8863 100644 --- a/src/com/alchemyapi/test/LanguageTest.java +++ b/src/com/alchemyapi/test/LanguageTest.java @@ -22,21 +22,21 @@ public static void main(String[] args) AlchemyAPI alchemyObj = AlchemyAPI.GetInstanceFromFile("api_key.txt"); // Detect the language for a web URL. - Document doc = alchemyObj.URLGetLanguage("http://news.google.fr/"); - System.out.println(getStringFromDocument(doc)); + String doc = alchemyObj.URLGetLanguage("http://news.google.fr/"); + System.out.println(doc); // Detect the language for a text string (requires at least 100 // characters). String htmlDoc = getFileContents("data/example.html"); doc = alchemyObj.TextGetLanguage("This is some english language text. What language do you speak?"); - System.out.println(getStringFromDocument(doc)); + System.out.println(doc); // Load a HTML document to analyze. htmlDoc = getFileContents("data/example.html"); // Detect the language for a HTML document. doc = alchemyObj.HTMLGetLanguage(htmlDoc, "http://www.test.com/"); - System.out.println(getStringFromDocument(doc)); + System.out.println(doc); } // utility function diff --git a/src/com/alchemyapi/test/MicroformatTest.java b/src/com/alchemyapi/test/MicroformatTest.java index 97c2c41..1daa69f 100644 --- a/src/com/alchemyapi/test/MicroformatTest.java +++ b/src/com/alchemyapi/test/MicroformatTest.java @@ -22,15 +22,15 @@ public static void main(String[] args) AlchemyAPI alchemyObj = AlchemyAPI.GetInstanceFromFile("api_key.txt"); // Extract microformats data from a web URL. - Document doc = alchemyObj.URLGetMicroformats("http://microformats.org/wiki/hcard"); - System.out.println(getStringFromDocument(doc)); + String doc = alchemyObj.URLGetMicroformats("http://microformats.org/wiki/hcard"); + System.out.println(doc); // Load a HTML document to analyze. String htmlDoc = getFileContents("data/microformats.html"); // Extract microformats data from a HTML document. doc = alchemyObj.HTMLGetMicroformats(htmlDoc, "http://www.test.com/"); - System.out.println(getStringFromDocument(doc)); + System.out.println(doc); } // utility function diff --git a/src/com/alchemyapi/test/ParameterTest.java b/src/com/alchemyapi/test/ParameterTest.java index eb81975..cd6dea2 100644 --- a/src/com/alchemyapi/test/ParameterTest.java +++ b/src/com/alchemyapi/test/ParameterTest.java @@ -25,21 +25,21 @@ public static void main(String[] args) AlchemyAPI_NamedEntityParams entityParams = new AlchemyAPI_NamedEntityParams(); entityParams.setDisambiguate(false); entityParams.setSentiment(true); - Document doc = alchemyObj.URLGetRankedNamedEntities("http://www.techcrunch.com/", entityParams); - System.out.println(getStringFromDocument(doc)); + String doc = alchemyObj.URLGetRankedNamedEntities("http://www.techcrunch.com/", entityParams); + System.out.println(doc); // Extract a ranked list of named entities from a text string. doc = alchemyObj.TextGetRankedNamedEntities( "Hello there, my name is Bob Jones. I live in the United States of America. " + "Where do you live, Fred?", entityParams); - System.out.println(getStringFromDocument(doc)); + System.out.println(doc); // Load a HTML document to analyze. String htmlDoc = getFileContents("data/example.html"); // Extract a ranked list of named entities from a HTML document. doc = alchemyObj.HTMLGetRankedNamedEntities(htmlDoc, "http://www.test.com/", entityParams); - System.out.println(getStringFromDocument(doc)); + System.out.println(doc); } diff --git a/src/com/alchemyapi/test/RelationsTest.java b/src/com/alchemyapi/test/RelationsTest.java index 311a97c..845c039 100644 --- a/src/com/alchemyapi/test/RelationsTest.java +++ b/src/com/alchemyapi/test/RelationsTest.java @@ -22,21 +22,21 @@ public static void main(String[] args) AlchemyAPI alchemyObj = AlchemyAPI.GetInstanceFromFile("api_key.txt"); // Extract a ranked list of relations for a web URL. - Document doc = alchemyObj.URLGetRelations("http://www.techcrunch.com/"); - System.out.println(getStringFromDocument(doc)); + String doc = alchemyObj.URLGetRelations("http://www.techcrunch.com/"); + System.out.println(doc); // Extract a ranked list of relations from a text string. doc = alchemyObj.TextGetRelations( "Hello there, my name is Bob Jones. I live in the United States of America. " + "Where do you live, Fred?"); - System.out.println(getStringFromDocument(doc)); + System.out.println(doc); // Load a HTML document to analyze. String htmlDoc = getFileContents("data/example.html"); // Extract a ranked list of relations from a HTML document. doc = alchemyObj.HTMLGetRelations(htmlDoc, "http://www.test.com/"); - System.out.println(getStringFromDocument(doc)); + System.out.println(doc); AlchemyAPI_RelationParams relationParams = new AlchemyAPI_RelationParams(); relationParams.setSentiment(true); @@ -44,13 +44,13 @@ public static void main(String[] args) relationParams.setDisambiguate(true); relationParams.setSentimentExcludeEntities(true); doc = alchemyObj.TextGetRelations("Madonna enjoys tasty Pepsi. I love her style.", relationParams); - System.out.println(getStringFromDocument(doc)); + System.out.println(doc); relationParams.setSentiment(true); relationParams.setRequireEntities(true); relationParams.setSentimentExcludeEntities(true); doc = alchemyObj.TextGetRelations("Madonna enjoys tasty Pepsi. I love her style.", relationParams); - System.out.println(getStringFromDocument(doc)); + System.out.println(doc); } // utility function diff --git a/src/com/alchemyapi/test/SentimentTest.java b/src/com/alchemyapi/test/SentimentTest.java index f999645..01750ae 100644 --- a/src/com/alchemyapi/test/SentimentTest.java +++ b/src/com/alchemyapi/test/SentimentTest.java @@ -21,46 +21,46 @@ public static void main(String[] args) throws IOException, SAXException, AlchemyAPI alchemyObj = AlchemyAPI.GetInstanceFromFile("api_key.txt"); // Extract sentiment for a web URL. - Document doc = alchemyObj.URLGetTextSentiment("http://www.techcrunch.com/"); - System.out.println(getStringFromDocument(doc)); + String doc = alchemyObj.URLGetTextSentiment("http://www.techcrunch.com/"); + System.out.println(doc); // Extract sentiment for a text string. doc = alchemyObj.TextGetTextSentiment( "That hat is ridiculous, Charles."); - System.out.println(getStringFromDocument(doc)); + System.out.println(doc); // Load a HTML document to analyze. String htmlDoc = getFileContents("data/example.html"); // Extract sentiment for a HTML document. doc = alchemyObj.HTMLGetTextSentiment(htmlDoc, "http://www.test.com/"); - System.out.println(getStringFromDocument(doc)); + System.out.println(doc); // Extract entity-targeted sentiment from a HTML document. AlchemyAPI_NamedEntityParams entityParams = new AlchemyAPI_NamedEntityParams(); entityParams.setSentiment(true); doc = alchemyObj.TextGetRankedNamedEntities("That Mike Tyson is such a sweetheart.", entityParams); - System.out.println(getStringFromDocument(doc)); + System.out.println(doc); // Extract keyword-targeted sentiment from a HTML document. AlchemyAPI_KeywordParams keywordParams = new AlchemyAPI_KeywordParams(); keywordParams.setSentiment(true); doc = alchemyObj.TextGetRankedKeywords("That Mike Tyson is such a sweetheart.", keywordParams); - System.out.println(getStringFromDocument(doc)); + System.out.println(doc); //Extract Targeted Sentiment from text AlchemyAPI_TargetedSentimentParams sentimentParams = new AlchemyAPI_TargetedSentimentParams(); sentimentParams.setShowSourceText(true); doc = alchemyObj.TextGetTargetedSentiment("This car is terrible.", "car", sentimentParams); - System.out.print(getStringFromDocument(doc)); + System.out.print(doc); //Extract Targeted Sentiment from url doc = alchemyObj.URLGetTargetedSentiment("http://techcrunch.com/2012/03/01/keen-on-anand-rajaraman-how-walmart-wants-to-leapfrog-over-amazon-tctv/", "Walmart",sentimentParams); - System.out.print(getStringFromDocument(doc)); + System.out.print(doc); //Extract Targeted Sentiment from html doc = alchemyObj.HTMLGetTargetedSentiment(htmlDoc, "http://www.test.com/", "WujWuj", sentimentParams); - System.out.print(getStringFromDocument(doc)); + System.out.print(doc); } // utility function diff --git a/src/com/alchemyapi/test/TaxonomyTest.java b/src/com/alchemyapi/test/TaxonomyTest.java index d3ba089..679e330 100644 --- a/src/com/alchemyapi/test/TaxonomyTest.java +++ b/src/com/alchemyapi/test/TaxonomyTest.java @@ -22,21 +22,21 @@ public static void main(String[] args) AlchemyAPI alchemyObj = AlchemyAPI.GetInstanceFromFile("api_key.txt"); // Extract a ranked list of relations for a web URL. - Document doc = alchemyObj.URLGetTaxonomy("http://www.techcrunch.com/"); - System.out.println(getStringFromDocument(doc)); + String doc = alchemyObj.URLGetTaxonomy("http://www.techcrunch.com/"); + System.out.println(doc); // Extract a ranked taxonomy from a text string. doc = alchemyObj.TextGetTaxonomy( "Hello there, my name is Bob Jones. I live in the United States of America. " + "Where do you live, Fred?"); - System.out.println(getStringFromDocument(doc)); + System.out.println(doc); // Load a HTML document to analyze. String htmlDoc = getFileContents("data/example.html"); // Extract a ranked taxonomy from a HTML document. doc = alchemyObj.HTMLGetTaxonomy(htmlDoc, "http://www.test.com/"); - System.out.println(getStringFromDocument(doc)); + System.out.println(doc); } // utility function diff --git a/src/com/alchemyapi/test/TextExtractTest.java b/src/com/alchemyapi/test/TextExtractTest.java index d5e71e5..504193a 100644 --- a/src/com/alchemyapi/test/TextExtractTest.java +++ b/src/com/alchemyapi/test/TextExtractTest.java @@ -23,17 +23,17 @@ public static void main(String[] args) // Extract page text from a web URL. (ignoring ads, navigation links, // and other content). - Document doc = alchemyObj.URLGetText("http://www.techcrunch.com/"); - System.out.println(getStringFromDocument(doc)); + String doc = alchemyObj.URLGetText("http://www.techcrunch.com/"); + System.out.println(doc); // Extract raw page text from a web URL. (including ads, navigation // links, and other content). doc = alchemyObj.URLGetRawText("http://www.techcrunch.com/"); - System.out.println(getStringFromDocument(doc)); + System.out.println(doc); // Extract a title from a web URL. doc = alchemyObj.URLGetTitle("http://www.techcrunch.com/"); - System.out.println(getStringFromDocument(doc)); + System.out.println(doc); // Load a HTML document to analyze. String htmlDoc = getFileContents("data/example.html"); @@ -41,16 +41,16 @@ public static void main(String[] args) // Extract page text from a HTML document. (ignoring ads, navigation // links, and other content). doc = alchemyObj.HTMLGetText(htmlDoc, "http://www.test.com/"); - System.out.println(getStringFromDocument(doc)); + System.out.println(doc); // Extract raw page text from a HTML document. (including ads, // navigation links, and other content). doc = alchemyObj.HTMLGetRawText(htmlDoc, "http://www.test.com/"); - System.out.println(getStringFromDocument(doc)); + System.out.println(doc); // Extract a title from a HTML document. doc = alchemyObj.HTMLGetTitle(htmlDoc, "http://www.test.com/"); - System.out.println(getStringFromDocument(doc)); + System.out.println(doc); } // utility function