List of usage examples for org.springframework.core.io.support PathMatchingResourcePatternResolver getResource
@Override
public Resource getResource(String location)
From source file:org.dkpro.similarity.experiments.sts2013.util.Features2Arff.java
public static void toArffFile(Mode mode, Dataset... datasets) throws IOException { for (Dataset dataset : datasets) { String path = GOLDSTANDARD_DIR + "/" + mode.toString().toLowerCase() + "/STS.gs." + dataset.toString() + ".txt"; PathMatchingResourcePatternResolver r = new PathMatchingResourcePatternResolver(); Resource res = r.getResource(path); toArffFile(mode, dataset, res.getFile()); }/*ww w. ja v a 2 s . c o m*/ }
From source file:org.dkpro.similarity.experiments.sts2013baseline.util.Features2Arff.java
public static void toArffFile(Mode mode, Dataset... datasets) throws IOException { for (Dataset dataset : datasets) { String path = GOLDSTANDARD_DIR + "/" + mode.toString().toLowerCase() + "/STS.gs." + dataset.toString() + ".txt"; PathMatchingResourcePatternResolver r = new PathMatchingResourcePatternResolver(); Resource res = r.getResource(path); toArffFile(mode, dataset, res.getInputStream()); }//from w w w. java 2 s . c om }
From source file:org.springsource.sinspctr.rest.ResourceLocator.java
public static String[] findResourcesPaths(String locationPattern) throws IOException { ClassLoader loader = findClassLoader(); PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(loader); Resource[] resources = resolver.getResources(locationPattern); // use project-relative path if appropriate String rootPath = resolver.getResource(".").getFile().getPath(); String[] results = new String[resources.length]; for (int i = 0; i < resources.length; i++) { String path = resources[i].getFile().getPath(); if (path.startsWith(rootPath)) { path = path.substring(rootPath.length(), path.length()); }//from w w w. j a v a 2 s . c o m results[i] = path; } return results; }
From source file:org.dkpro.similarity.experiments.sts2013baseline.util.Evaluator.java
private static void computePearsonCorrelation(Mode mode, Dataset dataset) throws IOException { File expScoresFile = new File( OUTPUT_DIR + "/" + mode.toString().toLowerCase() + "/" + dataset.toString() + ".csv"); String gsScoresFilePath = GOLDSTANDARD_DIR + "/" + mode.toString().toLowerCase() + "/" + "STS.gs." + dataset.toString() + ".txt"; PathMatchingResourcePatternResolver r = new PathMatchingResourcePatternResolver(); Resource res = r.getResource(gsScoresFilePath); File gsScoresFile = res.getFile(); List<Double> expScores = new ArrayList<Double>(); List<Double> gsScores = new ArrayList<Double>(); List<String> expLines = FileUtils.readLines(expScoresFile); List<String> gsLines = FileUtils.readLines(gsScoresFile); for (int i = 0; i < expLines.size(); i++) { expScores.add(Double.parseDouble(expLines.get(i))); gsScores.add(Double.parseDouble(gsLines.get(i))); }/*from w w w . ja v a 2s. c o m*/ double[] expArray = ArrayUtils.toPrimitive(expScores.toArray(new Double[expScores.size()])); double[] gsArray = ArrayUtils.toPrimitive(gsScores.toArray(new Double[gsScores.size()])); PearsonsCorrelation pearson = new PearsonsCorrelation(); Double correl = pearson.correlation(expArray, gsArray); FileUtils.writeStringToFile( new File(OUTPUT_DIR + "/" + mode.toString().toLowerCase() + "/" + dataset.toString() + ".txt"), correl.toString()); }
From source file:org.dkpro.similarity.experiments.sts2013.util.Evaluator.java
@SuppressWarnings("unchecked") private static void computePearsonCorrelation(Mode mode, Dataset dataset) throws IOException { File expScoresFile = new File( OUTPUT_DIR + "/" + mode.toString().toLowerCase() + "/" + dataset.toString() + ".csv"); String gsScoresFilePath = GOLDSTANDARD_DIR + "/" + mode.toString().toLowerCase() + "/" + "STS.gs." + dataset.toString() + ".txt"; PathMatchingResourcePatternResolver r = new PathMatchingResourcePatternResolver(); Resource res = r.getResource(gsScoresFilePath); File gsScoresFile = res.getFile(); List<Double> expScores = new ArrayList<Double>(); List<Double> gsScores = new ArrayList<Double>(); List<String> expLines = FileUtils.readLines(expScoresFile); List<String> gsLines = FileUtils.readLines(gsScoresFile); for (int i = 0; i < expLines.size(); i++) { expScores.add(Double.parseDouble(expLines.get(i))); gsScores.add(Double.parseDouble(gsLines.get(i))); }// w ww .jav a 2 s . c om double[] expArray = ArrayUtils.toPrimitive(expScores.toArray(new Double[expScores.size()])); double[] gsArray = ArrayUtils.toPrimitive(gsScores.toArray(new Double[gsScores.size()])); PearsonsCorrelation pearson = new PearsonsCorrelation(); Double correl = pearson.correlation(expArray, gsArray); FileUtils.writeStringToFile( new File(OUTPUT_DIR + "/" + mode.toString().toLowerCase() + "/" + dataset.toString() + ".txt"), correl.toString()); }
From source file:org.dkpro.similarity.experiments.sts2013baseline.util.Evaluator.java
public static void runEvaluationMetric(Mode mode, EvaluationMetric metric, Dataset... datasets) throws IOException { StringBuilder sb = new StringBuilder(); // Compute Pearson correlation for the specified datasets for (Dataset dataset : datasets) { computePearsonCorrelation(mode, dataset); }/*from ww w . j a va 2 s . com*/ if (metric == PearsonAll) { List<Double> concatExp = new ArrayList<Double>(); List<Double> concatGS = new ArrayList<Double>(); // Concat the scores for (Dataset dataset : datasets) { File expScoresFile = new File( OUTPUT_DIR + "/" + mode.toString().toLowerCase() + "/" + dataset.toString() + ".csv"); List<String> lines = FileUtils.readLines(expScoresFile); for (String line : lines) { concatExp.add(Double.parseDouble(line)); } } // Concat the gold standard for (Dataset dataset : datasets) { String gsScoresFilePath = GOLDSTANDARD_DIR + "/" + mode.toString().toLowerCase() + "/" + "STS.gs." + dataset.toString() + ".txt"; PathMatchingResourcePatternResolver r = new PathMatchingResourcePatternResolver(); Resource res = r.getResource(gsScoresFilePath); File gsScoresFile = res.getFile(); List<String> lines = FileUtils.readLines(gsScoresFile); for (String line : lines) { concatGS.add(Double.parseDouble(line)); } } double[] concatExpArray = ArrayUtils.toPrimitive(concatExp.toArray(new Double[concatExp.size()])); double[] concatGSArray = ArrayUtils.toPrimitive(concatGS.toArray(new Double[concatGS.size()])); PearsonsCorrelation pearson = new PearsonsCorrelation(); Double correl = pearson.correlation(concatExpArray, concatGSArray); sb.append(correl.toString()); } else if (metric == PearsonMean) { List<Double> scores = new ArrayList<Double>(); for (Dataset dataset : datasets) { File resultFile = new File( OUTPUT_DIR + "/" + mode.toString().toLowerCase() + "/" + dataset.toString() + ".txt"); double score = Double.parseDouble(FileUtils.readFileToString(resultFile)); scores.add(score); } double mean = 0.0; for (Double score : scores) { mean += score; } mean = mean / scores.size(); sb.append(mean); } FileUtils.writeStringToFile( new File(OUTPUT_DIR + "/" + mode.toString().toLowerCase() + "/" + metric.toString() + ".txt"), sb.toString()); }
From source file:org.dkpro.similarity.experiments.sts2013.util.Evaluator.java
@SuppressWarnings("unchecked") public static void runEvaluationMetric(Mode mode, EvaluationMetric metric, Dataset... datasets) throws IOException { StringBuilder sb = new StringBuilder(); // Compute Pearson correlation for the specified datasets for (Dataset dataset : datasets) { computePearsonCorrelation(mode, dataset); }//from www .j a v a2s . c om if (metric == PearsonAll) { List<Double> concatExp = new ArrayList<Double>(); List<Double> concatGS = new ArrayList<Double>(); // Concat the scores for (Dataset dataset : datasets) { File expScoresFile = new File( OUTPUT_DIR + "/" + mode.toString().toLowerCase() + "/" + dataset.toString() + ".csv"); List<String> lines = FileUtils.readLines(expScoresFile); for (String line : lines) { concatExp.add(Double.parseDouble(line)); } } // Concat the gold standard for (Dataset dataset : datasets) { String gsScoresFilePath = GOLDSTANDARD_DIR + "/" + mode.toString().toLowerCase() + "/" + "STS.gs." + dataset.toString() + ".txt"; PathMatchingResourcePatternResolver r = new PathMatchingResourcePatternResolver(); Resource res = r.getResource(gsScoresFilePath); File gsScoresFile = res.getFile(); List<String> lines = FileUtils.readLines(gsScoresFile); for (String line : lines) { concatGS.add(Double.parseDouble(line)); } } double[] concatExpArray = ArrayUtils.toPrimitive(concatExp.toArray(new Double[concatExp.size()])); double[] concatGSArray = ArrayUtils.toPrimitive(concatGS.toArray(new Double[concatGS.size()])); PearsonsCorrelation pearson = new PearsonsCorrelation(); Double correl = pearson.correlation(concatExpArray, concatGSArray); sb.append(correl.toString()); } else if (metric == PearsonMean) { List<Double> scores = new ArrayList<Double>(); for (Dataset dataset : datasets) { File resultFile = new File( OUTPUT_DIR + "/" + mode.toString().toLowerCase() + "/" + dataset.toString() + ".txt"); double score = Double.parseDouble(FileUtils.readFileToString(resultFile)); scores.add(score); } double mean = 0.0; for (Double score : scores) { mean += score; } mean = mean / scores.size(); sb.append(mean); } else if (metric == PearsonWeightedMean) { List<Double> scores = new ArrayList<Double>(); List<Integer> weights = new ArrayList<Integer>(); for (Dataset dataset : datasets) { File resultFile = new File( OUTPUT_DIR + "/" + mode.toString().toLowerCase() + "/" + dataset.toString() + ".txt"); double score = Double.parseDouble(FileUtils.readFileToString(resultFile)); File scoresFile = new File( OUTPUT_DIR + "/" + mode.toString().toLowerCase() + "/" + dataset.toString() + ".csv"); int weight = FileUtils.readLines(scoresFile).size(); scores.add(score); weights.add(weight); } double mean = 0.0; int weightsum = 0; for (int i = 0; i < scores.size(); i++) { Double score = scores.get(i); Integer weight = weights.get(i); mean += weight * score; weightsum += weight; } mean = mean / weightsum; sb.append(mean); } FileUtils.writeStringToFile( new File(OUTPUT_DIR + "/" + mode.toString().toLowerCase() + "/" + metric.toString() + ".txt"), sb.toString()); }
From source file:org.codehaus.groovy.grails.plugins.springsecurity.AuthorizeTools.java
@SuppressWarnings("unchecked") private static void loadExternalConfigs(final List<ConfigObject> configs, final ConfigObject config) { PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); List<String> locations = (List<String>) ConfigurationHolder.getFlatConfig() .get("springsecurity.config.locations"); if (locations != null) { for (String location : locations) { if (StringUtils.hasLength(location)) { try { Resource resource = resolver.getResource(location); InputStream stream = null; try { stream = resource.getInputStream(); ConfigSlurper configSlurper = new ConfigSlurper(GrailsUtil.getEnvironment()); configSlurper.setBinding(config); if (resource.getFilename().endsWith(".groovy")) { configs.add(configSlurper.parse(IOUtils.toString(stream))); } else if (resource.getFilename().endsWith(".properties")) { Properties props = new Properties(); props.load(stream); configs.add(configSlurper.parse(props)); }/* w w w. j a v a2s . com*/ } finally { if (stream != null) { stream.close(); } } } catch (Exception e) { LOG.warn("Unable to load specified config location $location : ${e.message}"); LOG.debug("Unable to load specified config location $location : ${e.message}", e); } } } } }
From source file:ch.sbb.releasetrain.jsfbootadapter.FileDownloadUtil.java
@RequestMapping(value = "/static/**", method = RequestMethod.GET) public void getFile(HttpServletResponse response, HttpServletRequest request) { try {//from ww w .j ava2 s . co m String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE); PathMatchingResourcePatternResolver res = new PathMatchingResourcePatternResolver(); Resource template = res.getResource(path); if (!template.exists()) { log.info("file n/a... " + path); return; } org.apache.commons.io.IOUtils.copy(template.getInputStream(), response.getOutputStream()); response.flushBuffer(); } catch (IOException ex) { log.info("Error writing file to output stream", ex); } }
From source file:com.jaxio.celerio.Brand.java
public Brand() { brandingPath = System.getProperty("user.home") + "/.celerio/branding.properties"; logoPath = System.getProperty("user.home") + "/.celerio/" + logoFilename; try {/*w w w .j a v a 2 s . co m*/ Properties p = new Properties(); File f = new File(brandingPath); if (f.exists()) { p.load(new FileInputStream(f)); companyName = p.getProperty("company_name", companyName); companyUrl = p.getProperty("company_url", companyUrl); footer = p.getProperty("footer", footer); rootPackage = p.getProperty("root_package", rootPackage); } else { p.setProperty("root_package", rootPackage); p.setProperty("company_name", companyName); p.setProperty("company_url", companyUrl); p.setProperty("footer", footer); if (!f.getParentFile().exists()) { f.getParentFile().mkdirs(); } p.store(new FileOutputStream(f), "CELERIO BRANDING"); } // copy logo if not present File logo = new File(logoPath); if (!logo.exists()) { PathMatchingResourcePatternResolver o = new PathMatchingResourcePatternResolver(); Resource defaultBrandLogo = o.getResource("classpath:/brand-logo.png"); new FileOutputStream(logo).write(IOUtils.toByteArray(defaultBrandLogo.getInputStream())); } } catch (Exception e) { throw new RuntimeException(e); } }