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));
  }
Ejemplo n.º 2
0
  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));
  }