use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project nd4j by deeplearning4j.
the class TFGraphTestAllHelper method readVars.
protected static Map<String, INDArray> readVars(String modelName, String base_dir, String pattern) throws IOException {
Map<String, INDArray> varMap = new HashMap<>();
String modelDir = base_dir + "/" + modelName;
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(new ClassPathResource(modelDir).getClassLoader());
Resource[] resources = resolver.getResources("classpath*:" + modelDir + "/" + pattern + ".shape");
val dtype = Nd4j.dataType();
for (int i = 0; i < resources.length; i++) {
String fileName = resources[i].getFilename();
String varPath = modelDir + "/" + fileName;
String[] varNameArr = fileName.split("\\.");
String varName = String.join(".", Arrays.copyOfRange(varNameArr, 0, varNameArr.length - 2));
int[] varShape = Nd4j.readNumpy(new ClassPathResource(varPath).getInputStream(), ",").data().asInt();
try {
float[] varContents = Nd4j.readNumpy(new ClassPathResource(varPath.replace(".shape", ".csv")).getInputStream(), ",").data().asFloat();
INDArray varValue;
if (varShape.length == 1) {
if (varShape[0] == 0) {
varValue = Nd4j.trueScalar(varContents[0]);
} else {
varValue = Nd4j.trueVector(varContents);
}
} else {
varValue = Nd4j.create(varContents, varShape);
}
// varValue = Nd4j.readNumpy(new ClassPathResource(varPath.replace(".shape", ".csv")).getInputStream(), ",").reshape(varShape);
if (varName.contains("____")) {
// these are intermediate node outputs
varMap.put(varName.replaceAll("____", "/"), varValue);
} else {
varMap.put(varName, varValue);
}
} catch (NumberFormatException e) {
// FIXME: we can't parse boolean arrays right now :(
continue;
}
}
return varMap;
}
use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project nd4j by deeplearning4j.
the class TFGraphTestAllHelper method modelDirNames.
private static String[] modelDirNames(String base_dir, ExecuteWith executeWith) throws IOException {
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(new ClassPathResource(base_dir).getClassLoader());
Resource[] resources = resolver.getResources("classpath*:" + base_dir + "/**/frozen_model.pb");
String[] exampleNames = new String[resources.length];
for (int i = 0; i < resources.length; i++) {
String nestedName = resources[i].getURL().toString().split(base_dir + "/")[1];
exampleNames[i] = nestedName.replaceAll(Pattern.quote(executeWith.getDefaultBaseDir()), "").replaceAll("/frozen_model.pb", "");
}
return exampleNames;
}
use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project service-proxy by membrane.
the class ClassFinder method find.
public static List<Class<?>> find(ClassLoader loader, String scannedPackage) throws IOException, ClassNotFoundException {
String scannedPath = scannedPackage.replace(PKG_SEPARATOR, DIR_SEPARATOR);
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(loader);
Resource[] resources = resolver.getResources("classpath:" + scannedPath + "/*");
List<Class<?>> classes = new ArrayList<Class<?>>();
for (Resource resource : resources) {
String filename = resource.getFilename();
Class clazz = getClasses(resolver, scannedPackage, filename);
if (clazz != null)
classes.add(clazz);
}
return classes;
}
use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project openmrs-core by openmrs.
the class MutableResourceBundleMessageSource method findPropertiesFiles.
/**
* Searches the filesystem for message properties files. ABKTODO: consider caching this, rather
* than searching every time
*
* @return an array of property file names
*/
private Resource[] findPropertiesFiles() {
Set<Resource> resourceSet = new HashSet<>();
try {
String pattern = "classpath*:messages*.properties";
ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver(OpenmrsClassLoader.getInstance());
Resource[] propertiesFiles = resourceResolver.getResources(pattern);
Collections.addAll(resourceSet, propertiesFiles);
for (ModuleClassLoader moduleClassLoader : ModuleFactory.getModuleClassLoaders()) {
resourceResolver = new PathMatchingResourcePatternResolver(moduleClassLoader);
propertiesFiles = resourceResolver.getResources(pattern);
Collections.addAll(resourceSet, propertiesFiles);
}
} catch (IOException e) {
log.error("Error generated", e);
}
if (log.isWarnEnabled() && (resourceSet.isEmpty())) {
log.warn("No properties files found.");
}
return resourceSet.toArray(new Resource[resourceSet.size()]);
}
use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project spring-boot-examples by ityouknow.
the class DataSource2Config method testSqlSessionFactory.
@Bean(name = "test2SqlSessionFactory")
public SqlSessionFactory testSqlSessionFactory(@Qualifier("test2DataSource") DataSource dataSource) throws Exception {
SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
bean.setDataSource(dataSource);
bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mybatis/mapper/test2/*.xml"));
return bean.getObject();
}
Aggregations