Skip to content

Commit

Permalink
修复mini二元文法在JRE初始化后第一次分词可能出现的不一致 fix: #1851 (comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
hankcs committed Oct 19, 2023
1 parent 9e2c58c commit 4b2686c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/hankcs/hanlp/dictionary/CoreDictionary.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public class CoreDictionary
}

// 一些特殊的WORD_ID
public static final int BEGIN_WORD_ID = getWordID(Predefine.TAG_BIGIN);
public static final int END_WORD_ID = getWordID(Predefine.TAG_END);
public static final int NR_WORD_ID = getWordID(Predefine.TAG_PEOPLE);
public static final int NS_WORD_ID = getWordID(Predefine.TAG_PLACE);
public static final int NT_WORD_ID = getWordID(Predefine.TAG_GROUP);
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/hankcs/hanlp/seg/common/Vertex.java
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,8 @@ public static Vertex newTimeInstance(String realWord)
*/
public static Vertex newB()
{
return new Vertex(Predefine.TAG_BIGIN, " ", new CoreDictionary.Attribute(Nature.begin, Predefine.TOTAL_FREQUENCY / 10), CoreDictionary.getWordID(Predefine.TAG_BIGIN));
int wordId = CoreDictionary.BEGIN_WORD_ID;
return new Vertex(Predefine.TAG_BIGIN, " ", new CoreDictionary.Attribute(Nature.begin, Predefine.TOTAL_FREQUENCY / 10), wordId);
}

/**
Expand All @@ -461,7 +462,8 @@ public static Vertex newB()
*/
public static Vertex newE()
{
return new Vertex(Predefine.TAG_END, " ", new CoreDictionary.Attribute(Nature.end, Predefine.TOTAL_FREQUENCY / 10), CoreDictionary.getWordID(Predefine.TAG_END));
int wordId = CoreDictionary.END_WORD_ID;
return new Vertex(Predefine.TAG_END, " ", new CoreDictionary.Attribute(Nature.end, Predefine.TOTAL_FREQUENCY / 10), wordId);
}

public int length()
Expand Down

0 comments on commit 4b2686c

Please sign in to comment.