Skip to content

Commit 0af6100

Browse files
committed
Allow count_phrase analyzer to accept more than one phrase
1 parent 0751b0f commit 0af6100

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

ica/analyzers/count_phrase.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,27 @@
1010
def main() -> None:
1111

1212
cli_args = ica.get_cli_args()
13-
phrase = cli_args.args[0]
14-
if not phrase:
15-
raise Exception("Phrase to count must be provided")
13+
phrases = cli_args.args
14+
if not phrases:
15+
raise Exception("Must provide at least one phrase to count")
1616
dfs = ica.get_dataframes(
1717
contact_name=cli_args.contact_name, timezone=cli_args.timezone
1818
)
1919
filtered_messages = dfs.messages[~dfs.messages["is_reaction"]]
20-
count = filtered_messages["text"].str.count(phrase, flags=re.IGNORECASE).sum()
2120
ica.output_results(
22-
(pd.DataFrame({"phrase": (phrase,), "count": (count,)}).set_index("phrase")),
21+
(
22+
pd.DataFrame(
23+
{
24+
"phrase": phrases,
25+
"count": (
26+
filtered_messages["text"]
27+
.str.count(phrase, flags=re.IGNORECASE)
28+
.sum()
29+
for phrase in phrases
30+
),
31+
}
32+
).set_index("phrase")
33+
),
2334
format=cli_args.format,
2435
output=cli_args.output,
2536
)

0 commit comments

Comments
 (0)