Skip to content

Conversation

@mustyoshi
Copy link
Contributor

@mustyoshi mustyoshi commented Jul 3, 2024

Occasionally the alias list for the item does not have the closing parenthesis. I opted for this approach rather than figure out how to fix the initial alias list parsing because I was having trouble figuring out where it was coming from.

Similarly, sometimes the alias list just doesn't have the descriptive name, but usually the image name does follow the correct pattern we expect from the recipe info.

@mustyoshi mustyoshi marked this pull request as ready for review July 3, 2024 14:03
mustyoshi added 2 commits July 3, 2024 10:05
…-osrs; branch 'main' of github.com:Flipping-Utilities/parsed-osrs into main-item-names
Comment on lines 140 to 153
private hasUnterminatedParenthesis(input: string): boolean {
let openParenthesisCount = 0;
let closeParenthesisCount = 0;

for (const char of input) {
if (char === '(') {
openParenthesisCount++;
} else if (char === ')') {
closeParenthesisCount++;
}
}

return closeParenthesisCount < openParenthesisCount;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

While this works, there are "cleaner" solutions IMO.
I would personally replace it with a regex to test for unmatched parenthesis, something like:

return !/^[^()]*(?:\([^()]*\)[^()]*)*$/.test(input);

But that's a fairly ugly regex.
To keep it code-based, I would augment it to match the parenthesis "depth" to ensure this )( doesn't pass either:

let depth = 0;
for (const char of input){
  if(char === '('){
    depth += 1;
  } else if(char === ')'){
    depth -=1;
    if(depth < 0){
      return true;
    }
  }
  return depth !== 0;
}

@AntonyGarand
Copy link
Contributor

Fyi: Aliases are built from the list of wiki redirects to this page, hence the inconsistent amount and quality of these: This isn't a reliable mechanism to find names, but it is good enough for most typos and meme names.
Do you have an example item I can use to debug? The main name / versions of an item should always match the value

Comment on lines 191 to 198
const score =
Number(item.isInMainGame) * 3 +
Number(item.isOnGrandExchange) +
Number(item.isTradeable);
const otherScore =
Number(otherItem.isInMainGame) * 3 +
Number(otherItem.isOnGrandExchange) +
Number(otherItem.isTradeable);
Copy link
Contributor

Choose a reason for hiding this comment

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

As this is getting repeated few additional times, I'd extract it in a weightItemScore method so it's easier to tweak in the long run

@mustyoshi
Copy link
Contributor Author

@AntonyGarand This diff is adding Nettle tea (milky) which we find via the image.
Which now that I'm looking at it, might actually be incorrect

@mustyoshi
Copy link
Contributor Author

This might have been a lofty endeavor, a lot more edge cases than I thought.

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.

3 participants