Skip to content

Commit

Permalink
集群环境中CoreStopWordDictionary适配IOAdapter: #530
Browse files Browse the repository at this point in the history
  • Loading branch information
hankcs committed May 16, 2017
1 parent ab1c2c3 commit 06686dd
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
31 changes: 25 additions & 6 deletions src/main/java/com/hankcs/hanlp/collection/MDAG/MDAG.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@

import com.hankcs.hanlp.corpus.io.ByteArray;
import com.hankcs.hanlp.corpus.io.ICacheAble;
import static com.hankcs.hanlp.HanLP.Config.IOAdapter;
import java.io.*;
import com.hankcs.hanlp.corpus.io.IOUtil;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.Map.Entry;

Expand Down Expand Up @@ -157,6 +160,16 @@ public boolean satisfiesCondition(String str1, String str2)
}
/////

/**
* 从文件路径构造
* @param path
* @throws IOException
*/
public MDAG(String path) throws IOException
{
this(IOUtil.newBufferedReader(path));
}


/**
* 从一个文件建立MDAG<br>
Expand All @@ -168,10 +181,16 @@ public boolean satisfiesCondition(String str1, String str2)
*/
public MDAG(File dataFile) throws IOException
{
BufferedReader dataFileBufferedReader = new BufferedReader(new InputStreamReader(IOAdapter == null ?
new FileInputStream(dataFile) :
IOAdapter.open(dataFile.getAbsolutePath())
, "UTF-8"));
this(IOUtil.newBufferedReader(dataFile.getPath()));
}

/**
* 从一个打开的BufferedReader构造
* @param dataFileBufferedReader
* @throws IOException
*/
public MDAG(BufferedReader dataFileBufferedReader) throws IOException
{
String currentString = "";
String previousString = "";

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/hankcs/hanlp/collection/MDAG/MDAGSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public MDAGSet()
{
}

public MDAGSet(String dictionaryPath) throws IOException
{
super(dictionaryPath);
}

@Override
public int size()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class CoreStopWordDictionary
{
try
{
dictionary = new StopWordDictionary(new File(HanLP.Config.CoreStopWordDictionaryPath));
dictionary = new StopWordDictionary(HanLP.Config.CoreStopWordDictionaryPath);
DataOutputStream out = new DataOutputStream(IOUtil.newOutputStream(HanLP.Config.CoreStopWordDictionaryPath + Predefine.BIN_EXT));
dictionary.save(out);
out.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public StopWordDictionary()
{
}

public StopWordDictionary(String stopWordDictionaryPath) throws IOException
{
super(stopWordDictionaryPath);
}

@Override
public boolean shouldInclude(Term term)
{
Expand Down

0 comments on commit 06686dd

Please sign in to comment.