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:
LetterNumeral -
LabelNumeral{AlphaNumeral}
- A, B, ..., Z, AA, BB, ..., ZZ, AAA... (group of 26 characters each)ArabicNumeral -
LabelNumeral{Int}
- 1, 2, 3, ...LookupNumeral -
LabelNumeral{LookupNumeral}
- mapped strings to integers like English words "One", "Two" etc.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
LabelNumerals.LabelNumeral
— Type. LabelNumeral{T<:Integer}
Wrapper around an Integer
type that provides the following caabilities:
Prefix - like A-1, A-2 etc...
Lower case or upper case conversions
show and print options.
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
LabelNumerals.LabelNumeral
— Method. 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
LabelNumerals.findLabels
— Function. 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.
AlphaNumeral
LabelNumerals.AlphaNumeral
— Type. AlphaNumeral
Numbers represented as alphabets. ex. A, B, C,... from 27 onwards AA, BB, CC etc.
LabelNumerals.AlphaNumeral
— Method. AlphaNumeral(str::String)
AlphaNumeral(n::Int)
Constructors for AlphaNumeral
.
LabelNumerals.@an_str
— Macro. @an_str(str)
String decorator for AlphaNumeral
definitions.
#Example
julia> an"AA"
LabelNumerals.AlphaNumeral(27, "AA")
AlphaNumNumeral
LabelNumerals.AlphaNumNumeral
— Type. AlphaNumNumeral
Numbers represented as alphabets as a base26 number where A, B, C represent digits. A = 0, B = 1, ..., Z = 25 etc.
LabelNumerals.AlphaNumNumeral
— Method. AlphaNumNumeral(str::String)
AlphaNumNumeral(n::Int)
Constructors for AlphaNumNumeral
.
LabelNumerals.@ann_str
— Macro. @ann_str(str)
String decorator for AlphaNumNumeral
definitions.
#Example
julia> ann"BB"
LabelNumerals.AlphaNumNumeral(27, "BB")
LookupNumeral
LabelNumerals.LookupNumeral
— Type. 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.
LabelNumerals.LookupNumeral
— Method. LookupNumeral(str::String)
LookupNumeral(n::Int)
Constructors for LookupNumeral
.
LabelNumerals.@ln_str
— Macro. @ln_str(str)
String decorator for LookupNumeral
definitions.
#Example
julia> ln"Three"
LabelNumerals.LookupNumeral(3, "Three")
External Numeral Types
ArabicNumeral
Represented as Int
types.
RomanNumeral
Represented as RomanNumeral
from the RomanNumerals
package.