Skip to content

Instantly share code, notes, and snippets.

@Kashif-E
Created July 13, 2021 07:41
Show Gist options
  • Save Kashif-E/89bab13bb00d426802a70c450d15db72 to your computer and use it in GitHub Desktop.
Save Kashif-E/89bab13bb00d426802a70c450d15db72 to your computer and use it in GitHub Desktop.
entityExtractor
.annotate(params)
.addOnSuccessListener { entityAnnotation ->
for (entitiy in entityAnnotation) {
val listOfEntities = entitiy.entities
for (entity in listOfEntities) {
when (entity.type) {
Entity.TYPE_ADDRESS -> {
binding.textView.append("address " + entitiy.annotatedText + "\n")
}
Entity.TYPE_DATE_TIME -> {
binding.textView.append("date time " + entitiy.annotatedText + "\n")
}
Entity.TYPE_EMAIL -> {
binding.textView.append("email " + entitiy.annotatedText + "\n")
}
Entity.TYPE_FLIGHT_NUMBER -> {
binding.textView.append("flight number " + entitiy.annotatedText + "\n")
}
Entity.TYPE_IBAN -> {
binding.textView.append("Iban " + entitiy.annotatedText + "\n")
}
Entity.TYPE_ISBN -> {
binding.textView.append("isbn " + entitiy.annotatedText + "\n")
}
Entity.TYPE_MONEY -> {
binding.textView.append("money " + entitiy.annotatedText + "\n")
}
Entity.TYPE_PAYMENT_CARD -> {
binding.textView.append("payment card " + entitiy.annotatedText + "\n")
}
Entity.TYPE_PHONE -> {
binding.textView.append("phone " + entitiy.annotatedText + "\n")
}
Entity.TYPE_TRACKING_NUMBER -> {
binding.textView.append("tracking number " + entitiy.annotatedText + "\n")
}
Entity.TYPE_URL -> {
binding.textView.append("type url " + entitiy.annotatedText + "\n")
}
else -> {
binding.textView.append(entitiy.annotatedText + "\n")
}
}
}
}
}
.addOnFailureListener {
Toast.makeText(
requireContext(),
"Entity Extraction failed",
Toast.LENGTH_SHORT
).show()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment