<commit_before>/**
 * Model operations DSL
 */
package common

/**
 * @author ShiZhan
 * Model extended operation
 * 1. load:  use file input stream API for better compatibility
 *           load with base
 * 2. join:  combine all models in Seq
 *           combine all models in Seq to base model
 * 3. load:  load model from given file name list
 *           load model from given file name list with absolute base URI
 * 4. write: encapsulate API for model writing in given format
 *           with given file name or instance as "UTF-8"
 */
object ModelEx {
  import scala.collection.JavaConversions._
  import java.io.{ File, FileOutputStream }
  import com.hp.hpl.jena.rdf.model.{ ModelFactory, Model }
  import com.hp.hpl.jena.vocabulary.{ DC_11 => DC, OWL, RDF }
  import com.hp.hpl.jena.datatypes.xsd.XSDDatatype._
  import com.hp.hpl.jena.util.FileManager
  import FileEx.FileOps
  import helper.{ Version, DateTime }

  def load(fileName: String) = {
    val m = ModelFactory.createDefaultModel
    try {
      val is = FileManager.get.open(fileName)
      m.read(is, "")
    } catch {
      case e: Exception => println(e); m
    }
  }

  def load(fileName: String, base: String) = {
    val m = ModelFactory.createDefaultModel
    try {
      val is = FileManager.get.open(fileName)
      m.read(is, base)
    } catch {
      case e: Exception => println(e); m
    }
  }

  implicit class ModelFileOps(fileNames: Seq[String]) {
    def asModels = fileNames map load
    def asModels(base: String) = fileNames map { load(_, base) }
  }

  implicit class ModelOps(m: Model) extends helper.Logging {
    def getImports = m.listStatements(null, OWL.imports, null)

    def rebase = {
      val bases = m.listSubjectsWithProperty(RDF.`type`, OWL.Ontology)
      for (b <- bases) m.remove(m.listStatements(b, null, null))
      m.createResource(URI.fromHost, OWL.Ontology)
        .addProperty(DC.date, DateTime.get, XSDdateTime)
        .addProperty(OWL.versionInfo, Version.get, XSDstring)
      m
    }<commit_msg>adjust log information in ModelEx load<commit_after>/**
 * Model operations DSL
 */
package common

/**
 * @author ShiZhan
 * Model extended operation
 * 1. load:  use file input stream API for better compatibility
 *           load with base
 * 2. join:  combine all models in Seq
 *           combine all models in Seq to base model
 * 3. load:  load model from given file name list
 *           load model from given file name list with absolute base URI
 * 4. write: encapsulate API for model writing in given format
 *           with given file name or instance as "UTF-8"
 */
object ModelEx extends helper.Logging {
  import scala.collection.JavaConversions._
  import java.io.{ File, FileOutputStream }
  import com.hp.hpl.jena.rdf.model.{ ModelFactory, Model }
  import com.hp.hpl.jena.vocabulary.{ DC_11 => DC, OWL, RDF }
  import com.hp.hpl.jena.datatypes.xsd.XSDDatatype._
  import com.hp.hpl.jena.util.FileManager
  import FileEx.FileOps
  import helper.{ Version, DateTime }

  def load(fileName: String) = {
    val m = ModelFactory.createDefaultModel
    try {
      val is = FileManager.get.open(fileName)
      m.read(is, "")
    } catch {
      case e: Exception => logger.error(fileName + ": " + e.toString); m
    }
  }

  def load(fileName: String, base: String) = {
    val m = ModelFactory.createDefaultModel
    try {
      val is = FileManager.get.open(fileName)
      m.read(is, base)
    } catch {
      case e: Exception => logger.error(fileName + ": " + e.toString); m
    }
  }

  implicit class ModelFileOps(fileNames: Seq[String]) {
    def asModels = fileNames map load
    def asModels(base: String) = fileNames map { load(_, base) }
  }

  implicit class ModelOps(m: Model) {
    def getImports = m.listStatements(null, OWL.imports, null)

    def rebase = {
      val bases = m.listSubjectsWithProperty(RDF.`type`, OWL.Ontology)
      for (b <- bases) m.remove(m.listStatements(b, null, null))
      m.createResource(URI.fromHost, OWL.Ontology)
        .addProperty(DC.date, DateTime.get, XSDdateTime)
        .addProperty(OWL.versionInfo, Version.get, XSDstring)
      m
    }
{'fraction_non_alphanumeric': 0.1063572637176698, 'fraction_numerical': 0.00338409475465313, 'mean_word_length': 2.845724907063197, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 9, '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': '7641658', 'n_tokens_mistral': 1343, 'n_tokens_neox': 1333, 'n_words': 387}