0

I have a question on Perl. I need to extract arrays and print in the columns below. The tricky part is that each word has different pronunciation types (which is specified in P or S) and each type is associated with its corresponding pronunciation and syllable shape. My codes did not work. It showed me syntax errors. Input (the data is located in celex corpus). The following is one example of the thousands of lines.

Input

31259\open\635\3\P\5-p@n[VV][CVC][@U][p@n]\P\5-pH[VV][CS][@U][pn,]\S\5-pF[VV][CS][@U][pm,] ........ ........

Output needs to look like this

WordForm Frequency Type Pronunciation SyllableShape

open 635 P [@U] [p@n] [VV] [CVC]

open 635 P [@U] [pn,] [VV] [CS]

open 635 S [@U] [pm,] [VV] [CS]

...

My codes

!/usr/bin/perl -w

use warnings;

Open file for reading

open my $f, '<' ,"/corpora/celex_release_2/english/epl/epl.cd " or die "No file!";

Open file for writing

open my $o, '>', "epl.cd";

Write out tab-separated column names

print $o "WordForm\tFrequency\tType\tPronunciation\tSyllableShape\n";

While not end of file

while() { # read line into variable ‘line’
$line = $_;

# remove line boundary symbols chomp($line);

# split strings into vector of space-separated tokens @c = split(//\ , $line)

Increment index for type, pronunciation and syllable shape

$i = 4 $j = $i + 2 $k =$i + 1

# for all the arrays in the line, $i is the position of the first pronunciation type.
for($i =4; $i <=$#c; $i+=4) {

# print WordForm, Frequency, Type, Pronunciation and SyllableShape print $o $c[1] . "\t" . $c[2] . "\t" . $c[$i] . “\t” . $c[$j]. “\t” . $c[$k] . “\n”;. }

}

Close files

close($f); close($o);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.