<commit_before>package leo.modules

import leo.datastructures.{Signature, Role, Term}
import leo.datastructures.tptp.Commons
import leo.modules.parsers.{InputProcessing, TPTP}
import leo.modules.output.{SZS_InputError, SZS_SyntaxError}

import scala.io.Source
import java.nio.file.{Files, Path, Paths}

/**
 * This facade object publishes some convenience methods
 * for parsing related utility including parsing of strings and problem files,
 *
 * @author <NAME> <<EMAIL>>
 * @since 29.04.2015
 */
object Parsing {

  /**
    * For parsing objects under TPTP Home
    */
  lazy val tptpHome : Path = {
    try {
      canonicalPath(System.getenv("TPTP"))
    } catch {
      case _: Exception => canonicalPath(".")
    }
  }

//  /**
//   * Reads the file located at `file` and parses it recursively using the `TPTP` parser.
//   * Note that the return value is a sequence of [[Commons.AnnotatedFormula]] since
//   * all includes are automatically parsed exhaustively.
//   * If `file` is a relative path, it is assumed to be equivalent to the path
//   * [[Utility.wd]]/file where `Utility.wd` is the working directory `user.dir`.
//   *
//   * @param file  The absolute or relative path to the problem file.
//   * @param assumeRead Implicitly assume that the problem files in this parameter
//   *                   have already been read. Hence, recursive parsing will skip this
//   *                   includes.
//   * @return The sequence of annotated TPTP formulae.
//   */
//  def readProblem(file: String, assumeRead: Set[Path] = Set()): Seq[Commons.AnnotatedFormula] = {
//    val canonicalFile = canonicalPath(file)
//    if (!assumeRead.contains(canonicalFile)) {
//      val p = shallowReadProblem(file)
//      val includes = p.getIncludes
//
//      val pIncludes = includes.map{case (inc, _) => readProblem(canonicalFile.getParent.resolve(inc).toString,assumeRead + canonicalFile)}
//      pIncludes.flatten ++ p.getFormulae
//    } else {
//      Seq()
//    }
//  }


