(Move / Repost) Extraction of articles containing specific words using e-Gov Law API and XML Python

Trigger

There is an article in the 201910 Business Law Journal entitled "Recommendation for organizing information by XML". There is excitement. First, I played with the decree XML.

Contents

--E-Gov Obtain the law specified from the law API and display the text. --It is also possible to display only the text that includes a specific word (I often use it personally)

code

python


import requests
import xml.etree.ElementTree as ET

#e-Gov Legal API Specification
#https://www.e-gov.go.jp/elaws/pdf/houreiapi_shiyosyo.pdf

#Decree selection
def lawName2No(KEYWORD, TAG='LawName'):
    url = 'https://elaws.e-gov.go.jp/api/1/lawlists/2'
    r = requests.get(url)
    root = ET.fromstring(r.content.decode(encoding='utf-8'))
    iflag = 0
    for i,e in enumerate(root.getiterator()):
        if TAG==e.tag:  
            iflag = 0
        if KEYWORD==e.text: 
            iflag = 1
        if iflag==1 and e.tag=='LawNo':
            return  str(e.text)

#Decree display / extraction
def lawTextExtractor(KEYWORD, lawnum='all', wordn=0, words=[]):
    if lawnum=='all':
        url = 'https://elaws.e-gov.go.jp/api/1/lawdata/'+lawName2No(KEYWORD)
    else:
        url = 'https://elaws.e-gov.go.jp/api/1/articles;lawNum='+lawName2No(KEYWORD)+';article='+str(lawnum)
    r = requests.get(url)
    if r.status_code!=requests.codes.ok:
        return
    root = ET.fromstring(r.content.decode(encoding='utf-8')) 
    lawstrs = []
    ssentcount = 0
    for i,e in enumerate(root.getiterator()):
        for xtag in ['LawTitle', 'SupplProvisionLabel', 'ArticleCaption', 'ArticleTitle', 'ParagraphNum', 'ItemTitle', 'Sentence']:
            if e.tag==xtag :

                if wordn==1 and xtag=='Sentence':#When specifying a word
                    tmpstr = ''
                    for word in words:
                        if str(e.text).find(word)>-1:
                            if tmpstr=='':
                                tmpstr = e.text.replace(word, '●'+word)
                            else:
                                tmpstr = tmpstr.replace(word, '★'+word)
                    if tmpstr!='':
                        lawstrs.append(tmpstr)
                        ssentcount += 1
                    
                else:
                    lawstrs.append(str(e.text))
    if lawstrs==[]:
        pass
    else:
        if lawnum=='all':
            print('● Number of clauses', ssentcount)
        print('\n'.join(lawstrs))


#Decree designation
KEYWORD = 'Copyright law'

#When extracting words 1
wordn = 1 
#Extracted word list
words = ['movies'] 

#Article designation This time, Articles 14 to 29
for lawnum in range(14,30): 
    lawTextExtractor(KEYWORD, lawnum, wordn, words)
    #Forcibly process "Article". We will consider countermeasures later.
    [lawTextExtractor(KEYWORD, str(lawnum)+'.'+str(i), wordn, words) for i in range(15)]

#When specifying the entire law (when the text is short, this is quicker)
lawTextExtractor(KEYWORD, 'all', wordn, words)

#In parallel,
#lawTextExtractor(KEYWORD, 18, 0, [])
#It is also good to check the hidden part of a specific article such as
#for n in [134,134.2,134.3,153,164.2,134.2]:
#    lawTextExtractor(KEYWORD, n, 0, [])
#Etc., "Article 134, paragraph 1 or 2, Article 134-2, paragraph 5,
#According to the provisions of Article 134-3, Article 153, paragraph 2 or Article 164-2, paragraph 2.
#It is also good to check all the quoted articles such as "only within the specified period".

Output result

――If you extract words, you can see that, for example, in movies, transfer rights are converted into distribution rights. --The clause number is left as it is regardless of whether or not the word is extracted. To help you understand the overall structure. ――The first term is None. I thought this would be easier for people who are accustomed to reading the law. ――I thought I would put an indent in the item, but I didn't. Because it became hard to see.

