Search

CN-121979508-A - Drools rule dynamic generation method and system based on commodity knowledge base

CN121979508ACN 121979508 ACN121979508 ACN 121979508ACN-121979508-A

Abstract

The invention provides a Drools rule dynamic generation method and a Drools rule dynamic generation system based on a commodity knowledge base in the technical field of intersection of a rule engine and artificial intelligence, wherein the method comprises the following steps of S1, constructing a commodity relation model based on entity attributes and association relations of commodities; the method comprises the steps of S2, preprocessing product basic data based on a product relation model to construct a product knowledge base, S3, setting a rule template based on a Drools rule grammar, S4, defining a prompt word instruction based on a rule scene and storing the prompt word instruction into the prompt word base, S5, analyzing product relation logic based on the product knowledge base and the prompt word base by an AI large model, generating a Drools rule file based on a product relation logic matching rule template, S6, carrying out asynchronous grammar check, logic conflict check and business suitability check on the Drools rule file, and S7, publishing the Drools rule file to a rule engine. The method has the advantages that the accuracy, the flexibility and the response efficiency of rule generation are greatly improved.

Inventors

  • ZHENG WENXIONG
  • Huang Huamou
  • CHEN CHENG
  • HUANG KEER

Assignees

  • 福建新大陆软件工程有限公司

Dates

Publication Date
20260505
Application Date
20251124

Claims (10)

  1. 1. A Drools rule dynamic generation method based on a commodity knowledge base is characterized by comprising the following steps: step S1, defining entity attributes and association relations among the entities based on the entities of the commodity, and constructing a commodity relation model based on the entity attributes and the association relations; S2, acquiring commodity basic data, preprocessing the commodity basic data at least comprising data cleaning and data normalization based on the commodity relation model, and constructing a commodity knowledge base based on the preprocessed commodity basic data; s3, setting a rule template based on a Drools rule grammar; S4, creating a prompt word library, defining prompt word instructions for guiding the AI large model based on a rule scene, and storing the prompt word instructions into the prompt word library; S5, the AI large model analyzes commodity relation logic based on the commodity knowledge base and the prompt word base, and generates a Drools rule file based on a rule template matched with the commodity relation logic; S6, carrying out asynchronous grammar check, logic conflict check and service suitability check on the Drools rule file; And S7, issuing the checked Drools rule file to a rule engine for deployment and testing.
  2. 2. The method for dynamically generating Drools rules based on commodity knowledge base according to claim 1, wherein in step S1, the association relationship comprises mutual exclusion relationship, dependency relationship, association relationship, cancellation and change relationship, and special and no relationship.
  3. 3. The method for dynamically generating Drools rules based on commodity knowledge base according to claim 1, wherein said step S2 is specifically: And acquiring commodity basic data from a database table based on an API (application program interface) through a database client, preprocessing the commodity basic data at least comprising data cleaning and data normalization based on the commodity relation model, and importing the preprocessed commodity basic data into an agent to extract triple knowledge so as to construct a commodity knowledge base.
  4. 4. The method for dynamically generating Drools rules based on commodity knowledge base according to claim 1, wherein said step S3 is specifically: Setting a rule template for generating a Drools rule file based on a Drools rule grammar, and setting a corresponding relation between each rule template and commodity production relation logic, wherein the rule template comprises replaceable parameters, and the replaceable parameters at least comprise commodity IDs, attribute constraints, relation type parameters, additional identifications of participating commodities, relation directions and modifiers, action types and action parameters, condition context parameters and rule metadata parameters.
  5. 5. The method for dynamically generating the Drools rule based on the commodity knowledge base according to claim 1, wherein in the step S6, the grammar check is specifically implemented by detecting whether the Drools rule file meets the Drools rule grammar; Verifying whether logic conflict exists in each Drools rule file generated through an AI large model and a commodity knowledge base; the service suitability check is specifically to simulate a service scene through an AI large model to perform coverage check on a Drools rule file.
  6. 6. A Drools rule dynamic generation system based on a commodity knowledge base is characterized by comprising the following modules: The commodity relation model building module is used for defining entity attributes and association relations among the entities based on the entities of the commodity, and building a commodity relation model based on the entity attributes and the association relations; The commodity knowledge base construction module is used for collecting commodity basic data, carrying out pretreatment at least comprising data cleaning and data normalization on the commodity basic data based on the commodity relation model, and constructing a commodity knowledge base based on the pretreated commodity basic data; the rule template setting module is used for setting a rule template based on a Drools rule grammar; The prompt word library creation module is used for creating a prompt word library, defining prompt word instructions for guiding the AI large model based on the rule scene, and storing the prompt word instructions into the prompt word library; The Drools rule file generation module is used for analyzing commodity relation logic based on the commodity knowledge base and the prompt word base by the AI large model, and generating a Drools rule file based on a rule template matched with the commodity relation logic; the Drools rule file verification module is used for carrying out asynchronous grammar verification, logic conflict verification and service suitability verification on the Drools rule file; And the Drools rule file deployment module is used for publishing the checked Drools rule files to a rule engine for deployment and testing.
  7. 7. The system for dynamically generating Drools rules based on commodity knowledge base according to claim 6, wherein said association relationship comprises mutual exclusion relationship, dependency relationship, association relationship, cancellation and change relationship, special and no relationship in said commodity relationship model construction module.
  8. 8. The dynamic Drools rule generating system based on commodity knowledge base according to claim 6, wherein said commodity knowledge base constructing module is specifically configured to: And acquiring commodity basic data from a database table based on an API (application program interface) through a database client, preprocessing the commodity basic data at least comprising data cleaning and data normalization based on the commodity relation model, and importing the preprocessed commodity basic data into an agent to extract triple knowledge so as to construct a commodity knowledge base.
  9. 9. The system for dynamically generating Drools rules based on commodity knowledge base according to claim 6, wherein said rule template setting module is specifically configured to: Setting a rule template for generating a Drools rule file based on a Drools rule grammar, and setting a corresponding relation between each rule template and commodity production relation logic, wherein the rule template comprises replaceable parameters, and the replaceable parameters at least comprise commodity IDs, attribute constraints, relation type parameters, additional identifications of participating commodities, relation directions and modifiers, action types and action parameters, condition context parameters and rule metadata parameters.
  10. 10. The system for dynamically generating the Drools rule based on the commodity knowledge base according to claim 6, wherein in the Drools rule file checking module, the grammar checking is specifically implemented by detecting whether the Drools rule file meets the Drools rule grammar; Verifying whether logic conflict exists in each Drools rule file generated through an AI large model and a commodity knowledge base; the service suitability check is specifically to simulate a service scene through an AI large model to perform coverage check on a Drools rule file.

