Java APG, Version 1.0
Author Lowell D. Thomas
Copyright © Coast to Coast Research, Inc. 2011

com.coasttocoastresearch.apg
Class Statistics

java.lang.Object
  extended by com.coasttocoastresearch.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
 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.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

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 only
alpha - if true, the rule or UDT nodes are displayed in alphabetical order, if false, rule or UDT nodes are ordered descending on hit count.
Throws:
java.lang.Exception - thrown if the type is none of the above.

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 - if true, Statistics will cumulate statistics for all parses of the Parser instance. If false, the statistics will be reset to zero (0) for each parse. The default value is enable=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

Java APG, Version 1.0
Author Lowell D. Thomas
Copyright © Coast to Coast Research, Inc. 2011

Licence Notification

All the software in this distribution is free software:
you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program in the COPYING file. If not, see GPL, Version 2
or GPL, Version 3 or write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.