Skip to content

Commit

Permalink
移除SmartBinTrie,用处不大
Browse files Browse the repository at this point in the history
  • Loading branch information
hankcs committed Nov 1, 2014
1 parent e971d44 commit 06be533
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 271 deletions.
12 changes: 1 addition & 11 deletions main/java/com/hankcs/hanlp/collection/trie/bintrie/BaseNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ protected boolean hasChild(char c)
return getChild(c) != null;
}

/**
* 获取节点代表的字符
* @return
*/
protected char getChar()
{
return c;
Expand Down Expand Up @@ -178,17 +174,11 @@ protected void walkToLoad(ByteArray byteArray, ValueArray valueArray)
child = new BaseNode[childSize];
for (int i = 0; i < childSize; ++i)
{
child[i] = newInstance();
child[i] = new Node<>();
child[i].walkToLoad(byteArray, valueArray);
}
}

/**
* 各个子类请在此返回一个子类的新实例
* @return
*/
protected abstract BaseNode<V> newInstance();

public static enum Status
{
/**
Expand Down
31 changes: 5 additions & 26 deletions main/java/com/hankcs/hanlp/collection/trie/bintrie/BinTrie.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.hankcs.hanlp.corpus.io.ByteArray;
import com.hankcs.hanlp.corpus.io.IOUtil;
import com.hankcs.hanlp.utility.CharUtility;
import com.hankcs.hanlp.utility.CharUtility;

import java.io.DataOutputStream;
import java.io.FileOutputStream;
Expand Down Expand Up @@ -47,28 +48,16 @@ public void put(String key, V value)
for (int i = 0; i < chars.length - 1; ++i)
{
// 除了最后一个字外,都是继续
branch.addChild(newNode(chars[i], Status.NOT_WORD_1, null));
branch.addChild(new Node(chars[i], Status.NOT_WORD_1, null));
branch = branch.getChild(chars[i]);
}
// 最后一个字加入时属性为end
if (branch.addChild(newNode(chars[chars.length - 1], Status.WORD_END_3, value)))
if (branch.addChild(new Node<V>(chars[chars.length - 1], Status.WORD_END_3, value)))
{
++size; // 维护size
}
}

/**
* 动态决定初始化哪种节点
* @param c
* @param status
* @param value
* @return
*/
protected BaseNode<V> newNode(char c, Status status, V value)
{
return new Node<V>(c, status, value);
}

/**
* 删除一个词
* @param key
Expand All @@ -83,7 +72,7 @@ public void remove(String key)
branch = branch.getChild(chars[i]);
}
// 最后一个字设为undefined
if (branch.addChild(newNode(chars[chars.length - 1], Status.UNDEFINED_0, value)))
if (branch.addChild(new Node(chars[chars.length - 1], Status.UNDEFINED_0, value)))
{
--size;
}
Expand Down Expand Up @@ -255,16 +244,6 @@ public BaseNode getChild(char c)
return child[c];
}

/**
* 返回一个空白的子节点,根据自己是否智能返回的节点类型不同
* @return
*/
@Override
protected BaseNode<V> newInstance()
{
return new Node<V>();
}

public boolean save(String path)
{
try
Expand Down Expand Up @@ -310,7 +289,7 @@ public boolean load(String path, V[] value)
int flag = byteArray.nextInt();
if (flag == 1)
{
child[i] = newInstance();
child[i] = new Node<>();
child[i].walkToLoad(byteArray, valueArray);
}
}
Expand Down
6 changes: 0 additions & 6 deletions main/java/com/hankcs/hanlp/collection/trie/bintrie/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,4 @@ public BaseNode getChild(char c)

return child[index];
}

@Override
protected BaseNode newInstance()
{
return new Node<>();
}
}

This file was deleted.

128 changes: 0 additions & 128 deletions main/java/com/hankcs/hanlp/collection/trie/bintrie/SmartNode.java

This file was deleted.

Loading

0 comments on commit 06be533

Please sign in to comment.