Source Code Cross Referenced for Check.java in  » Science » weka » weka » core » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Science » weka » weka.core 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *    This program is free software; you can redistribute it and/or modify
003:         *    it under the terms of the GNU General Public License as published by
004:         *    the Free Software Foundation; either version 2 of the License, or
005:         *    (at your option) any later version.
006:         *
007:         *    This program is distributed in the hope that it will be useful,
008:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
009:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
010:         *    GNU General Public License for more details.
011:         *
012:         *    You should have received a copy of the GNU General Public License
013:         *    along with this program; if not, write to the Free Software
014:         *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
015:         */
016:
017:        /*
018:         * CheckScheme.java
019:         * Copyright (C) 2006 University of Waikato, Hamilton, New Zealand
020:         *
021:         */
022:
023:        package weka.core;
024:
025:        import java.util.Enumeration;
026:        import java.util.Vector;
027:
028:        /**
029:         * Abstract general class for testing in Weka.
030:         *
031:         * @author FracPete (fracpete at waikato dot ac dot nz)
032:         * @version $Revision: 1.1 $
033:         */
034:        public abstract class Check implements  OptionHandler {
035:
036:            /** Debugging mode, gives extra output if true */
037:            protected boolean m_Debug = false;
038:
039:            /** Silent mode, for no output at all to stdout */
040:            protected boolean m_Silent = false;
041:
042:            /**
043:             * Returns an enumeration describing the available options.
044:             *
045:             * @return an enumeration of all the available options.
046:             */
047:            public Enumeration listOptions() {
048:                Vector result = new Vector();
049:
050:                result.addElement(new Option("\tTurn on debugging output.",
051:                        "D", 0, "-D"));
052:
053:                result.addElement(new Option(
054:                        "\tSilent mode - prints nothing to stdout.", "S", 0,
055:                        "-S"));
056:
057:                return result.elements();
058:            }
059:
060:            /**
061:             * Parses a given list of options. 
062:             *
063:             * @param options the list of options as an array of strings
064:             * @throws Exception if an option is not supported
065:             */
066:            public void setOptions(String[] options) throws Exception {
067:                setDebug(Utils.getFlag('D', options));
068:
069:                setSilent(Utils.getFlag('S', options));
070:            }
071:
072:            /**
073:             * Gets the current settings of the CheckClassifier.
074:             *
075:             * @return an array of strings suitable for passing to setOptions
076:             */
077:            public String[] getOptions() {
078:                Vector result;
079:
080:                result = new Vector();
081:
082:                if (getDebug())
083:                    result.add("-D");
084:
085:                if (getSilent())
086:                    result.add("-S");
087:
088:                return (String[]) result.toArray(new String[result.size()]);
089:            }
090:
091:            /**
092:             * Tries to instantiate a new instance of the given class and checks whether
093:             * it is an instance of the specified class. For convenience one can also
094:             * specify a classname prefix (e.g., "weka.classifiers") to avoid long 
095:             * classnames and then instantiate it with the shortened classname (e.g.,
096:             * "trees.J48").
097:             * 
098:             * @param prefix	the classname prefix (without trailing dot)
099:             * @param cls		the class to check whether the generated object is an
100:             * 			instance of
101:             * @param classname	the classname to instantiate
102:             * @param options	optional options for the object
103:             * @return		the configured object
104:             * @throws Exception	if instantiation fails
105:             */
106:            protected Object forName(String prefix, Class cls,
107:                    String classname, String[] options) throws Exception {
108:
109:                Object result;
110:
111:                result = null;
112:
113:                try {
114:                    result = Utils.forName(cls, classname, options);
115:                } catch (Exception e) {
116:                    // shall we try with prefix?
117:                    if (e.getMessage().toLowerCase().indexOf("can't find") > -1) {
118:                        try {
119:                            result = Utils.forName(cls, prefix + "."
120:                                    + classname, options);
121:                        } catch (Exception ex) {
122:                            if (e.getMessage().toLowerCase().indexOf(
123:                                    "can't find") > -1) {
124:                                throw new Exception("Can't find class called '"
125:                                        + classname + "' or '" + prefix + "."
126:                                        + classname + "'!");
127:                            } else {
128:                                throw new Exception(ex);
129:                            }
130:                        }
131:                    } else {
132:                        throw new Exception(e);
133:                    }
134:                }
135:
136:                return result;
137:            }
138:
139:            /**
140:             * Begin the tests, reporting results to System.out
141:             */
142:            public abstract void doTests();
143:
144:            /**
145:             * Set debugging mode
146:             *
147:             * @param debug true if debug output should be printed
148:             */
149:            public void setDebug(boolean debug) {
150:                m_Debug = debug;
151:                // disable silent mode, if necessary
152:                if (getDebug())
153:                    setSilent(false);
154:            }
155:
156:            /**
157:             * Get whether debugging is turned on
158:             *
159:             * @return true if debugging output is on
160:             */
161:            public boolean getDebug() {
162:                return m_Debug;
163:            }
164:
165:            /**
166:             * Set slient mode, i.e., no output at all to stdout
167:             *
168:             * @param value whether silent mode is active or not
169:             */
170:            public void setSilent(boolean value) {
171:                m_Silent = value;
172:            }
173:
174:            /**
175:             * Get whether silent mode is turned on
176:             *
177:             * @return true if silent mode is on
178:             */
179:            public boolean getSilent() {
180:                return m_Silent;
181:            }
182:
183:            /**
184:             * prints the given message to stdout, if not silent mode
185:             * 
186:             * @param msg         the text to print to stdout
187:             */
188:            protected void print(Object msg) {
189:                if (!getSilent())
190:                    System.out.print(msg);
191:            }
192:
193:            /**
194:             * prints the given message (+ LF) to stdout, if not silent mode
195:             * 
196:             * @param msg         the message to println to stdout
197:             */
198:            protected void println(Object msg) {
199:                print(msg + "\n");
200:            }
201:
202:            /**
203:             * prints a LF to stdout, if not silent mode
204:             */
205:            protected void println() {
206:                print("\n");
207:            }
208:
209:            /**
210:             * runs the CheckScheme with the given options
211:             * 
212:             * @param check	the checkscheme to setup and run
213:             * @param options	the commandline parameters to use
214:             */
215:            protected static void runCheck(Check check, String[] options) {
216:                try {
217:                    try {
218:                        check.setOptions(options);
219:                        Utils.checkForRemainingOptions(options);
220:                    } catch (Exception ex) {
221:                        String result = ex.getMessage()
222:                                + "\n\n"
223:                                + check.getClass().getName().replaceAll(
224:                                        ".*\\.", "") + " Options:\n\n";
225:                        Enumeration enm = check.listOptions();
226:                        while (enm.hasMoreElements()) {
227:                            Option option = (Option) enm.nextElement();
228:                            result += option.synopsis() + "\n"
229:                                    + option.description() + "\n";
230:                        }
231:                        throw new Exception(result);
232:                    }
233:
234:                    check.doTests();
235:                } catch (Exception ex) {
236:                    System.err.println(ex.getMessage());
237:                }
238:            }
239:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.