#! /usr/bin/perl

use LWP::Simple;
use bytes;
use utf8;

$inbody = 0;


while (<>) {
	if ($inbody > 0) {
		# eliminate XML
		chomp;
		s/<.+>//g;
	
		#print ("line is $_");
		# split text into words
		undef @words;
		@words = split(/[ \.;]/);


		# process each word and output the result
		
		foreach $word (@words) {
			if ($word =~ /[a-z]/ ) {
				$bare_word = $word;
				$bare_word =~ s/[\\\/\(\)\*,\.\;]//g;
				my $url = "http://www.perseus.tufts.edu/hopper/xmlmorph?lang=greek&lookup=$bare_word\n";
		  		#print ("url is $url\n");
		  		my $content = get $url;		
				#if ($content =~ /<lemma>(.+)<\/lemma>/) {
 					#print ("content is $content\n");
 			 	# 	print ("lemma is $1 \n");	
 				#}
				(@lem) = ($content =~ /<lemma>(.+)<\/lemma>/g);
				foreach $e (@lem) {
					$forms{$e}++;
					#print ("added lemma $e to forms list\n");
				}
				foreach $form (keys %forms) {
					print ("$form ");
				}
				undef %forms;
			}

		}
		print ("\n");		

	

	} else {
	$inbody++ if $_ =~ /\/teiheader/i;
	
	}

}






