01: /*
02: * WebSphinx web-crawling toolkit
03: *
04: * Copyright (c) 1998-2002 Carnegie Mellon University. All rights
05: * reserved.
06: *
07: * Redistribution and use in source and binary forms, with or without
08: * modification, are permitted provided that the following conditions
09: * are met:
10: *
11: * 1. Redistributions of source code must retain the above copyright
12: * notice, this list of conditions and the following disclaimer.
13: *
14: * 2. Redistributions in binary form must reproduce the above copyright
15: * notice, this list of conditions and the following disclaimer in
16: * the documentation and/or other materials provided with the
17: * distribution.
18: *
19: * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
20: * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
23: * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30: *
31: */
32:
33: package websphinx;
34:
35: import java.util.Vector;
36: import java.util.Enumeration;
37:
38: /**
39: * Base class for pattern matchers.
40: */
41: public abstract class Pattern
42: //#ifdef JDK1.1
43: implements java.io.Serializable
44: //#endif JDK1.1
45: {
46:
47: public abstract PatternMatcher match(Region region);
48:
49: public boolean found(Region region) {
50: return match(region).hasMoreElements();
51: }
52:
53: public Region oneMatch(Region region) {
54: return match(region).nextMatch();
55: }
56:
57: public Region[] allMatches (Region region) {
58: Vector v = new Vector ();
59: PatternMatcher enum = match (region);
60: Region r;
61: while ((r = enum.nextMatch ()) != null)
62: v.addElement (r);
63:
64: Region[] regions = new Region[v.size ()];
65: v.copyInto (regions);
66: return regions;
67: }
68:
69: public boolean found(String string) {
70: return found(new Page(string));
71: }
72:
73: public Region oneMatch(String string) {
74: return oneMatch(new Page(string));
75: }
76:
77: public Region[] allMatches(String string) {
78: return allMatches(new Page(string));
79: }
80:
81: public String[] getFieldNames() {
82: return new String[0];
83: }
84:
85: /**
86: * Return a string representation of the pattern.
87: */
88: public abstract String toString();
89:
90: public static final String groups = "Pattern.groups";
91:
92: }
|