Skip to content

Implemented fallback mechanism for unknown queries(#56)#61

Open
DhanashreePetare wants to merge 1 commit intodbpedia:masterfrom
DhanashreePetare:feature/unknown-query-fallback
Open

Implemented fallback mechanism for unknown queries(#56)#61
DhanashreePetare wants to merge 1 commit intodbpedia:masterfrom
DhanashreePetare:feature/unknown-query-fallback

Conversation

@DhanashreePetare
Copy link

@DhanashreePetare DhanashreePetare commented Dec 24, 2025

Summary

Restrict fallback smart replies to DBpedia-focused options to avoid slow/empty responses on unknown topics.
Refresh smart-reply pill layout (flex wrap, spacing, hover/focus) for clearer tap targets.
Use ASCII apostrophes in fallback/no-results text to avoid encoding artifacts on Windows.

Changes

  1. Updated fallback handling in TextHandler.java to serve DBpedia-only quick replies.
  2. Tweaked smart-reply styling in smart-reply.less for better readability and responsiveness.
  3. Normalized fallback copy in scenario-text.rive to fix apostrophe encoding issues.

Testing

  1. mvn test -q
  2. .\node\node -e "require('./node_modules/webpack/bin/webpack.js')" -p
  3. mvn package -DskipTests

Output

Screenshot 2025-12-25 001112

Summary by CodeRabbit

  • New Features

    • Added smart reply suggestions to guide users when uncertain responses occur
  • Improvements

    • Refined smart reply button styling with enhanced visual feedback and interaction states
    • Improved fallback messaging and prompts for clearer user guidance

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 24, 2025

📝 Walkthrough

Walkthrough

The changes enhance fallback handling in the chatbot by adding keyword extraction and DBpedia-based smart reply suggestions to the TextHandler, while updating RiveScript messaging and improving the visual presentation of smart reply components through flexible layout and enhanced interaction states.

Changes

Cohort / File(s) Summary
Smart Reply Styling
app/src/less/modules/smart-reply.less
Layout refactored to flexbox with wrap and gap spacing; border thickness, padding, and border-radius reduced; added color tokens (brand primary), box-shadow, and 120ms transitions; consolidated interaction states (hover/active/focus) with unified visual treatment (primary background, white text, enhanced shadow).
Fallback Suggestion Logic
src/main/java/chatbot/lib/handlers/TextHandler.java
Introduced fallback tracking flag and new appendFallbackSuggestions method to inject base prompt and fixed DBpedia-based smart replies; added extractKeyword helper for stopword filtering; conditionally invoke suggestions after RiveScript processing; updated imports and control flow to route through fallback before Eliza default.
RiveScript Configuration
src/main/resources/rivescript/scenario-text.rive
Updated fallback and no-result messaging from single-line apologies to bullet-style prompts for improved UX presentation.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant TextHandler
    participant RiveScript
    participant DBpedia

    Client->>TextHandler: Process user input
    TextHandler->>RiveScript: Query RiveScript
    RiveScript-->>TextHandler: Response (or FALLBACK_SCENARIO)
    
    alt Fallback Detected or No Response
        TextHandler->>TextHandler: Extract keyword from input
        TextHandler->>DBpedia: Fetch smart reply suggestions
        DBpedia-->>TextHandler: Return suggestions
        TextHandler->>TextHandler: appendFallbackSuggestions()
        TextHandler->>TextHandler: Add base prompt + suggestions
    end
    
    TextHandler-->>Client: Final response with suggestions
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately summarizes the main change: implementing a fallback mechanism for unknown queries, which is the primary objective across all modified files (TextHandler.java, smart-reply.less, and scenario-text.rive).
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/main/java/chatbot/lib/handlers/TextHandler.java (1)

12-12: Remove unused import.

The ResponseType import is not used anywhere in this file.

🔎 Proposed fix
-import chatbot.lib.response.ResponseType;
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4627979 and 111ec0c.

📒 Files selected for processing (3)
  • app/src/less/modules/smart-reply.less
  • src/main/java/chatbot/lib/handlers/TextHandler.java
  • src/main/resources/rivescript/scenario-text.rive
🧰 Additional context used
🧬 Code graph analysis (1)
src/main/java/chatbot/lib/handlers/TextHandler.java (4)
src/main/java/chatbot/lib/handlers/dbpedia/StatusCheckHandler.java (1)
  • StatusCheckHandler (21-117)
src/main/java/chatbot/lib/response/ResponseData.java (1)
  • ResponseData (13-276)
src/main/java/chatbot/lib/response/ResponseGenerator.java (1)
  • ResponseGenerator (17-116)
src/main/java/chatbot/lib/Utility.java (1)
  • Utility (15-107)
🔇 Additional comments (9)
src/main/resources/rivescript/scenario-text.rive (2)

44-45: LGTM! Improved fallback messaging with actionable guidance.

The updated fallback text provides clearer guidance to users and uses ASCII apostrophes to avoid encoding artifacts on Windows. This aligns well with the smart reply suggestions added in TextHandler.java.


48-48: LGTM! Consistent messaging improvements.

The no-results text is now more concise and uses ASCII apostrophes consistently with the fallback text changes.

src/main/java/chatbot/lib/handlers/TextHandler.java (4)

31-31: LGTM! Good fallback tracking design.

The fallbackTriggered field effectively tracks when the bot enters a fallback path, enabling conditional augmentation of responses.


81-81: LGTM! Fallback flag set at appropriate point.

The flag is correctly set when a FALLBACK_SCENARIO is detected, before the existing fallback handling logic executes.


110-127: All TemplateType constants are properly defined and have corresponding handlers.

Verification confirms that all six TemplateType constants used in the appendFallbackSuggestions method (DBPEDIA_ABOUT, DBPEDIA_CONTRIBUTE, CHECK_SERVICE, DBPEDIA_DATASET, DBPEDIA_LOOKUP, DBPEDIA_MAPPINGS) are properly defined in the TemplateType interface and have appropriate handlers in TemplateHandler. The concatenation pattern on line 120 is correctly implemented—the payload is split by STRING_SEPARATOR ("__") and the second part is passed to StatusCheckHandler as expected.


98-101: Verify the fallback suggestion logic—clarify if appending guidance after existing responses is intentional.

When fallbackTriggered is true (line 81), the code adds responses via Eliza (line 84) or NLHandler (line 88). The condition at line 99 (if(fallbackTriggered || responseGenerator.getResponse().size() == 0)) then appends a fallback prompt and smart reply suggestions via appendFallbackSuggestions.

The method adds guidance elements (a prompt text and UI smart replies), not duplicate responses. However, this means users receive:

  • Eliza fallback scenario: [Eliza response] + [Fallback prompt] + [Smart replies]
  • NLHandler fallback scenario: [NLHandler responses] + [Fallback prompt] + [Smart replies]

This design could be intentional to guide users in fallback scenarios. However, without tests or documentation clarifying the expected behavior, consider adding a comment explaining whether appending guidance after Eliza/NLHandler responses is intentional, especially if NLHandler already returns useful results.

app/src/less/modules/smart-reply.less (3)

3-6: LGTM! Excellent responsive layout improvement.

The switch to flexbox with flex-wrap and gap greatly improves responsiveness and maintainability compared to fixed layout approaches. This ensures smart reply pills wrap naturally on smaller screens and maintain consistent spacing.


10-17: LGTM! Polished visual design with smooth transitions.

The refined dimensions, explicit color, subtle shadow, and smooth 120ms transition create a more polished and modern appearance. These changes enhance the visual hierarchy and provide better user feedback.


20-26: LGTM! Enhanced interaction states improve usability.

The consolidated selector for hover, active, and focus states ensures consistent visual feedback across different interaction modes. The enhanced shadow and explicit removal of text-decoration improve both accessibility and visual polish.

Comment on lines +129 to +148
private String extractKeyword(String text) {
if(text == null || text.trim().length() == 0) {
return null;
}
String cleaned = text.replaceAll("[^A-Za-z0-9 ]", " ").toLowerCase();
String[] tokens = cleaned.split(" +");
String[] stop = new String[]{"what","who","where","why","how","is","are","the","a","an","of","in","on","for","with","to","tell","me","about","please"};
java.util.Set<String> stopSet = new java.util.HashSet<>();
for(String s : stop) stopSet.add(s);

String best = null;
for(String t : tokens) {
if(t.length() < 3) continue;
if(stopSet.contains(t)) continue;
if(best == null || t.length() > best.length()) {
best = t;
}
}
return best;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Remove unused extractKeyword method.

The extractKeyword method is defined but never called anywhere in the codebase. This is dead code that should either be:

  1. Removed if not needed, or
  2. Integrated into the fallback logic if it was intended to be used

If this method was intended for future use or for extracting keywords to personalize fallback suggestions, please clarify the intended use case. Otherwise, it should be removed to avoid code bloat.

Do you want me to generate a script to verify it's truly unused across the entire codebase, or open an issue to track its proper integration?

🤖 Prompt for AI Agents
In src/main/java/chatbot/lib/handlers/TextHandler.java around lines 129 to 148,
the extractKeyword method is defined but unused; either remove it or integrate
it into the handler fallback flow. If removing: delete the method and run the
project build/tests to ensure nothing relied on it. If integrating: call
extractKeyword(text) from the fallback handling path that generates user
suggestions, use the returned keyword (when non-null) to personalize or
prioritize suggestions, and update unit tests accordingly. Also run a global
search to confirm no other references remain after the change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant