Search Posts

Visits: 13

1. Arelleインストール

MacOSにArelleとXULEをインストールします。
GutHubからクArelleをローンしようとしたところ次のメッセージ。

~ $ git clone https://github.com/Arelle/Arelle.git

You have not agreed to the Xcode and Apple SDKs license. You must agree to the license below in order to use Xcode.
Press enter to display the license:

Xcode and Apple SDKs Agreement

PLEASE SCROLL DOWN AND READ ALL OF THE FOLLOWING TERMS AND CONDITIONS CAREFULLY BEFORE USING THE APPLE SOFTWARE OR APPLE SERVICES.  THIS IS A LEGAL AGREEMENT BETWEEN YOU AND APPLE.  IF YOU AGREE TO BE BOUND BY ALL OF THE TERMS AND CONDITIONS, CLICK THE “AGREE” BUTTON.  BY CLICKING “AGREE” OR BY DOWNLOADING, USING OR COPYING ANY PART OF THIS APPLE SOFTWARE OR USING ANY PART OF THE APPLE SERVICES, YOU ARE AGREEING ON YOUR OWN BEHALF AND/OR ON BEHALF OF YOUR COMPANY OR ORGANIZATION TO THE TERMS AND CONDITIONS STATED BELOW.  IF YOU DO NOT OR CANNOT AGREE TO THE TERMS OF THIS AGREEMENT, YOU CANNOT USE THIS APPLE SOFTWARE OR THE APPLE SERVICES.  DO NOT DOWNLOAD OR USE THIS APPLE SOFTWARE OR APPLE SERVICES IN THAT CASE.

”Xcode and Apple SDKs Agreement”に承認手続ぎ後、再度 git clone 実行。

Arelleは、python3.8以降が前提となっていて仮想環境の設定が必要でした。
ホームディレクトリに Arelleディレクトリを作成し、その下に環境を設定します。

Arelle $ pwd
/Users/pontsoleil/Arelle
Arelle $ python3 -m venv arelle-env
Arelle $ source arelle-env/bin/activate
(arelle-env) Arelle $ pip3 install -r requirements.txt
...
Successfully installed Cheroot-10.0.0 CherryPy-18.9.0 Matplotlib-3.8.2 NumPy-1.26.2 OpenPyXL-3.1.2 Pillow-10.2.0 PyCryptodome-3.20.0 PyMySQL-1.1.0 RDFLib-7.0.0 Tornado-6.4 aniso8601-9.0.1 annotated-types-0.6.0 asn1crypto-1.5.1 autocommand-2.2.2 certifi-2024.2.2 contourpy-1.2.0 cx-Oracle-8.3.0 cycler-0.12.1 et-xmlfile-1.1.0 fonttools-4.50.0 graphviz-0.20.2 holidays-0.44 inflect-7.0.0 isodate-0.6.1 jaraco.collections-5.0.0 jaraco.context-4.3.0 jaraco.functools-4.0.0 jaraco.text-3.12.0 kiwisolver-1.4.5 lxml-5.1.0 more-itertools-10.2.0 packaging-24.0 pg8000-1.30.5 portend-3.2.0 pycountry-23.12.11 pydantic-2.6.4 pydantic-core-2.16.3 pyodbc-5.1.0 pyparsing-3.1.2 python-dateutil-2.9.0.post0 pytz-2024.1 regex-2023.12.25 scramp-1.4.4 six-1.16.0 tempora-5.5.1 tinycss2-1.2.1 typing-extensions-4.10.0 webencodings-0.5.1 zc.lockfile-3.0.post1
WARNING: You are using pip version 21.2.4; however, version 24.0 is available.
You should consider upgrading via the '/Users/pontsoleil/Arelle/arelle-env/bin/python3 -m pip install --upgrade pip' command.

pipを更新しなさいというメッセージがあるので更新して、設定完了。

(arelle-env) Arelle $ /Users/pontsoleil/Arelle/arelle-env/bin/python3 -m pip install --upgrade pip
Requirement already satisfied: pip in ./arelle-env/lib/python3.10/site-packages (21.2.4)
Collecting pip
  Using cached pip-24.0-py3-none-any.whl (2.1 MB)
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 21.2.4
    Uninstalling pip-21.2.4:
      Successfully uninstalled pip-21.2.4
Successfully installed pip-24.0
(arelle-env) Arelle $

Arelleをコマンドライン実行できるか確認します。

(arelle-env) Arelle $ python arelleCmdLine.py --help
Usage: arelleCmdLine.py [options]

