def _validate_topic_similarities(cls, item): """Validate the topic similarities to be symmetric and have real values between 0.0 and 1.0. Args: item: datastore_services.Model. TopicSimilaritiesModel to validate. """ content = json.loads(item.content) all_topics = list(content.keys()) data = '%s\n' % ','.join(all_topics) for topics_to_compare in all_topics: similarity_list = [] for topic in content[topics_to_compare]: similarity_list.append( python_utils.UNICODE(content[topics_to_compare][topic])) if len(similarity_list): data = data + '%s\n' % ','.join(similarity_list) try: recommendations_services.validate_topic_similarities(data) except Exception as e: cls._add_error( 'topic similarity check', 'Entity id %s: Topic similarity validation for content: %s ' 'fails with error: %s' % (item.id, content, e))
def test_validate_default_similarities(self): recommendations_services.validate_topic_similarities( recommendations_services.DEFAULT_TOPIC_SIMILARITIES_STRING)