import pandas as pd


class DummyClassifier:

    """
    Dummy classifier. The class applied is that which occurs most frequently in
    the dataset.

    Created for testing purposes only; would probably break in current pipeline structure.

    Parameters
    ----------

    target : string
        Defines the target that we aim to classify. Defaults to "review_group".

    classes : list
        Defines the classes of the target.

    """

    def __init__(self, target="inregister", classes=[]):

        self.model = None
        self.target = target
        self.classes = classes

    def train(self, train_papers, labels):

        """
        Training of the classifier. Extracts the most-frequently
        occurring target from the dataset, and saves this as the model.

        Parameters
        ----------

        train_papers : DataFrame where each row represents a paper. Required to
        have a column with name identical to the target defined in the model
        initialization (default is "review_group").

        """

        most_occurring = labels[self.target].mode()[0]

        self.model = most_occurring

    def predict(self, papers):

        """
        Generates predictions from the trained classifier.

        Parameters
        ----------
        papers : DataFrame
            Each row should represent one paper.

        Returns
        -------
        predictions : list
            Predictions generated by the model, one for each paper that
            was provided in papers.

        """

        # do classification according to model
        papers['classification'] = self.model

        # convert to categorical column
        papers['classification'] = papers['classification'].astype('category', categories=self.classes)

        # save as dummy columns
        predictions = pd.get_dummies(papers['classification'])

        return predictions
