├── .gitignore
├── ChangeLog
├── LICENSE
├── README.md
├── build.xml
├── build_no_tests.xml
├── build_with_tests.xml
├── src
└── com
│ └── alchemyapi
│ ├── api
│ ├── AlchemyAPI.java
│ ├── AlchemyAPI_CategoryParams.java
│ ├── AlchemyAPI_CombinedParams.java
│ ├── AlchemyAPI_ConceptParams.java
│ ├── AlchemyAPI_ConstraintQueryParams.java
│ ├── AlchemyAPI_ImageParams.java
│ ├── AlchemyAPI_KeywordParams.java
│ ├── AlchemyAPI_LanguageParams.java
│ ├── AlchemyAPI_NamedEntityParams.java
│ ├── AlchemyAPI_Params.java
│ ├── AlchemyAPI_RelationParams.java
│ ├── AlchemyAPI_TargetedSentimentParams.java
│ ├── AlchemyAPI_TaxonomyParams.java
│ └── AlchemyAPI_TextParams.java
│ └── test
│ ├── AuthorTest.java
│ ├── CategoryTest.java
│ ├── CombinedTest.java
│ ├── ConceptTest.java
│ ├── ConstraintQueryTest.java
│ ├── EntityTest.java
│ ├── FeedLinksTest.java
│ ├── ImageTest.java
│ ├── KeywordTest.java
│ ├── LanguageTest.java
│ ├── MicroformatTest.java
│ ├── ParameterTest.java
│ ├── RelationsTest.java
│ ├── SentimentTest.java
│ ├── TaxonomyTest.java
│ └── TextExtractTest.java
└── testdir
├── api_key.txt
└── data
├── cat.jpg
├── example.html
├── example2.html
├── example2_nolinks.html
├── example3.html
└── microformats.html
/.gitignore:
--------------------------------------------------------------------------------
1 | bin
2 | dist
--------------------------------------------------------------------------------
/ChangeLog:
--------------------------------------------------------------------------------
1 | CHANGELOG
2 |
3 | 0.9 - Added support for combined call, ranked taxonomy & image extraction.
4 | 0.8 - Added support for author extraction & targeted sentiment.
5 | 0.7 - Added support for relations extraction.
6 | 0.6 - Added support for sentiment analysis.
7 | 0.5 - Added GetRankedConcepts calls and parameter object.
8 | 0.4.2 - Added Parameters, added RDF support
9 | 0.4.1 - Fixed compilation error in Entities example code.
10 | 0.4 - Added GetRankedKeywords calls, added TextGetCategory call.
11 | 0.3 - Added ConstraintQuery call, imports changes, exception reporting
12 | changes, general improvements.
13 | 0.2 - Added setApiKey() call, setApiHost() call, updated API endpoint.
14 | 0.1 - Initial Release
15 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ================================
2 | AlchemyAPI Java SDK: version 0.9
3 | ================================
4 |
5 | This is a Java implementation of the AlchemyAPI SDK - **_Please note that this legacy AlchemyAPI SDK is no longer supported by IBM. Please use the Watson SDKs https://github.com/watson-developer-cloud?utf8=✓&query=sdk_**
6 |
7 |
8 | INSTALLATION
9 |
10 | AlchemyAPI Java SDK provides Ant build files for systems lacking JUnit,
11 | an addition to JUnit-enabled build files. To build AlchemyAPI Java SDK
12 | without JUnit tests, type the following Ant command:
13 |
14 | ant jar
15 |
16 | If you desire to build AlchemyAPI Java SDK with JUnit tests enabled,
17 | rename your Ant .xml files and build using the following commands:
18 |
19 | ln -sf build_with_tests.xml build.xml; ant jar
20 |
21 |
22 | RUNNING EXAMPLES
23 |
24 | Several code examples are included to illustrate using the AlchemyAPI
25 | for named entity extraction, text classification, language identification,
26 | and other tasks.
27 |
28 | All code samples should be run from within the "testdir" directory.
29 |
30 | To run these code samples you must first edit the (testdir/api_key.txt) file,
31 | adding your assigned AlchemyAPI key.
32 |
33 | Code Samples:
34 |
35 | 1. Entity Extraction: java -jar ../dist/AlchemyAPI-Entity-Test.jar
36 |
37 | 2. Concept Tagging: java -jar ../dist/AlchemyAPI-Concept-Test.jar
38 |
39 | 3. Keyword Extraction: java -jar ../dist/AlchemyAPI-Keyword-Test.jar
40 |
41 | 4. Text Categorization: java -jar ../dist/AlchemyAPI-Category-Test.jar
42 |
43 | 5. Language Identification: java -jar ../dist/AlchemyAPI-Language-Test.jar
44 |
45 | 6. HTML Text Extraction: java -jar ../dist/AlchemyAPI-TextExtract-Test.jar
46 |
47 | 7. HTML Structured Content Scraping: java -jar ../dist/AlchemyAPI-ConstraintQuery-Test.jar
48 |
49 | 8. Microformats Extraction: java -jar ../dist/AlchemyAPI-Microformats-Test.jar
50 |
51 | 9. RSS / ATOM Feed Links Extraction: java -jar ../dist/AlchemyAPI-FeedLinks-Test.jar
52 |
53 | 10. Sentiment Analysis: java -jar ../dist/AlchemyAPI-Sentiment-Test.jar
54 |
55 | 11. Relations: java -jar ../dist/AlchemyAPI-Relations-Test.jar
56 |
57 | 12. Example of using the parameters object: java -jar ../dist/AlchemyAPI-Parameter-Test.jar
58 |
59 | 13. Author Extraction: java -jar ../dist/AlchemyAPI-Author-Test.jar
60 |
61 | 14. Combined Data Extraction: java -jar ../dist/AlchemyAPI-Combined-Test.jar
62 |
63 | 15. Ranked Taxonomy Extraction: java -jar ../dist/AlchemyAPI-Taxonomy-Test.jar
64 |
65 | 16. Image Extraction: java -jar ../dist/AlchemyAPI-Image-Test.jar
66 |
67 |
68 | DEPENDENCIES
69 |
70 | This module requires these other modules and libraries:
71 |
72 | Java JDK 1.5.x
73 | ANT (to build the packages)
74 | JUnit (optional, to build the tests)
75 |
76 |
77 | COPYRIGHT AND LICENCE
78 |
79 | Copyright (C) Orchestr8, LLC.
80 |
81 | This library is free software; you can redistribute it and/or modify
82 | it under the same terms as Perl version 5.8.5 or, at your option,
83 | any later version of Perl 5 you may have available.
84 |
85 |
86 |
--------------------------------------------------------------------------------
/build.xml:
--------------------------------------------------------------------------------
1 | build_with_tests.xml
--------------------------------------------------------------------------------
/build_no_tests.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Build file for AlchemyAPI code / examples.
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/build_with_tests.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Build file for AlchemyAPI code / examples.
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
--------------------------------------------------------------------------------
/src/com/alchemyapi/api/AlchemyAPI.java:
--------------------------------------------------------------------------------
1 | package com.alchemyapi.api;
2 |
3 | import java.io.File;
4 | import java.io.FileInputStream;
5 | import java.io.DataInputStream;
6 | import java.io.DataOutputStream;
7 | import java.io.InputStreamReader;
8 | import java.io.BufferedReader;
9 | import java.io.IOException;
10 | import java.io.FileNotFoundException;
11 |
12 | import java.net.HttpURLConnection;
13 | import java.net.URL;
14 |
15 | import javax.xml.parsers.DocumentBuilderFactory;
16 | import javax.xml.parsers.ParserConfigurationException;
17 | import javax.xml.xpath.*;
18 |
19 | import org.w3c.dom.Document;
20 | import org.w3c.dom.NodeList;
21 |
22 | import org.xml.sax.SAXException;
23 |
24 | public class AlchemyAPI {
25 |
26 | private String _apiKey;
27 | private String _requestUri = "http://access.alchemyapi.com/calls/";
28 |
29 | private AlchemyAPI() {
30 | }
31 |
32 |
33 | static public AlchemyAPI GetInstanceFromFile(String keyFilename)
34 | throws FileNotFoundException, IOException
35 | {
36 | AlchemyAPI api = new AlchemyAPI();
37 | api.LoadAPIKey(keyFilename);
38 |
39 | return api;
40 | }
41 |
42 | static public AlchemyAPI GetInstanceFromString(String apiKey)
43 | {
44 | AlchemyAPI api = new AlchemyAPI();
45 | api.SetAPIKey(apiKey);
46 |
47 | return api;
48 | }
49 |
50 | public void LoadAPIKey(String filename) throws IOException, FileNotFoundException
51 | {
52 | if (null == filename || 0 == filename.length())
53 | throw new IllegalArgumentException("Empty API key file specified.");
54 |
55 | File file = new File(filename);
56 | FileInputStream fis = new FileInputStream(file);
57 |
58 | BufferedReader breader = new BufferedReader(new InputStreamReader(fis));
59 |
60 | _apiKey = breader.readLine().replaceAll("\\n", "").replaceAll("\\r", "");
61 |
62 | fis.close();
63 | breader.close();
64 |
65 | if (null == _apiKey || _apiKey.length() < 5)
66 | throw new IllegalArgumentException("Too short API key.");
67 | }
68 |
69 | public void SetAPIKey(String apiKey) {
70 | _apiKey = apiKey;
71 |
72 | if (null == _apiKey || _apiKey.length() < 5)
73 | throw new IllegalArgumentException("Too short API key.");
74 | }
75 |
76 | public void SetAPIHost(String apiHost) {
77 | if (null == apiHost || apiHost.length() < 2)
78 | throw new IllegalArgumentException("Too short API host.");
79 |
80 | _requestUri = "http://" + apiHost + ".alchemyapi.com/calls/";
81 | }
82 |
83 | public Document URLGetAuthor(String url)
84 | throws IOException, SAXException,
85 | ParserConfigurationException, XPathExpressionException
86 | {
87 | return URLGetAuthor(url, new AlchemyAPI_Params());
88 | }
89 |
90 | public Document URLGetAuthor(String url, AlchemyAPI_Params params)
91 | throws IOException, SAXException, ParserConfigurationException,
92 | XPathExpressionException
93 | {
94 | CheckURL(url);
95 |
96 | params.setUrl(url);
97 |
98 | return GET("URLGetAuthor", "url", params);
99 | }
100 |
101 | public Document HTMLGetAuthor(String html, String url)
102 | throws IOException, SAXException, ParserConfigurationException,
103 | XPathExpressionException
104 | {
105 | return HTMLGetAuthor(html, url, new AlchemyAPI_Params());
106 | }
107 |
108 | public Document HTMLGetAuthor(String html, String url,
109 | AlchemyAPI_Params params)
110 | throws IOException, SAXException,
111 | ParserConfigurationException, XPathExpressionException
112 | {
113 | CheckHTML(html, url);
114 |
115 | params.setHtml(html);
116 | params.setUrl(url);
117 |
118 | return POST("HTMLGetAuthor", "html", params);
119 | }
120 |
121 | public Document URLGetRankedNamedEntities(String url)
122 | throws IOException, SAXException,
123 | ParserConfigurationException, XPathExpressionException
124 | {
125 | return URLGetRankedNamedEntities(url, new AlchemyAPI_NamedEntityParams());
126 | }
127 |
128 | public Document URLGetRankedNamedEntities(String url, AlchemyAPI_NamedEntityParams params)
129 | throws IOException, SAXException,
130 | ParserConfigurationException, XPathExpressionException
131 | {
132 | CheckURL(url);
133 |
134 | params.setUrl(url);
135 |
136 | return GET("URLGetRankedNamedEntities", "url", params);
137 | }
138 |
139 | public Document HTMLGetRankedNamedEntities(String html, String url)
140 | throws IOException, SAXException,
141 | ParserConfigurationException, XPathExpressionException
142 | {
143 | return HTMLGetRankedNamedEntities(html, url, new AlchemyAPI_NamedEntityParams());
144 | }
145 |
146 |
147 | public Document HTMLGetRankedNamedEntities(String html, String url, AlchemyAPI_NamedEntityParams params)
148 | throws IOException, SAXException,
149 | ParserConfigurationException, XPathExpressionException
150 | {
151 | CheckHTML(html, url);
152 |
153 | params.setUrl(url);
154 | params.setHtml(html);
155 |
156 | return POST("HTMLGetRankedNamedEntities", "html", params);
157 | }
158 |
159 | public Document TextGetRankedNamedEntities(String text)
160 | throws IOException, SAXException,
161 | ParserConfigurationException, XPathExpressionException
162 | {
163 | return TextGetRankedNamedEntities(text, new AlchemyAPI_NamedEntityParams());
164 | }
165 |
166 | public Document TextGetRankedNamedEntities(String text, AlchemyAPI_NamedEntityParams params)
167 | throws IOException, SAXException,
168 | ParserConfigurationException, XPathExpressionException
169 | {
170 | CheckText(text);
171 |
172 | params.setText(text);
173 |
174 | return POST("TextGetRankedNamedEntities", "text", params);
175 | }
176 |
177 |
178 |
179 | public Document URLGetRankedConcepts(String url)
180 | throws IOException, SAXException,
181 | ParserConfigurationException, XPathExpressionException
182 | {
183 | return URLGetRankedConcepts(url, new AlchemyAPI_ConceptParams());
184 | }
185 |
186 | public Document URLGetRankedConcepts(String url, AlchemyAPI_ConceptParams params)
187 | throws IOException, SAXException,
188 | ParserConfigurationException, XPathExpressionException
189 | {
190 | CheckURL(url);
191 |
192 | params.setUrl(url);
193 |
194 | return GET("URLGetRankedConcepts", "url", params);
195 | }
196 |
197 |
198 | public Document HTMLGetRankedConcepts(String html, String url)
199 | throws IOException, SAXException,
200 | ParserConfigurationException, XPathExpressionException
201 | {
202 | return HTMLGetRankedConcepts(html, url, new AlchemyAPI_ConceptParams());
203 | }
204 |
205 | public Document HTMLGetRankedConcepts(String html, String url, AlchemyAPI_ConceptParams params)
206 | throws IOException, SAXException,
207 | ParserConfigurationException, XPathExpressionException
208 | {
209 | CheckHTML(html, url);
210 |
211 | params.setUrl(url);
212 | params.setHtml(html);
213 |
214 | return POST("HTMLGetRankedConcepts", "html", params);
215 | }
216 |
217 | public Document TextGetRankedConcepts(String text) throws IOException, SAXException,
218 | ParserConfigurationException, XPathExpressionException {
219 | return TextGetRankedConcepts(text, new AlchemyAPI_ConceptParams());
220 | }
221 |
222 | public Document TextGetRankedConcepts(String text, AlchemyAPI_ConceptParams params) throws IOException, SAXException,
223 | ParserConfigurationException, XPathExpressionException
224 | {
225 | CheckText(text);
226 |
227 | params.setText(text);
228 |
229 | return POST("TextGetRankedConcepts", "text", params);
230 | }
231 |
232 |
233 |
234 | public Document URLGetRankedKeywords(String url)
235 | throws IOException, SAXException,
236 | ParserConfigurationException, XPathExpressionException
237 | {
238 | return URLGetRankedKeywords(url, new AlchemyAPI_KeywordParams());
239 | }
240 |
241 | public Document URLGetRankedKeywords(String url, AlchemyAPI_KeywordParams params)
242 | throws IOException, SAXException,
243 | ParserConfigurationException, XPathExpressionException
244 | {
245 | CheckURL(url);
246 |
247 | params.setUrl(url);
248 |
249 | return GET("URLGetRankedKeywords", "url", params);
250 | }
251 |
252 |
253 | public Document HTMLGetRankedKeywords(String html, String url)
254 | throws IOException, SAXException,
255 | ParserConfigurationException, XPathExpressionException
256 | {
257 | return HTMLGetRankedKeywords(html, url, new AlchemyAPI_KeywordParams());
258 | }
259 |
260 | public Document HTMLGetRankedKeywords(String html, String url, AlchemyAPI_KeywordParams params)
261 | throws IOException, SAXException,
262 | ParserConfigurationException, XPathExpressionException
263 | {
264 | CheckHTML(html, url);
265 |
266 | params.setUrl(url);
267 | params.setHtml(html);
268 |
269 | return POST("HTMLGetRankedKeywords", "html", params);
270 | }
271 |
272 | public Document TextGetRankedKeywords(String text) throws IOException, SAXException,
273 | ParserConfigurationException, XPathExpressionException {
274 | return TextGetRankedKeywords(text, new AlchemyAPI_KeywordParams());
275 | }
276 |
277 | public Document TextGetRankedKeywords(String text, AlchemyAPI_KeywordParams params) throws IOException, SAXException,
278 | ParserConfigurationException, XPathExpressionException
279 | {
280 | CheckText(text);
281 |
282 | params.setText(text);
283 |
284 | return POST("TextGetRankedKeywords", "text", params);
285 | }
286 |
287 | public Document URLGetLanguage(String url)
288 | throws IOException, SAXException,
289 | ParserConfigurationException, XPathExpressionException
290 | {
291 | return URLGetLanguage(url, new AlchemyAPI_LanguageParams());
292 | }
293 |
294 | public Document URLGetLanguage(String url, AlchemyAPI_LanguageParams params)
295 | throws IOException, SAXException,
296 | ParserConfigurationException, XPathExpressionException
297 | {
298 | CheckURL(url);
299 |
300 | params.setUrl(url);
301 |
302 | return GET("URLGetLanguage", "url", params);
303 | }
304 |
305 | public Document HTMLGetLanguage(String html, String url)
306 | throws IOException, SAXException,
307 | ParserConfigurationException, XPathExpressionException
308 | {
309 | return HTMLGetLanguage(html, url, new AlchemyAPI_LanguageParams());
310 | }
311 |
312 | public Document HTMLGetLanguage(String html, String url, AlchemyAPI_LanguageParams params)
313 | throws IOException, SAXException,
314 | ParserConfigurationException, XPathExpressionException
315 | {
316 | CheckHTML(html, url);
317 |
318 | params.setUrl(url);
319 | params.setHtml(html);
320 |
321 | return POST("HTMLGetLanguage", "html", params);
322 | }
323 |
324 | public Document TextGetLanguage(String text)
325 | throws IOException, SAXException,
326 | ParserConfigurationException, XPathExpressionException
327 | {
328 | return TextGetLanguage(text, new AlchemyAPI_LanguageParams());
329 | }
330 |
331 | public Document TextGetLanguage(String text, AlchemyAPI_LanguageParams params)
332 | throws IOException, SAXException,
333 | ParserConfigurationException, XPathExpressionException
334 | {
335 | CheckText(text);
336 |
337 | params.setText(text);
338 |
339 | return POST("TextGetLanguage", "text", params);
340 | }
341 |
342 | public Document URLGetCategory(String url)
343 | throws IOException, SAXException,
344 | ParserConfigurationException, XPathExpressionException
345 | {
346 | return URLGetCategory(url, new AlchemyAPI_CategoryParams());
347 | }
348 |
349 | public Document URLGetCategory(String url, AlchemyAPI_CategoryParams params)
350 | throws IOException, SAXException,
351 | ParserConfigurationException, XPathExpressionException
352 | {
353 | CheckURL(url);
354 |
355 | params.setUrl(url);
356 |
357 | return GET("URLGetCategory", "url", params);
358 | }
359 |
360 | public Document HTMLGetCategory(String html, String url)
361 | throws IOException, SAXException,
362 | ParserConfigurationException, XPathExpressionException
363 | {
364 | return HTMLGetCategory(html, url, new AlchemyAPI_CategoryParams());
365 | }
366 |
367 | public Document HTMLGetCategory(String html, String url, AlchemyAPI_CategoryParams params)
368 | throws IOException, SAXException,
369 | ParserConfigurationException, XPathExpressionException
370 | {
371 | CheckHTML(html, url);
372 |
373 | params.setUrl(url);
374 | params.setHtml(html);
375 |
376 | return POST("HTMLGetCategory", "html", params);
377 | }
378 |
379 | public Document TextGetCategory(String text)
380 | throws IOException, SAXException,
381 | ParserConfigurationException, XPathExpressionException
382 | {
383 | return TextGetCategory(text, new AlchemyAPI_TextParams());
384 | }
385 |
386 | public Document TextGetCategory(String text, AlchemyAPI_TextParams params)
387 | throws IOException, SAXException,
388 | ParserConfigurationException, XPathExpressionException
389 | {
390 | CheckText(text);
391 |
392 | params.setText(text);
393 |
394 | return POST("TextGetCategory", "text", params);
395 | }
396 |
397 | public Document URLGetText(String url)
398 | throws IOException, SAXException,
399 | ParserConfigurationException, XPathExpressionException
400 | {
401 | return URLGetText(url, new AlchemyAPI_TextParams());
402 | }
403 |
404 | public Document URLGetText(String url, AlchemyAPI_TextParams params)
405 | throws IOException, SAXException,
406 | ParserConfigurationException, XPathExpressionException
407 | {
408 | CheckURL(url);
409 |
410 | params.setUrl(url);
411 |
412 | return GET("URLGetText", "url", params);
413 | }
414 |
415 | public Document HTMLGetText(String html, String url)
416 | throws IOException, SAXException,
417 | ParserConfigurationException, XPathExpressionException
418 | {
419 | return HTMLGetText(html, url, new AlchemyAPI_TextParams());
420 | }
421 |
422 | public Document HTMLGetText(String html, String url, AlchemyAPI_TextParams params)
423 | throws IOException, SAXException,
424 | ParserConfigurationException, XPathExpressionException
425 | {
426 | CheckHTML(html, url);
427 |
428 | params.setUrl(url);
429 | params.setHtml(html);
430 |
431 | return POST("HTMLGetText", "html", params);
432 | }
433 |
434 | public Document URLGetRawText(String url)
435 | throws IOException, SAXException,
436 | ParserConfigurationException, XPathExpressionException
437 | {
438 | return URLGetRawText(url, new AlchemyAPI_Params());
439 | }
440 |
441 | public Document URLGetRawText(String url, AlchemyAPI_Params params)
442 | throws IOException, SAXException,
443 | ParserConfigurationException, XPathExpressionException
444 | {
445 | CheckURL(url);
446 |
447 | params.setUrl(url);
448 |
449 | return GET("URLGetRawText", "url", params);
450 | }
451 |
452 | public Document HTMLGetRawText(String html, String url)
453 | throws IOException, SAXException,
454 | ParserConfigurationException, XPathExpressionException
455 | {
456 | return HTMLGetRawText(html, url, new AlchemyAPI_Params());
457 | }
458 |
459 | public Document HTMLGetRawText(String html, String url, AlchemyAPI_Params params)
460 | throws IOException, SAXException,
461 | ParserConfigurationException, XPathExpressionException
462 | {
463 | CheckHTML(html, url);
464 |
465 | params.setUrl(url);
466 | params.setHtml(html);
467 |
468 | return POST("HTMLGetRawText", "html", params);
469 | }
470 |
471 | public Document URLGetTitle(String url)
472 | throws IOException, SAXException,
473 | ParserConfigurationException, XPathExpressionException
474 | {
475 | return URLGetTitle(url, new AlchemyAPI_Params());
476 | }
477 |
478 | public Document URLGetTitle(String url, AlchemyAPI_Params params)
479 | throws IOException, SAXException,
480 | ParserConfigurationException, XPathExpressionException
481 | {
482 | CheckURL(url);
483 |
484 | params.setUrl(url);
485 |
486 | return GET("URLGetTitle", "url", params);
487 | }
488 |
489 | public Document HTMLGetTitle(String html, String url)
490 | throws IOException, SAXException,
491 | ParserConfigurationException, XPathExpressionException
492 | {
493 | return HTMLGetTitle(html, url, new AlchemyAPI_Params());
494 | }
495 |
496 | public Document HTMLGetTitle(String html, String url, AlchemyAPI_Params params)
497 | throws IOException, SAXException,
498 | ParserConfigurationException, XPathExpressionException
499 | {
500 | CheckHTML(html, url);
501 |
502 | params.setUrl(url);
503 | params.setHtml(html);
504 |
505 | return POST("HTMLGetTitle", "html", params);
506 | }
507 |
508 | public Document URLGetFeedLinks(String url)
509 | throws IOException, SAXException,
510 | ParserConfigurationException, XPathExpressionException
511 | {
512 | return URLGetFeedLinks(url, new AlchemyAPI_Params());
513 | }
514 |
515 | public Document URLGetFeedLinks(String url, AlchemyAPI_Params params)
516 | throws IOException, SAXException,
517 | ParserConfigurationException, XPathExpressionException
518 | {
519 | CheckURL(url);
520 |
521 | params.setUrl(url);
522 |
523 | return GET("URLGetFeedLinks", "url", params);
524 | }
525 |
526 | public Document HTMLGetFeedLinks(String html, String url)
527 | throws IOException, SAXException,
528 | ParserConfigurationException, XPathExpressionException
529 | {
530 | return HTMLGetFeedLinks(html, url, new AlchemyAPI_Params());
531 | }
532 |
533 | public Document HTMLGetFeedLinks(String html, String url, AlchemyAPI_Params params)
534 | throws IOException, SAXException,
535 | ParserConfigurationException, XPathExpressionException
536 | {
537 | CheckHTML(html, url);
538 |
539 | params.setUrl(url);
540 | params.setHtml(html);
541 |
542 | return POST("HTMLGetFeedLinks", "html", params);
543 | }
544 |
545 | public Document URLGetMicroformats(String url)
546 | throws IOException, SAXException,
547 | ParserConfigurationException, XPathExpressionException
548 | {
549 | return URLGetMicroformats(url, new AlchemyAPI_Params());
550 | }
551 |
552 | public Document URLGetMicroformats(String url, AlchemyAPI_Params params)
553 | throws IOException, SAXException,
554 | ParserConfigurationException, XPathExpressionException
555 | {
556 | CheckURL(url);
557 |
558 | params.setUrl(url);
559 |
560 | return GET("URLGetMicroformatData", "url", params);
561 | }
562 |
563 | public Document HTMLGetMicroformats(String html, String url)
564 | throws IOException, SAXException,
565 | ParserConfigurationException, XPathExpressionException
566 | {
567 | return HTMLGetMicroformats(html, url, new AlchemyAPI_Params());
568 | }
569 |
570 | public Document HTMLGetMicroformats(String html, String url, AlchemyAPI_Params params)
571 | throws IOException, SAXException,
572 | ParserConfigurationException, XPathExpressionException
573 | {
574 | CheckHTML(html, url);
575 |
576 | params.setUrl(url);
577 | params.setHtml(html);
578 |
579 | return POST("HTMLGetMicroformatData", "html", params);
580 | }
581 |
582 | public Document URLGetConstraintQuery(String url, String query)
583 | throws IOException, XPathExpressionException,
584 | SAXException, ParserConfigurationException
585 | {
586 | return URLGetConstraintQuery(url, query, new AlchemyAPI_ConstraintQueryParams());
587 | }
588 |
589 | public Document URLGetConstraintQuery(String url, String query, AlchemyAPI_ConstraintQueryParams params)
590 | throws IOException, XPathExpressionException,
591 | SAXException, ParserConfigurationException
592 | {
593 | CheckURL(url);
594 | if (null == query || query.length() < 2)
595 | throw new IllegalArgumentException("Invalid constraint query specified");
596 |
597 | params.setUrl(url);
598 | params.setCQuery(query);
599 |
600 | return POST("URLGetConstraintQuery", "url", params);
601 | }
602 |
603 |
604 | public Document HTMLGetConstraintQuery(String html, String url, String query)
605 | throws IOException, XPathExpressionException,
606 | SAXException, ParserConfigurationException
607 | {
608 | return HTMLGetConstraintQuery(html, url, query, new AlchemyAPI_ConstraintQueryParams());
609 | }
610 |
611 | public Document HTMLGetConstraintQuery(String html, String url, String query, AlchemyAPI_ConstraintQueryParams params)
612 | throws IOException, XPathExpressionException,
613 | SAXException, ParserConfigurationException
614 | {
615 | CheckHTML(html, url);
616 | if (null == query || query.length() < 2)
617 | throw new IllegalArgumentException("Invalid constraint query specified");
618 |
619 | params.setUrl(url);
620 | params.setHtml(html);
621 | params.setCQuery(query);
622 |
623 | return POST("HTMLGetConstraintQuery", "html", params);
624 | }
625 |
626 | public Document URLGetTextSentiment(String url)
627 | throws IOException, SAXException,
628 | ParserConfigurationException, XPathExpressionException
629 | {
630 | return URLGetTextSentiment(url, new AlchemyAPI_Params());
631 | }
632 |
633 | public Document URLGetTextSentiment(String url, AlchemyAPI_Params params)
634 | throws IOException, SAXException,
635 | ParserConfigurationException, XPathExpressionException
636 | {
637 | CheckURL(url);
638 |
639 | params.setUrl(url);
640 |
641 | return GET("URLGetTextSentiment", "url", params);
642 | }
643 |
644 |
645 | public Document HTMLGetTextSentiment(String html, String url)
646 | throws IOException, SAXException,
647 | ParserConfigurationException, XPathExpressionException
648 | {
649 | return HTMLGetTextSentiment(html, url, new AlchemyAPI_Params());
650 | }
651 |
652 | public Document HTMLGetTextSentiment(String html, String url, AlchemyAPI_Params params)
653 | throws IOException, SAXException,
654 | ParserConfigurationException, XPathExpressionException
655 | {
656 | CheckHTML(html, url);
657 |
658 | params.setUrl(url);
659 | params.setHtml(html);
660 |
661 | return POST("HTMLGetTextSentiment", "html", params);
662 | }
663 |
664 | public Document TextGetTextSentiment(String text)
665 | throws IOException, SAXException,
666 | ParserConfigurationException, XPathExpressionException
667 | {
668 | return TextGetTextSentiment(text, new AlchemyAPI_Params());
669 | }
670 |
671 | public Document TextGetTextSentiment(String text, AlchemyAPI_Params params)
672 | throws IOException, SAXException,
673 | ParserConfigurationException, XPathExpressionException
674 | {
675 | CheckText(text);
676 |
677 | params.setText(text);
678 |
679 | return POST("TextGetTextSentiment", "text", params);
680 | }
681 |
682 | //------------------
683 |
684 | public Document URLGetTargetedSentiment(String url, String target)
685 | throws IOException, SAXException, ParserConfigurationException,
686 | XPathExpressionException
687 | {
688 | return URLGetTargetedSentiment(url, target,
689 | new AlchemyAPI_TargetedSentimentParams());
690 | }
691 |
692 | public Document URLGetTargetedSentiment(String url, String target,
693 | AlchemyAPI_TargetedSentimentParams params)
694 | throws IOException, SAXException, ParserConfigurationException,
695 | XPathExpressionException
696 | {
697 | CheckURL(url);
698 | CheckText(target);
699 |
700 | params.setUrl(url);
701 | params.setTarget(target);
702 |
703 | return GET("URLGetTargetedSentiment", "url", params);
704 | }
705 |
706 | public Document HTMLGetTargetedSentiment(String html, String url, String target)
707 | throws IOException, SAXException, ParserConfigurationException,
708 | XPathExpressionException
709 | {
710 | return HTMLGetTargetedSentiment(html, url, target,
711 | new AlchemyAPI_TargetedSentimentParams());
712 | }
713 |
714 | public Document HTMLGetTargetedSentiment(String html, String url, String target,
715 | AlchemyAPI_TargetedSentimentParams params)
716 | throws IOException, SAXException, ParserConfigurationException,
717 | XPathExpressionException
718 | {
719 | CheckHTML(html, url);
720 | CheckText(target);
721 |
722 | params.setHtml(html);
723 | params.setUrl(url);
724 | params.setTarget(target);
725 |
726 | return POST("HTMLGetTargetedSentiment", "html", params);
727 | }
728 |
729 | public Document TextGetTargetedSentiment(String text, String target)
730 | throws IOException, SAXException, ParserConfigurationException,
731 | XPathExpressionException
732 | {
733 | return TextGetTargetedSentiment(text, target,
734 | new AlchemyAPI_TargetedSentimentParams());
735 | }
736 |
737 | public Document TextGetTargetedSentiment(String text, String target,
738 | AlchemyAPI_TargetedSentimentParams params)
739 | throws IOException, SAXException, ParserConfigurationException,
740 | XPathExpressionException
741 | {
742 | CheckText(text);
743 | CheckText(target);
744 |
745 | params.setText(text);
746 | params.setTarget(target);
747 |
748 | return POST("TextGetTargetedSentiment", "text", params);
749 | }
750 |
751 | //------------------
752 |
753 | public Document URLGetRelations(String url) throws IOException, SAXException,
754 | ParserConfigurationException, XPathExpressionException
755 | {
756 | return URLGetRelations(url, new AlchemyAPI_RelationParams());
757 | }
758 |
759 | public Document URLGetRelations(String url, AlchemyAPI_RelationParams params)
760 | throws IOException, SAXException,
761 | ParserConfigurationException, XPathExpressionException
762 | {
763 | CheckURL(url);
764 |
765 | params.setUrl(url);
766 |
767 | return GET("URLGetRelations", "url", params);
768 | }
769 |
770 | public Document HTMLGetRelations(String html, String url)
771 | throws IOException, SAXException,
772 | ParserConfigurationException, XPathExpressionException
773 | {
774 | return HTMLGetRelations(html, url, new AlchemyAPI_RelationParams());
775 | }
776 |
777 | public Document HTMLGetRelations(String html, String url, AlchemyAPI_RelationParams params)
778 | throws IOException, SAXException,
779 | ParserConfigurationException, XPathExpressionException
780 | {
781 | CheckHTML(html, url);
782 |
783 | params.setUrl(url);
784 | params.setHtml(html);
785 |
786 | return POST("HTMLGetRelations", "html", params);
787 | }
788 |
789 | public Document TextGetRelations(String text)
790 | throws IOException, SAXException,
791 | ParserConfigurationException, XPathExpressionException
792 | {
793 | return TextGetRelations(text, new AlchemyAPI_RelationParams());
794 | }
795 |
796 | public Document TextGetRelations(String text, AlchemyAPI_RelationParams params)
797 | throws IOException, SAXException,
798 | ParserConfigurationException, XPathExpressionException
799 | {
800 | CheckText(text);
801 |
802 | params.setText(text);
803 |
804 | return POST("TextGetRelations", "text", params);
805 | }
806 |
807 | //------------------
808 |
809 | public Document URLGetCombined(String url) throws IOException, SAXException,
810 | ParserConfigurationException, XPathExpressionException
811 | {
812 | AlchemyAPI_CombinedParams params = new AlchemyAPI_CombinedParams();
813 | params.setExtractAll();
814 | return URLGetCombined(url, params);
815 | }
816 |
817 | public Document URLGetCombined(String url, AlchemyAPI_CombinedParams params)
818 | throws IOException, SAXException,
819 | ParserConfigurationException, XPathExpressionException
820 | {
821 | CheckURL(url);
822 |
823 | params.setUrl(url);
824 |
825 | return GET("URLGetCombinedData", "url", params);
826 | }
827 |
828 | public Document TextGetCombined(String text)
829 | throws IOException, SAXException,
830 | ParserConfigurationException, XPathExpressionException
831 | {
832 | AlchemyAPI_CombinedParams params = new AlchemyAPI_CombinedParams();
833 | params.setExtractAll();
834 | return TextGetCombined(text, params);
835 | }
836 |
837 | public Document TextGetCombined(String text, AlchemyAPI_CombinedParams params)
838 | throws IOException, SAXException,
839 | ParserConfigurationException, XPathExpressionException
840 | {
841 | CheckText(text);
842 |
843 | params.setText(text);
844 |
845 | return POST("TextGetCombinedData", "text", params);
846 | }
847 |
848 | //------------------
849 |
850 | public Document URLGetTaxonomy(String url) throws IOException, SAXException,
851 | ParserConfigurationException, XPathExpressionException
852 | {
853 | return URLGetTaxonomy(url, new AlchemyAPI_TaxonomyParams());
854 | }
855 |
856 | public Document URLGetTaxonomy(String url, AlchemyAPI_TaxonomyParams params)
857 | throws IOException, SAXException,
858 | ParserConfigurationException, XPathExpressionException
859 | {
860 | CheckURL(url);
861 |
862 | params.setUrl(url);
863 |
864 | return GET("URLGetRankedTaxonomy", "url", params);
865 | }
866 |
867 | public Document HTMLGetTaxonomy(String html, String url)
868 | throws IOException, SAXException,
869 | ParserConfigurationException, XPathExpressionException
870 | {
871 | return HTMLGetTaxonomy(html, url, new AlchemyAPI_TaxonomyParams());
872 | }
873 |
874 | public Document HTMLGetTaxonomy(String html, String url, AlchemyAPI_TaxonomyParams params)
875 | throws IOException, SAXException,
876 | ParserConfigurationException, XPathExpressionException
877 | {
878 | CheckHTML(html, url);
879 |
880 | params.setUrl(url);
881 | params.setHtml(html);
882 |
883 | return POST("HTMLGetRankedTaxonomy", "html", params);
884 | }
885 |
886 | public Document TextGetTaxonomy(String text)
887 | throws IOException, SAXException,
888 | ParserConfigurationException, XPathExpressionException
889 | {
890 | return TextGetTaxonomy(text, new AlchemyAPI_TaxonomyParams());
891 | }
892 |
893 | public Document TextGetTaxonomy(String text, AlchemyAPI_TaxonomyParams params)
894 | throws IOException, SAXException,
895 | ParserConfigurationException, XPathExpressionException
896 | {
897 | CheckText(text);
898 |
899 | params.setText(text);
900 |
901 | return POST("TextGetRankedTaxonomy", "text", params);
902 | }
903 |
904 | //------------------
905 |
906 | public Document URLGetImage(String url) throws IOException, SAXException,
907 | ParserConfigurationException, XPathExpressionException
908 | {
909 | return URLGetImage(url, new AlchemyAPI_ImageParams());
910 | }
911 |
912 | public Document URLGetImage(String url, AlchemyAPI_ImageParams params)
913 | throws IOException, SAXException,
914 | ParserConfigurationException, XPathExpressionException
915 | {
916 | CheckURL(url);
917 |
918 | params.setUrl(url);
919 |
920 | return GET("URLGetImage", "url", params);
921 | }
922 |
923 | public Document URLGetRankedImageKeywords(String url) throws IOException, SAXException,
924 | ParserConfigurationException, XPathExpressionException
925 | {
926 | return URLGetRankedImageKeywords(url, new AlchemyAPI_ImageParams());
927 | }
928 |
929 | public Document URLGetRankedImageKeywords(String url, AlchemyAPI_ImageParams params)
930 | throws IOException, SAXException,
931 | ParserConfigurationException, XPathExpressionException
932 | {
933 | CheckURL(url);
934 |
935 | params.setUrl(url);
936 |
937 | return GET("URLGetRankedImageKeywords", "url", params);
938 | }
939 |
940 | public Document ImageGetRankedImageKeywords(AlchemyAPI_ImageParams params)
941 | throws IOException, SAXException,
942 | ParserConfigurationException, XPathExpressionException
943 | {
944 | URL url = new URL(_requestUri + "image/ImageGetRankedImageKeywords?" +
945 | "apikey=" + this._apiKey + params.getParameterString());
946 | System.out.println(url.toString());
947 |
948 | HttpURLConnection handle = (HttpURLConnection) url.openConnection();
949 | handle.setDoOutput(true);
950 |
951 | byte[] image = params.getImage();
952 | handle.addRequestProperty("Content-Length", Integer.toString(image.length));
953 |
954 | DataOutputStream ostream = new DataOutputStream(handle.getOutputStream());
955 | ostream.write(image);
956 | ostream.close();
957 |
958 | return doRequest(handle, params.getOutputMode());
959 | }
960 |
961 | private void CheckHTML(String html, String url) {
962 | if (null == html || html.length() < 5)
963 | throw new IllegalArgumentException("Enter a HTML document to analyze.");
964 |
965 | if (null == url || url.length() < 10)
966 | throw new IllegalArgumentException("Enter an URL to analyze.");
967 | }
968 |
969 | private void CheckText(String text) {
970 | if (null == text )
971 | throw new IllegalArgumentException("Enter some text to analyze.");
972 | }
973 |
974 | private void CheckURL(String url) {
975 | if (null == url || url.length() < 10)
976 | throw new IllegalArgumentException("Enter an URL to analyze.");
977 | }
978 |
979 | private Document GET(String callName, String callPrefix, AlchemyAPI_Params params)
980 | throws IOException, SAXException,
981 | ParserConfigurationException, XPathExpressionException
982 | {
983 | StringBuilder uri = new StringBuilder();
984 | uri.append(_requestUri).append(callPrefix).append('/').append(callName)
985 | .append('?').append("apikey=").append(this._apiKey);
986 | uri.append(params.getParameterString());
987 |
988 | URL url = new URL(uri.toString());
989 | HttpURLConnection handle = (HttpURLConnection) url.openConnection();
990 | handle.setDoOutput(true);
991 |
992 | return doRequest(handle, params.getOutputMode());
993 | }
994 |
995 | private Document POST(String callName, String callPrefix, AlchemyAPI_Params params)
996 | throws IOException, SAXException,
997 | ParserConfigurationException, XPathExpressionException
998 | {
999 | URL url = new URL(_requestUri + callPrefix + "/" + callName);
1000 |
1001 | HttpURLConnection handle = (HttpURLConnection) url.openConnection();
1002 | handle.setDoOutput(true);
1003 |
1004 | StringBuilder data = new StringBuilder();
1005 |
1006 | data.append("apikey=").append(this._apiKey);
1007 | data.append(params.getParameterString());
1008 |
1009 | handle.addRequestProperty("Content-Length", Integer.toString(data.length()));
1010 |
1011 | DataOutputStream ostream = new DataOutputStream(handle.getOutputStream());
1012 | ostream.write(data.toString().getBytes());
1013 | ostream.close();
1014 |
1015 | return doRequest(handle, params.getOutputMode());
1016 | }
1017 |
1018 | private Document doRequest(HttpURLConnection handle, String outputMode)
1019 | throws IOException, SAXException,
1020 | ParserConfigurationException, XPathExpressionException
1021 | {
1022 | DataInputStream istream = new DataInputStream(handle.getInputStream());
1023 | Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(istream);
1024 |
1025 | istream.close();
1026 | handle.disconnect();
1027 |
1028 | XPathFactory factory = XPathFactory.newInstance();
1029 |
1030 | if(AlchemyAPI_Params.OUTPUT_XML.equals(outputMode)) {
1031 | String statusStr = getNodeValue(factory, doc, "/results/status/text()");
1032 | if (null == statusStr || !statusStr.equals("OK")) {
1033 | String statusInfoStr = getNodeValue(factory, doc, "/results/statusInfo/text()");
1034 | if (null != statusInfoStr && statusInfoStr.length() > 0)
1035 | throw new IOException("Error making API call: " + statusInfoStr + '.');
1036 |
1037 | throw new IOException("Error making API call: " + statusStr + '.');
1038 | }
1039 | }
1040 | else if(AlchemyAPI_Params.OUTPUT_RDF.equals(outputMode)) {
1041 | String statusStr = getNodeValue(factory, doc, "//RDF/Description/ResultStatus/text()");
1042 | if (null == statusStr || !statusStr.equals("OK")) {
1043 | String statusInfoStr = getNodeValue(factory, doc, "//RDF/Description/ResultStatus/text()");
1044 | if (null != statusInfoStr && statusInfoStr.length() > 0)
1045 | throw new IOException("Error making API call: " + statusInfoStr + '.');
1046 |
1047 | throw new IOException("Error making API call: " + statusStr + '.');
1048 | }
1049 | }
1050 |
1051 | return doc;
1052 | }
1053 |
1054 | private String getNodeValue(XPathFactory factory, Document doc, String xpathStr)
1055 | throws XPathExpressionException
1056 | {
1057 | XPath xpath = factory.newXPath();
1058 | XPathExpression expr = xpath.compile(xpathStr);
1059 | Object result = expr.evaluate(doc, XPathConstants.NODESET);
1060 | NodeList results = (NodeList) result;
1061 |
1062 | if (results.getLength() > 0 && null != results.item(0))
1063 | return results.item(0).getNodeValue();
1064 |
1065 | return null;
1066 | }
1067 | }
1068 |
--------------------------------------------------------------------------------
/src/com/alchemyapi/api/AlchemyAPI_CategoryParams.java:
--------------------------------------------------------------------------------
1 | package com.alchemyapi.api;
2 |
3 | import java.io.UnsupportedEncodingException;
4 | import java.net.URLEncoder;
5 |
6 | public class AlchemyAPI_CategoryParams extends AlchemyAPI_Params {
7 | public static final String CLEANED_OR_RAW = "cleaned_or_raw";
8 | public static final String CQUERY = "cquery";
9 | public static final String XPATH = "xpath";
10 |
11 | private String sourceText;
12 | private String cQuery;
13 | private String xPath;
14 | private String baseUrl;
15 |
16 | public String getSourceText() {
17 | return sourceText;
18 | }
19 | public void setSourceText(String sourceText) {
20 | if( !sourceText.equals(AlchemyAPI_CategoryParams.CLEANED_OR_RAW)
21 | && !sourceText.equals(AlchemyAPI_CategoryParams.CQUERY)
22 | && !sourceText.equals(AlchemyAPI_CategoryParams.XPATH))
23 | {
24 | throw new RuntimeException("Invalid setting " + sourceText + " for parameter sourceText");
25 | }
26 | this.sourceText = sourceText;
27 | }
28 | public String getCQuery() {
29 | return cQuery;
30 | }
31 | public void setCQuery(String cQuery) {
32 | this.cQuery = cQuery;
33 | }
34 | public String getXPath() {
35 | return xPath;
36 | }
37 | public void setXPath(String xPath) {
38 | this.xPath = xPath;
39 | }
40 | public String getBaseUrl() {
41 | return baseUrl;
42 | }
43 | public void setBaseUrl(String baseUrl) {
44 | this.baseUrl = baseUrl;
45 | }
46 |
47 | public String getParameterString(){
48 | String retString = super.getParameterString();
49 | try{
50 | if(sourceText!=null) retString+="&sourceText="+sourceText;
51 | if(cQuery!=null) retString+="&cquery="+URLEncoder.encode(cQuery,"UTF-8");
52 | if(xPath!=null) retString+="&xpath="+URLEncoder.encode(xPath,"UTF-8");
53 | if(baseUrl!=null) retString+="&baseUrl="+URLEncoder.encode(baseUrl,"UTF-8");
54 | }
55 | catch(UnsupportedEncodingException e ){
56 | retString = "";
57 | }
58 | return retString;
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/src/com/alchemyapi/api/AlchemyAPI_CombinedParams.java:
--------------------------------------------------------------------------------
1 | package com.alchemyapi.api;
2 | import java.net.URLEncoder;
3 | import java.io.UnsupportedEncodingException;
4 |
5 |
6 |
7 | public class AlchemyAPI_CombinedParams extends AlchemyAPI_Params{
8 | public static final String CLEANED_OR_RAW = "cleaned_or_raw";
9 | public static final String CLEANED = "cleaned";
10 | public static final String RAW = "raw";
11 | public static final String CQUERY = "cquery";
12 | public static final String XPATH = "xpath";
13 | public static final String EXTRACT_MODE_TRUST = "trust-metadata";
14 | public static final String EXTRACT_MODE_INFER = "always-infer";
15 | public static final String EXTRACT_PAGE_IMAGE = "page-image";
16 | public static final String EXTRACT_ENTITY = "entity";
17 | public static final String EXTRACT_KEYWORD = "keyword";
18 | public static final String EXTRACT_TITLE = "title";
19 | public static final String EXTRACT_AUTHOR = "author";
20 | public static final String EXTRACT_TAXONOMY = "taxonomy";
21 | public static final String EXTRACT_CONCEPT = "concept";
22 | public static final String EXTRACT_RELATION = "relation";
23 | public static final String EXTRACT_DOC_SENTIMENT = "doc-sentiment";
24 |
25 | private Boolean disambiguate;
26 | private Boolean linkedData;
27 | private Boolean coreference;
28 | private Boolean quotations;
29 | private String sourceText;
30 | private Boolean showSourceText;
31 | private String cQuery;
32 | private String xPath;
33 | private Integer maxRetrieve;
34 | private String baseUrl;
35 | private Boolean sentiment = false;
36 | private String extractMode;
37 | private String extract;
38 |
39 | public boolean isDisambiguate() {
40 | return disambiguate;
41 | }
42 | public void setDisambiguate(boolean disambiguate) {
43 | this.disambiguate = disambiguate;
44 | }
45 | public boolean isLinkedData() {
46 | return linkedData;
47 | }
48 | public void setLinkedData(boolean linkedData) {
49 | this.linkedData = linkedData;
50 | }
51 | public boolean isCoreference() {
52 | return coreference;
53 | }
54 | public void setCoreference(boolean coreference) {
55 | this.coreference = coreference;
56 | }
57 | public boolean isQuotations() {
58 | return quotations;
59 | }
60 | public void setQuotations(boolean quotations) {
61 | this.quotations = quotations;
62 | }
63 | public String getSourceText() {
64 | return sourceText;
65 | }
66 | public void setSourceText(String sourceText) {
67 | if( !sourceText.equals(AlchemyAPI_CombinedParams.CLEANED) && !sourceText.equals(AlchemyAPI_CombinedParams.CLEANED_OR_RAW)
68 | && !sourceText.equals(AlchemyAPI_CombinedParams.RAW) && !sourceText.equals(AlchemyAPI_CombinedParams.CQUERY)
69 | && !sourceText.equals(AlchemyAPI_CombinedParams.XPATH))
70 | {
71 | throw new RuntimeException("Invalid setting " + sourceText + " for parameter sourceText");
72 | }
73 | this.sourceText = sourceText;
74 | }
75 | public boolean isShowSourceText() {
76 | return showSourceText;
77 | }
78 | public void setShowSourceText(boolean showSourceText) {
79 | this.showSourceText = showSourceText;
80 | }
81 | public String getCQuery() {
82 | return cQuery;
83 | }
84 | public void setCQuery(String cQuery) {
85 | this.cQuery = cQuery;
86 | }
87 | public String getXPath() {
88 | return xPath;
89 | }
90 | public void setXPath(String xPath) {
91 | this.xPath = xPath;
92 | }
93 | public int getMaxRetrieve() {
94 | return maxRetrieve;
95 | }
96 | public void setMaxRetrieve(int maxRetrieve) {
97 | this.maxRetrieve = maxRetrieve;
98 | }
99 | public String getBaseUrl() {
100 | return baseUrl;
101 | }
102 | public void setBaseUrl(String baseUrl) {
103 | this.baseUrl = baseUrl;
104 | }
105 | public boolean isSentiment() {
106 | return sentiment;
107 | }
108 | public void setSentiment(boolean sentiment) {
109 | this.sentiment = sentiment;
110 | }
111 | public void setExtractMode(String extractMode) {
112 | if( !extractMode.equals(EXTRACT_MODE_TRUST) && !extractMode.equals(EXTRACT_MODE_INFER) )
113 | {
114 | throw new RuntimeException("Invalid setting " + extractMode + " for parameter extractMode");
115 | }
116 | this.extractMode = extractMode;
117 | }
118 | public void setExtractAll() {
119 | this.extract = EXTRACT_PAGE_IMAGE + EXTRACT_ENTITY + EXTRACT_KEYWORD
120 | + EXTRACT_TITLE + EXTRACT_AUTHOR + EXTRACT_TAXONOMY
121 | + EXTRACT_CONCEPT + EXTRACT_RELATION + EXTRACT_DOC_SENTIMENT;
122 | }
123 | public void setExtract(String extractArg) {
124 | if( !extractArg.equals(EXTRACT_PAGE_IMAGE)
125 | && !extractArg.equals(EXTRACT_ENTITY)
126 | && !extractArg.equals(EXTRACT_KEYWORD)
127 | && !extractArg.equals(EXTRACT_TITLE)
128 | && !extractArg.equals(EXTRACT_AUTHOR)
129 | && !extractArg.equals(EXTRACT_TAXONOMY)
130 | && !extractArg.equals(EXTRACT_CONCEPT)
131 | && !extractArg.equals(EXTRACT_RELATION)
132 | && !extractArg.equals(EXTRACT_DOC_SENTIMENT) )
133 | {
134 | throw new RuntimeException("Invalid setting " + extractArg + " for parameter extract");
135 | }
136 | if ((null == this.extract) || (0 == this.extract.length()))
137 | this.extract = extractArg;
138 | else
139 | this.extract += "," + extractArg;
140 | }
141 | public String getParameterString(){
142 | String retString = super.getParameterString();
143 | try{
144 | if (extractMode!=null) retString+="&extractMode="+extractMode;
145 | if (extract!=null) retString+="&extract="+extract;
146 | if(sentiment!=null) retString+="&sentiment="+(sentiment?"1":"0");
147 | if(showSourceText!=null) retString+="&showSourceText="+(showSourceText?"1":"0");
148 | if(maxRetrieve!=null) retString+="&maxRetrieve="+maxRetrieve.toString();
149 | if(baseUrl!=null) retString+="&baseUrl="+URLEncoder.encode(baseUrl,"UTF-8");
150 | if(disambiguate!=null) retString+="&disambiguate="+(disambiguate ? "1":"0");
151 | if(linkedData!=null) retString+="&linkedData="+(linkedData?"1":"0");
152 | if(coreference!=null) retString+="&coreference="+(coreference?"1":"0");
153 | if(quotations!=null) retString+=""ations="+(quotations?"1":"0");
154 | if(sourceText!=null) retString+="&sourceText="+sourceText;
155 | if(cQuery!=null) retString+="&cquery="+URLEncoder.encode(cQuery,"UTF-8");
156 | if(xPath!=null) retString+="&xpath="+URLEncoder.encode(xPath,"UTF-8");
157 | }
158 | catch(UnsupportedEncodingException e ){
159 | retString = "";
160 | }
161 | return retString;
162 | }
163 | }
164 |
165 |
166 |
167 |
--------------------------------------------------------------------------------
/src/com/alchemyapi/api/AlchemyAPI_ConceptParams.java:
--------------------------------------------------------------------------------
1 | package com.alchemyapi.api;
2 | import java.net.URLEncoder;
3 | import java.io.UnsupportedEncodingException;
4 |
5 |
6 |
7 | public class AlchemyAPI_ConceptParams extends AlchemyAPI_Params{
8 | public static final String CLEANED_OR_RAW = "cleaned_or_raw";
9 | public static final String CLEANED = "cleaned";
10 | public static final String RAW = "raw";
11 | public static final String CQUERY = "cquery";
12 | public static final String XPATH = "xpath";
13 |
14 | private Integer maxRetrieve;
15 | private String sourceText;
16 | private Boolean showSourceText;
17 | private String cQuery;
18 | private String xPath;
19 | private Boolean linkedData;
20 |
21 | public String getSourceText() {
22 | return sourceText;
23 | }
24 |
25 | public void setSourceText(String sourceText) {
26 | if( !sourceText.equals(AlchemyAPI_ConceptParams.CLEANED) && !sourceText.equals(AlchemyAPI_ConceptParams.CLEANED_OR_RAW)
27 | && !sourceText.equals(AlchemyAPI_ConceptParams.RAW) && !sourceText.equals(AlchemyAPI_ConceptParams.CQUERY)
28 | && !sourceText.equals(AlchemyAPI_ConceptParams.XPATH))
29 | {
30 | throw new RuntimeException("Invalid setting " + sourceText + " for parameter sourceText");
31 | }
32 | this.sourceText = sourceText;
33 | }
34 |
35 | public boolean isShowSourceText() {
36 | return showSourceText;
37 | }
38 |
39 | public void setShowSourceText(boolean showSourceText) {
40 | this.showSourceText = showSourceText;
41 | }
42 |
43 | public String getCQuery() {
44 | return cQuery;
45 | }
46 |
47 | public void setCQuery(String cQuery) {
48 | this.cQuery = cQuery;
49 | }
50 |
51 | public String getXPath() {
52 | return xPath;
53 | }
54 |
55 | public void setXPath(String xPath) {
56 | this.xPath = xPath;
57 | }
58 |
59 | public int getMaxRetrieve() {
60 | return maxRetrieve;
61 | }
62 |
63 | public void setMaxRetrieve(int maxRetrieve) {
64 | this.maxRetrieve = maxRetrieve;
65 | }
66 |
67 | public boolean isLinkedData() {
68 | return linkedData;
69 | }
70 |
71 | public void setLinkedData(boolean linkedData) {
72 | this.linkedData = linkedData;
73 | }
74 |
75 | public String getParameterString(){
76 | String retString = super.getParameterString();
77 | try{
78 | if(sourceText!=null) retString+="&sourceText="+sourceText;
79 | if(showSourceText!=null) retString+="&showSourceText="+(showSourceText?"1":"0");
80 | if(cQuery!=null) retString+="&cquery="+URLEncoder.encode(cQuery,"UTF-8");
81 | if(xPath!=null) retString+="&xpath="+URLEncoder.encode(xPath,"UTF-8");
82 | if(maxRetrieve!=null) retString+="&maxRetrieve="+maxRetrieve.toString();
83 | if(linkedData!=null) retString+="&linkedData="+(linkedData?"1":"0");
84 | }
85 | catch(UnsupportedEncodingException e ){
86 | retString = "";
87 | }
88 | return retString;
89 | }
90 |
91 |
92 |
93 | }
94 |
95 |
96 |
97 |
--------------------------------------------------------------------------------
/src/com/alchemyapi/api/AlchemyAPI_ConstraintQueryParams.java:
--------------------------------------------------------------------------------
1 | package com.alchemyapi.api;
2 | import java.net.URLEncoder;
3 | import java.io.UnsupportedEncodingException;
4 |
5 |
6 |
7 | public class AlchemyAPI_ConstraintQueryParams extends AlchemyAPI_Params{
8 |
9 | private String cQuery;
10 |
11 | public String getCQuery() {
12 | return cQuery;
13 | }
14 | public void setCQuery(String cQuery) {
15 | this.cQuery = cQuery;
16 | }
17 |
18 |
19 | public String getParameterString(){
20 | String retString = super.getParameterString();
21 | try{
22 | if(cQuery!=null) retString+="&cquery="+URLEncoder.encode(cQuery,"UTF-8");
23 | }
24 | catch(UnsupportedEncodingException e ){
25 | retString = "";
26 | }
27 | return retString;
28 | }
29 |
30 |
31 |
32 | }
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/src/com/alchemyapi/api/AlchemyAPI_ImageParams.java:
--------------------------------------------------------------------------------
1 | package com.alchemyapi.api;
2 | import java.net.URLEncoder;
3 | import java.io.UnsupportedEncodingException;
4 |
5 |
6 |
7 | public class AlchemyAPI_ImageParams extends AlchemyAPI_Params{
8 | public static final String CQUERY = "cquery";
9 | public static final String XPATH = "xpath";
10 | public static final String RAW = "raw";
11 | public static final String NOT_RAW = "not-raw";
12 | private String cQuery;
13 | private String xPath;
14 | private Integer maxRetrieve;
15 | private byte[] image;
16 | private String imagePostMode;
17 | private String baseUrl;
18 |
19 | public String getCQuery() {
20 | return cQuery;
21 | }
22 | public void setCQuery(String cQuery) {
23 | this.cQuery = cQuery;
24 | }
25 | public String getXPath() {
26 | return xPath;
27 | }
28 | public void setXPath(String xPath) {
29 | this.xPath = xPath;
30 | }
31 | public int getMaxRetrieve() {
32 | return maxRetrieve;
33 | }
34 | public void setMaxRetrieve(int maxRetrieve) {
35 | this.maxRetrieve = maxRetrieve;
36 | }
37 | public byte[] getImage() {
38 | return image;
39 | }
40 | public void setImage(byte[] image) {
41 | this.image = image;
42 | }
43 | public String getImagePostMode() {
44 | return imagePostMode;
45 | }
46 | public void setImagePostMode(String imagePostMode) {
47 | this.imagePostMode = imagePostMode;
48 | }
49 | public String getBaseUrl() {
50 | return baseUrl;
51 | }
52 | public void setBaseUrl(String baseUrl) {
53 | this.baseUrl = baseUrl;
54 | }
55 |
56 | public String getParameterString(){
57 | String retString = super.getParameterString();
58 | try{
59 | if(cQuery!=null) retString+="&cquery="+URLEncoder.encode(cQuery,"UTF-8");
60 | if(xPath!=null) retString+="&xpath="+URLEncoder.encode(xPath,"UTF-8");
61 | if(maxRetrieve!=null) retString+="&maxRetrieve="+maxRetrieve.toString();
62 | if(imagePostMode!=null) retString+="&imagePostMode="+URLEncoder.encode(imagePostMode,"UTF-8");
63 | if(baseUrl!=null) retString+="&baseUrl="+URLEncoder.encode(baseUrl,"UTF-8");
64 | }
65 | catch(UnsupportedEncodingException e ){
66 | retString = "";
67 | }
68 | return retString;
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/com/alchemyapi/api/AlchemyAPI_KeywordParams.java:
--------------------------------------------------------------------------------
1 | package com.alchemyapi.api;
2 | import java.net.URLEncoder;
3 | import java.io.UnsupportedEncodingException;
4 |
5 |
6 |
7 | public class AlchemyAPI_KeywordParams extends AlchemyAPI_Params{
8 | public static final String CLEANED_OR_RAW = "cleaned_or_raw";
9 | public static final String CLEANED = "cleaned";
10 | public static final String RAW = "raw";
11 | public static final String CQUERY = "cquery";
12 | public static final String XPATH = "xpath";
13 |
14 | public static final String EXTRACT_MODE_STRICT = "strict";
15 |
16 | private Integer maxRetrieve;
17 | private String sourceText;
18 | private Boolean showSourceText;
19 | private Boolean sentiment;
20 | private String cQuery;
21 | private String xPath;
22 | private String baseUrl;
23 | private String keywordExtractMode;
24 |
25 | public String getKeywordExtractMode() {
26 | return keywordExtractMode;
27 | }
28 |
29 | public void setKeywordExtractMode(String keywordExtractMode) {
30 | if( !keywordExtractMode.equals(AlchemyAPI_KeywordParams.EXTRACT_MODE_STRICT))
31 | {
32 | throw new RuntimeException("Invalid setting " + keywordExtractMode + " for parameter keywordExtractMode");
33 | }
34 | this.keywordExtractMode = keywordExtractMode;
35 | }
36 |
37 | public String getSourceText() {
38 | return sourceText;
39 | }
40 |
41 | public void setSourceText(String sourceText) {
42 | if( !sourceText.equals(AlchemyAPI_KeywordParams.CLEANED) && !sourceText.equals(AlchemyAPI_KeywordParams.CLEANED_OR_RAW)
43 | && !sourceText.equals(AlchemyAPI_KeywordParams.RAW) && !sourceText.equals(AlchemyAPI_KeywordParams.CQUERY)
44 | && !sourceText.equals(AlchemyAPI_KeywordParams.XPATH))
45 | {
46 | throw new RuntimeException("Invalid setting " + sourceText + " for parameter sourceText");
47 | }
48 | this.sourceText = sourceText;
49 | }
50 |
51 | public boolean isShowSourceText() {
52 | return showSourceText;
53 | }
54 |
55 | public void setShowSourceText(boolean showSourceText) {
56 | this.showSourceText = showSourceText;
57 | }
58 |
59 | public boolean isSentiment() {
60 | return sentiment;
61 | }
62 |
63 | public void setSentiment(boolean sentiment) {
64 | this.sentiment = sentiment;
65 | }
66 |
67 | public String getCQuery() {
68 | return cQuery;
69 | }
70 |
71 | public void setCQuery(String cQuery) {
72 | this.cQuery = cQuery;
73 | }
74 |
75 | public String getXPath() {
76 | return xPath;
77 | }
78 |
79 | public void setXPath(String xPath) {
80 | this.xPath = xPath;
81 | }
82 |
83 | public int getMaxRetrieve() {
84 | return maxRetrieve;
85 | }
86 |
87 | public void setMaxRetrieve(int maxRetrieve) {
88 | this.maxRetrieve = maxRetrieve;
89 | }
90 |
91 | public String getBaseUrl() {
92 | return baseUrl;
93 | }
94 |
95 | public void setBaseUrl(String baseUrl) {
96 | this.baseUrl = baseUrl;
97 | }
98 |
99 | public String getParameterString(){
100 | String retString = super.getParameterString();
101 | try{
102 | if(sourceText!=null) retString+="&sourceText="+sourceText;
103 | if(showSourceText!=null) retString+="&showSourceText="+(showSourceText?"1":"0");
104 | if(sentiment!=null) retString+="&sentiment="+(sentiment?"1":"0");
105 | if(cQuery!=null) retString+="&cquery="+URLEncoder.encode(cQuery,"UTF-8");
106 | if(xPath!=null) retString+="&xpath="+URLEncoder.encode(xPath,"UTF-8");
107 | if(maxRetrieve!=null) retString+="&maxRetrieve="+maxRetrieve.toString();
108 | if(baseUrl!=null) retString+="&baseUrl="+URLEncoder.encode(baseUrl,"UTF-8");
109 | if(keywordExtractMode!=null) retString+="&keywordExtractMode="+URLEncoder.encode(keywordExtractMode,"UTF-8");
110 | }
111 | catch(UnsupportedEncodingException e ){
112 | retString = "";
113 | }
114 | return retString;
115 | }
116 |
117 |
118 |
119 | }
120 |
121 |
122 |
123 |
--------------------------------------------------------------------------------
/src/com/alchemyapi/api/AlchemyAPI_LanguageParams.java:
--------------------------------------------------------------------------------
1 | package com.alchemyapi.api;
2 |
3 | import java.io.UnsupportedEncodingException;
4 | import java.net.URLEncoder;
5 |
6 | public class AlchemyAPI_LanguageParams extends AlchemyAPI_Params {
7 | public static final String CLEANED_OR_RAW = "cleaned_or_raw";
8 | public static final String CLEANED = "cleaned";
9 | public static final String RAW = "raw";
10 | public static final String CQUERY = "cquery";
11 | public static final String XPATH = "xpath";
12 |
13 | private String sourceText;
14 | private String cQuery;
15 | private String xPath;
16 |
17 | public String getSourceText() {
18 | return sourceText;
19 | }
20 |
21 | public void setSourceText(String sourceText) {
22 | if( !sourceText.equals(AlchemyAPI_LanguageParams.CLEANED_OR_RAW)
23 | && !sourceText.equals(AlchemyAPI_LanguageParams.CQUERY)
24 | && !sourceText.equals(AlchemyAPI_LanguageParams.XPATH))
25 | {
26 | throw new RuntimeException("Invalid setting " + sourceText + " for parameter sourceText");
27 | }
28 | this.sourceText = sourceText;
29 | }
30 |
31 | public String getCQuery() {
32 | return cQuery;
33 | }
34 |
35 | public void setCQuery(String cQuery) {
36 | this.cQuery = cQuery;
37 | }
38 |
39 | public String getXPath() {
40 | return xPath;
41 | }
42 |
43 | public void setXPath(String xPath) {
44 | this.xPath = xPath;
45 | }
46 |
47 | public String getParameterString(){
48 | String retString = super.getParameterString();
49 | try{
50 | if(sourceText!=null) retString+="&sourceText="+sourceText;
51 | if(cQuery!=null) retString+="&cquery="+URLEncoder.encode(cQuery,"UTF-8");
52 | if(xPath!=null) retString+="&xpath="+URLEncoder.encode(xPath,"UTF-8");
53 | }
54 | catch(UnsupportedEncodingException e ){
55 | retString = "";
56 | }
57 | return retString;
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/src/com/alchemyapi/api/AlchemyAPI_NamedEntityParams.java:
--------------------------------------------------------------------------------
1 | package com.alchemyapi.api;
2 | import java.net.URLEncoder;
3 | import java.io.UnsupportedEncodingException;
4 |
5 |
6 |
7 | public class AlchemyAPI_NamedEntityParams extends AlchemyAPI_Params{
8 | public static final String CLEANED_OR_RAW = "cleaned_or_raw";
9 | public static final String CLEANED = "cleaned";
10 | public static final String RAW = "raw";
11 | public static final String CQUERY = "cquery";
12 | public static final String XPATH = "xpath";
13 |
14 | private Boolean disambiguate;
15 | private Boolean linkedData;
16 | private Boolean coreference;
17 | private Boolean quotations;
18 | private String sourceText;
19 | private Boolean showSourceText;
20 | private String cQuery;
21 | private String xPath;
22 | private Integer maxRetrieve;
23 | private String baseUrl;
24 | private Boolean sentiment;
25 |
26 | public boolean isDisambiguate() {
27 | return disambiguate;
28 | }
29 | public void setDisambiguate(boolean disambiguate) {
30 | this.disambiguate = disambiguate;
31 | }
32 | public boolean isLinkedData() {
33 | return linkedData;
34 | }
35 | public void setLinkedData(boolean linkedData) {
36 | this.linkedData = linkedData;
37 | }
38 | public boolean isCoreference() {
39 | return coreference;
40 | }
41 | public void setCoreference(boolean coreference) {
42 | this.coreference = coreference;
43 | }
44 | public boolean isQuotations() {
45 | return quotations;
46 | }
47 | public void setQuotations(boolean quotations) {
48 | this.quotations = quotations;
49 | }
50 | public String getSourceText() {
51 | return sourceText;
52 | }
53 | public void setSourceText(String sourceText) {
54 | if( !sourceText.equals(AlchemyAPI_NamedEntityParams.CLEANED) && !sourceText.equals(AlchemyAPI_NamedEntityParams.CLEANED_OR_RAW)
55 | && !sourceText.equals(AlchemyAPI_NamedEntityParams.RAW) && !sourceText.equals(AlchemyAPI_NamedEntityParams.CQUERY)
56 | && !sourceText.equals(AlchemyAPI_NamedEntityParams.XPATH))
57 | {
58 | throw new RuntimeException("Invalid setting " + sourceText + " for parameter sourceText");
59 | }
60 | this.sourceText = sourceText;
61 | }
62 | public boolean isShowSourceText() {
63 | return showSourceText;
64 | }
65 | public void setShowSourceText(boolean showSourceText) {
66 | this.showSourceText = showSourceText;
67 | }
68 | public String getCQuery() {
69 | return cQuery;
70 | }
71 | public void setCQuery(String cQuery) {
72 | this.cQuery = cQuery;
73 | }
74 | public String getXPath() {
75 | return xPath;
76 | }
77 | public void setXPath(String xPath) {
78 | this.xPath = xPath;
79 | }
80 | public int getMaxRetrieve() {
81 | return maxRetrieve;
82 | }
83 | public void setMaxRetrieve(int maxRetrieve) {
84 | this.maxRetrieve = maxRetrieve;
85 | }
86 | public String getBaseUrl() {
87 | return baseUrl;
88 | }
89 | public void setBaseUrl(String baseUrl) {
90 | this.baseUrl = baseUrl;
91 | }
92 | public boolean isSentiment() {
93 | return sentiment;
94 | }
95 | public void setSentiment(boolean sentiment) {
96 | this.sentiment = sentiment;
97 | }
98 |
99 | public String getParameterString(){
100 | String retString = super.getParameterString();
101 | try{
102 | if(disambiguate!=null) retString+="&disambiguate="+(disambiguate ? "1":"0");
103 | if(linkedData!=null) retString+="&linkedData="+(linkedData?"1":"0");
104 | if(coreference!=null) retString+="&coreference="+(coreference?"1":"0");
105 | if(quotations!=null) retString+=""ations="+(quotations?"1":"0");
106 | if(sourceText!=null) retString+="&sourceText="+sourceText;
107 | if(showSourceText!=null) retString+="&showSourceText="+(showSourceText?"1":"0");
108 | if(cQuery!=null) retString+="&cquery="+URLEncoder.encode(cQuery,"UTF-8");
109 | if(xPath!=null) retString+="&xpath="+URLEncoder.encode(xPath,"UTF-8");
110 | if(maxRetrieve!=null) retString+="&maxRetrieve="+maxRetrieve.toString();
111 | if(baseUrl!=null) retString+="&baseUrl="+URLEncoder.encode(baseUrl,"UTF-8");
112 | if(sentiment!=null) retString+="&sentiment="+(sentiment?"1":"0");
113 | }
114 | catch(UnsupportedEncodingException e ){
115 | retString = "";
116 | }
117 | return retString;
118 | }
119 |
120 |
121 |
122 | }
123 |
124 |
125 |
126 |
--------------------------------------------------------------------------------
/src/com/alchemyapi/api/AlchemyAPI_Params.java:
--------------------------------------------------------------------------------
1 | package com.alchemyapi.api;
2 |
3 | import java.io.UnsupportedEncodingException;
4 | import java.net.URLEncoder;
5 |
6 |
7 |
8 | public class AlchemyAPI_Params {
9 | public static final String OUTPUT_XML = "xml";
10 | public static final String OUTPUT_RDF = "rdf";
11 |
12 | private String url;
13 | private String html;
14 | private String text;
15 | private String outputMode = OUTPUT_XML;
16 | private String customParameters;
17 |
18 | public String getUrl() {
19 | return url;
20 | }
21 | public void setUrl(String url) {
22 | this.url = url;
23 | }
24 | public String getHtml() {
25 | return html;
26 | }
27 | public void setHtml(String html) {
28 | this.html = html;
29 | }
30 | public String getText() {
31 | return text;
32 | }
33 | public void setText(String text) {
34 | this.text = text;
35 | }
36 | public String getOutputMode() {
37 | return outputMode;
38 | }
39 | public void setOutputMode(String outputMode) {
40 | if( !outputMode.equals(AlchemyAPI_Params.OUTPUT_XML) && !outputMode.equals(OUTPUT_RDF) )
41 | {
42 | throw new RuntimeException("Invalid setting " + outputMode + " for parameter outputMode");
43 | }
44 | this.outputMode = outputMode;
45 | }
46 | public String getCustomParameters() {
47 | return customParameters;
48 | }
49 |
50 | public void setCustomParameters(String... customParameters) {
51 | StringBuilder data = new StringBuilder();
52 | try{
53 | for (int i = 0; i < customParameters.length; ++i) {
54 | data.append('&').append(customParameters[i]);
55 | if (++i < customParameters.length)
56 | data.append('=').append(URLEncoder.encode(customParameters[i], "UTF8"));
57 | }
58 | }
59 | catch(UnsupportedEncodingException e){
60 | this.customParameters = "";
61 | return;
62 | }
63 | this.customParameters = data.toString();
64 | }
65 |
66 | public String getParameterString(){
67 | String retString = "";
68 | try{
69 | if(url!=null) retString+="&url="+URLEncoder.encode(url,"UTF-8");
70 | if(html!=null) retString+="&html="+URLEncoder.encode(html,"UTF-8");
71 | if(text!=null) retString+="&text="+URLEncoder.encode(text,"UTF-8");
72 | if(customParameters!=null) retString+=customParameters;
73 | if(outputMode!=null) retString+="&outputMode="+outputMode;
74 | }
75 | catch(UnsupportedEncodingException e ){
76 | retString = "";
77 | }
78 | return retString;
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/src/com/alchemyapi/api/AlchemyAPI_RelationParams.java:
--------------------------------------------------------------------------------
1 | package com.alchemyapi.api;
2 | import java.net.URLEncoder;
3 | import java.io.UnsupportedEncodingException;
4 |
5 |
6 |
7 | public class AlchemyAPI_RelationParams extends AlchemyAPI_Params{
8 | public static final String CLEANED_OR_RAW = "cleaned_or_raw";
9 | public static final String CLEANED = "cleaned";
10 | public static final String RAW = "raw";
11 | public static final String CQUERY = "cquery";
12 | public static final String XPATH = "xpath";
13 |
14 | private Boolean disambiguate;
15 | private Boolean linkedData;
16 | private Boolean coreference;
17 | private String sourceText;
18 | private Boolean showSourceText;
19 | private Boolean entities;
20 | private Boolean sentimentExcludeEntities;
21 | private Boolean requireEntities;
22 | private String cQuery;
23 | private String xPath;
24 | private Integer maxRetrieve;
25 | private String baseUrl;
26 | private Boolean sentiment;
27 |
28 | public boolean isDisambiguate() {
29 | return disambiguate;
30 | }
31 | public void setDisambiguate(boolean disambiguate) {
32 | this.disambiguate = disambiguate;
33 | }
34 | public boolean isLinkedData() {
35 | return linkedData;
36 | }
37 | public void setLinkedData(boolean linkedData) {
38 | this.linkedData = linkedData;
39 | }
40 | public boolean isCoreference() {
41 | return coreference;
42 | }
43 | public void setCoreference(boolean coreference) {
44 | this.coreference = coreference;
45 | }
46 |
47 | public String getSourceText() {
48 | return sourceText;
49 | }
50 | public void setSourceText(String sourceText) {
51 | if( !sourceText.equals(AlchemyAPI_NamedEntityParams.CLEANED) && !sourceText.equals(AlchemyAPI_NamedEntityParams.CLEANED_OR_RAW)
52 | && !sourceText.equals(AlchemyAPI_NamedEntityParams.RAW) && !sourceText.equals(AlchemyAPI_NamedEntityParams.CQUERY)
53 | && !sourceText.equals(AlchemyAPI_NamedEntityParams.XPATH))
54 | {
55 | throw new RuntimeException("Invalid setting " + sourceText + " for parameter sourceText");
56 | }
57 | this.sourceText = sourceText;
58 | }
59 | public boolean isShowSourceText() {
60 | return showSourceText;
61 | }
62 | public void setShowSourceText(boolean showSourceText) {
63 | this.showSourceText = showSourceText;
64 | }
65 | public boolean isEntities() {
66 | return entities;
67 | }
68 | public void setEntities(boolean entities) {
69 | this.entities = entities;
70 | }
71 | public boolean isSentimentExcludeEntities() {
72 | return sentimentExcludeEntities;
73 | }
74 | public void setSentimentExcludeEntities(boolean sentimentExcludeEntities) {
75 | this.sentimentExcludeEntities = sentimentExcludeEntities;
76 | }
77 | public boolean isRequireEntities() {
78 | return requireEntities;
79 | }
80 | public void setRequireEntities(boolean requireEntities) {
81 | this.requireEntities = requireEntities;
82 | }
83 | public String getCQuery() {
84 | return cQuery;
85 | }
86 | public void setCQuery(String cQuery) {
87 | this.cQuery = cQuery;
88 | }
89 | public String getXPath() {
90 | return xPath;
91 | }
92 | public void setXPath(String xPath) {
93 | this.xPath = xPath;
94 | }
95 | public int getMaxRetrieve() {
96 | return maxRetrieve;
97 | }
98 | public void setMaxRetrieve(int maxRetrieve) {
99 | this.maxRetrieve = maxRetrieve;
100 | }
101 | public String getBaseUrl() {
102 | return baseUrl;
103 | }
104 | public void setBaseUrl(String baseUrl) {
105 | this.baseUrl = baseUrl;
106 | }
107 | public boolean isSentiment() {
108 | return sentiment;
109 | }
110 | public void setSentiment(boolean sentiment) {
111 | this.sentiment = sentiment;
112 | }
113 |
114 | public String getParameterString(){
115 | String retString = super.getParameterString();
116 | try{
117 | if(disambiguate!=null) retString+="&disambiguate="+(disambiguate ? "1":"0");
118 | if(linkedData!=null) retString+="&linkedData="+(linkedData?"1":"0");
119 | if(coreference!=null) retString+="&coreference="+(coreference?"1":"0");
120 | if(sourceText!=null) retString+="&sourceText="+sourceText;
121 | if(showSourceText!=null) retString+="&showSourceText="+(showSourceText?"1":"0");
122 | if(entities!=null) retString+="&entities="+(entities?"1":"0");
123 | if(sentimentExcludeEntities!=null) retString+="&sentimentExcludeEntities="+(sentimentExcludeEntities?"1":"0");
124 | if(requireEntities!=null) retString+="&requireEntities="+(requireEntities?"1":"0");
125 | if(cQuery!=null) retString+="&cquery="+URLEncoder.encode(cQuery,"UTF-8");
126 | if(xPath!=null) retString+="&xpath="+URLEncoder.encode(xPath,"UTF-8");
127 | if(maxRetrieve!=null) retString+="&maxRetrieve="+maxRetrieve.toString();
128 | if(baseUrl!=null) retString+="&baseUrl="+URLEncoder.encode(baseUrl,"UTF-8");
129 | if(sentiment!=null) retString+="&sentiment="+(sentiment?"1":"0");
130 | }
131 | catch(UnsupportedEncodingException e ){
132 | retString = "";
133 | }
134 | return retString;
135 | }
136 |
137 | }
138 |
139 |
140 |
141 |
--------------------------------------------------------------------------------
/src/com/alchemyapi/api/AlchemyAPI_TargetedSentimentParams.java:
--------------------------------------------------------------------------------
1 | package com.alchemyapi.api;
2 |
3 | import java.io.UnsupportedEncodingException;
4 | import java.net.URLEncoder;
5 |
6 | public class AlchemyAPI_TargetedSentimentParams extends AlchemyAPI_Params {
7 |
8 | private Boolean showSourceText;
9 | private String target;
10 |
11 | public boolean isShowSourceText() {
12 | return showSourceText;
13 | }
14 |
15 | public void setShowSourceText(boolean showSourceText) {
16 | this.showSourceText = showSourceText;
17 | }
18 |
19 | public String getTarget(){
20 | return target;
21 | }
22 |
23 | public void setTarget(String target) {
24 | this.target = target;
25 | }
26 |
27 | public String getParameterString(){
28 | String retString = super.getParameterString();
29 | try{
30 | if(showSourceText!=null) retString+="&showSourceText="+(showSourceText?"1":"0");
31 | if(target!=null) retString+="&target="+URLEncoder.encode(target, "UTF-8");
32 |
33 | }
34 | catch(UnsupportedEncodingException e ){
35 | retString = "";
36 | }
37 |
38 | return retString;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/com/alchemyapi/api/AlchemyAPI_TaxonomyParams.java:
--------------------------------------------------------------------------------
1 | package com.alchemyapi.api;
2 | import java.net.URLEncoder;
3 | import java.io.UnsupportedEncodingException;
4 |
5 |
6 |
7 | public class AlchemyAPI_TaxonomyParams extends AlchemyAPI_Params{
8 | public static final String CLEANED_OR_RAW = "cleaned_or_raw";
9 | public static final String CLEANED = "cleaned";
10 | public static final String RAW = "raw";
11 | public static final String CQUERY = "cquery";
12 | public static final String XPATH = "xpath";
13 |
14 | private Boolean disambiguate;
15 | private Boolean linkedData;
16 | private Boolean coreference;
17 | private Boolean quotations;
18 | private String sourceText;
19 | private Boolean showSourceText;
20 | private String cQuery;
21 | private String xPath;
22 | private Integer maxRetrieve;
23 | private String baseUrl;
24 | private Boolean sentiment;
25 |
26 | public boolean isDisambiguate() {
27 | return disambiguate;
28 | }
29 | public void setDisambiguate(boolean disambiguate) {
30 | this.disambiguate = disambiguate;
31 | }
32 | public boolean isLinkedData() {
33 | return linkedData;
34 | }
35 | public void setLinkedData(boolean linkedData) {
36 | this.linkedData = linkedData;
37 | }
38 | public boolean isCoreference() {
39 | return coreference;
40 | }
41 | public void setCoreference(boolean coreference) {
42 | this.coreference = coreference;
43 | }
44 | public boolean isQuotations() {
45 | return quotations;
46 | }
47 | public void setQuotations(boolean quotations) {
48 | this.quotations = quotations;
49 | }
50 | public String getSourceText() {
51 | return sourceText;
52 | }
53 | public void setSourceText(String sourceText) {
54 | if( !sourceText.equals(AlchemyAPI_TaxonomyParams.CLEANED) && !sourceText.equals(AlchemyAPI_TaxonomyParams.CLEANED_OR_RAW)
55 | && !sourceText.equals(AlchemyAPI_TaxonomyParams.RAW) && !sourceText.equals(AlchemyAPI_TaxonomyParams.CQUERY)
56 | && !sourceText.equals(AlchemyAPI_TaxonomyParams.XPATH))
57 | {
58 | throw new RuntimeException("Invalid setting " + sourceText + " for parameter sourceText");
59 | }
60 | this.sourceText = sourceText;
61 | }
62 | public boolean isShowSourceText() {
63 | return showSourceText;
64 | }
65 | public void setShowSourceText(boolean showSourceText) {
66 | this.showSourceText = showSourceText;
67 | }
68 | public String getCQuery() {
69 | return cQuery;
70 | }
71 | public void setCQuery(String cQuery) {
72 | this.cQuery = cQuery;
73 | }
74 | public String getXPath() {
75 | return xPath;
76 | }
77 | public void setXPath(String xPath) {
78 | this.xPath = xPath;
79 | }
80 | public int getMaxRetrieve() {
81 | return maxRetrieve;
82 | }
83 | public void setMaxRetrieve(int maxRetrieve) {
84 | this.maxRetrieve = maxRetrieve;
85 | }
86 | public String getBaseUrl() {
87 | return baseUrl;
88 | }
89 | public void setBaseUrl(String baseUrl) {
90 | this.baseUrl = baseUrl;
91 | }
92 | public boolean isSentiment() {
93 | return sentiment;
94 | }
95 | public void setSentiment(boolean sentiment) {
96 | this.sentiment = sentiment;
97 | }
98 |
99 | public String getParameterString(){
100 | String retString = super.getParameterString();
101 | try{
102 | if(disambiguate!=null) retString+="&disambiguate="+(disambiguate ? "1":"0");
103 | if(linkedData!=null) retString+="&linkedData="+(linkedData?"1":"0");
104 | if(coreference!=null) retString+="&coreference="+(coreference?"1":"0");
105 | if(quotations!=null) retString+=""ations="+(quotations?"1":"0");
106 | if(sourceText!=null) retString+="&sourceText="+sourceText;
107 | if(showSourceText!=null) retString+="&showSourceText="+(showSourceText?"1":"0");
108 | if(cQuery!=null) retString+="&cquery="+URLEncoder.encode(cQuery,"UTF-8");
109 | if(xPath!=null) retString+="&xpath="+URLEncoder.encode(xPath,"UTF-8");
110 | if(maxRetrieve!=null) retString+="&maxRetrieve="+maxRetrieve.toString();
111 | if(baseUrl!=null) retString+="&baseUrl="+URLEncoder.encode(baseUrl,"UTF-8");
112 | if(sentiment!=null) retString+="&sentiment="+(sentiment?"1":"0");
113 | }
114 | catch(UnsupportedEncodingException e ){
115 | retString = "";
116 | }
117 | return retString;
118 | }
119 | }
120 |
--------------------------------------------------------------------------------
/src/com/alchemyapi/api/AlchemyAPI_TextParams.java:
--------------------------------------------------------------------------------
1 | package com.alchemyapi.api;
2 |
3 |
4 | public class AlchemyAPI_TextParams extends AlchemyAPI_Params{
5 | private Boolean useMetaData;
6 | private Boolean extractLinks;
7 |
8 | public boolean isUseMetaData() {
9 | return useMetaData;
10 | }
11 |
12 | public void setUseMetaData(boolean useMetaData) {
13 | this.useMetaData = useMetaData;
14 | }
15 |
16 | public boolean isExtractLinks() {
17 | return extractLinks;
18 | }
19 |
20 | public void setExtractLinks(boolean extractLinks) {
21 | this.extractLinks = extractLinks;
22 | }
23 |
24 | public String getParameterString(){
25 | String retString = super.getParameterString();
26 |
27 | if(useMetaData!=null) retString+="&useMetaData="+(useMetaData?"1":"0");
28 | if(extractLinks!=null) retString+="&extractLinks="+(extractLinks?"1":"0");
29 |
30 | return retString;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/com/alchemyapi/test/AuthorTest.java:
--------------------------------------------------------------------------------
1 | package com.alchemyapi.test;
2 |
3 | import com.alchemyapi.api.*;
4 |
5 | import org.xml.sax.SAXException;
6 | import org.w3c.dom.Document;
7 | import java.io.*;
8 |
9 | import javax.xml.parsers.ParserConfigurationException;
10 | import javax.xml.xpath.XPathExpressionException;
11 | import javax.xml.transform.Transformer;
12 | import javax.xml.transform.TransformerException;
13 | import javax.xml.transform.TransformerFactory;
14 | import javax.xml.transform.dom.DOMSource;
15 | import javax.xml.transform.stream.StreamResult;
16 |
17 | public class AuthorTest {
18 |
19 |
20 | public static void main(String[] args)
21 | throws IOException, SAXException,
22 | ParserConfigurationException, XPathExpressionException
23 | {
24 | // Create an AlchemyAPI object.
25 | AlchemyAPI alchemyObj = AlchemyAPI.GetInstanceFromFile("api_key.txt");
26 |
27 | // Load a HTML document to analyze.
28 | String htmlDoc = getFileContents("data/example.html");
29 |
30 | Document doc = alchemyObj.URLGetAuthor("http://www.politico.com/blogs/media/2012/02/detroit-news-ed-upset-over-romney-edit-115247.html");
31 | System.out.println(getStringFromDocument(doc));
32 |
33 | doc = alchemyObj.HTMLGetAuthor(htmlDoc, "http://www.test.com/");
34 | System.out.println(getStringFromDocument(doc));
35 | }
36 |
37 | // utility function
38 | private static String getFileContents(String filename)
39 | throws IOException, FileNotFoundException
40 | {
41 | File file = new File(filename);
42 | StringBuilder contents = new StringBuilder();
43 |
44 | BufferedReader input = new BufferedReader(new FileReader(file));
45 |
46 | try {
47 | String line = null;
48 |
49 | while ((line = input.readLine()) != null) {
50 | contents.append(line);
51 | contents.append(System.getProperty("line.separator"));
52 | }
53 | } finally {
54 | input.close();
55 | }
56 |
57 | return contents.toString();
58 | }
59 |
60 | // utility method
61 | private static String getStringFromDocument(Document doc) {
62 | try {
63 | DOMSource domSource = new DOMSource(doc);
64 | StringWriter writer = new StringWriter();
65 | StreamResult result = new StreamResult(writer);
66 |
67 | TransformerFactory tf = TransformerFactory.newInstance();
68 | Transformer transformer = tf.newTransformer();
69 | transformer.transform(domSource, result);
70 |
71 | return writer.toString();
72 | } catch (TransformerException ex) {
73 | ex.printStackTrace();
74 | return null;
75 | }
76 | }
77 |
78 |
79 |
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/src/com/alchemyapi/test/CategoryTest.java:
--------------------------------------------------------------------------------
1 | package com.alchemyapi.test;
2 |
3 | import com.alchemyapi.api.*;
4 |
5 | import org.xml.sax.SAXException;
6 | import org.w3c.dom.Document;
7 | import java.io.*;
8 | import javax.xml.parsers.ParserConfigurationException;
9 | import javax.xml.xpath.XPathExpressionException;
10 | import javax.xml.transform.Transformer;
11 | import javax.xml.transform.TransformerException;
12 | import javax.xml.transform.TransformerFactory;
13 | import javax.xml.transform.dom.DOMSource;
14 | import javax.xml.transform.stream.StreamResult;
15 |
16 | class CategoryTest {
17 | public static void main(String[] args)
18 | throws IOException, SAXException,
19 | ParserConfigurationException, XPathExpressionException
20 | {
21 | // Create an AlchemyAPI object.
22 | AlchemyAPI alchemyObj = AlchemyAPI.GetInstanceFromFile("api_key.txt");
23 |
24 | // Categorize a web URL by topic.
25 | Document doc = alchemyObj.URLGetCategory("http://www.techcrunch.com/");
26 | System.out.println(getStringFromDocument(doc));
27 |
28 | // Categorize some text.
29 | doc = alchemyObj.TextGetCategory("Latest on the War in Iraq.");
30 | System.out.println(getStringFromDocument(doc));
31 |
32 | // Load a HTML document to analyze.
33 | String htmlDoc = getFileContents("data/example.html");
34 |
35 | // Categorize a HTML document by topic.
36 | doc = alchemyObj.HTMLGetCategory(htmlDoc, "http://www.test.com/");
37 | System.out.println(getStringFromDocument(doc));
38 |
39 | AlchemyAPI_CategoryParams categoryParams = new AlchemyAPI_CategoryParams();
40 | categoryParams.setOutputMode(AlchemyAPI_Params.OUTPUT_RDF);
41 | doc = alchemyObj.HTMLGetCategory(htmlDoc, "http://www.test.com/", categoryParams);
42 | System.out.println(getStringFromDocument(doc));
43 | }
44 |
45 | // utility function
46 | private static String getFileContents(String filename)
47 | throws IOException, FileNotFoundException
48 | {
49 | File file = new File(filename);
50 | StringBuilder contents = new StringBuilder();
51 |
52 | BufferedReader input = new BufferedReader(new FileReader(file));
53 |
54 | try {
55 | String line = null;
56 |
57 | while ((line = input.readLine()) != null) {
58 | contents.append(line);
59 | contents.append(System.getProperty("line.separator"));
60 | }
61 | } finally {
62 | input.close();
63 | }
64 |
65 | return contents.toString();
66 | }
67 |
68 | // utility method
69 | private static String getStringFromDocument(Document doc) {
70 | try {
71 | DOMSource domSource = new DOMSource(doc);
72 | StringWriter writer = new StringWriter();
73 | StreamResult result = new StreamResult(writer);
74 |
75 | TransformerFactory tf = TransformerFactory.newInstance();
76 | Transformer transformer = tf.newTransformer();
77 | transformer.transform(domSource, result);
78 |
79 | return writer.toString();
80 | } catch (TransformerException ex) {
81 | ex.printStackTrace();
82 | return null;
83 | }
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/src/com/alchemyapi/test/CombinedTest.java:
--------------------------------------------------------------------------------
1 | package com.alchemyapi.test;
2 |
3 | import com.alchemyapi.api.*;
4 |
5 | import org.xml.sax.SAXException;
6 | import org.w3c.dom.Document;
7 | import java.io.*;
8 | import javax.xml.parsers.ParserConfigurationException;
9 | import javax.xml.xpath.XPathExpressionException;
10 | import javax.xml.transform.Transformer;
11 | import javax.xml.transform.TransformerException;
12 | import javax.xml.transform.TransformerFactory;
13 | import javax.xml.transform.dom.DOMSource;
14 | import javax.xml.transform.stream.StreamResult;
15 |
16 | class CombinedTest {
17 | public static void main(String[] args)
18 | throws IOException, SAXException,
19 | ParserConfigurationException, XPathExpressionException
20 | {
21 | // Create an AlchemyAPI object.
22 | AlchemyAPI alchemyObj = AlchemyAPI.GetInstanceFromFile("api_key.txt");
23 |
24 | // Extract combined data for a web URL.
25 | Document doc = alchemyObj.URLGetCombined("http://www.techcrunch.com/");
26 | System.out.println(getStringFromDocument(doc));
27 |
28 | // Extract combined data from a text string.
29 | doc = alchemyObj.TextGetCombined(
30 | "Hello there, my name is Bob Jones. I live in the United States of America. " +
31 | "Where do you live, Fred?");
32 | System.out.println(getStringFromDocument(doc));
33 |
34 | // Only extract entities & keywords
35 | AlchemyAPI_CombinedParams combinedParams = new AlchemyAPI_CombinedParams();
36 | combinedParams.setSentiment(true);
37 | combinedParams.setExtract("entity");
38 | combinedParams.setExtract("keyword");
39 | doc = alchemyObj.TextGetCombined("Madonna enjoys tasty Pepsi. I love her style.", combinedParams);
40 | System.out.println(getStringFromDocument(doc));
41 | }
42 |
43 | // utility function
44 | private static String getFileContents(String filename)
45 | throws IOException, FileNotFoundException
46 | {
47 | File file = new File(filename);
48 | StringBuilder contents = new StringBuilder();
49 |
50 | BufferedReader input = new BufferedReader(new FileReader(file));
51 |
52 | try {
53 | String line = null;
54 |
55 | while ((line = input.readLine()) != null) {
56 | contents.append(line);
57 | contents.append(System.getProperty("line.separator"));
58 | }
59 | } finally {
60 | input.close();
61 | }
62 |
63 | return contents.toString();
64 | }
65 |
66 | // utility method
67 | private static String getStringFromDocument(Document doc) {
68 | try {
69 | DOMSource domSource = new DOMSource(doc);
70 | StringWriter writer = new StringWriter();
71 | StreamResult result = new StreamResult(writer);
72 |
73 | TransformerFactory tf = TransformerFactory.newInstance();
74 | Transformer transformer = tf.newTransformer();
75 | transformer.transform(domSource, result);
76 |
77 | return writer.toString();
78 | } catch (TransformerException ex) {
79 | ex.printStackTrace();
80 | return null;
81 | }
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/src/com/alchemyapi/test/ConceptTest.java:
--------------------------------------------------------------------------------
1 | package com.alchemyapi.test;
2 |
3 | import com.alchemyapi.api.AlchemyAPI;
4 |
5 | import org.xml.sax.SAXException;
6 | import org.w3c.dom.Document;
7 | import java.io.*;
8 | import javax.xml.parsers.ParserConfigurationException;
9 | import javax.xml.xpath.XPathExpressionException;
10 | import javax.xml.transform.Transformer;
11 | import javax.xml.transform.TransformerException;
12 | import javax.xml.transform.TransformerFactory;
13 | import javax.xml.transform.dom.DOMSource;
14 | import javax.xml.transform.stream.StreamResult;
15 |
16 | class ConceptTest {
17 | public static void main(String[] args) throws IOException, SAXException,
18 | ParserConfigurationException, XPathExpressionException {
19 | // Create an AlchemyAPI object.
20 | AlchemyAPI alchemyObj = AlchemyAPI.GetInstanceFromFile("api_key.txt");
21 |
22 | // Extract concept tags for a web URL.
23 | Document doc = alchemyObj.URLGetRankedConcepts("http://www.techcrunch.com/");
24 | System.out.println(getStringFromDocument(doc));
25 |
26 | // Extract concept tags for a text string.
27 | doc = alchemyObj.TextGetRankedConcepts(
28 | "This thing has a steering wheel, tires, and an engine. Do you know what it is?");
29 | System.out.println(getStringFromDocument(doc));
30 |
31 | // Load a HTML document to analyze.
32 | String htmlDoc = getFileContents("data/example.html");
33 |
34 | // Extract concept tags for a HTML document.
35 | doc = alchemyObj.HTMLGetRankedConcepts(htmlDoc, "http://www.test.com/");
36 | System.out.println(getStringFromDocument(doc));
37 | }
38 |
39 | // utility function
40 | private static String getFileContents(String filename)
41 | throws IOException, FileNotFoundException
42 | {
43 | File file = new File(filename);
44 | StringBuilder contents = new StringBuilder();
45 |
46 | BufferedReader input = new BufferedReader(new FileReader(file));
47 |
48 | try {
49 | String line = null;
50 |
51 | while ((line = input.readLine()) != null) {
52 | contents.append(line);
53 | contents.append(System.getProperty("line.separator"));
54 | }
55 | } finally {
56 | input.close();
57 | }
58 |
59 | return contents.toString();
60 | }
61 |
62 | // utility method
63 | private static String getStringFromDocument(Document doc) {
64 | try {
65 | DOMSource domSource = new DOMSource(doc);
66 | StringWriter writer = new StringWriter();
67 | StreamResult result = new StreamResult(writer);
68 |
69 | TransformerFactory tf = TransformerFactory.newInstance();
70 | Transformer transformer = tf.newTransformer();
71 | transformer.transform(domSource, result);
72 |
73 | return writer.toString();
74 | } catch (TransformerException ex) {
75 | ex.printStackTrace();
76 | return null;
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/src/com/alchemyapi/test/ConstraintQueryTest.java:
--------------------------------------------------------------------------------
1 | package com.alchemyapi.test;
2 |
3 | import com.alchemyapi.api.AlchemyAPI;
4 |
5 | import org.xml.sax.SAXException;
6 | import org.w3c.dom.Document;
7 | import java.io.*;
8 | import javax.xml.parsers.ParserConfigurationException;
9 | import javax.xml.xpath.XPathExpressionException;
10 | import javax.xml.transform.Transformer;
11 | import javax.xml.transform.TransformerException;
12 | import javax.xml.transform.TransformerFactory;
13 | import javax.xml.transform.dom.DOMSource;
14 | import javax.xml.transform.stream.StreamResult;
15 |
16 | class ConstraintQueryTest {
17 | public static void main(String[] args)
18 | throws IOException, SAXException,
19 | ParserConfigurationException, XPathExpressionException
20 | {
21 | // Create an AlchemyAPI object.
22 | AlchemyAPI alchemyObj = AlchemyAPI.GetInstanceFromFile("api_key.txt");
23 |
24 | // Extract first link from an URL.
25 | Document doc = alchemyObj.URLGetConstraintQuery("http://microformats.org/wiki/hcard",
26 | "1st link");
27 | System.out.println(getStringFromDocument(doc));
28 |
29 | // Extract first link from a HTML.
30 | String htmlDoc = getFileContents("data/example.html");
31 | doc = alchemyObj.HTMLGetConstraintQuery(htmlDoc, "http://www.test.com/", "1st link");
32 | System.out.println(getStringFromDocument(doc));
33 | }
34 |
35 | // utility function
36 | private static String getFileContents(String filename)
37 | throws IOException, FileNotFoundException
38 | {
39 | File file = new File(filename);
40 | StringBuilder contents = new StringBuilder();
41 |
42 | BufferedReader input = new BufferedReader(new FileReader(file));
43 |
44 | try {
45 | String line = null;
46 |
47 | while ((line = input.readLine()) != null) {
48 | contents.append(line);
49 | contents.append(System.getProperty("line.separator"));
50 | }
51 | } finally {
52 | input.close();
53 | }
54 |
55 | return contents.toString();
56 | }
57 |
58 | // utility method
59 | private static String getStringFromDocument(Document doc) {
60 | try {
61 | DOMSource domSource = new DOMSource(doc);
62 | StringWriter writer = new StringWriter();
63 | StreamResult result = new StreamResult(writer);
64 |
65 | TransformerFactory tf = TransformerFactory.newInstance();
66 | Transformer transformer = tf.newTransformer();
67 | transformer.transform(domSource, result);
68 |
69 | return writer.toString();
70 | } catch (TransformerException ex) {
71 | ex.printStackTrace();
72 | return null;
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/src/com/alchemyapi/test/EntityTest.java:
--------------------------------------------------------------------------------
1 | package com.alchemyapi.test;
2 |
3 | import com.alchemyapi.api.AlchemyAPI;
4 |
5 | import org.xml.sax.SAXException;
6 | import org.w3c.dom.Document;
7 | import java.io.*;
8 | import javax.xml.parsers.ParserConfigurationException;
9 | import javax.xml.xpath.XPathExpressionException;
10 | import javax.xml.transform.Transformer;
11 | import javax.xml.transform.TransformerException;
12 | import javax.xml.transform.TransformerFactory;
13 | import javax.xml.transform.dom.DOMSource;
14 | import javax.xml.transform.stream.StreamResult;
15 |
16 | class EntityTest {
17 | public static void main(String[] args)
18 | throws IOException, SAXException,
19 | ParserConfigurationException, XPathExpressionException
20 | {
21 | // Create an AlchemyAPI object.
22 | AlchemyAPI alchemyObj = AlchemyAPI.GetInstanceFromFile("api_key.txt");
23 |
24 | // Extract a ranked list of named entities for a web URL.
25 | Document doc = alchemyObj.URLGetRankedNamedEntities("http://www.techcrunch.com/");
26 | System.out.println(getStringFromDocument(doc));
27 |
28 | // Extract a ranked list of named entities from a text string.
29 | doc = alchemyObj.TextGetRankedNamedEntities(
30 | "Hello there, my name is Bob Jones. I live in the United States of America. " +
31 | "Where do you live, Fred?");
32 | System.out.println(getStringFromDocument(doc));
33 |
34 | // Load a HTML document to analyze.
35 | String htmlDoc = getFileContents("data/example.html");
36 |
37 | // Extract a ranked list of named entities from a HTML document.
38 | doc = alchemyObj.HTMLGetRankedNamedEntities(htmlDoc, "http://www.test.com/");
39 | System.out.println(getStringFromDocument(doc));
40 | }
41 |
42 | // utility function
43 | private static String getFileContents(String filename)
44 | throws IOException, FileNotFoundException
45 | {
46 | File file = new File(filename);
47 | StringBuilder contents = new StringBuilder();
48 |
49 | BufferedReader input = new BufferedReader(new FileReader(file));
50 |
51 | try {
52 | String line = null;
53 |
54 | while ((line = input.readLine()) != null) {
55 | contents.append(line);
56 | contents.append(System.getProperty("line.separator"));
57 | }
58 | } finally {
59 | input.close();
60 | }
61 |
62 | return contents.toString();
63 | }
64 |
65 | // utility method
66 | private static String getStringFromDocument(Document doc) {
67 | try {
68 | DOMSource domSource = new DOMSource(doc);
69 | StringWriter writer = new StringWriter();
70 | StreamResult result = new StreamResult(writer);
71 |
72 | TransformerFactory tf = TransformerFactory.newInstance();
73 | Transformer transformer = tf.newTransformer();
74 | transformer.transform(domSource, result);
75 |
76 | return writer.toString();
77 | } catch (TransformerException ex) {
78 | ex.printStackTrace();
79 | return null;
80 | }
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/com/alchemyapi/test/FeedLinksTest.java:
--------------------------------------------------------------------------------
1 | package com.alchemyapi.test;
2 |
3 | import com.alchemyapi.api.AlchemyAPI;
4 |
5 | import org.xml.sax.SAXException;
6 | import org.w3c.dom.Document;
7 | import java.io.*;
8 | import javax.xml.parsers.ParserConfigurationException;
9 | import javax.xml.xpath.XPathExpressionException;
10 | import javax.xml.transform.Transformer;
11 | import javax.xml.transform.TransformerException;
12 | import javax.xml.transform.TransformerFactory;
13 | import javax.xml.transform.dom.DOMSource;
14 | import javax.xml.transform.stream.StreamResult;
15 |
16 | class FeedLinksTest {
17 | public static void main(String[] args)
18 | throws IOException, SAXException,
19 | ParserConfigurationException, XPathExpressionException
20 | {
21 | // Create an AlchemyAPI object.
22 | AlchemyAPI alchemyObj = AlchemyAPI.GetInstanceFromFile("api_key.txt");
23 |
24 | // Extract RSS / ATOM feed links from a web URL.
25 | Document doc = alchemyObj.URLGetFeedLinks("http://www.techcrunch.com/");
26 | System.out.println(getStringFromDocument(doc));
27 |
28 | // Load a HTML document to analyze.
29 | String htmlDoc = getFileContents("data/example.html");
30 |
31 | // Extract RSS / ATOM feed links from a HTML document.
32 | doc = alchemyObj.HTMLGetFeedLinks(htmlDoc, "http://www.test.com/");
33 | System.out.println(getStringFromDocument(doc));
34 | }
35 |
36 | // utility function
37 | private static String getFileContents(String filename)
38 | throws IOException, FileNotFoundException
39 | {
40 | File file = new File(filename);
41 | StringBuilder contents = new StringBuilder();
42 |
43 | BufferedReader input = new BufferedReader(new FileReader(file));
44 |
45 | try {
46 | String line = null;
47 |
48 | while ((line = input.readLine()) != null) {
49 | contents.append(line);
50 | contents.append(System.getProperty("line.separator"));
51 | }
52 | } finally {
53 | input.close();
54 | }
55 |
56 | return contents.toString();
57 | }
58 |
59 | // utility method
60 | private static String getStringFromDocument(Document doc) {
61 | try {
62 | DOMSource domSource = new DOMSource(doc);
63 | StringWriter writer = new StringWriter();
64 | StreamResult result = new StreamResult(writer);
65 |
66 | TransformerFactory tf = TransformerFactory.newInstance();
67 | Transformer transformer = tf.newTransformer();
68 | transformer.transform(domSource, result);
69 |
70 | return writer.toString();
71 | } catch (TransformerException ex) {
72 | ex.printStackTrace();
73 | return null;
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/src/com/alchemyapi/test/ImageTest.java:
--------------------------------------------------------------------------------
1 | package com.alchemyapi.test;
2 |
3 | import com.alchemyapi.api.*;
4 |
5 | import org.xml.sax.SAXException;
6 | import org.w3c.dom.Document;
7 | import java.io.*;
8 | import javax.xml.parsers.ParserConfigurationException;
9 | import javax.xml.xpath.XPathExpressionException;
10 | import javax.xml.transform.Transformer;
11 | import javax.xml.transform.TransformerException;
12 | import javax.xml.transform.TransformerFactory;
13 | import javax.xml.transform.dom.DOMSource;
14 | import javax.xml.transform.stream.StreamResult;
15 | import java.net.URLEncoder;
16 |
17 | class ImageTest {
18 | public static void main(String[] args)
19 | throws IOException, SAXException,
20 | ParserConfigurationException, XPathExpressionException
21 | {
22 | // Create an AlchemyAPI object.
23 | AlchemyAPI alchemyObj = AlchemyAPI.GetInstanceFromFile("api_key.txt");
24 |
25 | // Extract image for a web URL.
26 | Document doc = alchemyObj.URLGetImage("http://www.techcrunch.com/");
27 | System.out.println(getStringFromDocument(doc));
28 |
29 | doc = alchemyObj.URLGetRankedImageKeywords(
30 | "http://farm4.staticflickr.com/3726/11043305726_fdcb7785ec_m.jpg");
31 | System.out.println(getStringFromDocument(doc));
32 |
33 | byte[] imageByteArray = readFile("data/cat.jpg");
34 |
35 | AlchemyAPI_ImageParams imageParams = new AlchemyAPI_ImageParams();
36 | imageParams.setImage(imageByteArray);
37 | imageParams.setImagePostMode(AlchemyAPI_ImageParams.RAW);
38 | doc = alchemyObj.ImageGetRankedImageKeywords(imageParams);
39 | System.out.println(getStringFromDocument(doc));
40 | }
41 |
42 | // utility function
43 | private static byte[] readFile(String file) throws IOException {
44 | // Open file
45 | RandomAccessFile f = new RandomAccessFile(new File(file), "r");
46 | try {
47 | // Get and check length
48 | long longlength = f.length();
49 | int length = (int) longlength;
50 | if (length != longlength)
51 | throw new IOException("File size >= 2 GB");
52 | // Read file and return data
53 | byte[] data = new byte[length];
54 | f.readFully(data);
55 | return data;
56 | } finally {
57 | f.close();
58 | }
59 | }
60 |
61 | // utility method
62 | private static String getStringFromDocument(Document doc) {
63 | try {
64 | DOMSource domSource = new DOMSource(doc);
65 | StringWriter writer = new StringWriter();
66 | StreamResult result = new StreamResult(writer);
67 |
68 | TransformerFactory tf = TransformerFactory.newInstance();
69 | Transformer transformer = tf.newTransformer();
70 | transformer.transform(domSource, result);
71 |
72 | return writer.toString();
73 | } catch (TransformerException ex) {
74 | ex.printStackTrace();
75 | return null;
76 | }
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/src/com/alchemyapi/test/KeywordTest.java:
--------------------------------------------------------------------------------
1 | package com.alchemyapi.test;
2 |
3 | import com.alchemyapi.api.AlchemyAPI;
4 |
5 | import org.xml.sax.SAXException;
6 | import org.w3c.dom.Document;
7 | import java.io.*;
8 | import javax.xml.parsers.ParserConfigurationException;
9 | import javax.xml.xpath.XPathExpressionException;
10 | import javax.xml.transform.Transformer;
11 | import javax.xml.transform.TransformerException;
12 | import javax.xml.transform.TransformerFactory;
13 | import javax.xml.transform.dom.DOMSource;
14 | import javax.xml.transform.stream.StreamResult;
15 |
16 | class KeywordTest {
17 | public static void main(String[] args) throws IOException, SAXException,
18 | ParserConfigurationException, XPathExpressionException {
19 | // Create an AlchemyAPI object.
20 | AlchemyAPI alchemyObj = AlchemyAPI.GetInstanceFromFile("api_key.txt");
21 |
22 | // Extract topic keywords for a web URL.
23 | Document doc = alchemyObj.URLGetRankedKeywords("http://www.techcrunch.com/");
24 | System.out.println(getStringFromDocument(doc));
25 |
26 | // Extract topic keywords for a text string.
27 | doc = alchemyObj.TextGetRankedKeywords(
28 | "Hello there, my name is Bob Jones. I live in the United States of America. " +
29 | "Where do you live, Fred?");
30 | System.out.println(getStringFromDocument(doc));
31 |
32 | // Load a HTML document to analyze.
33 | String htmlDoc = getFileContents("data/example.html");
34 |
35 | // Extract topic keywords for a HTML document.
36 | doc = alchemyObj.HTMLGetRankedKeywords(htmlDoc, "http://www.test.com/");
37 | System.out.println(getStringFromDocument(doc));
38 | }
39 |
40 | // utility function
41 | private static String getFileContents(String filename)
42 | throws IOException, FileNotFoundException
43 | {
44 | File file = new File(filename);
45 | StringBuilder contents = new StringBuilder();
46 |
47 | BufferedReader input = new BufferedReader(new FileReader(file));
48 |
49 | try {
50 | String line = null;
51 |
52 | while ((line = input.readLine()) != null) {
53 | contents.append(line);
54 | contents.append(System.getProperty("line.separator"));
55 | }
56 | } finally {
57 | input.close();
58 | }
59 |
60 | return contents.toString();
61 | }
62 |
63 | // utility method
64 | private static String getStringFromDocument(Document doc) {
65 | try {
66 | DOMSource domSource = new DOMSource(doc);
67 | StringWriter writer = new StringWriter();
68 | StreamResult result = new StreamResult(writer);
69 |
70 | TransformerFactory tf = TransformerFactory.newInstance();
71 | Transformer transformer = tf.newTransformer();
72 | transformer.transform(domSource, result);
73 |
74 | return writer.toString();
75 | } catch (TransformerException ex) {
76 | ex.printStackTrace();
77 | return null;
78 | }
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/src/com/alchemyapi/test/LanguageTest.java:
--------------------------------------------------------------------------------
1 | package com.alchemyapi.test;
2 |
3 | import com.alchemyapi.api.AlchemyAPI;
4 |
5 | import org.xml.sax.SAXException;
6 | import org.w3c.dom.Document;
7 | import java.io.*;
8 | import javax.xml.parsers.ParserConfigurationException;
9 | import javax.xml.xpath.XPathExpressionException;
10 | import javax.xml.transform.Transformer;
11 | import javax.xml.transform.TransformerException;
12 | import javax.xml.transform.TransformerFactory;
13 | import javax.xml.transform.dom.DOMSource;
14 | import javax.xml.transform.stream.StreamResult;
15 |
16 | class LanguageTest {
17 | public static void main(String[] args)
18 | throws IOException, SAXException,
19 | ParserConfigurationException, XPathExpressionException
20 | {
21 | // Create an AlchemyAPI object.
22 | AlchemyAPI alchemyObj = AlchemyAPI.GetInstanceFromFile("api_key.txt");
23 |
24 | // Detect the language for a web URL.
25 | Document doc = alchemyObj.URLGetLanguage("http://news.google.fr/");
26 | System.out.println(getStringFromDocument(doc));
27 |
28 | // Detect the language for a text string (requires at least 100
29 | // characters).
30 | String htmlDoc = getFileContents("data/example.html");
31 | doc = alchemyObj.TextGetLanguage("This is some english language text. What language do you speak?");
32 | System.out.println(getStringFromDocument(doc));
33 |
34 | // Load a HTML document to analyze.
35 | htmlDoc = getFileContents("data/example.html");
36 |
37 | // Detect the language for a HTML document.
38 | doc = alchemyObj.HTMLGetLanguage(htmlDoc, "http://www.test.com/");
39 | System.out.println(getStringFromDocument(doc));
40 | }
41 |
42 | // utility function
43 | private static String getFileContents(String filename) throws IOException,
44 | FileNotFoundException {
45 | File file = new File(filename);
46 | StringBuilder contents = new StringBuilder();
47 |
48 | BufferedReader input = new BufferedReader(new FileReader(file));
49 |
50 | try {
51 | String line = null;
52 |
53 | while ((line = input.readLine()) != null) {
54 | contents.append(line);
55 | contents.append(System.getProperty("line.separator"));
56 | }
57 | } finally {
58 | input.close();
59 | }
60 |
61 | return contents.toString();
62 | }
63 |
64 | // utility method
65 | private static String getStringFromDocument(Document doc) {
66 | try {
67 | DOMSource domSource = new DOMSource(doc);
68 | StringWriter writer = new StringWriter();
69 | StreamResult result = new StreamResult(writer);
70 |
71 | TransformerFactory tf = TransformerFactory.newInstance();
72 | Transformer transformer = tf.newTransformer();
73 | transformer.transform(domSource, result);
74 |
75 | return writer.toString();
76 | } catch (TransformerException ex) {
77 | ex.printStackTrace();
78 | return null;
79 | }
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/com/alchemyapi/test/MicroformatTest.java:
--------------------------------------------------------------------------------
1 | package com.alchemyapi.test;
2 |
3 | import com.alchemyapi.api.AlchemyAPI;
4 |
5 | import org.xml.sax.SAXException;
6 | import org.w3c.dom.Document;
7 | import java.io.*;
8 | import javax.xml.parsers.ParserConfigurationException;
9 | import javax.xml.xpath.XPathExpressionException;
10 | import javax.xml.transform.Transformer;
11 | import javax.xml.transform.TransformerException;
12 | import javax.xml.transform.TransformerFactory;
13 | import javax.xml.transform.dom.DOMSource;
14 | import javax.xml.transform.stream.StreamResult;
15 |
16 | class MicroformatsTest {
17 | public static void main(String[] args)
18 | throws IOException, SAXException,
19 | ParserConfigurationException, XPathExpressionException
20 | {
21 | // Create an AlchemyAPI object.
22 | AlchemyAPI alchemyObj = AlchemyAPI.GetInstanceFromFile("api_key.txt");
23 |
24 | // Extract microformats data from a web URL.
25 | Document doc = alchemyObj.URLGetMicroformats("http://microformats.org/wiki/hcard");
26 | System.out.println(getStringFromDocument(doc));
27 |
28 | // Load a HTML document to analyze.
29 | String htmlDoc = getFileContents("data/microformats.html");
30 |
31 | // Extract microformats data from a HTML document.
32 | doc = alchemyObj.HTMLGetMicroformats(htmlDoc, "http://www.test.com/");
33 | System.out.println(getStringFromDocument(doc));
34 | }
35 |
36 | // utility function
37 | private static String getFileContents(String filename)
38 | throws IOException, FileNotFoundException
39 | {
40 | File file = new File(filename);
41 | StringBuilder contents = new StringBuilder();
42 |
43 | BufferedReader input = new BufferedReader(new FileReader(file));
44 |
45 | try {
46 | String line = null;
47 |
48 | while ((line = input.readLine()) != null) {
49 | contents.append(line);
50 | contents.append(System.getProperty("line.separator"));
51 | }
52 | } finally {
53 | input.close();
54 | }
55 |
56 | return contents.toString();
57 | }
58 |
59 | // utility method
60 | private static String getStringFromDocument(Document doc) {
61 | try {
62 | DOMSource domSource = new DOMSource(doc);
63 | StringWriter writer = new StringWriter();
64 | StreamResult result = new StreamResult(writer);
65 |
66 | TransformerFactory tf = TransformerFactory.newInstance();
67 | Transformer transformer = tf.newTransformer();
68 | transformer.transform(domSource, result);
69 |
70 | return writer.toString();
71 | } catch (TransformerException ex) {
72 | ex.printStackTrace();
73 | return null;
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/src/com/alchemyapi/test/ParameterTest.java:
--------------------------------------------------------------------------------
1 | package com.alchemyapi.test;
2 |
3 | import com.alchemyapi.api.*;
4 |
5 | import org.xml.sax.SAXException;
6 | import org.w3c.dom.Document;
7 | import java.io.*;
8 | import javax.xml.parsers.ParserConfigurationException;
9 | import javax.xml.xpath.XPathExpressionException;
10 | import javax.xml.transform.Transformer;
11 | import javax.xml.transform.TransformerException;
12 | import javax.xml.transform.TransformerFactory;
13 | import javax.xml.transform.dom.DOMSource;
14 | import javax.xml.transform.stream.StreamResult;
15 |
16 | class ParameterTest {
17 | public static void main(String[] args)
18 | throws IOException, SAXException,
19 | ParserConfigurationException, XPathExpressionException
20 | {
21 | // Create an AlchemyAPI object.
22 | AlchemyAPI alchemyObj = AlchemyAPI.GetInstanceFromFile("api_key.txt");
23 |
24 | // Extract a ranked list of named entities for a web URL. Turn off disambiguation
25 | AlchemyAPI_NamedEntityParams entityParams = new AlchemyAPI_NamedEntityParams();
26 | entityParams.setDisambiguate(false);
27 | entityParams.setSentiment(true);
28 | Document doc = alchemyObj.URLGetRankedNamedEntities("http://www.techcrunch.com/", entityParams);
29 | System.out.println(getStringFromDocument(doc));
30 |
31 | // Extract a ranked list of named entities from a text string.
32 | doc = alchemyObj.TextGetRankedNamedEntities(
33 | "Hello there, my name is Bob Jones. I live in the United States of America. " +
34 | "Where do you live, Fred?", entityParams);
35 | System.out.println(getStringFromDocument(doc));
36 |
37 | // Load a HTML document to analyze.
38 | String htmlDoc = getFileContents("data/example.html");
39 |
40 | // Extract a ranked list of named entities from a HTML document.
41 | doc = alchemyObj.HTMLGetRankedNamedEntities(htmlDoc, "http://www.test.com/", entityParams);
42 | System.out.println(getStringFromDocument(doc));
43 |
44 | }
45 |
46 | // utility function
47 | private static String getFileContents(String filename)
48 | throws IOException, FileNotFoundException
49 | {
50 | File file = new File(filename);
51 | StringBuilder contents = new StringBuilder();
52 |
53 | BufferedReader input = new BufferedReader(new FileReader(file));
54 |
55 | try {
56 | String line = null;
57 |
58 | while ((line = input.readLine()) != null) {
59 | contents.append(line);
60 | contents.append(System.getProperty("line.separator"));
61 | }
62 | } finally {
63 | input.close();
64 | }
65 |
66 | return contents.toString();
67 | }
68 |
69 | // utility method
70 | private static String getStringFromDocument(Document doc) {
71 | try {
72 | DOMSource domSource = new DOMSource(doc);
73 | StringWriter writer = new StringWriter();
74 | StreamResult result = new StreamResult(writer);
75 |
76 | TransformerFactory tf = TransformerFactory.newInstance();
77 | Transformer transformer = tf.newTransformer();
78 | transformer.transform(domSource, result);
79 |
80 | return writer.toString();
81 | } catch (TransformerException ex) {
82 | ex.printStackTrace();
83 | return null;
84 | }
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/src/com/alchemyapi/test/RelationsTest.java:
--------------------------------------------------------------------------------
1 | package com.alchemyapi.test;
2 |
3 | import com.alchemyapi.api.*;
4 |
5 | import org.xml.sax.SAXException;
6 | import org.w3c.dom.Document;
7 | import java.io.*;
8 | import javax.xml.parsers.ParserConfigurationException;
9 | import javax.xml.xpath.XPathExpressionException;
10 | import javax.xml.transform.Transformer;
11 | import javax.xml.transform.TransformerException;
12 | import javax.xml.transform.TransformerFactory;
13 | import javax.xml.transform.dom.DOMSource;
14 | import javax.xml.transform.stream.StreamResult;
15 |
16 | class RelationsTest {
17 | public static void main(String[] args)
18 | throws IOException, SAXException,
19 | ParserConfigurationException, XPathExpressionException
20 | {
21 | // Create an AlchemyAPI object.
22 | AlchemyAPI alchemyObj = AlchemyAPI.GetInstanceFromFile("api_key.txt");
23 |
24 | // Extract a ranked list of relations for a web URL.
25 | Document doc = alchemyObj.URLGetRelations("http://www.techcrunch.com/");
26 | System.out.println(getStringFromDocument(doc));
27 |
28 | // Extract a ranked list of relations from a text string.
29 | doc = alchemyObj.TextGetRelations(
30 | "Hello there, my name is Bob Jones. I live in the United States of America. " +
31 | "Where do you live, Fred?");
32 | System.out.println(getStringFromDocument(doc));
33 |
34 | // Load a HTML document to analyze.
35 | String htmlDoc = getFileContents("data/example.html");
36 |
37 | // Extract a ranked list of relations from a HTML document.
38 | doc = alchemyObj.HTMLGetRelations(htmlDoc, "http://www.test.com/");
39 | System.out.println(getStringFromDocument(doc));
40 |
41 | AlchemyAPI_RelationParams relationParams = new AlchemyAPI_RelationParams();
42 | relationParams.setSentiment(true);
43 | relationParams.setEntities(true);
44 | relationParams.setDisambiguate(true);
45 | relationParams.setSentimentExcludeEntities(true);
46 | doc = alchemyObj.TextGetRelations("Madonna enjoys tasty Pepsi. I love her style.", relationParams);
47 | System.out.println(getStringFromDocument(doc));
48 |
49 | relationParams.setSentiment(true);
50 | relationParams.setRequireEntities(true);
51 | relationParams.setSentimentExcludeEntities(true);
52 | doc = alchemyObj.TextGetRelations("Madonna enjoys tasty Pepsi. I love her style.", relationParams);
53 | System.out.println(getStringFromDocument(doc));
54 | }
55 |
56 | // utility function
57 | private static String getFileContents(String filename)
58 | throws IOException, FileNotFoundException
59 | {
60 | File file = new File(filename);
61 | StringBuilder contents = new StringBuilder();
62 |
63 | BufferedReader input = new BufferedReader(new FileReader(file));
64 |
65 | try {
66 | String line = null;
67 |
68 | while ((line = input.readLine()) != null) {
69 | contents.append(line);
70 | contents.append(System.getProperty("line.separator"));
71 | }
72 | } finally {
73 | input.close();
74 | }
75 |
76 | return contents.toString();
77 | }
78 |
79 | // utility method
80 | private static String getStringFromDocument(Document doc) {
81 | try {
82 | DOMSource domSource = new DOMSource(doc);
83 | StringWriter writer = new StringWriter();
84 | StreamResult result = new StreamResult(writer);
85 |
86 | TransformerFactory tf = TransformerFactory.newInstance();
87 | Transformer transformer = tf.newTransformer();
88 | transformer.transform(domSource, result);
89 |
90 | return writer.toString();
91 | } catch (TransformerException ex) {
92 | ex.printStackTrace();
93 | return null;
94 | }
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/src/com/alchemyapi/test/SentimentTest.java:
--------------------------------------------------------------------------------
1 | package com.alchemyapi.test;
2 |
3 | import com.alchemyapi.api.AlchemyAPI;
4 | import com.alchemyapi.api.*;
5 |
6 | import org.xml.sax.SAXException;
7 | import org.w3c.dom.Document;
8 | import java.io.*;
9 | import javax.xml.parsers.ParserConfigurationException;
10 | import javax.xml.xpath.XPathExpressionException;
11 | import javax.xml.transform.Transformer;
12 | import javax.xml.transform.TransformerException;
13 | import javax.xml.transform.TransformerFactory;
14 | import javax.xml.transform.dom.DOMSource;
15 | import javax.xml.transform.stream.StreamResult;
16 |
17 | class SentimentTest {
18 | public static void main(String[] args) throws IOException, SAXException,
19 | ParserConfigurationException, XPathExpressionException {
20 | // Create an AlchemyAPI object.
21 | AlchemyAPI alchemyObj = AlchemyAPI.GetInstanceFromFile("api_key.txt");
22 |
23 | // Extract sentiment for a web URL.
24 | Document doc = alchemyObj.URLGetTextSentiment("http://www.techcrunch.com/");
25 | System.out.println(getStringFromDocument(doc));
26 |
27 | // Extract sentiment for a text string.
28 | doc = alchemyObj.TextGetTextSentiment(
29 | "That hat is ridiculous, Charles.");
30 | System.out.println(getStringFromDocument(doc));
31 |
32 | // Load a HTML document to analyze.
33 | String htmlDoc = getFileContents("data/example.html");
34 |
35 | // Extract sentiment for a HTML document.
36 | doc = alchemyObj.HTMLGetTextSentiment(htmlDoc, "http://www.test.com/");
37 | System.out.println(getStringFromDocument(doc));
38 |
39 | // Extract entity-targeted sentiment from a HTML document.
40 | AlchemyAPI_NamedEntityParams entityParams = new AlchemyAPI_NamedEntityParams();
41 | entityParams.setSentiment(true);
42 | doc = alchemyObj.TextGetRankedNamedEntities("That Mike Tyson is such a sweetheart.", entityParams);
43 | System.out.println(getStringFromDocument(doc));
44 |
45 | // Extract keyword-targeted sentiment from a HTML document.
46 | AlchemyAPI_KeywordParams keywordParams = new AlchemyAPI_KeywordParams();
47 | keywordParams.setSentiment(true);
48 | doc = alchemyObj.TextGetRankedKeywords("That Mike Tyson is such a sweetheart.", keywordParams);
49 | System.out.println(getStringFromDocument(doc));
50 |
51 | //Extract Targeted Sentiment from text
52 | AlchemyAPI_TargetedSentimentParams sentimentParams = new AlchemyAPI_TargetedSentimentParams();
53 | sentimentParams.setShowSourceText(true);
54 | doc = alchemyObj.TextGetTargetedSentiment("This car is terrible.", "car", sentimentParams);
55 | System.out.print(getStringFromDocument(doc));
56 |
57 | //Extract Targeted Sentiment from url
58 | doc = alchemyObj.URLGetTargetedSentiment("http://techcrunch.com/2012/03/01/keen-on-anand-rajaraman-how-walmart-wants-to-leapfrog-over-amazon-tctv/", "Walmart",sentimentParams);
59 | System.out.print(getStringFromDocument(doc));
60 |
61 | //Extract Targeted Sentiment from html
62 | doc = alchemyObj.HTMLGetTargetedSentiment(htmlDoc, "http://www.test.com/", "WujWuj", sentimentParams);
63 | System.out.print(getStringFromDocument(doc));
64 | }
65 |
66 | // utility function
67 | private static String getFileContents(String filename)
68 | throws IOException, FileNotFoundException
69 | {
70 | File file = new File(filename);
71 | StringBuilder contents = new StringBuilder();
72 |
73 | BufferedReader input = new BufferedReader(new FileReader(file));
74 |
75 | try {
76 | String line = null;
77 |
78 | while ((line = input.readLine()) != null) {
79 | contents.append(line);
80 | contents.append(System.getProperty("line.separator"));
81 | }
82 | } finally {
83 | input.close();
84 | }
85 |
86 | return contents.toString();
87 | }
88 |
89 | // utility method
90 | private static String getStringFromDocument(Document doc) {
91 | try {
92 | DOMSource domSource = new DOMSource(doc);
93 | StringWriter writer = new StringWriter();
94 | StreamResult result = new StreamResult(writer);
95 |
96 | TransformerFactory tf = TransformerFactory.newInstance();
97 | Transformer transformer = tf.newTransformer();
98 | transformer.transform(domSource, result);
99 |
100 | return writer.toString();
101 | } catch (TransformerException ex) {
102 | ex.printStackTrace();
103 | return null;
104 | }
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/src/com/alchemyapi/test/TaxonomyTest.java:
--------------------------------------------------------------------------------
1 | package com.alchemyapi.test;
2 |
3 | import com.alchemyapi.api.*;
4 |
5 | import org.xml.sax.SAXException;
6 | import org.w3c.dom.Document;
7 | import java.io.*;
8 | import javax.xml.parsers.ParserConfigurationException;
9 | import javax.xml.xpath.XPathExpressionException;
10 | import javax.xml.transform.Transformer;
11 | import javax.xml.transform.TransformerException;
12 | import javax.xml.transform.TransformerFactory;
13 | import javax.xml.transform.dom.DOMSource;
14 | import javax.xml.transform.stream.StreamResult;
15 |
16 | class TaxonomyTest {
17 | public static void main(String[] args)
18 | throws IOException, SAXException,
19 | ParserConfigurationException, XPathExpressionException
20 | {
21 | // Create an AlchemyAPI object.
22 | AlchemyAPI alchemyObj = AlchemyAPI.GetInstanceFromFile("api_key.txt");
23 |
24 | // Extract a ranked list of relations for a web URL.
25 | Document doc = alchemyObj.URLGetTaxonomy("http://www.techcrunch.com/");
26 | System.out.println(getStringFromDocument(doc));
27 |
28 | // Extract a ranked taxonomy from a text string.
29 | doc = alchemyObj.TextGetTaxonomy(
30 | "Hello there, my name is Bob Jones. I live in the United States of America. " +
31 | "Where do you live, Fred?");
32 | System.out.println(getStringFromDocument(doc));
33 |
34 | // Load a HTML document to analyze.
35 | String htmlDoc = getFileContents("data/example.html");
36 |
37 | // Extract a ranked taxonomy from a HTML document.
38 | doc = alchemyObj.HTMLGetTaxonomy(htmlDoc, "http://www.test.com/");
39 | System.out.println(getStringFromDocument(doc));
40 | }
41 |
42 | // utility function
43 | private static String getFileContents(String filename)
44 | throws IOException, FileNotFoundException
45 | {
46 | File file = new File(filename);
47 | StringBuilder contents = new StringBuilder();
48 |
49 | BufferedReader input = new BufferedReader(new FileReader(file));
50 |
51 | try {
52 | String line = null;
53 |
54 | while ((line = input.readLine()) != null) {
55 | contents.append(line);
56 | contents.append(System.getProperty("line.separator"));
57 | }
58 | } finally {
59 | input.close();
60 | }
61 |
62 | return contents.toString();
63 | }
64 |
65 | // utility method
66 | private static String getStringFromDocument(Document doc) {
67 | try {
68 | DOMSource domSource = new DOMSource(doc);
69 | StringWriter writer = new StringWriter();
70 | StreamResult result = new StreamResult(writer);
71 |
72 | TransformerFactory tf = TransformerFactory.newInstance();
73 | Transformer transformer = tf.newTransformer();
74 | transformer.transform(domSource, result);
75 |
76 | return writer.toString();
77 | } catch (TransformerException ex) {
78 | ex.printStackTrace();
79 | return null;
80 | }
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/com/alchemyapi/test/TextExtractTest.java:
--------------------------------------------------------------------------------
1 | package com.alchemyapi.test;
2 |
3 | import com.alchemyapi.api.AlchemyAPI;
4 |
5 | import org.xml.sax.SAXException;
6 | import org.w3c.dom.Document;
7 | import java.io.*;
8 | import javax.xml.parsers.ParserConfigurationException;
9 | import javax.xml.xpath.XPathExpressionException;
10 | import javax.xml.transform.Transformer;
11 | import javax.xml.transform.TransformerException;
12 | import javax.xml.transform.TransformerFactory;
13 | import javax.xml.transform.dom.DOMSource;
14 | import javax.xml.transform.stream.StreamResult;
15 |
16 | class TextExtractTest {
17 | public static void main(String[] args)
18 | throws IOException, SAXException,
19 | ParserConfigurationException, XPathExpressionException
20 | {
21 | // Create an AlchemyAPI object.
22 | AlchemyAPI alchemyObj = AlchemyAPI.GetInstanceFromFile("api_key.txt");
23 |
24 | // Extract page text from a web URL. (ignoring ads, navigation links,
25 | // and other content).
26 | Document doc = alchemyObj.URLGetText("http://www.techcrunch.com/");
27 | System.out.println(getStringFromDocument(doc));
28 |
29 | // Extract raw page text from a web URL. (including ads, navigation
30 | // links, and other content).
31 | doc = alchemyObj.URLGetRawText("http://www.techcrunch.com/");
32 | System.out.println(getStringFromDocument(doc));
33 |
34 | // Extract a title from a web URL.
35 | doc = alchemyObj.URLGetTitle("http://www.techcrunch.com/");
36 | System.out.println(getStringFromDocument(doc));
37 |
38 | // Load a HTML document to analyze.
39 | String htmlDoc = getFileContents("data/example.html");
40 |
41 | // Extract page text from a HTML document. (ignoring ads, navigation
42 | // links, and other content).
43 | doc = alchemyObj.HTMLGetText(htmlDoc, "http://www.test.com/");
44 | System.out.println(getStringFromDocument(doc));
45 |
46 | // Extract raw page text from a HTML document. (including ads,
47 | // navigation links, and other content).
48 | doc = alchemyObj.HTMLGetRawText(htmlDoc, "http://www.test.com/");
49 | System.out.println(getStringFromDocument(doc));
50 |
51 | // Extract a title from a HTML document.
52 | doc = alchemyObj.HTMLGetTitle(htmlDoc, "http://www.test.com/");
53 | System.out.println(getStringFromDocument(doc));
54 | }
55 |
56 | // utility function
57 | private static String getFileContents(String filename)
58 | throws IOException, FileNotFoundException
59 | {
60 | File file = new File(filename);
61 | StringBuilder contents = new StringBuilder();
62 |
63 | BufferedReader input = new BufferedReader(new FileReader(file));
64 |
65 | try {
66 | String line = null;
67 |
68 | while ((line = input.readLine()) != null) {
69 | contents.append(line);
70 | contents.append(System.getProperty("line.separator"));
71 | }
72 | } finally {
73 | input.close();
74 | }
75 |
76 | return contents.toString();
77 | }
78 |
79 | // utility method
80 | private static String getStringFromDocument(Document doc) {
81 | try {
82 | DOMSource domSource = new DOMSource(doc);
83 | StringWriter writer = new StringWriter();
84 | StreamResult result = new StreamResult(writer);
85 |
86 | TransformerFactory tf = TransformerFactory.newInstance();
87 | Transformer transformer = tf.newTransformer();
88 | transformer.transform(domSource, result);
89 |
90 | return writer.toString();
91 | } catch (TransformerException ex) {
92 | ex.printStackTrace();
93 | return null;
94 | }
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/testdir/api_key.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlchemyAPI/alchemyapi_java/f2cf49757907f3c180bcb9586c8a026412936a08/testdir/api_key.txt
--------------------------------------------------------------------------------
/testdir/data/cat.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlchemyAPI/alchemyapi_java/f2cf49757907f3c180bcb9586c8a026412936a08/testdir/data/cat.jpg
--------------------------------------------------------------------------------
/testdir/data/example2.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | GOP votes for spending boondoggle - CNN.com
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
34 |
35 |
36 |
37 |
41 |
42 |
43 |
51 |
52 |
60 |
61 |
65 |
66 |
67 |
68 |
69 | CNN
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
85 |
91 |
101 |
102 |
103 |
104 |
122 |
123 |
124 |
127 |
128 |
129 |
135 |
136 |
137 |
138 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
172 |
173 |
174 |
175 |
180 |
181 |
182 |
242 |
243 |
244 |
245 |
246 |
247 |
GOP votes for spending boondoggle By John P. Avlon , CNN Contributor
STORY HIGHLIGHTS
House defeated a bid to kill a defense spending project that Pentagon says it doesn't need John Avlon says GOP critics of government spending voted for half-billion dollar project He says this was a clear-cut case of a way to cut the budget deficit Avlon asks how GOP can run on platform of cutting spending while supporting this project
250 | RELATED TOPICS
251 |
269 |
Editor's note: John P. Avlon is a CNN contributor and senior political columnist for The Daily Beast. He is the author of "Wingnuts: How the Lunatic Fringe is Hijacking America."
New York (CNN) -- In a time of voter anger at unsustainable government spending and Washington hypocrisy, here's a story that should get your blood up.
Last week, the House of Representatives considered eliminating a nearly half-billion dollar earmark that was snuck into a defense authorization bill. But members of both parties voted to keep the corporate pork in the bill -- despite a supposed moratorium on earmarks and despite that the Pentagon has repeatedly said it doesn't want the money.
Only in Washington would bureaucracy be force-fed a project it doesn't want or need.
But so far, we haven't seen this contempt for taxpayer dollars make its way to protest signs or talk radio driven talking points. That's because President Obama opposes the earmark and the Republican congressional leadership voted for it.
This doesn't fit neatly into the hyperpartisan narrative of screaming about socialism -- in which Republicans bewail overspending by Democrats -- but it's a perfect illustration of how deep the dysfunction is in Washington.
At issue is the alternate engine for the Joint Strike Fighter platform, a corporate subsidized boondoggle that has cost taxpayers $1.2 billion in earmarks since 2004. It is estimated to cost at least $2.9 billion more until its completion.
Defenders argue that paying GE and Rolls Royce to develop a second engine for Air Force fighters will stimulate competition in the defense industry and bring down costs in the long run while protecting jobs in the short run.
Critics point out that crony capitalism can't create a true free market in the defense industry -- it's the equivalent of diet hucksters who claim you can eat yourself fitter. This is about money: pork barrel politics hiding under the noble banner of national defense.
Here's how the sordid story unfolded:
An anonymous earmark was added to the defense authorization bill, requesting $485 million in new funds for the alternate engine program, despite a much-ballyhooed moratorium on earmarks going to for-profit entities (agreed to by Democrats), and a total ban on earmark requests agreed to by Republicans for fiscal year 2011.
In reaction, a small bipartisan group of members of Congress -- led by Democrat Chellie Pingree of Maine and Republican Tom Rooney of Florida, joined by Democrat John Larson of Connecticut and Republican Lynn Westmoreland of Georgia -- proposed an amendment to strip the bill of the ugly anonymous earmark. Their principled stand went down to defeat by a vote of 193 to 231.
It's no surprise that in a recession, the congressional representatives of Ohio and Indiana would vote to keep the earmark subsidy in the bill, including the normally stalwart fiscal conservative Mike Pence of Indiana. Those states are benefiting most from the development of the engines in terms of jobs on the ground.
What's more surprising is why so many of their colleagues would climb on this pork-barrel bandwagon, including the Republican congressional leadership led by John Boehner and Eric Cantor, who are trying to build the midterm election campaign around a promise to restore fiscal discipline.
That selling job that should be even tougher since a majority of Democrats voted to kill the alternate engine and a majority of Republicans voted to keep it going.
"This was the first big earmark test for 2010, and Congress failed," said Thomas A. Schatz, the President of Citizens Against Government Waste, which has been a steadfast critic of the alternate engine and recently released a detailed report on the subject.
"Neither party comes out looking good, but Republicans in particular missed a golden opportunity to show that they are really serious about getting government spending under control."
The next chance to stop the half-billion dollar alternate engine earmark is the Senate, when it takes up the defense authorization bill later this month. But even success there from genuine fiscal conservatives such as John McCain could be undone when the bill goes to conference -- it's the Washington way.
The final stop would be a presidential veto, which President Obama has promised, under advice from Defense Secretary Gates.
A half century ago, Republican President Eisenhower warned about the influence of the military-industrial complex.
The former five-star general crusaded against government waste, especially in the military, because he knew that a figure with lesser credibility could be attacked as being "soft on communism" for proposing responsible cuts from the Pentagon budget during the Cold War.
We are at war today on two fronts, even as we face down a fiscal crisis and escalating deficits and debt.
We owe it to our troops to see that every dollar allocated to the military is spent where they need it, not where congressional appropriators want it. And if fiscal conservative protesters cannot marshal their energy to oppose this half-billion dollar boondoggle, then it is not just Congress' hypocrisy they should be angry at -- it is their own.
The opinions expressed in this commentary are solely those of John P. Avlon.
338 |
339 |
340 |
341 |
342 |
365 |
366 |
367 |
368 |
369 |
373 |
374 |
375 |
376 |
377 |
378 |
379 |
380 |
381 |
385 |
386 |
387 |
388 |
389 |
390 |
391 |
392 |
393 |
394 |
398 |
399 |
400 |
401 |
402 |
403 |
404 |
405 |
406 |
407 |
408 |
409 |
410 |
411 |
412 |
Most popular stories right now
413 |
414 |
419 |
420 |
425 |
426 |
431 |
432 |
437 |
438 |
443 |
444 |
445 |
446 |
447 |
448 |
449 |
450 |
451 |
452 |
453 |
454 |
455 |
459 |
460 |
461 |
462 |
463 |
464 |
465 |
466 |
467 |
468 |
469 |
470 |
471 |
472 |
473 |
474 |
475 |
476 |
480 |
481 |
482 |
483 |
484 |
485 |
486 |
487 |
488 |
489 |
490 |
494 |
495 |
496 |
500 |
501 |
502 |
503 |
504 |
505 |
Loading weather data ...
506 |
507 |
508 |
523 |
524 |
525 |
526 |
527 |
528 |
529 |
530 |
531 |
532 |
533 |
534 |
535 |
536 |
537 |
538 |
542 |
543 |
547 |
548 |
549 |
550 |
551 |
552 |
555 |
556 |
559 |
564 |
565 |
566 |
567 |
568 |
576 |
577 |
580 |
583 |
584 |
585 |
586 |
587 |
--------------------------------------------------------------------------------
/testdir/data/example2_nolinks.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | b> John P. Avlon is a CNN contributor and senior political columnist for The Daily Beast. He is the author of "Wingnuts: How the Lunatic Fringe is Hijacking America."
4 | New York (CNN) -- In a time of voter anger at unsustainable government spending and Washington hypocrisy, here's a story that should get your blood up.
5 | Last week, the House of Representatives considered eliminating a nearly half-billion dollar earmark that was snuck into a defense authorization bill. But members of both parties
6 | voted to keep the corporate pork in the bill -- despite a supposed moratorium on earmarks and despite that the Pentagon has repeatedly said it doesn't want the money.
Only in
7 | Washington would bureaucracy be force-fed a project it doesn't want or need.
But so far, we haven't seen this contempt for taxpayer dollars make its way to protest signs or
8 | talk radio driven talking points. That's because President Obama opposes the earmark and the Republican congressional leadership voted for it.
This doesn't fit neatly into the
9 | hyperpartisan narrative of screaming about socialism -- in which Republicans bewail overspending by Democrats -- but it's a perfect illustration of how deep the dysfunction is in Washington.
10 |
At issue is the alternate engine for the Joint Strike Fighter platform, a corporate subsidized boondoggle that has cost taxpayers $1.2 billion in earmarks since 2004. It is
11 | estimated to cost at least $2.9 billion more until its completion.
Defenders argue that paying GE and Rolls Royce to develop a second engine for Air Force fighters will stimulate
12 | competition in the defense industry and bring down costs in the long run while protecting jobs in the short run.
Critics point out that crony capitalism can't create a true free
13 | market in the defense industry -- it's the equivalent of diet hucksters who claim you can eat yourself fitter. This is about money: pork barrel politics hiding under the noble banner of
14 | national defense.
Here's how the sordid story unfolded:
An anonymous earmark was added to the defense authorization bill, requesting $485 million in new funds for the
15 | alternate engine program, despite a much-ballyhooed moratorium on earmarks going to for-profit entities (agreed to by Democrats), and a total ban on earmark requests agreed to by
16 | Republicans for fiscal year 2011.
In reaction, a small bipartisan group of members of Congress -- led by Democrat Chellie Pingree of Maine and Republican Tom Rooney of Florida,
17 | joined by Democrat John Larson of Connecticut and Republican Lynn Westmoreland of Georgia -- proposed an amendment to strip the bill of the ugly anonymous earmark. Their principled stand
18 | went down to defeat by a vote of 193 to 231.
It's no surprise that in a recession, the congressional representatives of Ohio and Indiana would vote to keep the earmark subsidy in the
19 | bill, including the normally stalwart fiscal conservative Mike Pence of Indiana. Those states are benefiting most from the development of the engines in terms of jobs on the ground.
What's
20 | more surprising is why so many of their colleagues would climb on this pork-barrel bandwagon, including the Republican congressional leadership led by John Boehner and Eric Cantor, who are
21 | trying to build the midterm election campaign around a promise to restore fiscal discipline.
That selling job that should be even tougher since a majority of Democrats voted to kill
22 | the alternate engine and a majority of Republicans voted to keep it going.
"This was the first big earmark test for 2010, and Congress failed," said Thomas A. Schatz, the
23 | President of Citizens Against Government Waste, which has been a steadfast critic of the alternate engine and recently released a
24 | detailed report on the subject.
"Neither party
25 | comes out looking good, but Republicans in particular missed a golden opportunity to show that they are really serious about getting government spending under control."
The next
26 | chance to stop the half-billion dollar alternate engine earmark is the Senate, when it takes up the defense authorization bill later this month. But even success there from genuine fiscal
27 | conservatives such as John McCain could be undone when the bill goes to conference -- it's the Washington way.
The final stop would be a presidential veto, which President Obama has
28 | promised, under advice from Defense Secretary Gates.
A half century ago, Republican President Eisenhower warned about the influence of the military-industrial complex.
29 | The former five-star general crusaded against government waste, especially in the military, because he knew that a figure with lesser credibility could be attacked
30 | as being "soft on communism" for proposing responsible cuts from the Pentagon budget during the Cold War.
We are at war today on two fronts, even
31 | as we face down a fiscal crisis and escalating deficits and debt.
We owe it to our troops to see that every dollar allocated to the military is spent where
32 | they need it, not where congressional appropriators want it. And if fiscal conservative protesters cannot marshal their energy to oppose this half-billion dollar
33 | boondoggle, then it is not just Congress' hypocrisy they should be angry at -- it is their own.
The opinions expressed in this
34 | commentary are solely those of John P. Avlon.
35 |
36 |
--------------------------------------------------------------------------------
/testdir/data/example3.html:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlchemyAPI/alchemyapi_java/f2cf49757907f3c180bcb9586c8a026412936a08/testdir/data/example3.html
--------------------------------------------------------------------------------