parsing - Simple physical quantity measurement unit parser for Java -


i want able parse expressions representing physical quantities like

g/l m/s^2 m/s/kg m/(s*kg) kg*m*s °f/(lb*s^2) 

and on. in simplest way possible. possible using pyparsing (if such thing exists java), or should use more complex tools java cup?

edit: answere mrd's question goal make conversion between quantities, example convert g kg (this 1 simple...), or maybe °f/(kg*s^2) k/(lb*h^2) supposing h 4 hour , lb pounds

this harder looks. (i have done fair amount of work here). main problem there no standard (i have worked nist on units , although have created markup language few people use it). it's form of natural language processing , has deal :

  • ambiguity (what "m" mean - meters or mega)
  • inconsistent punctuation
  • abbreviations
  • symbols (e.g. "mu" micro)
  • unclear semantics (e.g. kg/m/s same kg/(m*s)?

if creating toy system should create bnf system , make sure examples adhere it. use common punctuation ("/", "", "(", ")", "^"). character fields can of variable length ("m", "kg", "lb"). algebra on these strings ("kg" -> 1000"g" has problems kg fundamental unit.

if doing antlr (@yaugen) useful, aware units in wild not follow regular grammar due inconsistencies above.

if serious (i.e. prepared put in solid month), i'd interested know. :-)

my current approach (which outside scope of question) collect large number of examples literature automatically , create number of heuristics.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -