#!/usr/local/bin/ruby -w
# $Id: EO.rb,v 1.13 2001/08/27 23:04:48 ser Exp $
#
# An example of how to use the Esperanto parser library.
# You can parse anything from paragraphs down to individual words.  Paragraphs
# contain sentances, which contain phrases, which contain words.  

# If you want to parse an entire paragraph, require Dokumento and parse the 
# text by creating a new Paragrafo
#
# If you just want to parse a single word, require Parser.  The parse() method
# returns all possible interpretations of the word.
# See runtest.rb for an example of how to parse single words.

require "Dokumento"

loop do
	printf "### "
	line = gets.chop
	break if line == "quit"

	paragrafo = EO::Paragrafo.new( line ) { printf "." ; $stdout.flush }
	puts
	paragrafo.each { |sintagmo|
		sintagmo.each { |frazo|
			frazo.each_index { |ind|
				vortoj = EO::Parser::filter frazo[ind]
				#vortoj = frazo[ind].sort{|x,y| y.validity <=> x.validity}
				#vortoj = frazo[ind]
				printf "[ " if vortoj.size > 1
				# Each word can have multiple interpretations
				vortoj.each_index { |index|
					printf vortoj[index].anglu
					printf " || " if index < vortoj.size-1
					$stdout.flush
				}
				printf "]" if vortoj.size > 1
				printf " " if ind < frazo.size-1
			}
			printf frazo.punctuate
			printf " "
		}
		printf sintagmo.punctuate
		printf " "
	}
	
	puts
end
