Skip to content
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

1.x #1579

Open
wants to merge 3 commits into
base: 1.x
Choose a base branch
from
Open

1.x #1579

wants to merge 3 commits into from

Conversation

xiaoheizai
Copy link

增加流的读取方式

增加流的读取方式
增加流的读取方式
增加流的读取方式
@hankcs
Copy link
Owner

hankcs commented Oct 29, 2020

感谢贡献。能谈一谈为什么需要InputStream吗?目前已经有了自定义IO的接口:

public class ResourceIOAdapter implements IIOAdapter

@xiaoheizai
Copy link
Author

谢谢回复
场景是这样的:
我利用hanlp训练crf模型后,模型文件比较小,我就直接放在了jar包里;
读取jar包的资源文件时,用流的方式比较方便,无法直接定位到jar包里的资源文件的路径,因而无法用String的方式;
但是发现crf读取文件的模式只有String模式,无法利用流的读取方式,因而希望增加流的读取方式
万分感谢

@hankcs
Copy link
Owner

hankcs commented Oct 30, 2020

在这种情景下,你应该用IO适配器。

https://github.com/hankcs/HanLP/blob/1.x/src/main/java/com/hankcs/hanlp/HanLP.java#L212-L216

@hankcs
Copy link
Owner

hankcs commented Oct 30, 2020

毕竟Portable版的文件也是打包在jar里,HanLP已经有一套完善的自定义接口。

@xiaoheizai
Copy link
Author

请问我该怎么使用这个IO适配器来获取crf的bin模型呢?
// 如何读取已经训练好的bin文件?
CRFSegmenter segmenter = new CRFSegmenter(输入文件路径);

@xiaoheizai
Copy link
Author

你好,我尝试了,还是有些问题
如果我没有理解错误,那么可以用如下方式读取
IIOAdapter IoAdapter = new ResourceIOAdapter();
InputStream is = IoAdapter.open("xxx.bin");
然而接下来我该如何加载模型呢?
CRFSegmenter并没有提供流的参数传入
我还是创建不了模型CRFSegmenter,请问利用IIOAdapter读取文件后,我该如何加载呢?是不是还有其他方式可以加载模型

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants