@@ -462,17 +462,21 @@ func topicDetectionPrintFormatted(categories IabCategoriesResult, width int) {
462462 table .Wrap = true
463463 table .MaxColWidth = uint ((width / 2 ) - 5 )
464464 table .Separator = "|"
465- table .AddRow ("TOPIC" , "TEXT" )
466- for _ , category := range categories .Results {
467- categories := ""
468- for i , innerCategory := range category .Labels {
469- categories += innerCategory .Label + " "
470- if i == 2 {
471- break
472- }
465+ table .AddRow ("RANK" , "TOPIC" )
466+ var ArrayCategoriesSorted []ArrayCategories
467+ for category , i := range categories .Summary {
468+ add := ArrayCategories {
469+ Category : category ,
470+ Score : i ,
473471 }
474- table .AddRow (categories , category .Text )
475- table .AddRow ("" , "" )
472+ ArrayCategoriesSorted = append (ArrayCategoriesSorted , add )
473+ }
474+ sort .SliceStable (ArrayCategoriesSorted , func (i , j int ) bool {
475+ return ArrayCategoriesSorted [i ].Score > ArrayCategoriesSorted [j ].Score
476+ })
477+
478+ for i , category := range ArrayCategoriesSorted {
479+ table .AddRow (i + 1 , category .Category )
476480 }
477481 fmt .Println (table )
478482 fmt .Println ()
@@ -551,3 +555,8 @@ func entityDetectionPrintFormatted(entities []Entity, width int) {
551555 fmt .Println (table )
552556 fmt .Println ()
553557}
558+
559+ type ArrayCategories struct {
560+ Score float64 `json:"score"`
561+ Category string `json:"category"`
562+ }
0 commit comments