/** * <!-- readLexicon(ExceptionlessInputStream,boolean) --> Reads a feature lexicon from the * specified stream. * * @param in The stream from which to read the feature lexicon. * @return The lexicon. **/ public static Lexicon readLexicon(ExceptionlessInputStream in) { return readLexicon(in, true); }
/** * <!-- readLexicon(URL) --> Reads a feature lexicon from the specified location. * * @param url The location from which to read the feature lexicon. * @return The lexicon. **/ public static Lexicon readLexicon(URL url) { return readLexicon(url, true); }
/** * Reads the learned function's feature lexicon from the specified location, overwriting the * lexicon present in this object, if any. This location is then cached in {@link #lexFilePath}. * * @param url The location from which to read the feature lexicon. **/ public void readLexicon(URL url) { lexicon = Lexicon.readLexicon(url); lexFilePath = url; }
/** * <!-- readLexicon(String) --> Reads and returns a feature lexicon from the specified file. * * @param filename The name of the file from which to read the feature lexicon. * @return The lexicon. **/ public static Lexicon readLexicon(String filename) { try { return readLexicon(new URL("file:" + filename)); } catch (Exception e) { System.err.println("Error constructing URL:"); e.printStackTrace(); System.exit(1); } return null; }
public static void main(String[] args) { String filename = null; boolean p = true; try { filename = args[0]; if (args.length == 2) p = Boolean.parseBoolean(args[1]); if (args.length > 2) throw new Exception(); } catch (Exception e) { System.out .println("usage: java edu.illinois.cs.cogcomp.lbjava.learn.Lexicon <lex file> [<package names = true>]"); System.exit(1); } Lexicon lexicon = readLexicon(filename); lexicon.printCountTable(p); if (lexicon.lexiconChildren != null) { System.out.println("\nChildren:"); lexicon.lexiconChildren.printCountTable(p); } }
/** * <!-- readLexicon(URL,boolean) --> Reads a feature lexicon from the specified location, with * the option to ignore the feature counts by setting the second argument to <code>false</code>. * * @param url The location from which to read the feature lexicon. * @param readCounts Whether or not to read the feature counts. * @return The lexicon. **/ public static Lexicon readLexicon(URL url, boolean readCounts) { ExceptionlessInputStream in = ExceptionlessInputStream.openCompressedStream(url); Lexicon result = readLexicon(in, readCounts); in.close(); return result; }
/** * Returns this learner's feature lexicon after discarding any feature counts it may have been * storing. This method is likely only useful when the lexicon and its counts are currently * stored on disk and {@link #readLexiconOnDemand(String)} or {@link #readLexiconOnDemand(URL)} * has already been called, in which case the lexicon is read from disk without wasting time * loading the counts. **/ public Lexicon getLexiconDiscardCounts() { if (readLexiconOnDemand && (lexicon == null || lexicon.size() == 0)) lexicon = Lexicon.readLexicon(lexFilePath, false); else lexicon.countFeatures(Lexicon.CountPolicy.none); return lexicon; }
/** * Reads the initial portion of the model file, including the containing package and name * strings, the names of the labeler and extractor, and finally the label lexicon. This method * will not read any further model parameters, however. * * @param in The input stream. **/ public void readLabelLexicon(ExceptionlessInputStream in) { containingPackage = in.readString().intern(); name = in.readString().intern(); encoding = in.readString(); if (encoding != null) encoding = encoding.intern(); String s = in.readString(); labeler = s == null ? null : ClassUtils.getClassifier(s); s = in.readString(); extractor = s == null ? null : ClassUtils.getClassifier(s); labelLexicon = Lexicon.readLexicon(in); if (predictions == null) predictions = new FVector(); predictions.read(in); }
newLabelLexicon = Lexicon.readLexicon(in); else newLabelLexicon = labelLexicon;
lexiconChildren = (ChildLexicon) Lexicon.readLexicon(in, readCounts);