(Estimation of author) Article 14 None (Author of the work created on the job) Article 15 None 2 (Author of cinematographic work) Article 16 None ● The authors of cinematographic works, except for the authors of novels, scripts, music and other works adapted or reproduced in the cinematographic works, produce, direct, direct, shoot, art, etc. Responsible for that ● The person who creatively contributed to the overall formation of the cinematographic work. (Author's rights) Article 17 None 2 (Publication right) Article 18 None 2 one two three According to the provisions of Article 29, the copyright of the cinematographic work belongs to the filmmaker. 3 one two three four Five 4 one two three four Five Six Seven Eight (Name display right) Article 19 None 2 3 4 one two three (Right to maintain identity) Article 20 None 2 one two three four (Reproduction right) Article 21 None (Performance right and performance right) Article 22 None (Screening right) Article 22-2 None (Public transmission right, etc.) Article 23 None 2 (Oral right) Article 24 None (Exhibition right) Article 25 None (Distribution right) Article 26 None The author has the exclusive right to distribute the cinematographic work in its reproduction. 2 The author has the exclusive right to distribute the work reproduced in the cinematographic work by the copy of the cinematographic work. (Transfer right) Article 26-2 None The author shall use the original work or reproduction (● for the work reproduced in the cinematographic work) of the work (● excluding the cinematographic work; the same shall apply hereinafter in this Article). Excludes reproductions of cinematographic works; the same shall apply hereinafter in this Article) and has the exclusive right to provide it to the public. 2 one two three four Five (Rental right) Article 26-3 None The author excludes the reproduction of the work (● excluding the cinematographic work) and the reproduction (● for the work reproduced in the cinematographic work, the ● excluding the reproduction of the cinematographic work). .) Exclusively the right to provide to the public by lending. (Translation right, adaptation right, etc.) Article 27 None The author has the exclusive right to translate, arrange, transform, or dramatize the work, make it into a movie, or otherwise adapt it. (Rights of the original author regarding the use of derivative works) Article 28 None Article 29 None ● The copyright of a cinematographic work (excluding those subject to the provisions of Article 15, paragraph 1, next paragraph or paragraph 3) is the copyright of the cinematographic work by the author. If you have promised to participate in the production of a thing, you belong to the ● movie maker. 2 Produced exclusively by broadcasters as a technical means for broadcasting ● The following rights among the copyrights of cinematographic works (excluding those subject to the provisions of Article 15, paragraph 1) are: ● Belongs to the broadcaster as a movie producer. one two 3 Produced exclusively by cable broadcasters as a technical means for cable broadcasting ● The following rights among the copyrights of cinematographic works (excluding those subject to the provisions of Article 15, paragraph 1) ● Belongs to the cable broadcasting company as a movie producer. one two

Revised Civil Code Example

・ In light of contracts and other causes of claims and common wisdom in transactions ·Warranty ・ Unfulfillable


KEYWORD = 'Civil law'
wordn = 0
words = []
for n in [ 400,412,415,483, 570 ]:
    lawTextExtractor(KEYWORD, n, wordn, words)
for lawnum in range(634,641):
    lawTextExtractor(KEYWORD, lawnum, wordn, words)
    [lawTextExtractor(KEYWORD, str(lawnum)+'.'+str(i), wordn, words) for i in range(15)]
for n in [ 412 ]:
    lawTextExtractor(KEYWORD, n, wordn, words)

● Number of clauses 0 (Duty of care when delivering a specific item) Article 400 None When the purpose of the claim is the delivery of a specific item, the debtor must store the item with the care of a good manager until the delivery. ● Number of clauses 0 (Performance period and delay in performance) Article 421 None When there is a fixed deadline for the performance of an obligation, the debtor shall be liable for delay from the time the deadline is reached. 2 If there is an indefinite deadline for the performance of an obligation, the debtor will be liable for delay from the time he learns that the deadline has come. 3 If no deadline is set for the performance of the obligation, the debtor will be liable for delay from the time the request for performance is received. ● Number of clauses 0 (Compensation for damages due to default) Article 415 None If the debtor does not perform in accordance with the purpose of the debt, the creditor may claim compensation for damages caused thereby. The same shall apply when it becomes impossible to perform due to reasons attributable to the debtor. ● Number of clauses 0 (Delivery of specific items according to the current situation) Article 843 None When the purpose of the claim is the delivery of a specific item, the person making the repayment must deliver the item as it is at the time of the delivery. ● Number of clauses 0 (Seller's liability for defect warranty) Article 570 None If there is a hidden defect in the object of sale, the provisions of Article 566 shall apply mutatis mutandis. However, this does not apply to compulsory auctions. ● Number of clauses 0 (Contractor's liability) Article 634 None If there is a defect in the object of work, the orderer may request the contractor to repair the defect for a reasonable period of time. However, this shall not apply when the defect is not important and the repair requires an excessive cost. 2 The orderer may make a claim for damages in place of or in conjunction with the repair of the defect. In this case, the provisions of Article 533 shall apply mutatis mutandis. ● Number of clauses 0 Article 635 None If there is a defect in the object of work and the purpose of the contract cannot be achieved due to it, the orderer may cancel the contract. However, this does not apply to buildings and other land structures. ● Number of clauses 0 (Not applicable to the contractor's liability for collateral) Article 636 None The provisions of the preceding two Articles shall not apply when a defect in the object of work is caused by the nature of the material provided by the orderer or the instruction given by the orderer. Provided, however, that this shall not apply if the contractor does not tell, knowing that the material or instruction is inappropriate. ● Number of clauses 0 (Duration of contractor's liability) Article 637 None The repair of defects, the claim for damages, and the cancellation of the contract pursuant to the provisions of the preceding three Articles must be made within one year from the time of delivery of the object of work. 2 If delivery of the object of work is not required, the period set forth in the preceding paragraph shall be calculated from the time the work is completed. ● Number of clauses 0 Article 638 None The contractor of the building or other land work shall be liable for the defect of the work or ground for five years after delivery. However, this period shall be ten years for masonry, earthen, brick, concrete, metal and other similar structures. 2 When a work is lost or damaged due to the defect set forth in the preceding paragraph, the orderer shall exercise the right pursuant to the provisions of Article 634 within one year from the time of the loss or damage. ● Number of clauses 0 (Extension of the duration of collateral liability) Article 339 None The period set forth in Article 637 and paragraph 1 of the preceding Article may be extended by contract only within the period of extinction prescription pursuant to the provisions of Article 167. ● Number of clauses 0 (Special contract not to be liable for collateral) Article 640 None Even when the contractor makes a special provision that he / she will not be liable for collateral pursuant to the provisions of Article 634 or 635, he / she will be liable for the facts that he / she did not know to tell. I can't escape. ● Number of clauses 0 (Performance period and delay in performance) Article 421 None When there is a fixed deadline for the performance of an obligation, the debtor shall be liable for delay from the time the deadline is reached. 2 If there is an indefinite deadline for the performance of an obligation, the debtor will be liable for delay from the time he learns that the deadline has come. 3 If no deadline is set for the performance of the obligation, the debtor will be liable for delay from the time the request for performance is received.


KEYWORD = 'Civil law'
wordn = 1
words = ['Defect']
lawTextExtractor(KEYWORD, 'all', wordn, words)

~ ~

Recommended Posts

(Move / Repost) Extraction of articles containing specific words using e-Gov Law API and XML Python
[Python] Get the text of the law from the e-GOV Law API
Development and deployment of REST API in Python using Falcon Web Framework
Get the number of articles accessed and likes with Qiita API + Python
Extraction of tweet.js (json.loads and eval) (Python)
Create an easy-to-read pdf of laws and government ordinances using the law api
[Python] Automatically totals the total number of articles posted by Qiita using the API
Continue to retrieve tweets containing specific keywords using the Streaming API in Python
Anonymous upload of images using Imgur API (using Python)
List of Python code to move and remember
Try using ChatWork API and Qiita API in Python