Options:
...
(arelle-env) Arelle $

確認できたので、XBRLインスタンス文書を検証できるか確認。

(arelle-env) Arelle $ python arelleCmdLine.py --file JISCinstance.xbrl --validate
[info] loaded in 3.57 secs at 2024-03-24T16:37:56 - JISCinstance.xbrl
[info] validated in 0.03 secs - JISCinstance.xbrl
(arelle-env) Arelle $

問題なく検証できました。

2. XULEプラグインの取得と設定

https://github.com/xbrlus/xule/tags/ に登録されているリリースの最新を選択します。

xule tags

xule 23722

https://github.com/xbrlus/xule/archive/refs/tags/23722.zip が最新のzipファイルなのでこれを取得します。

(arelle-env) Arelle $ wget https://github.com/xbrlus/xule/archive/refs/tags/23722.zip
--2024-03-24 16:43:58--  https://github.com/xbrlus/xule/archive/refs/tags/23722.zip
github.com (github.com) をDNSに問いあわせています... 20.27.177.113
github.com (github.com)|20.27.177.113|:443 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 302 Found
場所: https://codeload.github.com/xbrlus/xule/zip/refs/tags/23722 [続く]
--2024-03-24 16:43:59--  https://codeload.github.com/xbrlus/xule/zip/refs/tags/23722
codeload.github.com (codeload.github.com) をDNSに問いあわせています... 20.27.177.114
codeload.github.com (codeload.github.com)|20.27.177.114|:443 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 特定できません [application/zip]
`23722.zip' に保存中

23722.zip               [ <=>                ] 475.81K  2.82MB/s 時間 0.2s

2024-03-24 16:43:59 (2.82 MB/s) - `23722.zip' へ保存終了 [487230]
(arelle-env) Arelle $

ダウンロードした23722.zipを解凍します。

(arelle-env) Arelle $ unzip 23722.zip
Archive:  23722.zip
e8d801880fddfd43416ff42d5d6e0ff0c08aa49d
   creating: xule-23722/
 extracting: xule-23722/.gitignore
  inflating: xule-23722/LICENSE
  inflating: xule-23722/README.md
   creating: xule-23722/plugin/
   creating: xule-23722/plugin/FERC/
途中省略
   creating: xule-23722/plugin/SimpleXBRLModel/
途中省略
  inflating: xule-23722/plugin/Xince.py
   creating: xule-23722/plugin/serializer/
途中省略
   creating: xule-23722/plugin/validate/
途中省略
   creating: xule-23722/plugin/xendr/
途中省略
   creating: xule-23722/plugin/xodel/
途中省略
   creating: xule-23722/plugin/xule/
  inflating: xule-23722/plugin/xule/License.md
  inflating: xule-23722/plugin/xule/PatentNotice.md
  inflating: xule-23722/plugin/xule/README.md
途中省略

(arelle-env) Arelle $

plugin/xule/ をArelleのプラグインディレクトリ ~/Arelle/arelle/plugin/ に登録します。

mv xule-23722/plugin/xule arelle/plugin/

–helpを指定してXULEプラグインを実行して確認します。

