Example 2: Probabilistic context-free example

The parser can be used by running:
java -jar stefy.jar
(or: java -classpath stefy.jar stefy.Interpreter).

Input:

// Test 02 : testing probabilistic grammars
// $Id: 02,v 1.1 2007/03/24 04:04:10 vlado Exp $

print "TEST 02\n\n";

set PPath logP

[S] -> [NP] [VP].

[NP] -> [N]     / 0.4
[NP] -> [N] [N] / 0.2
[NP] -> [D] [N] / 0.4

[VP] -> [V] [NP] /0.5
[VP] -> [V] [PP] /0.5

[PP] -> [P] [NP].

[V] -> like  /0.3
[V] -> flies /0.7

[P] -> like.

[N] -> time  / 0.5
[N] -> arrow / 0.3
[N] -> flies / 0.2

[D] -> an .

tokenize <s> time flies like an arrow </s>
parse
print parse trees
print BestParse

println "\n\nAll edges:\n"
foreachpassiveedge e 'println e + "\n"';

println "\n\n--------------------\nWith pruning:\n\n";

// Pruning example
set prunePolicy 3  // Prune all expept the most probable edge over a
                   // span.  Policies 1 and 2 implement beam search,
		   // and 3 and 4 leave a fixed number of most
		   // probable edges over a span.
		   // For more information see API specification,
		   // Interpreter.
set pruneN 1

tokenize <s> time flies like an arrow </s>
parse
print parse trees
print BestParse

println "\n\nAll edges:\n"
foreachpassiveedge e 'println e + "\n"';

Output:

// Test 02 : testing probabilistic grammars
// $Id: 02,v 1.1 2007/03/24 04:04:10 vlado Exp $

print "TEST 02\n\n";

set PPath logP

[S] -> [NP] [VP].

[NP] -> [N]     / 0.4
[NP] -> [N] [N] / 0.2
[NP] -> [D] [N] / 0.4

[VP] -> [V] [NP] /0.5
[VP] -> [V] [PP] /0.5

[PP] -> [P] [NP].

[V] -> like  /0.3
[V] -> flies /0.7

[P] -> like.

[N] -> time  / 0.5
[N] -> arrow / 0.3
[N] -> flies / 0.2

[D] -> an .

tokenize <s> time flies like an arrow </s>
parse
print parse trees
print BestParse

println "\n\nAll edges:\n"
foreachpassiveedge e 'println e + "\n"';

println "\n\n--------------------\nWith pruning:\n\n";

// Pruning example
set prunePolicy 3  // Prune all expept the most probable edge over a
                   // span.  Policies 1 and 2 implement beam search,
		   // and 3 and 4 leave a fixed number of most
		   // probable edges over a span.
		   // For more information see API specification,
		   // Interpreter.
set pruneN 1

tokenize <s> time flies like an arrow </s>
parse
print parse trees
print BestParse

println "\n\nAll edges:\n"
foreachpassiveedge e 'println e + "\n"';


© 2000-2007 Vlado Keselj, last update: March 27, 2007.