🛠️ToolsShed

Generator Hashtag dari Teks

Menghasilkan hashtag yang relevan secara otomatis dari teks apa pun. Mengekstrak kata kunci dengan analisis frekuensi.

Pertanyaan yang Sering Diajukan

Implementasi Kode

import re
from collections import Counter

STOP_WORDS = {
    "a","an","the","and","or","but","in","on","at","to","for","of","with",
    "by","from","is","are","was","were","be","been","have","has","had",
    "do","does","did","will","would","could","should","this","that","it",
    "i","you","he","she","we","they","not","so","if","as","up","out",
    "about","into","just","also","get","make","go","come","see","use"
}

def generate_hashtags(text, min_length=3, max_count=20, remove_stop=True):
    words = re.findall(r"[a-z0-9']+", text.lower())
    cleaned = [w.strip("'") for w in words if len(w.strip("'")) >= min_length]
    if remove_stop:
        cleaned = [w for w in cleaned if w not in STOP_WORDS]
    freq = Counter(cleaned)
    top = freq.most_common(max_count)
    return [f"#{word}" for word, _ in top]

text = """Machine learning is transforming the software industry.
AI tools help developers write better code faster and improve productivity."""

hashtags = generate_hashtags(text)
print(" ".join(hashtags))

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.