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