Skip to main content
Question

How to convert Roman numerals to numbers?

  • May 28, 2019
  • 4 replies
  • 79 views

Hi!

 

I have a problem which I am not able to solve at the moment.

 

I have codes (as a string) including letters and roman numerals, in a style similar to this:

 

ABCDE IV-a

 

I would like to change this to:

 

ABCDE 4-a

 

 

I was able to split the string into parts, so that I have a new column with just the Roman numerals. But how do I change those roman numerals to numbers in FME?

 

 

Thank you!
This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

4 replies

david_r
Celebrity
  • 8394 replies
  • May 28, 2019

It should be fairly easy to incorporate the following code sample into a PythonCaller:

https://www.oreilly.com/library/view/python-cookbook/0596001673/ch03s24.html

 


david_r
Celebrity
  • 8394 replies
  • May 28, 2019

Here's a sample workspace (FME 2019) that demonstrates a possible solution: roman_numeral.fmwt

Assuming the input attribute code = ABCDE IV-a, the output is result = ABCDE 4-a

The regex in the StringSearcher assumes that the roman numeral will always be prefixed by a space and followed by a dash.


  • Author
  • 1 reply
  • May 29, 2019

Thank you! That's really helpful!


gio
Contributor
Forum|alt.badge.img+15
  • Contributor
  • 2252 replies
  • May 29, 2019

@volodya_17 @david_r

 

 

The python script posted is wrong, as there are rules in ROMAN.. 

In the posted script one can shamelessly enter VVVV as a roman, which is clearly not a roman number, and get 20 as result.

For instance IC is 99 according to the posted script, but this is not a roman number as XCIX = 99.

Max 3 consectutive of same numeral allowed. One numeral cannot be preceded by a numeral that is more than one level lower ( so XC is allowed but not IC). etc.

 

So you either respect  the rules for Roman numbers or should replace the string with

{1000 M 900 CM 500 D 400 CD 100 C 90 XC 50 L 40 XL 10 X 9 IX 5 V 4 IV 1 I}

and do some slight changes to the posted code.

 

I am wondering, you all do know this very awesome site? (if not you really should)

https://rosettacode.org

 

You see at that site several python  ways to do it.

 

But you also see, as fme has a R caller, that R has a function for it. How convenient is that?

 

Also you clearly see that TCL has a superior code...;)

 

Have fun and greets!