Search in sources :

Example 86 with PathMatchingResourcePatternResolver

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;
}
Also used : lombok.val(lombok.val) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) Resource(org.springframework.core.io.Resource) ClassPathResource(org.nd4j.linalg.io.ClassPathResource) ClassPathResource(org.nd4j.linalg.io.ClassPathResource) INDArray(org.nd4j.linalg.api.ndarray.INDArray) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver)

Example 87 with PathMatchingResourcePatternResolver

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;
}
Also used : PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) Resource(org.springframework.core.io.Resource) ClassPathResource(org.nd4j.linalg.io.ClassPathResource) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ClassPathResource(org.nd4j.linalg.io.ClassPathResource)

Example 88 with PathMatchingResourcePatternResolver

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;
}
Also used : PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) Resource(org.springframework.core.io.Resource) ArrayList(java.util.ArrayList) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver)

Example 89 with PathMatchingResourcePatternResolver

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()]);
}
Also used : PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) ModuleClassLoader(org.openmrs.module.ModuleClassLoader) Resource(org.springframework.core.io.Resource) IOException(java.io.IOException) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) HashSet(java.util.HashSet)

Example 90 with PathMatchingResourcePatternResolver

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();
}
Also used : SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)135 Resource (org.springframework.core.io.Resource)86 ResourcePatternResolver (org.springframework.core.io.support.ResourcePatternResolver)53 IOException (java.io.IOException)37 Bean (org.springframework.context.annotation.Bean)30 SqlSessionFactoryBean (org.mybatis.spring.SqlSessionFactoryBean)29 ArrayList (java.util.ArrayList)16 Properties (java.util.Properties)14 ClassPathResource (org.springframework.core.io.ClassPathResource)14 File (java.io.File)13 InputStream (java.io.InputStream)12 Test (org.junit.jupiter.api.Test)12 JndiDataSourceLookup (org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup)11 PageHelper (com.github.pagehelper.PageHelper)10 PersistenceUnitInfo (jakarta.persistence.spi.PersistenceUnitInfo)10 Primary (org.springframework.context.annotation.Primary)9 CachingMetadataReaderFactory (org.springframework.core.type.classreading.CachingMetadataReaderFactory)9 MetadataReader (org.springframework.core.type.classreading.MetadataReader)9 MetadataReaderFactory (org.springframework.core.type.classreading.MetadataReaderFactory)7 URL (java.net.URL)6