use of com.google.cloud.datalabeling.v1beta1.LabelTextRequest in project java-datalabeling by googleapis.
the class LabelText method labelText.
// Start a Text Labeling Task
static void labelText(String formattedInstructionName, String formattedAnnotationSpecSetName, String formattedDatasetName) throws IOException {
// String formattedInstructionName = DataLabelingServiceClient.formatInstructionName(
// "YOUR_PROJECT_ID", "YOUR_INSTRUCTION_UUID");
// String formattedAnnotationSpecSetName =
// DataLabelingServiceClient.formatAnnotationSpecSetName(
// "YOUR_PROJECT_ID", "YOUR_ANNOTATION_SPEC_SET_UUID");
// String formattedDatasetName = DataLabelingServiceClient.formatDatasetName(
// "YOUR_PROJECT_ID", "YOUR_DATASET_UUID");
// [END datalabeling_label_text_beta]
String endpoint = System.getenv("DATALABELING_ENDPOINT");
if (endpoint == null) {
endpoint = DataLabelingServiceSettings.getDefaultEndpoint();
}
// [START datalabeling_label_text_beta]
DataLabelingServiceSettings settings = DataLabelingServiceSettings.newBuilder().setEndpoint(endpoint).build();
try (DataLabelingServiceClient dataLabelingServiceClient = DataLabelingServiceClient.create(settings)) {
HumanAnnotationConfig humanAnnotationConfig = HumanAnnotationConfig.newBuilder().setAnnotatedDatasetDisplayName("annotated_displayname").setAnnotatedDatasetDescription("annotated_description").setLanguageCode("en-us").setInstruction(formattedInstructionName).build();
SentimentConfig sentimentConfig = SentimentConfig.newBuilder().setEnableLabelSentimentSelection(false).build();
TextClassificationConfig textClassificationConfig = TextClassificationConfig.newBuilder().setAnnotationSpecSet(formattedAnnotationSpecSetName).setSentimentConfig(sentimentConfig).build();
LabelTextRequest labelTextRequest = LabelTextRequest.newBuilder().setParent(formattedDatasetName).setBasicConfig(humanAnnotationConfig).setTextClassificationConfig(textClassificationConfig).setFeature(Feature.TEXT_CLASSIFICATION).build();
OperationFuture<AnnotatedDataset, LabelOperationMetadata> operation = dataLabelingServiceClient.labelTextAsync(labelTextRequest);
// You'll want to save this for later to retrieve your completed operation.
// System.out.format("Operation Name: %s\n", operation.getName());
// Cancel the operation to avoid charges when testing.
dataLabelingServiceClient.getOperationsClient().cancelOperation(operation.getName());
} catch (IOException | InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
Aggregations