#!/usr/bin/perl # Copyright 13th. October 2008, Cotman University # http://www.cotmanuniversity.com # Created by Dr. Peter Kjeldsen # Department for Computational Linguistics # Conversion of CVS format to WordFast TM format # File name: csvwf.pl # # Instructions # Change name of input file, source and target language # as required. # Run from command prompt perl csvwf.pl # # Setting up formated variable for handling date and time ($sec, $min, $hour, $mday, $mon, $year) = localtime(time); $mon++; $year+= 1900; $hour = sprintf("%02d", $hour); $min = sprintf("%02d", $min); $sec = sprintf("%02d", $sec); $timestamp = "$year" . "$mon" . "$mday" . "~" . "$hour$min$sec"; $creationtool = "Lingualizer tmXl8r"; $userid = "PK"; $srclang = "EN-US"; $tgtlang ="DA-01"; # Opening input file open (TXT, "; close (TXT); # Opening/creating output file open (TM, ">>lingualizerWfTM.txt") or die ("Cannot open file!"); # Creation of header for output file print TM '%'. "$timestamp\t". '%User ID,' ."$userid,\t" . '%' . "$srclang\t" . '%'. "$creationtool" . '/00' . "\t" . '%' . "$tgtlang\t" . '%---89668861' . "\t\t\t\n.\n"; # Looping through input file content line by line foreach $lines(@text) { # Splitting line content and creating translation units @line = split (/","/, $lines); # Chopping leading " from source string by reversing, chopping and reversing $words = reverse($line[0]); $char = chop($words); $rev2str = reverse($words); $CleanSource = $rev2str; # Chopping \n from the end of target string $char = chop($line[1]); $TargetChop = $line[1]; # Chopping " from the end of the target string $char = chop($TargetChop); $CleanTarget = $TargetChop; # Creating the translation unit print TM "$timestamp\t" . "$userid\t" . "0\t" ."$srclang\t" . "$CleanSource\t" . "$tgtlang\t" . "$CleanTarget\t\t\t\n"; } # Closing output file close (TM);