Source Code Cross Referenced for TechnicalInformation.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:         * TechnicalInformation.java
019:         * Copyright (C) 2006 University of Waikato, Hamilton, New Zealand
020:         */
021:
022:        package weka.core;
023:
024:        import java.util.Collections;
025:        import java.util.Enumeration;
026:        import java.util.Hashtable;
027:        import java.util.Vector;
028:
029:        /**
030:         * Used for paper references in the Javadoc and for BibTex generation.
031:         * Based on documentation found here: <p/>
032:         * <a href="http://www.ecst.csuchico.edu/~jacobsd/bib/formats/bibtex.html" target="_blank">http://www.ecst.csuchico.edu/~jacobsd/bib/formats/bibtex.html</a>
033:         * <p/>
034:         * BibTex examples can be found here: <p/>
035:         * <a href="http://bib2web.djvuzone.org/bibtex.html" target="_blank">http://bib2web.djvuzone.org/bibtex.html</a>
036:         * 
037:         * @author  fracpete (fracpete at waikato dot ac dot nz)
038:         * @version $Revision: 1.7 $
039:         * @see TechnicalInformationHandler
040:         */
041:        public class TechnicalInformation {
042:
043:            /** the different types of information */
044:            public enum Type {
045:                /** An article from a journal or magazine. */
046:                ARTICLE("article", "An article from a journal or magazine."),
047:                /** A book with an explicit publisher. */
048:                BOOK("book", "A book with an explicit publisher."),
049:                /** A work that is printed and bound, but without a named publisher or sponsoring institution. */
050:                BOOKLET(
051:                        "booklet",
052:                        "A work that is printed and bound, but without a named publisher or sponsoring institution."),
053:                /** The same as inproceedings. */
054:                CONFERENCE("conference", "The same as inproceedings."),
055:                /** A part of a book, which may be a chapter (or section or whatever) and/or a range of pages. */
056:                INBOOK(
057:                        "inbook",
058:                        "A part of a book, which may be a chapter (or section or whatever) and/or a range of pages."),
059:                /** A part of a book having its own title. */
060:                INCOLLECTION("incollection",
061:                        "A part of a book having its own title."),
062:                /** An article in a conference proceedings. */
063:                INPROCEEDINGS("inproceedings",
064:                        "An article in a conference proceedings."),
065:                /** Technical documentation. */
066:                MANUAL("manual", "Technical documentation."),
067:                /** A Master's thesis. */
068:                MASTERSTHESIS("mastersthesis", "A Master's thesis."),
069:                /** Use this type when nothing else fits. */
070:                MISC("misc", "Use this type when nothing else fits."),
071:                /** A PhD thesis. */
072:                PHDTHESIS("phdthesis", "A PhD thesis."),
073:                /** The proceedings of a conference. */
074:                PROCEEDINGS("proceedings", "The proceedings of a conference."),
075:                /** A report published by a school or other institution, usually numbered within a series. */
076:                TECHREPORT(
077:                        "techreport",
078:                        "A report published by a school or other institution, usually numbered within a series."),
079:                /** A document having an author and title, but not formally published. */
080:                UNPUBLISHED("unpublished",
081:                        "A document having an author and title, but not formally published.");
082:
083:                /** the string used in toString()  */
084:                protected String m_Display;
085:
086:                /** the comment about this type */
087:                protected String m_Comment;
088:
089:                /**
090:                 * the constructor
091:                 * 
092:                 * @param display	the string to return in toString()
093:                 * @param comment	a comment about the type
094:                 */
095:                private Type(String display, String comment) {
096:                    m_Display = display;
097:                    m_Comment = comment;
098:                }
099:
100:                /**
101:                 * returns the display string
102:                 * 
103:                 * @return 		the display string
104:                 */
105:                public String getDisplay() {
106:                    return m_Display;
107:                }
108:
109:                /**
110:                 * returns the comment string
111:                 * 
112:                 * @return		the comment string
113:                 */
114:                public String getComment() {
115:                    return m_Comment;
116:                }
117:
118:                /**
119:                 * returns the display string of the Type
120:                 * 
121:                 * @return		the display string
122:                 */
123:                public String toString() {
124:                    return m_Display;
125:                }
126:            }
127:
128:            /** the possible fields */
129:            public enum Field {
130:                /** Usually the address of the publisher or other type of institution. For major publishing houses, van Leunen recommends omitting the information entirely. For small publishers, on the other hand, you can help the reader by giving the complete address. */
131:                ADDRESS(
132:                        "address",
133:                        "Usually the address of the publisher or other type of institution. For major publishing houses, van Leunen recommends omitting the information entirely. For small publishers, on the other hand, you can help the reader by giving the complete address."),
134:                /** An annotation. It is not used by the standard bibliography styles, but may be used by others that produce an annotated bibliography. */
135:                ANNOTE(
136:                        "annote",
137:                        "An annotation. It is not used by the standard bibliography styles, but may be used by others that produce an annotated bibliography."),
138:                /** The name(s) of the author(s), in the format described in the LaTeX book. */
139:                AUTHOR("author",
140:                        "The name(s) of the author(s), in the format described in the LaTeX book."),
141:                /** Title of a book, part of which is being cited. See the LaTeX book for how to type titles. For book entries, use the title field instead. */
142:                BOOKTITLE(
143:                        "booktitle",
144:                        "Title of a book, part of which is being cited. See the LaTeX book for how to type titles. For book entries, use the title field instead."),
145:                /** A chapter (or section or whatever) number. */
146:                CHAPTER("chapter", "A chapter (or section or whatever) number."),
147:                /** The database key of the entry being cross referenced. Any fields that are missing from the current record are inherited from the field being cross referenced. */
148:                CROSSREF(
149:                        "crossref",
150:                        "The database key of the entry being cross referenced. Any fields that are missing from the current record are inherited from the field being cross referenced."),
151:                /** The edition of a book---for example, ``Second''. This should be an ordinal, and should have the first letter capitalized, as shown here; the standard styles convert to lower case when necessary. */
152:                EDITION(
153:                        "edition",
154:                        "The edition of a book---for example, ``Second''. This should be an ordinal, and should have the first letter capitalized, as shown here; the standard styles convert to lower case when necessary."),
155:                /** Name(s) of editor(s), typed as indicated in the LaTeX book. If there is also an author field, then the editor field gives the editor of the book or collection in which the reference appears. */
156:                EDITOR(
157:                        "editor",
158:                        "Name(s) of editor(s), typed as indicated in the LaTeX book. If there is also an author field, then the editor field gives the editor of the book or collection in which the reference appears."),
159:                /** How something strange has been published. The first word should be capitalized. */
160:                HOWPUBLISHED(
161:                        "howpublished",
162:                        "How something strange has been published. The first word should be capitalized."),
163:                /** The sponsoring institution of a technical report. */
164:                INSTITUTION("institution",
165:                        "The sponsoring institution of a technical report."),
166:                /** A journal name. Abbreviations are provided for many journals. */
167:                JOURNAL("journal",
168:                        "A journal name. Abbreviations are provided for many journals."),
169:                /** Used for alphabetizing, cross referencing, and creating a label when the ``author'' information is missing. This field should not be confused with the key that appears in the cite command and at the beginning of the database entry. */
170:                KEY(
171:                        "key",
172:                        "Used for alphabetizing, cross referencing, and creating a label when the ``author'' information is missing. This field should not be confused with the key that appears in the cite command and at the beginning of the database entry."),
173:                /** The month in which the work was published or, for an unpublished work, in which it was written. You should use the standard three-letter abbreviation, as described in Appendix B.1.3 of the LaTeX book. */
174:                MONTH(
175:                        "month",
176:                        "The month in which the work was published or, for an unpublished work, in which it was written. You should use the standard three-letter abbreviation, as described in Appendix B.1.3 of the LaTeX book."),
177:                /** Any additional information that can help the reader. The first word should be capitalized. */
178:                NOTE(
179:                        "note",
180:                        "Any additional information that can help the reader. The first word should be capitalized."),
181:                /** The number of a journal, magazine, technical report, or of a work in a series. An issue of a journal or magazine is usually identified by its volume and number; the organization that issues a technical report usually gives it a number; and sometimes books are given numbers in a named series. */
182:                NUMBER(
183:                        "number",
184:                        "The number of a journal, magazine, technical report, or of a work in a series. An issue of a journal or magazine is usually identified by its volume and number; the organization that issues a technical report usually gives it a number; and sometimes books are given numbers in a named series."),
185:                /** The organization that sponsors a conference or that publishes a manual. */
186:                ORGANIZATION("organization",
187:                        "The organization that sponsors a conference or that publishes a manual."),
188:                /** One or more page numbers or range of numbers, such as 42--111 or 7,41,73--97 or 43+ (the `+' in this last example indicates pages following that don't form a simple range). To make it easier to maintain Scribe-compatible databases, the standard styles convert a single dash (as in 7-33) to the double dash used in TeX to denote number ranges (as in 7--33). */
189:                PAGES(
190:                        "pages",
191:                        "One or more page numbers or range of numbers, such as 42--111 or 7,41,73--97 or 43+ (the `+' in this last example indicates pages following that don't form a simple range). To make it easier to maintain Scribe-compatible databases, the standard styles convert a single dash (as in 7-33) to the double dash used in TeX to denote number ranges (as in 7--33)."),
192:                /** The publisher's name. */
193:                PUBLISHER("publisher", "The publisher's name."),
194:                /** The name of the school where a thesis was written. */
195:                SCHOOL("school",
196:                        "The name of the school where a thesis was written."),
197:                /** The name of a series or set of books. When citing an entire book, the the title field gives its title and an optional series field gives the name of a series or multi-volume set in which the book is published. */
198:                SERIES(
199:                        "series",
200:                        "The name of a series or set of books. When citing an entire book, the the title field gives its title and an optional series field gives the name of a series or multi-volume set in which the book is published."),
201:                /** The work's title, typed as explained in the LaTeX book. */
202:                TITLE("title",
203:                        "The work's title, typed as explained in the LaTeX book."),
204:                /** The type of a technical report---for example, ``Research Note''. */
205:                TYPE("type",
206:                        "The type of a technical report---for example, ``Research Note''."),
207:                /** The volume of a journal or multi-volume book. */
208:                VOLUME("volume",
209:                        "The volume of a journal or multi-volume book."),
210:                /** The year of publication or, for an unpublished work, the year it was written. Generally it should consist of four numerals, such as 1984, although the standard styles can handle any year whose last four nonpunctuation characters are numerals, such as `\\hbox{(about 1984)}'. */
211:                YEAR(
212:                        "year",
213:                        "The year of publication or, for an unpublished work, the year it was written. Generally it should consist of four numerals, such as 1984, although the standard styles can handle any year whose last four nonpunctuation characters are numerals, such as `\\hbox{(about 1984)}'."),
214:                // other fields
215:                /** The authors affiliation. */
216:                AFFILIATION("affiliation", "The authors affiliation."),
217:                /** An abstract of the work. */
218:                ABSTRACT("abstract", "An abstract of the work."),
219:                /** A Table of Contents  */
220:                CONTENTS("contents", "A Table of Contents "),
221:                /** Copyright information. */
222:                COPYRIGHT("copyright", "Copyright information."),
223:                /** The International Standard Book Number. */
224:                ISBN("ISBN", "The International Standard Book Number."),
225:                /** The International Standard Serial Number. Used to identify a journal. */
226:                ISSN("ISSN",
227:                        "The International Standard Serial Number. Used to identify a journal."),
228:                /** Key words used for searching or possibly for annotation. */
229:                KEYWORDS("keywords",
230:                        "Key words used for searching or possibly for annotation."),
231:                /** The language the document is in. */
232:                LANGUAGE("language", "The language the document is in."),
233:                /** A location associated with the entry, such as the city in which a conference took place. */
234:                LOCATION(
235:                        "location",
236:                        "A location associated with the entry, such as the city in which a conference took place."),
237:                /** The Library of Congress Call Number. I've also seen this as lib-congress. */
238:                LCCN("LCCN",
239:                        "The Library of Congress Call Number. I've also seen this as lib-congress."),
240:                /** The Mathematical Reviews number. */
241:                MRNUMBER("mrnumber", "The Mathematical Reviews number."),
242:                /** The price of the document. */
243:                PRICE("price", "The price of the document."),
244:                /** The physical dimensions of a work. */
245:                SIZE("size", "The physical dimensions of a work."),
246:                /** The WWW Universal Resource Locator that points to the item being referenced. This often is used for technical reports to point to the ftp site where the postscript source of the report is located. */
247:                URL(
248:                        "URL",
249:                        "The WWW Universal Resource Locator that points to the item being referenced. This often is used for technical reports to point to the ftp site where the postscript source of the report is located."),
250:                // additional fields
251:                /** A link to a postscript file. */
252:                PS("PS", "A link to a postscript file."),
253:                /** A link to a postscript file. */
254:                PDF("PDF", "A link to a PDF file."),
255:                /** A link to a postscript file. */
256:                HTTP("HTTP", "A hyperlink to a resource.");
257:
258:                /** the string used in toString()  */
259:                protected String m_Display;
260:
261:                /** the comment about this type */
262:                protected String m_Comment;
263:
264:                /**
265:                 * the constructor
266:                 * 
267:                 * @param display	the string to return in toString()
268:                 * @param comment	a comment about the type
269:                 */
270:                private Field(String display, String comment) {
271:                    m_Display = display;
272:                    m_Comment = comment;
273:                }
274:
275:                /**
276:                 * returns the display string
277:                 * 
278:                 * @return		the display string
279:                 */
280:                public String getDisplay() {
281:                    return m_Display;
282:                }
283:
284:                /**
285:                 * returns the comment string
286:                 * 
287:                 * @return		the comment string
288:                 */
289:                public String getComment() {
290:                    return m_Comment;
291:                }
292:
293:                /**
294:                 * returns the display string of the Type
295:                 * 
296:                 * @return		the display string
297:                 */
298:                public String toString() {
299:                    return m_Display;
300:                }
301:            }
302:
303:            /** will be returned if no ID can be generated */
304:            protected final static String MISSING_ID = "missing_id";
305:
306:            /** the type of this technical information */
307:            protected Type m_Type = null;
308:
309:            /** the unique identifier of this information, will be generated 
310:             * automatically if left empty */
311:            protected String m_ID = "";
312:
313:            /** stores all the values associated with the fields (FIELD - String) */
314:            protected Hashtable m_Values = new Hashtable();
315:
316:            /** additional technical informations */
317:            protected Vector m_Additional = new Vector();
318:
319:            /**
320:             * Initializes the information with the given type
321:             * 
322:             * @param type	the type of this information
323:             * @see Type
324:             */
325:            public TechnicalInformation(Type type) {
326:                this (type, "");
327:            }
328:
329:            /**
330:             * Initializes the information with the given type
331:             * 
332:             * @param type	the type of this information
333:             * @param id		the unique ID (for BibTex), can be empty
334:             * @see Type
335:             */
336:            public TechnicalInformation(Type type, String id) {
337:                m_Type = type;
338:                m_ID = id;
339:            }
340:
341:            /**
342:             * returns the type of this technical information
343:             * 
344:             * @return		the type of this information
345:             */
346:            public Type getType() {
347:                return m_Type;
348:            }
349:
350:            /**
351:             * splits the authors on the " and " and returns a vector with the names
352:             * 
353:             * @return		the authors in an array
354:             */
355:            protected String[] getAuthors() {
356:                return getValue(Field.AUTHOR).split(" and ");
357:            }
358:
359:            /**
360:             * Generates an ID based on the current settings and returns it. If nothing
361:             * can be generated the MISSING_ID string will be returned
362:             * 
363:             * @return		the ID
364:             * @see #MISSING_ID
365:             */
366:            protected String generateID() {
367:                String result;
368:                String[] authors;
369:                String[] parts;
370:
371:                result = m_ID;
372:
373:                // try surname of first author and year
374:                if (result.length() == 0) {
375:                    if (exists(Field.AUTHOR) && exists(Field.YEAR)) {
376:                        authors = getAuthors();
377:                        if (authors[0].indexOf(",") > -1) {
378:                            parts = authors[0].split(",");
379:                            result = parts[0];
380:                        } else {
381:                            parts = authors[0].split(" ");
382:                            if (parts.length == 1)
383:                                result = parts[0];
384:                            else
385:                                result = parts[parts.length - 1];
386:                        }
387:                        result += getValue(Field.YEAR);
388:                        result = result.replaceAll(" ", "");
389:                    }
390:                }
391:
392:                // still nothing?
393:                if (result.length() == 0)
394:                    result = MISSING_ID;
395:
396:                return result;
397:            }
398:
399:            /**
400:             * returns the unique ID (either the one used in creating this instance
401:             * or the automatically generated one)
402:             * 
403:             * @return		the ID for this information
404:             */
405:            public String getID() {
406:                return generateID();
407:            }
408:
409:            /**
410:             * sets the value for the given field, overwrites any previously existing one.
411:             * 
412:             * @param field	the field to set the value for
413:             * @param value	the value of the field
414:             */
415:            public void setValue(Field field, String value) {
416:                m_Values.put(field, value);
417:            }
418:
419:            /**
420:             * returns the value associated with the given field, or empty if field is
421:             * not currently stored.
422:             * 
423:             * @param field	the field to retrieve the value for
424:             * @return		the value associated with this field, empty if not existing
425:             */
426:            public String getValue(Field field) {
427:                if (m_Values.containsKey(field))
428:                    return (String) m_Values.get(field);
429:                else
430:                    return "";
431:            }
432:
433:            /**
434:             * returns TRUE if the field is stored and has a value different from the
435:             * empty string.
436:             * 
437:             * @param field	the field to check
438:             * @return 		true if a value is stored for the field and non-empty
439:             */
440:            public boolean exists(Field field) {
441:                return (m_Values.containsKey(field) && (((String) m_Values
442:                        .get(field)).length() != 0));
443:            }
444:
445:            /**
446:             * returns an enumeration over all the stored fields
447:             * 
448:             * @return		all currently stored fields
449:             */
450:            public Enumeration fields() {
451:                return m_Values.keys();
452:            }
453:
454:            /**
455:             * returns true if there are further technical informations stored in this
456:             * 
457:             * @return true if there are further technical informations available
458:             */
459:            public boolean hasAdditional() {
460:                return (m_Additional.size() > 0);
461:            }
462:
463:            /**
464:             * returns an enumeration of all the additional technical informations (if
465:             * there are any)
466:             * 
467:             * @return an enumeration over all additional technical informations
468:             */
469:            public Enumeration additional() {
470:                return m_Additional.elements();
471:            }
472:
473:            /**
474:             * adds the given information to the list of additional technical 
475:             * informations
476:             * 
477:             * @param value the information to add
478:             */
479:            public void add(TechnicalInformation value) {
480:                if (value == this )
481:                    throw new IllegalArgumentException(
482:                            "Can't add object to itself!");
483:                m_Additional.add(value);
484:            }
485:
486:            /**
487:             * Adds an empty technical information with the given type to the list
488:             * of additional informations and returns the instance.
489:             * 
490:             * @param type	the type of the new information to add
491:             * @return 		the generated information
492:             */
493:            public TechnicalInformation add(Type type) {
494:                TechnicalInformation result;
495:
496:                result = new TechnicalInformation(type);
497:                add(result);
498:
499:                return result;
500:            }
501:
502:            /**
503:             * Returns a plain-text string representing this technical information.
504:             * Note: it only returns a string based on some fields. At least AUTHOR,
505:             * YEAR and TITLE are necessary.
506:             * 
507:             * @return		a string representation of this information
508:             */
509:            public String toString() {
510:                String result;
511:                String[] authors;
512:                int i;
513:                Enumeration enm;
514:
515:                result = "";
516:                authors = getAuthors();
517:
518:                // BOOK
519:                if (getType() == Type.BOOK) {
520:                    for (i = 0; i < authors.length; i++) {
521:                        if (i > 0)
522:                            result += ", ";
523:                        result += authors[i];
524:                    }
525:                    if (exists(Field.YEAR))
526:                        result += " (" + getValue(Field.YEAR) + ").";
527:                    else
528:                        result += ".";
529:                    result += " " + getValue(Field.TITLE) + ".";
530:                    result += " " + getValue(Field.PUBLISHER);
531:                    if (exists(Field.ADDRESS))
532:                        result += ", " + getValue(Field.ADDRESS);
533:                    result += ".";
534:                }
535:                // ARTICLE
536:                else if (getType() == Type.ARTICLE) {
537:                    for (i = 0; i < authors.length; i++) {
538:                        if (i > 0)
539:                            result += ", ";
540:                        result += authors[i];
541:                    }
542:                    if (exists(Field.YEAR))
543:                        result += " (" + getValue(Field.YEAR) + ").";
544:                    else
545:                        result += ".";
546:                    result += " " + getValue(Field.TITLE) + ".";
547:
548:                    // journal
549:                    if (exists(Field.JOURNAL)) {
550:                        result += " " + getValue(Field.JOURNAL) + ".";
551:
552:                        if (exists(Field.VOLUME))
553:                            result += " " + getValue(Field.VOLUME);
554:                        if (exists(Field.NUMBER))
555:                            result += "(" + getValue(Field.NUMBER) + ")";
556:                        if (exists(Field.PAGES))
557:                            result += ":" + getValue(Field.PAGES);
558:
559:                        result += ".";
560:                    }
561:
562:                    // other than JOURNAL???
563:
564:                    // URL
565:                    if (exists(Field.URL))
566:                        result += " URL " + getValue(Field.URL) + ".";
567:                }
568:                // CONFERENCE/INPROCEEDINGS
569:                else if ((getType() == Type.CONFERENCE)
570:                        || (getType() == Type.INPROCEEDINGS)) {
571:                    for (i = 0; i < authors.length; i++) {
572:                        if (i > 0)
573:                            result += ", ";
574:                        result += authors[i];
575:                    }
576:                    result += ": " + getValue(Field.TITLE) + ".";
577:                    result += " In: " + getValue(Field.BOOKTITLE);
578:
579:                    if (exists(Field.ADDRESS))
580:                        result += ", " + getValue(Field.ADDRESS);
581:                    if (exists(Field.PAGES))
582:                        result += ", " + getValue(Field.PAGES);
583:
584:                    if (exists(Field.YEAR))
585:                        result += ", " + getValue(Field.YEAR) + ".";
586:                    else
587:                        result += ".";
588:                }
589:                // INCOLLECTION
590:                else if (getType() == Type.INCOLLECTION) {
591:                    for (i = 0; i < authors.length; i++) {
592:                        if (i > 0)
593:                            result += ", ";
594:                        result += authors[i];
595:                    }
596:                    result += ": " + getValue(Field.TITLE) + ".";
597:                    result += " In ";
598:                    if (exists(Field.EDITOR))
599:                        result += getValue(Field.EDITOR) + ", editors, ";
600:                    result += getValue(Field.BOOKTITLE);
601:
602:                    if (exists(Field.ADDRESS))
603:                        result += ", " + getValue(Field.ADDRESS);
604:                    if (exists(Field.PAGES))
605:                        result += ", " + getValue(Field.PAGES);
606:
607:                    if (exists(Field.YEAR))
608:                        result += ", " + getValue(Field.YEAR) + ".";
609:                    else
610:                        result += ".";
611:                }
612:                // default
613:                else {
614:                    for (i = 0; i < authors.length; i++) {
615:                        if (i > 0)
616:                            result += ", ";
617:                        result += authors[i];
618:                    }
619:                    if (exists(Field.YEAR))
620:                        result += " (" + getValue(Field.YEAR) + ").";
621:                    else
622:                        result += ".";
623:                    result += " " + getValue(Field.TITLE) + ".";
624:                    if (exists(Field.ADDRESS))
625:                        result += " " + getValue(Field.ADDRESS) + ".";
626:                    if (exists(Field.URL))
627:                        result += " URL " + getValue(Field.URL) + ".";
628:                }
629:
630:                // additional informations?
631:                enm = additional();
632:                while (enm.hasMoreElements()) {
633:                    result += "\n\n" + enm.nextElement().toString();
634:                }
635:
636:                return result;
637:            }
638:
639:            /**
640:             * Returns a BibTex string representing this technical information. 
641:             * Note: this is just a very raw implementation, special characters need to
642:             * be escaped manually for LaTeX.
643:             * 
644:             * @return		the BibTeX representation of this information
645:             */
646:            public String toBibTex() {
647:                String result;
648:                Enumeration enm;
649:                Field field;
650:                Vector list;
651:                int i;
652:
653:                result = "@" + getType() + "{" + getID() + "";
654:
655:                // sort the fields
656:                list = new Vector();
657:                enm = fields();
658:                while (enm.hasMoreElements())
659:                    list.add(enm.nextElement());
660:                Collections.sort(list);
661:
662:                // list field=value pairs
663:                for (i = 0; i < list.size(); i++) {
664:                    field = (Field) list.get(i);
665:                    if (!exists(field))
666:                        continue;
667:                    result += ",\n   " + field + " = {" + getValue(field) + "}";
668:                }
669:
670:                result += "\n}";
671:
672:                // additional informations?
673:                enm = additional();
674:                while (enm.hasMoreElements()) {
675:                    result += "\n\n"
676:                            + ((TechnicalInformation) enm.nextElement())
677:                                    .toBibTex();
678:                }
679:
680:                return result;
681:            }
682:
683:            /**
684:             * Prints some examples of technical informations if there are no 
685:             * commandline options given. Otherwise the information of a given 
686:             * TechnicalInformationHandler can be printed. <p/>
687:             * 
688:             * Valid options are: <p/>
689:             * 
690:             * -W classname <br/>
691:             *  The classname of the TechnicalInformationHandler to print the 
692:             *  information for <p/>
693:             *  
694:             * -bibtex <br/>
695:             *  Print the information in BibTeX format <p/>
696:             *  
697:             * -plaintext <br/>
698:             *  Print the information in plain text format <p/>
699:             * 
700:             * @param args 	the commandline options
701:             * @throws Exception	if the option parsing fails
702:             */
703:            public static void main(String[] args) throws Exception {
704:                TechnicalInformation info;
705:                TechnicalInformation additional;
706:                String tmpStr;
707:                Class cls;
708:                TechnicalInformationHandler handler;
709:
710:                // example from command line
711:                if (args.length != 0) {
712:                    info = null;
713:
714:                    tmpStr = Utils.getOption('W', args);
715:                    if (tmpStr.length() != 0) {
716:                        cls = Class.forName(tmpStr);
717:                        handler = (TechnicalInformationHandler) cls
718:                                .newInstance();
719:                        info = handler.getTechnicalInformation();
720:                    } else {
721:                        throw new IllegalArgumentException(
722:                                "A classname has to be provided with the -W option!");
723:                    }
724:
725:                    if (Utils.getFlag("bibtex", args))
726:                        System.out.println("\n" + handler.getClass().getName()
727:                                + ":\n" + info.toBibTex());
728:
729:                    if (Utils.getFlag("plaintext", args))
730:                        System.out.println("\n" + handler.getClass().getName()
731:                                + ":\n" + info.toString());
732:                } else {
733:                    // first example
734:                    info = new TechnicalInformation(Type.BOOK);
735:                    info.setValue(Field.AUTHOR, "Ross Quinlan");
736:                    info.setValue(Field.YEAR, "1993");
737:                    info.setValue(Field.TITLE,
738:                            "C4.5: Programs for Machine Learning");
739:                    info
740:                            .setValue(Field.PUBLISHER,
741:                                    "Morgan Kaufmann Publishers");
742:                    info.setValue(Field.ADDRESS, "San Mateo, CA");
743:                    additional = info;
744:
745:                    System.out.println("\ntoString():\n" + info.toString());
746:                    System.out.println("\ntoBibTex():\n" + info.toBibTex());
747:
748:                    // second example
749:                    info = new TechnicalInformation(Type.INPROCEEDINGS);
750:                    info.setValue(Field.AUTHOR, "Freund, Y. and Mason, L.");
751:                    info.setValue(Field.YEAR, "1999");
752:                    info.setValue(Field.TITLE,
753:                            "The alternating decision tree learning algorithm");
754:                    info
755:                            .setValue(Field.BOOKTITLE,
756:                                    "Proceeding of the Sixteenth International Conference on Machine Learning");
757:                    info.setValue(Field.ADDRESS, "Bled, Slovenia");
758:                    info.setValue(Field.PAGES, "124-133");
759:
760:                    System.out.println("\ntoString():\n" + info.toString());
761:                    System.out.println("\ntoBibTex():\n" + info.toBibTex());
762:
763:                    // third example
764:                    info = new TechnicalInformation(Type.ARTICLE);
765:                    info.setValue(Field.AUTHOR, "R. Quinlan");
766:                    info.setValue(Field.YEAR, "1986");
767:                    info.setValue(Field.TITLE, "Induction of decision trees");
768:                    info.setValue(Field.JOURNAL, "Machine Learning");
769:                    info.setValue(Field.VOLUME, "1");
770:                    info.setValue(Field.NUMBER, "1");
771:                    info.setValue(Field.PAGES, "81-106");
772:
773:                    additional = new TechnicalInformation(Type.BOOK);
774:                    additional.setValue(Field.AUTHOR, "Ross Quinlan");
775:                    additional.setValue(Field.YEAR, "1993");
776:                    additional.setValue(Field.TITLE,
777:                            "C4.5: Programs for Machine Learning");
778:                    additional.setValue(Field.PUBLISHER,
779:                            "Morgan Kaufmann Publishers");
780:                    additional.setValue(Field.ADDRESS, "San Mateo, CA");
781:                    info.add(additional);
782:
783:                    System.out.println("\ntoString():\n" + info.toString());
784:                    System.out.println("\ntoBibTex():\n" + info.toBibTex());
785:                }
786:            }
787:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.