예제 #1
0
    def test_get_module_alias(self):
        """
        Test that when loading the module and it starts with an alias, it is replaced.
        """

        self.assertEqual(
            'nlp.weighting.tfidf',
            Exportable.get_module("<class 'nlp.term_weighting.tfidf.TFIDF'>"))
예제 #2
0
    def test_get_module(self):
        """
        Test getting the module name from a string.
        """

        self.assertEqual(
            'nlp.document',
            Exportable.get_module("<class 'nlp.document.Document'>"))
예제 #3
0
    def from_array(array):
        """
        Create a :class:`~vsm.clustering.cluster.Cluster` instance from the given associative array.

        :param array: The associative array with the attributes to create the cluster.
        :type array: dict

        :return: A new instance of an object with the same attributes stored in the object.
        :rtype: :class:`~vsm.clustering.cluster.Cluster`
        """

        vectors = []
        for vector in array.get('vectors'):
            module = importlib.import_module(
                Exportable.get_module(vector.get('class')))
            cls = getattr(module, Exportable.get_class(vector.get('class')))
            vectors.append(cls.from_array(vector))

        return Cluster(vectors=vectors, attributes=array.get('attributes'))
예제 #4
0
    def test_get_module_class_only(self):
        """
        Test that when getting the module name from a string that contains only a class name, nothing is returned.
        """

        self.assertEqual('', Exportable.get_module("<class 'Document'>"))