#1 2010-01-08 15:06

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,046

Roman Numerals Latin Numbers serialize insert

Due an request: How To serialize with  Roman Numerals


FROM               -  TO
Untitled6.txt    - Untitled6 I.txt
Untitled6.html    - Untitled6 II.html
Untitled5.vbs    - Untitled5 III.vbs
Untitled1.ahk    - Untitled1 IV.ahk





Info about Roman Numerals:
http://ancienthistory.about.com/od/math … merals.htm

I think we can create an script to make this more flexible:
http://www2.inetdirect.net/~charta/Roman_numerals.html
M=1000 | D=500 | C=100 | L=50 | X=10 | V=5 | I=1



... but i have not the time now and provide just an simple solution:


1.) Add your files to ReNamer
2.) Add an rule ==>  Insert =>  " " as Suffix (before extension) for an space between the last char and the number
3.) Add an rule ==>  UserInput <paste in the Roman Numerals from the list below>, ... (skip extension)
4.) Press Preview

I
II
III
IV
V
VI
VII
VIII
IX
X
XI
XII
XIII
XIV
XV
XVI
XVII
XVIII
XIX
XX
XXI
XXII
XXIII
XXIV
XXV
XXVI
XXVII
XXVIII
XXIX
XXX
XXXI
XXXII
XXXIII
XXXIV
XXXV
XXXVI
XXXVII
XXXIX
XXXVIII
XL
XLI
XXIX
XLIII
LIV
XLV
XLVI
XLVII
XLVIII
XLIX
L
LI
LII
LIII
LIV
LV
LVI
LVII
LVIII
LIX
LX
LXI
LXII
LXIII
LXIV
LXV
LXVI
LXVII
LXVIII
LXIX
LXX
LXXI
LXXII
LXXIII
LXXIV
LXXV
LXXVI
LXXVII
LXXVIII
LXXIX
LXXX
LXXXI
LXXXII
LXXXIII
LXXXIV
LXXXV
LXXXVI
LXXXVII
LXXXVIII
LXXXIX
XC
XCI
XCII
XCIII
XCIV
XCV
XCVI
XCVII
XCVIII
XCIX
C

Find me: insert roman number serializing  serialize roman latin numerals numeral roemisch roemische römische roman digit digits convert roman to europe

Last edited by Stefan (2010-01-08 16:25)


Please see HELP and MANUAL in Wiki for more info.
If ReNamer had helped you, please donate a coin to Denis or buy a Pro license for commercial use. (Lite vs Pro)

Offline

#2 2010-01-08 23:28

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,046

Re: Roman Numerals Latin Numbers serialize insert

I did an little research for an converter code and tinker around with an ReNamer PascalScript.

convert arabic numbers to roman:


// I don't know if this works for you or not !  Maybe i have overseen something.
// Please  test this first with test files in an temp folder in an virtual machine !

// ToDo:  some validating checks and  error handling

//den4b ReNamer Script:  Arabic2Roman_NumbersConverter.pas 
//Purpose: RegEx match an arabic number like '1234' and convert them to roman 'MCCXXXIV'
// Done with an code found at:
// http://www.madeasy.de/2/prgroem.htm

//  Roman Numerals
//  I = 1     
//  V = 5     
//  X = 10     
//  L = 50     
//  C = 100 
//  D = 500
//  M = 1000


// table to check my result
//http://www.yourdictionary.com/crossword/romanums.html

//online converter to check my result
//http://www.novaroma.org/via_romana/numbers.html

//please note that there are more rules
//then this simple script is able to follow:
//http://en.wikipedia.org/wiki/Roman_numerals


var
 Len: integer;
 input, output, arabic, roman: WideString;
 SubMatches: TStringsArray;
 
begin
    input := WideExtractBaseName(FileName);

//SETTING 1:
    //my test string was: "Roman 1234.txt"
    // So "SubMatches[0]" for MY RegEx will hold "Roman" 
    //and "SubMatches[1]" will contain "1234"
    //adjust the regex to match the number in YOUR string:
    SubMatches := SubMatchesRegEx(input, '(.+?)(\d+)', false);


    Len := Length( SubMatches[1] );

