Skip to content

Commit

Permalink
Merge pull request #267 from rosette-api/WS-3314-update-key-header-an…
Browse files Browse the repository at this point in the history
…d-urls

Ws 3314 update key header and urls
  • Loading branch information
seth-mg authored Nov 5, 2024
2 parents 0b04278 + bf37405 commit 753ada0
Show file tree
Hide file tree
Showing 55 changed files with 262 additions and 196 deletions.
35 changes: 26 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
<a href="https://www.babelstreet.com/rosette"><img src="https://charts.babelstreet.com/icon.png" width="47" height="60"/></a>
# Rosette by Babel Street
<a href="https://www.babelstreet.com/rosette">
<picture>
<source media="(prefers-color-scheme: light)" srcset="https://charts.babelstreet.com/icon-dark.png">
<source media="(prefers-color-scheme: dark)" srcset="https://charts.babelstreet.com/icon-light.png">
<img alt="Babel Street Logo" width="48" height="48">
</picture>
</a>

# Analytics by Babel Street

---

[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.basistech.rosette/rosette-api/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.basistech.rosette/rosette-api-java-binding)

Rosette uses natural language processing, statistical modeling, and machine learning to analyze unstructured and semi-structured text across hundreds of language-script combinations, revealing valuable information and actionable data. Rosette provides endpoints for extracting entities and relationships, translating and comparing the similarity of names, categorizing and adding linguistic tags to text and more. Rosette Server is the on-premises installation of Rosette, with access to Rosette's functions as RESTful web service endpoints. This solves cloud security worries and allows customization (models/indexes) as needed for your business.
Our product is a full text processing pipeline from data preparation to extracting the most relevant information and
analysis utilizing precise, focused AI that has built-in human understanding. Text Analytics provides foundational
linguistic analysis for identifying languages and relating words. The result is enriched and normalized text for
high-speed search and processing without translation.

Text Analytics extracts events and entities — people, organizations, and places — from unstructured text and adds the
structure of associating those entities into events that deliver only the necessary information for near real-time
decision making. Accompanying tools shorten the process of training AI models to recognize domain-specific events.

The product delivers a multitude of ways to sharpen and expand search results. Semantic similarity expands search
beyond keywords to words with the same meaning, even in other languages. Sentiment analysis and topic extraction help
filter results to what’s relevant.

