1 | package org.greenstone.server;
|
---|
2 |
|
---|
3 | import java.io.Serializable;
|
---|
4 |
|
---|
5 | public class GazetteerTrieTopLevelNode implements Serializable
|
---|
6 | {
|
---|
7 | private static final long serialVersionUID = 1L;
|
---|
8 | protected boolean _nameEnd = false;
|
---|
9 | protected GazetteerTrieNode[] _children = new GazetteerTrieNode[65000];
|
---|
10 |
|
---|
11 | /**
|
---|
12 | * Basic constructor for a non-unicode trie node
|
---|
13 | * @param nameEnd defines whether the new node represents the end of a place name
|
---|
14 | */
|
---|
15 | protected GazetteerTrieTopLevelNode(boolean nameEnd)
|
---|
16 | {
|
---|
17 | for(int i = 0; i < 65000; i++)
|
---|
18 | {
|
---|
19 | _children[i] = null;
|
---|
20 | }
|
---|
21 | _nameEnd = nameEnd;
|
---|
22 | }
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * Add a child to the current node
|
---|
26 | * @param c is the character used to decide where to add the child node
|
---|
27 | * @param nameEnd is whether or not this character represents the end of a place name
|
---|
28 | * @return true if a child was added and false if one already existed
|
---|
29 | */
|
---|
30 | protected boolean addChild(char c, boolean nameEnd)
|
---|
31 | {
|
---|
32 | if(c >= 65 && c <= 90)
|
---|
33 | {
|
---|
34 | c += 32;
|
---|
35 | }
|
---|
36 | //Add the ascii character if it either does not already exist or it signifies the end of a place name
|
---|
37 | if(_children[(int)c] != null)
|
---|
38 | {
|
---|
39 | if(_children[(int)c].isNameEnd() || nameEnd == false)
|
---|
40 | {
|
---|
41 | return false;
|
---|
42 | }
|
---|
43 | else
|
---|
44 | {
|
---|
45 | _children[(int)c].setNameEnd(true);
|
---|
46 | return true;
|
---|
47 | }
|
---|
48 | }
|
---|
49 | else
|
---|
50 | {
|
---|
51 | _children[(int)c] = new GazetteerTrieNode(nameEnd);
|
---|
52 | return true;
|
---|
53 | }
|
---|
54 | }
|
---|
55 |
|
---|
56 | /**
|
---|
57 | * @return whether or not this node represents the end of a place name
|
---|
58 | */
|
---|
59 | protected boolean isNameEnd()
|
---|
60 | {
|
---|
61 | return _nameEnd;
|
---|
62 | }
|
---|
63 |
|
---|
64 | /**
|
---|
65 | * Set whether or not this node represents the end of a place name
|
---|
66 | * @param nameEnd is the value to set it to
|
---|
67 | */
|
---|
68 | protected void setNameEnd(boolean nameEnd)
|
---|
69 | {
|
---|
70 | _nameEnd = nameEnd;
|
---|
71 | }
|
---|
72 |
|
---|
73 | /**
|
---|
74 | * Returns the child at the given index
|
---|
75 | * @param index is the index of the child to return
|
---|
76 | * @return the child at the given index
|
---|
77 | */
|
---|
78 | protected GazetteerTrieNode getChild(char c)
|
---|
79 | {
|
---|
80 | if(c >= 65 && c <= 90)
|
---|
81 | {
|
---|
82 | c += 32;
|
---|
83 | }
|
---|
84 | return _children[(int)c];
|
---|
85 | }
|
---|
86 |
|
---|
87 | public void output()
|
---|
88 | {
|
---|
89 | /*
|
---|
90 | if(_unicodeCharacters != null && _unicodeCharacters.size() >= 10)
|
---|
91 | {
|
---|
92 | System.out.println(_unicodeCharacters.size());
|
---|
93 | }
|
---|
94 |
|
---|
95 | for(GazetteerTrieNode g : _children)
|
---|
96 | {
|
---|
97 | if(g != null)
|
---|
98 | {
|
---|
99 | g.output();
|
---|
100 | }
|
---|
101 | }
|
---|
102 | */
|
---|
103 | }
|
---|
104 | } |
---|