//ones:
    arabic := WideCopy(SubMatches[1], Len, 1);
    If (arabic = '1') Then roman := 'I';
    If (arabic = '2') Then roman := 'II';
    If (arabic = '3') Then roman := 'III';
    If (arabic = '4') Then roman := 'IV';
    If (arabic = '5') Then roman := 'V';
    If (arabic = '6') Then roman := 'VI';
    If (arabic = '7') Then roman := 'VII';
    If (arabic = '8') Then roman := 'VIII';
    If (arabic = '9') Then roman := 'IX';
    output := roman;
    roman :='';

//tens:
If (Len > 1) Then
Begin
    arabic := WideCopy(SubMatches[1], Len - 1, 1);
    If (arabic = '1') Then roman := 'X';
    If (arabic = '2') Then roman := 'XX';
    If (arabic = '3') Then roman := 'XXX';
    If (arabic = '4') Then roman := 'XL';
    If (arabic = '5') Then roman := 'L';
    If (arabic = '6') Then roman := 'LX';
    If (arabic = '7') Then roman := 'LXX';
    If (arabic = '8') Then roman := 'LXXX';
    If (arabic = '9') Then roman := 'XC';
    output := roman + output;
    roman :='';
end;

//hunderts:
If (Len > 2) Then
Begin
    arabic := WideCopy(SubMatches[1], Len - 2, 1);
    If (arabic = '1') Then roman := 'C';
    If (arabic = '2') Then roman := 'CC';
    If (arabic = '3') Then roman := 'CCC';
    If (arabic = '4') Then roman := 'CD';
    If (arabic = '5') Then roman := 'D';
    If (arabic = '6') Then roman := 'DC';
    If (arabic = '7') Then roman := 'DCC';
    If (arabic = '8') Then roman := 'DCCC';
    If (arabic = '9') Then roman := 'CM';
    output := roman + output;
    roman :='';
end;

//tousends:
If (Len > 3) Then
Begin
    arabic := WideCopy(SubMatches[1], Len - 3, 1);
    If (arabic = '1') Then roman := 'M';
    If (arabic = '2') Then roman := 'MM';
    If (arabic = '3') Then roman := 'MMM';
    If (arabic = '4') Then roman := 'MMMM';
    If (arabic = '5') Then roman := 'MMMMM';     // (V)
    If (arabic = '6') Then roman := 'MMMMMM';    // (V)M
    If (arabic = '7') Then roman := 'MMMMMMM';    // (V)MM
    If (arabic = '8') Then roman := 'MMMMMMMM';   // (V)MMM
    If (arabic = '9') Then roman := 'MMMMMMMMM'; // (V)MMMM, (X), (C)
    output := roman + output;
    roman :='';
end;

//SETTING 2:
    //adjust the output to your needs:
    //ShowMessage(SubMatches[0] + output + WideExtractFileExt(FileName));
    FileName := SubMatches[0] + ' ' + output + WideExtractFileExt(FileName);

//clean up:
    filepath := '';
    output :='';
end.

Test:

