Completed
Push — master ( 980041...30b693 )
by
unknown
10s
created

ModelOutput.__init__()   C

Complexity

Conditions 8

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 19
rs 6.6666
cc 8
1
class ModelOutput(object):
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
    """Abstract base class for topic models.
3
4
    Ensures consistent interface across models, for base result display capabilities.
5
6
    Attributes
7
    ----------
8
    _doc_topic_matrix : mapping of document ids to weights for topic indices
9
                        matrix storing the relative topic weights for each document
10
    _topic_term_matrix : mapping of terms to each topic
11
    """
12
    def __init__(self, vectorized_corpus=None, model_func=None,
13
                 vocab=None, term_frequency=None, topic_term_matrix=None,
14
                 doc_lengths=None, doc_topic_matrix=None, **kwargs):
15
        if vectorized_corpus and model_func:
16
            self._vocab = vectorized_corpus.id_term_map
17
            self._doc_lengths = vectorized_corpus.doc_lengths
18
            self._term_frequency = vectorized_corpus.term_frequency
19
            self._topic_term_matrix, self._doc_topic_matrix = model_func(
20
                                                    vectorized_corpus, **kwargs)
21
22
        elif (vocab and term_frequency and topic_term_matrix and doc_lengths and
23
                     doc_topic_matrix):
24
            self._vocab = vocab
25
            self._term_frequency = term_frequency
26
            self._topic_term_matrix = topic_term_matrix
27
            self._doc_lengths = doc_lengths
28
            self._doc_topic_matrix = doc_topic_matrix
29
        else:
30
            raise ValueError("Must provide either vectorized corpus and model func, "
31
                             "or term data and doc data.")
32
33
    @property
34
    def vocab(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
35
        return self._vocab
36
37
    @property
38
    def term_frequency(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
39
        return self._term_frequency
40
41
    @property
42
    def topic_term_matrix(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
43
        return self._topic_term_matrix
44
45
    @property
46
    def doc_lengths(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
47
        return self._doc_lengths
48
49
    @property
50
    def doc_topic_matrix(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
51
        return self._doc_topic_matrix
52
53
54