/** * Reads the learned function's feature lexicon from the specified file, overwriting the lexicon * present in this object, if any. This file is then cached in {@link #lexFilePath}. * * @param filename The name of the file from which to read the feature lexicon. **/ public void readLexicon(String filename) { try { readLexicon(new URL("file:" + filename)); } catch (Exception e) { System.err.println("Error constructing URL:"); e.printStackTrace(); System.exit(1); } }
/** * Reads the learned function's binary internal represetation including both its model and * lexicons from the specified files, overwriting any and all data this object may have already * contained. These files are then cached in {@link #lcFilePath} and {@link #lexFilePath}. * * @param modelFile The name of the file from which to read the model. * @param lexFile The name of the file from which to read the feature lexicon. **/ public void read(String modelFile, String lexFile) { readModel(modelFile); readLexicon(lexFile); }
/** * Forces this learner to read in its lexicon representation, but only if the lexicon currently * available in this object is empty and the learner has been scheduled to read its lexicon on * demand with {@link #readLexiconOnDemand(URL)}. * * @see #readLexiconOnDemand * @return The lexicon just read into {@link #lexicon}. **/ public Lexicon demandLexicon() { if (readLexiconOnDemand && (lexicon == null || lexicon.size() == 0)) { readLexicon(lexFilePath); readLexiconOnDemand = false; } return lexicon; }
public static void main(String[] args) { String exFileName = null; String lexFileName = null; String lcFileName = null; try { exFileName = args[0]; lexFileName = args[1]; lcFileName = args[2]; if (args.length > 3) throw new Exception(); } catch (Exception e) { System.err .println("usage: java edu.illinois.cs.cogcomp.lbjava.parse.ArrayFileParser <example file> <lexicon file> <lc file>"); System.exit(1); } ArrayFileParser parser = new ArrayFileParser(exFileName); Learner learner = Learner.readLearner(lcFileName); learner.readLexicon(lexFileName); for (Object e = parser.next(); e != null; e = parser.next()) { FeatureVector v = new FeatureVector((Object[]) e, learner.getLexicon(), learner.getLabelLexicon()); v.sort(); System.out.println(v); } } }
readLexicon(lexFilePath); readLexiconOnDemand = false;