Skip to content

ordinal vs. fractional biasing #1

@nanobowers

Description

@nanobowers

I'm toying around with a port of Chronic to crystal and as Chronic uses Numerize, I have taken to trying to use this in its place. Thanks for putting this shard together!

One difference I'm running into is in how NumberParser handles suspected ordinals:
In Numerize, "may tenth" => "may 10th" whereas in NumberParser, "may 1/10"

It looks like NumberParser allows switching but between fractional/ordinal, but i think generally things work as i'd hope except one case:

NumberParser.parse("fourth") # => "4th"
NumberParser.parse("a fourth") # => "1/4"
NumberParser.parse("one fourth") # => "1/4"
NumberParser.parse("two fourths") # => "2/4"
NumberParser.parse("may fourth") # => "may 1/4"
^^ this causes me problems...

# biasing doesn't solve my problem..
NumberParser.parse("fourth", bias: :ordinal) # => "4th"
NumberParser.parse("a fourth", bias: :ordinal) # => "a 4th"
NumberParser.parse("one fourth", bias: :ordinal) # => "1 4th"
NumberParser.parse("two fourths", bias: :ordinal) # => "2/4"
NumberParser.parse("may fourth", bias: :ordinal) # => "may 4th"
NumberParser.parse("fourth", bias: :fractional) # => "1/4"
NumberParser.parse("a fourth", bias: :fractional) # => "1/4"
NumberParser.parse("one fourth", bias: :fractional) # => "1/4"
NumberParser.parse("two fourths", bias: :fractional) # => "2/4"
NumberParser.parse("may fourth", bias: :fractional) # => "may 1/4"

same applies for the "tenth" case

NumberParser.parse("tenth") # => "10th"
NumberParser.parse("a tenth") # => "1/10"
NumberParser.parse("one tenth") # => "1/10"
NumberParser.parse("two tenths") # => "2/10"
NumberParser.parse("may tenth") # => "may 1/10"
^^^ problematic...

For my use model, i think i'd prefer a word that the ordinal be used if either the preceding item is a either a number or /a | an/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions