GithubHelp home page GithubHelp logo

endrain / omninumeric Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 1.0 131 KB

Python module for numbers reading and writing in alphabetic numeral systems

License: MIT License

Python 100.00%
church-slavonic church-slavic alphabetic numeral system roman

omninumeric's People

Watchers

 avatar

Forkers

0xflotus

omninumeric's Issues

Some numbers "break" Cyrillic converter

By design, Cyrillic converter supports reading numbers with decorator irregularities - including missing "thousand" marks. (Whether this design is right is another question - #4.) The problem here is that certain irregularly written numbers can break current translation algorithm.

Concider this number:
раi҂ра҃i

Let's agree that all our numbers are properly written left-to right, only some decorators are missing. Now, current algorithm will not interpret this as 111,111,000 as it should. It will interpret this as 222,000. It will take the "thousand" mark from the first numeral group and index value (1) for the second numeral group. Both will yield a multiplier of 1,000. Hence, 111*1,000 + 111*1,000 = 222,000.

Publish regular expressions

#5 means that Omninumeric isn't going to validate input, instead just returning zeroes or empty strings on irregular input. But it's not impossible that someone using this library will need to write some checks. To support this, regular expressions must be published by respective modules.

EAFP

Refactor to conform to EAFP principle.

Support older versions

Some tests fail on Python 3.0-3.6:

self.assertEqual(10001010001, cu_to_arab("҂҂҂і҂҂а҂іа҃"))
AssertionError: 10001010001 != 10001000010001

self.assertEqual(18, cu_to_arab("и҃і"))
AssertionError: 18 != 8010

self.assertEqual(1015, cu_to_arab("҂ає҃і"))
AssertionError: 1015 != 1005010

Code should be refactored to support broader range of platforms.

Design: should reading from ANS be permissive?

By current design, Omninumeric tries to read from alphabetic numeral systems as permissively as possible. Numbers in ANS are not required to follow the system's rules for decorators by the book. For example, Cyrillic converter would render this:
араi
as 1,111, even though the "thousand" mark before the leftmost a is missing.

Is this the right design choice or not?

Arguments for this design:

  • ANSs generally have many variations within themselves. Cyrillic has two styles of writing with "thousand" marks and a third style implementing something entirely different. Byzantine Greek sees use of both number-long overstroke and "keraia" symbol for marking a number. It seems only natural to read as permissive as possible from such variable systems.
  • Relaxed reading allows for relaxed regular expression. Stricter reading will require stricter regex, which at some point might become a pain in the back.

Arguments against this design:

  • A system is a system, however variable it can be. There are rules for writing numbers in those systems, not guidelines. It would be only natural to demand that numbers read obey those rules.
  • A "thousand" mark is not a decorator but a significant, meaningful component of a numeral - and a number. It would be irrational not to expect these marks be in order.
  • Wrong inputs and corresponding results should be the user's problem, not the programmer's.
  • Stricter rules for reading mean more concise conversion algorithm, and through that, better readability and sustainability.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.