Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Hello monks

I am currently working on a data mining algorithm program in Perl, which requires the need to read the arff file format. Currently, I have gotten as far as I can in a regular expression I am working on.

The regexp is being designed to load from the arff file the @attribute directive. Currently I am trying to implement the different possible formats of this into a single regexp.

possible values
  • @attribute 'Sex' { Male, Female}
  • @attribute 'Feature 0' real
  • @attribute 'Feature 1' real
  • @attribute 'Feature 2' real
  • @attribute Malic_acid REAL
  • @attribute Ash REAL

With my regexp I am trying to pull the name and type from directive line. So I would get the name=Sex and type=Male, Female or name=Feature 0 and type=real, etc... Currently this the code I have written for testing.

my @lines = ( "@attribute 'Sex' { Male, Female}", "@attribute 'Feature 0' real", "@attribute 'Feature 1' real", "@attribute 'Feature 2' real", "@attribute Malic_acid REAL", "@attribute Ash REAL" ); foreach my $line (@lines) { $line =~ /^@attribute\s+[']?(.*?)[']?\s+[{]?(.*?)[}]?$/; print "relation name: $1\n"; print "type: $2\n"; }

With the current output of the program being

perl test.pl relation name: Sex type: Male, Female relation name: Feature type: 0' real relation name: Feature type: 1' real relation name: Feature type: 2' real relation name: Malic_acid type: REAL relation name: Ash type: REAL

As you can see the relation name for the Feature 0,1,2 are not being correctly read. I no I am so close, but it is getting late, and I have no idea where I am going with this regexp. I though I'd leave it open for the monks to tinker with.

Night


In reply to looking simple regexp for arff file format by thealienz1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (6)
    As of 2019-11-14 11:23 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Strict and warnings: which comes first?



      Results (77 votes). Check out past polls.

      Notices?