Intelligent legal contract generation method and device based on contract template and contract term semantics

By developing an intelligent legal contract generation method based on contract templates and contract clause semantics, and utilizing text parsing and symbolic execution technology, we have solved the problems of low automation and consistency in intelligent legal contract generation, and achieved efficient and reliable contract code generation and consistency verification.

CN120669971APending Publication Date: 2025-09-19CENTRAL UNIVERSITY OF FINANCE AND ECONOMICS
View PDF 0 Cites 3 Cited by

Patent Information

Application Number
CN202510695475.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-28
Publication Date
2025-09-19

AI Technical Summary

Technical Problem

Existing smart legal contract generation methods have low automation levels, poor template versatility, and difficulty in determining the semantic consistency between the generated contract code and the legal contract terms.

Method used

Through the intelligent legal contract generation method based on contract templates and contract clause semantics, text parsing, abstract syntax tree and symbolic execution technology are adopted to achieve automatic conversion and consistency verification from legal contracts to intelligent contracts.

Benefits of technology

It improves the automation level and legal consistency of smart legal contract generation, reduces the subjective errors caused by human intervention, and ensures the semantic consistency between contract code and legal contract.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120669971A_ABST
    Figure CN120669971A_ABST
Patent Text Reader

Abstract

The invention discloses an intelligent legal contract generation method and device based on a contract template and contract term semanteme, and belongs to the technical field of intelligent contracts, and the method comprises the steps: analyzing a legal contract text in combination with a plurality of natural language processing technologies, and constructing a contract meta-model; dynamically generating an intelligent legal contract template based on the contract meta-model; an executable intelligent legal contract code is generated through the contract template; and finally carrying out consistency check on the generated code and the original contract. Therefore, the problems of unclear structure, difficulty in semantic mapping, poor universality, law compliance and the like in the traditional process of converting the contract into the intelligent contract are solved, structured expression of the law text, automatic generation of the contract code and logic consistency verification are realized, and the generation efficiency and reliability of the intelligent law contract are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of smart contract technology, and more particularly to a method and device for generating smart legal contracts based on contract templates and contract clause semantics. Background Art

[0002] The original meaning of a smart contract is "a legally binding agreement that is transmitted, verified, or executed through information technology." It aims to solve legal contract enforcement issues through computer technology. However, with the rise of blockchain technology and platforms like Ethereum, the meaning of a smart contract has evolved to encompass computer programs that automatically execute instructions when predetermined conditions are met. In other words, in today's mainstream context, a "smart contract" is simply a computer program that automatically executes, controls, or records legally relevant events and actions according to the terms of a contract or agreement.

[0003] Therefore, while smart contracts can represent legal contracts in code and automatically execute when conditions are met, they are no different from traditional program code. They differ from legal contracts in terms of readability, ease of understanding, and legal validity. In fact, many so-called "smart contracts" are not drafted with the intent of the parties to enter into contracts, and self-executing code is not legally binding. This results in a lack of legal validity for smart contracts in practical applications, hindering their application in scenarios such as real-world transactions and payments.

[0004] To address this issue, the concept of smart legal contracts (also known as legalized smart contracts) emerged. Smart legal contracts are essentially legally compliant smart contracts. They logically and clearly translate legal contract terms into computer code, reducing flaws caused by ambiguous definitions and human error. This allows the smart contract format and its code execution to be recognized as legally valid electronic contracts. The key difference between "smart legal contracts" and current so-called "smart contracts" is that the former possesses contractual elements, includes contracting parties, and forms an offer-acceptance agreement. They are computer programs that embody the essential elements of a legal contract.

[0005] Smart legal contracts are intelligent contracts with legal attributes and automated execution capabilities. Therefore, there is a clear and consistent mapping between the smart contract code and the original legal contract text. This consistency ensures that the smart legal contract has a clear legal basis for automated execution and accurately implements the rights and obligations intended by the contracting parties. However, key challenges in current smart legal contract research remain in efficiently converting legal contracts into smart legal contracts and ensuring that the converted contract code remains highly consistent with the original contract in terms of logic, semantics, and execution results.

[0006] At present, the main ideas for generating smart legal contracts include system modeling and building contract templates.

[0007] System modeling methods construct models to describe the state changes, event trajectories, and functional behaviors of smart contracts, and then generate contract code. However, such methods generally have the problem of limited model state space. When dealing with complex terms and infinite variable scenarios, state space explosion is prone to occur, which restricts their application in complex business logic contracts.

[0008] The contract template approach originates from the concept of Ricardian Contracts. Ricardian Contracts achieve the conversion of legal terms into code and the automatic execution of contracts by defining legal terms, computer code, and the mapping relationship between the two. Specifically, the contract template approach involves defining a structured contract template based on commonly used contract templates in the legal community, with legal and computer experts then filling in parameters to generate contract code. This approach can effectively improve development efficiency and is more intuitive and convenient to use than methods such as system modeling, making it suitable for more complex business contract scenarios. However, current contract templates also have certain shortcomings. For example, flexibility is limited when processing new contracts, and the cost of modifications is high when contract terms or logic change. This, to a certain extent, limits the automation level and versatility of the contract template approach.

[0009] Natural language processing (NLP) technology can assist in the generation of contract templates. For example, named entity recognition (NER) can automatically extract key entity information from contract text, improving the automation level of the transition from legal text to contract template generation. However, a fully automated conversion solution from templates to executable code is currently lacking. Furthermore, current contract template approaches still require significant manual intervention to understand and express the complex logic and semantics of contract terms, making it difficult to achieve full automation of the construction of smart legal contracts.

[0010] Furthermore, ensuring consistency between the generated smart legal contract code and the original legal contract remains a key issue in current research. "Consistency" refers to the precise correspondence between the contract code's behavior, execution logic, and execution results and the legal provisions of the contract text. Currently, technologies such as symbolic execution have been applied to contract code verification, but simple code verification alone cannot effectively guarantee that the code execution process strictly adheres to the legal intent of the original contract.

[0011] Therefore, developing a method and device for intelligent legal contract generation that effectively improves the automation level of intelligent legal contract generation and significantly enhances the semantic consistency of the generated code with legal contract clauses has become a pressing technical problem. To address these existing technical issues, the present invention proposes a method and device for intelligent legal contract generation based on contract templates and contract clause semantics. This approach improves the automation level and legal consistency of contract generation, effectively addressing the shortcomings of existing technical solutions. Summary of the Invention

[0012] In light of this, the present invention provides a method and apparatus for generating intelligent legal contracts based on contract templates and contract clause semantics. This approach addresses existing intelligent legal contract generation solutions, including low automation, poor template versatility, and difficulty ensuring semantic consistency between the generated contract code and the legal contract. This invention significantly improves the efficiency, versatility, and legal compliance of intelligent legal contract generation, while reducing subjective errors caused by manual intervention.

[0013] To achieve the above object, the technical solution adopted by the present invention is:

[0014] In a first aspect, the present invention provides a method for generating an intelligent legal contract based on a contract template and the semantics of contract terms. The method mainly includes:

[0015] The contract construction phase realizes the generation of smart legal contracts from legal contracts, including contract template generation and contract code generation.

[0016] In the contract template generation phase, by parsing the legal contract text, the original contract key information and business rules are obtained, structured data is generated, and a standardized contract meta-model is constructed based on the data to keep the original contract structure consistent with the business logic. On this basis, the contract template is dynamically generated to achieve the generation of intelligent legal contract templates consistent with the legal contract;

[0017] In the contract code generation phase, based on the constructed contract template, abstract syntax tree technology and mapping rules are used to fill in the contract template execution function skeleton and further optimize the business logic code to achieve the transformation from the contract template to the executable smart legal contract code;

[0018] During the contract verification phase, the obtained smart legal contract is subjected to consistency verification. The execution path of the contract under different input conditions is simulated based on symbolic execution technology, and the conditions of each path, state changes and execution results are recorded to verify the consistency of the execution path, execution results and business logic between the generated smart legal contract code and the original legal contract.

[0019] Furthermore, in a preferred embodiment of the present invention, the legal text parsing in the contract template generation step specifically includes:

[0020] The legal contract text is subjected to text preprocessing, entity information extraction, clause segmentation and structure analysis, intent recognition and business logic extraction to obtain structured data of the legal contract text.

[0021] Furthermore, in a preferred embodiment of the present invention, the specific method for extracting entity information includes:

[0022] A rule-based named entity recognition method is used to extract key entity information such as contract number, contract title, contract party (such as Party A, Party B), signing date and contract amount.

[0023] Furthermore, in a preferred embodiment of the present invention, clause segmentation and structural analysis specifically include:

[0024] Match rules based on clause identifiers in the contract text to automatically segment clauses and subclauses;

[0025] Dependency parsing technology is used to analyze the syntactic structure in the contract text, identify clause boundaries, sub-clause relationships, and conditional judgment logic within clauses, clarify clause boundaries and the hierarchical relationship between clauses, and identify the core actions in each clause.

[0026] Furthermore, in a preferred embodiment of the present invention, intent recognition and business logic extraction specifically include:

[0027] Based on the large language model, the intent of the clauses describing business rules in the contract text is recognized, and the conditions for business execution and corresponding action descriptions are extracted. In particular, for clauses with ambiguous or complex logic, clear conditional judgments and business logic information are extracted for their structured representation.

[0028] Furthermore, in a preferred embodiment of the present invention, the contract metamodel construction step specifically includes:

[0029] The structured data obtained during the legal text parsing phase is mapped according to predefined contract metamodel structure specifications. The metamodel includes basic contract information, information about the parties, business extension data, and clause structure. Each clause and its subclauses contain a text summary, key fields, and business logic data, such as amount, conditions, and action descriptions.

[0030] Through the data verification mechanism, the accuracy of the constructed meta-model fields in terms of data integrity, logical consistency and format standardization is verified.

[0031] Furthermore, in a preferred embodiment of the present invention, the dynamic generation of the contract template specifically includes:

[0032] Determine the corresponding clause structure and execution logic framework in the contract template based on the structure of the contract meta-model;

[0033] Using the template engine tool, we traverse each clause and sub-clause in the meta-model, retain the original contract summary and key data in the form of comments in the template, generate the corresponding execution function skeleton, and use the business logic data in the meta-model to fill in the code placeholders, thus obtaining a smart legal contract template containing the original contract clause comments, function skeleton and business logic placeholders.

[0034] Furthermore, in a preferred embodiment of the present invention, the contract code generation step specifically includes:

[0035] Use Solidity's abstract syntax tree tool or a custom parser to traverse the contract template, identify the clause nodes in the contract template, and build a complete business logic code framework;

[0036] According to the preset mapping rules and contract metamodel data, the business logic placeholders in the template are converted into corresponding code snippets in the smart contract language (such as Solidity);

[0037] The generated contract code is checked for code compliance and partially optimized to obtain a complete smart legal contract code.

[0038] Furthermore, in a preferred embodiment of the present invention, the consistency check specifically includes:

[0039] Use symbolic execution technology to symbolize key variables in the generated smart contract code, simulate the contract's execution path under different input conditions, and record each path's conditions, state changes, and execution results;

[0040] The results of symbolic execution are compared and analyzed one by one with the original business logic in the corresponding clauses of the contract metamodel to verify the consistency of the generated contract code with the original legal contract text in terms of semantics, logic and execution results.

[0041] In a second aspect, the present invention further provides a device for generating an intelligent legal contract based on a contract template and contract clause semantics, which applies the aforementioned method for generating an intelligent legal contract based on a contract template and contract clause semantics. The device includes:

[0042] The contract template generation module is used to perform structured analysis on the input legal contract text, extract key information and business logic, and generate a standardized contract meta-model. Based on the meta-model data, it dynamically generates an intelligent legal contract template containing the original contract information and the execution function skeleton.

[0043] The contract code generation module is used to convert the placeholders in the contract template into smart contract code based on the abstract syntax tree technology and mapping rules, thus realizing the conversion from the template to the executable contract code;

[0044] The consistency verification module is used to verify the consistency of the execution path, execution results and business logic between the generated smart contract code and the legal contract text based on symbolic execution technology.

[0045] Furthermore, in a preferred embodiment of the present invention, the contract template generation module includes:

[0046] Text parsing unit, used for contract text preprocessing, entity information extraction, clause segmentation and structure analysis, intent recognition, and business logic extraction;

[0047] A metamodel building unit, used to build and verify a contract metamodel based on structured data;

[0048] The template generation unit is used to dynamically generate contract templates based on the template engine.

[0049] Furthermore, in a preferred embodiment of the present invention, the contract code generation module includes:

[0050] Template parsing unit, used to parse the contract template according to the abstract syntax tree and identify the business logic nodes;

[0051] The code mapping unit is used to convert the template placeholder into smart contract code based on the mapping rules;

[0052] The code optimization unit is used to check and optimize the contract code.

[0053] Furthermore, in a preferred embodiment of the present invention, the consistency check module includes:

[0054] Symbolic execution unit, used to simulate the contract execution path and record the conditions and state changes of each path;

[0055] The consistency analysis unit is used to compare the symbolic execution results with the original contract terms and verify the consistency between the contract code and the contract.

[0056] In a third aspect, the present invention also provides an electronic device comprising a processor and a memory, wherein the memory stores machine-executable instructions that can be executed by the processor, and the processor executes the machine-executable instructions to implement the above-mentioned method for generating an intelligent legal contract based on a contract template and contract clause semantics.

[0057] Compared with the existing technology, the present invention provides a method for generating smart legal contracts based on contract templates and contract clause semantics, which has at least the following beneficial technical effects:

[0058] 1. This invention achieves automated conversion of contracts into smart contracts through contract structure and semantic feature analysis, effectively improving the accuracy and reliability of smart contract generation and reducing manual intervention and technical barriers.

[0059] 2. This invention uses a combination of natural language processing technologies to extract the semantics of contract terms in legal contract texts and automatically generate contract templates, effectively reducing the subjective errors that may occur when manually writing templates;

[0060] 3. This invention improves the applicability of the template method by constructing a standardized contract metamodel and dynamically generating contract templates. It also uses abstract syntax tree technology and mapping rules to automatically convert templates into code, significantly improving the automation level of contract generation.

[0061] 4. This invention uses symbolic execution methods for consistency verification, effectively ensuring the consistency of the smart legal contract code with the original legal contract in terms of semantics, business logic and execution results, significantly improving the legal compliance and credibility of the smart legal contract.

[0062] Other features and advantages of the present invention will be described in the following description, and part of them will become obvious from the description, or will be understood by practicing the present invention. The purpose and other advantages of the present invention can be realized and obtained by the structures particularly pointed out in the written description and the accompanying drawings.

[0063] The technical solution of the present invention is further described in detail below through the accompanying drawings and embodiments. BRIEF DESCRIPTION OF THE DRAWINGS

[0064] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, a brief introduction will be given below to the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0065] The accompanying drawings are used to provide further understanding of the present invention and constitute a part of the specification. They are used to explain the present invention together with the embodiments of the present invention and do not constitute a limitation of the present invention.

[0066] Figure 1 This is a schematic diagram of the overall process of the method for generating an intelligent legal contract based on the contract template and the semantics of the contract terms in an embodiment of the present invention;

[0067] Figure 2 This is a schematic diagram of the specific process of generating a contract template in an embodiment of the present invention;

[0068] Figure 3 This is a schematic diagram of the specific process of legal text parsing and an example of the results in accordance with an embodiment of the present invention;

[0069] Figure 4 This is an example diagram of a contract metamodel in an embodiment of the present invention;

[0070] Figure 5 This is a flowchart of the dynamic generation of contract templates and an example of the results in accordance with an embodiment of the present invention;

[0071] Figure 6 This is a schematic diagram of the specific process of contract code generation in an embodiment of the present invention and an example of the results;

[0072] Figure 7 This is a schematic diagram of a specific process of the consistency check step in an embodiment of the present invention;

[0073] Figure 8 Schematic diagram of the structure of an intelligent legal contract generation device based on contract templates and contract clause semantics in an embodiment of the present invention;

[0074] Figure 9 Schematic diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0075] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments.

[0076] In describing the present invention, it should be noted that some processes described in this specification and accompanying drawings include multiple operations that appear in a specific order. However, it should be understood that these operations may be performed in a different order than the order in which they appear, or may be performed in parallel. Furthermore, the use of various sequence numbers is for descriptive purposes only and should not be construed as indicating or implying relative importance.

[0077] Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the invention as claimed, but merely represents selected embodiments of the present invention. All other embodiments derived by persons of ordinary skill in the art based on the embodiments of the present invention without creative effort shall fall within the scope of protection of the present invention.

[0078] See also Figure 1 As shown, an embodiment of the present invention provides a method for generating an intelligent legal contract based on a contract template and contract clause semantics. The method mainly includes the following steps:

[0079] In step S101, contract template generation is performed;

[0080] In step S102, contract code generation is performed;

[0081] In step S103, a consistency check of the smart legal contract is performed.

[0082] The following combination Figures 2 to 7 Describe in detail how to implement each step:

[0083] As a preferred embodiment of the present invention, refer to Figure 2 As shown in the figure, the specific process of generating a contract template includes:

[0084] In step S201, the legal text is structurally parsed;

[0085] In step S202, a contract meta-model is constructed based on the parsing result;

[0086] In step S203, a smart legal contract template is dynamically generated based on the contract meta-model.

[0087] The specific process of legal text analysis in step S201 is as follows: Figure 3 Shown, including:

[0088] 1. In legal text parsing, due to the diverse sources, types, and forms of legal contracts, there will be differences in format, typesetting, punctuation, etc. Therefore, the input original contract text needs to be pre-processed to perform format standardization and remove redundant characters and symbols to facilitate subsequent entity information extraction;

[0089] 2. Use a named entity recognition method based on regular expressions to automatically extract the contract number, contract title, signing date, contract amount, and information about the parties to the contract (such as Party A and Party B) from the contract text; the specific operations are as follows:

[0090] Based on an analysis of sample Chinese contracts, we predefine possible representations for various key information types. For example, for a contract number, possible representations include "Contract Number:" or "Number:," followed by a string of numbers or letters. Similarly, the amount field is often prefixed with "RMB" or "¥," while the date field might appear in formats such as "May 20, 2023" or "2023-05-20." In these cases, we can construct corresponding regular expression matching patterns based on these field representations.

[0091] For example, to extract the contract number, a regular expression like "Contract Number[::]?\s*([A-Za-z0-9\-]+)" can be used to identify the contract number string. To extract the amount, a similar expression like "(?:RMB|¥|¥)\s*([0-9,]+(?:\.\d{1,2})?)\s*(RMB|10,000 Yuan|RMB)?" can be used to extract the numeric amount and unit. This is a regular expression-based matching of the contract text. If a match is found, the matched content is identified as the target field and recorded in the structured results.

[0092] This solution is lightweight, efficient, and easy to deploy. It doesn't rely on pre-trained models or external knowledge bases, and can complete the structured processing of contracts with minimal computing resources. Furthermore, it supports flexible rule expansion and can be customized to meet the needs of different types of contract texts.

[0093] 3. Using rule matching combined with dependency parsing technology, we identify the hierarchical structure of contract clauses and subclauses and segment the contract text into structured clause information. The specific working principle is as follows:

[0094] Most contract texts in Chinese contracts follow specific format specifications. Although there are many types of contracts and the scope of entities covered and business logic vary, they still have similarities in the writing structure.

[0095] Therefore, we can first match and identify the clause numbering rules. By presetting a variety of common contract clause numbering rules, such as digital numbers ("1.", "1.1," "1.1.1"), Chinese numbers ("Article 1," "One," "(One)," "①"), etc., we can traverse and match the contract text to identify all text segments with clause numbering features as candidate sets for clause titles. Subsequently, we can judge the hierarchical relationship of the clauses based on the hierarchical features in the numbering (such as the number of dots, "clause" and "sub-clause" identifiers, nested brackets, etc.), and identify the clause hierarchy. For example, "Article 2" is a first-level clause, "2.1" is its subordinate sub-clause, and "2.1.1" is a second-level sub-clause.

[0096] For paragraphs that are not explicitly numbered but have clause semantics, this paper introduces dependency parsing technology to assist in identifying them. This technology analyzes the dependencies between words within a sentence to determine whether a paragraph is an independent clause, a supplementary explanation of a previous clause, or an ancillary content, thereby avoiding structural misjudgments and improving the accuracy and completeness of clause segmentation.

[0097] In specific implementations, a Chinese dependency parsing model from existing natural language processing tools can be used to parse the target paragraph. This embodiment uses spaCy's pre-trained Chinese parsing model as a syntactic analysis tool, which can annotate dependencies between the subject, predicate, object, and modifiers in a sentence. This model can identify core words in a sentence and display the syntactic connections between other words and the core word, such as subject-predicate relationships, attributive-predicate relationships, and adverbial-predicate relationships.

[0098] When structures such as "this article states", "as listed above", "the following clauses" appear in a paragraph, and the dependency analysis results show that it is semantically dependent on the previous clause, it will be classified as the subsidiary content of the clause; if the syntactic structure is complete, the core predicate is independent, and there is no obvious dependency relationship with the previous text, it can be determined as the beginning of a new clause or sub-clause.

[0099] By combining dependency syntactic analysis with clause numbering rule matching, this method can accurately model the hierarchical structure of contract clauses, which is expected to improve the semantic accuracy and scope of applicability of structured processing.

[0100] 4. Use a large language model to identify the intent of the segmented contract terms, extract the business logic and term semantics, and obtain condition judgments, action descriptions, and related business values;

[0101] In this step, the large language model is used to perform semantic analysis on the input natural language contract terms, focusing on business-related conditional judgments, action descriptions, and numerical parameters.

[0102] In the specific implementation, this paper uses the DeepSeek large language model API as a semantic analysis tool. This model has strong context understanding and business rule reasoning capabilities, and can effectively perform intent analysis tasks in complex sentence structures. The workflow of this method is as follows:

[0103] The text of the structured clause is used as input text, and a standardized prompt template is used to guide the model to perform semantic recognition tasks. The prompt statement can be arbitrarily written according to actual needs, for example, "Please extract from the following contract terms: (1) conditional judgment (such as "if...", "when..."); (2) action description (such as "should be performed", "right to terminate"); (3) numerical parameters (such as time, amount, ratio, etc.). The content of the clause is as follows: {}". When calling the large model, you can also use prompt statements to require the model to unify the format of the returned results, such as standardizing time units, amount units, etc. Call the large language model through the API, input the clause text and task prompts into the model together, and the model will return structured semantic extraction results.

[0104] The large language model described in the present invention can be flexibly replaced according to actual deployment requirements. In addition to the DeepSeek model used in the embodiment, this method can also use other large models with Chinese processing capabilities, such as ChatGLM, Qwen, etc.

[0105] Furthermore, this method does not restrict how large models are deployed. For example, to protect information, developers can deploy large models locally, ensuring they comply with instructions and understand contextual semantics to complete the same semantic parsing task. Therefore, the legal text parsing process of this invention offers excellent model adaptability and scalability, independent of specific vendors or model implementations.

[0106] 5. Integrate the above analysis results into JSON format structured data to provide a standardized data foundation for the construction of the contract metamodel.

[0107] It should be noted that the reason why the regular expression-based named entity recognition method is used to process Chinese contract texts in the embodiment of the present invention is as follows: Taking Chinese contract texts as an example, contracts usually have a relatively fixed format and structure, and the terms, numbers, dates, amounts and other information therein show a certain regularity in the document. Regular expressions can be used to quickly match and extract these key information with clear formats, reducing the dependence of complex models on large-scale annotated data, thereby having higher efficiency and stability in actual projects. In addition, the rule-based and dictionary-based methods can achieve higher accuracy in specific corpora because they formulate rules according to specific fields, and have been proven to achieve better results in specific fields (such as document information extraction in the legal field, etc.). However, the regular expression-based named entity recognition method is only an optional option for implementing the method of the present invention, that is, the embodiment of the legal text parsing step of the present invention can also adopt other named entity methods (such as named entity recognition methods based on statistical models, named entity recognition methods based on deep learning models) to automatically extract contract-related information from the contract text.

[0108] Similarly, the embodiments of the present invention do not limit the specific dependency parsing model and large language model used. Developers can freely choose the type of model used in legal text parsing based on actual scenarios and needs, and are not limited to the named entity recognition model used in this embodiment.

[0109] The contract meta-model in step S202 is as follows Figure 4 As shown, the specific construction process is as follows:

[0110] 1. Define a standardized contract metamodel data structure, including basic contract information (contract number, contract title, signatory information, etc.), clause and sub-clause structure, and business logic fields (amount, interest rate, default conditions, operation description, etc.);

[0111] 2. Based on the structured data generated during the legal text parsing phase, the data is mapped one by one into the contract metamodel using mapping rules;

[0112] In this invention, mapping rules are a set of definitions used to accurately map the structured data generated during the legal text parsing phase to corresponding fields in the contract metamodel. This rule system clearly defines the mapping path between structured fields and metamodel fields, supporting processing logic such as field value conversion, format specification, regular expression matching, and default value filling, serving as a bridge between the parsing module and the template generation module.

[0113] In this embodiment, the mapping rules are written according to the data structure of the contract metamodel and the actual situation of the structured data fields, and are saved and loaded using JSON format configuration files to support module reuse, parameter modification and rule expansion.

[0114] Mapping rules need to specify the data source, target field, and conversion method. Each mapping rule usually contains the following basic elements, as shown in Table 1:

[0115] Table 1 Basic elements

[0116]

[0117] Mapping rule types include entity mapping rules, structure mapping rules, and logical mapping rules. The setting of this field is intended to facilitate the maintenance and expansion of the rule set and does not affect the execution logic of the mapping.

[0118] Among them, the entity mapping rules are used to directly map the entities extracted from the structured data (such as contract number, signing date, amount, name of Party A and Party B, etc.) to the corresponding fields in the metamodel; the structure mapping rules are used to maintain the hierarchical structure in the structured contract data (such as the nested relationship between clauses and sub-clauses) and nest them into the metamodel structure; the logic mapping rules are used to process the conversion between the extracted semantic logic (such as conditions, actions, values) and the metamodel, such as format conversion, regular parsing, Boolean judgment and other operations.

[0119] In actual implementation, the system completes the mapping operation according to the mapping rules in the configuration file, following a pipelined approach: "field path reading → regular expression matching (if any) → value conversion (if any) → filling metamodel fields." Each rule is executed individually, ultimately filling in the complete contract metamodel structure item by item.

[0120] For example, to map the clause "This card cannot be gifted" to the "Can Be Gifted" field in the contract metamodel, set the businessModel.canBeGifted field during metamodel data structure design. A false value indicates that the card cannot be gifted. Then, set the corresponding mapping rule, for example: {"target":"businessModel.canBeGifted","type":"logic","pattern":"This card[\\s,、]*(?:cannot be gifted|cannot be transferred)","valueIfMatched":false,"valueIfNotMatched":true} This rule states: If the content in the source field matches the regular expression "This card cannot be gifted," set the canBeGifted field to false; otherwise, set it to true. After the mapping is executed, the metamodel field value "businessModel":{"canBeGifted":false} is obtained, completing the conversion from structured contract data to the metamodel.

[0121] 3. Verify the metamodel data to ensure that the required fields in the contract metamodel are filled in and the format is standardized, thereby ensuring the consistency of the metamodel with the original contract.

[0122] The contract metamodel is designed to include both the structural information of the original contract (such as the contract number, title, parties, clauses, subclauses, etc.) and the business logic extracted from the contract (such as the amount, interest rate, conditional judgment, action description, etc.). The contract structure includes the basic contract information and the clause hierarchy, which ensures that the format, clause division, and hierarchical relationships of the contract text are fully preserved. The business logic section, on the other hand, contains the specific business rules within the contract extracted using the previous NLP method. This information is stored in the business logic field under the corresponding clause or subclause.

[0123] Specifically, when building the metamodel, the parsed contract data is first read and an empty metamodel data structure is initialized, presetting the necessary fields. The basic contract information is then directly mapped into the metamodel. Each clause in the contract is then traversed, creating a corresponding clause node for each clause and processing its subclauses. When processing each subclause, the subclause description and content are first extracted, and the presence of specific business rules is checked. If so, the corresponding values ​​or logical conditions are filled into the business logic fields. Finally, the generated metamodel is validated to ensure that all required fields are complete and formatted correctly.

[0124] To ensure the integrity, standardization, and consistency of the contract metamodel data generated and converted from legal text parsing, this paper designs a systematic metamodel data validation method. This method checks the existence, format, hierarchical structure, and semantic logic of each model field, ensuring that the generated metamodel accurately reflects the original contract content and providing a reliable foundation for the subsequent generation of contract templates.

[0125] The first step is to verify the integrity of required fields. The metamodel's data structure includes certain required fields, such as the contract number, contract parties, clause number, and clause content. The verification process verifies each of these fields to ensure they are empty or missing, ensuring the minimum level of information completeness in key contract metamodel attributes. For example, if the contract number field is empty, the subsequent process will be aborted and an error message will be logged, stating "Contract number cannot be empty."

[0126] The second step is data format compliance verification. Sensitive fields involving information such as dates, numbers, and percentages require format verification to ensure the data is in the legal format and units. For example, all date fields must conform to the standard "YYYY-MM-DD" format, amount fields must be positive integers in the unit of "yuan," and interest rate fields must be within a reasonable range of 0% to 100%. This verification is implemented through regular expressions or data type judgment, effectively avoiding interference caused by format errors in contract logic generation.

[0127] The third is clause structure consistency verification. This verifies the hierarchical relationship between clauses and their subclauses, ensuring that each subclause has a corresponding parent clause, that its numbering structure is continuous and logically consistent, that there are no duplicates at the same level, and that clause numbers adhere to naming conventions. For example, if a subclause numbered "2.1.1" exists but a parent clause numbered "2.1" is not detected, a structural exception error will be thrown. This verification mechanism ensures that the complex nested structure in the original contract is accurately restored in the metamodel.

[0128] The fourth is semantic association verification, which checks the relevance and rationality of business logic fields. For example, if a clause contains a "liquidated penalty" field, it will be checked for related "default conditions." If a clause sets a "payment time limit," it will be confirmed whether it corresponds to a clear payment action. Conditions and actions in the same clause should not be empty or conflicting. This verification ensures the accurate expression of contract semantics in the metamodel.

[0129] The metamodel constructed through the above steps not only reflects the structure of the original contract text but also includes the explicit or implicit business logic data in the contract, thereby maintaining consistency with the original contract content. Every field, clause, and business rule in the metamodel can be traced back to the corresponding text in the contract. As long as the mapping rules are correct and the data extraction is accurate, the original contract and the metamodel are one-to-one corresponding and consistent in content. Therefore, the constructed metamodel is highly consistent with the original legal contract in terms of structure, logic, and semantics.

[0130] The specific process of dynamically generating the contract template in step S203 is as follows: Figure 5 Shown, including:

[0131] 1. Use the contract metamodel to determine the overall structure of the smart contract template, including the contract header information, clauses, and sub-clause function skeletons;

[0132] 2. Based on the template engine, the contract metamodel data is traversed to automatically generate clause numbers, clause content annotations, and corresponding execution functions in the template file;

[0133] 3. Fill the parameter placeholders of the business logic inside the function and retain the original comments of the terms for easy maintenance and reuse;

[0134] 4. Output and generate a smart legal contract template with Solidity-like syntax, providing a basis for subsequent generation of contract code.

[0135] The core of the present invention's dynamic generation of contract templates lies in generating corresponding contract templates based on the extracted contract structure information, without the need to manually write templates for each contract type in advance. The advantage of this method is that once the parsing and mapping models and rules are built, it can support the automatic conversion of multiple types of contracts without the need to write separate templates for each contract. When faced with a new contract, it only requires the legal text to be parsed successfully to identify its structure and map it to the contract metamodel. The subsequent template generation and code generation links can then be automatically adapted, without the need to manually write a set of contract templates for each type of contract. This not only greatly reduces the risk of manual coding, but also improves the reusability and flexibility of the template, and can quickly adapt even when the contract terms change.

[0136] By loading the contract metamodel generated in the previous stage, passing the obtained data information to the customized contract template framework, using the template engine to traverse the contract metamodel data, and replacing the placeholders in the template, it is possible to generate a function framework for each clause and sub-clause that retains the original contract clause as an annotation, and at the same time fill in the corresponding code logic according to business rules.

[0137] This embodiment adopts a template syntax similar to the template engine Jinja2 in the design of the template file. Its basic structure includes a contract header (including basic contract information variables, constructors, etc.), clause comments and function skeletons, and business logic filling. Among them, for each clause, the template first outputs the clause comments, records the clause number and title; then, generates a corresponding execution function for each sub-clause. A default business logic code segment is preset inside the function. If the corresponding sub-clause in the metamodel contains key business data, the corresponding code is filled in, otherwise the default placeholder is inserted. At the same time, multiple placeholders are reserved in the template file for subsequent generation of corresponding code based on the business logic of each sub-clause in the metamodel.

[0138] The generated template not only embeds the basic contract information and clause summaries in the form of annotations, but also generates execution function skeletons for each clause node. The reserved placeholders in the template are automatically filled with business rule data parsed from the metamodel, forming a combination of fixed logic and variable parameters, which facilitates future reuse of similar businesses.

[0139] It should be noted that the "Solidity-like syntax" mentioned in this step is merely a template format used in this embodiment. Its purpose is to facilitate the subsequent generation of smart legal contract code written in Solidity, a universal smart contract language. If developers wish to generate contract code in other languages ​​for specific scenarios, they can similarly switch to templates in other formats. Similarly, this embodiment uses the Python-based Jinja2 template engine, but this does not restrict developers from choosing other similar template engine tools based on their own development environment.

[0140] As a preferred embodiment of the present invention, refer to Figure 6 As shown, the specific process of generating the contract code in step S102 includes:

[0141] 1. Read the contract template, parse it using an abstract syntax tree tool, and record the structured node information of the code, such as variable declarations, function definitions, and comments;

[0142] 2. Use the template engine tool to automatically replace the business logic placeholders in the template file with specific business logic code snippets based on predefined code mapping rules;

[0143] In a preferred embodiment of the present invention, contract code generation relies on the Jinja2 template engine for template rendering. Jinja2 is a lightweight, highly scalable text template engine based on Python. It supports a variety of functions such as variable substitution, conditional judgment, and loop structures, and can dynamically generate structured and executable contract code text.

[0144] Similar to the field mapping mechanism used during metamodel conversion, the code mapping rules proposed in this invention are a set of rules for accurately mapping and injecting structured fields from the contract metamodel into placeholders within the smart legal contract template file. Using a template engine tool, this rule set, combined with variable substitution, conditional judgment, and format conversion, can automatically convert contract business logic and contract templates into executable contract code statements.

[0145] In this embodiment, code mapping rules are configured based on the contract metamodel's field structure and placeholder variables defined in the contract template. These rules are stored in a unified JSON format as a configuration file to support unified management, loading, maintenance, and version control of the rules. Of course, the Jinja2 template engine and the present invention's method do not inherently rely on or mandate the use of JSON to write mapping rules. This format was chosen primarily for its versatility and compatibility, driven by the need for configurable and modular management in engineering practice.

[0146] The mapping rules in this embodiment are designed for the Solidity language, adapting to code generation tasks in mainstream scenarios. For other contract languages ​​(such as Vyper, Rust, etc.), developers can also customize the corresponding template structure and mapping rules based on the framework of this invention, with good cross-language scalability.

[0147] Each mapping rule must clearly specify the variable placeholder name in the template, the data source field path, and optional conversion functions and rendering conditions. The basic structure of the code mapping rule is shown in Table 2:

[0148] Table 2 Basic structure of code mapping rules

[0149]

[0150] During the actual execution process, the mapping rules in the configuration file will be read, and rendering will be performed according to the pipeline mode of "field path reading → conversion processing (if any) → condition judgment (if any) → replacement of template placeholders". Finally, the template engine will inject the generated context data into the preset placeholder position in the template file and output a complete and structured contract code text.

[0151] For example, let's replace the clauses[2.1].logic.time_limit="15 working days" field in the contract metamodel with the template variable payment_deadline. The template file reserves the following variable placeholder: uint256paymentDeadline={{payment_deadline}}, with the mapping rule: {"placeholder":"payment_deadline","source":"clauses[2.1].logic.time_limit","transform":"to_seconds"}. Here, to_seconds is a transformation function that converts "15 working days" to the number of seconds, 1296000. After the template is rendered, the contract code "uint256 paymentDeadline=1296000;" is automatically generated.

[0152] Through the automatic connection mechanism of "metamodel field → mapping rule → template variable → contract code" mentioned above, it is possible to batch process the placeholders in the template file based on unified mapping rules, realize the conversion of contract template into smart legal contract code, and ensure that the generated contract code has a standardized structure, complete semantics, and logical executable.

[0153] 3. Perform local optimization and structural reconstruction on the replaced code, such as variable naming standardization, code block optimization, and smart contract syntax checking. After the above automatic conversion and optimization steps, a complete smart contract code file can be obtained.

[0154] 4. Output smart legal contract code files that meet the common language requirements of smart contracts, ensuring that the contract code accurately reflects the business logic and clause semantics of the contract.

[0155] As a preferred embodiment of the present invention, refer to Figure 7 The specific process of consistency verification of the smart legal contract in step S103 includes:

[0156] 1. First, use symbolic execution tools to perform path analysis on the generated smart contract code, enumerate all possible execution paths, and record the output results and contract status changes under each path, so as to fully obtain the contract's operating behavior information.

[0157] 2. Based on the acquired path data, multiple consistency evaluation indicators are further calculated to quantitatively analyze the correspondence between the smart contract code and the original legal contract at the semantic, logical, and execution levels. The main consistency indicators compared during the consistency test in this embodiment of the present invention include:

[0158] ① Execution path consistency: measures whether the execution path in the smart contract code is consistent with the expected logical path in the legal contract;

[0159] ② Execution result consistency: Evaluate whether the output results under each execution path are consistent with the execution results stipulated in the contract terms;

[0160] ③State consistency: Verify whether the state changes of the contract after each operation comply with the state transition rules specified in the contract;

[0161] ④ Clause coverage: reflects the degree to which the execution function in the current contract code covers the executable clauses of the original contract, ensuring that all key clauses have corresponding implementation logic;

[0162] ⑤ Path detection error rate: Count the proportion of contract code that has logical conflicts, undefined behaviors, or potential abnormal paths during symbolic execution, thereby evaluating code security and potential risks.

[0163] 3. Compare and analyze the consistency between the smart contract code and the contract text using the aforementioned indicators. If all indicators meet the preset standards, the generated smart contract can be considered to accurately reflect the business logic and legal semantics of the original legal contract. If it is found that some indicators do not meet the standards, the specific differences will be reported, and it will be necessary to return to the previous stage for code correction and structural optimization until the generated code meets the consistency requirements.

[0164] From the description of the above embodiments, those skilled in the art can understand that: the present invention provides a method for generating smart legal contracts based on contract templates and contract clause semantics, which effectively realizes the automatic generation of smart legal contract code from legal contract text, ensures the correctness and compliance of the business logic of the generated smart legal contract, lowers the technical threshold for the design and implementation of smart legal contracts, and improves the reliability and applicability of smart legal contracts in actual legal scenarios.

[0165] Furthermore, if Figure 8 As shown, corresponding to the above method, this embodiment also provides an intelligent legal contract generation device 10 based on contract templates and contract clause semantics, which mainly includes:

[0166] The contract template generation module 101 is used to execute step S101;

[0167] The contract code generation module 102 is used to execute step S102;

[0168] The consistency checking module 103 is configured to execute step S103.

[0169] Furthermore, if Figure 8 As shown, the contract template generation module 101 mainly includes:

[0170] The legal text parsing submodule 1011 is used to perform structured parsing of legal texts;

[0171] The contract metamodel construction submodule 1012 is used to construct a contract metamodel based on the structured data;

[0172] The contract template dynamic generation submodule 1013 is used to dynamically generate smart legal contract templates.

[0173] An embodiment of the present invention provides an intelligent legal contract generation device based on contract templates and contract clause semantics. Its implementation principle and technical effects are the same as those of the aforementioned method embodiment. For the sake of brief description, for parts not mentioned in this embodiment, please refer to the corresponding content in the aforementioned method embodiment, and no further details will be given here.

[0174] In addition, refer to Figure 9 As shown, an embodiment of the present invention further provides an electronic device, which may include a processor, a memory, a communication bus, and a communication interface, and may also include a computer program stored in the memory and run on the processor, and the processor executes the computer program to implement the smart legal contract generation method based on the contract template and contract clause semantics in the above method embodiment.

[0175] In some embodiments, the processor may be comprised of an integrated circuit, such as a single packaged integrated circuit or a combination of multiple packaged integrated circuits with the same or different functions, including one or more central processing units (CPUs), microprocessors, digital processing chips, graphics processors, and various control chips. The processor is the control core of an electronic device, connecting the various components of the entire electronic device using various interfaces and circuits. It executes programs or modules stored in memory and accesses data stored in memory to perform various functions of the electronic device and process data.

[0176] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, apparatuses, electronic devices, or computer program products. Thus, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product implemented on one or more storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0177] It should be noted that the word "comprising" does not exclude the presence of elements or steps not listed in a claim. The word "a" or "an" preceding an element does not exclude the presence of a plurality of such elements. The invention can be implemented by means of hardware comprising several distinct elements, and by means of a suitably programmed computer.

[0178] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0179] The above description of the disclosed embodiments is intended to enable one skilled in the art to implement or use the present invention. Various modifications to these embodiments will be readily apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention is not limited to the embodiments shown herein but is intended to conform to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A method for generating smart legal contracts based on contract templates and contract clause semantics, characterized in that: The method comprises the following steps: Parse the legal contract to generate structured data; construct a contract meta-model based on the structured data, and dynamically generate a smart legal contract template consistent with the legal contract business logic based on the contract meta-model; Using abstract syntax trees and mapping rules, we fill in the smart legal contract template execution function skeleton, optimize the business logic code, and generate the smart legal contract code; The generated smart legal contract code is subjected to consistency check based on the symbolic execution method to verify the consistency of the execution path, execution results and business logic between the smart legal contract code and the original legal contract.

2. The method for generating an intelligent legal contract based on a contract template and contract clause semantics according to claim 1, characterized in that: Parsing of legal contracts, including: contract text preprocessing, entity information extraction, clause segmentation and structure analysis, intent recognition and business logic extraction.

3. The method for generating an intelligent legal contract based on a contract template and contract clause semantics according to claim 2, characterized in that: The entity information extraction includes: A rule-based named entity recognition method is used to extract key entity information such as contract number, contract title, contract subject, signing date and contract amount.

4. The method for generating an intelligent legal contract based on a contract template and contract clause semantics according to claim 2, characterized in that: The clause segmentation and structural analysis include: Match rules based on clause identifiers in the contract text to separate clauses and subclauses; The syntactic structure in the contract text is analyzed through the dependency syntax analysis method to identify the clause boundaries, sub-clause relationships and the location of conditional judgments, clarify the clause boundaries and the hierarchical relationship between clauses and the core actions of each clause.

5. The method for generating an intelligent legal contract based on a contract template and contract clause semantics according to claim 2, characterized in that: The intent recognition and business logic extraction include: Based on the large language model, the intent of the clauses describing business rules in the contract text is recognized, and the conditions for business execution and corresponding action descriptions are extracted. For ambiguous or logically complex clauses, clear conditional judgments and business logic information are extracted and structured.

6. The method for generating an intelligent legal contract based on a contract template and contract clause semantics according to claim 1, characterized in that: Constructing a contract meta-model based on the structured data, the specific steps include: According to the predefined contract metamodel structure specification, the structured data is mapped in a regular manner. The contract metamodel includes basic contract information, contract party information, business extension data, and clause structure. Each clause and its subclauses contain text summaries, key fields, and business logic data. The data integrity, logical consistency and format accuracy of the metamodel fields are verified through the data verification mechanism.

7. The method for generating an intelligent legal contract based on a contract template and contract clause semantics according to claim 1, characterized in that: The specific steps for dynamically generating smart legal contract templates include: Determine the corresponding clause structure and execution logic framework in the contract template based on the structure of the contract meta-model; Using the template engine tool, we traverse each clause and sub-clause in the meta-model, retain the original contract summary and key data in the form of comments in the template, generate the corresponding execution function skeleton, and use the business logic data in the meta-model to fill in the code placeholders, thus obtaining a smart legal contract template containing the original contract clause comments, function skeleton and business logic placeholders.

8. The method for generating an intelligent legal contract based on a contract template and contract clause semantics according to claim 1, characterized in that: The specific steps to generate smart legal contract code include: Use Solidity's abstract syntax tree tool or a custom parser to traverse the smart legal contract template, identify the clause nodes in the contract template, and obtain the complete business logic code framework; According to the preset mapping rules and contract metamodel data, the business logic placeholders in the template are converted into corresponding code snippets in the smart contract language; The generated contract code is checked for code standardization and partially optimized to obtain a complete smart legal contract code.

9. The method for generating an intelligent legal contract based on a contract template and contract clause semantics according to claim 1, characterized in that: The consistency check specifically includes: Use symbolic execution methods to symbolize key variables in the generated smart contract code, simulate the contract's execution path under different input conditions, and record each path's conditions, state changes, and execution results; The results of symbolic execution are compared and analyzed one by one with the original business logic in the corresponding clauses of the contract metamodel to verify the consistency of the generated smart legal contract code with the original legal contract text in terms of execution path, execution results and business logic.

10. An intelligent legal contract generation device based on contract templates and contract clause semantics, characterized in that: When applied, a method for generating an intelligent legal contract based on a contract template and contract clause semantics according to any one of claims 1 to 9 is executed, and the device comprises: A contract template generation module is used to parse legal contracts and generate structured data; construct a contract metamodel based on the structured data; and dynamically generate an intelligent legal contract template consistent with the business logic of the legal contract based on the contract metamodel; The contract code generation module is used to use the abstract syntax tree and mapping rules to fill in the smart legal contract template execution function skeleton, optimize the business logic code, and generate the smart legal contract code; A consistency verification module is used to perform consistency verification on the generated smart legal contract code based on the symbolic execution method to verify the consistency of the execution path, execution results and business logic between the smart legal contract code and the original legal contract.

Citation Information

Cited By

  • Legal provision and code consistency verification method and system based on large model semantic vectorization, medium and equipment

    CN121920380A

  • A legal clause and code consistency verification method and system based on large model semantic vectorization, medium and equipment

    CN121920380B

  • Intelligent analysis method and device for forbidden item of ecological environment access list

    CN122221855A