All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mayabot.nlp.resources.ClasspathNlpResourceFactory Maven / Gradle / Ivy

There is a newer version: 4.0.0
Show newest version
package com.mayabot.nlp.resources;

import java.net.URL;
import java.nio.charset.Charset;

/**
 * 从Claspath下面的路径下加载资源
 *
 * @author jimichan
 */
public class ClasspathNlpResourceFactory implements NlpResourceFactory {

    private ClassLoader classLoader;

    public ClasspathNlpResourceFactory(ClassLoader classLoader) {
        this.classLoader = classLoader;
    }

    @Override
    public NlpResource load(String resourceName, Charset charset) {

        if (resourceName.startsWith("/")) {
            resourceName = resourceName.substring(1);
        }
        String path = resourceName;

        URL resource = classLoader.getResource(path);

        if (resource != null) {
            return new URLNlpResource(resource, charset);
        }

        return null;
    }
}






© 2015 - 2024 Weber Informatics LLC | Privacy Policy