1 2 package net.nutch.quality.dynamic; 3 4 import java.io.*; 5 import java.util.*; 6 7 14 15 public class PageDescription implements PageDescriptionConstants { 16 HashMap values = new HashMap(); 17 ArrayList inputs = new ArrayList(); 18 ArrayList interprets = new ArrayList(); 19 20 public HashMap getValues() { 21 return values; 22 23 } 24 25 public ArrayList getInputs() { 26 return inputs; 27 } 28 29 public ArrayList getInterprets() { 30 return interprets; 31 } 32 33 36 public static void main(String argv[]) throws IOException, ParseException { 37 if (argv.length < 1) { 38 System.out.println("Usage: java net.nutch.quality.PageDescription <srcFile>"); 39 return; 40 } 41 PageDescription pd = new PageDescription(new FileInputStream(new File(argv[0]))); 42 pd.parse(); 43 } 44 45 final public void parse() throws ParseException { 46 jj_consume_token(10); 47 label_1: 48 while (true) { 49 switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { 50 case KEYWORD: 51 ; 52 break; 53 default: 54 jj_la1[0] = jj_gen; 55 break label_1; 56 } 57 param(); 58 } 59 jj_consume_token(11); 60 label_2: 61 while (true) { 62 switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { 63 case 13: 64 case 14: 65 case 15: 66 ; 67 break; 68 default: 69 jj_la1[1] = jj_gen; 70 break label_2; 71 } 72 element(); 73 } 74 switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { 75 case 12: 76 jj_consume_token(12); 77 break; 78 default: 79 jj_la1[2] = jj_gen; 80 ; 81 } 82 } 83 84 final public void param() throws ParseException { 85 String keyword; 86 String value; 87 jj_consume_token(KEYWORD); 88 keyword = token.image.toLowerCase(); 89 jj_consume_token(EQUALS); 90 value = value(); 91 values.put(keyword,value); 92 } 93 94 final public void element() throws ParseException { 95 HashMap input; 96 HashMap interpret; 97 switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { 98 case 13: 99 jj_consume_token(13); 100 input = new HashMap(); inputs.add(input); 101 label_3: 102 while (true) { 103 switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { 104 case KEYWORD: 105 ; 106 break; 107 default: 108 jj_la1[3] = jj_gen; 109 break label_3; 110 } 111 inputItem(input); 112 } 113 break; 114 case 14: 115 jj_consume_token(14); 116 interpret = new HashMap(); interprets.add(interpret); 117 label_4: 118 while (true) { 119 switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { 120 case KEYWORD: 121 ; 122 break; 123 default: 124 jj_la1[4] = jj_gen; 125 break label_4; 126 } 127 matchItem(interpret); 128 } 129 break; 130 case 15: 131 jj_consume_token(15); 132 jj_consume_token(KEYWORD); 133 label_5: 134 while (true) { 135 switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { 136 case KEYWORD: 137 ; 138 break; 139 default: 140 jj_la1[5] = jj_gen; 141 break label_5; 142 } 143 jj_consume_token(KEYWORD); 144 switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { 145 case EQUALS: 146 jj_consume_token(EQUALS); 147 value(); 148 break; 149 default: 150 jj_la1[6] = jj_gen; 151 ; 152 } 153 } 154 break; 155 default: 156 jj_la1[7] = jj_gen; 157 jj_consume_token(-1); 158 throw new ParseException(); 159 } 160 switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { 161 case 16: 162 jj_consume_token(16); 163 break; 164 case 11: 165 jj_consume_token(11); 166 break; 167 default: 168 jj_la1[8] = jj_gen; 169 jj_consume_token(-1); 170 throw new ParseException(); 171 } 172 } 173 174 final public void inputItem(HashMap input) throws ParseException { 175 String keyword; 176 String value = null; 177 jj_consume_token(KEYWORD); 178 keyword = token.image.toLowerCase(); 179 switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { 180 case EQUALS: 181 jj_consume_token(EQUALS); 182 value = value(); 183 break; 184 default: 185 jj_la1[9] = jj_gen; 186 ; 187 } 188 input.put(keyword,value); 189 } 190 191 final public void matchItem(HashMap interpret) throws ParseException { 192 String keyword; 193 String value = null; 194 jj_consume_token(KEYWORD); 195 keyword = token.image.toLowerCase(); 196 jj_consume_token(EQUALS); 197 value = value(); 198 interpret.put(keyword,value); 199 } 200 201 final public String value() throws ParseException { 202 String image; 203 switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { 204 case QUOTED_VALUE: 205 jj_consume_token(QUOTED_VALUE); 206 image = token.image.substring(1,token.image.length()-1); 207 break; 208 case UNQUOTED_VALUE: 209 jj_consume_token(UNQUOTED_VALUE); 210 image = token.image; 211 break; 212 default: 213 jj_la1[10] = jj_gen; 214 jj_consume_token(-1); 215 throw new ParseException(); 216 } 217 {if (true) return image;} 218 throw new Error ("Missing return statement in function"); 219 } 220 221 public PageDescriptionTokenManager token_source; 222 SimpleCharStream jj_input_stream; 223 public Token token, jj_nt; 224 private int jj_ntk; 225 private int jj_gen; 226 final private int[] jj_la1 = new int[11]; 227 static private int[] jj_la1_0; 228 static { 229 jj_la1_0(); 230 } 231 private static void jj_la1_0() { 232 jj_la1_0 = new int[] {0x40,0xe000,0x1000,0x40,0x40,0x40,0x80,0xe000,0x10800,0x80,0x300,}; 233 } 234 235 public PageDescription(java.io.InputStream stream) { 236 jj_input_stream = new SimpleCharStream(stream, 1, 1); 237 token_source = new PageDescriptionTokenManager(jj_input_stream); 238 token = new Token(); 239 jj_ntk = -1; 240 jj_gen = 0; 241 for (int i = 0; i < 11; i++) jj_la1[i] = -1; 242 } 243 244 public void ReInit(java.io.InputStream stream) { 245 jj_input_stream.ReInit(stream, 1, 1); 246 token_source.ReInit(jj_input_stream); 247 token = new Token(); 248 jj_ntk = -1; 249 jj_gen = 0; 250 for (int i = 0; i < 11; i++) jj_la1[i] = -1; 251 } 252 253 public PageDescription(java.io.Reader stream) { 254 jj_input_stream = new SimpleCharStream(stream, 1, 1); 255 token_source = new PageDescriptionTokenManager(jj_input_stream); 256 token = new Token(); 257 jj_ntk = -1; 258 jj_gen = 0; 259 for (int i = 0; i < 11; i++) jj_la1[i] = -1; 260 } 261 262 public void ReInit(java.io.Reader stream) { 263 jj_input_stream.ReInit(stream, 1, 1); 264 token_source.ReInit(jj_input_stream); 265 token = new Token(); 266 jj_ntk = -1; 267 jj_gen = 0; 268 for (int i = 0; i < 11; i++) jj_la1[i] = -1; 269 } 270 271 public PageDescription(PageDescriptionTokenManager tm) { 272 token_source = tm; 273 token = new Token(); 274 jj_ntk = -1; 275 jj_gen = 0; 276 for (int i = 0; i < 11; i++) jj_la1[i] = -1; 277 } 278 279 public void ReInit(PageDescriptionTokenManager tm) { 280 token_source = tm; 281 token = new Token(); 282 jj_ntk = -1; 283 jj_gen = 0; 284 for (int i = 0; i < 11; i++) jj_la1[i] = -1; 285 } 286 287 final private Token jj_consume_token(int kind) throws ParseException { 288 Token oldToken; 289 if ((oldToken = token).next != null) token = token.next; 290 else token = token.next = token_source.getNextToken(); 291 jj_ntk = -1; 292 if (token.kind == kind) { 293 jj_gen++; 294 return token; 295 } 296 token = oldToken; 297 jj_kind = kind; 298 throw generateParseException(); 299 } 300 301 final public Token getNextToken() { 302 if (token.next != null) token = token.next; 303 else token = token.next = token_source.getNextToken(); 304 jj_ntk = -1; 305 jj_gen++; 306 return token; 307 } 308 309 final public Token getToken(int index) { 310 Token t = token; 311 for (int i = 0; i < index; i++) { 312 if (t.next != null) t = t.next; 313 else t = t.next = token_source.getNextToken(); 314 } 315 return t; 316 } 317 318 final private int jj_ntk() { 319 if ((jj_nt=token.next) == null) 320 return (jj_ntk = (token.next=token_source.getNextToken()).kind); 321 else 322 return (jj_ntk = jj_nt.kind); 323 } 324 325 private java.util.Vector jj_expentries = new java.util.Vector (); 326 private int[] jj_expentry; 327 private int jj_kind = -1; 328 329 public ParseException generateParseException() { 330 jj_expentries.removeAllElements(); 331 boolean[] la1tokens = new boolean[17]; 332 for (int i = 0; i < 17; i++) { 333 la1tokens[i] = false; 334 } 335 if (jj_kind >= 0) { 336 la1tokens[jj_kind] = true; 337 jj_kind = -1; 338 } 339 for (int i = 0; i < 11; i++) { 340 if (jj_la1[i] == jj_gen) { 341 for (int j = 0; j < 32; j++) { 342 if ((jj_la1_0[i] & (1<<j)) != 0) { 343 la1tokens[j] = true; 344 } 345 } 346 } 347 } 348 for (int i = 0; i < 17; i++) { 349 if (la1tokens[i]) { 350 jj_expentry = new int[1]; 351 jj_expentry[0] = i; 352 jj_expentries.addElement(jj_expentry); 353 } 354 } 355 int[][] exptokseq = new int[jj_expentries.size()][]; 356 for (int i = 0; i < jj_expentries.size(); i++) { 357 exptokseq[i] = (int[])jj_expentries.elementAt(i); 358 } 359 return new ParseException(token, exptokseq, tokenImage); 360 } 361 362 final public void enable_tracing() { 363 } 364 365 final public void disable_tracing() { 366 } 367 368 } 369 | Popular Tags |