Roman 1.txt    Roman  I.txt
Roman 2.txt    Roman  II.txt
Roman 3.txt    Roman  III.txt
Roman 4.txt    Roman  IV.txt
Roman 5.txt    Roman  V.txt
Roman 6.txt    Roman  VI.txt
Roman 7.txt    Roman  VII.txt
Roman 8.txt    Roman  VIII.txt
Roman 9.txt    Roman  IX.txt
Roman 10.txt    Roman  X.txt
Roman 11.txt    Roman  XI.txt
Roman 13.txt    Roman  XIII.txt
Roman 14.txt    Roman  XIV.txt
Roman 15.txt    Roman  XV.txt
Roman 16.txt    Roman  XVI.txt
Roman 17.txt    Roman  XVII.txt
Roman 18.txt    Roman  XVIII.txt
Roman 19.txt    Roman  XIX.txt
Roman 20.txt    Roman  XX.txt
Roman 21.txt    Roman  XXI.txt
Roman 25.txt    Roman  XXV.txt
Roman 40.txt    Roman  XL.txt
Roman 50.txt    Roman  L.txt
Roman 60.txt    Roman  LX.txt
Roman 70.txt    Roman  LXX.txt
Roman 78.txt    Roman  LXXVIII.txt
Roman 79.txt    Roman  LXXIX.txt
Roman 80.txt    Roman  LXXX.txt
Roman 81.txt    Roman  LXXXI.txt
Roman 90.txt    Roman  XC.txt
Roman 100.txt    Roman  C.txt
Roman 101.txt    Roman  CI.txt
Roman 123.txt    Roman  CXXIII.txt
Roman 150.txt    Roman  CL.txt
Roman 200.txt    Roman  CC.txt
Roman 300.txt    Roman  CCC.txt
Roman 349.txt    Roman  CCCXLIX.txt
Roman 400.txt    Roman  CD.txt
Roman 450.txt    Roman  CDL.txt
Roman 499.txt    Roman  CDXCIX.txt
Roman 500.txt    Roman  D.txt
Roman 600.txt    Roman  DC.txt
Roman 700.txt    Roman  DCC.txt
Roman 800.txt    Roman  DCCC.txt
Roman 888.txt    Roman  DCCCLXXXVIII.txt
Roman 900.txt    Roman  CM.txt
Roman 902.txt    Roman  CMII.txt
Roman 1000.txt    Roman  M.txt
Roman 1234.txt    Roman  MCCXXXIV.txt
Roman 1600.txt    Roman  MDC.txt
Roman 1700.txt    Roman  MDCC.txt
Roman 1900.txt    Roman  MCM.txt
Roman 1999.txt    Roman  MCMXCIX.txt
Roman 2010.txt    Roman  MMX.txt
Roman 2344.txt    Roman  MMCCCXLIV.txt
Roman 3999.txt    Roman  MMMCMXCIX.txt
Roman 4002.txt    Roman  MMMMII.txt

Please see HELP and MANUAL in Wiki for more info.
If ReNamer had helped you, please donate a coin to Denis or buy a Pro license for commercial use. (Lite vs Pro)

Offline

#3 2010-01-09 10:48

SafetyCar
Senior Member
Registered: 2008-04-28
Posts: 446
Website

Re: Roman Numerals Latin Numbers serialize insert

This script can be tested with the analyze window

It's just the conversion, not the serialization, it works until 3000000...

Const
  AllFulls = 'I|X|C|M|(X)|(C)|(M)';
  AllHalves = 'V|L|D|(V)|(L)|(D)';

var
  Fulls, Halves: TStringsArray;
  Arabic, Roman: WideString;
  I, U: Integer;
  
begin
  Fulls := WideSplitString(AllFulls, '|');
  Halves := WideSplitString(AllHalves, '|');
  
  Arabic := FileName;
  Roman := '';
  
  for I:=0 to Length(Arabic)-1 do
  begin
    U := StrToInt(Arabic[Length(Arabic)-I]);
    If U = 0 then Roman := Roman;
    If U = 1 then Roman := Fulls[i] + Roman;
    If U = 2 then Roman := Fulls[i] + Fulls[i] + Roman;
    If U = 3 then Roman := Fulls[i] + Fulls[i] + Fulls[i] + Roman;
    If U = 4 then Roman := Fulls[i] + Halves[i] + Roman;
    If U = 5 then Roman := Halves[i] + Roman;
    If U = 6 then Roman := Halves[i] + Fulls[i] + Roman;
    If U = 7 then Roman := Halves[i] + Fulls[i] + Fulls[i] + Roman;
    If U = 8 then Roman := Halves[i] + Fulls[i] + Fulls[i] + Fulls[i] + Roman;
    If U = 9 then Roman := Fulls[i] + Fulls[i+1] + Roman;
  end;
  
  FileName := Roman;
end.


Can be useful?

---

EDITED: to reach from 3000(before) to 3000000(now)

Last edited by SafetyCar (2010-01-09 11:41)


