Program code self-adapting generation method based on multi-language context deduction
Patent Information
- Application Number
- CN202611251712.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-18
- Publication Date
- 2026-11-03
AI Technical Summary
现有技术在基于多语言上下文推演生成权限控制程序代码时,未能及时感知权限状态更新,导致生成的代码中存在过期权限判断规则,形成安全漏洞,降低了程序代码自适配生成的可靠性与安全性。
By acquiring real-time permission change nodes, role switching times, and authorization expiration times, the context deduction segments are divided and time-stamped to generate context deduction information with temporal characteristics. The permission mapping data is dynamically updated, and the permission control statements are rewritten segment by segment to ensure that the program code is consistent with the current permission status.
It improves the reliability and security of self-adaptive code generation, ensures that the permission control logic is consistent with the actual permission state, reduces resource consumption, and improves the efficiency of iterative updates and the continuity and stability of permission control.
Smart Images

Figure CN123030166A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of artificial intelligence technology, and more specifically to a method for self-adaptive generation of program code based on multilingual context inference. Background Technology
[0002] Self-adaptive code generation based on multi-language context inference refers to the use of a large model to comprehensively understand the semantic relationships between different programming languages, development frameworks, business requirement descriptions, and existing code environments. It automatically infers and adapts the code structure, syntax, and implementation methods based on the current software development scenario, achieving automatic code generation and adjustment for different technical environments. Based on the above analysis, this technology is mainly applied to research tasks on large-model-driven multi-language code generation and development efficiency optimization. Its core lies in building a code knowledge base covering mainstream programming languages and commonly used development frameworks, enabling the large model to have cross-language understanding capabilities. When inputting requirement documents, business logic descriptions, or existing code context, the model can identify the target development language, framework type, interface dependencies, and internal enterprise coding standards, and complete code structure design, functional logic decomposition, and program statement generation based on context information. For example, for the same business requirement to implement user authentication functionality, the model can generate backend code conforming to the Spring framework specification based on a Java enterprise application environment, or generate corresponding implementation code based on a Python data processing environment, while supplementing with exception handling, permission verification, and security control based on enterprise technical standards. This process differs from simple code translation. Instead, it uses contextual semantic reasoning to analyze the mapping relationship between requirements and code, dynamically adjusts the code generation strategy, and enables the generated program to have language adaptability, framework compatibility, and business consistency, thereby improving software development efficiency and reducing manual modification costs.
[0003] Existing technologies have the following shortcomings: When generating access control program code based on multi-language context inference, user roles and authorization status in enterprise systems change in real time as business operations progress. When the large model continuously infers code based on historical context without timely sensing of permission status updates, it will generate corresponding access control logic based on expired permission information. This results in the generated code solidifying expired permission judgment rules, allowing revoked access permissions to remain valid during program execution. This further causes the actual access control result to deviate from the current permission status, creating security vulnerabilities that are difficult to pinpoint in a short time, and reducing the reliability and security of self-adaptive code generation.
[0004] The information disclosed in the background section is only intended to enhance the understanding of the background of this disclosure, and therefore may include information that does not constitute prior art known to those skilled in the art. Summary of the Invention
[0005] The purpose of this invention is to provide a method for self-adaptive generation of program code based on multilingual context inference, so as to solve the problems in the background art mentioned above.
[0006] To achieve the above objectives, the present invention provides the following technical solution: a method for self-adaptive generation of program code based on multilingual context inference, comprising the following steps:
[0007] Obtain the real-time permission change nodes, role switching times, and authorization expiration times corresponding to multi-language program code, divide the context inference segments according to the time span, write the corresponding time identifier into each context inference segment, and obtain context inference information with time sequence characteristics.
[0008] Extract context inference information with temporal characteristics, rearrange the program association information in each context inference segment according to the permission change interval, perform replacement processing on permission descriptions that exceed the preset time limit, and output context inference results with continuous temporal sequence.
[0009] Read the sequential context deduction results, count the number of role changes, calculate the scope of influence of corresponding permissions, establish a correspondence between role changes and program statements, write the corresponding dynamic permission mapping relationship into the sequential context deduction results, and generate dynamic permission mapping data.
[0010] The dynamic permission mapping data is invoked, the program code generation order is rearranged according to the effective time of the permissions corresponding to the program statements, and the permission control statements are rewritten segment by segment to obtain the self-adaptive program code corresponding to the current permission state.
[0011] For self-adaptive program code, a dynamic update time marker is written according to the frequency of subsequent permission changes. In the next round of program code generation, the corresponding program code fragment with the dynamic update time marker is read to continuously update the permission control logic.
[0012] Preferably, the steps for obtaining contextual inference information with temporal characteristics are as follows:
[0013] Obtain real-time permission change nodes, role switching times, and authorization expiration times corresponding to multi-language program code, and associate them with program association information;
[0014] The context deduction segments are divided according to the time span corresponding to the adjacent permission change records. Each context deduction segment saves the program association information, permission description content, resource access content and role information within the corresponding time range.
[0015] Write the corresponding time identifiers respectively. The time identifiers include the start time of the context deduction segment, the end time, the time when the real-time permission change node occurs, the time when the role switch occurs, and the time when the authorization expires.
[0016] Read all context deduction fragments with written timestamps, re-establish the correspondence between program association information, permission description content, role information, authorization status content, resource access content and timestamps, and obtain context deduction information with temporal characteristics.
[0017] Preferably, each context deduction segment retains the permission status content, role information, and program association information within the corresponding time range. The same program statement records the corresponding permission content for different time markers, and the time markers are arranged consecutively in chronological order.
[0018] The preferred steps for outputting temporally continuous contextual inference results are as follows:
[0019] Extract contextual inference information with temporal characteristics to obtain program association information, permission description content, role information, authorization status content, resource access content and time identifier;
[0020] The program association information in each context deduction segment is rearranged in combination with time intervals, while maintaining the correspondence between the permission change process and the program semantic change process;
[0021] For the rearranged program association information, read the corresponding permission description content. If the permission description exceeds the preset time limit, replace it with the latest permission description content within the corresponding time range.
[0022] Read all context deduction fragments after the permission description replacement process is completed, re-establish the correspondence between program association information, permission description content, role information, authorization status content, resource access content and time identifier, and output the context deduction results with continuous time sequence.
[0023] Preferably, when adding a permission, the description of the new permission access will replace the description of the permission before the new permission is added; when switching roles, the description of the permission for the corresponding role will be updated synchronously; when deleting an authorization, the permission status will replace the original authorization status; and the time stamps will be arranged continuously.
[0024] Preferably, the steps for generating dynamic permission mapping data are as follows:
[0025] Read the context deduction results with continuous timing, extract role information, time markers and program association information, count the number of role changes, and record the set of program statements corresponding to role changes;
[0026] Calculate the scope of influence of corresponding permissions based on the number of times the role changes, and associate the scope of influence of permissions with the corresponding program information;
[0027] Write role change identifiers and permission impact identifiers into program statements, establish a correspondence between role changes and program statements, and write the corresponding dynamic permission mapping relationship.
[0028] Based on the temporal continuous context inference results of writing dynamic permission mapping relationships, program statement identifiers, time identifiers, role information, permission description content, permission influence scope and dynamic permission mapping values are saved to generate dynamic permission mapping data.
[0029] Preferably, when a program statement is located within the time interval corresponding to the scope of permission influence, a role change identifier and a permission influence identifier are written. The same program statement is written with dynamic permission mapping values for different time intervals. The dynamic permission mapping values are arranged continuously in chronological order and written with dynamic permission mapping strength.
[0030] Preferably, the steps for obtaining the adaptive program code corresponding to the current permission status are as follows:
[0031] Call the dynamic permission mapping data to obtain the program statement identifier, permission description content, role information, permission scope, dynamic permission mapping value and permission effective time, and organize the program statements according to the permission effective time;
[0032] The program code generation order is rearranged according to the time when the permissions take effect, and the program statement set corresponding to the program function name, program method name, interface access statement, database access statement and permission control statement is also rearranged.
[0033] Rewrite the access control statements item by item, write the access description and role information into the access control statements, and retain the access control segments corresponding to different time ranges;
[0034] Integrate the rearranged sequence of program statements and the rewritten permission control statements to obtain adaptive program code corresponding to the current permission state.
[0035] Preferably, the program statements are arranged sequentially according to the time when the permissions take effect. The same program statement retains permission control segments for different time ranges. The permission control statements are written with the corresponding permission description content and role information. The self-adaptive program code maintains the program semantic relationship between program function names, program method names, interface access statements, and database access statements.
[0036] Preferably, the steps for dynamically updating the timestamp writing and access control logic update are as follows:
[0037] Extract program function names, program method names, interface access statements, database access statements, and permission control statements from the adapter program code; count the permission change frequency corresponding to the program statements; and write a dynamic update time identifier containing the permission change frequency, the time of the most recent permission change, and the time when the permission takes effect.
[0038] The program statements are reorganized according to the dynamic update time identifier. The program code is arranged continuously according to the dynamic update time identifier, and the positions of the access control statements, interface access statements, database access statements and resource access statements are adjusted accordingly.
[0039] Select the program code segment with the corresponding dynamically updated time marker. In the next round of program code generation, prioritize updating the corresponding program statement and retain the permission control logic corresponding to different time ranges.
[0040] Continuously update access control statements involving permission changes, retain dynamic update timestamps, and output program code that continuously updates access control logic.
[0041] The technical effects and advantages provided by the present invention in the above technical solution are as follows:
[0042] This invention focuses on the characteristic that permission status changes continuously over time. It integrates real-time permission change nodes, role switching moments, and authorization expiration moments into the context inference process to form context inference information with temporal characteristics. Combined with dynamic permission mapping data, the program code generation order is reorganized so that the program code always maintains a correspondence with the current permission status. This avoids the continuous participation of historical permission information in program inference, which helps to improve the consistency between permission control logic and actual permission status and enhances the reliability of program code self-adaptive generation.
[0043] This invention writes a dynamic update time marker after generating self-adaptive program code, and continuously reads the corresponding program code segment to update the permission control logic according to the frequency of subsequent permission changes. This allows permission changes to be gradually reflected in the subsequent program code generation process, reducing the resource consumption caused by repeatedly generating the entire program code, while keeping the program code continuously adapting to permission status changes, improving the efficiency of program code iteration and update, as well as the continuity and stability of permission control. Attached Figure Description
[0044] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in this invention. For those skilled in the art, other drawings can be obtained based on these drawings.
[0045] Figure 1 This is a flowchart of the program code self-adaptive generation method based on multilingual context inference of the present invention. Detailed Implementation
[0046] Exemplary embodiments will now be described more fully with reference to the accompanying drawings. However, these exemplary embodiments can be implemented in many forms and should not be construed as limited to the examples set forth herein; rather, they are provided so that the description of this disclosure will be more complete and fully convey the concept of the exemplary embodiments to those skilled in the art.
[0047] This invention provides, for example Figure 1 The code self-adaptive generation method based on multilingual context inference, as shown, includes the following steps:
[0048] Obtain the real-time permission change nodes, role switching times, and authorization expiration times corresponding to multi-language program code, divide the context inference segments according to the time span, write the corresponding time identifier into each context inference segment, and obtain context inference information with time sequence characteristics.
[0049] Permission status changes continuously during program code deduction. To ensure the program context remains synchronized with the permission status, permission change information is organized into the context content according to the time evolution process. This maintains a consistent correspondence between program semantics, permission status, and temporal relationships, providing contextual information with time-related characteristics for subsequent program code deduction. The specific steps are as follows:
[0050] The system reads the permission management, role management, and authorization management records corresponding to the multi-language program code, continuously recording real-time permission change nodes, role switch times, and authorization expiration times during program execution. Specifically, real-time permission change nodes record the occurrence times of permission additions, deletions, adjustments, and changes in accessed resources; role switch times record the occurrence times of user transitions from ordinary user to administrator, from administrator to auditor, and from auditor to visitor; and authorization expiration times record the occurrence times of authorization expiration, voluntary authorization revocation, authorization relationship termination, and role exit.
[0051] Each permission change is associated with a corresponding program statement, interface call statement, resource access statement, database access statement, and permission control statement in the program code. It also records the corresponding programming language type, program file path, program function name, program class name, program method name, and resource identifier, ensuring that each permission change corresponds to unique program-related information. When permission changes occur simultaneously across different programming languages, a unified timeline is used to record all permission changes, arranged sequentially according to the actual occurrence of events. Any new permissions, role changes, and authorization terminations retain their original time positions, resulting in a continuously arranged record of permission changes. Each record fully preserves the permission status, program-related information, and corresponding time position.
[0052] The program context is reorganized based on consecutively arranged permission change records. Instead of using a fixed number of program statements to constitute the context content, multiple context deduction segments are created based on the time span between two adjacent permission change records. Each context deduction segment covers the program association information generated within its corresponding time range. When a real-time permission change node occurs, the current context deduction segment stops recording subsequent program content, and the new real-time permission change node becomes the starting position of the next context deduction segment. When a role switch occurs, the program association information corresponding to the current role is retained in the existing context deduction segment, while the program association information corresponding to the new role is written to a new context deduction segment. When authorization expires, the program statements before and after authorization expiration are assigned to different context deduction segments to avoid program content generated under different permission states being retained in the same context deduction segment simultaneously.
[0053] Each context deduction fragment stores all program association information, permission descriptions, resource access information, and role information within the corresponding time range. The beginning and end of each context deduction fragment are connected sequentially in chronological order, and each time range corresponds to independent context content. The program context is converted from continuous text into multiple context deduction fragments with time boundaries.
[0054] Write corresponding time identifiers for each of the already divided context deduction segments. Each time identifier includes the start time, end time, real-time permission change node occurrence time, role switch occurrence time, and authorization expiration occurrence time of the context deduction segment. At the same time, record the permission status identifier, role identifier, authorization status identifier, and program version identifier corresponding to the current context deduction segment.
[0055] After the timestamps are written, the associated information of each program is reorganized according to the corresponding timestamps. When the permissions of the same program statement change within different time ranges, the context deduction fragments under the corresponding timestamps are retained respectively, and the different timestamps maintain a continuous arrangement. When multiple program files have permission changes at the same time, the context deduction fragments corresponding to each program file are written to the corresponding timestamps and arranged in chronological order.
[0056] When the same program function undergoes multiple role switching consecutively, each role switching corresponds to an independent time marker, and each role information is retained in the corresponding context deduction fragment, thus completely recording the entire process of the continuous change of permission status along the time direction. The program semantic content and permission status content always maintain a one-to-one correspondence, and each piece of program-related information can be located to a unique time range.
[0057] Read all context inference fragments with timestamps already written, and re-establish the correspondence between program association information, permission descriptions, role information, authorization status, resource access content, and timestamps in each context inference fragment to obtain context inference information with temporal characteristics. Context inference information with temporal characteristics not only preserves the program semantic relationships corresponding to the program code, but also fully preserves the evolution of permission status, role transformation relationships, and authorization change relationships over time. Different time ranges correspond to different permission states, and the same program statement records the corresponding permission content for different time ranges. All permission changes can be continuously traced chronologically, and program association information always corresponds to the permission status within the current time range.
[0058] When subsequent program code reads contextual deduction information with temporal characteristics, program statements, permission descriptions, role information, authorization status, and resource access content all participate in the deduction according to the corresponding time identifier. Historical permission content and current permission content are stored independently and continuously connected. The entire context content is transformed from a static program description into dynamic context information with time evolution and permission change relationships, continuously providing program context content within the corresponding time range for subsequent program code self-adaptive generation.
[0059] Extract context inference information with temporal characteristics, rearrange the program association information in each context inference segment according to the permission change interval, perform replacement processing on permission descriptions that exceed the preset time limit, and output context inference results with continuous temporal sequence.
[0060] As permission status changes continuously over time, the permission description in the program context evolves with role changes, authorization adjustments, and access control changes. To ensure that the program context always corresponds to the current permission status, the program associations are reorganized based on the context deduction information with temporal characteristics, and the permission description content is continuously updated. This ensures that subsequent program code deduction is always based on the continuously changing permission context. The specific steps are as follows:
[0061] Read the context deduction information with temporal characteristics, expand each context deduction segment one by one, and extract the program association information, permission description content, role information, authorization status content, resource access content and corresponding time identifier stored in each context deduction segment.
[0062] The program association information corresponds to program file name, package name, program class name, program function name, program method name, interface access statement, database query statement, database update statement, resource access statement, and access control statement. Each piece of program association information corresponds to a unique permission description and a unique time identifier. Then, the time intervals between adjacent real-time permission change nodes are read, and the duration between the role switch time and the next role switch time, as well as the duration between the authorization expiration time and the next authorization establishment time, are recorded. These time intervals are written into the corresponding program association information, ensuring that each piece of program association information simultaneously stores the permission change start time, permission change end time, role duration, and authorization duration. When the same program statement exists continuously within multiple time ranges, the program association information and permission description content for each corresponding time range are retained.
[0063] When multiple program files access the same resource, each program file retains independent program association information, and different program files maintain corresponding time relationships, thereby obtaining a complete set of program association information that records the continuous process of permission changes, providing a complete time basis for the subsequent rearrangement of program association information.
[0064] The program association information with established time intervals is reorganized and rearranged. It no longer maintains the original order within the context deduction segments, but instead rearranges the program association information in each context deduction segment according to the permission change interval. Program association information generated between permission addition and permission adjustment is arranged in the same continuous area, while program association information generated between permission adjustment and permission deletion is arranged in another continuous area. For roles maintained as ordinary users, the corresponding program function names, program method names, interface access statements, and permission control statements are grouped together. For roles changed to administrators, the corresponding program association information is rearranged to the administrator's corresponding area, and for roles changed to auditors, the corresponding program association information continues to be adjusted to the auditor's corresponding area. Database query statements, database update statements, and resource access statements generated during authorization establishment are arranged in the corresponding authorized validity position, and program association information after authorization termination is arranged in the authorized termination position, no longer overlapping with program content generated during the authorized validity period.
[0065] Program files corresponding to different programming languages are reorganized according to a unified arrangement rule. When multiple program method names are involved within the same program class name, the program method names are arranged consecutively according to the permission change interval. When multiple resource access statements are involved in the same interface access statement, the resource access statements are arranged consecutively according to the time of permission change. This ensures that the program association information within the entire context deduction segment always unfolds sequentially along the permission change direction, and the permission change process and the program semantic change process maintain a synchronous correspondence.
[0066] For each item in the rearranged program association information, read the corresponding permission description content, read the time identifier corresponding to the permission description content, and calculate the duration between the start time and end time of the permission description.
[0067] When the duration of a permission description exceeds a preset time limit, the current permission description content is stopped being retained. Simultaneously, real-time permission change nodes, role switch times, and authorization expiration times generated after the corresponding time range are read, and the latest permission description content within the corresponding time range replaces the current permission description content. For example, when a permission is added, the access permission content after the addition replaces the permission description before the addition; when a permission is deleted, the access permission content after the deletion replaces the permission description before the deletion; when a role changes from a regular user to an administrator, the administrator's permission description replaces the regular user's permission description; when a role changes from an administrator to an auditor, the auditor's permission description replaces the administrator's permission description; after an authorization relationship is terminated, the permission status corresponding to the authorization termination replaces the original authorization status; after authorization is re-established, the permission status corresponding to the re-establishment replaces the permission status after the authorization termination.
[0068] When the same program function name involves multiple time ranges, the corresponding permission description content is retained for each time range, and different time ranges do not overwrite each other; when the same database query statement corresponds to multiple permission states, each permission state corresponds to a different time range, the permission description always corresponds to the current time identifier, historical permission descriptions stop continuing forward, and updated permission descriptions continuously overwrite the corresponding program association information, so that all permission content within the program context always corresponds to the permission state within the current time range.
[0069] After reading all context deduction fragments after the permission description replacement process is completed, the rearranged program association information, updated permission description content, role information, authorization status content, resource access content, and time stamp are re-established to establish a continuous correspondence, and the temporally continuous context deduction result is output. The temporally continuous contextual deduction results fully preserve the correspondence between program file names, program class names, program function names, program method names, interface access statements, database query statements, database update statements, resource access statements, access control statements, access descriptions, role information, authorization status, and time stamps. Each piece of program-related information corresponds to a unique time range and a unique access status. The same program statement corresponds to different access descriptions in different time ranges. Each time range is arranged continuously according to the order in which access changes occur. Access addition, access adjustment, access deletion, role conversion, authorization establishment, and authorization revocation each correspond to independent context content. The end position of the previous time range is continuously connected to the beginning position of the next time range. The entire temporally continuous contextual deduction results fully record the entire process of access status from generation, change, adjustment, to update. At the same time, it fully records the correspondence of program-related information that continuously evolves with access status changes, providing continuous, complete, and current access status-corresponding contextual deduction content for subsequent establishment of dynamic access mapping relationships.
[0070] Read the sequential context deduction results, count the number of role changes, calculate the scope of influence of corresponding permissions, establish a correspondence between role changes and program statements, write the corresponding dynamic permission mapping relationship into the sequential context deduction results, and generate dynamic permission mapping data.
[0071] Permission status changes over time and continuously affect program statements, with different roles imposing different access constraints on program statements within different timeframes. To ensure that the program code derivation process accurately reflects the impact of role changes on program statements, based on the existing temporally continuous context derivation results, a correlation between the number of role changes and the scope of permission influence is introduced. Furthermore, a dynamic correspondence between program statements and role changes is established, thereby obtaining continuously updated dynamic permission mapping data. The specific steps are as follows:
[0072] Read the sequential context deduction results, extract the recorded role information, time stamps, and program association information item by item, and continuously record role changes according to the time stamps. Count the number of times a role changes from its initial role to subsequent roles on the same timeline, treating each role switch as an independent change event, and record the set of program statements corresponding to the role change, including program function names, program method names, interface access statements, database access statements, and access control statements. Construct a role change counting expression based on the above role change records:
[0073]
[0074] in, Indicates the number of times the role changes. Indicates the first Each time marker corresponds to a role information. This indicates the role information corresponding to adjacent time markers. The value is 1 if the role information in two adjacent time markers is inconsistent, and 0 otherwise. This expression is used to count the cumulative number of role changes in the entire time-series continuous context inference results, and to establish a correspondence between this number and the set of program statements within the corresponding time range, so that each program statement can be associated with the number of role changes within its time range.
[0075] Based on the number of role changes, we further characterize the expansion relationship of the impact of role changes on the scope of permissions. For each time period corresponding to a role change, we extract the number of program statements, resource accesses, and permission control statements involved within that time period, and construct an expression for the scope of permission impact by combining this with the number of role changes:
[0076]
[0077] in, Indicates the scope of the permissions. Indicates the number of program functions. Indicates the number of program methods. Indicates the number of API access statements. Indicates the number of database access statements. This represents the number of role changes. This expression reflects the amplifying effect of the number of role changes on the scope of influence of program statements. As the number of role changes increases, the scope of influence of the corresponding permissions expands synchronously, and the set of program statements involved also expands. Through this expression, role changes can be transformed from a single-point-in-time event into an area of influence covering multiple program statements, and this area of influence can be bound to specific program-related information.
[0078] After obtaining the scope of permission influence, a one-to-one correspondence is established between role changes and specific program statements. For each program statement, its corresponding time stamp and role information are read, and the scope of permission influence is used to determine whether the program statement is affected by the current role change. When a program statement falls within the time interval corresponding to the scope of permission influence, the corresponding role change identifier and permission influence identifier are written to the program statement, and a mapping relationship between program statements and role changes is constructed. To enhance the expressiveness of the mapping relationship, a dynamic permission mapping expression is introduced:
[0079]
[0080] in, This represents the dynamic permission mapping value corresponding to the program statement. The scope of the permissions. This represents the participation coefficient of a program statement within a corresponding time frame. This coefficient indicates whether the program statement participates in access control within the current time frame: it takes a value of 1 when the program statement is an access control statement; a value of 0.5 when the program statement is a regular logic statement; and a value of 0 when the program statement does not involve access control. This expression characterizes the degree of participation of different types of program statements in the process of access control changes, thus ensuring that the correspondence between role changes and program statements reflects not only temporal correlation but also differences in the degree of influence.
[0081] After establishing the correspondence between program statements and role changes, all mapping results are written into the sequential context deduction results to generate dynamic permission mapping data. The dynamic permission mapping data includes program statement identifiers, time identifiers, role information, permission descriptions, permission impact scope, and dynamic permission mapping values. Each data item maintains a one-to-one correspondence and is arranged sequentially in chronological order. To ensure that subsequent program code deduction can prioritize the identification of key permission change areas, a mapping strength expression is further constructed within the dynamic permission mapping data:
[0082]
[0083] in, This indicates the strength of dynamic permission mapping, used to comprehensively reflect the importance of program statements during permission changes. This represents the dynamic permission mapping value. This expression represents the scope of permission influence. It combines the degree of involvement of program statements with the scope of permission influence, ensuring that the mapping strength reflects both the coverage of permission changes and the involvement of program statements. The resulting dynamic permission mapping data not only comprehensively records the number of role changes, the scope of permission influence, and the correspondence of program statements, but also reflects the degree of influence of each program statement during the permission change process. This provides a precise mapping basis for rewriting permission control statements during subsequent program code generation.
[0084] The dynamic permission mapping data is invoked, the program code generation order is rearranged according to the effective time of the permissions corresponding to the program statements, and the permission control statements are rewritten segment by segment to obtain the self-adaptive program code corresponding to the current permission state.
[0085] Program statements correspond to different permission states within different time ranges. Dynamic permission mapping data has already depicted role changes, the scope of permission influence, and the correspondence between program statements. To ensure that the generated program code always matches the current permission state, it is necessary to introduce a synchronization relationship between the time when permissions take effect and the program statements during the program generation stage, so that the program code structure can be dynamically adjusted as permissions change. The specific steps are as follows:
[0086] The system retrieves the dynamic permission mapping data, reading each recorded program statement identifier, permission description, role information, permission scope, dynamic permission mapping value, and corresponding permission effective time. All program statements are then grouped according to their effective time. Program statements corresponding to the same permission effective time are grouped together, while those corresponding to different permission effective times are arranged chronologically, forming a program statement distribution structure based on permission effective time.
[0087] In this structure, program function names, program method names, interface access statements, database access statements, and access control statements are respectively assigned to the statement sets at the time when the corresponding permissions take effect. The original semantic order of the program is preserved within each statement set, while different statement sets are continuously expanded according to the time when the permissions take effect, thereby changing the distribution state of program statements from the original logical order to a time-order structure dominated by the time when the permissions take effect.
[0088] Table 1: Dynamic Permission Mapping Data Structure Table
[0089] Program statement identifier Permission description content Character Information When the permission takes effect Scope of permission Dynamic permission mapping value Method A Read permission Regular users T1 Scope 1 Value 1 Method B Write permissions administrator T2 Scope 2 Value 2 Method C Deletion Permission Auditors T3 Range 3 Value 3
[0090] Function: To record the correspondence between program statements and permission status, providing a data source for adjusting the program code generation order.
[0091] After completing the program statement distribution structure based on the effective time of permissions, the program code generation order is rearranged. Program statements corresponding to different effective times of permissions are generated sequentially according to time, with earlier effective times taking precedence, followed by later effective times, forming a time-progressive program generation order. Within the same effective time of permission, program statements are locally ordered based on semantic dependencies of function names, method names, interface access statements, database access statements, and permission control statements. This ensures that data access statements appear before permission control statements, and permission control statements appear before business processing statements, thereby guaranteeing consistency between the program execution path and the permission effective path.
[0092] For program statements that persist across multiple permission periods, corresponding statement fragments are generated within their respective time ranges, ensuring that the same program statement has an independent generation location under different permission states, thus avoiding the mixing of program statements under different permission states.
[0093] Table 2: Program Code Generation Order Table
[0094] When the permission takes effect Program function name Program method name Interface access statement Access control statements T1 Function 1 Method 1 Interface A Judgment 1 T2 Function 2 Method 2 Interface B Judgment 2 T3 Function 3 Method 3 Interface C Judgment 3
[0095] Purpose: To describe the order of program statements corresponding to the time when different permissions take effect.
[0096] For the rearranged sequence of program statements, the access control statements are rewritten segment by segment. Each access control statement reads the access description and role information from its corresponding dynamic access mapping data and replaces the content according to the access status at the current time when the access is effective. When reading the access description, the original access judgment condition is replaced with the access permission condition within the current time range, and the access permission range corresponding to the role information is written into the access control statement. At the same time, multiple access control segments corresponding to different time ranges are retained in the same program statement, so that the program executes the corresponding access control logic in different time ranges.
[0097] During the segment-by-segment rewriting process, each permission control statement is processed independently. Permission control statements corresponding to different program function names are rewritten separately. When different program method names involve multiple permission judgment conditions, they are rewritten one by one according to the effective time of the corresponding permission, so that the permission control statements are consistent with the dynamic permission mapping data.
[0098] Table 3: Access Control Statement Rewriting Table
[0099] Original access control statement When the permission takes effect New permission description Character Information Rewritten statement Determine if it can be deleted T1 Deletion Permission administrator Determine if the administrator deletes Determine if it is writable T2 Write permissions Regular users Determine user write Determine if it is readable T3 Read permission Auditors Determine if the review is read
[0100] Purpose: To describe the rewrite of access control statements when different permissions are in effect.
[0101] After rewriting all access control statements segment by segment, the rearranged sequence of program statements is integrated with the rewritten access control statements to obtain adaptive program code corresponding to the current access status. The adaptive program code maintains the original logical relationships between program function names, program method names, interface access statements, and database access statements in its structure, while its content completely corresponds to the access status at the time the current access is effective. Each program statement is arranged sequentially according to the time the access is effective, and the access control statements correspond to different access descriptions within different time ranges.
[0102] This self-adaptive program code not only reflects the semantic relationships of the program, but also reflects the process of permission status changing over time, so that the program always executes access control logic according to the current permission status during execution.
[0103] Table 4: Self-adaptive Program Code Structure Table
[0104] Program function name Program method name When the permission takes effect Access control statements Resource access statements Function 1 Method 1 T1 Judgment 1 Access resource A Function 2 Method 2 T2 Judgment 2 Access resource B Function 3 Method 3 T3 Judgment 3 Access resource C
[0105] Purpose: To demonstrate the correspondence between the final generated program code structure and the permission status.
[0106] The self-adaptive program code obtained through the above process can correspond to the correct permission control logic under different permission states. The order of program statements is consistent with the time when the permission takes effect, and the permission control statements are continuously updated as the permission state changes, thereby realizing the synchronous correspondence between the program code generation result and the current permission state.
[0107] For self-adaptive program code, dynamic update time markers are written according to the frequency of subsequent permission changes. In the next round of program code generation, the corresponding dynamic update time marker program code fragments are read to continuously update the permission control logic.
[0108] Permission status changes continuously during program execution. Although the self-adaptive program code already corresponds to the current permission status, subsequent permission changes will still affect the permission control logic in the program code. Therefore, a dynamic update time marker is introduced on the basis of the self-adaptive program code, so that the program code can continuously detect permission changes and update them during subsequent generation processes. The specific steps are as follows:
[0109] The system reads program function names, program method names, interface access statements, database access statements, and access control statements from the adaptive program code. It then extracts the permission description, role information, and permission activation time for each statement. Simultaneously, it combines historical permission change records to calculate the permission change frequency of each statement within a given time period. The permission change frequency record tracks the cumulative number of permission additions, deletions, adjustments, and role switches within the corresponding time range, establishing a one-to-one correspondence with the corresponding program statements.
[0110] Within the same program function name, different program method names correspond to different permission change frequency values. The permission control statements within each program method name record independent permission change frequencies, ensuring that each program statement possesses complete permission change frequency information. Subsequently, a corresponding dynamic update time identifier is written after each program statement. This identifier includes the permission change frequency, the time of the most recent permission change, and the time when the corresponding permission took effect. This ensures that the program statement not only contains permission control logic but also corresponding update time information, providing a time-based basis for subsequent program code generation.
[0111] For self-adaptive program code that has already been written with dynamic update timestamps, all program statements are reorganized according to the dynamic update timestamps, with different dynamic update timestamps corresponding to different update priorities. Program statements with higher permission change frequency are placed at the beginning of the update sequence, and program statements with lower permission change frequency are placed at the end of the update sequence. Under the same permission change frequency, they are arranged according to the time of the most recent permission change, so that program statements with recently changed permissions are given priority in entering the update sequence.
[0112] Within the same program function name, access control statements are rearranged according to dynamic update timestamps. Interface access statements, database access statements, and resource access statements are adjusted according to the positions of their corresponding access control statements, ensuring that the overall program code structure is consistent with the dynamic update timestamps. Different program files are sorted according to a unified rule, and program statements within each program file are arranged consecutively according to dynamic update timestamps, thus forming a program code distribution structure based on dynamic update timestamps. This ensures that the program code as a whole presents an arrangement relationship synchronized with the frequency of access control changes.
[0113] After the program code is reorganized according to the dynamic update timestamp, the next round of program code generation reads the program code fragments corresponding to the dynamic update timestamps and filters the program statements that need to be updated first according to the dynamic update timestamps. For program statements with high frequency of permission changes recorded in the dynamic update timestamps, the corresponding program code fragments are read first, and their permission control statements are updated in combination with the current permission status; for program statements with low frequency of permission changes, the original program code fragments are kept unchanged and are only updated when necessary.
[0114] During the reading of program code snippets, each program statement carries a corresponding dynamic update time marker, enabling the program code generation process to distinguish the update priority of different statements and prioritize processing permission control statements with higher change frequencies. Furthermore, when the same program method name corresponds to multiple time ranges, the program code snippets with the corresponding dynamic update time markers are read separately, ensuring that the permission control logic within different time ranges participates in the update process independently. This guarantees that the program code generation process is always based on the latest permission changes.
[0115] After completing the reading and priority allocation of program code snippets, the permission control logic is continuously updated for program statements involving permission changes, ensuring that the program code remains synchronized with the permission status during subsequent generation. During the update process, each permission control statement is rewritten based on the current permission description and corresponding role information, and the updated permission control statement overwrites the original program statement. Simultaneously, the dynamic update time marker is retained, allowing subsequent permission changes to continue affecting this program statement. Among multiple program function names, update operations are executed sequentially according to the dynamic update time marker order, causing the overall program code structure to evolve gradually with permission changes.
[0116] The resulting program code can prioritize updating the corresponding program statements based on the dynamic update time marker in each generation process. The permission control logic is continuously adjusted as permissions change, thereby realizing continuous updates of the program code in multiple generation processes, so that changes in permission status can always be reflected in the program code content.
[0117] This invention focuses on the characteristic that permission status changes continuously over time. It integrates real-time permission change nodes, role switching moments, and authorization expiration moments into the context inference process to form context inference information with temporal characteristics. Combined with dynamic permission mapping data, the program code generation order is reorganized so that the program code always maintains a correspondence with the current permission status. This avoids the continuous participation of historical permission information in program inference, which helps to improve the consistency between permission control logic and actual permission status and enhances the reliability of program code self-adaptive generation.
[0118] This invention writes a dynamic update time marker after generating self-adaptive program code, and continuously reads the corresponding program code segment to update the permission control logic according to the frequency of subsequent permission changes. This allows permission changes to be gradually reflected in the subsequent program code generation process, reducing the resource consumption caused by repeatedly generating the entire program code, while keeping the program code continuously adapting to permission status changes, improving the efficiency of program code iteration and update, as well as the continuity and stability of permission control.
[0119] The foregoing has only described certain exemplary embodiments of the present invention by way of illustration. Undoubtedly, those skilled in the art can modify the described embodiments in various ways without departing from the spirit and scope of the present invention. Therefore, the foregoing drawings and descriptions are illustrative in nature and should not be construed as limiting the scope of protection of the claims of the present invention.
Claims
1. A method for self-adaptive generation of program code based on multilingual context inference, characterized in that, Includes the following steps: Obtain the real-time permission change nodes, role switching times, and authorization expiration times corresponding to multi-language program code, divide the context inference segments according to the time span, write the corresponding time identifier into each context inference segment, and obtain context inference information with time sequence characteristics. Extract context inference information with temporal characteristics, rearrange the program association information in each context inference segment according to the permission change interval, perform replacement processing on permission descriptions that exceed the preset time limit, and output context inference results with continuous temporal sequence. Read the sequential context deduction results, count the number of role changes, calculate the scope of influence of corresponding permissions, establish a correspondence between role changes and program statements, write the corresponding dynamic permission mapping relationship into the sequential context deduction results, and generate dynamic permission mapping data. The dynamic permission mapping data is invoked, the program code generation order is rearranged according to the effective time of the permissions corresponding to the program statements, and the permission control statements are rewritten segment by segment to obtain the self-adaptive program code corresponding to the current permission state. For self-adaptive program code, a dynamic update time marker is written according to the frequency of subsequent permission changes. In the next round of program code generation, the corresponding program code fragment with the dynamic update time marker is read to continuously update the permission control logic.
2. The method for self-adaptive generation of program code based on multilingual context inference according to claim 1, characterized in that, The steps for obtaining contextual inference information with temporal characteristics are as follows: Obtain real-time permission change nodes, role switching times, and authorization expiration times corresponding to multi-language program code, and associate them with program-related information; The context deduction segments are divided according to the time span corresponding to the adjacent permission change records. Each context deduction segment saves the program association information, permission description content, resource access content and role information within the corresponding time range. Write the corresponding time identifiers respectively. The time identifiers include the start time of the context deduction segment, the end time, the time when the real-time permission change node occurs, the time when the role switch occurs, and the time when the authorization expires. Read all context deduction fragments with written timestamps, re-establish the correspondence between program association information, permission description content, role information, authorization status content, resource access content and timestamps, and obtain context deduction information with temporal characteristics.
3. The program code self-adaptive generation method based on multilingual context inference according to claim 2, characterized in that, Each context deduction segment retains the permission status content, role information, and program association information within the corresponding time range. The same program statement records the corresponding permission content for different time markers, and the time markers are arranged consecutively in chronological order.
4. The program code self-adaptive generation method based on multilingual context inference according to claim 2, characterized in that, The steps for outputting the temporally continuous context inference results are as follows: Extract contextual inference information with temporal characteristics to obtain program association information, permission description content, role information, authorization status content, resource access content and time identifier; The program association information in each context deduction segment is rearranged in combination with time intervals, while maintaining the correspondence between the permission change process and the program semantic change process; For the rearranged program association information, read the corresponding permission description content. If the permission description exceeds the preset time limit, replace it with the latest permission description content within the corresponding time range. Read all context deduction fragments after the permission description replacement process is completed, re-establish the correspondence between program association information, permission description content, role information, authorization status content, resource access content and time identifier, and output the context deduction results with continuous time sequence.
5. The program code self-adaptive generation method based on multilingual context inference according to claim 4, characterized in that, When adding a permission, the description of the new access permission will be replaced with the description of the permission before the new permission was added. When switching roles, the description of the permissions for the corresponding roles will be updated synchronously. When deleting an authorization, the status of the corresponding permission will be replaced with the original authorization status. The time stamps will be arranged continuously.
6. The program code self-adaptive generation method based on multilingual context inference according to claim 4, characterized in that, The steps for generating dynamic permission mapping data are as follows: Read the context deduction results with continuous timing, extract role information, time markers and program association information, count the number of role changes, and record the set of program statements corresponding to role changes; Calculate the scope of influence of corresponding permissions based on the number of times the role changes, and associate the scope of influence of permissions with the corresponding program information; Write role change identifiers and permission impact identifiers into program statements, establish a correspondence between role changes and program statements, and write the corresponding dynamic permission mapping relationship. Based on the temporal continuous context inference results of writing dynamic permission mapping relationships, program statement identifiers, time identifiers, role information, permission description content, permission influence scope and dynamic permission mapping values are saved to generate dynamic permission mapping data.
7. The method for self-adaptive generation of program code based on multilingual context inference according to claim 6, characterized in that, When a program statement is located within the time interval corresponding to the scope of permission influence, a role change identifier and a permission influence identifier are written. The same program statement is written with dynamic permission mapping values for different time intervals. All dynamic permission mapping values are arranged consecutively in chronological order and written with dynamic permission mapping strength into the dynamic permission mapping data.
8. The method for self-adaptive generation of program code based on multilingual context inference according to claim 6, characterized in that, The steps to obtain the adaptive program code corresponding to the current permission status are as follows: Call the dynamic permission mapping data to obtain the program statement identifier, permission description content, role information, permission scope, dynamic permission mapping value and permission effective time, and organize the program statements according to the permission effective time; The program code generation order is rearranged according to the time when the permissions take effect, and the program statement set corresponding to the program function name, program method name, interface access statement, database access statement and permission control statement is also rearranged. Rewrite the access control statements item by item, write the access description and role information into the access control statements, and retain the access control segments corresponding to different time ranges; Integrate the rearranged sequence of program statements and the rewritten permission control statements to obtain adaptive program code corresponding to the current permission state.
9. The method for self-adaptive generation of program code based on multilingual context inference according to claim 8, characterized in that, The program statements are arranged sequentially according to the time when the permissions take effect. The same program statement retains the permission control segment for different time ranges. The permission control statement is written with the corresponding permission description and role information. The self-adaptive program code maintains the program semantic relationship between program function names, program method names, interface access statements, and database access statements.
10. The program code self-adaptive generation method based on multilingual context inference according to claim 8, characterized in that, The steps for dynamically updating the time stamp and updating the access control logic are as follows: Extract program function names, program method names, interface access statements, database access statements, and permission control statements from the adapter program code; count the permission change frequency corresponding to the program statements; and write a dynamic update time identifier containing the permission change frequency, the time of the most recent permission change, and the time when the permission takes effect. The program statements are reorganized according to the dynamic update time identifier. The program code is arranged continuously according to the dynamic update time identifier, and the positions of the access control statements, interface access statements, database access statements and resource access statements are adjusted accordingly. Select the program code segment with the corresponding dynamically updated time marker. In the next round of program code generation, prioritize updating the corresponding program statement and retain the permission control logic corresponding to different time ranges. Continuously update access control statements involving permission changes, retain dynamic update timestamps, and output program code that continuously updates access control logic.
