return count;\r
}\r
\r
- void recursiveSetDescendantOffsetCount() {\r
+ void recursiveSetDescendantCounts() {\r
+ descendantTokenCount = entryDescriptorsMap.size();\r
descendantEntryCount = 0;\r
- descendantTokenCount = 0;\r
- for (final List<EntryDescriptor> entryDescriptors : entryDescriptorsMap.values()) {\r
- descendantTokenCount += 1;\r
- descendantEntryCount += entryDescriptors.size();\r
- }\r
+\r
for (final Node child : children.values()) {\r
- child.recursiveSetDescendantOffsetCount();\r
+ child.recursiveSetDescendantCounts();\r
descendantTokenCount += child.descendantTokenCount;\r
descendantEntryCount += child.descendantEntryCount;\r
}\r
+\r
+ for (final List<EntryDescriptor> entryDescriptors : entryDescriptorsMap.values()) {\r
+ descendantEntryCount += entryDescriptors.size();\r
+ }\r
}\r
\r
@Override\r
assert indexFileLocation == file.getFilePointer();\r
}\r
\r
- // Children.\r
+ // Children to location.\r
file.writeInt(children.size());\r
for (final Map.Entry<String, Node> child : children.entrySet()) {\r
file.writeUTF(child.getKey());\r
file.writeInt(entry.getValue().get(i).offset);\r
}\r
}\r
+\r
+ // Dump counts.\r
+ file.writeInt(descendantTokenCount);\r
+ file.writeInt(descendantEntryCount);\r
\r
// Dump children.\r
for (final Map.Entry<String, Node> child : children.entrySet()) {\r
if (token.length() <= 1 || !Character.isLetter(token.charAt(0))) {\r
continue;\r
}\r
- tokenToNormalizedMap.put(token, EntryFactory.entryFactory.normalizeToken(token, lang));\r
+ tokenToNormalizedMap.put(token, EntryFactory.entryFactory.normalizeToken(token));\r
}\r
for (final Map.Entry<String, String> tokenToNormalized : tokenToNormalizedMap.entrySet()) {\r
final String normalizedToken = tokenToNormalized.getValue();\r
fileLocation = dictionaryFile.getFilePointer();\r
}\r
dictionaryFile.close();\r
+ \r
+ root.recursiveSetDescendantCounts();\r
+ \r
return root;\r
}\r
\r
static final String file = "c:\\dict-de-en.txt";\r
static final String file_index = file + "_index_0";\r
\r
+ public void testRoot() throws IOException {\r
+ System.out.println(" testRoot");\r
+ final Index index = new Index(file_index);\r
+ final Node node = index.lookup("");\r
+ assertNotNull(node);\r
+ \r
+ assertEquals(312220, node.descendantTokenCount);\r
+ assertEquals(1087063, node.descendantEntryCount);\r
+ \r
+ for (final String token : node.tokenToOffsets.keySet()) {\r
+ System.out.println(token);\r
+ assertTrue(token.toLowerCase().contains("handhubwagen"));\r
+ }\r
+ }\r
+ \r
public void testLookup() throws IOException {\r
- System.out.println("testLookup");\r
+ System.out.println(" testLookup");\r
final Index index = new Index(file_index);\r
final Node node = index.lookup("handhubwagen");\r
assertNotNull(node);\r
\r
- final RandomAccessFile raf = new RandomAccessFile(file, "r");\r
- for (int i = 0; i < node.offsets.length; ++i) {\r
- final String entry = FileUtil.readLine(raf, node.offsets[i]);\r
- System.out.println(entry);\r
- assertTrue(entry.toLowerCase().contains("handhubwagen"));\r
+ assertEquals(1, node.descendantTokenCount);\r
+ assertEquals(2, node.descendantEntryCount);\r
+ \r
+ for (final String token : node.tokenToOffsets.keySet()) {\r
+ System.out.println(token);\r
+ assertTrue(token.toLowerCase().contains("handhubwagen"));\r
}\r
}\r
\r
public void testGetDescendantOffsets() throws IOException {\r
- System.out.println("testGetDescendantOffsets");\r
+ System.out.println(" testGetDescendantOffsets");\r
final Index index = new Index(file_index);\r
\r
final Node node = index.lookup("handhebe");\r
assertNotNull(node);\r
- assertEquals("handhebel", node.text);\r
+ assertEquals("handhebel", node.nodeHandle.normalizedToken);\r
final Set<Integer> offsets = new LinkedHashSet<Integer>();\r
node.getDescendantEntryOffsets(offsets, 10);\r
final RandomAccessFile raf = new RandomAccessFile(file, "r");\r
for (final Integer offset : offsets) {\r
final String entry = FileUtil.readLine(raf, offset);\r
System.out.println(entry);\r
- assertTrue(entry.toLowerCase().contains(node.text));\r
+ assertTrue(entry.toLowerCase().contains(node.nodeHandle.normalizedToken));\r
+ }\r
+ }\r
+\r
+ public void testGetDescendants() throws IOException {\r
+ System.out.println(" testGetDescendant");\r
+ final Index index = new Index(file_index);\r
+ final RandomAccessFile raf = new RandomAccessFile(file, "r");\r
+ for (int i = 1000000; i < 1000050; ++i) {\r
+ final Object o = index.root.getDescendant(i);\r
+ if (o instanceof Integer) {\r
+ System.out.println(" " + FileUtil.readLine(raf, (Integer)o));\r
+ } else {\r
+ System.out.println(o);\r
+ }\r
}\r
+ raf.close();\r
}\r
\r
}\r