<commit_before>package latis.reader.tsml.ml

import java.io.File
import java.io.FileNotFoundException
import java.net.URL

import latis.util.LatisProperties

/**
 * Provides access to a tsml from a url, path, or name. 
 */
object TsmlResolver {
  
  def fromUrl(url: URL) = Tsml(url)
    
  def fromPath(path: String) = {
    val url = if (path.contains(":")) path //already absolute with a scheme
    else if (path.startsWith(File.separator)) "file:" + path //absolute file path
    else getClass.getResource("/"+path) match { //try in the classpath (e.g. "resources")
      case url: URL => url.toString
      case null => {
        //Try looking in the working directory.
        //Make sure it exists, otherwise this would become a catch-all
        val file = scala.util.Properties.userDir + File.separator + path
        if (new File(file).exists) "file:" + file  //TODO: use java7 Files
        else null
      }
    }
    
    if (url != null) fromUrl(new URL(url))
    else throw new FileNotFoundException(s"Could not resolve path: '$path'.")
  }

  def fromName(name: String) = {
    val path = LatisProperties.getOrElse("dataset.dir", "datasets") + 
               File.separator + name + ".tsml"
    fromPath(path)
  }

}<commit_msg>Add return types for clarity<commit_after>package latis.reader.tsml.ml

import java.io.File
import java.io.FileNotFoundException
import java.net.URL

import latis.util.LatisProperties

/**
 * Provides access to a tsml from a url, path, or name. 
 */
object TsmlResolver {
  
  def fromUrl(url: URL): Tsml = Tsml(url)
    
  def fromPath(path: String): Tsml = {
    val url = if (path.contains(":")) path //already absolute with a scheme
    else if (path.startsWith(File.separator)) "file:" + path //absolute file path
    else getClass.getResource("/"+path) match { //try in the classpath (e.g. "resources")
      case url: URL => url.toString
      case null => {
        //Try looking in the working directory.
        //Make sure it exists, otherwise this would become a catch-all
        val file = scala.util.Properties.userDir + File.separator + path
        if (new File(file).exists) "file:" + file  //TODO: use java7 Files
        else null
      }
    }
    
    if (url != null) fromUrl(new URL(url))
    else throw new FileNotFoundException(s"Could not resolve path: '$path'.")
  }

  def fromName(name: String): Tsml = {
    val path = LatisProperties.getOrElse("dataset.dir", "datasets") + 
               File.separator + name + ".tsml"
    fromPath(path)
  }

}
{'fraction_non_alphanumeric': 0.12247324613555291, 'fraction_numerical': 0.0007927070947284979, 'mean_word_length': 2.7671641791044777, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5559493', 'n_tokens_mistral': 791, 'n_tokens_neox': 777, 'n_words': 245}