public static LexicalizedParser loadModelFromZip(String zipFilename, String modelName) { LexicalizedParser parser = null; try { File file = new File(zipFilename); if (file.exists()) { ZipFile zin = new ZipFile(file); ZipEntry zentry = zin.getEntry(modelName); if (zentry != null) { InputStream in = zin.getInputStream(zentry); // gunzip it if necessary if (modelName.endsWith(".gz")) { in = new GZIPInputStream(in); } ObjectInputStream ois = new ObjectInputStream(in); parser = loadModel(ois); ois.close(); in.close(); } zin.close(); }
/** * Construct a new LexicalizedParser object from a previously * serialized grammar read from a System property * <code>edu.stanford.nlp.SerializedLexicalizedParser</code>, or a * default classpath location * ({@code edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz}). */ /*public static LexicalizedParser loadModel() { * return loadModel(new Options()); * }*/ /** * Construct a new LexicalizedParser object from a previously * serialized grammar read from a System property * <code>edu.stanford.nlp.SerializedLexicalizedParser</code>, or a * default classpath location * ({@code edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz}). * * @param op Options to the parser. These get overwritten by the * Options read from the serialized parser; I think the only * thing determined by them is the encoding of the grammar * iff it is a text grammar */ /*public static LexicalizedParser loadModel(Options op, * String ... extraFlags) { * String source = System.getProperty(SERIALIZED_PARSER_PROPERTY); * if (source == null) { * source = DEFAULT_PARSER_LOC; * } * return loadModel(source, op, extraFlags); * }*/ /*public static LexicalizedParser loadModel(String parserFileOrUrl, * String ... extraFlags) { * return loadModel(parserFileOrUrl, new Options(), extraFlags); * }*/ /*public static LexicalizedParser loadModel(String parserFileOrUrl, * List<String> extraFlags) { * return loadModel(parserFileOrUrl, new Options(), extraFlags); * }*/ /** * Construct a new LexicalizedParser. This loads a grammar * that was previously assembled and stored as a serialized file. * @param parserFileOrUrl Filename/URL to load parser from * @param op Options for this parser. These will normally be overwritten * by options stored in the file * @throws IllegalArgumentException If parser data cannot be loaded */ public static LexicalizedParser loadModel(String parserFileOrUrl, /*Options op,*/ List <string> extraFlags) { // System.err.print("Loading parser from file " + parserFileOrUrl); LexicalizedParser parser = getParserFromFile(parserFileOrUrl, op); if (extraFlags.Count > 0) { parser.setOptionFlags(extraFlags); } return(parser); }