de.tudarmstadt.ukp.dkpro.core.api.resources.ResourceUtils.resolveLocation()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(10.6k)|赞(0)|评价(0)|浏览(118)

本文整理了Java中de.tudarmstadt.ukp.dkpro.core.api.resources.ResourceUtils.resolveLocation方法的一些代码示例,展示了ResourceUtils.resolveLocation的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ResourceUtils.resolveLocation方法的具体详情如下:
包路径:de.tudarmstadt.ukp.dkpro.core.api.resources.ResourceUtils
类名称:ResourceUtils
方法名:resolveLocation

ResourceUtils.resolveLocation介绍

[英]Resolve a location (which can be many things) to an URL. If the location starts with classpath: the location is interpreted as a classpath location. Otherwise it is tried as a URL, file and at last UIMA resource. If the location is treated as a classpath or file location, an URL is only returned if the target exists. If it is an URL, it is possible that the target may not actually exist.
[中]将一个位置(可以是很多东西)解析为URL。如果位置以类路径开始:该位置将被解释为类路径位置。否则,它将尝试作为URL、文件,最后是UIMA资源。如果该位置被视为类路径或文件位置,则仅当目标存在时才会返回URL。如果它是一个URL,那么目标可能实际上并不存在。

代码示例

代码示例来源:origin: dkpro/dkpro-core

/**
 * Resolve a location (which can be many things) to an URL. If the location starts with
 * {@code classpath:} the location is interpreted as a classpath location. Otherwise it is tried
 * as a URL, file and at last UIMA resource. If the location is treated as a classpath or file
 * location, an URL is only returned if the target exists. If it is an URL, it is possible that
 * the target may not actually exist.
 *
 * @param aLocation
 *            a location (classpath, URL, file or UIMA resource location).
 * @return the resolved URL.
 * @throws IOException
 *             if the target could not be found.
 */
public static URL resolveLocation(String aLocation)
  throws IOException
{
  return resolveLocation(aLocation, null, null);
}

代码示例来源:origin: de.tudarmstadt.ukp.similarity.algorithms/de.tudarmstadt.ukp.similarity.algorithms.lexical-asl

public CharacterNGramMeasure(int n, String idfValuesFile)
  throws IOException
{
  this.n = n;
  
  URL resourceUrl = ResourceUtils.resolveLocation(idfValuesFile, this, null);
  
  idf = new HashMap<String, Double>();
  for (String line : FileUtils.readLines(new File(resourceUrl.getFile())))
  {
    String[] linesplit = line.split("\t");
    idf.put(linesplit[0], Double.parseDouble(linesplit[1]));
  }
}

代码示例来源:origin: dkpro/dkpro-similarity

public CharacterNGramMeasure(int n, String idfValuesFile)
  throws IOException
{
  this.n = n;
  
  URL resourceUrl = ResourceUtils.resolveLocation(idfValuesFile, this, null);
  
  idf = new HashMap<String, Double>();
  try (InputStream is = resourceUrl.openStream()) {
    for (String line : IOUtils.readLines(is, StandardCharsets.UTF_8))
    {
      String[] linesplit = line.split("\t");
      idf.put(linesplit[0], Double.parseDouble(linesplit[1]));
    }
  }
}

代码示例来源:origin: org.dkpro.similarity/dkpro-similarity-algorithms-lexical-asl

public CharacterNGramMeasure(int n, String idfValuesFile)
  throws IOException
{
  this.n = n;
  
  URL resourceUrl = ResourceUtils.resolveLocation(idfValuesFile, this, null);
  
  idf = new HashMap<String, Double>();
  try (InputStream is = resourceUrl.openStream()) {
    for (String line : IOUtils.readLines(is, StandardCharsets.UTF_8))
    {
      String[] linesplit = line.split("\t");
      idf.put(linesplit[0], Double.parseDouble(linesplit[1]));
    }
  }
}

代码示例来源:origin: org.dkpro.tc/dkpro-tc-api-features

public static Set<String> getStopwords(String inputFile, boolean toLowerCase) throws IOException
{
  Set<String> stopwords = new HashSet<String>();
  if (inputFile != null) {
    URL stopUrl = ResourceUtils.resolveLocation(inputFile, null);
    InputStream is = stopUrl.openStream();
    for (String stopword : IOUtils.readLines(is, "UTF-8")) {
      if (toLowerCase) {
        stopwords.add(stopword.toLowerCase());
      }
      else {
        stopwords.add(stopword);
      }
    }
  }
  return stopwords;
}

代码示例来源:origin: dkpro/dkpro-tc

