Skip to content

Commit

Permalink
Show match count and use colors
Browse files Browse the repository at this point in the history
  • Loading branch information
rafidka committed Nov 30, 2024
1 parent edff848 commit 6755d16
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pat_cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.6"
__version__ = "0.2.0"
11 changes: 9 additions & 2 deletions pat_cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# 3rd party imports
from sklearn.cluster import Birch, KMeans
from tqdm import tqdm
from termcolor import colored
import pandas as pd

# Local imports
Expand Down Expand Up @@ -160,10 +161,14 @@ def main():
# Cluster the lines.
clustered_lines = cluster_lines(input_lines, vectorizer, clusterer)

for _, lines in clustered_lines.items():
for _, lines in sorted(
clustered_lines.items(), key=lambda x: len(x[1]), reverse=True
):
if not lines:
continue

count = len(lines)

# Check if any line in the cluster matches the grep pattern.
if args.grep:
if not any(args.grep in line for line in lines):
Expand All @@ -173,7 +178,9 @@ def main():
lines = [line for line in lines if args.grep in line]

# Print the first line of each cluster unindented.
print(lines[0])
match_count = colored(f"(match count: {count})", "green")
header = colored(lines[0], "blue")
print(f"{header} {match_count}")

# Print the rest of the lines of each cluster indented.
max_lines = (
Expand Down
16 changes: 15 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pat-cli"
version = "0.1.6"
version = "0.2.0"
description = ""
authors = ["Rafid Al-Humaimidi <rafidka@gmail.com>"]
readme = "README.md"
Expand All @@ -15,6 +15,7 @@ numpy = "^2.1.3"
pandas = "^2.2.3"
scikit-learn = "^1.5.2"
fasttext = "^0.9.3"
termcolor = "^2.5.0"


[tool.poetry.group.dev.dependencies]
Expand Down

0 comments on commit 6755d16

Please sign in to comment.