如果只是在类路径和pos标记器的模型文件中包含解析器的模型文件,那么您应该没问题。 “引理”需要“pos”,因此您需要将其包含在注释器列表中。
例如:“edu / stanford / nlp / models / lexparser / englishPCFG.ser.gz”和“edu / stanford / nlp / models / pos-tagger / english-left3words / english-left3words-distsim.tagger”应该是你的全部需要。
您可以创建该目录结构并在类路径中包含这些文件,或者只使用其中的文件制作一个jar。你绝对可以切掉大部分罐子。
最重要的是,如果您遗漏了某些内容,您的代码将因资源丢失而崩溃。所以你只需要继续添加文件,直到代码停止崩溃。你肯定不需要那个jar中的很多文件。
按照@StanfordNLPHelp提到的类似方法,我使用了maven-shade-plugin并减小了我最终编译的jar文件的大小。你需要改变“Package.MainClass”和 includes 标记或添加 excludes 标签
includes
excludes
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>3.1.0</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <transformers> <!-- adding Main-Class to manifest file --> <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <mainClass>Package.MainClass</mainClass> </transformer> </transformers> <minimizeJar>true</minimizeJar> <filters> <filter> <artifact>edu.stanford.nlp:stanford-corenlp</artifact> <includes> <include>**</include> </includes> </filter> <filter> <artifact>edu.stanford.nlp:stanford-corenlp:models</artifact> <includes> <include>edu/stanford/nlp/models/pos-tagger/**</include> </includes> </filter> </filters> </configuration> </execution> </executions> </plugin>