Skip to content

Commit 2663a2e

Browse files
Merge pull request #169 from rosette-api/ws-2161-event-endpoint-for-Rosette-Server
WS-2161 event endpoint for rosette server
2 parents 10f057d + 9f2d05b commit 2663a2e

File tree

6 files changed

+186
-2
lines changed

6 files changed

+186
-2
lines changed

common/src/main/java/com/basistech/rosette/api/common/AbstractRosetteAPI.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public abstract class AbstractRosetteAPI implements AutoCloseable {
5454
public static final String INFO_SERVICE_PATH = "/info";
5555
public static final String PING_SERVICE_PATH = "/ping";
5656
public static final String SUPPORTED_LANGUAGES_SUBPATH = "/supported-languages";
57+
public static final String EVENTS_SERVICE_PATH = "/events";
5758

5859
public static final Set<String> DOC_ENDPOINTS = new HashSet<>(Arrays.asList(
5960
LANGUAGE_SERVICE_PATH,
@@ -74,7 +75,8 @@ public abstract class AbstractRosetteAPI implements AutoCloseable {
7475
SIMILAR_TERMS_SERVICE_PATH,
7576
SYNTAX_DEPENDENCIES_SERVICE_PATH,
7677
TRANSLITERATION_SERVICE_PATH,
77-
TOPICS_SERVICE_PATH
78+
TOPICS_SERVICE_PATH,
79+
EVENTS_SERVICE_PATH
7880
));
7981

8082
public static final Set<String> NAMES_ENDPOINTS = new HashSet<>(Arrays.asList(
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2021 Basis Technology Corp.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.basistech.rosette.examples;
17+
18+
import com.basistech.rosette.api.HttpRosetteAPI;
19+
import com.basistech.rosette.apimodel.DocumentRequest;
20+
import com.basistech.rosette.apimodel.EventsOptions;
21+
import com.basistech.rosette.apimodel.EventsResponse;
22+
import com.basistech.util.LanguageCode;
23+
24+
/**
25+
* Example which demonstrates the events API.
26+
*/
27+
public class EventsExample extends ExampleBase {
28+
public static void main(String[] args) {
29+
try {
30+
new EventsExample().run();
31+
} catch (Exception e) {
32+
e.printStackTrace();
33+
System.exit(1);
34+
}
35+
}
36+
37+
private void run() throws Exception {
38+
String topicsData = "I am looking for flights to Super Bowl 2022 in Inglewood, LA.";
39+
HttpRosetteAPI rosetteApi = new HttpRosetteAPI.Builder()
40+
.key(getApiKeyFromSystemProperty())
41+
.url(getAltUrlFromSystemProperty())
42+
.build();
43+
DocumentRequest<EventsOptions> request = DocumentRequest.<EventsOptions>builder()
44+
.language(LanguageCode.ENGLISH)
45+
.content(topicsData)
46+
.build();
47+
EventsResponse resp = rosetteApi.perform(HttpRosetteAPI.EVENTS_SERVICE_PATH, request, EventsResponse.class);
48+
System.out.println(responseToJson(resp));
49+
}
50+
}

json/src/test/java/com/basistech/rosette/apimodel/PolymorphicRequestTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ public void init() {
3636
@Test
3737
public void testRequestTypes() throws Exception {
3838
String json = "{\"content\": \"what is my type\", \"language\": \"eng\", \"options\": {\"calculateConfidence\": true}}";
39-
Request request = mapper.readValue(json, new TypeReference<DocumentRequest<EntitiesOptions>>() { });
39+
Request request = mapper.readValue(json, new TypeReference<DocumentRequest<EventsOptions>>() { });
40+
assertTrue(request instanceof DocumentRequest);
41+
42+
json = "{\"content\": \"what is my type\", \"language\": \"eng\", \"options\": {\"calculateConfidence\": true}}";
43+
request = mapper.readValue(json, new TypeReference<DocumentRequest<EntitiesOptions>>() { });
4044
assertTrue(request instanceof DocumentRequest);
4145

4246
json = "{\"content\": \"what is my type\", \"language\": \"eng\", \"options\": {\"includeDBpediaType\": true, \"calculateConfidence\": true}}";
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2021 Basis Technology Corp.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.basistech.rosette.apimodel;
18+
19+
import com.basistech.rosette.annotations.JacksonMixin;
20+
import lombok.Builder;
21+
import lombok.Value;
22+
23+
import java.util.List;
24+
25+
/**
26+
* Event
27+
*/
28+
@Value
29+
@Builder
30+
@JacksonMixin
31+
public class Event {
32+
33+
/**
34+
* @return the event type
35+
*/
36+
private final String type;
37+
38+
/**
39+
* @return the confidence score for the event (0.0-1.0)
40+
*/
41+
private final Double confidence;
42+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2021 Basis Technology Corp.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.basistech.rosette.apimodel;
18+
19+
import com.basistech.rosette.annotations.JacksonMixin;
20+
import lombok.Builder;
21+
import lombok.Value;
22+
23+
/**
24+
* Events options
25+
*/
26+
@Value
27+
@Builder
28+
@JacksonMixin
29+
public class EventsOptions extends Options {
30+
/**
31+
* Default options
32+
*/
33+
public static final EventsOptions DEFAULT = EventsOptions.builder()
34+
.calculateConfidence(false)
35+
.modelType("stubModel")
36+
.build();
37+
38+
/**
39+
* @return the calculateConfidence flag.
40+
*/
41+
private final Boolean calculateConfidence;
42+
43+
/**
44+
* @return the modelType to use.
45+
*/
46+
private final String modelType;
47+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2021 Basis Technology Corp.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.basistech.rosette.apimodel;
18+
19+
import com.basistech.rosette.annotations.JacksonMixin;
20+
import lombok.Builder;
21+
import lombok.EqualsAndHashCode;
22+
import lombok.Getter;
23+
24+
import java.util.List;
25+
26+
/**
27+
* Simple api response data model for events
28+
*/
29+
@Getter
30+
@EqualsAndHashCode
31+
@Builder
32+
@JacksonMixin
33+
public final class EventsResponse extends Response {
34+
35+
/**
36+
* @return the list of events
37+
*/
38+
private final List<Event> events;
39+
}

0 commit comments

Comments
 (0)