|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.util.Observable
de.folt.fuzzy.FuzzyDataStructureElement<K,T>
de.folt.fuzzy.FuzzyNode<K,T>
public class FuzzyNode<K,T>
This class implements a KD-TREE.
A fuzzy node consists of a n-dimensional fuzzy key FuzzyNodeKey where each element of the n-dim vector is a number. This number is normally generated
based on a tri-gram index for strings, but essentially can be computed in whatever way is convenient or necessary.
Each node has a left and right son (which can be null if there is none). The insert algorithms ensures that the left son is always lower than the right son. It has also a vector of values associated with it which contain the real data of the node (ids, objects or whatever). The values are typed.
The normal usage of the class is that it is sub classed where <T> gets a specific instantiation. For an example see of this see MonoLingualFuzzyNode
Basic fuzzy search mechanism works as follows:
int percentDiff = 100 - similarity; // the difference percentage value
Vector<FuzzyNodeSearchResult<K, T>> matches = new Vector<FuzzyNodeSearchResult<K, T>>();
Stack<FuzzyNode<K, T>> stack = new Stack<FuzzyNode<K, T>>(); // the stack for the search
// use the minimum of the key sum now
int minkeysum = this.getFuzzyNodeKey().getKeysum();
// difference allowed between search node and node inspected
float dist = 0;
if (percentDiff > 0)
{
dist = (int) ((minkeysum * percentDiff) / 100) + 2;
}
stack.push(this);
while (stack.size() > 0)
{
FuzzyNode<K, T> currentFuzzyNode = stack.pop(); // node to inspect
int difference = currentFuzzyNode.computeKeyDistance(fuzzyCompareKey);
boolean compval = (dist >= difference);
if (compval)
{
FuzzyNodeSearchResult<K, T> result = new FuzzyNodeSearchResult<K, T>(percentdiffreal, similarity, dist, difference, currentFuzzyNode, NODESSEARCHED, NODESMATCHED, NODESPUSHED);
matches.add(result);
}
int currentNodeLevelSum = currentFuzzyNode.getFuzzyNodeKey().computeKeySumTillLevel(currentFuzzyNode.LEVEL);
int compareNodeLevelSum = fuzzyCompareKey.getFuzzyNodeKey().computeKeySumTillLevel(currentFuzzyNode.LEVEL);
if (currentNodeLevelSum >= (compareNodeLevelSum - dist))
{
FuzzyNode<K, T> entry = currentFuzzyNode.getLeftSon() != null ? currentFuzzyNode.getLeftSon() : null;
if (entry != null)
{
stack.push(entry);
}
}
if (currentNodeLevelSum <= (compareNodeLevelSum + dist))
{
FuzzyNode<K, T> entry = currentFuzzyNode.getRightSon() != null ? currentFuzzyNode.getRightSon() : null;
if (entry != null)
{
stack.push(entry);
fuzzyCompareKey.NODESPUSHED = fuzzyCompareKey.NODESPUSHED + 1;
}
}
}
Pattern used: Factory
| Nested Class Summary | |
|---|---|
static class |
FuzzyNode.FUZZYNODESTATUS
|
| Constructor Summary | |
|---|---|
FuzzyNode()
This is the default constructor, basically does nothing. |
|
| Method Summary | |
|---|---|
int |
computeKeyDistance(FuzzyNode<K,T> fuzzyNode)
computeKeyDistance computes the distance between two fuzzy nodes based on its keys For the implementation see FuzzyNodeKey |
int |
countNodes()
countNodes count all the values below the actual nodes (the actual node is not included!) |
int |
countSons()
countSons count the number of sons |
int |
countValues()
countValues return the number of values of a node |
java.lang.String |
format()
format formats a FuzzyNode and returns a formatted string of the fuzzy node this + ":" + this.nodeID + "(" + this.maxID + "):" + ":" + this.status + " LE:" + this.LEVEL + " :LS(" + ils + " " + this.leftSon + "):RS(" + irs + " " + this.rightSon + "):" + this.fuzzyNodeKey.format() |
java.lang.String |
formatTree()
formatTree formats a FuzzyNode and its children and returns a formatted string of the fuzzy nodes |
java.lang.String |
formatTree(boolean bShortFormat)
formatTree formats a FuzzyNode and its children and returns a formatted string of the fuzzy nodes |
int |
getDepth()
getDepth get the depth of the KD-TREE fuzzy node |
FuzzyNodeKey |
getFuzzyNodeKey()
Get the FuzzyNodeKey associated with the FuzzyNode |
FuzzyNode<K,T> |
getLeftSon()
Get the left son of the FuzzyNode |
long |
getMaxID()
Get the maximum number of FuzzyNodes associated with this FuzzyNode |
static int |
getNGram()
Get the NGrams associated with the FuzzyNode (for FuzzyNodes based on Strings!) |
long |
getNodeID()
Get the unique identifier of the FuzzyNode |
int |
getNODESMATCHED()
|
int |
getNODESPUSHED()
|
int |
getNODESSEARCHED()
|
FuzzyNode<K,T> |
getRightSon()
Set the right son of the FuzzyNode |
FuzzyNode.FUZZYNODESTATUS |
getStatus()
Get the status of the node |
java.util.Vector<T> |
getValues()
Get the values associated with the FuzzyNode. |
int |
iBalance()
iBalance determine the height depth) difference in the nodes sons |
boolean |
insertFuzzyNode(FuzzyNode<K,T> fuzzyNodeToAdd)
insertFuzzyNode inserts a new FuzzyNode in the current FuzzyNode - which is actually a tree |
boolean |
insertFuzzyNode(FuzzyNode<K,T> fuzzyNodeToAdd,
boolean bInsertMode)
insertFuzzyNode insert a Fuzzy Node at a specific position in the tree applying a KDTREE insert algorithm. |
boolean |
isAVLTree()
isAVLTree check if AVL tree |
boolean |
isBInsertMode()
Get the insermode of the FuzzyNode |
void |
remove(java.lang.Object value)
remove remove for a fuzzy node based on the value of a node and removes this value from the value list. |
boolean |
removeValue(FuzzyNode<K,T> fuzzyCompareKey)
removeValue removes a value from the value list of the values of the node based on a key. |
boolean |
removeValue(java.lang.Object value)
removeValue removes a value from the value list of the values of the node |
boolean |
removeValue(java.util.Vector<java.lang.Object> values)
removeValue removes a vector of values from the value list of the values of the node |
java.util.Vector<FuzzyNodeSearchResult<K,T>> |
search(FuzzyNode<K,T> fuzzyCompareKey,
int similarity)
search searches FuzzyNode and its sons with a given similarity and returns a Vector of matching keys. |
java.util.Vector<FuzzyNode<K,T>> |
search(java.lang.Object value)
search search for a fuzzy node based on the value of a node |
void |
setBInsertmode(boolean insertmode)
Set the insert mode of the FuzzyNode. |
void |
setFuzzyNodeKey(FuzzyNodeKey fuzzyNodeKey)
Set the FuzzyNodeKey associated with the FuzzyNode |
void |
setLeftSon(FuzzyNode<K,T> leftSon)
Set the left son of the FuzzyNode |
void |
setMaxID(long maxID)
Set the maximum number of nodes for a given FuzzyNode. |
void |
setNodeID(long nodeID)
Set the uneque identifier of the FuzzyNode |
void |
setRightSon(FuzzyNode<K,T> rightSon)
Set the left son of the FuzzyNode |
void |
setStatus(FuzzyNode.FUZZYNODESTATUS status)
Set the status of the node |
void |
setValues(java.util.Vector<T> values)
Set the values associated with the FuzzyNode. |
java.lang.String |
shortFormat()
shortformat formats a FuzzyNode and returns a formatted string of the fuzzy node in a more compact way than format() |
boolean |
updateFuzzyNode(FuzzyNode<K,T> fuzzyNodeToAdd,
boolean bInsertMode)
updateFuzzyNode updates an existing fuzzy node with the value of the fuzzyNodeToAdd. |
| Methods inherited from class java.util.Observable |
|---|
addObserver, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public FuzzyNode()
| Method Detail |
|---|
public static int getNGram()
public int computeKeyDistance(FuzzyNode<K,T> fuzzyNode)
fuzzyNode - the fuzzy node to compare against the actual fuzzy node
public int countNodes()
public int countSons()
public int countValues()
public java.lang.String format()
this + ":" + this.nodeID + "(" + this.maxID + "):" + ":" + this.status + " LE:" + this.LEVEL + " :LS(" + ils + " " + this.leftSon + "):RS(" + irs + " " + this.rightSon + "):"
+ this.fuzzyNodeKey.format()
public java.lang.String formatTree()
public java.lang.String formatTree(boolean bShortFormat)
bShortFormat - true = use a short format display for node / false = long format
public int getDepth()
public FuzzyNodeKey getFuzzyNodeKey()
public FuzzyNode<K,T> getLeftSon()
public long getMaxID()
public long getNodeID()
public int getNODESMATCHED()
public int getNODESPUSHED()
public int getNODESSEARCHED()
public FuzzyNode<K,T> getRightSon()
public FuzzyNode.FUZZYNODESTATUS getStatus()
public java.util.Vector<T> getValues()
public int iBalance()
public boolean insertFuzzyNode(FuzzyNode<K,T> fuzzyNodeToAdd)
fuzzyNodeToAdd - the fuzzy node to add
public boolean insertFuzzyNode(FuzzyNode<K,T> fuzzyNodeToAdd,
boolean bInsertMode)
fuzzyNodeToAdd - the node to add to the fuzzy nodebInsertMode - if true the entry is added even if the node exists (values added), if false the found node has a value and only one value per node is allowed
public boolean isAVLTree()
public boolean isBInsertMode()
public void remove(java.lang.Object value)
value - public boolean removeValue(FuzzyNode<K,T> fuzzyCompareKey)
fuzzyCompareKey - the key containing the value to remove
public boolean removeValue(java.lang.Object value)
value - the object to remove
public boolean removeValue(java.util.Vector<java.lang.Object> values)
values - the vector of object values to remove
public java.util.Vector<FuzzyNodeSearchResult<K,T>> search(FuzzyNode<K,T> fuzzyCompareKey,
int similarity)
fuzzyCompareKey - the node to search for in the current node and its sonssimilarity - the similarity in % (100% = perfect match)
public java.util.Vector<FuzzyNode<K,T>> search(java.lang.Object value)
value -
public void setBInsertmode(boolean insertmode)
insertmode - the bInsertmode to setpublic void setFuzzyNodeKey(FuzzyNodeKey fuzzyNodeKey)
fuzzyNodeKey - the fuzzyNodeKey to setpublic void setLeftSon(FuzzyNode<K,T> leftSon)
leftSon - the leftSon to setpublic void setMaxID(long maxID)
maxID - the maxID to setpublic void setNodeID(long nodeID)
nodeID - the nodeID to setpublic void setRightSon(FuzzyNode<K,T> rightSon)
rightSon - the rightSon to setpublic void setStatus(FuzzyNode.FUZZYNODESTATUS status)
status - the status to setpublic void setValues(java.util.Vector<T> values)
values - the values to setpublic java.lang.String shortFormat()
public boolean updateFuzzyNode(FuzzyNode<K,T> fuzzyNodeToAdd,
boolean bInsertMode)
fuzzyNodeToAdd - the fuzzy node from which the value should be addedbInsertMode - if true the entry is added even if the node exists (values added), if false the found node has a value and only one value per node is allowed
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||