Consider depict's P18 when suggesting categories

This commit is contained in:
savsch 2025-01-14 23:05:27 +05:30
parent d59adcd588
commit aab79a5e3e

View file

@ -127,30 +127,64 @@ class CategoriesModel
/** /**
* Fetches details of every category associated with selected depictions, converts them into * Fetches details of every category associated with selected depictions, converts them into
* CategoryItem and returns them in a list. * CategoryItem and returns them in a list.
* If a selected depiction has no categories, the categories in which its P18 belongs are
* returned in the list.
* *
* @param selectedDepictions selected DepictItems * @param selectedDepictions selected DepictItems
* @return List of CategoryItem associated with selected depictions * @return List of CategoryItem associated with selected depictions
*/ */
private fun categoriesFromDepiction(selectedDepictions: List<DepictedItem>): Observable<MutableList<CategoryItem>>? = private fun categoriesFromDepiction(selectedDepictions: List<DepictedItem>): Observable<MutableList<CategoryItem>>? {
Observable val observables = selectedDepictions.map { depictedItem ->
.fromIterable( if (depictedItem.commonsCategories.isEmpty()) {
selectedDepictions.map { it.commonsCategories }.flatten(), if (depictedItem.primaryImage == null) {
).map { categoryItem -> return@map Observable.just(emptyList<CategoryItem>())
categoryClient }
.getCategoriesByName( Observable.just(
categoryItem.name, depictedItem.primaryImage
categoryItem.name, ).map { image ->
SEARCH_CATS_LIMIT, categoryClient
).map { .getCategoriesOfImage(
CategoryItem( image,
it[0].name, SEARCH_CATS_LIMIT,
it[0].description, ).map {
it[0].thumbnail, it.map { category ->
it[0].isSelected, CategoryItem(
) category.name,
}.blockingGet() category.description,
}.toList() category.thumbnail,
.toObservable() category.isSelected,
)
}
}.blockingGet()
}.flatMapIterable { it }.toList()
.toObservable()
} else {
Observable
.fromIterable(
depictedItem.commonsCategories,
).map { categoryItem ->
categoryClient
.getCategoriesByName(
categoryItem.name,
categoryItem.name,
SEARCH_CATS_LIMIT,
).map {
CategoryItem(
it[0].name,
it[0].description,
it[0].thumbnail,
it[0].isSelected,
)
}.blockingGet()
}.toList()
.toObservable()
}
}
return Observable.concat(observables)
.scan(mutableListOf<CategoryItem>()) { accumulator, currentList ->
accumulator.apply { addAll(currentList) }
}
}
/** /**
* Fetches details of every category by their name, converts them into * Fetches details of every category by their name, converts them into