Numbers as Labels

Numbers as Labels

Numeric quantities are used sometimes for pure representational purposes without any true a numeric significance. For example, the page numbering is carried out using simple arabic numerals, roman numerals, alphabets. These numbers have additive properties but may not have any multiplicative significance. Such numbers can also have prefix notations as well. In some cases, the representation can be in upper case or lower case as well. This package implements such a numerals. Such numeric schemes are used as page numbers in PDF file specification. However, the need may be felt else where as well, which prompted the author to implement it as an independent package. The interface has been also influenced significantly by the RomanNumerals package.

Usage

LabelNumerals introduces the following new types:

  1. LetterNumeral - LabelNumeral{AlphaNumeral} - A, B, ..., Z, AA, BB, ..., ZZ, AAA... (group of 26 characters each)

  2. ArabicNumeral - LabelNumeral{Int} - 1, 2, 3, ...

  3. LookupNumeral - LabelNumeral{LookupNumeral} - mapped strings to integers like English words "One", "Two" etc.

  4. AlphaNumNumeral - LabelNumeral{AlphaNumNumeral} - alphabets representing numbers like BA, BB, BC etc.

It also supports RomanNumeral from RomanNumerals package.

They support ability to provide a string prefix. The prefix does not get incremented as numbers are incremented.

!!Note: Letter, arabic and roman numerals are used in the PDF file pages as page number labels.

LabelNumeral

    LabelNumeral{T<:Integer}

Wrapper around an Integer type that provides the following caabilities:

  1. Prefix - like A-1, A-2 etc...

  2. Lower case or upper case conversions

  3. show and print options.

  4. Mathematical operators like +, -, <=, ==, >, isless, max and min

The wrapped struct should implement the following methods:

1. T(::String)
2. T(::Int)
3. Base.hash(::T)
4. Base.convert{S <: Integer}(::Type{S}, num::T)  <-- to covert to standard numeral types
source
    LabelNumeral{T <: Integer}(::T; prefix="", caselower=false)
    LabelNumeral{T <: Integer}(::Type{T}, i::Integer; prefix="", caselower=false)
    LabelNumeral{T <: Integer}(::Type{T}, s::String; prefix="", caselower=false)

Example:

julia> using RomanNumerals

julia> a = LabelNumeral(rn"XXIV"; prefix="A-", caselower=true)
A-xxiv

julia> a = LabelNumeral(rn"XXIV"; prefix="A-")
A-XXIV

Constructors for LabelNumeral

source
    findLabels(label::String, ::Vector{DataType} = allNumerals; pfxList=Vector{String}=[""])
        -> Vector{Tuple{LabelNumeral,Type}}}

Given allNumerals =[AlphaNumeral, RomanNumeral, Int, LookupNumeral, AlphaNumNumeral]

Finds the LabelNumeral that is most suitably matching to the input String. pfxList provides one or more label prefix values.

The function returns an array of all the matching LabelNumeral and the Type of numeral that best matches its internal composition.

source

AlphaNumeral

    AlphaNumeral

Numbers represented as alphabets. ex. A, B, C,... from 27 onwards AA, BB, CC etc.

source
    AlphaNumeral(str::String)
    AlphaNumeral(n::Int)

Constructors for AlphaNumeral.

source
    @an_str(str)

String decorator for AlphaNumeral definitions.

#Example

julia> an"AA"
LabelNumerals.AlphaNumeral(27, "AA")
source

AlphaNumNumeral

    AlphaNumNumeral

Numbers represented as alphabets as a base26 number where A, B, C represent digits. A = 0, B = 1, ..., Z = 25 etc.

source
    AlphaNumNumeral(str::String)
    AlphaNumNumeral(n::Int)

Constructors for AlphaNumNumeral.

source
    @ann_str(str)

String decorator for AlphaNumNumeral definitions.

#Example

julia> ann"BB"
LabelNumerals.AlphaNumNumeral(27, "BB")
source

LookupNumeral

    LookupNumeral

Numbers represented as from a lookup table. No digits or additional system of extension possible. Only numbers available in the lookup table are valid.

source
    LookupNumeral(str::String)
    LookupNumeral(n::Int)

Constructors for LookupNumeral.

source
    @ln_str(str)

String decorator for LookupNumeral definitions.

#Example

julia> ln"Three"
LabelNumerals.LookupNumeral(3, "Three")
source

External Numeral Types

ArabicNumeral

Represented as Int types.

RomanNumeral

Represented as RomanNumeral from the RomanNumerals package.