<commit_before>//
//  AppSetting.swift
//  tabijiman
//
//  Copyright (c) 2016 FUKUI Association of information & system industry
//
//  Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
//
//  The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
//
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.

import Foundation

// tabijiman アプリ View共通設定をまとめるクラス
// 方向性として static let を利用した クラス変数 としてまとめていく
final class AppSetting {
    static var startUp_flag: Bool? = false

    static let shareTag = "#tabijiman"  // シェア時に追加するハッシュタグ
    
    /// debug用フラグ
    /// false - ファイルの書き込みディレクトリが Library  に
    /// true  - ファイルの書き込みディレクトリが Document に
    static let debug: Bool = false
    static let documentPath =
    debug ? NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0]
        : NSSearchPathForDirectoriesInDomains(.LibraryDirectory, .UserDomainMask, true)[0]
    static let imagesPath = documentPath + "/images/"
    
    // Db file Path
    static let placeDataBase = documentPath + "/place.sqlite3"
    static let frameDataBase = documentPath + "/frame.sqlite3"
    static let initDataBase = documentPath + "/init.sqlite3"
    static let getFrameDataBase = documentPath + "/getFrame.sqlite3"

    
    // lang
    static let preferredLanguage: Array<String> = {
        let languages = NSLocale.preferredLanguages()  // like "ja-JP", "en", "en-JP", "ja-US", "zh-Hans" ...
        let firstLang = (languages.first! as String).characters.split("-").map{ String($0) }  // like Optional(["ja", "JP"])
        return firstLang
    }()

    // SPARQL クエリで使う言語タグ用
    static var langSparql: String {
        get {
            let lang = preferredLanguage.first!
            let langKeywords = preferredLanguage
            let separeter = "-"

//            print(langKeywords)
            
            switch lang {
            case "ja":
                return lang  // ja  (not ja-JP OR ja-US)
            case "ko":
                return lang  // ko
            case "zh":
                let second = langKeywords[1]
                if second == "HK" || second == "TW" {
                    return "zh-Hant"  // zh-HK OR zh-TW の場合は zh-Hant　をレスポンス
                } else {
                    return lang + separeter + langKeywords[1]  // zh-Hans (中国語簡体字) OR zh-Hant (中国語繁体字)
                }
            case "pt":
                return lang  // pt  (not pt-PT)
            default:
                return "en"  // その他の言語はすべて
            }
        }
    }

    // アプリ画面UI用
    static var langUi: String {
        get {
            let lang = preferredLanguage.first!  // only need "ja" or "en" or others
            
            switch lang {
            case "ja":
                return lang
            default:
                return "en"  // ja 以外はすべて
            }
        }
    }
    
    // SPARQL
    static let SPARQL_endpoint = "http://sparql.odp.jig.jp/api/v1/sparql"
    static let SPARQL_get_param = "?output=json&query="
    static let minDescriptionString = 10  // 最低文字数を設定
    
    // 観光情報を取得　（言語タグなし、住所をOption[任意]として指定）
    static let SPARQL_query_place =
    "select ?s ?name ?cat ?lat ?lng ?add ?name ?desc ?img {"
        + "?s <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.org/jrrk#CivicPOI>;"
        + "<http://imi.ipa.go.jp/ns/core/rdf#種別> ?cat;"
        + "<http://www.w3.org/2003/01/geo/wgs84_pos#long> ?lng;"
        + "<http://www.w3.org/2003/01/geo/wgs84_pos#lat> ?lat;"
        + "<http://www.w3.org/2000/01/rdf-schema#label> ?name;"
        + "<http://imi.ipa.go.jp/ns/core/rdf#説明> ?desc;"
        + "<http://schema.org/image> ?img;"
        + "OPTIONAL {"
        +     "?s <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.org/jrrk#CivicPOI>;"
        +     "<http://purl.org/jrrk#address> ?add; }"
        + "}"

    // 観光情報を取得　（言語タグなし、住所なし、画像情報をOption[任意]として指定）
    static let SPARQL_query_place_imgOption =
    "select ?s ?name ?cat ?lat ?lng ?add ?name ?desc ?img {"
        + "?s <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.org/jrrk#CivicPOI>;"
        + "<http://imi.ipa.go.jp/ns/core/rdf#種別> ?cat;"
        + "<http://www.w3.org/2003/01/geo/wgs84_pos#long> ?lng;"
        + "<http://www.w3.org/2003/01/geo/wgs84_pos#lat> ?lat;"
        + "<http://www.w3.org/2000/01/rdf-schema#label> ?name;"
        + "<http://imi.ipa.go.jp/ns/core/rdf#説明> ?desc;"
        + "OPTIONAL {"
        +     "?s <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.org/jrrk#CivicPOI>;"
        +     "<http://schema.org/image> ?img; }"
        + "}"
    
    // カオハメフレームを取得　（言語タグ でフィルタあり、Prefix表記）
    static let SPARQL_prefix =
    "prefix geo:   <http://www.w3.org/2003/01/geo/wgs84_pos#>"
        + "prefix odp:   <http://odp.jig.jp/odp/1.0#>"
        + "prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#>"
        + "prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#>"
        + "prefix schema: <http://schema.org/>"
    
    static let SPARQL_query_frame = SPARQL_prefix
    + "select ?s ?name ?desc ?img ?scope ?center ?lat ?lng ?rads ?rad ?unit {"
        + "?s rdf:type odp:ComicForeground  ."
        + "?s rdfs:label ?name . FILTER ( lang(?name) = \"".stringByAppendingString(langSparql) + "\" )"
        + "?s schema:description ?desc . FILTER ( lang(?desc) = \"".stringByAppendingString(langSparql) + "\" )"
        + "?s schema:image ?img ."
        + "?s odp:scope ?scope ."
        + "?scope odp:midpoint ?center ."
        + "?center geo:lat ?lat ."
        + "?center geo:long ?lng ."
        + "?scope odp:radius ?rads ."
        + "?rads rdf:value ?rad ."
        + "?rads odp:unit ?unit . }"

