当前位置: 首页>>代码示例>>Java>>正文


Java Utils.writeFile方法代码示例

本文整理汇总了Java中org.antlr.v4.runtime.misc.Utils.writeFile方法的典型用法代码示例。如果您正苦于以下问题:Java Utils.writeFile方法的具体用法?Java Utils.writeFile怎么用?Java Utils.writeFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.antlr.v4.runtime.misc.Utils的用法示例。


在下文中一共展示了Utils.writeFile方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import org.antlr.v4.runtime.misc.Utils; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
		LangDescriptor[] languages = new LangDescriptor[] {
			JAVA_DESCR,
			JAVA8_DESCR,
			JAVA_GUAVA_DESCR,
			JAVA8_GUAVA_DESCR,
			ANTLR4_DESCR,
			SQLITE_CLEAN_DESCR,
			TSQL_CLEAN_DESCR,
			SQLITE_NOISY_DESCR,
			TSQL_NOISY_DESCR,
//			QUORUM_DESCR,
		};
		List<String> corpusDirs = map(languages, l -> l.corpusDir);
		String[] dirs = corpusDirs.toArray(new String[languages.length]);
		String python = testAllLanguages(languages, dirs, "leave_one_out.pdf");
		String fileName = "python/src/leave_one_out.py";
		Utils.writeFile(fileName, python);
		System.out.println("wrote python code to "+fileName);
	}
 
开发者ID:antlr,项目名称:codebuff,代码行数:21,代码来源:LeaveOneOutValidator.java

示例2: format

import org.antlr.v4.runtime.misc.Utils; //导入方法依赖的package包/类
public static void format(LangDescriptor language,
                          String testFileName,
                          String outputFileName)
	throws Exception
{
	// load all files up front
	List<String> allFiles = getFilenames(new File(language.corpusDir), language.fileRegex);
	List<InputDocument> documents = load(allFiles, language);
	// if in corpus, don't include in corpus
	final String path = new File(testFileName).getAbsolutePath();
	List<InputDocument> others = filter(documents, d -> !d.fileName.equals(path));
	InputDocument testDoc = parse(testFileName, language);
	Corpus corpus = new Corpus(others, language);
	corpus.train();

	Formatter formatter = new Formatter(corpus, language.indentSize, Formatter.DEFAULT_K,
	                                    FEATURES_INJECT_WS, FEATURES_HPOS);
	String output = formatter.format(testDoc, false);

	if ( outputFileName!=null ) {
		Utils.writeFile(outputFileName, output);
	}
	else {
		System.out.print(output);
	}
}
 
开发者ID:antlr,项目名称:codebuff,代码行数:27,代码来源:Tool.java

示例3: checkCExec

import org.antlr.v4.runtime.misc.Utils; //导入方法依赖的package包/类
public void checkCExec(String filename) throws Exception {
	URL testFolderURL = TestCGen.class.getClassLoader().getResource(SAMPLES_DIR);
	String testFolder = testFolderURL.getPath();
	String workingDir = getWorkingDir();

	String J_pathToFile = testFolder+"/"+filename;
	String C_filename = basename(filename)+".c";

	JTran jTran = new JTran();
	String C_code = jTran.translate(J_pathToFile, C_filename, false, false);

	Utils.writeFile(workingDir+"/"+C_filename, C_code);

	// compile
	String[] cc = {"cc", "-o", basename(filename), C_filename};
	Triple<Integer, String, String> cc_result = exec(cc, getWorkingDir());
	int execCode = cc_result.a;
	String stdout = cc_result.b;
	String stderr = cc_result.c;

	assertEquals("", stdout);
	assertEquals("", stderr);
	assertEquals(0, execCode);

	// execute
	String[] exec_cmd = {"./"+basename(filename)};
	Triple<Integer, String, String> result = exec(exec_cmd, getWorkingDir());
	execCode = result.a;
	stdout = result.b;
	stderr = result.c;

	String expected_output_filename = basename(filename)+".txt";
	String expected_output = readFile(testFolder+"/"+expected_output_filename);

	assertEquals(expected_output, stdout);
	assertEquals("", stderr);
	assertEquals(0, execCode);
}
 
开发者ID:aabajaj2,项目名称:vtable-aabajaj2,代码行数:39,代码来源:TestCGen.java

示例4: writePython

import org.antlr.v4.runtime.misc.Utils; //导入方法依赖的package包/类
public static void writePython(LangDescriptor[] languages, List<Integer> ks, Float[][] medians) throws IOException {
	StringBuilder data = new StringBuilder();
	StringBuilder plot = new StringBuilder();
	for (int i = 0; i<languages.length; i++) {
		LangDescriptor language = languages[i];
		List<Float> filteredMedians = BuffUtils.filter(Arrays.asList(medians[i]), m -> m!=null);
		data.append(language.name+'='+filteredMedians+'\n');
		plot.append(String.format("ax.plot(ks, %s, label=\"%s\", marker='%s', color='%s')\n",
		                          language.name, language.name,
		                          nameToGraphMarker.get(language.name),
								  nameToGraphColor.get(language.name)));
	}

	String python =
		"#\n"+
		"# AUTO-GENERATED FILE. DO NOT EDIT\n" +
		"# CodeBuff %s '%s'\n" +
		"#\n"+
		"import numpy as np\n"+
		"import matplotlib.pyplot as plt\n\n" +
		"%s\n" +
		"ks = %s\n"+
		"fig = plt.figure()\n"+
		"ax = plt.subplot(111)\n"+
		"%s"+
		"ax.tick_params(axis='both', which='major', labelsize=18)\n" +
		"ax.set_xlabel(\"$k$ nearest neighbors\", fontsize=20)\n"+
		"ax.set_ylabel(\"Median error rate\", fontsize=20)\n" +
		"#ax.set_title(\"k Nearest Neighbors vs\\nLeave-one-out Validation Error Rate\")\n"+
		"plt.legend(fontsize=18)\n\n" +
		"fig.savefig('images/vary_k.pdf', format='pdf')\n"+
		"plt.show()\n";
	String code = String.format(python, Tool.version, new Date(), data, ks, plot);

	String fileName = "python/src/vary_k.py";
	Utils.writeFile(fileName, code);
	System.out.println("wrote python code to "+fileName);
}
 
开发者ID:antlr,项目名称:codebuff,代码行数:39,代码来源:TestK.java

示例5: main

import org.antlr.v4.runtime.misc.Utils; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
	LangDescriptor[] languages = new LangDescriptor[] {
		JAVA_DESCR,
		JAVA8_DESCR,
		JAVA_GUAVA_DESCR,
	};
	List<String> corpusDirs = map(languages, l -> l.corpusDir);
	String[] dirs = corpusDirs.toArray(new String[languages.length]);
	String python = testAllLanguages(languages, dirs, "all_java_leave_one_out.pdf");
	String fileName = "python/src/all_java_leave_one_out.py";
	Utils.writeFile(fileName, python);
	System.out.println("wrote python code to "+fileName);
}
 
开发者ID:antlr,项目名称:codebuff,代码行数:14,代码来源:AllJavaLeaveOneOutValidation.java

示例6: main

import org.antlr.v4.runtime.misc.Utils; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
	LangDescriptor[] languages = new LangDescriptor[] {
		SQLITE_NOISY_DESCR,
		SQLITE_CLEAN_DESCR,
		TSQL_NOISY_DESCR,
		TSQL_CLEAN_DESCR,
	};
	List<String> corpusDirs = map(languages, l -> l.corpusDir);
	String[] dirs = corpusDirs.toArray(new String[languages.length]);
	String python = testAllLanguages(languages, dirs, "all_sql_leave_one_out.pdf");
	String fileName = "python/src/all_sql_leave_one_out.py";
	Utils.writeFile(fileName, python);
	System.out.println("wrote python code to "+fileName);
}
 
开发者ID:antlr,项目名称:codebuff,代码行数:15,代码来源:AllSQLLeaveOneOutValidation.java

示例7: validate

import org.antlr.v4.runtime.misc.Utils; //导入方法依赖的package包/类
public static Triple<Formatter,Float,Float> validate(LangDescriptor language,
	                                                     List<InputDocument> documents,
	                                                     InputDocument testDoc,
	                                                     boolean saveOutput,
	                                                     boolean computeEditDistance)
		throws Exception
	{
//		kNNClassifier.resetCache();
		Corpus corpus = new Corpus(documents, language);
		corpus.train();
//		System.out.printf("%d feature vectors\n", corpus.featureVectors.size());
		Formatter formatter = new Formatter(corpus, language.indentSize);
		String output = formatter.format(testDoc, false);
		float editDistance = 0;
		if ( computeEditDistance ) {
			editDistance = normalizedLevenshteinDistance(testDoc.content, output);
		}
		ClassificationAnalysis analysis = new ClassificationAnalysis(testDoc, formatter.getAnalysisPerToken());
//		System.out.println(testDoc.fileName+": edit distance = "+editDistance+", error rate = "+analysis.getErrorRate());
		if ( saveOutput ) {
			File dir = new File(outputDir+"/"+language.name);
			if ( saveOutput ) {
				dir = new File(outputDir+"/"+language.name);
				dir.mkdir();
			}
			Utils.writeFile(dir.getPath()+"/"+new File(testDoc.fileName).getName(), output);
		}
		return new Triple<>(formatter, editDistance, analysis.getErrorRate());
	}
 
开发者ID:antlr,项目名称:codebuff,代码行数:30,代码来源:SubsetValidator.java

示例8: writeFile

import org.antlr.v4.runtime.misc.Utils; //导入方法依赖的package包/类
public static void writeFile(String dir, String fileName, String content) {
	try {
		Utils.writeFile(dir+"/"+fileName, content, "UTF-8");
	}
	catch (IOException ioe) {
		System.err.println("can't write file");
		ioe.printStackTrace(System.err);
	}
}
 
开发者ID:janyou,项目名称:ANTLR-Swift-Target,代码行数:10,代码来源:BaseTest.java

示例9: checkCGen

import org.antlr.v4.runtime.misc.Utils; //导入方法依赖的package包/类
public void checkCGen(String filename) throws Exception {
	URL testFolderURL = TestCGen.class.getClassLoader().getResource(SAMPLES_DIR);
	String testFolder = testFolderURL.getPath();
	String workingDir = getWorkingDir();

	String J_pathToFile = testFolder+"/"+filename;
	String C_filename = basename(filename)+".c";

	JTran jTran = new JTran();
	String C_code = jTran.translate(J_pathToFile, C_filename, false, false);

	Utils.writeFile(workingDir+"/"+C_filename, C_code);

	String[] indent_result_cmd = {
		"indent",
		"-bap", "-bad", "-br", "-nce", "-ncs", "-nprs", "-npcs", "-sai", "-saw",
		"-di1", "-brs", "-blf", "--indent-level4", "-nut", "-sob", "-l200",
		C_filename,
		"-o", C_filename // write on top of itself
	};

	// normalize generated code
	exec(indent_result_cmd, workingDir);

	// format the expected file as well
	String expected_C_CodeFilename = testFolder+"/"+C_filename;
	String[] indent_expected_cmd = {
		"indent",
		"-bap", "-bad", "-br", "-nce", "-ncs", "-nprs", "-npcs", "-sai", "-saw",
		"-di1", "-brs", "-blf", "--indent-level4", "-nut", "-sob", "-l200",
		expected_C_CodeFilename,
		"-o", "expected_"+C_filename
	};
	exec(indent_expected_cmd, workingDir);

	// compare with expected c file
	String[] diff_cmd = {
		"diff", "expected_"+C_filename, C_filename
	};
	Triple<Integer, String, String> result = exec(diff_cmd, workingDir);
	int execCode = result.a;
	String stdout = result.b;
	String stderr = result.c;

	assertEquals("", stdout);
	assertEquals("", stderr);
	assertEquals(0, execCode);
}
 
开发者ID:aabajaj2,项目名称:vtable-aabajaj2,代码行数:49,代码来源:TestCGen.java

示例10: main

import org.antlr.v4.runtime.misc.Utils; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
		LangDescriptor[] languages = new LangDescriptor[] {
//			QUORUM_DESCR,
			ANTLR4_DESCR,
			JAVA_DESCR,
			JAVA8_DESCR,
			JAVA_GUAVA_DESCR,
			JAVA8_GUAVA_DESCR,
			SQLITE_CLEAN_DESCR,
			TSQL_CLEAN_DESCR,
		};

		int maxNumFiles = 30;
		int trials = 50;
		Map<String,float[]> results = new HashMap<>();
		for (LangDescriptor language : languages) {
			float[] medians = getMedianErrorRates(language, maxNumFiles, trials);
			results.put(language.name, medians);
		}
		String python =
			"#\n"+
			"# AUTO-GENERATED FILE. DO NOT EDIT\n" +
			"# CodeBuff <version> '<date>'\n" +
			"#\n"+
			"import numpy as np\n"+
			"import matplotlib.pyplot as plt\n\n" +
			"fig = plt.figure()\n"+
			"ax = plt.subplot(111)\n"+
			"N = <maxNumFiles>\n" +
			"sizes = range(1,N+1)\n" +
			"<results:{r |\n" +
			"<r> = [<rest(results.(r)); separator={,}>]\n"+
			"ax.plot(range(1,len(<r>)+1), <r>, label=\"<r>\", marker='<markers.(r)>', color='<colors.(r)>')\n" +
			"}>\n" +
			"ax.yaxis.grid(True, linestyle='-', which='major', color='lightgrey', alpha=0.5)\n" +
			"ax.set_xlabel(\"Number of training files in sample corpus subset\", fontsize=14)\n"+
			"ax.set_ylabel(\"Median Error rate for <trials> trials\", fontsize=14)\n" +
			"ax.set_title(\"Effect of Corpus size on Median Leave-one-out Validation Error Rate\")\n"+
			"plt.legend()\n" +
			"plt.tight_layout()\n" +
			"fig.savefig('images/subset_validator.pdf', format='pdf')\n"+
			"plt.show()\n";
		ST pythonST = new ST(python);
		pythonST.add("results", results);
		pythonST.add("markers", LeaveOneOutValidator.nameToGraphMarker);
		pythonST.add("colors", LeaveOneOutValidator.nameToGraphColor);
		pythonST.add("version", version);
		pythonST.add("date", new Date());
		pythonST.add("trials", trials);
		pythonST.add("maxNumFiles", maxNumFiles);
		List<String> corpusDirs = map(languages, l -> l.corpusDir);
		String[] dirs = corpusDirs.toArray(new String[languages.length]);
		String fileName = "python/src/subset_validator.py";
		Utils.writeFile(fileName, pythonST.render());
		System.out.println("wrote python code to "+fileName);
	}
 
开发者ID:antlr,项目名称:codebuff,代码行数:57,代码来源:SubsetValidator.java


注:本文中的org.antlr.v4.runtime.misc.Utils.writeFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。