⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 digraph.java

📁 这是一个从音频信号里提取特征参量的程序
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	    }		}		  	// repaint the work area	//	workArea.repaint();    }      // method: cut    //    // arguments: none    // returns  : none    //    // method cuts the current vertex and adds it to the clipboard    //    public void cut() {	// check for a valid vertex	//	if (currVertexFocus == null) {	    return;	}	// clear the current contents of the clipboard	//	clipboard.removeAllElements();	// add the vertex to the clipboard	//	clipboard.addElement(currVertexFocus);	// remove the vertex 	//	removeVertex(currVertexFocus);	// repaint the work area	//	workArea.repaint();    }    // method: copy    //    // arguments: none    // returns  : none    //    // method copies the current vertex and adds it to the clipboard    //    public void copy() {	// check for a valid vertex	//	if (currVertexFocus == null) {	    return;	}	// we cannot copy and paste SAMPLED_DATA and FEATURE	// vertices, hence, we check for them here	//	if ((currVertexFocus.getVertexType() == START) || 	    (currVertexFocus.getVertexType() == STOP)) {	    JFrame frame = new JFrame("Warning");	    JOptionPane.showMessageDialog(frame, 					  "You cannot paste Input or output block");	    return;	}	// clear the current contents of the clipboard	//	clipboard.removeAllElements();	// add the vertex to the clipboard	//	clipboard.addElement(currVertexFocus);	// repaint the work area	//	workArea.repaint();    }    // method: paste    //    // arguments: none    // returns  : none    //    // method pastes the current vertex from the clipboard    //    public void paste() {	// loop through each element in the clipboard and add them back	//	for(int i=0; i < clipboard.size(); i++) {	    // get the vertex that we intend to paste	    //	    Vertex v = (Vertex)clipboard.elementAt(i);	    	    // create a copy of the vertex and remove all arcs	    //	    Vertex vertex = new Vertex(v);	    // remove all parents and children associated with the vertex	    //	    vertex.vertexParents.removeAllElements();	    vertex.vertexChildren.removeAllElements();	    // attach a mouse motion listener to the vertex	    //	    vertex.addMouseListener(this);	    vertex.addMouseMotionListener(this);	    // set the font for the vertex	    //	    vertex.setFont(newCoeffFont);	    // set the location of the vertex	    //	    Point coordinates = new Point(mouseXloc, mouseYloc);	    vertex.setLocation(coordinates);	    	    // we need create a unique name for the current vertex	    // if it is of type CUSTOM or CONTAINER	    //	    if ((vertex.getVertexType() == CUSTOM) ||		(vertex.getVertexType() == CONTAINER)) {		// when the old name does not exist reuse it		//		if (!coeffLabels.contains(vertex.getText())) {		    currVertexLabel = vertex.getText();		}		// when the old name exist create a new copy		//		else {		    int offset = -1;		    currVertexLabel = vertex.getText();		    while (coeffLabels.contains(currVertexLabel)) {			offset++;			currVertexLabel = vertex.getText() + offset;		    }		}		maxInputVertices++;		currVertexLabel = "S"+maxInputVertices;		// set the name of the vertex		//		if (currVertexLabel.length() > 3) {		    vertex.setText(currVertexLabel.substring(0, 3));		}		else {		    vertex.setText(currVertexLabel);		}		vertex.setVertexName(currVertexLabel);		coeffLabels.addElement(currVertexLabel);	    }	    // add the element to the data structures	    //	    vertices.addElement(vertex);	    workArea.add(vertex);	}		// repaint the work area	//	workArea.repaint();    }     // method: clearAllMemory    //    // arguments: none    // returns  : none    //    // method clears out all memory, i.e., vectors and hash tables    //    public void clearAllMemory() {	// reset the maximum number of vertices	//	maxInputVertices = 0;		// reset the vertices	//	initVertexFocus = null;	cfgVertexFocus = null;	currVertexFocus = null;	vertexParent = null;	vertexChild = null;		inputBlockExist = false;	outputBlockExist = false;	// clear out all vectors	//	vertices.removeAllElements();	coeffLabels.removeAllElements();	dataLabels.removeAllElements();	clipboard.removeAllElements();	selectedVertices.removeAllElements();		// reset the current line index	//	line_index = 0;	// clear out all hash tables	//	tagToVertex.clear();	// clear out the work area	//	workArea.removeAll();	// clear out graphArc object	//	graphArc = new GraphArc();    }    // method: writeGraph    //    // arguments: none    // return   : none    //    // writes the sof file    //    public void writeGraph() {	getVertexSymbol();	// convert the Digraph format to JSGF format	//	convertJSGF();    }        // method: getVertexSymbol    //    // arguments: none    // return   : none    //    // get Digraph inforamtion    //    public void getVertexSymbol() {		// define tempory vertex collection	//	Vector vertexCollection = null; 	wordVertex = new Vector(100, 50);	wordSymbol = new Vector(100, 50);	for (int i=0; i < vertices.size(); i++) {	    	    //get the start vertex	    //	    Vertex vertex = (Vertex)vertices.elementAt(i);	    	    if(vertex.getVertexType() != START && vertex.getVertexType() != STOP) {		String datavar = "" + vertex.values.get(0);		StringTokenizer tokens = new StringTokenizer(datavar, " ");				String xvar = (tokens.nextToken()).trim();		if(wordSymbol == null) {		    wordSymbol.add(xvar);		}		else {		    if(!wordSymbol.contains(xvar)) {    			wordSymbol.add(xvar);		    }		}		SymbolTable s1 = new SymbolTable();		s1.vName = xvar;		s1.nodeIndex = vertex.vertexName;		s1.symbolIndex = wordSymbol.indexOf(xvar);		wordVertex.add(s1);				while(tokens.hasMoreTokens()) {		    xvar = (tokens.nextToken()).trim();		    if(!wordSymbol.contains(xvar)) {    		    wordSymbol.add(xvar);		    }		    SymbolTable s2 = new SymbolTable();		    s2.vName = xvar;		    s2.nodeIndex = vertex.vertexName;		    s2.symbolIndex = wordSymbol.indexOf(xvar);		    wordVertex.add(s2);		}					    }	}	// declare local variables	//	FileOutputStream fout = null;	PrintWriter file = null;	String line = null;	// reset the save flag to indicate the obvious	// 	saveWork = false;	// open the selected file for writing	//	try {	    // initialize the variables	    //	    line = new String();	    	    // initialize the file output stream	    //	    fout = new FileOutputStream(graphFile);	    file = new PrintWriter(fout);	    // write the file header	    //	    file.println(HEADER_TAG_00);	    file.println(HEADER_TAG_05);			    // write search symbol	    //	    writeSearchSymbol(file);	    writeSymbolVertices(file);	    writeSymbolArcs(file);	    file.println("};");	    // close the file descriptor	    //	    file.close();	}	// catch and deal with any file I/O exceptions	//	catch(IOException e1) {}    }    // method: writeSearchSymbol    //    // arguments:    //    BufferedReader file: (input) file descriptor    // return   : none    //    // writes the sof file    //    public void writeSearchSymbol(PrintWriter file) {		String line = null;	file.println("values = {");	for(int i=0; i < wordSymbol.size(); i++) {	    String tmp = (String)wordSymbol.elementAt(i);	    tmp = tmp.toUpperCase();	    line = "  \""+tmp+"\"";	    file.println(line);	    if(i < wordSymbol.size() - 1)		line = "}, {";	    else		line = "};"; 	    file.println(line);	}    }    // method: writeSymbolVertices    //    // arguments:    //    BufferedReader file: (input) file descriptor    // return   : none    //    // writes the sof file    //    public void writeSymbolVertices(PrintWriter file) {		String line = null;		file.println(HEADER_TAG_06);	file.println("values = {");	file.println("  weighted = true;");	file.println("  vertices =");		for(int i=0; i < wordVertex.size(); i++) {	    SymbolTable s1 = (SymbolTable)wordVertex.elementAt(i);	    if(i < wordVertex.size() - 1)		line = "        {" + i  + ", {" + s1.symbolIndex + "}},";	    else		line = "        {" + i  + ", {" + s1.symbolIndex + "}};";	    file.println(line);	}    }    // method: writeSymbolArcs    //    // arguments:    //    BufferedReader file: (input) file descriptor    // return   : none    //    // writes the sof file    //    public void writeSymbolArcs(PrintWriter file) {		// declare local variables	//	String src = null;	String dst = null;	String line = null;	String wei = null;	String epi = null;	file.println("  arcs =");	boolean start = false;	for (int i=0; i < vertices.size(); i++) {	    	    //get the start vertex	    //	    Vertex vertex = (Vertex)vertices.elementAt(i);	    	    if(vertex.getVertexType() == START) {				int index = i;							// check if the vertex has any children		//				if (vertex.getOutDegree() > 0) {				    // get the vector of children		    //		    Vector children = (Vector)vertex.getChildren();		    		    // loop over all children and write the arcs		    //		    for (int j=0; j < children.size(); j++) {					// get the current child			//			Vertex child = (Vertex)children.elementAt(j);						for(int k = 0; k < graphArc.from.size(); k++) {			    if((Vertex)graphArc.from.get(k) == vertex && (Vertex)graphArc.to.get(k) == child) {			    wei = (String)graphArc.weights.get(k);			    double tmpw;			    if(wei==null)				wei=""+"1.0";			    tmpw = Double.valueOf(wei).doubleValue();			    if(wei.equals("0.0") || tmpw == 0.0)				tmpw = -23.02585093;			    else				tmpw = Math.log(tmpw);			    wei = Double.toString(tmpw);			    epi = (String)graphArc.epsilon.get(k);			    break;			    }			}						src = new String("S");			for(int w=0; w < wordVertex.size(); w++) {			    SymbolTable s1 = (SymbolTable)wordVertex.elementAt(w);			    if(s1.nodeIndex.equals(child.vertexName)) {				if (start) {				    file.println(",");				}				dst = new String("" + w);			    				if(epi == "true") {				    line = "        {" + src + ", " + dst + ", " + "epi" + 					", " + "true" +"}";				}				else {				    line = "        {" + src + ", " + dst + ", " 					+ wei +"}";				}		    				file.print(line);				start = true;			    }			} // end for loop w		    }// end for loop j		}		break;	    }	} // end for loop i	writeSubSymbolArcs(file, vertices);	file.println(";");	    }    public void writeSubSymbolArcs(PrintWriter file, Vector vec) {	// declare local variables	//	String src = null;	String dst = null;	String wei = null;	String epi = null;	String line = null;	boolean start = false;	boolean selfloop = false;	for (int i=0; i < vec.size(); i++) {		    // get the current vertex	    //	    	    Vertex vertex = (Vertex)vec.elementAt(i);	    if(vertex.getVertexType() != START && vertex.getVertexType() != 	       STOP) {		file.println(",");		start = false;		//check if the vertex has self arc		//		for(int k = 0; k < graphArc.from.size(); k++) {		    selfloop = false;		    if((Vertex)graphArc.from.get(k) == vertex && (Vertex)graphArc.to.get(k) == vertex) {			selfloop = true;			wei = (String)graphArc.weights.get(k);			double tmpw;					if(wei==null)			    wei=""+"1.0";			tmpw = Double.valueOf(wei).doubleValue();			if(wei.equals("0.0") || tmpw == 0.0)			    tmpw = -23.02585093;			else			    tmpw = Math.log(tmpw);			wei = Double.toString(tmpw);			epi = (String)graphArc.epsilon.get(k);			for(int w=0; w < wordVertex.size(); w++) {			    			    SymbolTable s1 = (SymbolTable)wordVertex.elementAt(w);			    if(s1.nodeIndex.equals(vertex.vertexName)) {				src = new String("" + w);								for(int n = 0; n < wordVertex.size(); n++) {				      SymbolTable s2 = (SymbolTable)wordVertex.elementAt(n);				      if(s2.nodeIndex.equals(vertex.vertexName)) {					  if (start) 					      file.println(",");					  					  dst = new String("" + n);									  if(epi == "true") {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -