def test_build(self): ReviewModality(data=[]).build(uid_map=self.uid_map, iid_map=self.iid_map, dok_matrix=self.dok_matrix) ReviewModality(data=self.review_data, filter_by='user').build(uid_map=self.uid_map, iid_map=self.iid_map, dok_matrix=self.dok_matrix) ReviewModality(data=self.review_data, filter_by='item').build(uid_map=self.uid_map, iid_map=self.iid_map, dok_matrix=self.dok_matrix) try: ReviewModality().build() except ValueError: assert True
def test_with_modalities(self): data = Reader().read("./tests/data.txt") sentiment_data = Reader().read("./tests/sentiment_data.txt", fmt="UITup", sep=",", tup_sep=":") review_data = Reader().read("./tests/review.txt", fmt="UIReview") bm = BaseMethod.from_splits(train_data=data[:-1], test_data=data[-1:]) self.assertIsNone(bm.user_text) self.assertIsNone(bm.item_text) self.assertIsNone(bm.user_image) self.assertIsNone(bm.item_image) self.assertIsNone(bm.user_graph) self.assertIsNone(bm.item_graph) self.assertIsNone(bm.sentiment) bm.user_text = TextModality() bm.item_text = ReviewModality(data=review_data, filter_by='item') bm.item_image = ImageModality() bm.sentiment = SentimentModality(data=sentiment_data) bm._build_modalities() try: bm.user_text = ImageModality() except ValueError: assert True try: bm.item_text = ImageModality() except ValueError: assert True try: bm.user_image = TextModality() except ValueError: assert True try: bm.item_image = TextModality() except ValueError: assert True try: bm.user_graph = TextModality() except ValueError: assert True try: bm.item_graph = ImageModality() except ValueError: assert True try: bm.sentiment = TextModality() except ValueError: assert True try: bm.sentiment = ImageModality() except ValueError: assert True
# limitations under the License. # ============================================================================ import cornac from cornac.data import Reader from cornac.datasets import amazon_digital_music from cornac.eval_methods import RatioSplit from cornac.data import ReviewModality from cornac.data.text import BaseTokenizer feedback = amazon_digital_music.load_feedback() reviews = amazon_digital_music.load_review() review_modality = ReviewModality( data=reviews, tokenizer=BaseTokenizer(stop_words="english"), max_vocab=4000, max_doc_freq=0.5, ) ratio_split = RatioSplit( data=feedback, test_size=0.1, val_size=0.1, exclude_unknowns=True, review_text=review_modality, verbose=True, seed=123, ) pretrained_word_embeddings = {} # You can load pretrained word embedding here
def test_init(self): try: ReviewModality(filter_by='something') except ValueError: assert True