    // Functions that go from file/string to unprocessed internal TPTP-syntax
    // "String -> TPTP"
    /**
      * Reads the file located at `file` and parses it recursively using the `TPTP` parser.
      * Note that the return value is a sequence of [[Commons.AnnotatedFormula]] since
      * all includes are automatically parsed exhaustively.
      * If `file` is a relative path, it is assumed to be equivalent to the path
      * `user.dir`/file.
      *
      * @param file  The absolute or relative path to the problem file.
      * @param assumeRead Implicitly assume that the problem files in this parameter
      *                   have already been read. Hence, recursive parsing will skip this
      *                   includes.
      * @return The sequence of annotated TPTP formulae.
      */
    def readProblem(file: String, assumeRead: Set[Path] = Set()): Seq[Commons.AnnotatedFormula] = {
      val canonicalFile = canonicalPath(file)
      if (!assumeRead.contains(canonicalFile)) {
        val p = try {shallowReadProblem(file)} catch {case _ : Exception =>
          try {
            val alt = tptpHome.resolve(file)
            shallowReadProblem(alt.toString)
          } catch {case _ : Exception => throw new SZSException(SZS_InputError, s"The file $file does not exist.")}
        }
        val includes = p.getIncludes

        // TODO Assume Read should be a shared between the calls (Dependencies between siblings not detected)

        val pIncludes = includes.map{case (inc, _) =>
          try {
            val next = canonicalFile.getParent.resolve(inc)
            readProblem(next.toString, assumeRead + canonicalFile)
          } catch {
            case _ : Exception =>
              try {
                val tnext = tptpHome.resolve(inc)
                readProblem(tnext.toString, assumeRead + canonicalFile)
              } catch {
                case _ : Exception => throw new SZSException(SZS_InputError, s"The file $inc does not exist.")
              }
          }
        }
        pIncludes.flatten ++ p.getFormulae
      } else {
        Seq()
      }<commit_msg>corrected error message for parsing<commit_after>package leo.modules

import leo.datastructures.{Signature, Role, Term}
import leo.datastructures.tptp.Commons
import leo.modules.parsers.{InputProcessing, TPTP}
import leo.modules.output.{SZS_InputError, SZS_SyntaxError}

import scala.io.Source
import java.nio.file.{Files, Path, Paths}

/**
 * This facade object publishes some convenience methods
 * for parsing related utility including parsing of strings and problem files,
 *
 * @author <NAME> <<EMAIL>>
 * @since 29.04.2015
 */
object Parsing {

  /**
    * For parsing objects under TPTP Home
    */
  lazy val tptpHome : Path = {
    try {
      canonicalPath(System.getenv("TPTP"))
    } catch {
      case _: Exception => canonicalPath(".")
    }
  }

//  /**
//   * Reads the file located at `file` and parses it recursively using the `TPTP` parser.
//   * Note that the return value is a sequence of [[Commons.AnnotatedFormula]] since
//   * all includes are automatically parsed exhaustively.
//   * If `file` is a relative path, it is assumed to be equivalent to the path
//   * [[Utility.wd]]/file where `Utility.wd` is the working directory `user.dir`.
//   *
//   * @param file  The absolute or relative path to the problem file.
//   * @param assumeRead Implicitly assume that the problem files in this parameter
//   *                   have already been read. Hence, recursive parsing will skip this
//   *                   includes.
//   * @return The sequence of annotated TPTP formulae.
//   */
//  def readProblem(file: String, assumeRead: Set[Path] = Set()): Seq[Commons.AnnotatedFormula] = {
//    val canonicalFile = canonicalPath(file)
//    if (!assumeRead.contains(canonicalFile)) {
//      val p = shallowReadProblem(file)
//      val includes = p.getIncludes
//
//      val pIncludes = includes.map{case (inc, _) => readProblem(canonicalFile.getParent.resolve(inc).toString,assumeRead + canonicalFile)}
//      pIncludes.flatten ++ p.getFormulae
//    } else {
//      Seq()
//    }
//  }


    // Functions that go from file/string to unprocessed internal TPTP-syntax
    // "String -> TPTP"
    /**
      * Reads the file located at `file` and parses it recursively using the `TPTP` parser.
      * Note that the return value is a sequence of [[Commons.AnnotatedFormula]] since
      * all includes are automatically parsed exhaustively.
      * If `file` is a relative path, it is assumed to be equivalent to the path
      * `user.dir`/file.
      *
      * @param file  The absolute or relative path to the problem file.
      * @param assumeRead Implicitly assume that the problem files in this parameter
      *                   have already been read. Hence, recursive parsing will skip this
      *                   includes.
      * @return The sequence of annotated TPTP formulae.
      */
    def readProblem(file: String, assumeRead: Set[Path] = Set()): Seq[Commons.AnnotatedFormula] = {
      val canonicalFile = canonicalPath(file)
      if (!assumeRead.contains(canonicalFile)) {
        val p = try {shallowReadProblem(file)} catch {case _ : Exception =>
          try {
            val alt = tptpHome.resolve(file)
            shallowReadProblem(alt.toString)
          } catch {case e : Exception => throw new SZSException(SZS_InputError, s"${e.toString}")}
        }
        val includes = p.getIncludes

        // TODO Assume Read should be a shared between the calls (Dependencies between siblings not detected)

        val pIncludes = includes.map{case (inc, _) =>
          try {
            val next = canonicalFile.getParent.resolve(inc)
            readProblem(next.toString, assumeRead + canonicalFile)
          } catch {
            case _ : Exception =>
              try {
                val tnext = tptpHome.resolve(inc)
                readProblem(tnext.toString, assumeRead + canonicalFile)
              } catch {
                case _ : Exception => throw new SZSException(SZS_InputError, s"The file $inc does not exist.")
              }
          }
        }
        pIncludes.flatten ++ p.getFormulae
      } else {
        Seq()
      }
{'fraction_non_alphanumeric': 0.10212765957446808, 'fraction_numerical': 0.0019452887537993921, 'mean_word_length': 2.4076222038111017, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 25, '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': '7046151', 'n_tokens_mistral': 2419, 'n_tokens_neox': 2309, 'n_words': 744}