Sub topic 10
Automating Routing and Duplicate Detection
Assume you can read short Python programs and that your course platform can export questions with fields such as id, title, body, and asked_at. Automation should support moderation, not replace it. A rule can suggest a category or possible duplicate, but a person should make the final decision.
Start with simple routing rules
Routing sends a question to the right queue or person. For example:
- Billing questions go to course operations.
- Technical questions go to a technical moderator.
- Content questions go to the instructor.
- Personal or sensitive questions go to a private support channel.
Begin with explicit rules that are easy to inspect. A keyword rule checks whether known words appear in the question. The first matching rule wins, so put more specific rules before broad rules.
RULES = [
("billing", ("refund", "invoice", "charge")),
("technical", ("error", "install", "traceback")),
("content", ("lecture", "quiz", "slide")),
]
def triage(text):
lowered = text.lower()
for category, keywords in RULES:
if any(word in lowered for word in keywords):
return category
return "general"
questions = [
"I get an error when I install the course files",
"Where can I download the lecture slides?",
"I need help with my refund",
]
for question in questions:
print(triage(question), "-", question)This approach is useful when categories are stable and the volume is moderate. It is also easy to test. Add examples for every category, including questions that should remain general.
Detect likely duplicates
Duplicate detection compares a new question with questions that already have answers. The goal is not to delete the new question automatically. The goal is to suggest a related answer or ask a moderator to merge the discussion.
A basic method uses text similarity. Python's SequenceMatcher returns a ratio from 0 to 1. A score of 1 means the strings are identical. A threshold such as 0.7 is only a starting point. Test it against real course questions.
from difflib import SequenceMatcher
def similarity(first, second):
return SequenceMatcher(
None, first.lower(), second.lower()
).ratio()
def find_duplicates(new_question, existing, threshold=0.7):
scored = [
(question, similarity(new_question, question))
for question in existing
]
matches = [
item for item in scored
if item[1] >= threshold
]
return sorted(matches, key=lambda item: item[1], reverse=True)
existing = [
"How do I submit assignment 2?",
"Where can I find the slides?",
]
matches = find_duplicates(
"How can I submit assignment 2?",
existing,
)
for question, score in matches:
print(f"{score:.2f}: {question}")This method works best for short, similarly worded questions. It can miss duplicates when students use different vocabulary. It can also produce false matches when common words such as “assignment” or “help” appear in many questions.
Combine automation with moderation
A practical workflow separates suggestions from actions:
flowchart TD
A[New question] --> B[Normalize text]
B --> C[Suggest category]
B --> D[Find similar answered questions]
C --> E[Moderator reviews]
D --> E
E --> F[Route or link to an answer]
E --> G[Record correction]
G --> H[Improve rules and examples]The correction record matters. Store the original suggestion, the moderator's decision, and the final category or linked answer. This gives you test data for improving the system.
Normalize text before comparison by lowercasing it, removing extra spaces, and optionally removing punctuation. Avoid removing words blindly. A phrase such as “cannot submit” may carry important meaning.
Common failure modes
Keyword routing has several limits:
- A word can have multiple meanings. “Charge” might describe a billing issue or a science example.
- Students may use a term that is missing from your rule.
- One question may contain several issues and need more than one route.
- Rules can become contradictory as the course grows.
Similarity detection has different limits:
- Short questions contain too little text for reliable comparison.
- Two questions can look similar but require different answers because course versions differ.
- Personal details can create privacy risks if stored in comparison logs.
- A threshold that works for one course may be wrong for another.
Keep private information out of shared duplicate indexes where possible. Restrict access to question data, define how long logs are retained, and allow moderators to remove sensitive content.
| Automation result | Recommended action |
|---|---|
| Clear category, no duplicate | Route to the category queue |
| Several possible categories | Send to manual triage |
| Strong possible duplicate | Show the earlier answer for review |
| Sensitive or personal content | Use a private escalation path |
Exercise
A new question contains the word “quiz,” but it also says, “The platform shows an error when I submit.” Should a simple keyword rule route it only to the content queue?
Show answer
No. The question contains both content and technical signals. Route it to manual triage or use a rule that gives technical errors priority, then record whether that decision was correct.