<commit_before>/*
 * Copyright 2015-2017 <NAME> <<EMAIL>>
 *
 * This file is part of Jem.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package jem.scj

import jclp.io.extName
import jclp.log.Log
import jclp.log.LogLevel
import jclp.setting.MapSettings
import jem.Book
import jem.Build
import jem.epm.EpmManager
import jem.epm.MakerParam
import jem.epm.ParserParam
import mala.App
import mala.App.tr
import mala.AppVerbose
import mala.Plugin
import mala.cli.*
import org.apache.commons.cli.DefaultParser
import org.apache.commons.cli.HelpFormatter
import org.apache.commons.cli.Option
import org.apache.commons.cli.OptionGroup
import java.lang.System.getProperty
import java.time.LocalDate

fun main(args: Array<String>) {
    App.run(SCI, args)
}

object SCI : CDelegate(DefaultParser()) {
    private const val TAG = "SCI"

    override val name = "scj"

    override val version = Build.VERSION

    @Suppress("UNCHECKED_CAST")
    val inArguments
        get() = MapSettings(context["p"] as? MutableMap<String, Any>)

    @Suppress("UNCHECKED_CAST")
    val outArguments
        get() = MapSettings(context["m"] as? MutableMap<String, Any>)

    @Suppress("UNCHECKED_CAST")
    val outAttributes
        get() = context["a"] as? MutableMap<String, Any> ?: hashMapOf()

    @Suppress("UNCHECKED_CAST")
    val outExtensions
        get() = context["e"] as? MutableMap<String, Any> ?: hashMapOf()

    val outputFormat get() = context["t"]?.toString() ?: SCISettings.outputFormat

    val output get() = context["o"]?.toString() ?: "."

    override fun onStart() {
        restoreState(SCISettings)
        appOptions()
        jemOptions()
    }

    override fun onStop() {
        saveState(SCISettings)
    }

    fun processInputs(processor: InputProcessor): Int {
        Log.d(TAG) { "app context: $context" }
        Log.d(TAG) { "app inputs: $inputs" }
        if (inputs.isEmpty()) {
            App.error(tr("err.input.empty"))
            return -1
        }
        var code = 0
        for (input in inputs) {
            val format = context["f"]?.toString() ?: extName(input)
            code = if (checkInputFormat(format, input)) {
                minOf(code, if (processor.process(input, format)) 0 else -1)
            } else {
                -1
            }
        }
        return code
    }

    private fun appOptions() {
        newOption("h", "help").command {
            with(HelpFormatter()) {
                descPadding = 4<commit_msg>fix bug for settings of locale<commit_after>/*
 * Copyright 2015-2017 <NAME> <<EMAIL>>
 *
 * This file is part of Jem.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package jem.scj

import jclp.io.extName
import jclp.log.Log
import jclp.log.LogLevel
import jclp.setting.MapSettings
import jem.Book
import jem.Build
import jem.epm.EpmManager
import jem.epm.MakerParam
import jem.epm.ParserParam
import mala.App
import mala.App.tr
import mala.AppVerbose
import mala.Plugin
import mala.cli.*
import org.apache.commons.cli.DefaultParser
import org.apache.commons.cli.HelpFormatter
import org.apache.commons.cli.Option
import org.apache.commons.cli.OptionGroup
import java.lang.System.getProperty
import java.time.LocalDate

fun main(args: Array<String>) {
    App.run(SCI, args)
}

object SCI : CDelegate(DefaultParser()) {
    private const val TAG = "SCI"

    override val name = "scj"

    override val version = Build.VERSION

    @Suppress("UNCHECKED_CAST")
    val inArguments
        get() = MapSettings(context["p"] as? MutableMap<String, Any>)

    @Suppress("UNCHECKED_CAST")
    val outArguments
        get() = MapSettings(context["m"] as? MutableMap<String, Any>)

    @Suppress("UNCHECKED_CAST")
    val outAttributes
        get() = context["a"] as? MutableMap<String, Any> ?: hashMapOf()

    @Suppress("UNCHECKED_CAST")
    val outExtensions
        get() = context["e"] as? MutableMap<String, Any> ?: hashMapOf()

    val outputFormat get() = context["t"]?.toString() ?: SCISettings.outputFormat

    val output get() = context["o"]?.toString() ?: "."

    override fun onStart() {
        restoreState(SCISettings)
        appOptions()
        jemOptions()
    }

    override fun onStop() {
    }

    fun processInputs(processor: InputProcessor): Int {
        Log.d(TAG) { "app context: $context" }
        Log.d(TAG) { "app inputs: $inputs" }
        if (inputs.isEmpty()) {
            App.error(tr("err.input.empty"))
            return -1
        }
        var code = 0
        for (input in inputs) {
            val format = context["f"]?.toString() ?: extName(input)
            code = if (checkInputFormat(format, input)) {
                minOf(code, if (processor.process(input, format)) 0 else -1)
            } else {
                -1
            }
        }
        return code
    }

    private fun appOptions() {
        newOption("h", "help").command {
            with(HelpFormatter()) {
                descPadding = 4
{'fraction_non_alphanumeric': 0.1153588195841717, 'fraction_numerical': 0.006036217303822937, 'mean_word_length': 2.8212684176809737, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4872736', 'n_tokens_mistral': 1815, 'n_tokens_neox': 1768, 'n_words': 515}