Get Your API Credentials

If you haven't already done so, you will need to sign up.

Sign up to our free plan here: developer.aylien.com/signup.

The Free plan allows you to make 1,000 calls/day for free. For further information on paid plans please visit our plans page.

Getting Started with AYLIEN Text Analysis API Using Java

Requirements

  • JDK

Getting the SDK

Since Text Analysis API is published to Maven Central, it is enough to add the dependency to the POM:

<dependency>
  <groupId>com.aylien.textapi</groupId>
  <artifactId>client</artifactId>
  <version>0.3.0</version>
</dependency>

And for SBT users:

"com.aylien.textapi" % "client" % "0.3.0"

Using the SDK

The following example demonstrates how to extract concepts mentioned in a URL and determine the language it's written in.

import com.aylien.textapi.TextAPIClient;
import com.aylien.textapi.parameters.*;
import com.aylien.textapi.responses.*;
import java.net.URL;

class Example {
  public static void main(String[] args) throws Exception {
    TextAPIClient client = new TextAPIClient("YourApplicationId", "YourApplicationKey");
    URL url = new URL("http://www.bbc.com/news/science-environment-30097648");
    ConceptsParams.Builder builder = ConceptsParams.newBuilder();
    builder.setUrl(url);
    Concepts concepts = client.concepts(builder.build());
    System.out.println(concepts.getText());
    for (Concept c: concepts.getConcepts()) {
      System.out.print(c.getUri() + ": ");
      for (SurfaceForm sf: c.getSurfaceForms()) {
        System.out.print(sf.getString() + " ");
      }
      System.out.println();
    }

    LanguageParams languageParams = new LanguageParams(null, url);
    Language language = client.language(languageParams);
    System.out.printf("\nLanguage is: %s (%f)\n", language.getLanguage(), language.getConfidence());
  }
}