use v6.d;

use lib <. lib>;

use ML::StreamsBlendingRecommender::CoreSBR;
use Data::Reshapers;

use Test;

plan 6;

##-----------------------------------------------------------
## Creation and ingestion
##-----------------------------------------------------------

my @dsTitanic = Data::Reshapers::get-titanic-dataset(headers => 'auto');

my ML::StreamsBlendingRecommender::CoreSBR $sbrObj .= new;

## 1
ok $sbrObj.make-tag-inverse-indexes-from-wide-form(
        @dsTitanic,
        tagTypes => @dsTitanic[0].keys.grep({ $_ ne 'id' }).Array,
        itemColumnName => <id>,
        :!addTagTypesToColumnNames).transpose-tag-inverse-indexes,
        'Ingest SMR matrix from CSV file';

## 2
is $sbrObj.take-tag-inverse-indexes.elems == 17, True,
        'Expected number of tags';

## 3
is $sbrObj.take-item-inverse-indexes.elems ≥ 1309, True,
        'Expected number of items';

##-----------------------------------------------------------
## Recommendations by profile
##-----------------------------------------------------------
my @prof = <male 3rd>;

## 4
ok $sbrObj.recommend-by-profile(@prof, 10, :normalize, :!object),
        'Recommend by profile';

## 5
my %recs = $sbrObj.recommend-by-profile(@prof, 10, :normalize, :!object);
ok %recs.elems == 10, 'recs.elems';


##-----------------------------------------------------------
## Classify by profile
##-----------------------------------------------------------

# I would like to have a check like this:
#
#       is-deeply %recs2, %(died => 38, survived => 12), 'recsIDF.elems';
#
# but the current normalization methods do not include normalizePerItem.
# Also,

## 6
my %recs2 = $sbrObj.classify-by-profile('passengerSurvival', @prof, n-top-nearest-neighbors => 50, :!normalize, :!object);
is %recs2<died> ≥ 2 * %recs2<survived>, True, 'Expected classification distribution';

done-testing;
