PyLucene 3.4.0-1 import
[pylucene.git] / lucene-java-3.4.0 / lucene / contrib / analyzers / common / src / java / org / apache / lucene / analysis / wikipedia / WikipediaTokenizerImpl.java
1 /* The following code was generated by JFlex 1.5.0-SNAPSHOT on 10/3/10 8:05 AM */
2
3 package org.apache.lucene.analysis.wikipedia;
4
5 /**
6  * Licensed to the Apache Software Foundation (ASF) under one or more
7  * contributor license agreements.  See the NOTICE file distributed with
8  * this work for additional information regarding copyright ownership.
9  * The ASF licenses this file to You under the Apache License, Version 2.0
10  * (the "License"); you may not use this file except in compliance with
11  * the License.  You may obtain a copy of the License at
12  *
13  *     http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21
22 import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
23
24
25 /**
26  * This class is a scanner generated by 
27  * <a href="http://www.jflex.de/">JFlex</a> 1.5.0-SNAPSHOT
28  * on 10/3/10 8:05 AM from the specification file
29  * <tt>C:/Users/rmuir/workspace/lucene_3xclean/lucene/contrib/analyzers/common/src/java/org/apache/lucene/analysis/wikipedia/WikipediaTokenizerImpl.jflex</tt>
30  */
31 class WikipediaTokenizerImpl {
32
33   /** This character denotes the end of file */
34   public static final int YYEOF = -1;
35
36   /** initial size of the lookahead buffer */
37   private static final int ZZ_BUFFERSIZE = 16384;
38
39   /** lexical states */
40   public static final int THREE_SINGLE_QUOTES_STATE = 10;
41   public static final int EXTERNAL_LINK_STATE = 6;
42   public static final int DOUBLE_EQUALS_STATE = 14;
43   public static final int INTERNAL_LINK_STATE = 4;
44   public static final int DOUBLE_BRACE_STATE = 16;
45   public static final int CATEGORY_STATE = 2;
46   public static final int YYINITIAL = 0;
47   public static final int STRING = 18;
48   public static final int FIVE_SINGLE_QUOTES_STATE = 12;
49   public static final int TWO_SINGLE_QUOTES_STATE = 8;
50
51   /**
52    * ZZ_LEXSTATE[l] is the state in the DFA for the lexical state l
53    * ZZ_LEXSTATE[l+1] is the state in the DFA for the lexical state l
54    *                  at the beginning of a line
55    * l is of the form l = 2*k, k a non negative integer
56    */
57   private static final int ZZ_LEXSTATE[] = { 
58      0,  0,  1,  1,  2,  2,  3,  3,  4,  4,  5,  5,  6,  6,  7,  7, 
59      8,  8,  9, 9
60   };
61
62   /** 
63    * Translates characters to character classes
64    */
65   private static final String ZZ_CMAP_PACKED = 
66     "\11\0\1\24\1\23\1\0\1\24\1\22\22\0\1\24\1\0\1\12"+
67     "\1\53\2\0\1\3\1\1\4\0\1\14\1\5\1\2\1\10\12\16"+
68     "\1\27\1\0\1\7\1\11\1\13\1\53\1\4\2\15\1\30\5\15"+
69     "\1\41\21\15\1\25\1\0\1\26\1\0\1\6\1\0\1\31\1\43"+
70     "\2\15\1\33\1\40\1\34\1\50\1\41\4\15\1\42\1\35\1\51"+
71     "\1\15\1\36\1\52\1\32\3\15\1\44\1\37\1\15\1\45\1\47"+
72     "\1\46\102\0\27\15\1\0\37\15\1\0\u0568\15\12\17\206\15\12\17"+
73     "\u026c\15\12\17\166\15\12\17\166\15\12\17\166\15\12\17\166\15\12\17"+
74     "\167\15\11\17\166\15\12\17\166\15\12\17\166\15\12\17\340\15\12\17"+
75     "\166\15\12\17\u0166\15\12\17\266\15\u0100\15\u0e00\15\u1040\0\u0150\21\140\0"+
76     "\20\21\u0100\0\200\21\200\0\u19c0\21\100\0\u5200\21\u0c00\0\u2bb0\20\u2150\0"+
77     "\u0200\21\u0465\0\73\21\75\15\43\0";
78
79   /** 
80    * Translates characters to character classes
81    */
82   private static final char [] ZZ_CMAP = zzUnpackCMap(ZZ_CMAP_PACKED);
83
84   /** 
85    * Translates DFA states to action switch labels.
86    */
87   private static final int [] ZZ_ACTION = zzUnpackAction();
88
89   private static final String ZZ_ACTION_PACKED_0 =
90     "\12\0\4\1\4\2\1\3\1\1\1\4\1\1\2\5"+
91     "\1\6\2\5\1\7\1\5\2\10\1\11\1\12\1\11"+
92     "\1\13\1\14\1\10\1\15\1\16\1\15\1\17\1\20"+
93     "\1\10\1\21\1\10\4\22\1\23\1\22\1\24\1\25"+
94     "\1\26\3\0\1\27\14\0\1\30\1\31\1\32\1\33"+
95     "\1\11\1\0\1\34\1\35\1\0\1\36\1\0\1\37"+
96     "\3\0\1\40\1\41\2\42\1\41\2\43\2\0\1\42"+
97     "\1\0\14\42\1\41\3\0\1\11\1\44\3\0\1\45"+
98     "\1\46\5\0\1\47\4\0\1\47\2\0\2\47\2\0"+
99     "\1\11\5\0\1\31\1\41\1\42\1\50\3\0\1\11"+
100     "\2\0\1\51\30\0\1\52\2\0\1\53\1\54\1\55";
101
102   private static int [] zzUnpackAction() {
103     int [] result = new int[183];
104     int offset = 0;
105     offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result);
106     return result;
107   }
108
109   private static int zzUnpackAction(String packed, int offset, int [] result) {
110     int i = 0;       /* index in packed string  */
111     int j = offset;  /* index in unpacked array */
112     int l = packed.length();
113     while (i < l) {
114       int count = packed.charAt(i++);
115       int value = packed.charAt(i++);
116       do result[j++] = value; while (--count > 0);
117     }
118     return j;
119   }
120
121
122   /** 
123    * Translates a state to a row index in the transition table
124    */
125   private static final int [] ZZ_ROWMAP = zzUnpackRowMap();
126
127   private static final String ZZ_ROWMAP_PACKED_0 =
128     "\0\0\0\54\0\130\0\204\0\260\0\334\0\u0108\0\u0134"+
129     "\0\u0160\0\u018c\0\u01b8\0\u01e4\0\u0210\0\u023c\0\u0268\0\u0294"+
130     "\0\u02c0\0\u02ec\0\u01b8\0\u0318\0\u0344\0\u0370\0\u01b8\0\u039c"+
131     "\0\u03c8\0\u03f4\0\u0420\0\u044c\0\u0478\0\u01b8\0\u039c\0\u04a4"+
132     "\0\u01b8\0\u04d0\0\u04fc\0\u0528\0\u0554\0\u0580\0\u05ac\0\u05d8"+
133     "\0\u0604\0\u0630\0\u065c\0\u0688\0\u06b4\0\u01b8\0\u06e0\0\u039c"+
134     "\0\u070c\0\u0738\0\u0764\0\u0790\0\u01b8\0\u01b8\0\u07bc\0\u07e8"+
135     "\0\u0814\0\u01b8\0\u0840\0\u086c\0\u0898\0\u08c4\0\u08f0\0\u091c"+
136     "\0\u0948\0\u0974\0\u09a0\0\u09cc\0\u09f8\0\u0a24\0\u0a50\0\u0a7c"+
137     "\0\u01b8\0\u01b8\0\u0aa8\0\u0ad4\0\u0b00\0\u0b00\0\u0b2c\0\u0b58"+
138     "\0\u0b84\0\u0bb0\0\u0bdc\0\u0c08\0\u0c34\0\u0c60\0\u0c8c\0\u0cb8"+
139     "\0\u0ce4\0\u0d10\0\u0898\0\u0d3c\0\u0d68\0\u0d94\0\u0dc0\0\u0dec"+
140     "\0\u0e18\0\u0e44\0\u0e70\0\u0e9c\0\u0ec8\0\u0ef4\0\u0f20\0\u0f4c"+
141     "\0\u0f78\0\u0fa4\0\u0fd0\0\u0ffc\0\u1028\0\u1054\0\u1080\0\u10ac"+
142     "\0\u10d8\0\u01b8\0\u1104\0\u1130\0\u115c\0\u1188\0\u01b8\0\u11b4"+
143     "\0\u11e0\0\u120c\0\u1238\0\u1264\0\u1290\0\u12bc\0\u12e8\0\u1314"+
144     "\0\u1340\0\u136c\0\u1398\0\u13c4\0\u086c\0\u09f8\0\u13f0\0\u141c"+
145     "\0\u1448\0\u1474\0\u14a0\0\u14cc\0\u14f8\0\u1524\0\u01b8\0\u1550"+
146     "\0\u157c\0\u15a8\0\u15d4\0\u1600\0\u162c\0\u1658\0\u1684\0\u16b0"+
147     "\0\u01b8\0\u16dc\0\u1708\0\u1734\0\u1760\0\u178c\0\u17b8\0\u17e4"+
148     "\0\u1810\0\u183c\0\u1868\0\u1894\0\u18c0\0\u18ec\0\u1918\0\u1944"+
149     "\0\u1970\0\u199c\0\u19c8\0\u19f4\0\u1a20\0\u1a4c\0\u1a78\0\u1aa4"+
150     "\0\u1ad0\0\u1afc\0\u1b28\0\u1b54\0\u01b8\0\u01b8\0\u01b8";
151
152   private static int [] zzUnpackRowMap() {
153     int [] result = new int[183];
154     int offset = 0;
155     offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result);
156     return result;
157   }
158
159   private static int zzUnpackRowMap(String packed, int offset, int [] result) {
160     int i = 0;  /* index in packed string  */
161     int j = offset;  /* index in unpacked array */
162     int l = packed.length();
163     while (i < l) {
164       int high = packed.charAt(i++) << 16;
165       result[j++] = high | packed.charAt(i++);
166     }
167     return j;
168   }
169
170   /** 
171    * The transition table of the DFA
172    */
173   private static final int [] ZZ_TRANS = zzUnpackTrans();
174
175   private static final String ZZ_TRANS_PACKED_0 =
176     "\1\13\1\14\5\13\1\15\1\13\1\16\3\13\1\17"+
177     "\1\20\1\21\1\22\1\23\1\24\2\13\1\25\2\13"+
178     "\15\17\1\26\2\13\3\17\1\13\7\27\1\30\5\27"+
179     "\4\31\1\27\1\32\3\27\1\33\1\27\15\31\3\27"+
180     "\3\31\10\27\1\30\5\27\4\34\1\27\1\32\3\27"+
181     "\1\35\1\27\15\34\3\27\3\34\1\27\7\36\1\37"+
182     "\5\36\4\40\1\36\1\32\2\27\1\36\1\41\1\36"+
183     "\15\40\3\36\1\42\2\40\2\36\1\43\5\36\1\37"+
184     "\5\36\4\44\1\36\1\45\2\36\1\46\2\36\15\44"+
185     "\3\36\3\44\10\36\1\37\5\36\4\47\1\36\1\45"+
186     "\2\36\1\46\2\36\15\47\3\36\3\47\10\36\1\37"+
187     "\5\36\4\47\1\36\1\45\2\36\1\50\2\36\15\47"+
188     "\3\36\3\47\10\36\1\37\1\36\1\51\3\36\4\52"+
189     "\1\36\1\45\5\36\15\52\3\36\3\52\10\36\1\53"+
190     "\5\36\4\54\1\36\1\45\5\36\15\54\1\36\1\55"+
191     "\1\36\3\54\1\36\1\56\1\57\5\56\1\60\1\56"+
192     "\1\61\3\56\4\62\1\56\1\63\2\56\1\64\2\56"+
193     "\15\62\2\56\1\65\3\62\1\56\55\0\1\66\62\0"+
194     "\1\67\4\0\4\70\7\0\6\70\1\71\6\70\3\0"+
195     "\3\70\12\0\1\72\43\0\1\73\1\74\1\75\1\76"+
196     "\2\77\1\0\1\100\3\0\1\100\1\17\1\20\1\21"+
197     "\1\22\7\0\15\17\3\0\3\17\3\0\1\101\1\0"+
198     "\1\102\2\103\1\0\1\104\3\0\1\104\3\20\1\22"+
199     "\7\0\15\20\3\0\3\20\2\0\1\73\1\105\1\75"+
200     "\1\76\2\103\1\0\1\104\3\0\1\104\1\21\1\20"+
201     "\1\21\1\22\7\0\15\21\3\0\3\21\3\0\1\106"+
202     "\1\0\1\102\2\77\1\0\1\100\3\0\1\100\4\22"+
203     "\7\0\15\22\3\0\3\22\24\0\1\13\55\0\1\107"+
204     "\73\0\1\110\16\0\1\67\4\0\4\70\7\0\15\70"+
205     "\3\0\3\70\16\0\4\31\7\0\15\31\3\0\3\31"+
206     "\24\0\1\27\56\0\1\111\42\0\4\34\7\0\15\34"+
207     "\3\0\3\34\27\0\1\112\42\0\4\40\7\0\15\40"+
208     "\3\0\3\40\16\0\4\40\7\0\2\40\1\113\12\40"+
209     "\3\0\3\40\2\0\1\114\67\0\4\44\7\0\15\44"+
210     "\3\0\3\44\24\0\1\36\55\0\1\115\43\0\4\47"+
211     "\7\0\15\47\3\0\3\47\26\0\1\116\37\0\1\111"+
212     "\57\0\4\52\7\0\15\52\3\0\3\52\11\0\1\117"+
213     "\4\0\4\70\7\0\15\70\3\0\3\70\16\0\4\54"+
214     "\7\0\15\54\3\0\3\54\47\0\1\111\6\0\1\120"+
215     "\63\0\1\121\57\0\4\62\7\0\15\62\3\0\3\62"+
216     "\24\0\1\56\55\0\1\122\43\0\4\70\7\0\15\70"+
217     "\3\0\3\70\14\0\1\36\1\0\4\123\1\0\3\124"+
218     "\3\0\15\123\3\0\3\123\14\0\1\36\1\0\4\123"+
219     "\1\0\3\124\3\0\3\123\1\125\11\123\3\0\3\123"+
220     "\16\0\1\126\1\0\1\126\10\0\15\126\3\0\3\126"+
221     "\16\0\1\127\1\130\1\131\1\132\7\0\15\127\3\0"+
222     "\3\127\16\0\1\133\1\0\1\133\10\0\15\133\3\0"+
223     "\3\133\16\0\1\134\1\135\1\134\1\135\7\0\15\134"+
224     "\3\0\3\134\16\0\1\136\2\137\1\140\7\0\15\136"+
225     "\3\0\3\136\16\0\1\100\2\141\10\0\15\100\3\0"+
226     "\3\100\16\0\1\142\2\143\1\144\7\0\15\142\3\0"+
227     "\3\142\16\0\4\135\7\0\15\135\3\0\3\135\16\0"+
228     "\1\145\2\146\1\147\7\0\15\145\3\0\3\145\16\0"+
229     "\1\150\2\151\1\152\7\0\15\150\3\0\3\150\16\0"+
230     "\1\153\1\143\1\154\1\144\7\0\15\153\3\0\3\153"+
231     "\16\0\1\155\2\130\1\132\7\0\15\155\3\0\3\155"+
232     "\30\0\1\156\1\157\64\0\1\160\27\0\4\40\7\0"+
233     "\2\40\1\161\12\40\3\0\3\40\2\0\1\162\101\0"+
234     "\1\163\1\164\40\0\4\70\7\0\6\70\1\165\6\70"+
235     "\3\0\3\70\2\0\1\166\63\0\1\167\71\0\1\170"+
236     "\1\171\34\0\1\172\1\0\1\36\1\0\4\123\1\0"+
237     "\3\124\3\0\15\123\3\0\3\123\16\0\4\173\1\0"+
238     "\3\124\3\0\15\173\3\0\3\173\12\0\1\172\1\0"+
239     "\1\36\1\0\4\123\1\0\3\124\3\0\10\123\1\174"+
240     "\4\123\3\0\3\123\2\0\1\73\13\0\1\126\1\0"+
241     "\1\126\10\0\15\126\3\0\3\126\3\0\1\175\1\0"+
242     "\1\102\2\176\6\0\1\127\1\130\1\131\1\132\7\0"+
243     "\15\127\3\0\3\127\3\0\1\177\1\0\1\102\2\200"+
244     "\1\0\1\201\3\0\1\201\3\130\1\132\7\0\15\130"+
245     "\3\0\3\130\3\0\1\202\1\0\1\102\2\200\1\0"+
246     "\1\201\3\0\1\201\1\131\1\130\1\131\1\132\7\0"+
247     "\15\131\3\0\3\131\3\0\1\203\1\0\1\102\2\176"+
248     "\6\0\4\132\7\0\15\132\3\0\3\132\3\0\1\204"+
249     "\2\0\1\204\7\0\1\134\1\135\1\134\1\135\7\0"+
250     "\15\134\3\0\3\134\3\0\1\204\2\0\1\204\7\0"+
251     "\4\135\7\0\15\135\3\0\3\135\3\0\1\176\1\0"+
252     "\1\102\2\176\6\0\1\136\2\137\1\140\7\0\15\136"+
253     "\3\0\3\136\3\0\1\200\1\0\1\102\2\200\1\0"+
254     "\1\201\3\0\1\201\3\137\1\140\7\0\15\137\3\0"+
255     "\3\137\3\0\1\176\1\0\1\102\2\176\6\0\4\140"+
256     "\7\0\15\140\3\0\3\140\3\0\1\201\2\0\2\201"+
257     "\1\0\1\201\3\0\1\201\3\141\10\0\15\141\3\0"+
258     "\3\141\3\0\1\106\1\0\1\102\2\77\1\0\1\100"+
259     "\3\0\1\100\1\142\2\143\1\144\7\0\15\142\3\0"+
260     "\3\142\3\0\1\101\1\0\1\102\2\103\1\0\1\104"+
261     "\3\0\1\104\3\143\1\144\7\0\15\143\3\0\3\143"+
262     "\3\0\1\106\1\0\1\102\2\77\1\0\1\100\3\0"+
263     "\1\100\4\144\7\0\15\144\3\0\3\144\3\0\1\77"+
264     "\1\0\1\102\2\77\1\0\1\100\3\0\1\100\1\145"+
265     "\2\146\1\147\7\0\15\145\3\0\3\145\3\0\1\103"+
266     "\1\0\1\102\2\103\1\0\1\104\3\0\1\104\3\146"+
267     "\1\147\7\0\15\146\3\0\3\146\3\0\1\77\1\0"+
268     "\1\102\2\77\1\0\1\100\3\0\1\100\4\147\7\0"+
269     "\15\147\3\0\3\147\3\0\1\100\2\0\2\100\1\0"+
270     "\1\100\3\0\1\100\1\150\2\151\1\152\7\0\15\150"+
271     "\3\0\3\150\3\0\1\104\2\0\2\104\1\0\1\104"+
272     "\3\0\1\104\3\151\1\152\7\0\15\151\3\0\3\151"+
273     "\3\0\1\100\2\0\2\100\1\0\1\100\3\0\1\100"+
274     "\4\152\7\0\15\152\3\0\3\152\3\0\1\205\1\0"+
275     "\1\102\2\77\1\0\1\100\3\0\1\100\1\153\1\143"+
276     "\1\154\1\144\7\0\15\153\3\0\3\153\3\0\1\206"+
277     "\1\0\1\102\2\103\1\0\1\104\3\0\1\104\1\154"+
278     "\1\143\1\154\1\144\7\0\15\154\3\0\3\154\3\0"+
279     "\1\203\1\0\1\102\2\176\6\0\1\155\2\130\1\132"+
280     "\7\0\15\155\3\0\3\155\31\0\1\157\54\0\1\207"+
281     "\64\0\1\210\26\0\4\40\7\0\15\40\3\0\1\40"+
282     "\1\211\1\40\31\0\1\164\54\0\1\212\35\0\1\36"+
283     "\1\0\4\123\1\0\3\124\3\0\3\123\1\213\11\123"+
284     "\3\0\3\123\2\0\1\214\102\0\1\171\54\0\1\215"+
285     "\34\0\1\216\52\0\1\172\3\0\4\173\7\0\15\173"+
286     "\3\0\3\173\12\0\1\172\1\0\1\217\1\0\4\123"+
287     "\1\0\3\124\3\0\15\123\3\0\3\123\16\0\1\220"+
288     "\1\132\1\220\1\132\7\0\15\220\3\0\3\220\16\0"+
289     "\4\140\7\0\15\140\3\0\3\140\16\0\4\144\7\0"+
290     "\15\144\3\0\3\144\16\0\4\147\7\0\15\147\3\0"+
291     "\3\147\16\0\4\152\7\0\15\152\3\0\3\152\16\0"+
292     "\1\221\1\144\1\221\1\144\7\0\15\221\3\0\3\221"+
293     "\16\0\4\132\7\0\15\132\3\0\3\132\16\0\4\222"+
294     "\7\0\15\222\3\0\3\222\33\0\1\223\61\0\1\224"+
295     "\30\0\4\40\6\0\1\225\15\40\3\0\2\40\1\226"+
296     "\33\0\1\227\32\0\1\172\1\0\1\36\1\0\4\123"+
297     "\1\0\3\124\3\0\10\123\1\230\4\123\3\0\3\123"+
298     "\2\0\1\231\104\0\1\232\36\0\4\233\7\0\15\233"+
299     "\3\0\3\233\3\0\1\175\1\0\1\102\2\176\6\0"+
300     "\1\220\1\132\1\220\1\132\7\0\15\220\3\0\3\220"+
301     "\3\0\1\205\1\0\1\102\2\77\1\0\1\100\3\0"+
302     "\1\100\1\221\1\144\1\221\1\144\7\0\15\221\3\0"+
303     "\3\221\3\0\1\204\2\0\1\204\7\0\4\222\7\0"+
304     "\15\222\3\0\3\222\34\0\1\234\55\0\1\235\26\0"+
305     "\1\236\60\0\4\40\6\0\1\225\15\40\3\0\3\40"+
306     "\34\0\1\237\31\0\1\172\1\0\1\111\1\0\4\123"+
307     "\1\0\3\124\3\0\15\123\3\0\3\123\34\0\1\240"+
308     "\32\0\1\241\2\0\4\233\7\0\15\233\3\0\3\233"+
309     "\35\0\1\242\62\0\1\243\20\0\1\244\77\0\1\245"+
310     "\53\0\1\246\32\0\1\36\1\0\4\173\1\0\3\124"+
311     "\3\0\15\173\3\0\3\173\36\0\1\247\53\0\1\250"+
312     "\33\0\4\251\7\0\15\251\3\0\3\251\36\0\1\252"+
313     "\53\0\1\253\54\0\1\254\61\0\1\255\11\0\1\256"+
314     "\12\0\4\251\7\0\15\251\3\0\3\251\37\0\1\257"+
315     "\53\0\1\260\54\0\1\261\22\0\1\13\62\0\4\262"+
316     "\7\0\15\262\3\0\3\262\40\0\1\263\53\0\1\264"+
317     "\43\0\1\265\26\0\2\262\1\0\2\262\1\0\2\262"+
318     "\2\0\5\262\7\0\15\262\3\0\4\262\27\0\1\266"+
319     "\53\0\1\267\24\0";
320
321   private static int [] zzUnpackTrans() {
322     int [] result = new int[7040];
323     int offset = 0;
324     offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result);
325     return result;
326   }
327
328   private static int zzUnpackTrans(String packed, int offset, int [] result) {
329     int i = 0;       /* index in packed string  */
330     int j = offset;  /* index in unpacked array */
331     int l = packed.length();
332     while (i < l) {
333       int count = packed.charAt(i++);
334       int value = packed.charAt(i++);
335       value--;
336       do result[j++] = value; while (--count > 0);
337     }
338     return j;
339   }
340
341
342   /* error codes */
343   private static final int ZZ_UNKNOWN_ERROR = 0;
344   private static final int ZZ_NO_MATCH = 1;
345   private static final int ZZ_PUSHBACK_2BIG = 2;
346
347   /* error messages for the codes above */
348   private static final String ZZ_ERROR_MSG[] = {
349     "Unkown internal scanner error",
350     "Error: could not match input",
351     "Error: pushback value was too large"
352   };
353
354   /**
355    * ZZ_ATTRIBUTE[aState] contains the attributes of state <code>aState</code>
356    */
357   private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute();
358
359   private static final String ZZ_ATTRIBUTE_PACKED_0 =
360     "\12\0\1\11\7\1\1\11\3\1\1\11\6\1\1\11"+
361     "\2\1\1\11\14\1\1\11\6\1\2\11\3\0\1\11"+
362     "\14\0\2\1\2\11\1\1\1\0\2\1\1\0\1\1"+
363     "\1\0\1\1\3\0\7\1\2\0\1\1\1\0\15\1"+
364     "\3\0\1\1\1\11\3\0\1\1\1\11\5\0\1\1"+
365     "\4\0\1\1\2\0\2\1\2\0\1\1\5\0\1\11"+
366     "\3\1\3\0\1\1\2\0\1\11\30\0\1\1\2\0"+
367     "\3\11";
368
369   private static int [] zzUnpackAttribute() {
370     int [] result = new int[183];
371     int offset = 0;
372     offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result);
373     return result;
374   }
375
376   private static int zzUnpackAttribute(String packed, int offset, int [] result) {
377     int i = 0;       /* index in packed string  */
378     int j = offset;  /* index in unpacked array */
379     int l = packed.length();
380     while (i < l) {
381       int count = packed.charAt(i++);
382       int value = packed.charAt(i++);
383       do result[j++] = value; while (--count > 0);
384     }
385     return j;
386   }
387
388   /** the input device */
389   private java.io.Reader zzReader;
390
391   /** the current state of the DFA */
392   private int zzState;
393
394   /** the current lexical state */
395   private int zzLexicalState = YYINITIAL;
396
397   /** this buffer contains the current text to be matched and is
398       the source of the yytext() string */
399   private char zzBuffer[] = new char[ZZ_BUFFERSIZE];
400
401   /** the textposition at the last accepting state */
402   private int zzMarkedPos;
403
404   /** the current text position in the buffer */
405   private int zzCurrentPos;
406
407   /** startRead marks the beginning of the yytext() string in the buffer */
408   private int zzStartRead;
409
410   /** endRead marks the last character in the buffer, that has been read
411       from input */
412   private int zzEndRead;
413
414   /** number of newlines encountered up to the start of the matched text */
415   private int yyline;
416
417   /** the number of characters up to the start of the matched text */
418   private int yychar;
419
420   /**
421    * the number of characters from the last newline up to the start of the 
422    * matched text
423    */
424   private int yycolumn;
425
426   /** 
427    * zzAtBOL == true <=> the scanner is currently at the beginning of a line
428    */
429   private boolean zzAtBOL = true;
430
431   /** zzAtEOF == true <=> the scanner is at the EOF */
432   private boolean zzAtEOF;
433
434   /** denotes if the user-EOF-code has already been executed */
435   private boolean zzEOFDone;
436
437   /* user code: */
438
439 public static final int ALPHANUM          = WikipediaTokenizer.ALPHANUM_ID;
440 public static final int APOSTROPHE        = WikipediaTokenizer.APOSTROPHE_ID;
441 public static final int ACRONYM           = WikipediaTokenizer.ACRONYM_ID;
442 public static final int COMPANY           = WikipediaTokenizer.COMPANY_ID;
443 public static final int EMAIL             = WikipediaTokenizer.EMAIL_ID;
444 public static final int HOST              = WikipediaTokenizer.HOST_ID;
445 public static final int NUM               = WikipediaTokenizer.NUM_ID;
446 public static final int CJ                = WikipediaTokenizer.CJ_ID;
447 public static final int INTERNAL_LINK     = WikipediaTokenizer.INTERNAL_LINK_ID;
448 public static final int EXTERNAL_LINK     = WikipediaTokenizer.EXTERNAL_LINK_ID;
449 public static final int CITATION          = WikipediaTokenizer.CITATION_ID;
450 public static final int CATEGORY          = WikipediaTokenizer.CATEGORY_ID;
451 public static final int BOLD              = WikipediaTokenizer.BOLD_ID;
452 public static final int ITALICS           = WikipediaTokenizer.ITALICS_ID;
453 public static final int BOLD_ITALICS      = WikipediaTokenizer.BOLD_ITALICS_ID;
454 public static final int HEADING           = WikipediaTokenizer.HEADING_ID;
455 public static final int SUB_HEADING       = WikipediaTokenizer.SUB_HEADING_ID;
456 public static final int EXTERNAL_LINK_URL = WikipediaTokenizer.EXTERNAL_LINK_URL_ID;
457
458
459 private int currentTokType;
460 private int numBalanced = 0;
461 private int positionInc = 1;
462 private int numLinkToks = 0;
463 //Anytime we start a new on a Wiki reserved token (category, link, etc.) this value will be 0, otherwise it will be the number of tokens seen
464 //this can be useful for detecting when a new reserved token is encountered
465 //see https://issues.apache.org/jira/browse/LUCENE-1133
466 private int numWikiTokensSeen = 0;
467
468 public static final String [] TOKEN_TYPES = WikipediaTokenizer.TOKEN_TYPES;
469
470 /**
471 Returns the number of tokens seen inside a category or link, etc.
472 @return the number of tokens seen inside the context of wiki syntax.
473 **/
474 public final int getNumWikiTokensSeen(){
475   return numWikiTokensSeen;
476 }
477
478 public final int yychar()
479 {
480     return yychar;
481 }
482
483 public final int getPositionIncrement(){
484   return positionInc;
485 }
486
487 /**
488  * Fills Lucene token with the current token text.
489  */
490 final void getText(CharTermAttribute t) {
491   t.copyBuffer(zzBuffer, zzStartRead, zzMarkedPos-zzStartRead);
492 }
493
494 final int setText(StringBuilder buffer){
495   int length = zzMarkedPos - zzStartRead;
496   buffer.append(zzBuffer, zzStartRead, length);
497   return length;
498 }
499
500
501
502
503   /**
504    * Creates a new scanner
505    * There is also a java.io.InputStream version of this constructor.
506    *
507    * @param   in  the java.io.Reader to read input from.
508    */
509   WikipediaTokenizerImpl(java.io.Reader in) {
510     this.zzReader = in;
511   }
512
513   /**
514    * Creates a new scanner.
515    * There is also java.io.Reader version of this constructor.
516    *
517    * @param   in  the java.io.Inputstream to read input from.
518    */
519   WikipediaTokenizerImpl(java.io.InputStream in) {
520     this(new java.io.InputStreamReader(in));
521   }
522
523   /** 
524    * Unpacks the compressed character translation table.
525    *
526    * @param packed   the packed character translation table
527    * @return         the unpacked character translation table
528    */
529   private static char [] zzUnpackCMap(String packed) {
530     char [] map = new char[0x10000];
531     int i = 0;  /* index in packed string  */
532     int j = 0;  /* index in unpacked array */
533     while (i < 230) {
534       int  count = packed.charAt(i++);
535       char value = packed.charAt(i++);
536       do map[j++] = value; while (--count > 0);
537     }
538     return map;
539   }
540
541
542   /**
543    * Refills the input buffer.
544    *
545    * @return      <code>false</code>, iff there was new input.
546    * 
547    * @exception   java.io.IOException  if any I/O-Error occurs
548    */
549   private boolean zzRefill() throws java.io.IOException {
550
551     /* first: make room (if you can) */
552     if (zzStartRead > 0) {
553       System.arraycopy(zzBuffer, zzStartRead,
554                        zzBuffer, 0,
555                        zzEndRead-zzStartRead);
556
557       /* translate stored positions */
558       zzEndRead-= zzStartRead;
559       zzCurrentPos-= zzStartRead;
560       zzMarkedPos-= zzStartRead;
561       zzStartRead = 0;
562     }
563
564     /* is the buffer big enough? */
565     if (zzCurrentPos >= zzBuffer.length) {
566       /* if not: blow it up */
567       char newBuffer[] = new char[zzCurrentPos*2];
568       System.arraycopy(zzBuffer, 0, newBuffer, 0, zzBuffer.length);
569       zzBuffer = newBuffer;
570     }
571
572     /* finally: fill the buffer with new input */
573     int numRead = zzReader.read(zzBuffer, zzEndRead,
574                                             zzBuffer.length-zzEndRead);
575
576     if (numRead > 0) {
577       zzEndRead+= numRead;
578       return false;
579     }
580     // unlikely but not impossible: read 0 characters, but not at end of stream    
581     if (numRead == 0) {
582       int c = zzReader.read();
583       if (c == -1) {
584         return true;
585       } else {
586         zzBuffer[zzEndRead++] = (char) c;
587         return false;
588       }     
589     }
590
591         // numRead < 0
592     return true;
593   }
594
595     
596   /**
597    * Closes the input stream.
598    */
599   public final void yyclose() throws java.io.IOException {
600     zzAtEOF = true;            /* indicate end of file */
601     zzEndRead = zzStartRead;  /* invalidate buffer    */
602
603     if (zzReader != null)
604       zzReader.close();
605   }
606
607
608   /**
609    * Resets the scanner to read from a new input stream.
610    * Does not close the old reader.
611    *
612    * All internal variables are reset, the old input stream 
613    * <b>cannot</b> be reused (internal buffer is discarded and lost).
614    * Lexical state is set to <tt>ZZ_INITIAL</tt>.
615    *
616    * Internal scan buffer is resized down to its initial length, if it has grown.
617    *
618    * @param reader   the new input stream 
619    */
620   public final void yyreset(java.io.Reader reader) {
621     zzReader = reader;
622     zzAtBOL  = true;
623     zzAtEOF  = false;
624     zzEOFDone = false;
625     zzEndRead = zzStartRead = 0;
626     zzCurrentPos = zzMarkedPos = 0;
627     yyline = yychar = yycolumn = 0;
628     zzLexicalState = YYINITIAL;
629     if (zzBuffer.length > ZZ_BUFFERSIZE)
630       zzBuffer = new char[ZZ_BUFFERSIZE];
631   }
632
633
634   /**
635    * Returns the current lexical state.
636    */
637   public final int yystate() {
638     return zzLexicalState;
639   }
640
641
642   /**
643    * Enters a new lexical state
644    *
645    * @param newState the new lexical state
646    */
647   public final void yybegin(int newState) {
648     zzLexicalState = newState;
649   }
650
651
652   /**
653    * Returns the text matched by the current regular expression.
654    */
655   public final String yytext() {
656     return new String( zzBuffer, zzStartRead, zzMarkedPos-zzStartRead );
657   }
658
659
660   /**
661    * Returns the character at position <tt>pos</tt> from the 
662    * matched text. 
663    * 
664    * It is equivalent to yytext().charAt(pos), but faster
665    *
666    * @param pos the position of the character to fetch. 
667    *            A value from 0 to yylength()-1.
668    *
669    * @return the character at position pos
670    */
671   public final char yycharat(int pos) {
672     return zzBuffer[zzStartRead+pos];
673   }
674
675
676   /**
677    * Returns the length of the matched text region.
678    */
679   public final int yylength() {
680     return zzMarkedPos-zzStartRead;
681   }
682
683
684   /**
685    * Reports an error that occured while scanning.
686    *
687    * In a wellformed scanner (no or only correct usage of 
688    * yypushback(int) and a match-all fallback rule) this method 
689    * will only be called with things that "Can't Possibly Happen".
690    * If this method is called, something is seriously wrong
691    * (e.g. a JFlex bug producing a faulty scanner etc.).
692    *
693    * Usual syntax/scanner level error handling should be done
694    * in error fallback rules.
695    *
696    * @param   errorCode  the code of the errormessage to display
697    */
698   private void zzScanError(int errorCode) {
699     String message;
700     try {
701       message = ZZ_ERROR_MSG[errorCode];
702     }
703     catch (ArrayIndexOutOfBoundsException e) {
704       message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR];
705     }
706
707     throw new Error(message);
708   } 
709
710
711   /**
712    * Pushes the specified amount of characters back into the input stream.
713    *
714    * They will be read again by then next call of the scanning method
715    *
716    * @param number  the number of characters to be read again.
717    *                This number must not be greater than yylength()!
718    */
719   public void yypushback(int number)  {
720     if ( number > yylength() )
721       zzScanError(ZZ_PUSHBACK_2BIG);
722
723     zzMarkedPos -= number;
724   }
725
726
727   /**
728    * Resumes scanning until the next regular expression is matched,
729    * the end of input is encountered or an I/O-Error occurs.
730    *
731    * @return      the next token
732    * @exception   java.io.IOException  if any I/O-Error occurs
733    */
734   public int getNextToken() throws java.io.IOException {
735     int zzInput;
736     int zzAction;
737
738     // cached fields:
739     int zzCurrentPosL;
740     int zzMarkedPosL;
741     int zzEndReadL = zzEndRead;
742     char [] zzBufferL = zzBuffer;
743     char [] zzCMapL = ZZ_CMAP;
744
745     int [] zzTransL = ZZ_TRANS;
746     int [] zzRowMapL = ZZ_ROWMAP;
747     int [] zzAttrL = ZZ_ATTRIBUTE;
748
749     while (true) {
750       zzMarkedPosL = zzMarkedPos;
751
752       yychar+= zzMarkedPosL-zzStartRead;
753
754       zzAction = -1;
755
756       zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL;
757   
758       zzState = ZZ_LEXSTATE[zzLexicalState];
759
760
761       zzForAction: {
762         while (true) {
763     
764           if (zzCurrentPosL < zzEndReadL)
765             zzInput = zzBufferL[zzCurrentPosL++];
766           else if (zzAtEOF) {
767             zzInput = YYEOF;
768             break zzForAction;
769           }
770           else {
771             // store back cached positions
772             zzCurrentPos  = zzCurrentPosL;
773             zzMarkedPos   = zzMarkedPosL;
774             boolean eof = zzRefill();
775             // get translated positions and possibly new buffer
776             zzCurrentPosL  = zzCurrentPos;
777             zzMarkedPosL   = zzMarkedPos;
778             zzBufferL      = zzBuffer;
779             zzEndReadL     = zzEndRead;
780             if (eof) {
781               zzInput = YYEOF;
782               break zzForAction;
783             }
784             else {
785               zzInput = zzBufferL[zzCurrentPosL++];
786             }
787           }
788           int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput] ];
789           if (zzNext == -1) break zzForAction;
790           zzState = zzNext;
791
792           int zzAttributes = zzAttrL[zzState];
793           if ( (zzAttributes & 1) == 1 ) {
794             zzAction = zzState;
795             zzMarkedPosL = zzCurrentPosL;
796             if ( (zzAttributes & 8) == 8 ) break zzForAction;
797           }
798
799         }
800       }
801
802       // store back cached position
803       zzMarkedPos = zzMarkedPosL;
804
805       switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {
806         case 16: 
807           { currentTokType = HEADING; yybegin(DOUBLE_EQUALS_STATE); numWikiTokensSeen++; return currentTokType;
808           }
809         case 46: break;
810         case 39: 
811           { positionInc = 1; return ACRONYM;
812           }
813         case 47: break;
814         case 8: 
815           { /* ignore */
816           }
817         case 48: break;
818         case 20: 
819           { numBalanced = 0; numWikiTokensSeen = 0; currentTokType = EXTERNAL_LINK;yybegin(EXTERNAL_LINK_STATE);
820           }
821         case 49: break;
822         case 35: 
823           { positionInc = 1; return COMPANY;
824           }
825         case 50: break;
826         case 4: 
827           { numWikiTokensSeen = 0; positionInc = 1; currentTokType = EXTERNAL_LINK_URL; yybegin(EXTERNAL_LINK_STATE);
828           }
829         case 51: break;
830         case 25: 
831           { numWikiTokensSeen = 0; positionInc = 1; currentTokType = CITATION; yybegin(DOUBLE_BRACE_STATE);
832           }
833         case 52: break;
834         case 43: 
835           { numWikiTokensSeen = 0; positionInc = 1; currentTokType = CATEGORY; yybegin(CATEGORY_STATE);
836           }
837         case 53: break;
838         case 22: 
839           { numWikiTokensSeen = 0; positionInc = 1; if (numBalanced == 0){numBalanced++;yybegin(TWO_SINGLE_QUOTES_STATE);} else{numBalanced = 0;}
840           }
841         case 54: break;
842         case 34: 
843           { positionInc = 1; return NUM;
844           }
845         case 55: break;
846         case 32: 
847           { positionInc = 1; return APOSTROPHE;
848           }
849         case 56: break;
850         case 23: 
851           { numWikiTokensSeen = 0; positionInc = 1; yybegin(DOUBLE_EQUALS_STATE);
852           }
853         case 57: break;
854         case 21: 
855           { yybegin(STRING); return currentTokType;/*pipe*/
856           }
857         case 58: break;
858         case 2: 
859           { positionInc = 1; return ALPHANUM;
860           }
861         case 59: break;
862         case 29: 
863           { currentTokType = INTERNAL_LINK; numWikiTokensSeen = 0;  yybegin(INTERNAL_LINK_STATE);
864           }
865         case 60: break;
866         case 17: 
867           { yybegin(DOUBLE_BRACE_STATE); numWikiTokensSeen = 0; return currentTokType;
868           }
869         case 61: break;
870         case 44: 
871           { currentTokType = CATEGORY; numWikiTokensSeen = 0; yybegin(CATEGORY_STATE);
872           }
873         case 62: break;
874         case 26: 
875           { yybegin(YYINITIAL);
876           }
877         case 63: break;
878         case 3: 
879           { positionInc = 1; return CJ;
880           }
881         case 64: break;
882         case 38: 
883           { numBalanced = 0;currentTokType = ALPHANUM; yybegin(YYINITIAL);/*end sub header*/
884           }
885         case 65: break;
886         case 15: 
887           { currentTokType = SUB_HEADING; numWikiTokensSeen = 0; yybegin(STRING);
888           }
889         case 66: break;
890         case 30: 
891           { numBalanced = 0;currentTokType = ALPHANUM; yybegin(YYINITIAL);/*end italics*/
892           }
893         case 67: break;
894         case 6: 
895           { yybegin(CATEGORY_STATE); numWikiTokensSeen++; return currentTokType;
896           }
897         case 68: break;
898         case 5: 
899           { positionInc = 1;
900           }
901         case 69: break;
902         case 19: 
903           { yybegin(STRING); numWikiTokensSeen++; return currentTokType;/* STRING ALPHANUM*/
904           }
905         case 70: break;
906         case 42: 
907           { positionInc = 1; numWikiTokensSeen++; yybegin(EXTERNAL_LINK_STATE); return currentTokType;
908           }
909         case 71: break;
910         case 27: 
911           { numLinkToks = 0; yybegin(YYINITIAL);
912           }
913         case 72: break;
914         case 11: 
915           { currentTokType = BOLD;  yybegin(THREE_SINGLE_QUOTES_STATE);
916           }
917         case 73: break;
918         case 13: 
919           { currentTokType = EXTERNAL_LINK; numWikiTokensSeen = 0; yybegin(EXTERNAL_LINK_STATE);
920           }
921         case 74: break;
922         case 14: 
923           { yybegin(STRING); numWikiTokensSeen++; return currentTokType;
924           }
925         case 75: break;
926         case 45: 
927           { numBalanced = 0; numWikiTokensSeen = 0; currentTokType = CATEGORY;yybegin(CATEGORY_STATE);
928           }
929         case 76: break;
930         case 28: 
931           { currentTokType = INTERNAL_LINK; numWikiTokensSeen = 0; yybegin(INTERNAL_LINK_STATE);
932           }
933         case 77: break;
934         case 37: 
935           { numBalanced = 0;currentTokType = ALPHANUM;yybegin(YYINITIAL);/*end bold*/
936           }
937         case 78: break;
938         case 9: 
939           { if (numLinkToks == 0){positionInc = 0;} else{positionInc = 1;} numWikiTokensSeen++; currentTokType = EXTERNAL_LINK; yybegin(EXTERNAL_LINK_STATE); numLinkToks++; return currentTokType;
940           }
941         case 79: break;
942         case 7: 
943           { yybegin(INTERNAL_LINK_STATE); numWikiTokensSeen++; return currentTokType;
944           }
945         case 80: break;
946         case 24: 
947           { numWikiTokensSeen = 0; positionInc = 1; currentTokType = INTERNAL_LINK; yybegin(INTERNAL_LINK_STATE);
948           }
949         case 81: break;
950         case 40: 
951           { positionInc = 1; return EMAIL;
952           }
953         case 82: break;
954         case 1: 
955           { numWikiTokensSeen = 0;  positionInc = 1;
956           }
957         case 83: break;
958         case 18: 
959           { /* ignore STRING */
960           }
961         case 84: break;
962         case 36: 
963           { currentTokType = BOLD_ITALICS;  yybegin(FIVE_SINGLE_QUOTES_STATE);
964           }
965         case 85: break;
966         case 33: 
967           { positionInc = 1; return HOST;
968           }
969         case 86: break;
970         case 31: 
971           { numBalanced = 0; numWikiTokensSeen = 0; currentTokType = INTERNAL_LINK;yybegin(INTERNAL_LINK_STATE);
972           }
973         case 87: break;
974         case 41: 
975           { numBalanced = 0;currentTokType = ALPHANUM; yybegin(YYINITIAL);/*end bold italics*/
976           }
977         case 88: break;
978         case 12: 
979           { currentTokType = ITALICS; numWikiTokensSeen++;  yybegin(STRING); return currentTokType;/*italics*/
980           }
981         case 89: break;
982         case 10: 
983           { numLinkToks = 0; positionInc = 0; yybegin(YYINITIAL);
984           }
985         case 90: break;
986         default: 
987           if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
988             zzAtEOF = true;
989             return YYEOF;
990           } 
991           else {
992             zzScanError(ZZ_NO_MATCH);
993           }
994       }
995     }
996   }
997
998
999 }