use of com.google.cloud.datalabeling.v1beta1.Dataset in project java-datalabeling by googleapis.
the class CreateInstruction method createInstruction.
// Create a instruction for a dataset.
static void createInstruction(String projectId, String pdfUri) throws IOException {
// String projectId = "YOUR_PROJECT_ID";
// String pdfUri = "gs://YOUR_BUCKET_ID/path_to_pdf_or_csv";
// [END datalabeling_create_instruction_beta]
String endpoint = System.getenv("DATALABELING_ENDPOINT");
if (endpoint == null) {
endpoint = DataLabelingServiceSettings.getDefaultEndpoint();
}
// [START datalabeling_create_instruction_beta]
DataLabelingServiceSettings settings = DataLabelingServiceSettings.newBuilder().setEndpoint(endpoint).build();
try (DataLabelingServiceClient dataLabelingServiceClient = DataLabelingServiceClient.create(settings)) {
ProjectName projectName = ProjectName.of(projectId);
// There are two types of instructions: CSV (CsvInstruction) or PDF (PdfInstruction)
PdfInstruction pdfInstruction = PdfInstruction.newBuilder().setGcsFileUri(pdfUri).build();
Instruction instruction = Instruction.newBuilder().setDisplayName("YOUR_INSTRUCTION_DISPLAY_NAME").setDescription("YOUR_DESCRIPTION").setDataType(// DataTypes: AUDIO, IMAGE, VIDEO, TEXT
DataType.IMAGE).setPdfInstruction(// .setCsvInstruction() or .setPdfInstruction()
pdfInstruction).build();
CreateInstructionRequest createInstructionRequest = CreateInstructionRequest.newBuilder().setInstruction(instruction).setParent(projectName.toString()).build();
OperationFuture<Instruction, CreateInstructionMetadata> operation = dataLabelingServiceClient.createInstructionAsync(createInstructionRequest);
Instruction result = operation.get();
System.out.format("Name: %s\n", result.getName());
System.out.format("DisplayName: %s\n", result.getDisplayName());
System.out.format("Description: %s\n", result.getDescription());
System.out.format("GCS SOURCE URI: %s\n", result.getPdfInstruction().getGcsFileUri());
} catch (IOException | InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
use of com.google.cloud.datalabeling.v1beta1.Dataset in project java-datalabeling by googleapis.
the class ITSystemTest method beforeClass.
@BeforeClass
public static void beforeClass() throws Exception {
client = DataLabelingServiceClient.create();
/**
* create Dataset
*/
Dataset dataSetResponse = client.createDataset(PARENT, DATASET);
dataSetId = dataSetResponse.getName().split("/")[3];
LOGGER.info("Dataset created successfully.");
/**
* create AnnotationSpecSet
*/
Map<String, String> annotationLabels = new HashMap<>();
annotationLabels.put(LABEL_1, DESCRIPTION1);
annotationLabels.put(LABEL_2, DESCRIPTION2);
List<AnnotationSpec> annotationSpecs = new ArrayList<>();
for (Map.Entry<String, String> entry : annotationLabels.entrySet()) {
AnnotationSpec annotationSpec = AnnotationSpec.newBuilder().setDisplayName(entry.getKey()).setDescription(entry.getValue()).build();
annotationSpecs.add(annotationSpec);
}
AnnotationSpecSet annotationSpecSet = AnnotationSpecSet.newBuilder().setDisplayName(ANNOTATION_SPEC_SET).setDescription(DESCRIPTION).addAllAnnotationSpecs(annotationSpecs).build();
AnnotationSpecSet response = client.createAnnotationSpecSet(PARENT, annotationSpecSet);
annotationSpecSetId = response.getName().split("/")[3];
LOGGER.info("AnnotationSpecSet created successfully.");
}
use of com.google.cloud.datalabeling.v1beta1.Dataset in project java-datalabeling by googleapis.
the class ITSystemTest method getDatasetTest.
@Test
public void getDatasetTest() {
String dataset = DatasetName.format(PROJECT_ID, dataSetId);
Dataset response = client.getDataset(dataset);
assertEquals(DATASET_DISPLAY_NAME, response.getDisplayName());
assertEquals(DESCRIPTION, response.getDescription());
}
use of com.google.cloud.datalabeling.v1beta1.Dataset in project java-datalabeling by googleapis.
the class DataLabelingServiceClientTest method listDatasetsTest.
@Test
public void listDatasetsTest() throws Exception {
Dataset responsesElement = Dataset.newBuilder().build();
ListDatasetsResponse expectedResponse = ListDatasetsResponse.newBuilder().setNextPageToken("").addAllDatasets(Arrays.asList(responsesElement)).build();
mockDataLabelingService.addResponse(expectedResponse);
ProjectName parent = ProjectName.of("[PROJECT]");
String filter = "filter-1274492040";
ListDatasetsPagedResponse pagedListResponse = client.listDatasets(parent, filter);
List<Dataset> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getDatasetsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockDataLabelingService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListDatasetsRequest actualRequest = ((ListDatasetsRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertEquals(filter, actualRequest.getFilter());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.datalabeling.v1beta1.Dataset in project java-datalabeling by googleapis.
the class DataLabelingServiceClientTest method listDatasetsTest2.
@Test
public void listDatasetsTest2() throws Exception {
Dataset responsesElement = Dataset.newBuilder().build();
ListDatasetsResponse expectedResponse = ListDatasetsResponse.newBuilder().setNextPageToken("").addAllDatasets(Arrays.asList(responsesElement)).build();
mockDataLabelingService.addResponse(expectedResponse);
String parent = "parent-995424086";
String filter = "filter-1274492040";
ListDatasetsPagedResponse pagedListResponse = client.listDatasets(parent, filter);
List<Dataset> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getDatasetsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockDataLabelingService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListDatasetsRequest actualRequest = ((ListDatasetsRequest) actualRequests.get(0));
Assert.assertEquals(parent, actualRequest.getParent());
Assert.assertEquals(filter, actualRequest.getFilter());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Aggregations