I am not claiming this is entirely the correct way to do this in this
package, just that it works fairly easily to expand the scope of the
Conversions goodie, as well.
Gonna need feedback from @moollaza and @mintsoft.
On the upside, I found a bug in the styler code by writing a test here!
Considering how all of this works, I'm not sure roles are quite the
right fit. It seems like we might just want a shared "Utility" package
or namespace to let us have access to some common library functions.
DDG::GoodieRole::NumberStyle is a particularly horrible name because
it's not even a role!
Also, the comments suck.
But such is the nature of a proof-of-concept.
This would be better with some proper parsing, but this resolves some
issues with the current HTML output, making it raise things to
arbitrarily high superscripting levels based on what it seems to look
like.
I think this makes it somewhat easier to follow the intent here. We're
just trying to convert these two known strings into different output
formats, so wrapping that up seems like a good idea.
The old version clearly worked, but it was clunky and somewhat
inexplciable. While reading up on something else, I discovered `perldoc
quotemeta` which resolves this in a much more predictable and correct
way.
There should never be a thousands separator in that place, so don't
allow one. This was a bit masked by taking all of the numbers in
combination which gave them more context.
Testing a number individually exposed the error.
This includes multiplication and division in things which should not be
rounded to our determined precision. While this doesn't break any
current tests, it might lead to some surprising floating-point issues.
On the other hand, the other way led to some surprising results where
418.10 / 2 != 418.1 / 2
Hopefully there exists a better long-term solution which we'll find soon
enough.
Addresses issue #509.
- Fixed global flag on regex subs
- Change the Decode module to the old module name (in case it is linked
by someone)
- Fix attribution links, add ‘crazedpsyc’ to attribution section in the
new module
- Add a comment about the separation of the encode and decode
functionality
- Fix test file for the module name change
This is an attempt to add the requested "squared" operation without all
of the nasty trigger changes I introduced last time I tried.
Also added a constant for 'score' as both an attempt to better
understand that trigger regex and an historical oddity.
It's clear that if I want to continue with this I should make a lexer.
– Add HTMLEntitiesDecode.pm and .t
– Add HTMLEntitiesEncode.pm and .t
– Add URLEncode and .t
– Remove HTMLEntities.pm and HTMLEntitiesCode.pm and their test files
– Initial commit perl module
– Initial commit test file
– Displays the “maybe inaccurate” message for android devices by using
JavaScript to get the user-agent
– Contains commented out lines of JavaScript code that can be enabled
to not show any resolution numbers if device user-agent is Android
- regex to clean up whitespaces and to remove filler words (for, of)
- symbol and sign presence/absence in query does not make a difference
in hits
- all ‘-‘ are replaced by ’ ‘.
- accented_chars keys have no spaces now
- updated triggers
HTMLEntitiesCodes.pm
1. Substring replacers
A few practical examples as a result of this change — the following
query pairs will now lookup the same key: ‘trademark symbol’ and
‘trademark’ // ‘up-down arrow’ and ‘up down arrow’ // ‘pound sign’ and
‘pound’, and so on…
2. Update the keys for this change (extraneous keys removed).
This mostly just adds style to the HTML answers to be more in line with
other IAs.
The test changes are because, in general, the HTML answer is exactly the
same as the text answer, just wrapped up in some HTML. We're mostly
concerned with if we get correct answers, not how they happen to be
wrapped for HTML display.
In cases where that's different (the <sup> regression) we do more
thorough testing on the contents.
Also, removed one repeated test.
I'm starting to think this "apply_css" and maybe even "wrap_html" should
be in a role somewhere.
Total run time may well exceed 1 second with the pre- and post-
processing, but this makes it significantly less annoying to try things
out with `duckpan query`.
Also adds a test which shows the `duckpan query` parameters I was
trying, showing how `squared` is applied (and may result in confusion)
This fixes the problem of the simple case, but handling, say, expressions
in parens would require a lot more thought (a lexer would help!) I'll
leave that problem for another day.
Fixes#483.
Some of the problems inherent in the old trigger regex made themselves
obvious once the 'squared' operation was added. This simplification
should make maintenance a smidge easier.
Resolves#482.
Because of floating-point issues, sin(pi) does not come out to exactly
0. It looks like something we try to guard against a couple lines down.
So, if we don't have a defined precision (such that we can let sprintf
worry about the correct answer), we will set these very small values to
0.
This worked fine with things like '1 + sin(pi)' which made the whole thing
more confusing at the start. Thus, this commit also includes a passel of
new tests for things I considered as possible faults, plus one other thing
I wanted to demonstrate working [cos(2pi)].
"flip", "mirror", "spin", and "rotate" are all very common words, and this instant answer comes up often for queries such as "flip flops". While we don't have a way of setting individual goodies with low priority (all goodies have high priority at the moment), it's important that we control the query space of each one. So in this case, adding a "text" as a requirement will prevent it from triggering on "flip flop", "back flip", etc.
- Make ln alias more like others.
- Put named constants in a hash and generate the substitution list
therefrom.
- Update test and comment text slightly for accuracy.
I had fixed a number of different problems iteratively and didn't
recognize that these changes were viable until now.