{"id":6475,"date":"2022-06-23T13:52:26","date_gmt":"2022-06-23T04:52:26","guid":{"rendered":"https:\/\/www.sambuichi.jp\/?p=6475"},"modified":"2022-08-09T18:51:06","modified_gmt":"2022-08-09T09:51:06","slug":"jp-pint-0-9-3%e3%81%ae%e3%82%b9%e3%82%ad%e3%83%bc%e3%83%9e%e3%83%88%e3%83%ad%e3%83%b3%e3%83%ab%e3%83%bc%e3%83%ab%e3%81%af%e3%80%81%e3%81%a9%e3%81%93%e3%81%8c%e5%a4%89%e6%9b%b4%e3%81%95%e3%82%8c","status":"publish","type":"post","link":"https:\/\/www.sambuichi.jp\/?p=6475","title":{"rendered":"JP PINT 0.9.3\u306e\u30b9\u30ad\u30fc\u30de\u30c8\u30ed\u30f3\u30eb\u30fc\u30eb\u306f\u3001\u3069\u3053\u304c\u5909\u66f4\u3055\u308c\u305f\u306e\u304b\uff1f"},"content":{"rendered":"<p>Views: 94<\/p><p>JP PINT 0.9.3\u30680.9.2\u306e\u6bd4\u8f03\u3067\u3059\u3002<\/p>\n<p>\u3042\u307e\u308a\u610f\u5473\u306e\u306a\u3044\u8a18\u8ff0\u30b9\u30bf\u30a4\u30eb\u306e\u5909\u66f4\u304c\u3042\u308a\u307e\u3059\u304c\u300120\u4e16\u7d00\u30a8\u30f3\u30b8\u30cb\u30a2\u306e\u89b3\u70b9\u304b\u3089\u306f\u3001\u300c\u6c17\u4ed8\u3044\u305f\u304b\u3089\u5909\u66f4\u3059\u308b\u3002\u300d\u306e\u3067\u306f\u306a\u304f\u3001\u5148\u305a\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u30b9\u30bf\u30a4\u30eb\u3084\u30d1\u30bf\u30fc\u30f3\u3054\u3068\u306e\u8a18\u8ff0\u65b9\u5f0f\u3092\u6c7a\u3081\u305f\u4e0a\u3067\u3001\u8a2d\u8a08\u65b9\u91dd\u306b\u5f93\u3063\u3066\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u3092\u3057\u306a\u3044\u3068\u54c1\u8cea\u78ba\u4fdd\u304c\u96e3\u3057\u3044\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u3044\u304b\u304c\u3067\u3057\u3087\u3046\u304b\u3002<br \/>\n40\u5e74\u524d\u306b\u6d77\u5916\u304b\u3089\u5c0e\u5165\u3057\u305f\u30bd\u30d5\u30c8\u30a6\u30a8\u30a2\u306e\u65e5\u672c\u7248\u5bfe\u5fdc\u4f5c\u696d\u3067\u306f\u3001\u5f53\u521d\u6c17\u3065\u304b\u306a\u304b\u3063\u305f\u6f5c\u5728\u4e0d\u826f\u304c\u5f8c\u304b\u3089\u767a\u898b\u3055\u308c\u3066\u3001\u5bfe\u5fdc\u4f5c\u696d\u306b\u56f0\u308b\u4e8b\u304c\u591a\u304b\u3063\u305f\u4e8b\u304c\u601d\u3044\u51fa\u3055\u308c\u307e\u3059\u3002<\/p>\n<h3>Aligned\u30eb\u30fc\u30eb<\/h3>\n<h4>aligned-ibrp-050-jp(fatal)<\/h4>\n<p>[aligned-ibrp-050-jp]-Each Invoice line (ibg-25) MUST be categorized with an Invoiced item tax category code (ibt-151) and Invoiced item tax rate (ibt-152).<\/p>\n<p>context\u306e\u5909\u66f4\u306a\u3057\u3000\/ubl:InvoiceLine | \/cn:CreditNoteLine<br \/>\ntest\u30b9\u30af\u30ea\u30d7\u30c8\u5909\u66f4<br \/>\n0.9.3\u3067\u306f\u3001\u660e\u7d30\u884c\u306ecac:Item\u306e\u307f\u3092\u5bfe\u8c61\u3068\u3059\u308b\u3088\u3046\u306b\u8a02\u6b63\u3055\u308c\u305f\u30020.9.2\u3067\u306f\u3001\u5b9a\u7fa9\u3055\u308c\u305f\u3059\u3079\u3066\u306e\u968e\u5c64\u306ecac:Item\u3092\u5bfe\u8c61\u3068\u3057\u3066\u3044\u305f\u3002<\/p>\n<pre class=\"height-set:true width-set:false lang:default decode:true \" title=\"0.9.3\" >(\r\n  cac:Item\/cac:ClassifiedTaxCategory[cac:TaxScheme\/(normalize-space(upper-case(cbc:ID))='VAT')]\/cbc:ID\r\n) and \r\n(\r\n  cac:Item\/cac:ClassifiedTaxCategory[cac:TaxScheme\/(normalize-space(upper-case(cbc:ID))='VAT')]\/cbc:Percent\r\n)<\/pre>\n<p>0.9.2<\/p>\n<pre class=\"height-set:true width-set:false lang:default decode:true \"  title=\"0.9.2\">(\r\n  \/\/cac:ClassifiedTaxCategory[cac:TaxScheme\/(normalize-space(upper-case(cbc:ID))='VAT')]\/cbc:ID\r\n) and \r\n(\r\n  \/\/cac:ClassifiedTaxCategory[cac:TaxScheme\/(normalize-space(upper-case(cbc:ID))='VAT')]\/cbc:Percent\r\n)<\/pre>\n<h4>\u7a0e\u7387 0 \u306e\u5224\u5b9a\u30b9\u30af\u30ea\u30d7\u30c8\u8a02\u6b63<\/h4>\n<p>\u6b21\u306e\u30eb\u30fc\u30eb\u306e\u5224\u5b9a\u5f0f\u304c <span class=\"lang:default decode:true  crayon-inline \" >(cbc:Percent = 0)<\/span> \u3000<span class=\"lang:default decode:true  crayon-inline \" >(xs:decimal(cbc:Percent) = 0)<\/span>\u306b\u8a02\u6b63\u3055\u308c\u305f\u3002<br \/>\nxs:decimal\u306f\u3001XSLT\u306e\u95a2\u6570\u3067\u5bfe\u8c61\u3068\u3059\u308bXML\u8981\u7d20\u306e\u5024\u3092\u6570\u5024\u306b\u5909\u63db\u3059\u308b\u3002<\/p>\n<dl>\n<dt>aligned-ibrp-e-06(fatal)<\/dt>\n<dd>[aligned-ibrp-e-06]-In a Document level allowance (ibg-20) where the Document level allowance tax category code (ibt-95) is &#8220;Exempt from tax&#8221;, the Document level allowance tax rate (ibt-96) MUST be 0 (zero).<\/dd>\n<dt>aligned-ibrp-e-07(fatal)<\/dt>\n<dd>[aligned-ibrp-e-07]-In a Document level charge (ibg-21) where the Document level charge tax category code (ibt-102) is &#8220;Exempt from tax&#8221;, the Document level charge tax rate (ibt-103) MUST be 0 (zero).<\/dd>\n<dt>aligned-ibrp-g-06(fatal)<\/dt>\n<dd>[aligned-ibrp-g-06]-In a Document level allowance (ibg-20) where the Document level allowance tax category code (ibt-95) is &#8220;Export&#8221; the Document level allowance tax rate (ibt-96) MUST be 0 (zero).<\/dd>\n<dt>aligned-ibrp-g-07(fatal)<\/dt>\n<dd>[aligned-ibrp-g-07]-In a Document level charge (ibg-21) where the Document level charge tax category code (ibt-102) is &#8220;Export&#8221; the Document level charge tax rate (ibt-103) MUST be 0 (zero).<\/dd>\n<\/dl>\n<h3>Sharerd\u30eb\u30fc\u30eb<\/h3>\n<h4>\u65b0\u898f\u8ffd\u52a0<\/h4>\n<p>\u6b21\u306e\uff12\u3064\u306e\u30eb\u30fc\u30eb\u304c\u8ffd\u52a0\u3055\u308c\u305f\u3002<\/p>\n<dl>\n<dt>ibr-sr-57(fatal)<\/dt>\n<dd>[ibr-sr-57]-Company identifier MUST exist in the party tax scheme class.<\/dd>\n<dt>context<\/dt>\n<dd>\/\/cac:PartyTaxScheme<\/dd>\n<dt>test<\/dt>\n<dd>exists(cbc:CompanyID)<\/dd>\n<\/dl>\n<dl>\n<dt>ibr-sr-58(fatal)<\/dt>\n<dd>[ibr-sr-58]-The Invoiced item TAX category code (ibt-151) MUST be present.<\/dd>\n<dt>context<\/dt>\n<dd>cac:InvoiceLine\/cac:Item\/cac:ClassifiedTaxCategory<\/dd>\n<dt>test<\/dt>\n<dd>exists(cbc:ID)<\/dd>\n<\/dl>\n<h4>\u6587\u66f8\u30ec\u30d9\u30eb\u306eAllowance\u53ca\u3073Charge\u306e\u91d1\u984d<\/h4>\n<p>\u305d\u308c\u305e\u308c\u91d1\u984d\u3092\u8a18\u8f09\u3057\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u3068\u3044\u3046\u30eb\u30fc\u30eb\u3060\u304c\u3001\u30c1\u30a7\u30c3\u30af\u5bfe\u8c61\u3092\u6307\u5b9a\u3059\u308bcontext\u306e\u8a18\u8ff0\u3092\u5909\u66f4\u3057\u3066\u3044\u308b\u3002<br \/>\n\u4f46\u3057\u3001\/\/cac:AllowanceCharge\u306e\u8a18\u8ff0\u3067\u306f\u3001\/ubl:Invoice\/cac:AllowanceCharge\u3060\u3051\u3067\u306a\u304f\/ubl:Invoice\/cac:InvoiceLine\/cac:AllowanceCharge\u3082\u5bfe\u8c61\u3068\u3055\u308c\u308b\u306e\u3067\u3001\u30eb\u30fc\u30eb\u306e\u5bfe\u8c61\u304c\u6587\u66f8\u30ec\u30d9\u30eb\u53ca\u3073\u660e\u7d30\u884c\u30ec\u30d9\u30eb\u3068\u62e1\u5f35\u3055\u308c\u3066\u304a\u308a\u610f\u56f3\u304c\u6b63\u3057\u304f\u53cd\u6620\u3055\u308c\u3066\u3044\u306a\u3044\u3088\u3046\u306b\u601d\u3048\u308b\u3002<\/p>\n<dl>\n<dt>ibr-031(fatal)<\/dt>\n<dd>[ibr-031]-Each Document level allowance (ibg-20) MUST have a Document level allowance amount (ibt-092).<\/dd>\n<dt>\u5909\u66f4\u5f8c context<\/dt>\n<dd>\/\/cac:AllowanceCharge[cbc:ChargeIndicator = false()]<\/dd>\n<dt>\u5909\u66f4\u524d context<\/dt>\n<dd>\/ubl:Invoice\/cac:AllowanceCharge[cbc:ChargeIndicator = false()] | \/cn:CreditNote\/cac:AllowanceCharge[cbc:ChargeIndicator = false()]<\/dd>\n<\/dl>\n<dl>\n<dt>ibr-036(fatal)<\/dt>\n<dd>[ibr-036]-Each Document level charge (ibg-21) MUST have a Document level charge amount (ibt-099).<\/dd>\n<dt>\u5909\u66f4\u5f8c context<\/dt>\n<dd>\/\/cac:AllowanceCharge[cbc:ChargeIndicator = true()]<\/dd>\n<dt>\u5909\u66f4\u524d context<\/dt>\n<dd>\/ubl:Invoice\/cac:AllowanceCharge[cbc:ChargeIndicator = true()] | \/cn:CreditNote\/cac:AllowanceCharge[cbc:ChargeIndicator = true()]<\/dd>\n<\/dl>\n<h4>\u6587\u66f8\u30ec\u30d9\u30eb\u306eAllowance\u53ca\u3073Charge\u306e\u7406\u7531\u306e\u4ef6\u6570<\/h4>\n<p>\u305d\u308c\u305e\u308c\u7406\u7531\u4ef6\u6570\u306f\u6700\u59271 \u3068\u3044\u3046\u30eb\u30fc\u30eb\u3060\u304c\u3001\u30c1\u30a7\u30c3\u30af\u5bfe\u8c61\u3092\u6307\u5b9a\u3059\u308bcontext\u306e\u8a18\u8ff0\u3092\u4e0a\u8a18\u540c\u69d8\u306b\u5909\u66f4\u3057\u3066\u3044\u308b\u3002<br \/>\n\u3053\u3061\u3089\u3082\u30eb\u30fc\u30eb\u306e\u5bfe\u8c61\u304c\u6587\u66f8\u30ec\u30d9\u30eb\u53ca\u3073\u660e\u7d30\u884c\u30ec\u30d9\u30eb\u3068\u62e1\u5f35\u3055\u308c\u3066\u304a\u308a\u610f\u56f3\u304c\u6b63\u3057\u304f\u53cd\u6620\u3055\u308c\u3066\u3044\u306a\u3044\u3088\u3046\u306b\u601d\u3048\u308b\u3002<\/p>\n<dl>\n<dt>ibr-sr-30(fatal)<\/dt>\n<dd>[ibr-sr-30]-Document level allowance reason MUST occur maximum once<\/dd>\n<dt>ibr-sr-31(fatal)<\/dt>\n<dd>[ibr-sr-31]-Document level charge reason MUST occur maximum once<\/dd>\n<\/dl>\n<h4>\u91d1\u984d\u306e\u5c0f\u6570\u70b9\u4ee5\u4e0b\u306e\u6841\u6570\u306f2\u4ee5\u4e0b<\/h4>\n<p>Invoice amount due for payment (ibt-115) \u3067\u306f\u3001\u8868\u73fe\u3092\u5909\u66f4\u3057\u3066\u3044\u308b\u304c\u5185\u5bb9\u306f\u524d\u3068\u540c\u3058\u3002<\/p>\n<dl>\n<dt>ibr-091(fatal)<\/dt>\n<dd>[ibr-091]-Invoice amount due for payment (ibt-115) MUST have no more than 2 decimals.<\/dd>\n<dt>\u5909\u66f4\u5f8c<br \/>context<\/dt>\n<dd>cac:LegalMonetaryTotal<\/dd>\n<dt>test<\/dt>\n<dd>string-length(substring-after(cbc:PayableAmount, &#8216;.&#8217;)) <= 2<\/dd>\n<dt>\u5909\u66f4\u524d<br \/>context<\/dt>\n<dd>cac:LegalMonetaryTotal\/cbc:PayableAmount<\/dd>\n<dt>test<\/dt>\n<dd>string-length(substring-after(., &#8216;.&#8217;)) <= 2<\/dd>\n<\/dl>\n<p>\u3053\u306e\u307b\u304b\u306b\u6b21\u306e\u9805\u76ee\u306b\u3064\u3044\u3066>\u91d1\u984d\u306e\u5c0f\u6570\u70b9\u4ee5\u4e0b\u306e\u6841\u6570\u306f2\u4ee5\u4e0b\u3068\u3044\u3046\u6761\u4ef6\u304c\u8ffd\u52a0\u3055\u308c\u305f\u3002<\/p>\n<dl>\n<dt>ibr-121(fatal)<\/dt>\n<dd>[ibr-121]-Document level allowance amount (ibt-107) MUST have no more than 2 decimals.<\/dd>\n<dt>ibr-122(fatal)<\/dt>\n<dd>[ibr-122]-Document level charge amount (ibt-108) MUST have no more than 2 decimals.<\/dd>\n<dt>ibr-123(fatal)<\/dt>\n<dd>[ibr-123]-Invoice total amount without TAX (ibt-109) MUST have no more than 2 decimals.<\/dd>\n<dt>ibr-124(fatal)<\/dt>\n<dd>[ibr-124]-Invoice total TAX amount (ibt-110) MUST have no more than 2 decimals.<\/dd>\n<dt>ibr-125(fatal)<\/dt>\n<dd>[ibr-125]- Invoice total amount with TAX (ibt-112) MUST have no more than 2 decimals.<\/dd>\n<dt>ibr-126(fatal)<\/dt>\n<dd>[ibr-126]- All currencyID attributes must have the same value as the Invoice currency code (ibt-005), except for amounts expected to be in Tax accounting currency (ibt-006).<\/dd>\n<\/dl>\n<h4>\u901a\u8ca8\u30b3\u30fc\u30c9<\/h4>\n<p>\u7a0e\u52d9\u4f1a\u8a08\u901a\u8ca8\u30b3\u30fc\u30c9\u3092\u4f7f\u7528\u3059\u308b\u3068\u6307\u5b9a\u3055\u308c\u3066\u3044\u306a\u3044\u91d1\u984d\u306b\u3064\u3044\u3066\u306f\u8acb\u6c42\u306e\u6587\u66f8\u901a\u8ca8\u30b3\u30fc\u30c9\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u3002<br \/>\n\u3053\u306e\u30eb\u30fc\u30eb\u306fBIS Billing 3.0\u3067\u3082\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u305f\u304cPINT\u3067\u306f\u7a0e\u52d9\u4f1a\u8a08\u901a\u8ca8\u30b3\u30fc\u30c9\u3092\u4f7f\u7528\u3059\u308b\u3068\u6307\u5b9a\u3055\u308c\u305f\u9805\u76ee\u304c\u5f93\u6765\u306e\u8acb\u6c42\u66f8\u5408\u8a08\u7a0e\u984d\u306e\u307b\u304b\u306b\u62e1\u5927\u3055\u308c\u305f\u305f\u3081\u5bfe\u8c61\u3092\u6307\u5b9a\u3059\u308bcontect\u304c\u5909\u66f4\u3055\u308c\u305f\u3002<br \/>\n\u5bfe\u51e6\u3068\u3059\u308b\u91d1\u984d\u306eXML\u8981\u7d20\u306e\u968e\u5c64\u304c\u4e0d\u5b9a\u3067\u3042\u308b\u3053\u3068\u304b\u3089\u6bd4\u8f03\u5bfe\u8c61\u306e\u8acb\u6c42\u306e\u6587\u66f8\u901a\u8ca8\u30b3\u30fc\u30c9\u3092\/\/cbc:DocumentCurrencyCode\u3068 \/\/ \u3092\u4f7f\u7528\u3057\u3066\u6307\u5b9a\u3057\u3066\u3044\u308b\u3002<\/p>\n<dl>\n<dt>ibr-126(fatal)<\/dt>\n<dd>[ibr-126]- All currencyID attributes must have the same value as the Invoice currency code (ibt-005), except for amounts expected to be in Tax accounting currency (ibt-006).<\/dd>\n<dt>context<\/dt>\n<dd>cbc:Amount | cbc:BaseAmount | cbc:PriceAmount | cbc:LineExtensionAmount | cbc:TaxExclusiveAmount | cbc:TaxInclusiveAmount | cbc:AllowanceTotalAmount | cbc:ChargeTotalAmount | cbc:PrepaidAmount | cbc:PayableRoundingAmount | cbc:PayableAmount |<br \/>\ncac:TaxTotal[cbc:TaxAmount\/@currencyID = \/*\/cbc:DocumentCurrencyCode]\/cbc:TaxAmount |<br \/>\ncac:TaxTotal[cbc:TaxAmount\/@currencyID = \/*\/cbc:DocumentCurrencyCode]\/cac:TaxSubtotal\/cbc:TaxableAmount |<br \/>\ncac:TaxTotal[cbc:TaxAmount\/@currencyID = \/*\/cbc:DocumentCurrencyCode]\/cac:TaxSubtotal\/cbc:TaxAmount<\/dd>\n<dt>test<\/dt>\n<dd>@currencyID = \/\/cbc:DocumentCurrencyCode<\/dd>\n<\/dl>\n<h4>\u6570\u91cf\u5358\u4f4d<\/h4>\n<p>\u6570\u91cf\u5358\u4f4d\u306b\u306f\u56fd\u9023\u30b3\u30fc\u30c9\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3002\u3068\u3044\u3046\u30eb\u30fc\u30eb\u3067\u5f93\u6765\u304b\u3089\u3042\u3063\u305f\u3082\u306e\u3060\u304c\u3001cbc:CreditedQuantity\u304c\u8ffd\u52a0\u3055\u308c\u305f\u3002<\/p>\n<dl>\n<dt>ibr-cl-23(fatal)<\/dt>\n<dd>[ibr-cl-23]-Unit code MUST be coded according to the UN\/ECE Recommendation 20 with Rec 21 extension<\/dd>\n<dt>\u5909\u66f4\u5f8ccontext<\/p>\n<dt>\n<dd>cbc:InvoicedQuantity[@unitCode] | cbc:BaseQuantity[@unitCode] | cbc:CreditedQuantity[@unitCode]<\/dd>\n<dt>\u5909\u66f4\u524dcontext<\/p>\n<dt>\n<dd>cbc:InvoicedQuantity[@unitCode] | cbc:BaseQuantity[@unitCode]<\/dd>\n<\/dl>\n<h4>\u5148\u884c\u3059\u308b\u8acb\u6c42\u66f8\u3078\u306e\u53c2\u7167\u306e\u4ef6\u6570<\/h4>\n<p>\u30eb\u30fc\u30eb\u306e\u6587\u8a00\u306f\u5909\u66f4\u306a\u3044\u304c\u3001context\u53ca\u3073test\u306e\u8a18\u8ff0\u3092\u5909\u66f4\u3057\u3066\u3044\u308b\u3002\u8a18\u8ff0\u8868\u73fe\u306f\u9055\u3046\u304c\u5b9a\u7fa9\u5185\u5bb9\u306f\u5909\u308f\u3089\u306a\u3044\u3002<\/p>\n<dl>\n<dt>ibr-sr-06(fatal)<\/dt>\n<dd>[ibr-sr-06]-Preceding invoice reference MUST occur maximum once<\/dd>\n<dt>\u5909\u66f4\u5f8c<br \/>context<\/dt>\n<dd>cac:BillingReference<\/dd>\n<dt>test<\/dt>\n<dd>(count(cac:InvoiceDocumentReference) <= 1)<\/dd>\n<dt>\u5909\u66f4\u524d<br \/>context<\/dt>\n<dd>\/ubl:Invoice | \/cn:CreditNote<\/dd>\n<dt>test<\/dt>\n<dd>(count(cac:BillingReference\/InvoiceDocumentReference) <= 1)<\/dd>\n<\/dl>\n<h4>Seller tax representative\u306e\u540d\u524d\u306e\u4ef6\u6570<\/h4>\n<p>test\u30b9\u30af\u30ea\u30d7\u30c8\u306e\u30a8\u30e9\u30fc\u3092\u8a02\u6b63\u3002cac:TaxRepresentativeParty\/cac:Party\/cac:PartyName\/cbc:Name\u306f\u8aa4\u308a\u3002\u6b63\u3057\u304f\u306f\u3001cac:TaxRepresentativeParty\/cac:PartyName\/cbc:Name<\/p>\n<dl>\n<dt>ibr-sr-22(fatal)<\/dt>\n<dd>[ibr-sr-22]-Seller tax representative name MUST occur maximum once, if the Seller has a tax representative<\/dd>\n<dt>context<\/dt>\n<dd>cac:TaxRepresentativeParty<\/dd>\n<dt>\u5909\u66f4\u5f8ctest<\/dt>\n<dd>(count(cac:PartyName\/cbc:Name) <= 1)<\/dd>\n<dt>\u5909\u66f4\u524dtest<\/dt>\n<dd>(count(cac:Party\/cac:PartyName\/cbc:Name) <= 1)<\/dd>\n<\/dl>\n<h3>\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u30d5\u30a1\u30a4\u30eb\u89e3\u6790\u30bd\u30d5\u30c8(Schematron\u3092TSV\u306b\u5909\u63db\uff09<\/h3>\n<p>Python3 ElementTree csv\u304a\u3088\u3073\u81ea\u4f5c\u306e\u30e9\u30a4\u30d6\u30e9\u30eadic2etree\u3092\u4f7f\u7528\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"height-set:true width-set:false lang:default decode:true \" title=\"schematron2csv.py\" >#!\/usr\/bin\/env python3\r\n#coding: utf-8\r\n#\r\n# generate TSV from XML Schematron\r\n# \r\n# designed by SAMBUICHI, Nobuyuki (Sambuichi Professional Engineers Office)\r\n# written by SAMBUICHI, Nobuyuki (Sambuichi Professional Engineers Office)\r\n#\r\n# MIT License\r\n# \r\n# Copyright (c) 2021 SAMBUICHI Nobuyuki (Sambuichi Professional Engineers Office)\r\n# \r\n# Permission is hereby granted, free of charge, to any person obtaining a copy\r\n# of this software and associated documentation files (the \"Software\"), to deal\r\n# in the Software without restriction, including without limitation the rights\r\n# to use, copy, modify, merge, publish, distribute, sublicense, and\/or sell\r\n# copies of the Software, and to permit persons to whom the Software is\r\n# furnished to do so, subject to the following conditions:\r\n# \r\n# The above copyright notice and this permission notice shall be included in all\r\n# copies or substantial portions of the Software.\r\n# \r\n# THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\n# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\n# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\n# SOFTWARE.\r\nimport xml.etree.ElementTree as ET\r\nfrom collections import defaultdict\r\nfrom operator import itemgetter\r\nimport csv\r\nimport re\r\nimport json\r\nimport sys \r\nimport os\r\nimport argparse\r\n\r\nfrom dic2etree import *\r\n\r\ndictID = defaultdict(type(''))\r\ndictXpath = defaultdict(type(''))\r\n\r\ndef file_path(pathname):\r\n  if '\/' == pathname[0:1]:\r\n    return pathname\r\n  else:\r\n    dir = os.path.dirname(__file__)\r\n    new_path = os.path.join(dir, pathname)\r\n    return new_path\r\n\r\ndef dict_to_tsv(tsv, root):\r\n  def setup_record(context, id, flag, test, text):\r\n    test = test.strip()\r\n    test = ' '.join(test.split())\r\n    text = text.strip()\r\n    text = ' '.join(text.split())\r\n    terms_pattern = 'I?BT-[0-9]*'\r\n    terms = re.findall(terms_pattern, text, flags=re.IGNORECASE)\r\n    terms = ' '.join(terms)\r\n    groups_pattern = 'I?BG-[0-9]*'\r\n    groups = re.findall(groups_pattern, text, flags=re.IGNORECASE)\r\n    groups = ' '.join(groups)\r\n    record = [id, flag, text, context, test, groups, terms]\r\n    return record\r\n\r\n  def process_pattern(tsv, pattern):\r\n    pattern_id = pattern['@id']\r\n    rules = pattern['sch:rule']\r\n    if isinstance(rules, dict):\r\n      try:\r\n        context = rules['@context']\r\n        d = rules['sch:assert']\r\n        if isinstance(d, list):\r\n          for v in d:\r\n            record = setup_record(context, v['@id'], v['@flag'], v['@test'], v['#text'])\r\n            tsv.append(record)\r\n        elif isinstance(d, dict):\r\n          record = setup_record(context, d['@id'], d['@flag'], d['@test'], d['#text'])\r\n          tsv.append(record)\r\n        else:\r\n          if verbose:\r\n            print(json.dumps(d))\r\n          pass\r\n      except Exception as expt:\r\n        if verbose:\r\n          print(expt.args)\r\n        pass\r\n    elif isinstance(rules, list):\r\n      for rule in rules:\r\n        try:\r\n          context = rule['@context']\r\n          d = rule['sch:assert']\r\n          if isinstance(d, list):\r\n            for v in d:\r\n              record = setup_record(context, v['@id'], v['@flag'], v['@test'], v['#text'])\r\n              tsv.append(record)\r\n          elif isinstance(d, dict):\r\n            record = setup_record(context, d['@id'], d['@flag'], d['@test'], d['#text'])\r\n            tsv.append(record)\r\n          else:\r\n            if verbose:\r\n              print(json.dumps(d))\r\n            pass\r\n        except Exception as expt:\r\n          if verbose:\r\n            print(expt.args)\r\n          pass\r\n    else:\r\n      pass\r\n    return tsv\r\n  \r\n  # header\r\n  record = ['id', 'flag', 'text', 'context', 'test', 'BG', 'BT']\r\n  tsv.append(record)\r\n  if 'sch:pattern' in root:\r\n    pattern = root['sch:pattern']\r\n    tsv = process_pattern(tsv, pattern)\r\n  elif root['sch:schema'] and isinstance(root['sch:schema'], dict):\r\n    for tag, body in root['sch:schema'].items():\r\n      if 'sch:pattern' == tag:\r\n        for pattern in body:\r\n          tsv = process_pattern(tsv, pattern)\r\n\r\nif __name__ == '__main__':\r\n  # Create the parser\r\n  parser = argparse.ArgumentParser(prog='invoice2tsv',\r\n                                  usage='%(prog)s [options] pintFile -o out_file',\r\n                                  description='\u30b9\u30ad\u30fc\u30de\u30c8\u30ed\u30f3\u30d5\u30a1\u30a4\u30eb\u3092tsv\u30d5\u30a1\u30a4\u30eb\u306b\u5909\u63db')\r\n  # trn-invoice\/schematron\/PINT-jurisdiction-aligned-rules.sch -va\r\n  # Add the arguments\r\n  parser.add_argument('pintFile', metavar='pintfile', type=str, help='\u5165\u529bPINT-UBL\u30d5\u30a1\u30a4\u30eb')\r\n  parser.add_argument('-o', '--out')\r\n  parser.add_argument('-v', '--verbose', action='store_true')\r\n  args = parser.parse_args()\r\n  pint_file = file_path(args.pintFile)\r\n  pre, ext = os.path.splitext(pint_file)\r\n  # tmp_file = pre + '.tmp'\r\n  if args.out:\r\n    out_file = args.out.lstrip()\r\n    out_file = file_path(out_file)\r\n  else:\r\n    out_file = pre + '.txt'\r\n  verbose = args.verbose\r\n  # Check if infile exists\r\n  if not os.path.isfile(pint_file):\r\n    print('\u5165\u529b\u30d5\u30a1\u30a4\u30eb\u304c\u3042\u308a\u307e\u305b\u3093')\r\n    sys.exit()\r\n  if verbose:\r\n    print('** START ** ', __file__)\r\n\r\n  pint_tree = ET.parse(pint_file)\r\n  pint_root = pint_tree.getroot()\r\n  pint_dict = etree_to_dict(pint_root)\r\n  dicJson = json.dumps(pint_dict)\r\n  dicJson = re.sub('{' + ns[''] + '}', '', dicJson)\r\n  dicJson = re.sub('{' + ns['cac'] + '}', 'cac:', dicJson)\r\n  dicJson = re.sub('{' + ns['cbc'] + '}', 'cbc:', dicJson)\r\n  dicJson = re.sub('{' + ns['sch'] + '}', 'sch:', dicJson)\r\n  pint_dict2 = json.loads(dicJson)\r\n  pint_tsv = []\r\n  dict_to_tsv(pint_tsv, pint_dict2)\r\n\r\n  pint_set = set([json.dumps(x) for x in pint_tsv])\r\n  pint_list = list(pint_set)\r\n  tsv = [json.loads(w) for w in pint_list]\r\n  sorted_tsv = sorted(tsv,key=lambda x: x[0])\r\n\r\n  header = ['id', 'flag', 'text', 'context', 'test', 'BG', 'BT']\r\n\r\n  with open(out_file, 'w') as f:\r\n      writer = csv.writer(f, delimiter='\\t')\r\n      writer.writerow(header)\r\n      for d in sorted_tsv:\r\n        writer.writerow(d)\r\n\r\n  if verbose:\r\n    print(f'** END ** {out_file}')<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Views: 94JP PINT 0.9.3\u30680.9.2\u306e\u6bd4\u8f03\u3067\u3059\u3002 \u3042\u307e\u308a\u610f\u5473\u306e\u306a\u3044\u8a18\u8ff0\u30b9\u30bf\u30a4\u30eb\u306e\u5909\u66f4\u304c\u3042\u308a\u307e\u3059\u304c\u300120\u4e16\u7d00\u30a8\u30f3\u30b8\u30cb\u30a2\u306e\u89b3\u70b9\u304b\u3089\u306f\u3001\u300c\u6c17\u4ed8\u3044\u305f\u304b\u3089\u5909\u66f4\u3059\u308b\u3002\u300d\u306e\u3067\u306f\u306a\u304f\u3001\u5148\u305a\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u30b9\u30bf\u30a4\u30eb\u3084\u30d1\u30bf\u30fc [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":6484,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[45,49],"tags":[],"_links":{"self":[{"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=\/wp\/v2\/posts\/6475"}],"collection":[{"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6475"}],"version-history":[{"count":16,"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=\/wp\/v2\/posts\/6475\/revisions"}],"predecessor-version":[{"id":6794,"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=\/wp\/v2\/posts\/6475\/revisions\/6794"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=\/wp\/v2\/media\/6484"}],"wp:attachment":[{"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6475"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6475"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6475"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}