-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
关于IIOAdapter的疑问 #536
Comments
下面是我实现的HDFS的词库加载类,经测试可以正常使用 import com.hankcs.hanlp.corpus.io.IIOAdapter;
import com.hankcs.hanlp.corpus.io.IOUtil;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
public class HdfsIoAdapter implements IIOAdapter {
public InputStream open(String s) throws IOException {
URL url = new URL(s+"?op=OPEN");
System.out.println(url.toString());
HttpURLConnection con = (HttpURLConnection)url.openConnection();
if (con.getResponseCode() >= 400){
return null;
}
int contentLength = con.getContentLength();
InputStream is = con.getInputStream();
if (contentLength <= 0){
contentLength = is.available();
}
byte[] buffer = new byte[contentLength];
IOUtil.readBytesFromOtherInputStream(is,buffer);
return new ByteArrayInputStream(buffer);
}
public OutputStream create(String s) throws IOException {
return null;
}
} 这里有个问题,最初的 public InputStream open(String s) throws IOException {
URL url = new URL(s+"?op=OPEN");
return url.getInputStream();
} 此时 对于 |
同时建议 |
|
|
我明白你的意思了。
|
|
|
明天会对新的版本进行整合测试,到时候报告一下测试结果,多谢 |
String rootPath = settings.get("analysis.hanlp.rootPath", null);
if (TextUtility.isBlank(rootPath)){
return;
}
String ioType = settings.get("analysis.hanlp.ioType", "file");
if (!isSuccess || (ioType.equals("hdfs") && !HdfsUtils.isDirExits(rootPath))){
HanLP.Config.IOAdapter = new FileIOAdapter();
rootPath = settings.get("analysis.hanlp.localDicPath", null);
ioType = "file";
if (TextUtility.isBlank(rootPath)){
return;
}
}
File f = new File(rootPath);
if (!f.exists()){
return;
} |
|
读取hdfs词库文件出现java heap size溢出; 跟踪查看了,因为com.hankcs.hanlp.dictionary.CoreDictionary.Attribute 加载 不知道什么原因造成的,期待大牛们帮忙解决...或是有其它的途进读取hdfs上的词典,方便告知... |
|
感谢 @hankcs , 参考hanlp-ext调试可以了! |
其实传进来的参数都是路径,是否尝试过直接使用hdfs的方法操作呢?FSDataInputStream以及FSDataOutputStream是可以直接当做InputStream和OutputStream来操作的。
|
IIOAdapter中有两个接口需要实现:open与create;
现在我想将词库放在HDFS上,读取很好实现,只是现在不大清楚create方法的具体作用;
现在需要明确的是:
The text was updated successfully, but these errors were encountered: