Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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