<commit_msg>FIX : 観光情報取得クエリに言語タグの指定を追加。 odp側の多言語情報アップロードによる大量情報取得問題への対応。<commit_after>//
//  AppSetting.swift
//  tabijiman
//
//  Copyright (c) 2016 FUKUI Association of information & system industry
//
//  Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
//
//  The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
//
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.

import Foundation

// tabijiman アプリ View共通設定をまとめるクラス
// 方向性として static let を利用した クラス変数 としてまとめていく
final class AppSetting {
    static var startUp_flag: Bool? = false

    static let shareTag = "#tabijiman"  // シェア時に追加するハッシュタグ
    
    /// debug用フラグ
    /// false - ファイルの書き込みディレクトリが Library  に
    /// true  - ファイルの書き込みディレクトリが Document に
    static let debug: Bool = false
    static let documentPath =
    debug ? NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0]
        : NSSearchPathForDirectoriesInDomains(.LibraryDirectory, .UserDomainMask, true)[0]
    static let imagesPath = documentPath + "/images/"
    
    // Db file Path
    static let placeDataBase = documentPath + "/place.sqlite3"
    static let frameDataBase = documentPath + "/frame.sqlite3"
    static let initDataBase = documentPath + "/init.sqlite3"
    static let getFrameDataBase = documentPath + "/getFrame.sqlite3"

    
    // lang
    static let preferredLanguage: Array<String> = {
        let languages = NSLocale.preferredLanguages()  // like "ja-JP", "en", "en-JP", "ja-US", "zh-Hans" ...
        let firstLang = (languages.first! as String).characters.split("-").map{ String($0) }  // like Optional(["ja", "JP"])
        return firstLang
    }()

    // SPARQL クエリで使う言語タグ用
    static var langSparql: String {
        get {
            let lang = preferredLanguage.first!
            let langKeywords = preferredLanguage
            let separeter = "-"

//            print(langKeywords)
            
            switch lang {
            case "ja":
                return lang  // ja  (not ja-JP OR ja-US)
            case "ko":
                return lang  // ko
            case "zh":
                let second = langKeywords[1]
                if second == "HK" || second == "TW" {
                    return "zh-Hant"  // zh-HK OR zh-TW の場合は zh-Hant　をレスポンス
                } else {
                    return lang + separeter + langKeywords[1]  // zh-Hans (中国語簡体字) OR zh-Hant (中国語繁体字)
                }
            case "pt":
                return lang  // pt  (not pt-PT)
            default:
                return "en"  // その他の言語はすべて
            }
        }
    }

    // アプリ画面UI用
    static var langUi: String {
        get {
            let lang = preferredLanguage.first!  // only need "ja" or "en" or others
            
            switch lang {
            case "ja":
                return lang
            default:
                return "en"  // ja 以外はすべて
            }
        }
    }
    
    // SPARQL
    static let SPARQL_endpoint = "http://sparql.odp.jig.jp/api/v1/sparql"
    static let SPARQL_get_param = "?output=json&query="
    static let minDescriptionString = 10  // 最低文字数を設定
    
    // 観光情報を取得　（言語タグなし、住所をOption[任意]として指定。';' 記法で主語省略）
    static let SPARQL_query_place =
    "select ?s ?name ?cat ?lat ?lng ?add ?name ?desc ?img {"
        + "?s <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.org/jrrk#CivicPOI>;"
        + "<http://imi.ipa.go.jp/ns/core/rdf#種別> ?cat;"
        + "<http://www.w3.org/2003/01/geo/wgs84_pos#long> ?lng;"
        + "<http://www.w3.org/2003/01/geo/wgs84_pos#lat> ?lat;"
        + "<http://www.w3.org/2000/01/rdf-schema#label> ?name;"
        + "<http://imi.ipa.go.jp/ns/core/rdf#説明> ?desc;"
        + "<http://schema.org/image> ?img;"
        + "OPTIONAL {"
        +     "?s <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.org/jrrk#CivicPOI>;"
        +     "<http://purl.org/jrrk#address> ?add; }"
        + "FILTER ( lang(?name) = \"" + String(langSparql) + "\" )"
        + "FILTER ( lang(?desc) = \"" + String(langSparql) + "\" )"
        + "}"

    // 観光情報を取得　（言語タグなし、住所なし、画像情報をOption[任意]として指定）
    static let SPARQL_query_place_imgOption =
    "select ?s ?name ?cat ?lat ?lng ?add ?name ?desc ?img {"
        + "?s <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.org/jrrk#CivicPOI>;"
        + "<http://imi.ipa.go.jp/ns/core/rdf#種別> ?cat;"
        + "<http://www.w3.org/2003/01/geo/wgs84_pos#long> ?lng;"
        + "<http://www.w3.org/2003/01/geo/wgs84_pos#lat> ?lat;"
        + "<http://www.w3.org/2000/01/rdf-schema#label> ?name;"
        + "<http://imi.ipa.go.jp/ns/core/rdf#説明> ?desc;"
        + "OPTIONAL {"
        +     "?s <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.org/jrrk#CivicPOI>;"
        +     "<http://schema.org/image> ?img; }"
        + "}"
    
    // カオハメフレームを取得　（言語タグ でフィルタあり、Prefix表記。 '.' 記法で主語必須）
    static let SPARQL_prefix =
    "prefix geo:   <http://www.w3.org/2003/01/geo/wgs84_pos#>"
        + "prefix odp:   <http://odp.jig.jp/odp/1.0#>"
        + "prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#>"
        + "prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#>"
        + "prefix schema: <http://schema.org/>"
    
    static let SPARQL_query_frame = SPARQL_prefix
    + "select ?s ?name ?desc ?img ?scope ?center ?lat ?lng ?rads ?rad ?unit {"
        + "?s rdf:type odp:ComicForeground  ."
        + "?s rdfs:label ?name . FILTER ( lang(?name) = \"".stringByAppendingString(langSparql) + "\" )"
        + "?s schema:description ?desc . FILTER ( lang(?desc) = \"".stringByAppendingString(langSparql) + "\" )"
        + "?s schema:image ?img ."
        + "?s odp:scope ?scope ."
        + "?scope odp:midpoint ?center ."
        + "?center geo:lat ?lat ."
        + "?center geo:long ?lng ."
        + "?scope odp:radius ?rads ."
        + "?rads rdf:value ?rad ."
        + "?rads odp:unit ?unit . }"


{'fraction_non_alphanumeric': 0.14597390913180386, 'fraction_numerical': 0.019343229869545658, 'mean_word_length': 2.1534278959810873, 'pattern_counts': {'":': 10, '<': 57, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 26, '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': '3714098', 'n_tokens_mistral': 5133, 'n_tokens_neox': 4897, 'n_words': 1076}