public static Set<String> getStopwords(String inputFile, boolean toLowerCase) throws IOException
{
  Set<String> stopwords = new HashSet<String>();
  if (inputFile != null) {
    URL stopUrl = ResourceUtils.resolveLocation(inputFile, null);
    InputStream is = stopUrl.openStream();
    for (String stopword : IOUtils.readLines(is, "UTF-8")) {
      if (toLowerCase) {
        stopwords.add(stopword.toLowerCase());
      }
      else {
        stopwords.add(stopword);
      }
    }
  }
  return stopwords;
}

代码示例来源:origin: de.tudarmstadt.ukp.similarity.algorithms/de.tudarmstadt.ukp.similarity.algorithms.style-asl

private void init(String functionWordListLocation) throws IOException {
  functionWords = new ArrayList<String>();
  InputStream is = null;
  try {
    URL url = ResourceUtils.resolveLocation(functionWordListLocation, this, null);
    is = url.openStream();
    String content = IOUtils.toString(is, "UTF-8");
    for (String line : Arrays.asList(content.split("\n"))) {
      if (line.length() > 0) {
        functionWords.add(line);
      }
    }
  }
  finally{
    IOUtils.closeQuietly(is);
  }
}

代码示例来源:origin: de.tudarmstadt.ukp.similarity.algorithms/de.tudarmstadt.ukp.similarity.algorithms.structure-asl

public StopwordNGramContainmentMeasure(int n, String stopwordList)
  throws IOException
{
  this.n = n;

  stopwords = new ArrayList<String>();
  InputStream is = null;
  try {
    URL url = ResourceUtils.resolveLocation(stopwordList, this, null);
    is = url.openStream();
    String content = IOUtils.toString(is, "UTF-8");
    for (String line : Arrays.asList(content.split("\n"))) {
      if (line.length() > 0)
        stopwords.add(line);
    }
  }
  finally{
    IOUtils.closeQuietly(is);
  }
}

代码示例来源:origin: org.dkpro.similarity/dkpro-similarity-algorithms-structure-asl

public StopwordNGramContainmentMeasure(int n, String stopwordList)
  throws IOException
{
  this.n = n;

  stopwords = new ArrayList<String>();
  InputStream is = null;
  try {
    URL url = ResourceUtils.resolveLocation(stopwordList, this, null);
    is = url.openStream();
    String content = IOUtils.toString(is, "UTF-8");
    for (String line : Arrays.asList(content.split("\n"))) {
      if (line.length() > 0)
        stopwords.add(line);
    }
  }
  finally{
    IOUtils.closeQuietly(is);
  }
}

代码示例来源:origin: dkpro/dkpro-similarity

private void init(String functionWordListLocation) throws IOException {
  functionWords = new ArrayList<String>();
  InputStream is = null;
  try {
    URL url = ResourceUtils.resolveLocation(functionWordListLocation, this, null);
    is = url.openStream();
    String content = IOUtils.toString(is, "UTF-8");
    for (String line : Arrays.asList(content.split("\n"))) {
      if (line.length() > 0) {
        functionWords.add(line);
      }
    }
  }
  finally{
    IOUtils.closeQuietly(is);
  }
}

代码示例来源:origin: de.tudarmstadt.ukp.dkpro.core/de.tudarmstadt.ukp.dkpro.core.textnormalizer-asl

@Override
public void initialize(UimaContext aContext)
  throws ResourceInitializationException
{
  super.initialize(aContext);
  try {
    URL url = ResourceUtils.resolveLocation(modelLocation);
    try (InputStream is = url.openStream()) {
      dict = new HashSet<>(IOUtils.readLines(is ,modelEncoding));
    }
  }
  catch (IOException e) {
    throw new ResourceInitializationException(e);
  }
}

代码示例来源:origin: dkpro/dkpro-core

@Override
public boolean initialize(ResourceSpecifier aSpecifier,
    Map aAdditionalParams)
  throws ResourceInitializationException
{
  if (!super.initialize(aSpecifier, aAdditionalParams)) {
    return false;
  }
  try {
    URL ngramUrl = ResourceUtils.resolveLocation(ngramLocation, this, null);
    URL indexUrl = ResourceUtils.resolveLocation(indexLocation, this, null);
    finder = new Finder(new File(indexUrl.toURI()), new File(ngramUrl.toURI()));
  }
  catch (IOException e) {
    throw new ResourceInitializationException(e);
  }
  catch (URISyntaxException e) {
    throw new ResourceInitializationException(e);
  }
  return true;
}

代码示例来源:origin: de.tudarmstadt.ukp.dkpro.core/de.tudarmstadt.ukp.dkpro.core.dictionaryannotator-asl

