public virtual void save(string name) { try { PrintWriter printWriter = new PrintWriter(new FileWriter(name)); printWriter.println(new StringBuilder().append(this.ngauss).append(" ").append(this.ncoefs).toString()); for (int i = 0; i < this.ngauss; i++) { printWriter.println(new StringBuilder().append("gauss ").append(i).append(' ').append(this.getWeight(i)).toString()); for (int j = 0; j < this.ncoefs; j++) { printWriter.print(new StringBuilder().append(this.means[i][j]).append(" ").toString()); } printWriter.println(); for (int j = 0; j < this.ncoefs; j++) { printWriter.print(new StringBuilder().append(this.getVar(i, j)).append(" ").toString()); } printWriter.println(); } printWriter.println(this.nT); printWriter.close(); } catch (IOException ex) { Throwable.instancehelper_printStackTrace(ex); } }
public virtual void store(string filePath, int index) { PrintWriter printWriter = new PrintWriter(filePath, "UTF-8"); printWriter.println("1"); printWriter.println(this.loader.getNumStreams()); for (int i = 0; i < this.loader.getNumStreams(); i++) { printWriter.println(this.loader.getVectorLength()[i]); for (int j = 0; j < this.loader.getVectorLength()[i]; j++) { for (int k = 0; k < this.loader.getVectorLength()[i]; k++) { printWriter.print(this.As[index][i][j][k]); printWriter.print(" "); } printWriter.println(); } for (int j = 0; j < this.loader.getVectorLength()[i]; j++) { printWriter.print(this.Bs[index][i][j]); printWriter.print(" "); } printWriter.println(); for (int j = 0; j < this.loader.getVectorLength()[i]; j++) { printWriter.print("1.0 "); } printWriter.println(); } printWriter.close(); }
private void AppendNode(PrintWriter @out, Node node) { @out.print("create ("); @out.print(Identifier(node)); string labels = LabelString(node); if (labels.Length > 0) { @out.print(labels); } FormatProperties(@out, node); @out.println(")"); }
private void FormatProperties(PrintWriter @out, PropertyContainer pc) { if (!pc.PropertyKeys.GetEnumerator().hasNext()) { return; } @out.print(" "); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final String propertyString = formatProperties(pc); string propertyString = FormatProperties(pc); @out.print(propertyString); }
public virtual void saveHTK(string nomFich, string nomHMM, string parmKind) { try { PrintWriter printWriter = new PrintWriter(new FileWriter(nomFich)); printWriter.println("~o"); printWriter.println("<HMMSETID> tree"); printWriter.println(new StringBuilder().append("<STREAMINFO> 1 ").append(this.getNcoefs()).toString()); printWriter.println(new StringBuilder().append("<VECSIZE> ").append(this.getNcoefs()).append("<NULLD>").append(parmKind).append("<DIAGC>").toString()); printWriter.println("~r \"rtree_1\""); printWriter.println("<REGTREE> 1"); printWriter.println(new StringBuilder().append("<TNODE> 1 ").append(this.getNgauss()).toString()); printWriter.println(new StringBuilder().append("~h \"").append(nomHMM).append('"').toString()); printWriter.println("<BEGINHMM>"); printWriter.println("<NUMSTATES> 3"); printWriter.println("<STATE> 2"); printWriter.println(new StringBuilder().append("<NUMMIXES> ").append(this.getNgauss()).toString()); for (int i = 1; i <= this.getNgauss(); i++) { printWriter.println(new StringBuilder().append("<MIXTURE> ").append(i).append(' ').append(this.getWeight(i - 1)).toString()); printWriter.println("<RCLASS> 1"); printWriter.println(new StringBuilder().append("<MEAN> ").append(this.getNcoefs()).toString()); for (int j = 0; j < this.getNcoefs(); j++) { printWriter.print(new StringBuilder().append(this.getMean(i - 1, j)).append(" ").toString()); } printWriter.println(); printWriter.println(new StringBuilder().append("<VARIANCE> ").append(this.getNcoefs()).toString()); for (int j = 0; j < this.getNcoefs(); j++) { printWriter.print(new StringBuilder().append(this.getVar(i - 1, j)).append(" ").toString()); } printWriter.println(); } printWriter.println("<TRANSP> 3"); printWriter.println("0 1 0"); printWriter.println("0 0.7 0.3"); printWriter.println("0 0 0"); printWriter.println("<ENDHMM>"); printWriter.close(); } catch (IOException ex) { Throwable.instancehelper_printStackTrace(ex); } }
private void printDepth(PrintWriter @out, int depth) { for (int i = 0; i < 2 * depth; i++) { @out.print(" "); } }
private void AppendIndexes(PrintWriter @out) { foreach (string line in ExportIndexes()) { @out.print(line); @out.println(";"); } }
private void AppendConstraints(PrintWriter @out) { foreach (string line in ExportConstraints()) { @out.print(line); @out.println(";"); } }
internal virtual void PrintProgress(int progress) { Out.print('.'); if (progress % 20 == 0) { Out.printf(" %3d%%%n", progress / 2); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private void processMultiPart(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws java.io.IOException private void processMultiPart(HttpServletRequest req, HttpServletResponse resp) { PrintWriter @out = resp.Writer; resp.ContentType = "text/plain"; MultipartParser mp = new MultipartParser(req, 2048); Part part = null; while ((part = mp.readNextPart()) != null) { string name = part.Name.Trim(); if (part.Param) { // it's a parameter part ParamPart paramPart = (ParamPart)part; string value = paramPart.StringValue.Trim(); LOG.info("param; name=" + name + ", value=" + value); @out.print("param; name=" + name + ", value=" + value); } else if (part.File) { // it's a file part FilePart filePart = (FilePart)part; string fileName = filePart.FileName; if (!string.ReferenceEquals(fileName, null)) { // the part actually contained a file // StringWriter sw = new StringWriter(); // long size = filePart.writeTo(new File(System // .getProperty("java.io.tmpdir"))); System.IO.MemoryStream baos = new System.IO.MemoryStream(); long size = filePart.writeTo(baos); LOG.info("file; name=" + name + "; filename=" + fileName + ", filePath=" + filePart.FilePath + ", content type=" + filePart.ContentType + ", size=" + size); @out.print(string.Format("{0}: {1}", name, (StringHelperClass.NewString(baos.toByteArray())).Trim())); } else { // the field did not contain a file LOG.info("file; name=" + name + "; EMPTY"); } @out.flush(); } } resp.Status = HttpServletResponse.SC_OK; }
private static void dump(PrintWriter writer, Node node, Stack <Node> predecessors) { if (predecessors.Count > 0) { Node parent = null; foreach (Node predecessor in predecessors) { if (isLastSibling(predecessor, parent)) { writer.print(" "); } else { writer.print("| "); } parent = predecessor; } writer.println("|"); } Node parent = null; foreach (Node predecessor in predecessors) { if (isLastSibling(predecessor, parent)) { writer.print(" "); } else { writer.print("| "); } parent = predecessor; } writer.print("+- "); writer.println(node.ToString()); predecessors.Push(node); for (int i = 0; i < node.Cardinality; i++) { dump(writer, node.getChild(i), predecessors); } predecessors.Pop(); }
private void saveDensityFileAscii(Pool pool, string text, bool append) { this.logger.info("Saving density file to: "); this.logger.info(text); OutputStream outputStream = StreamFactory.getOutputStream(this.location, text, append); if (outputStream == null) { string text2 = new StringBuilder().append("Error trying to write file ").append(this.location).append(text).toString(); throw new IOException(text2); } PrintWriter printWriter = new PrintWriter(outputStream, true); printWriter.print("param "); int feature = pool.getFeature(Pool.Feature.__NUM_SENONES, -1); printWriter.print(new StringBuilder().append(feature).append(" ").toString()); int feature2 = pool.getFeature(Pool.Feature.__NUM_STREAMS, -1); printWriter.print(new StringBuilder().append(feature2).append(" ").toString()); int feature3 = pool.getFeature(Pool.Feature.__NUM_GAUSSIANS_PER_STATE, -1); printWriter.println(feature3); for (int i = 0; i < feature; i++) { printWriter.println(new StringBuilder().append("mgau ").append(i).toString()); printWriter.println("feat 0"); for (int j = 0; j < feature3; j++) { printWriter.print(new StringBuilder().append("density \t").append(j).toString()); int id = i * feature3 + j; float[] array = (float[])pool.get(id); for (int k = 0; k < this.vectorLength; k++) { printWriter.print(new StringBuilder().append(" ").append(array[k]).toString()); } printWriter.println(); } } outputStream.close(); }
public virtual void saveHTKState(PrintWriter fout) { fout.println(new StringBuilder().append("<NUMMIXES> ").append(this.getNgauss()).toString()); for (int i = 1; i <= this.getNgauss(); i++) { fout.println(new StringBuilder().append("<MIXTURE> ").append(i).append(' ').append(this.getWeight(i - 1)).toString()); fout.println("<RCLASS> 1"); fout.println(new StringBuilder().append("<MEAN> ").append(this.getNcoefs()).toString()); for (int j = 0; j < this.getNcoefs(); j++) { fout.print(new StringBuilder().append(this.getMean(i - 1, j)).append(" ").toString()); } fout.println(); fout.println(new StringBuilder().append("<VARIANCE> ").append(this.getNcoefs()).toString()); for (int j = 0; j < this.getNcoefs(); j++) { fout.print(new StringBuilder().append(this.getVar(i - 1, j)).append(" ").toString()); } fout.println(); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private void processFileUpload(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws java.io.IOException private void processFileUpload(HttpServletRequest req, HttpServletResponse resp) { System.IO.Stream @is = req.InputStream; PrintWriter @out = resp.Writer; resp.ContentType = "text/plain"; string fileContents = getContent(@is); @out.print(fileContents.Trim()); @out.flush(); resp.Status = HttpServletResponse.SC_OK; }
private void printPath(PrintWriter @out, string path, int depth) { if (path == null || !path.exists()) { return; } printDepth(@out, depth); if (path.isDirectory()) { @out.print(path.getFullPath()); @out.print("/"); } else if (path.isFile()) { @out.print("<a href='?file=" + path.getFullPath() + "'>"); @out.print(path.getTail()); @out.print("</a>"); } else { @out.print(path.getTail()); } @out.print(" "); @out.print(" len=" + path.getLength()); @out.println(); if (path.isDirectory()) { string [] names = path.list(); if (names == null) { return; } Arrays.sort(names); for (String name : names) { string subPath = path.lookup(name); printPath(@out, subPath, depth + 1); } } }
/// <summary> /// Exports a list of strings to a file. </summary> /// <param name="filename"> the name of the file to write. </param> /// <param name="strings"> a non-null Vector of Strings, each element of which will be /// another line in the file. </param> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: protected void export(String filename, java.util.List<String> strings) throws Exception protected internal virtual void export(string filename, IList <string> strings) { string routine = "StateMod_Data_JFrame.export"; // First see if we can write the file given the security // settings... if (!SecurityCheck.canWriteFile(filename)) { Message.printWarning(1, routine, "Cannot save \"" + filename + "\"."); throw new Exception("Security check failed - unable to write \"" + filename + "\""); } JGUIUtil.setWaitCursor(this, true); // Create a new FileOutputStream wrapped with a DataOutputStream // for writing to a file. PrintWriter oStream = null; try { oStream = new PrintWriter(new StreamWriter(filename)); } catch (Exception) { JGUIUtil.setWaitCursor(this, false); throw new Exception("Error opening file \"" + filename + "\"."); } try { // Write each element of the strings Vector to a file. // For some reason, when just using println in an // applet, the cr-nl pair is not output like it should // be on Windows95. Java Bug??? string linesep = System.getProperty("line.separator"); int size = strings.Count; for (int i = 0; i < size; i++) { oStream.print(strings[i].ToString() + linesep); } oStream.flush(); oStream.close(); } catch (Exception) { JGUIUtil.setWaitCursor(this, false); throw new Exception("Error writing to file \"" + filename + "\"."); } JGUIUtil.setWaitCursor(this, false); }
public virtual void saveHTKtailer(int nstates, PrintWriter fout) { fout.println(new StringBuilder().append("<TRANSP> ").append(nstates).toString()); for (int i = 0; i < nstates; i++) { fout.print("0 "); } fout.println(); for (int i = 1; i < nstates - 1; i++) { for (int j = 0; j < i; j++) { fout.print("0 "); } fout.print("0.5 0.5"); for (int j = i + 3; j < nstates; j++) { fout.print("0 "); } } fout.println(); fout.println("0 0 0"); fout.println("<ENDHMM>"); }
private void AppendRelationship(PrintWriter @out, Relationship rel) { @out.print("create ("); @out.print(Identifier(rel.StartNode)); @out.print(")-[:"); @out.print(Quote(rel.Type.name())); FormatProperties(@out, rel); @out.print("]->("); @out.print(Identifier(rel.EndNode)); @out.println(")"); }
private void saveMixtureWeightsAscii(GaussianWeights gaussianWeights, string text, bool append) { this.logger.info("Saving mixture weights to: "); this.logger.info(text); OutputStream outputStream = StreamFactory.getOutputStream(this.location, text, append); if (outputStream == null) { string text2 = new StringBuilder().append("Error trying to write file ").append(this.location).append(text).toString(); throw new IOException(text2); } PrintWriter printWriter = new PrintWriter(outputStream, true); printWriter.print("mixw "); int statesNum = gaussianWeights.getStatesNum(); printWriter.print(new StringBuilder().append(statesNum).append(" ").toString()); int streamsNum = gaussianWeights.getStreamsNum(); printWriter.print(new StringBuilder().append(streamsNum).append(" ").toString()); int gauPerState = gaussianWeights.getGauPerState(); printWriter.println(gauPerState); for (int i = 0; i < statesNum; i++) { for (int j = 0; j < streamsNum; j++) { printWriter.print(new StringBuilder().append("mixw [").append(i).append(" ").append(j).append("] ").toString()); float[] array = new float[gauPerState]; float[] array2 = new float[gauPerState]; for (int k = 0; k < gauPerState; k++) { array2[k] = gaussianWeights.get(i, j, k); } this.logMath.logToLinear(array2, array); float num = 0f; for (int l = 0; l < gauPerState; l++) { num += array[l]; } printWriter.println(num); printWriter.print("\n\t"); for (int l = 0; l < gauPerState; l++) { printWriter.print(new StringBuilder().append(" ").append(array[l]).toString()); } printWriter.println(); } } outputStream.close(); }
/** * Método que genera el gráfico del árbol binario de búsqueda con graphviz, * considerando como la raíz de dicho árbol el actual Nodo. * @param path Ruta de la imagen que se generará. */ public void graficar(String path) { FileWriter fichero = null; PrintWriter escritor; try { fichero = new FileWriter("aux_grafico.dot"); escritor = new PrintWriter(fichero); escritor.print(getCodigoGraphviz()); } catch (Exception e) { System.err.println("Error al escribir el archivo aux_grafico.dot"); } finally { try { if (null != fichero) { fichero.close(); } } catch (Exception e2) { System.err.println("Error al cerrar el archivo aux_grafico.dot"); } } try { Runtime rt = Runtime.getRuntime(); rt.exec("dot -Tjpg -o " + path + " aux_grafico.dot"); //Esperamos medio segundo para dar tiempo a que la imagen se genere. //Para que no sucedan errores en caso de que se decidan graficar varios //árboles sucesivamente. Thread.sleep(500); } catch (Exception ex) { System.err.println("Error al generar la imagen para el archivo aux_grafico.dot"); } }
public static void save(ConfigurationManager cm, File cmLocation) { if (!String.instancehelper_endsWith(cmLocation.getName(), ".sxl")) { java.lang.System.err.println("WARNING: Serialized s4-configuration should have the suffix '.sxl'"); } if (!ConfigurationManagerUtils.assertionsDisabled && cm == null) { throw new AssertionError(); } try { PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(new FileOutputStream(cmLocation), Charset.forName("UTF-8"))); string text = ConfigurationManagerUtils.toXML(cm); printWriter.print(text); printWriter.flush(); printWriter.close(); } catch (FileNotFoundException ex) { Throwable.instancehelper_printStackTrace(ex); } }
public static void dump(PrintWriter pw, int padding, string @string) { pw.print(Utilities.pad(padding)); pw.println(@string); }
public static void generate(PrintWriter @out, ArrayValue array) { int size = array.getSize(); int bins = size / MAX_SIZE; if (size % MAX_SIZE > 0) { bins++; } int bin = 0; Value [] keys = array.keysToArray(); Value [] values = array.valuesToArray(); @out.print("new ArrayValueComponent[] {"); while (bin < bins) { int binSize = MAX_SIZE; if (bin != 0) { @out.print(", "); } if (bin + 1 == bins) { binSize = size - bin * MAX_SIZE; } @out.println("new ArrayValueComponent() {"); @out.println(" public void init() {"); @out.print(" _keys = new Value[] {"); for (int i = 0; i < binSize; i++) { if (i != 0) { @out.print(", "); } keys[i + bin * MAX_SIZE].generate(out); } @out.println("};"); @out.print(" _values = new Value[] {"); for (int i = 0; i < binSize; i++) { if (i != 0) { @out.print(", "); } values[i + bin * MAX_SIZE].generate(out); } @out.println("};"); @out.println(" }"); @out.println(" }"); bin++; } @out.print("}"); }
/** * Generates code to recreate the expression. * * @param @out the writer to the Java source code. */ public static void generateImpl(PrintWriter @out, StringBuilderValue value) { // max JVM constant string length int maxSublen = 0xFFFE; int len = value.length(); if (len == 1) { @out.print("(ConstStringValue.create((char) '"); printJavaChar(@out, value[0]); @out.print("'))"); } else if (len < maxSublen) { @out.print("(new CompiledConstStringValue (\""); printJavaString(@out, value); @out.print("\", "); value.toLongValue().generate(out); @out.print(", "); value.toDoubleValue().generate(out); @out.print(", "); @out.print(value.getValueType()); @out.print(", "); Value key = value.toKey(); if (key instanceof LongValue) { key.generate(out); @out.print(", "); } @out.print(value.hashCode()); @out.print("))"); } else { @out.print("(new ConstStringValue(new StringBuilderValue(\""); // php/313u for (int i = 0; i < len; i += maxSublen) { if (i != 0) { @out.print("\").append(\""); } printJavaString(@out, value.substring(i, Math.min(i + maxSublen, len))); } @out.print("\")))"); } }
internal virtual void convertLexicon(string text) { IOException ex2; try { BufferedReader bufferedReader = new BufferedReader(new FileReader(text)); PrintWriter printWriter = new PrintWriter(new FileWriter(new StringBuilder().append(text).append(".conv").toString())); for (;;) { string text2 = bufferedReader.readLine(); if (text2 == null) { break; } StringTokenizer stringTokenizer = new StringTokenizer(text2); if (stringTokenizer != null) { if (stringTokenizer.hasMoreTokens()) { string text3 = stringTokenizer.nextToken(); string text4 = (string)this.wordConv.get(text3); if (text4 != null) { text3 = text4; } printWriter.print(new StringBuilder().append(text3).append(' ').toString()); while (stringTokenizer.hasMoreTokens()) { string text5 = stringTokenizer.nextToken(); if (String.instancehelper_charAt(text5, 0) == '[') { while (!String.instancehelper_endsWith(text5, "]")) { text5 = stringTokenizer.nextToken(); } text5 = stringTokenizer.nextToken(); } this.split3ph(text5); string text6 = this.conv3ph(); printWriter.print(new StringBuilder().append(text6).append(' ').toString()); } printWriter.println(); } } } printWriter.close(); bufferedReader.close(); } catch (IOException ex) { ex2 = ex; goto IL_131; } return; IL_131: IOException ex3 = ex2; Throwable.instancehelper_printStackTrace(ex3); }
private static string DetailedMessage(string errorMessage, MethodNode method, Frame[] frames, AbstractInsnNode errorLocation) { StringWriter message = new StringWriter(); using (PrintWriter @out = new PrintWriter(message)) { IList <int> localLengths = new List <int>(); IList <int> stackLengths = new List <int>(); foreach (Frame frame in frames) { if (frame != null) { for (int i = 0; i < frame.Locals; i++) { Insert(i, frame.getLocal(i), localLengths); } for (int i = 0; i < frame.StackSize; i++) { Insert(i, frame.getStack(i), stackLengths); } } } Textifier formatted = new Textifier(); TraceMethodVisitor mv = new TraceMethodVisitor(formatted); @out.println(errorMessage); @out.append("\t\tin ").append(method.name).append(method.desc).println(); for (int i = 0; i < method.instructions.size(); i++) { AbstractInsnNode insn = method.instructions.get(i); insn.accept(mv); Frame frame = frames[i]; @out.append("\t\t"); @out.append(insn == errorLocation ? ">>> " : " "); @out.format("%05d [", i); if (frame == null) { //JAVA TO C# CONVERTER WARNING: Unlike Java's ListIterator, enumerators in .NET do not allow altering the collection: Padding(@out, localLengths.GetEnumerator(), '?'); @out.append(" : "); //JAVA TO C# CONVERTER WARNING: Unlike Java's ListIterator, enumerators in .NET do not allow altering the collection: Padding(@out, stackLengths.GetEnumerator(), '?'); } else { Emit(@out, localLengths, frame.getLocal, frame.Locals); Padding(@out, localLengths.listIterator(frame.Locals), '-'); @out.append(" : "); Emit(@out, stackLengths, frame.getStack, frame.StackSize); Padding(@out, stackLengths.listIterator(frame.StackSize), ' '); } @out.print("] : "); @out.print(formatted.text.get(formatted.text.size() - 1)); } for (int j = 0; j < method.tryCatchBlocks.size(); j++) { method.tryCatchBlocks.get(j).accept(mv); @out.print(" " + formatted.text.get(formatted.text.size() - 1)); } } return(message.ToString()); }
internal virtual void convertWordGrammar(string text) { try { BufferedReader bufferedReader = new BufferedReader(new FileReader(text)); PrintWriter printWriter = new PrintWriter(new FileWriter(new StringBuilder().append(text).append(".conv").toString())); for (;;) { string text2 = bufferedReader.readLine(); if (text2 == null) { break; } printWriter.println(text2); if (String.instancehelper_indexOf(text2, "\\data\\") == 0) { goto Block_3; } } printWriter.close(); bufferedReader.close(); return; Block_3: for (;;) { string text2 = bufferedReader.readLine(); if (text2 == null) { break; } printWriter.println(text2); if (String.instancehelper_indexOf(text2, "\\1-grams:") == 0) { goto Block_5; } } printWriter.close(); bufferedReader.close(); return; Block_5: int num = 0; while (num == 0) { string text2 = bufferedReader.readLine(); if (text2 == null) { printWriter.close(); bufferedReader.close(); return; } if (String.instancehelper_indexOf(text2, "\\2-grams:") == 0) { printWriter.println(text2); break; } if (String.instancehelper_indexOf(text2, "\\end\\") == 0) { num = 1; printWriter.println(text2); break; } StringTokenizer stringTokenizer = new StringTokenizer(text2); if (stringTokenizer.hasMoreTokens()) { printWriter.print(new StringBuilder().append(stringTokenizer.nextToken()).append(' ').toString()); if (stringTokenizer.hasMoreTokens()) { string text3 = stringTokenizer.nextToken(); string text4 = (string)this.wordConv.get(text3); if (text4 == null) { java.lang.System.err.println(new StringBuilder().append("WARNING word ").append(text3).append(" not in lexicon !").toString()); this.addInConv(text3, this.wordConv); text4 = (string)this.wordConv.get(text3); } printWriter.print(new StringBuilder().append(text4).append(' ').toString()); while (stringTokenizer.hasMoreTokens()) { printWriter.print(new StringBuilder().append(stringTokenizer.nextToken()).append(' ').toString()); } } printWriter.println(); } } while (num == 0) { string text2 = bufferedReader.readLine(); if (text2 == null) { printWriter.close(); bufferedReader.close(); return; } if (String.instancehelper_indexOf(text2, "\\3-grams:") == 0) { printWriter.println(text2); break; } if (String.instancehelper_indexOf(text2, "\\end\\") == 0) { num = 1; printWriter.println(text2); break; } StringTokenizer stringTokenizer = new StringTokenizer(text2); if (stringTokenizer.hasMoreTokens()) { printWriter.print(new StringBuilder().append(stringTokenizer.nextToken()).append(' ').toString()); if (stringTokenizer.hasMoreTokens()) { string text3 = stringTokenizer.nextToken(); string text4 = (string)this.wordConv.get(text3); if (text4 == null) { text4 = text3; } printWriter.print(new StringBuilder().append(text4).append(' ').toString()); if (stringTokenizer.hasMoreTokens()) { text3 = stringTokenizer.nextToken(); text4 = (string)this.wordConv.get(text3); if (text4 == null) { text4 = text3; } printWriter.print(new StringBuilder().append(text4).append(' ').toString()); while (stringTokenizer.hasMoreTokens()) { printWriter.print(new StringBuilder().append(stringTokenizer.nextToken()).append(' ').toString()); } } } printWriter.println(); } } while (num == 0) { string text2 = bufferedReader.readLine(); if (text2 == null) { printWriter.close(); bufferedReader.close(); return; } if (String.instancehelper_indexOf(text2, "\\end\\") == 0) { printWriter.println(text2); break; } StringTokenizer stringTokenizer = new StringTokenizer(text2); if (stringTokenizer.hasMoreTokens()) { printWriter.print(new StringBuilder().append(stringTokenizer.nextToken()).append(' ').toString()); if (stringTokenizer.hasMoreTokens()) { string text3 = stringTokenizer.nextToken(); string text4 = (string)this.wordConv.get(text3); if (text4 == null) { text4 = text3; } printWriter.print(new StringBuilder().append(text4).append(' ').toString()); if (stringTokenizer.hasMoreTokens()) { text3 = stringTokenizer.nextToken(); text4 = (string)this.wordConv.get(text3); if (text4 == null) { text4 = text3; } printWriter.print(new StringBuilder().append(text4).append(' ').toString()); if (stringTokenizer.hasMoreTokens()) { text3 = stringTokenizer.nextToken(); text4 = (string)this.wordConv.get(text3); if (text4 == null) { text4 = text3; } printWriter.print(new StringBuilder().append(text4).append(' ').toString()); while (stringTokenizer.hasMoreTokens()) { printWriter.print(new StringBuilder().append(stringTokenizer.nextToken()).append(' ').toString()); } } } } printWriter.println(); } } printWriter.close(); bufferedReader.close(); return; } catch (IOException ex) { Throwable.instancehelper_printStackTrace(ex); } }
public virtual void saveAsTxt(string filePath, string delimiter) { if (filePath == null) { throw new System.ArgumentException("File path is null!"); } // default delimiter is space if other is not specified if ((delimiter == null) || delimiter.Equals("")) { delimiter = " "; } try { using (PrintWriter @out = new PrintWriter(new FileWriter(new File(filePath)))) { int columnCount = inputSize + outputSize; if ((columnNames != null) && (columnNames.Length > 0)) { for (int i = 0; i < columnNames.Length; i++) { @out.print(columnNames[i]); if (i < columnCount - 1) { @out.print(delimiter); } } @out.println(); } foreach (DataSetRow row in this.rows) { double[] input = row.Input; for (int i = 0; i < input.Length; i++) { @out.print(input[i]); if (i < columnCount - 1) { @out.print(delimiter); } } if (row.Supervised) { double[] output = row.DesiredOutput; for (int j = 0; j < output.Length; j++) { @out.print(output[j]); if (inputSize + j < columnCount - 1) { @out.print(delimiter); } } } @out.println(); } @out.flush(); } } catch (IOException ex) { throw new NeurophException("Error saving data set file!", ex); } }
protected internal virtual void saveTransitionMatricesAscii(Pool pool, string path, bool append) { OutputStream outputStream = StreamFactory.getOutputStream(this.location, path, append); if (outputStream == null) { string text = new StringBuilder().append("Error trying to write file ").append(this.location).append(path).toString(); throw new IOException(text); } PrintWriter printWriter = new PrintWriter(outputStream, true); this.logger.info("Saving transition matrices to: "); this.logger.info(path); int num = pool.size(); if (!Sphinx3Saver.assertionsDisabled && num <= 0) { throw new AssertionError(); } float[][] array = (float[][])pool.get(0); int num2 = array[0].Length; printWriter.println(new StringBuilder().append("tmat ").append(num).append(' ').append(num2).toString()); for (int i = 0; i < num; i++) { printWriter.println(new StringBuilder().append("tmat [").append(i).append(']').toString()); array = (float[][])pool.get(i); for (int j = 0; j < num2; j++) { for (int k = 0; k < num2; k++) { if (j < num2 - 1) { if (this.sparseForm) { if (k < j) { printWriter.print("\t"); } if (k == j || k == j + 1) { printWriter.print((float)this.logMath.logToLinear(array[j][k])); } } else { printWriter.print((float)this.logMath.logToLinear(array[j][k])); } if (num2 - 1 == k) { printWriter.println(); } else { printWriter.print(" "); } } if (this.logger.isLoggable(Level.FINE)) { this.logger.fine(new StringBuilder().append("tmat j ").append(j).append(" k ").append(k).append(" tm ").append(array[j][k]).toString()); } } } } outputStream.close(); }
private void saveHMMPool(bool flag, OutputStream outputStream, string text) { this.logger.info("Saving HMM file to: "); this.logger.info(text); if (outputStream == null) { string text2 = new StringBuilder().append("Error trying to write file ").append(this.location).append(text).toString(); throw new IOException(text2); } PrintWriter printWriter = new PrintWriter(outputStream, true); int num = 0; int num2 = 0; int num3 = 0; int num4 = 0; Iterator iterator = this.hmmManager.iterator(); while (iterator.hasNext()) { HMM hmm = (HMM)iterator.next(); num4 += hmm.getOrder() + 1; if (((SenoneHMM)hmm).isContextDependent()) { num2++; } else { num++; num3 += hmm.getOrder(); } } printWriter.println("0.3"); printWriter.println(new StringBuilder().append(num).append(" n_base").toString()); printWriter.println(new StringBuilder().append(num2).append(" n_tri").toString()); printWriter.println(new StringBuilder().append(num4).append(" n_state_map").toString()); int statesNum = this.mixtureWeights.getStatesNum(); printWriter.println(new StringBuilder().append(statesNum).append(" n_tied_state").toString()); printWriter.println(new StringBuilder().append(num3).append(" n_tied_ci_state").toString()); int num5 = num; if (!Sphinx3Saver.assertionsDisabled && num5 != this.matrixPool.size()) { throw new AssertionError(); } printWriter.println(new StringBuilder().append(num5).append(" n_tied_tmat").toString()); printWriter.println("#"); printWriter.println("# Columns definitions"); printWriter.println("#base lft rt p attrib tmat ... state id's ..."); Iterator iterator2 = this.hmmManager.iterator(); while (iterator2.hasNext()) { HMM hmm2 = (HMM)iterator2.next(); SenoneHMM senoneHMM = (SenoneHMM)hmm2; if (!senoneHMM.isContextDependent()) { Unit unit = senoneHMM.getUnit(); string name = unit.getName(); printWriter.print(new StringBuilder().append(name).append('\t').toString()); string text3 = "-"; printWriter.print(new StringBuilder().append(text3).append(" ").toString()); string text4 = "-"; printWriter.print(new StringBuilder().append(text4).append(' ').toString()); string text5 = senoneHMM.getPosition().toString(); printWriter.print(new StringBuilder().append(text5).append('\t').toString()); string text6 = (!unit.isFiller()) ? "n/a" : "filler"; printWriter.print(new StringBuilder().append(text6).append('\t').toString()); int num6 = this.matrixPool.indexOf(senoneHMM.getTransitionMatrix()); if (!Sphinx3Saver.assertionsDisabled && num6 >= num5) { throw new AssertionError(); } printWriter.print(new StringBuilder().append(num6).append("\t").toString()); SenoneSequence senoneSequence = senoneHMM.getSenoneSequence(); Senone[] senones = senoneSequence.getSenones(); Senone[] array = senones; int num7 = array.Length; for (int i = 0; i < num7; i++) { Senone @object = array[i]; int num8 = this.senonePool.indexOf(@object); if (!Sphinx3Saver.assertionsDisabled && (num8 < 0 || num8 >= num3)) { throw new AssertionError(); } printWriter.print(new StringBuilder().append(num8).append("\t").toString()); } printWriter.println("N"); if (this.logger.isLoggable(Level.FINE)) { this.logger.fine(new StringBuilder().append("Saved ").append(unit).toString()); } } } iterator2 = this.hmmManager.iterator(); while (iterator2.hasNext()) { HMM hmm2 = (HMM)iterator2.next(); SenoneHMM senoneHMM = (SenoneHMM)hmm2; if (senoneHMM.isContextDependent()) { Unit unit = senoneHMM.getUnit(); LeftRightContext leftRightContext = (LeftRightContext)unit.getContext(); Unit[] leftContext = leftRightContext.getLeftContext(); Unit[] rightContext = leftRightContext.getRightContext(); if (!Sphinx3Saver.assertionsDisabled && (leftContext.Length != 1 || rightContext.Length != 1)) { throw new AssertionError(); } string text5 = unit.getName(); printWriter.print(new StringBuilder().append(text5).append('\t').toString()); string text6 = leftContext[0].getName(); printWriter.print(new StringBuilder().append(text6).append(" ").toString()); string name2 = rightContext[0].getName(); printWriter.print(new StringBuilder().append(name2).append(' ').toString()); string text7 = senoneHMM.getPosition().toString(); printWriter.print(new StringBuilder().append(text7).append('\t').toString()); string text8 = (!unit.isFiller()) ? "n/a" : "filler"; if (!Sphinx3Saver.assertionsDisabled && !String.instancehelper_equals(text8, "n/a")) { throw new AssertionError(); } printWriter.print(new StringBuilder().append(text8).append('\t').toString()); int num9 = this.matrixPool.indexOf(senoneHMM.getTransitionMatrix()); if (!Sphinx3Saver.assertionsDisabled && num9 >= num5) { throw new AssertionError(); } printWriter.print(new StringBuilder().append(num9).append("\t").toString()); SenoneSequence senoneSequence2 = senoneHMM.getSenoneSequence(); Senone[] senones2 = senoneSequence2.getSenones(); Senone[] array2 = senones2; int num8 = array2.Length; for (int j = 0; j < num8; j++) { Senone object2 = array2[j]; int num10 = this.senonePool.indexOf(object2); if (!Sphinx3Saver.assertionsDisabled && (num10 < 0 || num10 >= statesNum)) { throw new AssertionError(); } printWriter.print(new StringBuilder().append(num10).append("\t").toString()); } printWriter.println("N"); if (this.logger.isLoggable(Level.FINE)) { this.logger.fine(new StringBuilder().append("Saved ").append(unit).toString()); } } } outputStream.close(); }