我正在使用IKVM将一些java库移植到我的c#项目中.库api(StanfordNLP)要求加载文件以训练nlp函数使用的统计模型.从文件系统加载文件已经好几周了,但我现在想将文件作为嵌入式资源添加到dll中,而不是从文件系统中检索它.
问题是java api没有找到.net嵌入式资源.
以下是从文件系统检索文件时有效的代码片段:
public class SNLPModel
{
public LexicalizedParser LP;
public SNLPModel()
{
// Using a relative file path in the target build directory
LP = LexicalizedParser.loadModel("models-stanford\\englishPCFG.ser.gz");
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我将"englishPCFG.ser.gz"文件设置为visual studio中的嵌入式资源(使用VS2012)时,更改代码以匹配:
public class SNLPModel
{
public LexicalizedParser LP;
public SNLPModel()
{
// Using this line of code to verify that the file is being loaded as
// an embedded resource. Running in debug, I have verified that it is, and
// noted its complete name.
string[] s = System.Reflection.Assembly.GetExecutingAssembly() …Run Code Online (Sandbox Code Playgroud)