@Override
public boolean initialize(ResourceSpecifier aSpecifier, Map aAdditionalParams)
  throws ResourceInitializationException
{
  if (!super.initialize(aSpecifier, aAdditionalParams)) {
    return false;
  }
  try {
    final URL uri = ResourceUtils.resolveLocation(resourcePath, this, null);
    readFileToMap(new BufferedReader(new InputStreamReader(uri.openStream())));
      }
  catch (IOException e) {
    throw new ResourceInitializationException(e);
  }
  return true;
}

代码示例来源:origin: dkpro/dkpro-core

@Override
public boolean initialize(ResourceSpecifier aSpecifier, Map aAdditionalParams)
  throws ResourceInitializationException
{
  if (!super.initialize(aSpecifier, aAdditionalParams)) {
    return false;
  }
  try {
    final URL uri = ResourceUtils.resolveLocation(resourcePath, this, null);
    readFileToMap(new BufferedReader(new InputStreamReader(uri.openStream())));
      }
  catch (IOException e) {
    throw new ResourceInitializationException(e);
  }
  return true;
}

代码示例来源:origin: de.tudarmstadt.ukp.dkpro.core/de.tudarmstadt.ukp.dkpro.core.textnormalizer-asl

@Override
public void initialize(UimaContext aContext)
  throws ResourceInitializationException
{
  super.initialize(aContext);
  try {
    mappings = readMappings(ResourceUtils.resolveLocation(modelLocation));
  }
  catch (IOException e) {
    throw new ResourceInitializationException(e);
  }
}

代码示例来源:origin: de.tudarmstadt.ukp.dkpro.core/de.tudarmstadt.ukp.dkpro.core.io.xml-asl

@Override
public void initialize(UimaContext aContext)
  throws ResourceInitializationException
{
  super.initialize(aContext);
  if (xslt != null) {
    TransformerFactory tf = TransformerFactory.newInstance();
    try {
      URL url = ResourceUtils.resolveLocation(xslt, this, getContext());
      transformer = tf.newTransformer(new StreamSource(url.openStream()));
    } catch (Exception e) {
      throw new ResourceInitializationException(e);
    }
  }
  cas2xml = new CasToInlineXml();
}

代码示例来源:origin: de.tudarmstadt.ukp.dkpro.wsd/de.tudarmstadt.ukp.dkpro.wsd.core

@Override
public void initialize(UimaContext context)
  throws ResourceInitializationException
{
  super.initialize(context);
  try {
    senseMap = WSDUtils.readMap(
        ResourceUtils.resolveLocation(fileName, this, context),
        keyColumn, String.class, valueColumn, String.class,
        delimiterRegex);
  }
  catch (Exception e) {
    throw new ResourceInitializationException(e);
  }
}

代码示例来源:origin: de.tudarmstadt.ukp.dkpro.core/de.tudarmstadt.ukp.dkpro.core.jazzy-asl

@Override
public void initialize(final UimaContext context)
  throws ResourceInitializationException
{
  super.initialize(context);
  InputStream is = null;
  try {
    URL url = ResourceUtils.resolveLocation(dictPath, this, context);
    this.getLogger().debug("Loading dictionary from " + url);
    is = url.openStream();
    dict = new SpellDictionaryHashMap(new InputStreamReader(is, dictEncoding));
  }
  catch (IOException e) {
    throw new ResourceInitializationException(e);
  }
  finally {
    closeQuietly(is);
  }
}

代码示例来源:origin: dkpro/dkpro-core

@Override
public void initialize(final UimaContext context)
  throws ResourceInitializationException
{
  super.initialize(context);
  InputStream is = null;
  try {
    URL url = ResourceUtils.resolveLocation(dictPath, this, context);
    this.getLogger().debug("Loading dictionary from " + url);
    is = url.openStream();
    dict = new SpellDictionaryHashMap(new InputStreamReader(is, dictEncoding));
  }
  catch (IOException e) {
    throw new ResourceInitializationException(e);
  }
  finally {
    closeQuietly(is);
  }
}

代码示例来源:origin: de.tudarmstadt.ukp.dkpro.wsd/de.tudarmstadt.ukp.dkpro.wsd.si.wordnet

@Override
public void initialize(UimaContext context)
  throws ResourceInitializationException
{
  super.initialize(context);
  if (indexSenseFile != null && sourceInventory != null) {
    throw new ResourceInitializationException(
        new AnnotatorConfigurationException(
            AnnotatorConfigurationException.MUTUALLY_EXCLUSIVE_PARAMS,
            new String[] { PARAM_INDEX_SENSE_FILE + ", "
                + SOURCE_SENSE_INVENTORY_RESOURCE }));
  }
  if (indexSenseFile != null) {
    try {
      senseMap = getSenseMap(ResourceUtils.resolveLocation(
          indexSenseFile, this, context));
    }
    catch (Exception e) {
      throw new ResourceInitializationException(e);
    }
  }
}

相关文章

微信公众号

最新文章

更多