#!/usr/bin/perl use strict; use warnings; die "Usage: $0 []\n" if @ARGV < 1; { my %words; my $file=shift; open my $fh, '<', $file or die "Can't open `$file': $!\n"; while (<$fh>) { chomp; my ($first, @rest)=split; $words{$first}{$_}=1 for @rest; } sub matchword { my $word=shift; my $uword=uc $word; return $word if $words{$uword}; $words{$_}{$uword} and return "mainterm:$_:matchedterm:$word" for sort keys %words; return; # nothing if nothing is found } } while (<>) { chomp; my ($id, undef, $abs)=split /\|/; my @sentences=split /\./, $abs; print "$id|"; for (0..$#sentences) { print '<', $_+1, '>', join ' ', map matchword($_), split ' ', $sentences[$_]; } print "\n"; } __END__