CoreNlp splitting the stanford-corenlp-3.2.0-models.jar



我正试图部署stanford-corenlp-3.2.0-models.jar,但我的主机说罐子太大了?

如果我只是想使用POS,我可以用什么罐子代替。

或者我该如何拆分罐子?

您只需要了解如何使用jar命令。jar文件只是zip文件的变体。您可以使用jar -xf stanford-corenlp-3.2.0-models.jar扩展它的内容,获得您需要的内容,然后将其放入一个新的较小的jar文件中。

如果您只需要POS标记器,那么您可以从这里下载一个更轻的版本(35mb)的仅POS标记:http://nlp.stanford.edu/software/tagger.shtml

您可以使用Properties文件自定义注释器选项,如下所示:

Properties props1 = new Properties();
props1.put("annotators", "tokenize, cleanxml,ssplit, pos");

示例Java代码:

package parserOnly;
     import java.io.*;
     import java.util.*;
     import edu.stanford.nlp.io.*;
     import edu.stanford.nlp.ling.*;
     import edu.stanford.nlp.pipeline.*;
     import edu.stanford.nlp.semgraph.SemanticGraph;
     import edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations;
     import edu.stanford.nlp.trees.*;
     import edu.stanford.nlp.util.*;
     public class ParserOnly {
      public static void main(String[] args) throws IOException {
      PrintWriter out;
      if (args.length > 1) {
      out = new PrintWriter(args[1]);
    } else {
      out = new PrintWriter(System.out);
    }
    PrintWriter xmlOut = null;
    if (args.length > 2) {
      xmlOut = new PrintWriter(args[2]);
    }
    Properties props1 = new Properties();
    props1.put("annotators", "tokenize, cleanxml,ssplit, pos");
    StanfordCoreNLP pipeline = new StanfordCoreNLP(props1);
    Annotation annotation;
    if (args.length > 0) {
      annotation = new Annotation(IOUtils.slurpFileNoExceptions(args[0]));
    } else {
      annotation = new Annotation("Kosgi Santosh sent an email to Stanford University. He didn't get a reply.");
    }
    pipeline.annotate(annotation);
    pipeline.prettyPrint(annotation, out);
    if (xmlOut != null) {
      pipeline.xmlPrint(annotation, xmlOut);
    }
    // An Annotation is a Map and you can get and use the various analyses individually.
    // For instance, this gets the parse tree of the first sentence in the text.
    out.println();
    // The toString() method on an Annotation just prints the text of the Annotation
    // But you can see what is in it with other methods like toShorterString()
    out.println("The top level annotation");
    out.println(annotation.toShorterString());
    List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class);
    if (sentences != null && sentences.size() > 0) {
      ArrayCoreMap sentence = (ArrayCoreMap) sentences.get(0);
      out.println("The first sentence is:");
      out.println(sentence.toShorterString());
     // Tree tree = sentence.get(TreeCoreAnnotations.TreeAnnotation.class);
      out.println();
      out.println("The first sentence tokens are:");
      for (CoreMap token : sentence.get(CoreAnnotations.TokensAnnotation.class)) {
        ArrayCoreMap aToken = (ArrayCoreMap) token;
        out.println(aToken.toShorterString());
      }
     /* out.println("The first sentence parse tree is:");
      tree.pennPrint(out);
      out.println("The first sentence basic dependencies are:"); 
      System.out.println(sentence.get(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class).toString("plain"));
      out.println("The first sentence collapsed, CC-processed dependencies are:");
      SemanticGraph graph = sentence.get(SemanticGraphCoreAnnotations.CollapsedCCProcessedDependenciesAnnotation.class);
      System.out.println(graph.toString("plain"));*/
    }
  }
}

最新更新