public static BasicRelationExtractor load(String modelPath) throws IOException, ClassNotFoundException { return IOUtils.readObjectFromURLOrClasspathOrFileSystem(modelPath); }
public static SentimentModel loadSerialized(String path) { try { return IOUtils.readObjectFromURLOrClasspathOrFileSystem(path); } catch (IOException | ClassNotFoundException e) { throw new RuntimeIOException(e); } }
private static Set<String> loadVocabulary(String wordCountsPath) { Set<String> vocabulary = new HashSet<>(); try { Counter<String> counts = IOUtils.readObjectFromURLOrClasspathOrFileSystem(wordCountsPath); for (Map.Entry<String, Double> e : counts.entrySet()) { if (e.getValue() > MIN_WORD_COUNT) { vocabulary.add(e.getKey()); } } } catch (Exception e) { throw new RuntimeException("Error loading word counts", e); } return vocabulary; }
protected static List<List<CRFDatum<Collection<String>, String>>> loadProcessedData(String filename) { List<List<CRFDatum<Collection<String>, String>>> result; try { result = IOUtils.readObjectFromURLOrClasspathOrFileSystem(filename); } catch (Exception e) { log.warn(e); result = Collections.emptyList(); } log.info("Loading processed data from serialized file ... done. Got " + result.size() + " datums."); return result; }
public static MentionDetectionClassifier loadMentionDetectionClassifier(String filename) throws ClassNotFoundException, IOException { log.info("loading MentionDetectionClassifier ..."); MentionDetectionClassifier mdc = IOUtils.readObjectFromURLOrClasspathOrFileSystem(filename); log.info("done"); return mdc; }
/** * Load a factory model from a given path. This can be trained with * {@link ClauseSplitter#train(Stream, Optional, Optional, Featurizer)}. * * @return A function taking a dependency tree, and returning a clause searcher. */ static ClauseSplitter load(String serializedModel) throws IOException { try { long start = System.currentTimeMillis(); Pair<Classifier<ClauseClassifierLabel,String>, Featurizer> data = IOUtils.readObjectFromURLOrClasspathOrFileSystem(serializedModel); ClauseSplitter rtn = (tree, truth) -> new ClauseSplitterSearchProblem(tree, truth, Optional.of(data.first), Optional.of(data.second)); log.info("Loading clause splitter from " + serializedModel + " ... done [" + Redwood.formatTimeDifference(System.currentTimeMillis() - start) + "]"); return rtn; } catch (ClassNotFoundException e) { throw new IllegalStateException("Invalid model at path: " + serializedModel, e); } }
@SuppressWarnings({"unchecked"}) private static Set<String>[] loadDictionary(String serializePath) { Set<String>[] dict = new HashSet[MAX_LEXICON_LENGTH+1]; for (int i = 0; i <= MAX_LEXICON_LENGTH; i++) { dict[i] = Generics.newHashSet(); } // logger.info("loading dictionaries from " + serializePath + "..."); try { // once we read MAX_LEXICON_LENGTH and cdtos as well // now these files only store one object we care about //ChineseDictionary.MAX_LEXICON_LENGTH = (int) ois.readObject(); dict = IOUtils.readObjectFromURLOrClasspathOrFileSystem(serializePath); } catch (Exception e) { logger.error("Failed to load Chinese dictionary " + serializePath, e); throw new RuntimeException(e); } return dict; }
public HybridCorefMentionFinder(HeadFinder headFinder, Properties props) throws ClassNotFoundException, IOException { this.headFinder = headFinder; this.lang = CorefProperties.getLanguage(props); mdClassifier = (CorefProperties.isMentionDetectionTraining(props))? null : IOUtils.readObjectFromURLOrClasspathOrFileSystem(CorefProperties.getMentionDetectionModel(props)); }
public DependencyCorefMentionFinder(Properties props) throws ClassNotFoundException, IOException { this.lang = CorefProperties.getLanguage(props); mdClassifier = (CorefProperties.isMentionDetectionTraining(props)) ? null : IOUtils.readObjectFromURLOrClasspathOrFileSystem(CorefProperties.getMentionDetectionModel(props)); }
/** * Load Bergsma and Lin (2006) gender and number list. * <br> * The list is converted from raw text and numbers to a serialized * map, which saves quite a bit of time loading. * See edu.stanford.nlp.dcoref.util.ConvertGenderFile */ private void loadGenderNumber(String file, String neutralWordsFile) { try { getWordsFromFile(neutralWordsFile, neutralWords, false); } catch (IOException e) { throw new RuntimeIOException("Couldn't load " + neutralWordsFile); } try { Map<List<String>, Gender> temp = IOUtils.readObjectFromURLOrClasspathOrFileSystem(file); genderNumber.putAll(temp); } catch (IOException | ClassNotFoundException e) { throw new RuntimeIOException("Couldn't load " + file); } }
Object object = IOUtils.readObjectFromURLOrClasspathOrFileSystem(model); KBPRelationExtractor statisticalExtractor; if (object instanceof LinearClassifier) {
public static <T> T readObjectAnnouncingTimingFromURLOrClasspathOrFileSystem(Redwood.RedwoodChannels log, String msg, String path) { T obj; try { Timing timing = new Timing(); obj = IOUtils.readObjectFromURLOrClasspathOrFileSystem(path); log.info(msg + ' ' + path + " ... done [" + timing.toSecondsString() + " sec]."); } catch (IOException | ClassNotFoundException e) { throw new RuntimeIOException(e); } return obj; }
public static ParserGrammar loadModel(String path, String ... extraFlags) { ParserGrammar parser; try { Timing timing = new Timing(); parser = IOUtils.readObjectFromURLOrClasspathOrFileSystem(path); timing.done(logger, "Loading parser from serialized file " + path); } catch (IOException | ClassNotFoundException e) { throw new RuntimeIOException(e); } if (extraFlags.length > 0) { parser.setOptionFlags(extraFlags); } return parser; }
public static Sieve loadSieve(Properties props, String sievename) throws Exception { // log.info("Loading sieve: "+sievename+" ..."); switch(HybridCorefProperties.getClassifierType(props, sievename)) { case RULE: DeterministicCorefSieve sieve = (DeterministicCorefSieve) Class.forName("edu.stanford.nlp.coref.hybrid.sieve."+sievename).getConstructor().newInstance(); sieve.props = props; sieve.lang = HybridCorefProperties.getLanguage(props); return sieve; case RF: log.info("Loading sieve: " + sievename + " from " + HybridCorefProperties.getPathModel(props, sievename) + " ... "); RFSieve rfsieve = IOUtils.readObjectFromURLOrClasspathOrFileSystem(HybridCorefProperties.getPathModel(props, sievename)); rfsieve.thresMerge = HybridCorefProperties.getMergeThreshold(props, sievename); log.info("done. Merging threshold: " + rfsieve.thresMerge); return rfsieve; case ORACLE: OracleSieve oracleSieve = new OracleSieve(props, sievename); oracleSieve.props = props; return oracleSieve; default: throw new RuntimeException("no sieve type specified"); } }
Object object = IOUtils.readObjectFromURLOrClasspathOrFileSystem(STATISTICAL_MODEL); KBPRelationExtractor statisticalExtractor; if (object instanceof LinearClassifier) {
public static DVParser loadModel(String filename, String[] args) { log.info("Loading serialized model from " + filename); DVParser dvparser; try { dvparser = IOUtils.readObjectFromURLOrClasspathOrFileSystem(filename); dvparser.op.setOptions(args); } catch (IOException e) { throw new RuntimeIOException(e); } catch (ClassNotFoundException e) { throw new RuntimeIOException(e); } log.info("... done"); return dvparser; }
Object model = IOUtils.readObjectFromURLOrClasspathOrFileSystem(MODEL_FILE); KBPStatisticalExtractor classifier; if (model instanceof Classifier) {
public static SentimentModel loadSerialized(String path) { try { return IOUtils.readObjectFromURLOrClasspathOrFileSystem(path); } catch (IOException | ClassNotFoundException e) { throw new RuntimeIOException(e); } }
public static SentimentModel loadSerialized(String path) { try { return IOUtils.readObjectFromURLOrClasspathOrFileSystem(path); } catch (IOException e) { throw new RuntimeIOException(e); } catch (ClassNotFoundException e) { throw new RuntimeIOException(e); } }
public static <T> T readObjectAnnouncingTimingFromURLOrClasspathOrFileSystem(Redwood.RedwoodChannels log, String msg, String path) { T obj; try { Timing timing = new Timing(); obj = IOUtils.readObjectFromURLOrClasspathOrFileSystem(path); log.info(msg + ' ' + path + " ... done [" + timing.toSecondsString() + " sec]."); } catch (IOException | ClassNotFoundException e) { throw new RuntimeIOException(e); } return obj; }