@java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } if (!(obj instanceof com.google.cloud.language.v1beta2.ClassificationCategory)) { return super.equals(obj); } com.google.cloud.language.v1beta2.ClassificationCategory other = (com.google.cloud.language.v1beta2.ClassificationCategory) obj; boolean result = true; result = result && getName().equals(other.getName()); result = result && (java.lang.Float.floatToIntBits(getConfidence()) == java.lang.Float.floatToIntBits(other.getConfidence())); result = result && unknownFields.equals(other.unknownFields); return result; }
@java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptor().hashCode(); hash = (37 * hash) + NAME_FIELD_NUMBER; hash = (53 * hash) + getName().hashCode(); hash = (37 * hash) + CONFIDENCE_FIELD_NUMBER; hash = (53 * hash) + java.lang.Float.floatToIntBits(getConfidence()); hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }
public Builder mergeFrom(com.google.cloud.language.v1beta2.ClassificationCategory other) { if (other == com.google.cloud.language.v1beta2.ClassificationCategory.getDefaultInstance()) return this; if (!other.getName().isEmpty()) { name_ = other.name_; onChanged(); } if (other.getConfidence() != 0F) { setConfidence(other.getConfidence()); } this.mergeUnknownFields(other.unknownFields); onChanged(); return this; }
/** * Detects categories in text using the Language Beta API. */ public static void classifyText(String text) throws Exception { // [START classify_text] // 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] }
/** * Detects categories in a GCS hosted file using the Language Beta API. */ public static void classifyFile(String gcsUri) throws Exception { // [START classify_file] // 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] } }