📄 cdata.java
字号:
int curr_index = ((Integer)indices_a.get(i)).intValue(); SearchLevel curr_level = getCurrLevel(); symbols.add(curr_level.symbols_d.get(curr_index)); } return symbols; } /** * conver a string vector to a index vector * * @param symbols_a a vector of indices * @return a vector of string */ public static Vector symbolsToIndices(Vector symbols_a) { Vector indices = new Vector(); for (int i = 0; i < symbols_a.size(); i++) { Object curr_symbol = symbols_a.get(i); SearchLevel curr_level = getCurrLevel(); int index = curr_level.symbols_d.indexOf(curr_symbol); indices.add(new Integer(index)); } return indices; } /** * store the data into a file * * @param none * @return void */ public static void loadOptions() { Properties options = new Properties(); // read data from a file // try{ options.clear(); options.load(new FileInputStream(OPTION_FILE)); } catch (Exception e){ e.printStackTrace(System.out); } ISIP_NETWORK_CONVERTER = options.getProperty(ISIP_NETWORK_CONVERTER_TAG, DEF_ISIP_NETWORK_CONVERTER); System.out.println("using: " + ISIP_NETWORK_CONVERTER ); // read data from a file // /* try{ options.store(new FileOutputStream(OPTION_FILE), "isip_network_builder options"); } catch (Exception e){ e.printStackTrace(System.out); } */ } /** * check errors in the model * * @return a flag indicate the status */ public static boolean check() { // set the inital error message // error_message_d = "Found errors in the model, cannot save in other format: \n"; // store all levels // for (int i= 0; i < search_levels_d.size(); i++) { SearchLevel curr_level = (SearchLevel)search_levels_d.get(i); String message = "checking level: " + String.valueOf(i); if ( !curr_level.check("", message)){ showMessageDlg("Error", error_message_d); /* JDialog message_pane = new JDialog(); message_pane.getContentPane().add(new JScrollPane (new JTextArea(error_message_d))); message_pane.show(); */ //JOptionPane.showMessageDialog(main_frame_d, error_message_d); //System.out.print(error_message_d); return false; } } return true; } /** * Hiearchy | Symbols action performed * * @return void */ public static void showMessageDlg(String title_a, String message_a) { UIMessageDialog dlg = new UIMessageDialog( CData.main_frame_d, title_a, message_a, true); Dimension dlgSize = dlg.getPreferredSize(); Dimension frmSize = CData.main_frame_d.getSize(); Point loc = CData.main_frame_d.getLocation(); dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y); dlg.show(); } /** * store the data into a file * * @param none * @return void */ public static void store(boolean save_as) { // set the file name // if ( (curr_file_d == null) || save_as ){ //String file_name = chooseFile("Save As"); String file_name = chooseLMFile(curr_file_d); if ( file_name == null){ return ; } curr_file_d = file_name; } System.out.println("storing ... " + curr_file_d); // set current description // CData.lm_file_description_d = CData.open_lm_file_description_d; // test file name // File file = new File(curr_file_d); String ext = UIFileFilter.getExtension(file); //if ( ext.equals(FILE_FILTER_EXTENSION_DIGRAPH) ) { if ( ext.equals(FILE_FILTER_EXTENSION_DIGRAPH) && lm_file_description_d.equals(FILE_FILTER_DESCRIPTION_DIGRAPH)) { // store as a temp file first // String temp_file = curr_file_d; try { curr_file_d = temp_file_d = File.createTempFile("temp", ".text").getAbsolutePath(); } catch ( Exception e ) { e.printStackTrace(); } /* if ( !check() ){ curr_file_d = temp_file; return; } */ store(false); // convert to new models // convertModels(curr_file_d,"NATIVE", temp_file, " ", "DIGRAPH", "TEXT"); curr_file_d = temp_file; return; } if ( ext.equals(FILE_FILTER_EXTENSION_JSGF) && lm_file_description_d.equals(FILE_FILTER_DESCRIPTION_JSGF)) { // store as a temp file first // String temp_file = curr_file_d; try { curr_file_d = temp_file_d = File.createTempFile("temp", ".text").getAbsolutePath(); } catch ( Exception e ) { e.printStackTrace(); } /* if ( !check() ){ curr_file_d = temp_file; return; } */ store(false); // convert to new models // convertModels(curr_file_d,"NATIVE", temp_file, " ", "JSGF", "TEXT"); curr_file_d = temp_file; return; } if ( ext.equals(FILE_FILTER_EXTENSION_BINARY) && lm_file_description_d.equals(FILE_FILTER_DESCRIPTION_BINARY)) { // store as a temp file first // String temp_file = curr_file_d; try { curr_file_d = temp_file_d = File.createTempFile("temp", ".text").getAbsolutePath(); } catch ( Exception e ) { e.printStackTrace(); } /* if ( !check() ){ curr_file_d = temp_file; return; } */ store(false); // convert to new models // convertModels(curr_file_d,"NATIVE", temp_file, " ", "JSGF", "binary"); curr_file_d = temp_file; return; } // tags // String level_size_tag = CData.IO_CDATA_LEVEL_SIZE; // values // String level_size = String.valueOf(search_levels_d.size()); // store all data members // io_d.setProperty(level_size_tag, level_size); // store all levels // for (int i= 0; i < search_levels_d.size(); i++) { SearchLevel curr_level = (SearchLevel)search_levels_d.get(i); String prefix = CData.IO_SEARCHLEVEL_PREFIX + String.valueOf(i); curr_level.store(prefix); } try{ // store into a file // io_d.store(new FileOutputStream(curr_file_d), "native format models"); } catch (Exception e){ e.printStackTrace(System.out); } } /** * store the data into a file * * @param none * @return void */ public static void storeAll() { // test file name // File file = new File(curr_file_d); String ext = UIFileFilter.getExtension(file); if ( ext.equals(FILE_FILTER_EXTENSION_DIGRAPH) && lm_file_description_d.equals(FILE_FILTER_DESCRIPTION_DIGRAPH)) { // store as a temp file first // String temp_file = curr_file_d; try { curr_file_d = temp_file_d = File.createTempFile("temp", ".text").getAbsolutePath(); } catch ( Exception e ) { e.printStackTrace(); } store(false); // convert to new models // convertModels(curr_file_d,"NATIVE", temp_file, curr_sm_file_d, "DIGRAPH", "TEXT"); curr_file_d = temp_file; return; } if ( ext.equals(FILE_FILTER_EXTENSION_JSGF) && lm_file_description_d.equals(FILE_FILTER_DESCRIPTION_JSGF)) { // store as a temp file first // String temp_file = curr_file_d; try { curr_file_d = temp_file_d = File.createTempFile("temp", ".text").getAbsolutePath(); } catch ( Exception e ) { e.printStackTrace(); } store(false); // convert to new models // convertModels(curr_file_d,"NATIVE", temp_file, curr_sm_file_d, "JSGF", "TEXT"); curr_file_d = temp_file; return; } if ( ext.equals(FILE_FILTER_EXTENSION_BINARY) && lm_file_description_d.equals(FILE_FILTER_DESCRIPTION_BINARY)) { // store as a temp file first // String temp_file = curr_file_d; try { curr_file_d = temp_file_d = File.createTempFile("temp", ".text").getAbsolutePath(); } catch ( Exception e ) { e.printStackTrace(); } store(false); // convert to new models // convertModels(curr_file_d,"NATIVE", temp_file, curr_sm_file_d, "JSGF", "binary"); curr_file_d = temp_file; return; } // save the statistical model // store(false); // store as a temp file first // String temp_file = ""; try { temp_file = temp_file_d = File.createTempFile("temp", ".text").getAbsolutePath(); } catch ( Exception e ) { e.printStackTrace(); } // convert to new models // convertModels(curr_file_d,"NATIVE", temp_file, curr_sm_file_d, "JSGF", "TEXT"); } /** * load the data from a file * * @param none * @return void */ public static void newModel(boolean new_file_a) { // do we use new file // if ( new_file_a ){ String file_name = chooseFile("New"); if ( file_name == null){ return ; } curr_file_d = file_name; } else{ curr_file_d = null; } // initialize // init(); // update UI // main_frame_d.updateAll(); } /** * load the data from a file * * @param none * @return void */ public static void load(boolean load_curr_file) { if ( ! load_curr_file ){ //String file_name = chooseFile("Open"); String file_name = chooseLMFile(curr_file_d); if ( file_name == null){ return ; } File file = new File(file_name); if ( ! file.exists() ){ System.out.println(file_name + "does not exist"); return ; } curr_file_d = file_name; } System.out.println("load file:" + curr_file_d); // find the extension of the file and call different commands // File file = new File(curr_file_d); String ext = UIFileFilter.getExtension(file); if ( ext.equals(FILE_FILTER_EXTENSION_DIGRAPH) ) { // store as a temp file first // String temp_file = curr_file_d; try { curr_file_d = temp_file_d = File.createTempFile("temp", ".text").getAbsolutePath(); } catch ( Exception e ) { e.printStackTrace(); } // convert to new models // convertModels(temp_file, "DIGRAPH", curr_file_d, " ", "NATIVE", "text"); load(true); curr_file_d = temp_file; return; } if ( ext.equals(FILE_FILTER_EXTENSION_JSGF) ) { // store as a temp file first // String temp_file = curr_file_d; try { curr_file_d = temp_file_d = File.createTempFile("temp", ".text").getAbsolutePath(); } catch ( Exception e ) { e.printStackTrace(); } // convert to new models // convertModels(temp_file, "JSGF", curr_file_d, " ", "NATIVE", "text"); load(true); curr_file_d = temp_file; return; } if ( ext.equals(FILE_FILTER_EXTENSION_BINARY) ) { // store as a temp file first // String temp_file = curr_file_d; try { curr_file_d = temp_file_d = File.createTempFile("temp", ".text").getAbsolutePath(); } catch ( Exception e ) { e.printStackTrace(); } // convert to new models // convertModels(temp_file, "DIGRAPH", curr_file_d, " ", "NATIVE", "text"); load(true); curr_file_d = temp_file; return; } // initialize // init(); // read data from a file // try{ io_d.clear(); System.out.println("start loading ... "); io_d.load(new FileInputStream(curr_file_d)); System.out.println("end of loading ... "); } catch (Exception e){ e.printStackTrace(System.out);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -