Legal document extraction service

更新时间:
复制 MD 格式

This document describes the request and response parameters of the API for the legal document extraction service.

This service is provided by the NLP Self-Learning Platform. You can use this service by calling the API directly.

Important

To improve the extraction algorithm and preserve contextual semantics, text is now chunked by sentence. Each chunk cannot exceed 500 characters. Chinese characters, English letters, spaces, and line feeds are all counted as characters. If adding the last sentence to a chunk causes the chunk to exceed 500 characters, that sentence is moved to the next chunk. Each chunk is counted as one call. If you have more questions, join the NLP Self-Learning Platform Q&A DingTalk group (ID: 44619071) for assistance.

Service activation and resource plan purchase

You must activate the service before you can use it. After activation, purchase a resource plan.

Service invocation and testing

For more information about model invocation, see Model invocation.

For more information about SDK examples, see SDK examples.

Debugging

You can run this API operation directly in OpenAPI Explorer without needing to calculate a signature. Upon successful execution, OpenAPI Explorer automatically generates SDK code examples.

Configure access credentials (AKSK) using environment variables

  1. Notes:

    1. An AccessKey for an Alibaba Cloud account has full access to all APIs, which poses a high security threat. For improved security, create and use a Resource Access Management (RAM) user for API calls and daily O&M. To create a RAM user, log on to the RAM console.

    2. Do not hard-code your AccessKey ID and AccessKey secret in your code because this poses a security risk. Instead, configure environment variables to store and access your credentials.

  2. Configure on Linux and macOS

    export NLP_AK_ENV=<ACCESS_KEY_ID>
    export NLP_SK_ENV=<ACCESS_KEY_SECRET>

    Replace <ACCESS_KEY_ID> with your AccessKey ID and <ACCESS_KEY_SECRET> with your AccessKey secret. For more information about how to obtain an AccessKey ID and an AccessKey secret, see Step 2: Obtain an AccessKey.

  3. Configure on Windows

    1. Create a new environment variable file. Add the NLP_AK_ENV and NLP_SK_ENV environment variables and write your AccessKey ID and AccessKey secret to these variables.

    2. Restart Windows.

Note

For the legal document extraction service, set ServiceName to LegalDocumentExtraction.

Java code example

/**
 * An AccessKey for an Alibaba Cloud account has full access to all APIs, which is a high security threat. 
 * We strongly recommend that you create and use a RAM user for API calls and daily O&M. 
 * To create a RAM user, log on to the RAM console.
 * This example shows how to store the AccessKey ID and AccessKey secret in environment variables. 
 * You can also store them in a configuration file as needed.
 * We strongly recommend that you do not hard-code your AccessKey ID and AccessKey secret in your code. This can lead to security threats.
 */
String accessKeyId = System.getenv("NLP_AK_ENV");
String accessKeySecret = System.getenv("NLP_SK_ENV");
DefaultProfile defaultProfile = DefaultProfile.getProfile("cn-hangzhou",accessKeyId,accessKeySecret);
IAcsClient client = new DefaultAcsClient(defaultProfile);
String content = "{\"reqId\":\"xxx\",\"cause\":[\"Crime of intentional injury\"],\"content\":\"Body of the legal document. Be sure to keep the line feed \\n.\",\"services\":[\"normal\",\"liangxing\"]}";
RunPreTrainServiceRequest request = new RunPreTrainServiceRequest();
request.setServiceName("LegalDocumentExtraction");
request.setPredictContent(content);
RunPreTrainServiceResponse response = client.getAcsResponse(request);
System.out.println(response.getPredictResult());

Python code example

# Install dependencies
pip install aliyun-python-sdk-core
pip install aliyun-python-sdk-nlp-automl
# -*- coding: utf8 -*-
import json
import os

from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdknlp_automl.request.v20191111 import RunPreTrainServiceRequest

/**
 * An AccessKey for an Alibaba Cloud account has full access to all APIs, which is a high security threat. 
 * We strongly recommend that you create and use a RAM user for API calls and daily O&M. 
 * To create a RAM user, log on to the RAM console.
 * This example shows how to store the AccessKey ID and AccessKey secret in environment variables. 
 * You can also store them in a configuration file as needed.
 * We strongly recommend that you do not hard-code your AccessKey ID and AccessKey secret in your code. This can lead to security threats.
 */
access_key_id = os.environ['NLP_AK_ENV']
access_key_secret = os.environ['NLP_SK_ENV']

# Initialize AcsClient instance
client = AcsClient(
  access_key_id,
  access_key_secret,
  "cn-hangzhou"
);

input_params = {
        "reqId": "xxx",
        "cause": ["Crime of intentional injury"],
        "content": "Body of the legal document",
        "services":["normal","liangxing"], 
}

# Initialize a request and set parameters
request = RunPreTrainServiceRequest.RunPreTrainServiceRequest()
request.set_ServiceName('LegalDocumentExtraction')
request.set_PredictContent(json.dumps(input_params))

# Print response
response = client.do_action_with_exception(request)
resp_obj = json.loads(response)
predict_result = json.loads(resp_obj['PredictResult'])
print(json.dumps(predict_result['data']))

PredictContent example

The PredictContent parameter is passed as a JSON string. The following example shows the content of the JSON string.

{
  "reqId": "xxx",
  "cause": ["Crime of intentional injury"],
  "content": "Body of the legal document",
  "services":["normal","liangxing"]
 }

Request parameters

Parameter

Description

reqId

A custom request ID.

cause

The cause of action.

content

The body of the legal document. The value is a string.

services

The service type. `normal`: Parses standard fields. `liangxing`: Parses sentencing fields.

Note

1. The `cause` parameter supports multiple causes of action. You can pass them in a JSONArray. If the cause is unknown, pass an empty array `[]`.

2. The results for different service types can be parsed and output individually or as a merged result.

3. The service supports parsing documents for the 10 causes of action listed below. If the input cause of action is not in the list, the algorithm determines whether to output general fields for a criminal or civil case. Fields for administrative cases are not currently supported.

4. The service prioritizes the user-specified cause of action. The algorithm determines the cause of action only if the input cause is not in the supported list or is left empty.

Enumerated values for cause of action

Cause of action

Crime of causing a traffic accident

Crime of provoking trouble

Crime of intentional injury

Crime of theft

Crime of opening a casino

Crime of smuggling, trafficking, transporting, or manufacturing drugs

Crime of dangerous driving

Crime of fraud

Private lending dispute

Public interest litigation

PredictResult Content Examples

Parameter

Description

reqId

The request ID. The value is a string and corresponds to the input.

result

The result struct. The value is in JSON format.

The `result` structure is as follows:

Parameter

Description

extract

The extracted information.

laws

The legal articles extracted from the document.

segments

The segmented content of the legal document.

The enumerated values for `segments` are as follows:

segments

Litigation participant

Judge's assistant

Third-party statement

Original trial details (retrial)

Claim

Counterclaim

Title

Legal effect

Retrial details

Fact-finding

Original trial details (first-instance defense)

Original trial details (counterclaim defense)

Judgment result

Case number

Date of judgment

Original trial details (second-instance judgment)

Counterclaim defense

Original trial details (first-instance fact-finding)

Original trial details (first-instance third-party statement)

Original trial details (second-instance claim)

Trial proceedings

Appeal

Details of the challenged administrative act

Original trial details (first-instance judgment)

Court

Original trial details (second-instance third-party statement)

Other

Defense

Evidence section

Original trial details (second-instance defense)

Document type

Adjudicating personnel

Original trial details (first-instance claim)

Original trial details (counterclaim)

Original trial details (second-instance fact-finding)

Clerk

Attachment

Original trial details (protest details)

The `PredictResult` is a JSON string. You must deserialize it before parsing. The following example shows the structure.

{
    "reqId": "003",
    "result": {
        "extract": {
            "Crime of causing a traffic accident-Fled scene to evade legal pursuit": "No",
            "Crime of causing a traffic accident-Caused death by fleeing": "No",
            "Crime of causing a traffic accident-Fled the scene": "No",
            "Crime of causing a traffic accident-Overloaded": "No",
            "Crime of causing a traffic accident-Drunk or drugged driving": "No",
            "Crime of causing a traffic accident-Driving without a license": "No",
            "Crime of causing a traffic accident-Designated driver": "No",
            "Crime of causing a traffic accident-Caused death": "Yes",
            "Crime of causing a traffic accident-Caused serious injury": "No",
            "Crime of causing a traffic accident-Caused major loss to public or private property": "No",
            "Crime of causing a traffic accident-Received forgiveness from victim or family": "No",
            "Crime of causing a traffic accident-Previously handled for traffic offenses": "No",
            "Crime of causing a traffic accident-Purchased insurance": "No",
            "Crime of causing a traffic accident-Applicable for non-custodial penalties": "Yes",
            "Crime of causing a traffic accident-Vehicle met national motor vehicle safety standards": "Yes",
            "Crime of causing a traffic accident-Defendant objects to prosecution's charges": "No",
            "Crime of causing a traffic accident-Compensation amount to victim or family": [
                "CNY 238,000"
            ],
            "Crime of causing a traffic accident-Driver was driving a school bus": "No",
            "General criminal-Prosecuting authority name": [
                "People's Procuratorate of Gaobeidian City, Hebei Province"
            ],
            "General criminal-Legal articles for judgment": [
                "Article 73, Paragraph 2 of the Criminal Law of the People's Republic of China",
                "Article 72, Paragraph 1 of the Criminal Law of the People's Republic of China",
                "Article 133 of the Criminal Law of the People's Republic of China",
                "Article 67 of the Criminal Law of the People's Republic of China"
            ],
            "General criminal-Date of judgment": [
                "October 16, 2014"
            ],
            "General criminal-Issuing authority": [
                "People's Court of Gaobeidian City, Hebei Province"
            ],
            "General criminal-Adjudication panel": "Sole adjudication",
            "General criminal-Trial method": "Public hearing",
            "General criminal-Document name": [
                "Criminal Judgment"
            ],
            "General criminal-Document type": "Judgment",
            "General criminal-Document number": [
                "(2014) Gao Xing Chu Zi No. 1222"
            ],
            "General criminal-Case trial stage": "First instance",
            "General criminal-Incident location": [
                "Traveling south on old National Highway 112 to the intersection of Gaojingyuan Cemetery in Gaobeidian City"
            ],
            "General criminal-Incident time": [
                "07:40 on December 31, 2013"
            ],
            "General criminal-Defendant information": [
                {
                    "Accident liability": "Primary responsibility",
                    "Sentence": "One year and one month of fixed-term imprisonment, with a two-year probation",
                    "Is a deputy to the People's Congress or a member of the CPPCC": "No",
                    "Is a member of a democratic party": "No",
                    "Is a person related to Taiwan": "No",
                    "Is a foreign national": "No",
                    "Is a person related to Hong Kong or Macao": "No",
                    "Is a repeat offender": "No",
                    "Has mitigating circumstances for a lighter sentence": "Yes",
                    "Has aggravating circumstances": "No",
                    "Is a principal offender": "No",
                    "Is an accomplice": "No",
                    "Is a minor": "No",
                    "Is a ringleader": "No",
                    "Crime committed": [
                        "Crime of causing a traffic accident"
                    ],
                    "Special identity information": [],
                    "Fine-Specific amount": "",
                    "Fine-Paid in full": "",
                    "Defendant date of birth": "",
                    "Defendant alias": "",
                    "Defendant name": "Liu Mou",
                    "Defendant household registration": "",
                    "Defendant education level": "",
                    "Defendant ethnicity": "",
                    "Defendant current residence": "",
                    "Defendant place of origin": "",
                    "Defendant occupation": "Farmer",
                    "Charged crime": [
                        "Crime of causing a traffic accident"
                    ]
                }
            ],
            "General criminal-Violated legal articles by defendant": [],
            "General criminal-Indictment number": [
                "Gao Jian Gong Su Xing Su (2014) No. 240"
            ]
        },
        "laws": [
            {
                "lawName": "Criminal Law of the People's Republic of China",
                "provisionFullName": "Article 133 of the Criminal Law of the People's Republic of China",
                "provisionID": 133,
                "provisionName": "One hundred thirty-three"
            },
            {
                "lawName": "Criminal Law of the People's Republic of China",
                "provisionFullName": "Article 67 of the Criminal Law of the People's Republic of China",
                "provisionID": 67,
                "provisionName": "Sixty-seven"
            },
            {
                "lawName": "Criminal Law of the People's Republic of China",
                "provisionFullName": "Article 72, Paragraph 1 of the Criminal Law of the People's Republic of China",
                "provisionID": 72,
                "provisionName": "Seventy-two"
            },
            {
                "lawName": "Criminal Law of the People's Republic of China",
                "provisionFullName": "Article 73, Paragraph 2 of the Criminal Law of the People's Republic of China",
                "provisionID": 73,
                "provisionName": "Seventy-three"
            }
        ],
        "segments": {
            "Clerk": "Clerk Liu Xiukun",
            "Fact-finding": "It was also found that after the incident, both parties reached an agreement. A relative of the defendant Liu Mou compensated the victim's family for a total of CNY 238,000 in economic losses in a lump sum.\nThe defendant did not object to the above facts during the court hearing. The facts are sufficiently established and supported by evidence, including a diagram of the road traffic accident scene, on-site investigation records and photos, a forensic autopsy report, a vehicle inspection report, a road traffic accident determination report, a motor vehicle driver's license query result, a compensation mediation agreement and receipt, and the defendant's household registration certificate.",
            "Adjudicating personnel": "Judge Liu Ligang",
            "Trial proceedings": "The People's Procuratorate of Gaobeidian City filed a public prosecution with this court, accusing the defendant Liu Mou of the crime of causing a traffic accident in indictment Gao Jian Gong Su Xing Su (2014) No. 240. This court legally applied summary procedures, conducted a sole adjudication, and held a public hearing for this case. Prosecutor Zhang Zhiying and Acting Prosecutor Zhai Jing from the People's Procuratorate of Gaobeidian City appeared in court to support the public prosecution. The defendant Liu Mou appeared in court to participate in the litigation. The trial has now concluded.",
            "Document type": "Criminal Judgment",
            "Case number": "(2014) Gao Xing Chu Zi No. 1222",
            "Legal effect": "If you do not agree with this judgment, you may appeal to this court or directly to the Intermediate People's Court of Baoding City, Hebei Province within ten days from the day after receiving the judgment. For a written appeal, one original and two copies of the appeal petition must be submitted.",
            "Court": "People's Court of Gaobeidian City, Hebei Province",
            "Date of judgment": "October 16, 2014",
            "Judgment result": "This court holds that the defendant Liu Mou violated traffic and transportation management regulations, thereby causing a major accident that resulted in one death, and bears the primary responsibility for the accident. His behavior constitutes the crime of causing a traffic accident, and the charge brought by the prosecuting authority is established. After the accident, the defendant Liu Mou called the police and waited at the scene. After the public security traffic police arrived, he truthfully confessed his crime, which constitutes a voluntary surrender, and he may be given a lighter punishment according to law. Given that the defendant Liu Mou pleaded guilty and showed remorse, and his family compensated the victim's relatives for economic losses after the incident, a lighter punishment and probation may also be considered at sentencing. In accordance with Article 133, Article 67, Article 72 Paragraph 1, and Article 73 Paragraphs 2 and 3 of the Criminal Law of the People's Republic of China, the judgment is as follows:\nDefendant Liu Mou is convicted of the crime of causing a traffic accident and is sentenced to one year and one month of fixed-term imprisonment, with a two-year probation.\n(The probation period is calculated from the date the judgment becomes final.)",
            "Litigation participant": "Prosecuting authority: People's Procuratorate of Gaobeidian City, Hebei Province.\nDefendant Liu Mou, farmer. Was criminally detained by the Gaobeidian City Public Security Bureau on January 18, 2014, for this case, placed under residential surveillance by the same bureau on January 26 of the same year, and released on bail pending trial on July 26.",
            "Claim": "The prosecuting authority alleges that at approximately 07:40 on December 31, 2013, the defendant Liu Mou was driving a silver-gray Jetta sedan with license plate number Ji F××××× south on old National Highway 112. At the intersection of Gaojingyuan Cemetery in Gaobeidian City, he collided with the victim Wang Mou, who was riding an electric bicycle and turning from west to north onto the highway. The collision caused Wang Mou to be injured and die after rescue efforts failed, and both vehicles were damaged to varying degrees. After the accident, Liu Mou called the 120 emergency number and the 122 police number and waited at the scene for traffic police to handle the accident. A forensic examination determined that Wang Mou's death was consistent with craniocerebral injury combined with hemorrhagic shock caused by a traffic accident. The Gaobeidian City Public Security Traffic Police Brigade determined that the defendant Liu Mou bears the primary responsibility for this accident, and Wang Mou bears the secondary responsibility."
        }
    }
}