If this software has helped you, consider getting your pro version. :)

Offline

#4 2010-01-09 18:15

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,046

Re: Roman Numerals Latin Numbers serialize insert

Yes, That's coding  big_smile


--------------------------------------------------------------------
Idea:
If you want to use this for real filenames instead of 'analyze window' only, modify the script to

FROM
Arabic := FileName;
TO
Arabic := WideExtractBaseName(FileName);


and
FROM
FileName := Roman;
TO
FileName := Roman + WideExtractFileExt(FileName);

And an splitting the file name for non-digit parts is missing, so your script will drop any chars.
I imaging to put your code into an function, and add an another function to split the file name into parts
of numbers [with IsWideCharDigit()] and chars and call the converter function for each digit part.
--------------------------------------------------------------------

However, to use the 'analyze window' is an good idea for an quick check the script.


Please see HELP and MANUAL in Wiki for more info.
If ReNamer had helped you, please donate a coin to Denis or buy a Pro license for commercial use. (Lite vs Pro)

Offline

#5 2010-01-09 18:35

SafetyCar
Senior Member
Registered: 2008-04-28
Posts: 446
Website

Re: Roman Numerals Latin Numbers serialize insert

I ended doing the serialization like this:

var
  Count: Integer;

function ArabicToRoman(Number:Integer):WideString;
var
  Fulls, Halves: TStringsArray;
  AllFulls, AllHalves, Arabic, Roman: WideString;
  I, U: Integer;
  
begin
  Roman  := '';
  Arabic := IntToStr(Number);
  
  AllFulls  := 'I|X|C|M|(X)|(C)|(M)';
  AllHalves := 'V|L|D|(V)|(L)|(D)';
    
  Fulls  := WideSplitString(AllFulls, '|');
  Halves := WideSplitString(AllHalves, '|');
  
  for I:=0 to Length(Arabic)-1 do
  begin
    U := StrToInt(Arabic[Length(Arabic)-I]);
    If U = 0 then Roman := Roman;
    If U = 1 then Roman := Fulls[i] + Roman;
    If U = 2 then Roman := Fulls[i] + Fulls[i] + Roman;
    If U = 3 then Roman := Fulls[i] + Fulls[i] + Fulls[i] + Roman;
    If U = 4 then Roman := Fulls[i] + Halves[i] + Roman;
    If U = 5 then Roman := Halves[i] + Roman;
    If U = 6 then Roman := Halves[i] + Fulls[i] + Roman;
    If U = 7 then Roman := Halves[i] + Fulls[i] + Fulls[i] + Roman;
    If U = 8 then Roman := Halves[i] + Fulls[i] + Fulls[i] + Fulls[i] + Roman;
    If U = 9 then Roman := Fulls[i] + Fulls[I+1] + Roman;
  end;
  
  Result := Roman;
end;

begin
  Count := Count + 1;
  FileName := WideExtractBaseName(FileName) + ' ' + ArabicToRoman(Count) + WideExtractFileExt(FileName);
end.

If this software has helped you, consider getting your pro version. :)

Offline

#6 2010-01-09 20:22

SafetyCar
Senior Member
Registered: 2008-04-28
Posts: 446
Website

Re: Roman Numerals Latin Numbers serialize insert

And this replaces arabic numerals with roman ones

var
  Parts: TStringsArray;
  Replace: WideString;
  R, StrAsInt: Integer;

function ArabicToRoman(Number:Integer):WideString;
var
  Fulls, Halves: TStringsArray;
  AllFulls, AllHalves, Arabic, Roman: WideString;
  I, U: Integer;
  
