Skip to main content
Question

How to convert Roman numerals to numbers?


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!

4 replies

david_r
Celebrity
  • 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
  • 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.


Thank you! That's really helpful!


gio
Contributor
Forum|alt.badge.img+15
  • Contributor
  • 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!

 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings