use of com.google.cloud.language.v1.ClassificationCategory in project java-docs-samples by GoogleCloudPlatform.
the class AnalyzeBeta method classifyFile.
/**
* Detects categories in a GCS hosted file using the Language Beta API.
*/
public static void classifyFile(String gcsUri) throws Exception {
// Instantiate a beta client : com.google.cloud.language.v1beta2.LanguageServiceClient
try (LanguageServiceClient language = LanguageServiceClient.create()) {
// set the GCS content URI path
Document doc = Document.newBuilder().setGcsContentUri(gcsUri).setType(Type.PLAIN_TEXT).build();
ClassifyTextRequest request = ClassifyTextRequest.newBuilder().setDocument(doc).build();
// detect categories in the given file
ClassifyTextResponse response = language.classifyText(request);
for (ClassificationCategory category : response.getCategoriesList()) {
System.out.printf("Category name : %s, Confidence : %.3f\n", category.getName(), category.getConfidence());
}
}
// [END classify_file]
}
use of com.google.cloud.language.v1.ClassificationCategory in project java-docs-samples by GoogleCloudPlatform.
the class Analyze method classifyText.
/**
* Detects categories in text using the Language Beta API.
*/
public static void classifyText(String text) throws Exception {
// Instantiate the Language client com.google.cloud.language.v1.LanguageServiceClient
try (LanguageServiceClient language = LanguageServiceClient.create()) {
// set content to the text string
Document doc = Document.newBuilder().setContent(text).setType(Type.PLAIN_TEXT).build();
ClassifyTextRequest request = ClassifyTextRequest.newBuilder().setDocument(doc).build();
// detect categories in the given text
ClassifyTextResponse response = language.classifyText(request);
for (ClassificationCategory category : response.getCategoriesList()) {
System.out.printf("Category name : %s, Confidence : %.3f\n", category.getName(), category.getConfidence());
}
}
// [END classify_text]
}
use of com.google.cloud.language.v1.ClassificationCategory in project java-docs-samples by GoogleCloudPlatform.
the class Analyze method classifyFile.
/**
* Detects categories in a GCS hosted file using the Language Beta API.
*/
public static void classifyFile(String gcsUri) throws Exception {
// Instantiate the Language client com.google.cloud.language.v1.LanguageServiceClient
try (LanguageServiceClient language = LanguageServiceClient.create()) {
// set the GCS content URI path
Document doc = Document.newBuilder().setGcsContentUri(gcsUri).setType(Type.PLAIN_TEXT).build();
ClassifyTextRequest request = ClassifyTextRequest.newBuilder().setDocument(doc).build();
// detect categories in the given file
ClassifyTextResponse response = language.classifyText(request);
for (ClassificationCategory category : response.getCategoriesList()) {
System.out.printf("Category name : %s, Confidence : %.3f\n", category.getName(), category.getConfidence());
}
}
// [END classify_file]
}
use of com.google.cloud.language.v1.ClassificationCategory in project java-docs-samples by GoogleCloudPlatform.
the class AnalyzeBeta method classifyText.
/**
* Detects categories in text using the Language Beta API.
*/
public static void classifyText(String text) throws Exception {
// Instantiate a beta client : com.google.cloud.language.v1beta2.LanguageServiceClient
try (LanguageServiceClient language = LanguageServiceClient.create()) {
// set content to the text string
Document doc = Document.newBuilder().setContent(text).setType(Type.PLAIN_TEXT).build();
ClassifyTextRequest request = ClassifyTextRequest.newBuilder().setDocument(doc).build();
// detect categories in the given text
ClassifyTextResponse response = language.classifyText(request);
for (ClassificationCategory category : response.getCategoriesList()) {
System.out.printf("Category name : %s, Confidence : %.3f\n", category.getName(), category.getConfidence());
}
}
// [END classify_text]
}
Aggregations