9.2.6 A Test Interface

Here is a small interface: it binds a variable (Chart) to the result of parsing a string i.e. the final chart. The function Result then takes this chart as input, filters from the list of edges listed in the minimal position of the chart those edges which end in the maximal position and returns their category.

<main.oz>=
declare Modules = ['parser.ozf' 'sentences.ozf' 'grammar.ozf' 'lexicon.ozf' 'ChartToWindow.ozf']
declare [P S G Lexicon Ch2Win] = {Link Modules}
declare Sentences = S.testSuite
declare MakeParser = P.new
declare Grammar = G.rules
declare  fun{Result Chart}
            {Map {Filter {Chart.get Chart.min}
                  fun{$ E} E.'end' == Chart.max end}
             fun{$ E} E.cat end}
         end 
declare Parser = {MakeParser Grammar Lexicon}
declare C2W = Ch2Win.chartToWindow
 
%% Test
for Sentence in Sentences do 
   {Inspect Sentence}
   Chart={Parser Sentence}
   Edges = {Chart.toList}
   Res = {Filter Edges fun{$ E}
                          {And {And
                                E.begin==Chart.min  
                                E.'end'==Chart.max}
                           E.cat==s}
                       end}
in   
   {Inspect 'number of parses:'#{Length Res}}
end 
 
 
declare W = {C2W {Parser [john runs]}}
declare W = {C2W {Parser [john sees the man with the telescope]}}


Denys Duchier, Claire Gardent and Joachim Niehren
Version 1.3.99 (20050412)