begin
  If 0<Number then If Number<4000000 then
  begin
    Roman  := '';
    Arabic := IntToStr(Number);
  
    AllFulls  := 'I|X|C|M|(X)|(C)|(M)';
    AllHalves := 'V|L|D|(V)|(L)|(D)';
    
    Fulls  := WideSplitString(AllFulls, '|');
    Halves := WideSplitString(AllHalves, '|');
  
    for I:=0 to Length(Arabic)-1 do
    begin
      U := StrToInt(Arabic[Length(Arabic)-I]);
      If U = 0 then Roman := Roman;
      If U = 1 then Roman := Fulls[i] + Roman;
      If U = 2 then Roman := Fulls[i] + Fulls[i] + Roman;
      If U = 3 then Roman := Fulls[i] + Fulls[i] + Fulls[i] + Roman;
      If U = 4 then Roman := Fulls[i] + Halves[i] + Roman;
      If U = 5 then Roman := Halves[i] + Roman;
      If U = 6 then Roman := Halves[i] + Fulls[i] + Roman;
      If U = 7 then Roman := Halves[i] + Fulls[i] + Fulls[i] + Roman;
      If U = 8 then Roman := Halves[i] + Fulls[i] + Fulls[i] + Fulls[i] + Roman;
      If U = 9 then Roman := Fulls[i] + Fulls[I+1] + Roman;
    end;
  
    Result := Roman;
  end
  else
    Result := IntToStr(Number);
end;

begin
  Replace := WideExtractBaseName(FileName);
  Replace := ReplaceRegEx(Replace, '(\d+)', '|$1|', False, True);

  Parts := WideSplitString(Replace, '|');

  Replace := ''; // Reset to rebuild from 0

  For R:=0 to Length(Parts)-1 do
  begin
    StrAsInt := StrToInt(Parts[R]);
    If StrAsInt=-1 then Parts[R]:=Parts[R] else Parts[R]:=ArabicToRoman(StrAsInt);
    Replace := Replace + Parts[R];
  end;
  
  FileName := Replace + WideExtractFileExt(FilePath);
end.

Someone could give me his opinion about the way I did the replacements?

I filtered everything again after spliting, this could be avoided? I would prefer to just go and request the replacement without checking.

From what I see the MatchesRegEx can get just the numbers, to do it like I want, but using it I don't know how to restore each thing to its place...

Is it possible? roll


(I don't need this code but its a good way to learn for future situations tongue )


If this software has helped you, consider getting your pro version. :)

Offline

#7 2010-01-13 21:10

prologician
Member
Registered: 2009-01-30
Posts: 84

Re: Roman Numerals Latin Numbers serialize insert

It's not a serialize, as per what this question is asking... but I actually already addressed some of this very same mania months ago. wink

Thread post, if you want to reexplore: http://www.den4b.com/forum/viewtopic.php?id=642 (It took me a lil while to find it, and I'm surprised it didn't show up in searches. Heh.)

Offline

#8 2010-02-05 12:10

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,067

Re: Roman Numerals Latin Numbers serialize insert

Can someone put up the final version (or few different versions if they do different things) on to Wiki?

I have created a stab record at ReNamer:Scripts and the article should go here:

ReNamer:Scripts:Roman numerals serialization

Offline

#9 2010-02-05 13:49

eR@SeR
Senior Member
From: Земун, Србија
Registered: 2008-01-23
Posts: 328

Re: Roman Numerals Latin Numbers serialize insert

SafetyCar wrote:

Someone could give me his opinion about the way I did the replacements?

Great job SafetyCar big_smile
I've found some converter, played around with larger numbers and it says:
5046008 in Roman Numerals is not convertable, number exceeds 3999999. So that is maximum, right?
Denis, can you add SafetyCar's script to pascal script?


TRUTH, FREEDOM, JUSTICE and FATHERLAND are the highest morale values which human is born, lives and dies for!

Offline

#10 2010-02-05 15:13

SafetyCar
Senior Member
Registered: 2008-04-28
Posts: 446
Website

Re: Roman Numerals Latin Numbers serialize insert

den4b wrote:

Can someone put up the final version (or few different versions if they do different things) on to Wiki?

I have created a stab record at ReNamer:Scripts and the article should go here:

ReNamer:Scripts:Roman numerals serialization

I'll try (maybe I'll need some help) to do it later when I have a little more time.

Last edited by SafetyCar (2010-02-05 15:14)


If this software has helped you, consider getting your pro version. :)

Offline

Board footer

Powered by FluxBB