mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
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:
@@ -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 = {}
|
||||
|
||||
Reference in New Issue
Block a user