(arelle-env) Arelle $ python arelleCmdLine.py --plugin xule --help
Usage: arelleCmdLine.py [options]

Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -f ENTRYPOINTFILE, --file=ENTRYPOINTFILE
                        FILENAME is an entry point, which may be an XBRL
                        instance, schema, linkbase file, inline XBRL instance,
                        testcase file, testcase index file.  FILENAME may be a
                        local file or a URI to a web located file.  For
                        multiple instance filings may be | separated file
                        names or JSON list of file/parameter dicts
                        [{"file":"filepath"}, {"file":"file2path"} ...].

  Arelleのオプションの一覧が続いた後、XULEのオプションの一覧が表示されます。今回使用するのは、次の3種類です。

  Xule Business Rule:
    --xule-compile=XULE_COMPILE
                        Xule files to be compiled.  This may be a file or
                        directory.  When a directory is provided, all files in
                        the directory will be processed.  Multiple file and
                        directory names are separated by a '|' character.
    --xule-rule-set=XULE_RULE_SET
                        RULESET to use (this is the directory where compile
                        rules are stored.
    --xule-run          Indicates that the rules should be processed.

(arelle-env) Arelle $

これでXULEプラグインの登録が確認できましました。

3. xBRL-CSVをXULEで解析

xBRL-CSVをもとに残高試算表をXULEで作成しようと試作しています。
ディメンション d_JISC03, d_JISC04b, d_BS05bCはそれぞれ仕訳入力、借方/貸方の明細行、及び原価部門や銀行口座などの補助科目に対応しています。
それ以外の代表的な項目を次の表に示します。

d_JISC03

仕訳入力

d_JISC04b

借方/貸方の明細行

d_BS05bC

原価部門

ISC04b_GL03_01

勘定科目番号

JISC04b_GL03_02

勘定科目名

JISC04b_GL03_06

借方/貸方区分(trueが借方)

CC04w_01

金額

次のxBRL-CSVは、General Ledgerの一部です。

d_JISC03

d_JISC04b

d_BS05bC

JISC03_GL02_01

JISC03_GL02_03

JISC03_GL02_06

JISC04b_GL03_01

JISC04b_GL03_02

JISC04b_GL03_06

CC04w_01

JISC04b_GL03_03

BS05bC_01

BS05bC_02

BS05bC_04

1

0001-20090401-18-1-1-463

2008-08-01

gj

1

1

726

Travel expense

true

18572

1

1

1

10

Sapporo

Department

1

2

191

Provisional payment consumption tax, etc.

true

928

1

2

1

10

Sapporo

Department

1

3

111

Cash

false

19500

Travel expense

1

3

1

0

Common

Department

2

0001-20090401-246-2-1-465

2008-08-19

gj

2

1

726

Travel expense

true

9524

2

1

1

30

Nagoya

Department

2

2

191

Provisional payment consumption tax, etc.

true

476

2

2

1

30

Nagoya

Department

2

3

111

Cash

false

10000

2

3

1

0

Common

Department

おなじ内容のXBRLインスタンス文書の一部を次に掲載します。

    <context id="c-02">
        <entity>
            <identifier scheme="http://www.example.com">Example Co.</identifier>
            <segment>
                <xbrldi:typedMember dimension="cor:d_JISC03"><cor:_v>1</cor:_v></xbrldi:typedMember>
                <xbrldi:typedMember dimension="cor:d_JISC04b"><cor:_v>1</cor:_v></xbrldi:typedMember>
            </segment>
        </entity>
        <period>
            <instant>2023-10-31</instant>
        </period>
    </context>
    <cor:JISC04b_GL03_01 contextRef="c-02" id="adc.r_2.JISC04b_GL03_01">726</cor:JISC04b_GL03_01>
    <cor:JISC04b_GL03_02 contextRef="c-02" id="adc.r_2.JISC04b_GL03_02">Travel expense</cor:JISC04b_GL03_02>
    <cor:JISC04b_GL03_06 contextRef="c-02" id="adc.r_2.JISC04b_GL03_06">true</cor:JISC04b_GL03_06>
    <cor:CC04w_01 contextRef="c-02" decimals="INF" id="adc.r_2.CC04w_01" unitRef="u-01">18572</cor:CC04w_01>
    <cor:JISC04b_GL03_03 contextRef="c-02" id="adc.r_2.JISC04b_GL03_03">Travel expense</cor:JISC04b_GL03_03>

XULEでインスタンス文書を解析して必要な情報を抽出します。
構造化CSV(階層型Tidy data)は、その階層構造をディメンションで定義しています。

namespace cor=http://www.iso.org/awi21926_jisc

output TravelExpense

/* Sets based on conditions matched by ID substrings */
$DebitEntries = set({covered @concept=cor:JISC04b_GL03_06 where $fact==true}.dimensions())
$CreditEntries = set({covered @concept=cor:JISC04b_GL03_06 where $fact==false}.dimensions())

$TravelExpenses = set({covered @concept=cor:JISC04b_GL03_01 where $fact=='726'}.dimensions())

/* Totals calculation based on conditions */
$totalDebitTravelExpenses = sum(list({covered @cor:CC04w_01 where $fact.dimensions() in $DebitEntries and $fact.dimensions() in $TravelExpenses}))
$totalCreditTravelExpenses = sum(list({covered @cor:CC04w_01 where $fact.dimensions() in $CreditEntries and $fact.dimensions() in $TravelExpenses}))

/* Output statement for total expenses */
"The total travel expenses are Debit:{$totalDebitTravelExpenses} JPY Credit:{$totalCreditTravelExpenses} JPY"

–xule-compileを指定してコンパイルします。

(arelle-env) Arelle $ python arelleCmdLine.py --plugin xule --xule-compile travel_expense.xule --xule-rule-set travel_expense.xulec
[info] Activation of plug-in XBRL rule processor (xule) successful, version Check version using Tools->Xule->Version on the GUI or --xule-version on the command line. - xule
[info] Xule version: 3.0.23722 -
2024-03-25T16:04:59.818515: post parse start
2024-03-25T16:04:59.819181: post parse end. Took 0:00:00.000666
2024-03-25T16:04:59.820116: Parsing finished. Took 0:00:00.003632
(arelle-env) Arelle $

–plugin “xule|loadFromOIM”の指定でOIM-CSVファイルを読み込みXULEで情報を抽出します。
xBRL-CSVのメタファイル(JSON)を—​fileで、コンパイルしたXULEファイルを—​xule-ruleで指定し、–xule-runで解析実行を指示しています。

(arelle-env) Arelle $ python arelleCmdLine.py --file JISCinstance.json --plugin "xule|loadFromOIM" --xule-run --xule-rule travel_expense.xulec
[info] Activation of plug-in XBRL rule processor (xule) successful, version Check version using Tools->Xule->Version on the GUI or --xule-version on the command line. - xule
[info] Activation of plug-in Load From OIM successful, version 1.2. - loadFromOIM
[info] Xule version: 3.0.23722 -
[info] loaded in 0.06 secs at 2024-03-25T16:08:51 - JISCinstance.json
[xule:error] rule TravelExpense: unhashable type: 'dict' - JISCinstance.xbrl
(arelle-env) Arelle $

こちらのXULEスクリプトは、XMLSpy 2023では、問題なく処理していましたが、[xule:error] が発生しました。
XBRL USに確認中です。
dimensionの情報は、xBRL-CSVを読み込むと内部でXMLのid属性に展開されます。
このid情報の先頭部分がディメンション情報に対応しているので、この情報を使って条件を指定してみます。

namespace cor=http://www.iso.org/awi21926_jisc

output TravelExpense

/* Sets based on conditions matched by ID substrings */
$DebitEntries = set({covered @concept=cor:JISC04b_GL03_06 where $fact==true}.id.substring(1,8))
$CreditEntries = set({covered @concept=cor:JISC04b_GL03_06 where $fact==false}.id.substring(1,8))

$TravelExpenses = set({covered @concept=cor:JISC04b_GL03_01 where $fact=='726'}.id.substring(1,8))

/* Totals calculation based on conditions */
$totalDebitTravelExpenses = sum(list({covered @cor:CC04w_01 where $fact.id.substring(1,8) in $DebitEntries and $fact.id.substring(1,8) in $TravelExpenses}))
$totalCreditTravelExpenses = sum(list({covered @cor:CC04w_01 where $fact.id.substring(1,8) in $CreditEntries and $fact.id.substring(1,8) in $TravelExpenses}))

/* Output statement for total expenses */
"The total travel expenses are Debit:{$totalDebitTravelExpenses} JPY Credit:{$totalCreditTravelExpenses} JPY"

こちらも—​xule-compileを指定してコンパイルします。

(arelle-env) Arelle $ python arelleCmdLine.py --plugin xule --xule-compile travel_expense_substring.xule --xule-rule-set travel_expense_substring.xulec
[info] Activation of plug-in XBRL rule processor (xule) successful, version Check version using Tools->Xule->Version on the GUI or --xule-version on the command line. - xule
[info] Xule version: 3.0.23722 -
2024-03-25T16:05:56.498980: post parse start
2024-03-25T16:05:56.499777: post parse end. Took 0:00:00.000797
2024-03-25T16:05:56.500789: Parsing finished. Took 0:00:00.003951
(arelle-env) Arelle $

こちらも同様に、
–plugin “xule|loadFromOIM”の指定でOIM-CSVファイルを読み込みXULEで情報を抽出します。
xBRL-CSVのメタファイル(JSON)を—​fileで、コンパイルしたXULEファイルを—​xule-ruleで指定し、–xule-runで解析実行を指示しています。

(arelle-env) Arelle $ python arelleCmdLine.py --file JISCinstance.json --plugin "xule|loadFromOIM" --xule-run --xule-rule travel_expense_substring.xulec
[info] Activation of plug-in XBRL rule processor (xule) successful, version Check version using Tools->Xule->Version on the GUI or --xule-version on the command line. - xule
[info] Activation of plug-in Load From OIM successful, version 1.2. - loadFromOIM
[info] Xule version: 3.0.23722 -
[info] loaded in 0.05 secs at 2024-03-25T16:09:38 - JISCinstance.json
[TravelExpense] The total travel expenses are Debit:28,096 JPY Credit:None JPY - JISCinstance.xbrl
(arelle-env) Arelle $

借方の旅費合計金額が求まりました。

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です