## Rosette API Access
- Rosette Cloud [Sign Up](https://developer.rosette.com/signup)
## Analytics API Access
- Analytics Cloud [Sign Up](https://developer.babelstreet.com/signup)
## Quick Start

#### Maven
Expand All @@ -26,17 +43,17 @@ in the Maven Central badge at the top of this page.

#### Test Releases
Versions, of the form `x.y.z`, where `z` is greater than or equal to `100`, are internal testing versions. Do not use
them without consultation with Basis Technology Corp.
them without consultation with Babel Street.

#### Examples
View small example programs for each Rosette endpoint in the
View small example programs for each Analytics endpoint in the
[examples](examples/src/main/java/com/basistech/rosette/examples) directory.

#### Documentation & Support
- [Binding API](https://rosette-api.github.io/java/)
- [Rosette Platform API](https://docs.babelstreet.com/API/en/index-en.html)
- [Analytics Platform API](https://docs.babelstreet.com/API/en/index-en.html)
- [Binding Release Notes](https://github.com/rosette-api/java/wiki/Release-Notes)
- [Rosette Platform Release Notes](https://babelstreet.my.site.com/support/s/article/Rosette-Cloud-Release-Notes)
- [Analytics Platform Release Notes](https://docs.babelstreet.com/Release/en/rosette-cloud.html)
- [Support](https://babelstreet.my.site.com/support/s/)
- [Binding License: Apache 2.0](LICENSE.txt)

Expand Down
2 changes: 1 addition & 1 deletion all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</parent>
<artifactId>rosette-api-all</artifactId>
<name>rosette-api-all</name>
<description>Rosette API all modules combined</description>
<description>Babel Street Analytics API all modules combined</description>
<dependencies>
<dependency>
<groupId>com.basistech</groupId>
Expand Down
2 changes: 1 addition & 1 deletion annotations/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</parent>
<artifactId>rosette-api-annotations</artifactId>
<name>rosette-api-annotations</name>
<description>Rosette API Annotations</description>
<description>Babel Street Analytics API Annotations</description>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
Expand Down
2 changes: 1 addition & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</parent>
<artifactId>rosette-api</artifactId>
<name>rosette-api</name>
<description>Rosette API Communications</description>
<description>Babel Street Analytics API Communications</description>
<properties>
<skip-mockserver>false</skip-mockserver>
</properties>
Expand Down
82 changes: 53 additions & 29 deletions api/src/main/java/com/basistech/rosette/api/HttpRosetteAPI.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 Basis Technology Corp.
* Copyright 2024 Basis Technology Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -79,17 +79,17 @@
import static java.net.HttpURLConnection.HTTP_OK;

/**
* Access to the RosetteAPI via HTTP.
* Access to the Analytics API via HTTP.
*/
public class HttpRosetteAPI extends AbstractRosetteAPI {

public static final String DEFAULT_URL_BASE = "https://api.rosette.com/rest/v1";
public static final String SERVICE_NAME = "RosetteAPI";
public static final String DEFAULT_URL_BASE = "https://analytics.babelstreet.com/rest/v1";
public static final String SERVICE_NAME = "Babel-Street-Analytics-API";
public static final String BINDING_VERSION = getVersion();
public static final String USER_AGENT_STR = SERVICE_NAME + "-Java/" + BINDING_VERSION + "/"
+ System.getProperty("java.version");
private static final Logger LOG = LoggerFactory.getLogger(HttpRosetteAPI.class);
private static final String IO_EXCEPTION_MESSAGE = "IO Exception communicating with the Rosette API";
private static final String IO_EXCEPTION_MESSAGE = "IO Exception communicating with the Babel Street Analytics API";
private static final Pattern TRAILING_SLASHES = Pattern.compile("/+$");
private String urlBase = DEFAULT_URL_BASE;
private int failureRetries = 1;
Expand All @@ -104,16 +104,16 @@ private HttpRosetteAPI() {
}

/**
* Constructs a Rosette API instance using the builder syntax.
* Constructs an Analytics API instance using the builder syntax.
*
* @param key Rosette API key. This may be null for use with an on-premise deployment
* of the Rosette API.
* @param urlToCall Alternate Rosette API URL. {@code null} uses the default, public, URL.
* @param key Analytics API key. This may be null for use with an on-premise deployment
* of the Analytics API.
* @param urlToCall Alternate Analytics API URL. {@code null} uses the default, public, URL.
* @param failureRetries Number of times to retry in case of failure; {@code null} uses the
* default value: 1.
* @param connectionConcurrency Number of concurrent connections. Pass this if have subscribed
* to a plan that supports enhanced concurrency, or if you are using
* an on-premise deployment of the Rosette API. {@code null} uses the
* an on-premise deployment of the Analytics API. {@code null} uses the
* default value: 2.
* @throws HttpRosetteAPIException Problem with the API request
*/
Expand Down Expand Up @@ -197,7 +197,10 @@ private void initHeaders(String key, List<Header> additionalHeaders) {
this.additionalHeaders.add(new BasicHeader(HttpHeaders.USER_AGENT, USER_AGENT_STR));
this.additionalHeaders.add(new BasicHeader(HttpHeaders.ACCEPT_ENCODING, "gzip"));
if (key != null) {
this.additionalHeaders.add(new BasicHeader("X-RosetteAPI-Key", key));
this.additionalHeaders.add(new BasicHeader("X-BabelStreetAPI-Key", key));
this.additionalHeaders.add(new BasicHeader("X-BabelStreetAPI-Binding", "java"));
this.additionalHeaders.add(new BasicHeader("X-BabelStreetAPI-Binding-Version", BINDING_VERSION));
// TODO: Remove in a future release.
this.additionalHeaders.add(new BasicHeader("X-RosetteAPI-Binding", "java"));
this.additionalHeaders.add(new BasicHeader("X-RosetteAPI-Binding-Version", BINDING_VERSION));
}
Expand All @@ -216,32 +219,32 @@ public int getFailureRetries() {
}

/**
* Gets information about the Rosette API, returns name, version, build number and build time.
* Gets information about the Analytics API, returns name, version, build number and build time.
*
* @return InfoResponse
* @throws HttpRosetteAPIException Rosette specific exception
* @throws HttpRosetteAPIException Analytics specific exception
* @throws IOException General IO exception
*/
public InfoResponse info() throws IOException, HttpRosetteAPIException {
return sendGetRequest(urlBase + INFO_SERVICE_PATH, InfoResponse.class);
}

/**
* Pings the Rosette API for a response indicating that the service is available.
* Pings the Analytics API for a response indicating that the service is available.
*
* @return PingResponse
* @throws HttpRosetteAPIException Rosette specific exception
* @throws HttpRosetteAPIException Analytics specific exception
* @throws IOException General IO exception
*/
public PingResponse ping() throws IOException, HttpRosetteAPIException {
return sendGetRequest(urlBase + PING_SERVICE_PATH, PingResponse.class);
}

/**
* Gets the set of language and script codes supported by the specified Rosette API endpoint.
* Gets the set of language and script codes supported by the specified Analytics API endpoint.
*
* @return SupportedLanguagesResponse
* @throws HttpRosetteAPIException for an error returned from the Rosette API.
* @throws HttpRosetteAPIException for an error returned from the Analytics API.
*/
@Override
public SupportedLanguagesResponse getSupportedLanguages(String endpoint) throws HttpRosetteAPIException {
Expand All @@ -254,12 +257,12 @@ public SupportedLanguagesResponse getSupportedLanguages(String endpoint) throws
}

/**
* Gets the set of language, script codes and transliteration scheme pairs supported by the specified Rosette API
* Gets the set of language, script codes and transliteration scheme pairs supported by the specified Analytics API
* endpoint.
*
* @param endpoint Rosette API endpoint.
* @param endpoint Analytics API endpoint.
* @return SupportedLanguagePairsResponse
* @throws HttpRosetteAPIException for an error returned from the Rosette API.
* @throws HttpRosetteAPIException for an error returned from the Analytics API.
*/
@Override
public SupportedLanguagePairsResponse getSupportedLanguagePairs(String endpoint) throws HttpRosetteAPIException {
Expand All @@ -279,7 +282,7 @@ public SupportedLanguagePairsResponse getSupportedLanguagePairs(String endpoint)
* @param <RequestType> the type of the request object.
* @param <ResponseType> the type of the response object.
* @return the response.
* @throws HttpRosetteAPIException for an error returned from the Rosette API.
* @throws HttpRosetteAPIException for an error returned from the Analytics API.
* @throws RosetteRuntimeException for other errors, such as communications problems with HTTP.
*/
@Override
Expand All @@ -300,7 +303,7 @@ public <RequestType extends Request, ResponseType extends Response> ResponseType
* @param request the data for the request.
* @param <RequestType> the type of the request object.
* @return the response, {@link com.basistech.rosette.dm.AnnotatedText}.
* @throws HttpRosetteAPIException for an error returned from the Rosette API.
* @throws HttpRosetteAPIException for an error returned from the Analytics API.
* @throws RosetteRuntimeException for other errors, such as communications problems with HTTP.
*/
@Override
Expand All @@ -326,11 +329,11 @@ public <RequestType extends Request> AnnotatedText perform(String endpoint, Requ
}

/**
* Sends a GET request to Rosette API.
* Sends a GET request to Analytics API.
* <p>
* Returns a Response.
*
* @param urlStr Rosette API end point.
* @param urlStr Analytics API end point.
* @param clazz Response class
* @return Response
* @throws HttpRosetteAPIException
Expand All @@ -351,11 +354,11 @@ private <T extends Response> T sendGetRequest(String urlStr, Class<T> clazz) thr
}

/**
* Sends a POST request to Rosette API.
* Sends a POST request to Analytics API.
* <p>
* Returns a Response.
*
* @param urlStr Rosette API end point.
* @param urlStr Analytics API end point.
* @param clazz Response class
* @return Response
* @throws IOException
Expand Down Expand Up @@ -401,10 +404,15 @@ private <T> T sendPostRequest(Object request, String urlStr, Class<T> clazz)
while (numRetries-- > 0) {
try (CloseableHttpResponse response = httpClient.execute(post)) {
T resp = getResponse(response, clazz);
// TODO: Remove in a future release
Header ridHeader = response.getFirstHeader("X-RosetteAPI-DocumentRequest-Id");
if (ridHeader != null && ridHeader.getValue() != null) {
LOG.debug("DocumentRequest ID {}", ridHeader.getValue());
}
Header bsidHeader = response.getFirstHeader("X-BabelStreetAPI-DocumentRequest-Id");
if (bsidHeader != null && bsidHeader.getValue() != null) {
LOG.debug("DocumentRequest ID {}", bsidHeader.getValue());
}
if (resp instanceof Response) {
responseHeadersToExtendedInformation((Response)resp, response);
}
Expand Down Expand Up @@ -556,21 +564,37 @@ private <T extends Object> T getResponse(HttpResponse httpResponse, Class<T> cla
InputStream stream = httpResponse.getEntity().getContent();
InputStream inputStream = "gzip".equalsIgnoreCase(encoding) ? new GZIPInputStream(stream) : stream) {
String ridHeader = headerValueOrNull(httpResponse.getFirstHeader("X-RosetteAPI-DocumentRequest-Id"));
String bsidHeader = headerValueOrNull(httpResponse.getFirstHeader("X-BabelStreetAPI-DocumentRequest-Id"));
if (HTTP_OK != status) {
String ecHeader = headerValueOrNull(httpResponse.getFirstHeader("X-RosetteAPI-Status-Code"));
String emHeader = headerValueOrNull(httpResponse.getFirstHeader("X-RosetteAPI-Status-Message"));
String ecHeader;
if (headerValueOrNull(httpResponse.getFirstHeader("X-BabelStreetAPI-Status-Code")) != null) {
ecHeader = headerValueOrNull(httpResponse.getFirstHeader("X-BabelStreetAPI-Status-Code"));
} else {
// TODO: Remove in a future release
ecHeader = headerValueOrNull(httpResponse.getFirstHeader("X-RosetteAPI-Status-Code"));
}
String emHeader;
if (headerValueOrNull(httpResponse.getFirstHeader("X-BabelStreetAPI-Status-Message")) != null) {
emHeader = headerValueOrNull(httpResponse.getFirstHeader("X-BabelStreetAPI-Status-Message"));
} else {
// TODO: Remove in a future release
emHeader = headerValueOrNull(httpResponse.getFirstHeader("X-RosetteAPI-Status-Message"));
}
String responseContentType = headerValueOrNull(httpResponse.getFirstHeader(HttpHeaders.CONTENT_TYPE));
if ("application/json".equals(responseContentType)) {
ErrorResponse errorResponse = mapper.readValue(inputStream, ErrorResponse.class);
if (ridHeader != null) {
LOG.debug("DocumentRequest ID {}", ridHeader);
}
if (bsidHeader != null) {
LOG.debug("DocumentRequest ID {}", bsidHeader);
}
if (ecHeader != null) {
errorResponse.setCode(ecHeader);
}
if (429 == status) {
String concurrencyMessage = "You have exceeded your plan's limit on concurrent calls. "
+ "This could be caused by multiple processes or threads making Rosette API calls "
+ "This could be caused by multiple processes or threads making Analytics API calls "
+ "in parallel, or if your httpClient is configured with higher concurrency "
+ "than your plan allows.";
if (emHeader == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014 Basis Technology Corp.
* Copyright 2024 Basis Technology Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,7 @@
package com.basistech.rosette.api;

/**
* Specify which feature you want Rosette API Morphology endpoint to return. Specify COMPLETE for every feature.
* Specify which feature you want Analytics API Morphology endpoint to return. Specify COMPLETE for every feature.
*/
public enum MorphologicalFeature {
COMPLETE("complete"),
Expand Down
8 changes: 4 additions & 4 deletions api/src/test/java/com/basistech/rosette/api/BasicTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 Basis Technology Corp.
* Copyright 2024 Basis Technology Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -138,7 +138,7 @@ void testHeaders() throws Exception {
.withHeader(HttpHeaders.USER_AGENT, HttpRosetteAPI.USER_AGENT_STR))
.respond(HttpResponse.response()
.withHeader("Content-Type", "application/json")
.withHeader("X-RosetteAPI-Concurrency", "5")
.withHeader("X-BabelStreetAPI-Concurrency", "5")
.withStatusCode(200)
.withBody("{\"message\":\"Rosette API at your service\",\"time\":1461788498633}", StandardCharsets.UTF_8));

Expand All @@ -148,7 +148,7 @@ void testHeaders() throws Exception {
.additionalHeader("X-Foo", "Bar")
.build();
var resp = api.ping();
assertEquals("5", resp.getExtendedInformation().get("X-RosetteAPI-Concurrency"));
assertEquals("5", resp.getExtendedInformation().get("X-BabelStreetAPI-Concurrency"));
}

@Test
Expand Down Expand Up @@ -185,7 +185,7 @@ void testExtendedInfo() throws Exception {
.withHeader("Content-Type", "application/json")
.withHeader("X-Foo", "Bar")
.withHeader("X-FooMulti", "Bar1", "Bar2")
.withHeader("X-RosetteAPI-Concurrency", "5")
.withHeader("X-BabelStreetAPI-Concurrency", "5")
.withBody("{\"message\":\"Rosette API at your service\",\"time\":1461788498633}", StandardCharsets.UTF_8));
api = new HttpRosetteAPI.Builder()
.key("foo-key")
Expand Down
Loading

0 comments on commit 753ada0

Please sign in to comment.