Skip to content

Commit fa9e089

Browse files
author
Kyle Bridburg
authored
AISDK-191: Add topic extraction client (#43)
1 parent f261dca commit fa9e089

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1606
-60
lines changed

examples/AsyncTranscribeLocalMediaFile.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package ai.rev.speechtotext;
1+
package ai.rev;
22

33
import ai.rev.speechtotext.models.asynchronous.RevAiCaptionType;
44
import ai.rev.speechtotext.models.asynchronous.RevAiJob;

examples/AsyncTranscribeMediaUrl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package ai.rev.speechtotext;
1+
package ai.rev;
22

33
import ai.rev.speechtotext.models.asynchronous.RevAiCaptionType;
44
import ai.rev.speechtotext.models.asynchronous.RevAiJob;

examples/CustomVocabularies.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package ai.rev.speechtotext;
1+
package ai.rev;
22

33
import ai.rev.speechtotext.models.vocabulary.CustomVocabulary;
44
import ai.rev.speechtotext.models.vocabulary.CustomVocabularyInformation;

examples/StreamingFromLocalFile.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package ai.rev.speechtotext;
1+
package ai.rev;
22

33
import ai.rev.speechtotext.models.streaming.ConnectedMessage;
44
import ai.rev.speechtotext.models.streaming.Hypothesis;

examples/TopicExtraction.java

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package ai.rev;
2+
3+
import ai.rev.topicextraction.models.TopicExtractionJobOptions;
4+
import ai.rev.topicextraction.models.TopicExtractionJob;
5+
import ai.rev.topicextraction.models.TopicExtractionJobStatus;
6+
import ai.rev.topicextraction.models.TopicExtractionResult;
7+
import ai.rev.topicextraction.TopicExtractionClient;
8+
9+
import java.io.IOException;
10+
import java.util.Arrays;
11+
12+
public class TopicExtraction {
13+
14+
public static void main(String[] args) {
15+
// Assign your access token to a String
16+
String accessToken = "your_access_token";
17+
18+
// Initialize the TopicExtractionClient with your access token
19+
TopicExtractionClient topicExtractionClient = new TopicExtractionClient(accessToken);
20+
21+
// Create TopicExtractionJobOptions for your submission
22+
TopicExtractionJobOptions jobOptions = new TopicExtractionJobOptions();
23+
String textSubmission = "An orange is a fruit of various citrus species in the family Rutaceae " +
24+
"it primarily refers to Citrus sinensis which is also called sweet orange, " +
25+
"to distinguish it from the related Citrus aurantium, referred to as bitter orange. " +
26+
"The sweet orange reproduces asexually. varieties of sweet orange arise through mutations. " +
27+
"The orange is a hybrid between pomelo (Citrus maxima) and mandarin (Citrus reticulata). " +
28+
"The chloroplast genome, and therefore the maternal line, is that of pomelo. " +
29+
"The sweet orange has had its full genome sequenced.";
30+
31+
32+
TopicExtractionJob submittedJob;
33+
try {
34+
submittedJob = topicExtractionClient.submitJobText(textSubmission, jobOptions);
35+
} catch (IOException e) {
36+
throw new RuntimeException("Failed to submit topic extraction job " + e.getMessage());
37+
}
38+
39+
String jobId = submittedJob.getJobId();
40+
System.out.println("Job Id: " + jobId);
41+
System.out.println("Job Status: " + submittedJob.getJobStatus());
42+
System.out.println("Created On: " + submittedJob.getCreatedOn());
43+
44+
// Waits 5 seconds between each status check to see if job is complete
45+
boolean isProcessingComplete = false;
46+
while (!isProcessingComplete) {
47+
TopicExtractionJob retrievedJob;
48+
try {
49+
retrievedJob = topicExtractionClient.getJobDetails(jobId);
50+
} catch (IOException e) {
51+
throw new RuntimeException(
52+
"Failed to retrieve topic extraction job info ["
53+
+ jobId
54+
+ "] "
55+
+ e.getMessage());
56+
}
57+
58+
TopicExtractionJobStatus status = retrievedJob.getJobStatus();
59+
if (status == TopicExtractionJobStatus.COMPLETED
60+
|| status == TopicExtractionJobStatus.FAILED) {
61+
System.out.println(
62+
"Processing for "
63+
+ jobId
64+
+ ": "
65+
+ status);
66+
isProcessingComplete = true;
67+
} else {
68+
try {
69+
Thread.sleep(5000);
70+
} catch (InterruptedException e) {
71+
e.printStackTrace();
72+
}
73+
}
74+
}
75+
76+
try {
77+
TopicExtractionResult result =
78+
topicExtractionClient.getResultObject(jobId);
79+
} catch (IOException e) {
80+
e.printStackTrace();
81+
}
82+
83+
/*
84+
* The job can now be deleted. Deleting the job will remove ALL information
85+
* about the job from the Rev AI servers. Subsequent requests to Rev AI that
86+
* use the deleted jobs Id will return 404's.
87+
*/
88+
// apiClient.deleteJob(jobId);
89+
}
90+
}

pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
44
<modelVersion>4.0.0</modelVersion>
5-
<groupId>ai.rev.speechtotext</groupId>
6-
<artifactId>revai-java-sdk-speechtotext</artifactId>
7-
<version>1.4.0</version>
8-
<name>Rev AI speech to text SDK for Java</name>
9-
<description>Java SDK for Rev AI speech to text API</description>
5+
<groupId>ai.rev</groupId>
6+
<artifactId>revai-java-sdk</artifactId>
7+
<version>2.0.0</version>
8+
<name>Rev AI SDK for Java</name>
9+
<description>Java SDK for Rev AI API</description>
1010
<url>https://docs.rev.ai/</url>
1111
<licenses>
1212
<license>

src/main/java/ai/rev/speechtotext/exceptions/AuthorizationException.java renamed to src/main/java/ai/rev/exceptions/AuthorizationException.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
package ai.rev.speechtotext.exceptions;
1+
package ai.rev.exceptions;
22

33
import org.json.JSONObject;
44

55
/**
6-
* The AuthorizationException happens when an invalid token access is used to query the account
7-
* information endpoint.
6+
* The AuthorizationException happens when an invalid token access is used to query any
7+
* endpoint.
88
*/
99
public class AuthorizationException extends RevAiApiException {
1010

src/main/java/ai/rev/speechtotext/exceptions/ForbiddenStateException.java renamed to src/main/java/ai/rev/exceptions/ForbiddenStateException.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
package ai.rev.speechtotext.exceptions;
1+
package ai.rev.exceptions;
22

33
import org.json.JSONObject;
44

55
/**
6-
* The ForbiddenStateException occurs when a user attempts to retrieve the transcript or caption of
7-
* a unprocessed job.
6+
* The ForbiddenStateException occurs when a user attempts to retrieve the result of
7+
* an unprocessed job.
88
*/
99
public class ForbiddenStateException extends RevAiApiException {
1010

src/main/java/ai/rev/speechtotext/exceptions/InvalidHeaderException.java renamed to src/main/java/ai/rev/exceptions/InvalidHeaderException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package ai.rev.speechtotext.exceptions;
1+
package ai.rev.exceptions;
22

33
import org.json.JSONObject;
44

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package ai.rev.speechtotext.exceptions;
1+
package ai.rev.exceptions;
22

33
import org.json.JSONObject;
44

0 commit comments

Comments
 (0)