2017-05-25 84 views
0

我目前使用下面的C#代碼來創建我的成功Lexparser:斯坦福NLP Lexparser loadModel()

return LexicalizedParser.loadModel(projectDir + @"StanfordResources/lexparser/englishPCFG.ser.gz"); 

但由於部署原因,我寧願嵌入「englishPCFG.ser.gz」文件作爲某種資源進入程序集或作爲Resource.resx。

所以我嘗試閱讀我的byte []文件像這樣:

ObjectInputStream stream = new ObjectInputStream(new ByteArrayInputStream(Resource.englishPCFG_ser)); 
     return LexicalizedParser.loadModel(stream); 

,但我得到了以下錯誤:

java.io.StreamCorruptedException: invalid stream header: 1F8B0800 

是否有另一種方式來加載這個,而不是從一個文件路徑還是我做一個愚蠢的?

回答

0

1F8B0800是GZIP頭,這是有道理的,給出你想要讀取的文件的名稱。所以,你需要把java.util.zip.GZIPInputStreamByteArrayInputStreamObjectInputStream之間:

new ObjectInputStream(new GZIPInputStream(new ByteArrayInputStream(Resource.englishPCFG_ser))) 
+0

砸,謝謝。 – Wurd