Package org.predict4all.nlp.ngram.trie
Class StaticNGramTrieNode
- java.lang.Object
-
- org.predict4all.nlp.ngram.trie.AbstractNGramTrieNode<StaticNGramTrieNode>
-
- org.predict4all.nlp.ngram.trie.StaticNGramTrieNode
-
public class StaticNGramTrieNode extends AbstractNGramTrieNode<StaticNGramTrieNode>
Represent a static ngram trie node : when node are used only to retrieve information and compute probabilities, but children are never updated.
This node is particular because children node are loaded on demand from aFileChannel
.
This node is produced in a read only version : to create this node,DynamicNGramTrieNode
andTrainingNGramDictionary
should be used.
-
-
Field Summary
-
Fields inherited from class org.predict4all.nlp.ngram.trie.AbstractNGramTrieNode
children, childrenBackoffWeight, childrenPosition, DYNAMIC_TRIE_NODE_SIZE_BYTE, frequency, STATIC_TRIE_NODE_SIZE_BYTE
-
-
Constructor Summary
Constructors Constructor Description StaticNGramTrieNode()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
checkChildrenLoading(java.nio.channels.FileChannel fileChannel)
Check that children for this node are loaded.
If not, try to load children from the given fileChannel.int
getChildrenSize()
StaticNGramTrieNode
getNodeFor(java.nio.channels.FileChannel fileChannel, int[] prefix, int index)
Will try to retrieve a node for a given prefix.
Load needed node on demand while browsing the trie.
Children of the returned node are not loaded yet.int
readNodeInformation(java.nio.ByteBuffer buffWrite)
Read the node information contained into the given buffer to this node (without any check).-
Methods inherited from class org.predict4all.nlp.ngram.trie.AbstractNGramTrieNode
compact, getChildren, getChildrenBackoffWeight, getFrequency
-
-
-
-
Method Detail
-
getNodeFor
public StaticNGramTrieNode getNodeFor(java.nio.channels.FileChannel fileChannel, int[] prefix, int index) throws java.io.IOException
Will try to retrieve a node for a given prefix.
Load needed node on demand while browsing the trie.
Children of the returned node are not loaded yet.- Parameters:
fileChannel
- the file channel containing the trie structure.prefix
- ngram prefixindex
- index in prefix (0 = full prefix)- Returns:
- the node found for the given prefix (or null if the trie doesn't contains any node for the given prefix)
- Throws:
java.io.IOException
- if children can't be read for a node
-
checkChildrenLoading
public boolean checkChildrenLoading(java.nio.channels.FileChannel fileChannel) throws java.io.IOException
Check that children for this node are loaded.
If not, try to load children from the given fileChannel.- Parameters:
fileChannel
- file channel containing the trie structure.- Returns:
- true if there is children and children are loaded.
- Throws:
java.io.IOException
- if there is children, but they can't be loaded
-
readNodeInformation
public int readNodeInformation(java.nio.ByteBuffer buffWrite)
Read the node information contained into the given buffer to this node (without any check).- Parameters:
buffWrite
- the buffer containing node information.- Returns:
- this node word id (read from buffer)
-
getChildrenSize
public int getChildrenSize()
- Specified by:
getChildrenSize
in classAbstractNGramTrieNode<StaticNGramTrieNode>
- Returns:
- the different children count (not the total children count)
-
-