public static AlchemyAPI GetInstanceFromFile(String keyFilename) throws FileNotFoundException, IOException { AlchemyAPI api = new AlchemyAPI(); api.LoadAPIKey(keyFilename); return api; }
public void processMessage(String message) { JsonParser parser = new JsonParser(); JsonObject messageJSON = (JsonObject) parser.parse(message); String postedURL = messageJSON.get("postedURL").getAsString(); AlchemyAPI alchemyObj = AlchemyAPI.GetInstanceFromString("5fc91e98eacfa5ebf83440e8c6a61d0f60fa380b"); // String URLString = // "http://www.huffingtonpost.com/2015/04/05/report-vegan-diet_n_7008156.html"; System.out.println("URL sent to URLGetAuthor AlchemyAPI --> " + postedURL); Document doc = null; try { doc = alchemyObj.URLGetAuthor(postedURL); } catch (XPathExpressionException | IOException | SAXException | ParserConfigurationException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } String convertDocToString = getStringFromDocument(doc); // System.out.println(convertDocToString); String alchemyAPIResult = null; try { alchemyAPIResult = returnResultFromXML(convertDocToString); } catch (SAXException | IOException | ParserConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } // System.out.println(convertDocToString); System.out.println( "Output from URLGetAuthor AlchemyAPI: Author is --> " + alchemyAPIResult.toUpperCase()); JsonObject reply = new JsonObject(); reply.addProperty("Author", alchemyAPIResult.toUpperCase()); reply.addProperty("AlchemyBackend", "JavaAPI: " + toString()); SendOptions opts = SendOptions.builder().setQos(QOS.AT_LEAST_ONCE).build(); mqlightClient.send( PUBLISH_TOPIC, reply.toString(), null, opts, new CompletionListener<Void>() { public void onSuccess(NonBlockingClient client, Void context) { logger.log(Level.INFO, "Sent reply!"); } public void onError(NonBlockingClient client, Void context, Exception exception) { logger.log(Level.INFO, "Error!." + exception.toString()); } }, null); }
public static void main(String[] args) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { // Create an AlchemyAPI object. AlchemyAPI alchemyObj = AlchemyAPI.GetInstanceFromFile("api_key.txt"); // Extract topic keywords for a web URL. Document doc = alchemyObj.URLGetRankedKeywords("http://www.techcrunch.com/"); System.out.println(getStringFromDocument(doc)); // Extract topic keywords for a text string. doc = alchemyObj.TextGetRankedKeywords( "Hello there, my name is Bob Jones. I live in the United States of America. " + "Where do you live, Fred?"); System.out.println(getStringFromDocument(doc)); // Load a HTML document to analyze. String htmlDoc = getFileContents("data/example.html"); // Extract topic keywords for a HTML document. doc = alchemyObj.HTMLGetRankedKeywords(htmlDoc, "http://www.test.com/"); System.out.println(getStringFromDocument(doc)); }
public static void main(String[] args) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { // Create an AlchemyAPI object. AlchemyAPI alchemyObj = AlchemyAPI.GetInstanceFromFile("api_key.txt"); // Extract page text from a web URL. (ignoring ads, navigation links, // and other content). Document doc = alchemyObj.URLGetText("http://www.techcrunch.com/"); System.out.println(getStringFromDocument(doc)); // Extract raw page text from a web URL. (including ads, navigation // links, and other content). doc = alchemyObj.URLGetRawText("http://www.techcrunch.com/"); System.out.println(getStringFromDocument(doc)); // Extract a title from a web URL. doc = alchemyObj.URLGetTitle("http://www.techcrunch.com/"); System.out.println(getStringFromDocument(doc)); // Load a HTML document to analyze. String htmlDoc = getFileContents("data/example.html"); // Extract page text from a HTML document. (ignoring ads, navigation // links, and other content). doc = alchemyObj.HTMLGetText(htmlDoc, "http://www.test.com/"); System.out.println(getStringFromDocument(doc)); // Extract raw page text from a HTML document. (including ads, // navigation links, and other content). doc = alchemyObj.HTMLGetRawText(htmlDoc, "http://www.test.com/"); System.out.println(getStringFromDocument(doc)); // Extract a title from a HTML document. doc = alchemyObj.HTMLGetTitle(htmlDoc, "http://www.test.com/"); System.out.println(getStringFromDocument(doc)); }
public static AlchemyAPI GetInstanceFromString(String apiKey) { AlchemyAPI api = new AlchemyAPI(); api.SetAPIKey(apiKey); return api; }