Source Code Cross Referenced for WordlistLoader.java in  » Net » lucene-connector » org » apache » lucene » analysis » 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 » Net » lucene connector » org.apache.lucene.analysis 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.apache.lucene.analysis;
002:
003:        /**
004:         * Licensed to the Apache Software Foundation (ASF) under one or more
005:         * contributor license agreements.  See the NOTICE file distributed with
006:         * this work for additional information regarding copyright ownership.
007:         * The ASF licenses this file to You under the Apache License, Version 2.0
008:         * (the "License"); you may not use this file except in compliance with
009:         * the License.  You may obtain a copy of the License at
010:         *
011:         *     http://www.apache.org/licenses/LICENSE-2.0
012:         *
013:         * Unless required by applicable law or agreed to in writing, software
014:         * distributed under the License is distributed on an "AS IS" BASIS,
015:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016:         * See the License for the specific language governing permissions and
017:         * limitations under the License.
018:         */
019:
020:        import java.io.BufferedReader;
021:        import java.io.File;
022:        import java.io.FileReader;
023:        import java.io.IOException;
024:        import java.io.Reader;
025:        import java.util.HashMap;
026:        import java.util.HashSet;
027:
028:        /**
029:         * Loader for text files that represent a list of stopwords.
030:         *
031:         *
032:         * @version $Id: WordlistLoader.java 564236 2007-08-09 15:21:19Z gsingers $
033:         */
034:        public class WordlistLoader {
035:
036:            /**
037:             * Loads a text file and adds every line as an entry to a HashSet (omitting
038:             * leading and trailing whitespace). Every line of the file should contain only
039:             * one word. The words need to be in lowercase if you make use of an
040:             * Analyzer which uses LowerCaseFilter (like StandardAnalyzer).
041:             *
042:             * @param wordfile File containing the wordlist
043:             * @return A HashSet with the file's words
044:             */
045:            public static HashSet getWordSet(File wordfile) throws IOException {
046:                HashSet result = new HashSet();
047:                FileReader reader = null;
048:                try {
049:                    reader = new FileReader(wordfile);
050:                    result = getWordSet(reader);
051:                } finally {
052:                    if (reader != null)
053:                        reader.close();
054:                }
055:                return result;
056:            }
057:
058:            /**
059:             * Reads lines from a Reader and adds every line as an entry to a HashSet (omitting
060:             * leading and trailing whitespace). Every line of the Reader should contain only
061:             * one word. The words need to be in lowercase if you make use of an
062:             * Analyzer which uses LowerCaseFilter (like StandardAnalyzer).
063:             *
064:             * @param reader Reader containing the wordlist
065:             * @return A HashSet with the reader's words
066:             */
067:            public static HashSet getWordSet(Reader reader) throws IOException {
068:                HashSet result = new HashSet();
069:                BufferedReader br = null;
070:                try {
071:                    if (reader instanceof  BufferedReader) {
072:                        br = (BufferedReader) reader;
073:                    } else {
074:                        br = new BufferedReader(reader);
075:                    }
076:                    String word = null;
077:                    while ((word = br.readLine()) != null) {
078:                        result.add(word.trim());
079:                    }
080:                } finally {
081:                    if (br != null)
082:                        br.close();
083:                }
084:                return result;
085:            }
086:
087:            /**
088:             * Reads a stem dictionary. Each line contains:
089:             * <pre>word<b>\t</b>stem</pre>
090:             * (i.e. two tab seperated words)
091:             *
092:             * @return stem dictionary that overrules the stemming algorithm
093:             * @throws IOException 
094:             */
095:            public static HashMap getStemDict(File wordstemfile)
096:                    throws IOException {
097:                if (wordstemfile == null)
098:                    throw new NullPointerException(
099:                            "wordstemfile may not be null");
100:                HashMap result = new HashMap();
101:                BufferedReader br = null;
102:                FileReader fr = null;
103:                try {
104:                    fr = new FileReader(wordstemfile);
105:                    br = new BufferedReader(fr);
106:                    String line;
107:                    while ((line = br.readLine()) != null) {
108:                        String[] wordstem = line.split("\t", 2);
109:                        result.put(wordstem[0], wordstem[1]);
110:                    }
111:                } finally {
112:                    if (fr != null)
113:                        fr.close();
114:                    if (br != null)
115:                        br.close();
116:                }
117:                return result;
118:            }
119:
120:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.