Description

Drools rule dynamic generation method and system based on commodity knowledge base Technical Field The invention relates to the technical field of intersection of a rule engine and artificial intelligence, in particular to a Drools rule dynamic generation method and system based on a commodity knowledge base. Background In an enterprise digital operation system, a commodity data relationship is a key infrastructure for supporting business decisions, and specifically covers core contents such as an association relationship between a product and a commodity, a relationship between the commodity and an organization structure, mapping logic between pricing and attributes of the commodity, a dependence relationship between commodity attributes, a matching mechanism of a business rule and the commodity. Currently, drools is a widely used rule engine in the industry, and service logic is usually defined by a rule file (such as a drl file). However, in such application scenarios, traditional rule development approaches face the following significant bottlenecks: 1. The manual dependency degree is high, the rule file is written completely by manually constructing according to the commodity data relationship, the development efficiency is low, the rule failure is easily caused by human negligence (such as logic omission and parameter configuration errors), and the later-stage problem investigation and repair cost is high. 2. The business adaptation capability is insufficient, when the data relationship of the commodity is changed (such as newly-added commodity attribute, adjusting product association strategy, updating attribute matching condition, etc.), the rule file needs to be manually modified or rewritten by a developer, the response is slow, and the rapidly-changed business requirement is difficult to support. 3. The complex logic processing capability is limited, and the problems of logic conflict, incomplete coverage of boundary scenes and the like are easily caused by manual writing rules, and debugging and tracing are difficult in the face of multi-dimensional and cross-level commodity production relations (for example, nested logic such as 'the commodity B related to the product A needs to meet the attribute C and simultaneously matches the combination condition of the attribute E and the attribute F of the commodity D'). Although the prior art has attempted to generate rules in batches by a template mode so as to improve the development efficiency, the method generally lacks the understanding and resolving capability of deep semantics of the commodity relation, is difficult to accurately process complex association logic, and does not introduce artificial intelligence technology to realize intelligent optimization and dynamic adaptation of the rules. Therefore, how to provide a method and a system for dynamically generating Drools rules based on commodity knowledge base, so as to improve accuracy, flexibility and response efficiency of rule generation, and the method and the system are a technical problem to be solved urgently. Disclosure of Invention The invention aims to solve the technical problem of providing a Drools rule dynamic generation method and system based on a commodity knowledge base, and the accuracy, flexibility and response efficiency of rule generation are improved. In a first aspect, the present invention provides a method for dynamically generating Drools rules based on a knowledge base of commodity production, comprising the following steps: step S1, defining entity attributes and association relations among the entities based on the entities of the commodity, and constructing a commodity relation model based on the entity attributes and the association relations; S2, acquiring commodity basic data, preprocessing the commodity basic data at least comprising data cleaning and data normalization based on the commodity relation model, and constructing a commodity knowledge base based on the preprocessed commodity basic data; s3, setting a rule template based on a Drools rule grammar; S4, creating a prompt word library, defining prompt word instructions for guiding the AI large model based on a rule scene, and storing the prompt word instructions into the prompt word library; S5, the AI large model analyzes commodity relation logic based on the commodity knowledge base and the prompt word base, and generates a Drools rule file based on a rule template matched with the commodity relation logic; S6, carrying out asynchronous grammar check, logic conflict check and service suitability check on the Drools rule file; And S7, issuing the checked Drools rule file to a rule engine for deployment and testing. Further, in the step S1, the association relationship includes a mutual exclusion relationship, a dependency relationship, a cancel and change relationship, and a special and no relationship. Further, the step S2 specifically includes: And acquiring commodity basic data from a database tabl