Results 1 to 14 of 14
  1. #1
    dunworry is offline Member
    Join Date
    Dec 2010
    Posts
    6
    Rep Power
    0

    Default How to identify a roman numeral

    Hello All, I am having trouble identifying a roman numeral. I need to separate the txt file by chapters so i use this pattern to do it, but it does not work.

    Java Code:
    Pattern.compile("chapter [i+x*c*l*v*][i*x+c*l*v*][i*x*c+l*v*][i*x*c*l+v*][i*x*c*l*v+]")
    any ideas?

    thanks alot

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Can you show us the content of your text file? It does not work sense, do you end-up with any error?


  3. #3
    dunworry is offline Member
    Join Date
    Dec 2010
    Posts
    6
    Rep Power
    0

    Default

    for example i have a book in .txt format and i want to divide the .txt up by it's chapters

    Java Code:
    valiant chase of this unnearable brute.  The Virgin crowding all sail, made
    after her four young keels, and thus they all disappeared far to leeward,
    still in bold, hopeful chase.  Oh!  many are the Fin-Backs, and many are the
    Dericks, my friend.
    .. <p 359 >
    .. < chapter lxxxii 24  THE HONOR AND GLORY OF WHALING >
    
         There are some
    enterprises in which a careful disorderliness is the true method.  The more I
    but in another book it might simple be

    Java Code:
     CHAPTER I
    no errors. just it doesn't show all of the chapters of the book when i test it. there might be 150 chapters and it only shows 130

  4. #4
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    case sensitity is a must?

  5. #5
    dunworry is offline Member
    Join Date
    Dec 2010
    Posts
    6
    Rep Power
    0

    Default

    ^ nope. i turn the entire txt to lowercase

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  7. #7
    dunworry is offline Member
    Join Date
    Dec 2010
    Posts
    6
    Rep Power
    0

    Default

    nope. the second book doesn't have the <> braces

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  9. #9
    dunworry is offline Member
    Join Date
    Dec 2010
    Posts
    6
    Rep Power
    0

    Default

    What?? I can already use the pattern: "chapter [icvxl]"

    but the only problem with that is if something like that is in the book for example

    "did u read the chapter coca?

    Is there a way of just putting 'chapter + (c or l or v or x or i) + space'

  10. #10
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Maybe you need a way to distunguish chapter headings in your text file so it will never be confused with ordinary chapter text

  11. #11
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by dunworry View Post
    What?? I can already use the pattern: "chapter [icvxl]"

    but the only problem with that is if something like that is in the book for example

    "did u read the chapter coca?

    Is there a way of just putting 'chapter + (c or l or v or x or i) + space'
    I mean you've to validate the pattern at the beginning of the line of text. You don't need to find within the sentence right?

  12. #12
    dunworry is offline Member
    Join Date
    Dec 2010
    Posts
    6
    Rep Power
    0

    Default

    yes.. how would i go about of doing that

  13. #13
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    You have to split the text file with the fullstops. Then validate each with the pattern you already define.

  14. #14
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,453
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by dunworry View Post
    Is there a way of just putting 'chapter + (c or l or v or x or i) + space'
    You could try recognizing trailing spaces: "chapter\\s+[ivxlcdm]+\\s+" Just in case there are more space between the word 'chapter' and the Roman number I put a \\s+ between those two parts as well. The regular expression has to end with at least one space too.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Convert the number to Roman numerals
    By ŖΫ ỏ Ңόρę in forum New To Java
    Replies: 9
    Last Post: 11-29-2012, 10:44 PM
  2. Replies: 11
    Last Post: 11-02-2010, 05:46 PM
  3. Convert roman numerals
    By matzahboy in forum New To Java
    Replies: 4
    Last Post: 02-21-2010, 10:06 PM
  4. Roman numeral to Decimal
    By hector100 in forum Advanced Java
    Replies: 3
    Last Post: 04-04-2009, 07:48 PM
  5. Convert roman numerals to integers
    By Felissa in forum Advanced Java
    Replies: 2
    Last Post: 07-01-2007, 11:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •