#!/usr/bin/perl

$yourdir = 'I:\syn\synonyme';
my $filecount = 0;

opendir(INDIR,$yourdir) or die "$!";
my @files = readdir INDIR;
close INDIR;

open(SYN,">syn-part2-notchecked.txt");

foreach my $inputFile (@files) {

	next if($inputFile=~/^\./);		# ignore . files
	next if($inputFile=~/\.pl/);	# perl file to ignore
	next if(-d $inputFile);			# Ignore directories
	my $string = "";

	open(RH,"<$yourdir\\$inputFile");
		while(<RH>){
			$string .= $_;
		}; # while(<RH>){
	close RH;
	
	my @content		= split("\n", $string);
	my $linecount	= 0;
	my $synonym		= "";
	my $syncount	= 0;
	my $last		= "";
	foreach my $line (@content) {
		eval {

			if ( $line =~ /\s+<\/b> <br>/i) {
				$line =~ s/<br>//ig;
				$line =~ s/<\/b>//;
				$line =~ s/^\s+//;
				$line =~ s/\s+$//;
				# print "LINE: $line\n";
				$synonym .= "$line," if ( $line ne $last || $line !~ /$last/i);
				$syncount++ if ( $line ne $last || $line !~ /$last/i);
				$last = $line;
			}; # if ( $line =~ /\s+<\/b> <br>/i) {
		
		};
		
		$linecount++;

	}; # foreach my $line (@content) {

	chop $synonym;
	print SYN "$synonym\n" if ( $syncount > 2 && $synonym !~ /\s/ );
	# print "SYNONYM: $synonym\n" if ( $syncount > 1 );
	
	my $file = $inputFile;
	$file =~ s/\.html//igs;
	print "[$filecount/$#files] $file\n";

	$linecount	= 0;
	$synonym	= "";
	$syncount	= 0;
	$string		= "";

	$filecount++;

}; # foreach my $inputFile (@files) {
