Skip to content

Conversation

@Jasrags
Copy link
Contributor

@Jasrags Jasrags commented May 3, 2025

Description

Refactor the Room.FindNoun method to improve multi‑word noun matching, alias resolution, and plural/singular handling. This change ensures that full‑phrase lookups (e.g. “rocky island”) are tried first, aliases are unwrapped recursively, and common plural forms (…ies, …es, …s) are handled in a predictable order. It also fixes previously failing tests for “ponies” and “rocky”.

Changes

  • Reordered matching logic to test the entire input string first, then each individual word, before falling back to plural/singular rules.
  • Simplified alias handling by unwrapping any number of :‑prefixed aliases in a single loop.
  • Consolidated pluralization/singularization checks.
  • Removed the old nested split‑and‑append heuristic in favor of a clear candidate list built via util.SplitButRespectQuotes.
  • Updated unit tests now pass for FindNoun("rocky island") → ("island","a tropical paradise").
  • Updated unit tests now pass for circular references checks
Screenshot 2025-05-03 at 11 41 08 AM

@Jasrags Jasrags added the bug Something isn't working label May 3, 2025
@Jasrags Jasrags requested a review from Copilot May 3, 2025 16:54
@Jasrags Jasrags self-assigned this May 3, 2025
@Jasrags Jasrags requested a review from Volte6 as a code owner May 3, 2025 16:54
@Jasrags Jasrags linked an issue May 3, 2025 that may be closed by this pull request
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the Room.FindNoun method to address issue 356 by improving multi‑word matching, alias resolution, and plural/singular handling.

  • Reordered matching logic and candidate list construction for more predictable noun matching.
  • Simplified and consolidated alias resolution and pluralization/singularization checks.
  • Updated unit tests to verify the corrected behavior of full‑phrase lookups and alias chaining.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
internal/rooms/rooms_test.go Added test cases to validate improved matching and alias resolution.
internal/rooms/rooms.go Refactored alias and pluralization handling in the FindNoun method.

Copy link
Member

@Volte6 Volte6 left a comment

Choose a reason for hiding this comment

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

Looks good!

@Volte6
Copy link
Member

Volte6 commented May 3, 2025

Does this handle circular references?

"feet": ":hands",
"hands": ":feet"

@Jasrags
Copy link
Contributor Author

Jasrags commented May 3, 2025

Does this handle circular references?

"feet": ":hands",
"hands": ":feet"

Good catch, it will loop for circular aliases. Do we have an expected behavior for this case?

I’d say we should catch them as early as possible. We could detect on load and log a warning or error when a cycle is found and flatten aliases at load time into a map, so runtime lookups are cycle‑free or enforce a max alias depth or maintain a visited set during runtime lookup to break cycles.

I'm leaning to the detect on load as it gives the benefit of creating the noun map once and would simplify the logic FindNoun.

@Volte6
Copy link
Member

Volte6 commented May 3, 2025

I think just making it so no alias can point to another alias might be fine. Why would anyone want to do:

"leaf" => ":leaves"
"leaves" => ":tree leaves"
"tree leaves" => ":branches"
"branches" => "You see some branches"

When they could just do:

"leaf" => ":branches"
"leaves" => ":branches"
"tree leaves" => ":branches"
"branches" => "You see some branches"

@Jasrags Jasrags requested a review from Copilot May 13, 2025 00:18
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the Room.FindNoun method to improve multi‑word noun matching, alias resolution, and plural/singular handling, addressing issue #356 and updating the corresponding tests.

  • Reorders matching logic to try full‑phrase lookups before individual words
  • Consolidates pluralization/singularization checks and simplifies alias handling
  • Adds test cases for multi‑word inputs and circular alias references

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
internal/rooms/rooms_test.go New test cases added for island, rocks, and circular alias handling
internal/rooms/rooms.go Refactored FindNoun method with improved candidate generation, alias, and pluralization logic
Comments suppressed due to low confidence (1)

internal/rooms/rooms.go:1633

  • [nitpick] The variable name 'tn' is not very descriptive; consider renaming it to something like 'candidateNoun' for improved clarity.
tn := strings.TrimSuffix(newNoun, "es")

@Jasrags Jasrags merged commit d968512 into master May 13, 2025
2 checks passed
@Jasrags Jasrags deleted the 356-fix-noun-aliases branch May 13, 2025 00:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix Noun aliases

3 participants