populate_db: Generate topics using config fixture.

Instread of using stream_name + Intergers as topics, we now
generate topics using pos in `config.generate_data.json`.

This helps us create and test more realistic topics.
This commit is contained in:
Aman Agrawal
2020-05-05 11:25:47 +05:30
committed by Tim Abbott
parent 28375e82c5
commit a4495dbc6b
2 changed files with 30 additions and 3 deletions

View File

@@ -12,6 +12,29 @@ def load_config() -> Dict[str, Any]:
return config
def generate_topics(num_topics: int) -> List[str]:
config = load_config()["gen_fodder"]
topics = []
# Make single word topics account for 30% of total topics.
# Single word topics are most common, thus
# it is important we test on it.
num_single_word_topics = num_topics // 3
for _ in itertools.repeat(None, num_single_word_topics):
topics.append(random.choice(config["nouns"]))
sentence = ["adjectives", "nouns", "connectors", "verbs", "adverbs"]
for pos in sentence:
# Add an empty string so that we can generate variable length topics.
config[pos].append("")
for _ in itertools.repeat(None, num_topics - num_single_word_topics):
generated_topic = [random.choice(config[pos]) for pos in sentence]
topic = " ".join(filter(None, generated_topic))
topics.append(topic)
return topics
def load_generators(config: Dict[str, Any]) -> Dict[str, Any]:
results = {}