Package apg
Class Statistics
- java.lang.Object
-
- apg.Statistics
-
public class Statistics extends java.lang.Object
The Statistics class is used to collect and display syntax tree node statistics. The statistics count the number of times each node was visited (hit) by the parser in its journey through the syntax tree and the result of each hit - that is, whether the node matched a phrase of the input string or not.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
displayStats(java.io.PrintStream out, java.lang.String type)
Displays the statistics on the output device.void
displayStats(java.io.PrintStream out, java.lang.String type, boolean alpha)
Displays the statistics on the output device.void
enableCumulate(boolean enable)
Called to enable or disable the cumulation of statistics.int
getHits(java.lang.String type)
Returns the hit count for the requested node type.
-
-
-
Method Detail
-
enableCumulate
public void enableCumulate(boolean enable)
Called to enable or disable the cumulation of statistics. Instances of a Parsers will sometimes be rerun several or many times on different strings or with different parameters of some sort. Occasionally the user will wish to see the total statistics of all parses. If cumulation is enabled, the Statistics class will collect a running sum of the statistics of all parses of the same instance of the Parser.- Parameters:
enable
- iftrue
, Statistics will cumulate statistics for all parses of the Parser instance. Iffalse
, the statistics will be reset to zero (0) for each parse. The default value isenable=false
.
-
getHits
public int getHits(java.lang.String type) throws java.lang.Exception
Returns the hit count for the requested node type.- Parameters:
type
- determines the type of hit count to return.
"match"
- hit count for nodes that were matched with non-empty phrases
"empty"
- hit count for nodes that were matched with empty phrases
"nomatch"
- hit count for nodes that were did not match any phrase at all
"total"
- total of all hits of all of the above types- Returns:
- the hit count for the requested type
- Throws:
java.lang.Exception
- thrown if the type parameter is not valid
-
displayStats
public void displayStats(java.io.PrintStream out, java.lang.String type) throws java.lang.Exception
Displays the statistics on the output device.- Parameters:
out
- the output device.type
- the type of statistics to display
"operators"
- display node hits for all operator types except rule and UDT
"rules"
- display node hits for rule name nodes only
"udt"
- display node hits for UDT nodes only
Rule name or UDT node names are ordered descending on hit count.- Throws:
java.lang.Exception
- thrown if the type is none of the above.
-
displayStats
public void displayStats(java.io.PrintStream out, java.lang.String type, boolean alpha) throws java.lang.Exception
Displays the statistics on the output device.- Parameters:
out
- the output device.type
- the type of statistics to display
"operators"
- display node hits for all operator types except rule and UDT
"rules"
- display node hits for rule name nodes only
"udt"
- display node hits for UDT nodes onlyalpha
- iftrue
, the rule or UDT nodes are displayed in alphabetical order, iffalse
, rule or UDT nodes are ordered descending on hit count.- Throws:
java.lang.Exception
- thrown if the type is none of the above.
-
-