Skip to content

Instantly share code, notes, and snippets.

@DanishAmjad12
Created August 17, 2021 05:24
Show Gist options
  • Save DanishAmjad12/67ddd75449c641d605e0af0fea135312 to your computer and use it in GitHub Desktop.
Save DanishAmjad12/67ddd75449c641d605e0af0fea135312 to your computer and use it in GitHub Desktop.
entityExtractor
.downloadModelIfNeeded()
.addOnSuccessListener { _ ->
//step3
val params =
EntityExtractionParams.Builder("My flight is LX373")
.build()
entityExtractor
.annotate(params)
.addOnSuccessListener {
//step4
for (entityAnnotation in it) {
val entities: List<Entity> = entityAnnotation.entities
Log.d("VALUE", "Range: ${entityAnnotation.start} - ${entityAnnotation.end}")
for (entity in entities) {
when (entity) {
is DateTimeEntity -> {
result.text="Granularity: ${entity.dateTimeGranularity} \n TimeStamp: ${entity.timestampMillis}"
Log.d("VALUE", "Granularity: ${entity.dateTimeGranularity}")
Log.d("VALUE", "TimeStamp: ${entity.timestampMillis}")
}
is FlightNumberEntity -> {
result.text= "Airline Code: ${entity.airlineCode} \nFlight number: ${entity.flightNumber}"
Log.d("VALUE", "Airline Code: ${entity.airlineCode}")
Log.d("VALUE", "Flight number: ${entity.flightNumber}")
}
else -> {
Log.d("VALUE", " $entity")
}
}
}
}
}
.addOnFailureListener {
// Check failure message here.
}
}
.addOnFailureListener { _ -> /* Model downloading failed. */ }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment