thealienz1 has asked for the wisdom of the Perl Monks concerning the following question:
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: looking simple regexp for arff file format
by l.frankline (Hermit) on Nov 29, 2005 at 07:29 UTC |