A prompt word dynamic generation method based on a domain ontology
By using a variable system based on domain ontology and a semantically structured assignment method, the problems of semantic ambiguity and low reusability in existing prompt word generation technologies are solved, achieving efficient and accurate prompt word generation.
Patent Information
- Application Number
- CN202511851520.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-10
- Publication Date
- 2026-02-17
- Estimated Expiration
- 2045-12-10
AI Technical Summary
Existing prompt generation technologies lack a structured understanding of global knowledge, leading to semantic ambiguity, inability to accurately adapt to professional and complex business scenarios, and low template reusability and maintenance efficiency.
A variable system is built based on the domain ontology. The context data is deeply extracted and interpreted through the semantic structure of the scene variables. Values are assigned in real time in strict accordance with the semantic path to generate high-quality, structured prompt words.
It improves the reusability and maintenance efficiency of prompt word templates, meets the needs of large models for high-quality, structured contextual information, and achieves accurate adaptation of prompt words.
Smart Images

Figure CN121301587B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the technical field of prompt word engineering, and more specifically, to a method for dynamically generating prompt words based on domain ontology. Background Technology
[0002] Prompt word engineering, as an interaction method relying on natural language, focuses on designing appropriate prompts to guide large language models in generating the desired output. Ontology, a high-quality and rigorous knowledge graph, establishes modeling meta-terms such as classes, relations, attributes, individuals, instances, and rules, and defines typical relations and attributes. It establishes a structural framework and semantic standards for the definition of entities and relations. Domain ontology, in particular, deeply organizes concepts and their interrelationships within a specific domain, possessing strong professionalism and logical constraints. It is widely used in information retrieval, deep analysis, and knowledge automation, serving as a key foundation for improving system intelligence. Therefore, applying domain ontology to prompt word engineering has significant application prospects.
[0003] While dynamic generation techniques for prompts have emerged in the existing field of prompt engineering, incorporating the concept of object variables, these solutions have significant limitations. Current variable handling largely remains at a superficial level of contextual text replacement. Dynamic generation relies solely on local information from the current dialogue (such as the user's last sentence), lacking a structured understanding of global knowledge and the support of a structured variable system based on a semantic knowledge base. This means that variables in existing prompt templates are typically unconstrained and non-standardized, making it difficult to leverage inherent logical relationships within domain knowledge to verify data accuracy or supplement deeper background knowledge. This leads to semantic ambiguity during prompt generation, hindering accurate adaptation to specialized and complex business scenarios. Furthermore, the reusability and maintenance efficiency of prompt templates are low, failing to meet the urgent needs of large models for high-quality, structured contextual information. Summary of the Invention
[0004] To address the issues of low semantic accuracy and inability to accurately adapt to specialized business scenarios in existing prompt generation methods, this invention proposes a dynamic prompt generation method based on domain ontology. This method improves the semantic accuracy of prompts during the generation process, accurately adapts to specialized and complex business scenarios, and offers high reusability and maintenance efficiency of prompt templates, thus meeting the urgent need of large models for high-quality, structured contextual information.
[0005] To achieve the above-mentioned technical effects, the technical solution of the present invention is as follows:
[0006] Firstly, this application proposes a method for dynamically generating prompts based on domain ontology, comprising the following steps:
[0007] Receive user requests, determine the requested application scenario based on the user requests, and match pre-set prompt word templates and scenario variables based on the requested application scenario;
[0008] Based on the domain ontology structure of the current application scenario, an ontology variable system is constructed, and the semantic structure of scenario variables is defined based on the ontology variable system.
[0009] The context data of the current session in which the user request is located and the domain ontology of the application scenario of the request are extracted and interpreted, and the scenario variables are assigned values in real time based on the semantic structure of the defined scenario variables.
[0010] The prompt words are dynamically generated using the assigned scene variables.
[0011] In this technical solution, the user request is first received to determine the specific application scenario. Based on the ontology structure of the current application scenario domain, an ontology variable system is constructed and a structured prompt word template containing preset scenario variables is matched. On this basis, the context data of the current session is deeply extracted and interpreted, and the unstructured user input is mapped to instance data of the domain ontology. The structured prompt word template of the scenario variable is accurately assigned in real time according to the semantic path defined by the scenario variable, which greatly improves the reusability and maintenance efficiency of the prompt word template. Finally, prompt words are dynamically generated using the assigned scenario variables, thereby meeting the urgent need of large models for high-quality, structured context information.
[0012] Preferably, the prompt word template includes a role definition submodule, a task instruction submodule, a background knowledge submodule, and an output requirement submodule; the role definition submodule sets the identity of the large model in the current session; the task instruction submodule is used to describe the specific requirements of the business; the background knowledge submodule provides background information in the professional field; and the output requirement submodule defines the output format requirements of the data generated to complete the instruction requirements.
[0013] Preferably, the ontology variable system includes context-assigned variables and ontology data extraction variables. The context-assigned variables and ontology data extraction variables are used together as scenario variables in the prompt word template corresponding to a certain request application scenario, and are inserted into the prompt word template as placeholders. During the prompt word generation process, the scenario variables are dynamically assigned values.
[0014] Preferably, the semantic structure of the context-assigned variables supports multi-level structure definition. The context-assigned variables include: class-level sub-variables, attribute-level sub-variables, relation-level sub-variables, and relation-attribute-level sub-variables. The class-level sub-variables are used to extract individual instances and sets of instances belonging to a specified class from the context data of the current session in the application scenario and assign values. The attribute-level sub-variables are used to extract specific attribute values corresponding to instances in the set of individual instances and assign values. The relation-level sub-variables are used to extract and assign values to a set of associated objects that have a specific semantic relationship with the set of individual instances. The relation-attribute-level sub-variables are used to extract and assign values to a set of associated objects in the set of individual instances whose attributes have specific attribute values in the relation.
[0015] Preferably, the semantic structure of the ontology data extraction variables supports multi-level structure definition, including: architecture layer sub-variables, data layer sub-variables, and relationship layer sub-variables; the architecture layer sub-variables are used to extract the ontology's classification system and concept definitions, the data layer sub-variables are used to extract the data list of a specific category under the ontology's classification system, and the relationship layer sub-variables are used to extract the relationship between the classification system obtained by the architecture layer sub-variables and the specific data obtained by the data layer sub-variables, thus obtaining a complete knowledge description.
[0016] Preferably, the context-assigned variable is instantiated and assigned a value based on the user request and context data, and the process is as follows:
[0017] Parse the context data in the user request, and identify and extract the attribute values or relational objects in the context data;
[0018] Based on the semantic structure defined by the context assignment variable, unstructured attribute values or relational objects extracted from the context data are mapped to instances that conform to the semantic structure.
[0019] The instance that conforms to the semantic structure is assigned to the context assignment variable, thus completing the instantiation assignment of the context assignment variable.
[0020] Preferably, the ontology data extraction variable extracts background knowledge data from the domain ontology of the requested application scenario, and injects the background knowledge data into the background knowledge submodule of the prompt word template. The process is as follows:
[0021] Parse the sub-variables of the architecture layer and extract the complete classification system, concept definitions and their hierarchical structure involved in the request application scenario from the domain ontology;
[0022] Use data layer sub-variables to traverse specific instance data belonging to the above architecture layer sub-variables from the domain ontology;
[0023] By utilizing the relationship layer sub-variables, the classification system obtained from the architecture layer sub-variables is extracted, and the specific data obtained from the data layer sub-variables is used to form complete background knowledge data;
[0024] Background knowledge data is injected into the prompt word template in natural language form, and the ontology data extraction variables in the scene variables are assigned values.
[0025] Secondly, this application also proposes a dynamic prompt word generation system based on domain ontology, the system comprising:
[0026] The scenario variable matching module is used to receive user requests, determine the requested application scenario based on the user requests, and match pre-set prompt word templates and scenario variables based on the requested application scenario;
[0027] The scene variable semantic structure definition module is used to construct an ontology variable system based on the domain ontology structure of the current application scenario, and to define the semantic structure of scene variables based on the ontology variable system.
[0028] The scenario variable assignment module is used to extract and interpret the context data of the current session in which the user request is located and the domain ontology of the request application scenario, and to assign values to the scenario variables in real time based on the semantic structure of the defined scenario variables.
[0029] The prompt word generation module is used to dynamically generate prompt words using the assigned scene variable values.
[0030] Thirdly, this application also proposes a computer device, which includes a memory, a processor, and a computer program stored in the memory that can be run on the processor. The processor executes the computer program to implement the aforementioned method for dynamically generating prompts based on domain ontology.
[0031] Fourthly, this application also proposes a computer storage medium storing a computer program, the computer program including program instructions, which, when executed by a computer, cause the computer to execute the aforementioned method for dynamically generating prompts based on domain ontology.
[0032] Compared with the prior art, the beneficial effects of the present invention are:
[0033] This invention proposes a method for dynamically generating prompt words based on domain ontology. First, it receives user requests to determine the specific application scenario. Then, it constructs an ontology variable system based on the ontology structure of the current application scenario domain and matches it with a structured prompt word template containing preset scenario variables. Next, it deeply extracts and interprets the context data of the current session, mapping unstructured user input to instance data of the domain ontology. Finally, it precisely assigns real-time values to the structured prompt word templates of the scenario variables according to the semantic paths defined by the scenario variables. This significantly improves the reusability and maintenance efficiency of the prompt word templates. Ultimately, it dynamically generates prompt words using the assigned scenario variables, thus meeting the urgent need of large models for high-quality, structured contextual information. Attached Figure Description
[0034] Figure 1 This is a flowchart illustrating a method for dynamically generating prompts based on domain ontology, as proposed in Embodiment 1 of the present invention.
[0035] Figure 2 A schematic diagram illustrating the structural definition and instantiation relationship of the ontology variable system proposed in Embodiment 2 of the present invention;
[0036] Figure 3 This is a schematic diagram illustrating the structure of a prompt word dynamic generation system based on domain ontology proposed in Embodiment 3 of the present invention;
[0037] Figure 4 This is a schematic diagram of the structure of the computer device proposed in Embodiment 4 of the present invention. Detailed Implementation
[0038] The accompanying drawings are for illustrative purposes only and should not be construed as limiting the scope of this patent.
[0039] To better illustrate this embodiment, some parts of the accompanying drawings may be omitted, enlarged, or reduced, and do not represent the actual dimensions;
[0040] It is understandable to those skilled in the art that some well-known details may be omitted from the accompanying drawings.
[0041] The technical solution of the present invention will be further described below with reference to the accompanying drawings and embodiments.
[0042] The positional relationships depicted in the accompanying drawings are for illustrative purposes only and should not be construed as limiting this patent.
[0043] Example 1
[0044] This embodiment proposes a method for dynamically generating prompts based on domain ontology. A flowchart illustrating this method can be found here. Figure 1 This includes the following steps:
[0045] S1. Receive a user request, determine the requested application scenario based on the user request, and match a pre-set prompt word template and scenario variable based on the requested application scenario;
[0046] S2. Based on the domain ontology structure of the current application scenario, construct an ontology variable system, and define the semantic structure of scenario variables based on the ontology variable system;
[0047] S3. Extract and interpret the context data of the current session in which the user request is located and the domain ontology of the application scenario of the request, and assign values to the scenario variables in real time based on the semantic structure of the defined scenario variables;
[0048] S4. Dynamically generate prompt words using the assigned scene variables.
[0049] In this embodiment, a user request is first received, the specific application scenario is determined, and an ontology variable system is constructed based on the ontology structure of the current application scenario domain. A structured prompt word template containing preset scenario variables is then matched. Based on this, the context data of the current session is deeply extracted and interpreted, mapping unstructured user input to instance data of the domain ontology. The structured prompt word template of the scenario variables is then precisely assigned values in real time according to the semantic path defined by the scenario variables. This significantly improves the reusability and maintenance efficiency of the prompt word template. Finally, prompt words are dynamically generated using the assigned scenario variables, thus meeting the urgent need of large models for high-quality, structured contextual information.
[0050] Example 2
[0051] In this embodiment, the prompt word template includes a role definition submodule, a task instruction submodule, a background knowledge submodule, and an output requirement submodule; the role definition submodule sets the identity of the large model in the current session; the task instruction submodule is used to describe the specific requirements of the business; the background knowledge submodule provides background information in the professional field; and the output requirement submodule defines the output format requirements of the data generated to complete the instruction requirements.
[0052] Specifically, the user requests include specific requirements for scenarios such as entity extraction, information classification, business review, paper search, and text summarization. For example, "check the papers written by Zhang San in the last 3 years" belongs to the "paper search" scenario. Some scenarios include contextual content. For example, to classify specified information, the classification criteria and the data to be classified must be given. Entity extraction also requires the target text to be extracted.
[0053] Specifically, taking the analysis of work order content in the telecommunications field as an example, the role definition submodule is used to set the identity of the large model in the current session, so that its reply conforms to the tone of a specific profession or expert. The specific sub-template content includes: "You are a professional telecommunications analyst, focusing on work order content analysis."
[0054] The task instruction submodule is used to describe specific business requirements, embedding context-assigned variables prefixed with the symbol $ and ontology data extraction variables prefixed with the symbol $$. These variables are like "fill-in-the-blank questions," where the system will fill in the specific data input by the user (such as the specific work order text) at runtime. The specific sub-template content includes: "Analyze the problem products and phenomena mentioned in ${individual set: Thing\work order.content}, where the products must be in $${class set: Thing\product.name}, $${individual set: Thing\product.name} or $${class set: Thing\product.synonyms}, $${individual set: Thing\product.synonyms}, and find the classification path of each product as the product type. Output ${individual set: Thing\work order} and the corresponding product type, product, and problem phenomenon in a list."
[0055] The background knowledge submodule is used to provide background information within a specific professional field. When the system runs on ontology data extraction variables, it will query the data in the domain ontology library. For example, for the variable instruction $${class set: Thing\product.name}, the system will scan all individual instances under the class "Thing\product" in the domain ontology and extract the names and attribute values of these instances, ultimately forming a list or set.
[0056] In this embodiment, the ontology variable system includes context-assigned variables and ontology data extraction variables. The context-assigned variables and ontology data extraction variables are used together as scenario variables in the prompt word template corresponding to a certain request application scenario, and are inserted into the prompt word template as placeholders. During the prompt word generation process, the scenario variables are dynamically assigned values.
[0057] In this embodiment, the semantic structure of the context assignment variable supports multi-level structure definition. The context assignment variable includes: class-level sub-variables, attribute-level sub-variables, relation-level sub-variables, and relation-attribute-level sub-variables. The class-level sub-variables are used to extract individual instances and sets of instances belonging to a specified class from the context data of the current session in the application scenario and assign values. The attribute-level sub-variables are used to extract specific attribute values corresponding to instances in the set of individual instances and assign values. The relation-level sub-variables are used to extract and assign values to a set of associated objects that have a specific semantic relationship with the set of individual instances. The relation-attribute-level sub-variables are used to extract and assign values to a set of associated objects in the set of individual instances that have the relationship and whose attribute has a specific attribute value.
[0058] Specifically, context-assigned variables include individual set variables and individual variables; wherein, the individual set variables are used to process batch data, which extracts a set of data that meets specific conditions from the context data of the current session and presents it in the form of a set or list, and is usually used in statistical, classification or batch analysis scenarios; the individual variables are used to process a single specific instance, which points to a specific object in the set, and is usually used to perform in-depth analysis or detailed display of a single complex object.
[0059] Table 1
[0060]
[0061] Specifically, the syntax and definition of individual set variables in context assignment variables are shown in Table 1. Table 1 defines four levels of variable forms: First, class-level set variables, with the syntax ${individual set: class}, for example ${individual set: Thing\work order}, represent the set of all individual variables in the current session's context data that conform to the "work order" class structure, and implicitly include all attributes and relationships of that class; second, attribute-level set variables, with the syntax ${individual set: class.attribute}, for example ${individual set: Thing\work order.source}, specifically represent the "source" attribute in the "work order" class. The first set of variables is the set of objects at the relational object level. The third set is the set of objects at the relational object level, defined with the syntax ${individual set: class.relation}, for example, ${individual set: Things\work order.associated customer}. This represents the set of object variables pointed to by the "work order" class through the "associated customer" relationship. Finally, there is the set of objects at the relational object attribute level, defined with the syntax ${individual set: class.relation.attribute}, for example, ${individual set: Things\work order.associated customer.name}. This represents the set of "name" attribute variables of the object after the "work order" class finds the corresponding object through the "associated customer" relationship, demonstrating the system's ability to extract specific attribute data across entities.
[0062] Table 2
[0063]
[0064] Specifically, the syntax and definition of individual variables in context assignment variables are shown in Table 2. Table 2 defines four levels of variable forms: First, single-class instance variables, with the syntax ${individual:class}, such as ${individual:Thing\work order}, refer to a specific work order instance in the context data of the current session, such as "work order 001", and serve as the basis for subsequent attribute references; second, single-attribute value variables, with the syntax ${individual:class.attribute}, such as ${individual:work order.source}, represent a specific attribute value of the specific work order instance; third, single-relationship variables... The first type is the object variable, defined by syntax ${individual: class.relationship}, for example ${individual: work order.associated customer}. It represents the specific customer object associated with the work order through the "associated customer" relationship. The second type is the single-relationship object attribute variable, defined by syntax ${individual: class.relationship.attribute}, for example ${individual: work order.associated customer.name} or ${individual: work order.associated customer.product}. It represents the attribute value such as "name" or "product" of the associated customer object of the work order (such as "Zhang San" or "mobile phone"), thus realizing precise referencing and assignment of cross-entity attributes of a single instance.
[0065] Specifically, the assignment process also involves an agent that analyzes the context of the current session and the reasoning results based on ontology, performs set operations in the maximum candidate space to obtain a specific subset of individuals. Finally, the variables in the prompt word template are filled only with data from this specific subset, completing the assignment of context-based variables.
[0066] In this embodiment, the semantic structure of the ontology data extraction variables supports multi-level structure definition, including: architecture layer sub-variables, data layer sub-variables, and relationship layer sub-variables; the architecture layer sub-variables are used to extract the ontology's classification system and concept definitions, the data layer sub-variables are used to extract the data list of a specific category under the ontology's classification system, and the relationship layer sub-variables are used to extract the relationship between the classification system obtained by the architecture layer sub-variables and the specific data obtained by the data layer sub-variables, thus obtaining a complete knowledge description.
[0067] Specifically, the architecture layer sub-variables include class set items and class name items, the data layer sub-variables include individual set items, and the relationship layer sub-variables include triples. The individual set item is used to extract the complete set of specific instance data under a given class. This is typically used to generate "whitelists," "standard lists," or "known entity libraries" for large models. The class set item is used to extract the ontology's taxonomy; it doesn't concern itself with specific instances (e.g., "Zhang San"), but only with the classification system itself (e.g., what subcategories are under "work order"). The class name item is used to extract the metadata of a single class definition. It focuses on the conceptual definition of the "class" itself, such as synonyms or aliases, rather than its instances or subclasses.
[0068] Table 3
[0069]
[0070] Specifically, the syntax and definition of the individual set item are shown in Table 3, which details four variable extraction methods: First, extract all individual data of a specified class, with the syntax defined as $${individual set: class}, used to return all individual instances under the specified class in the ontology. These instances contain all attributes and relationships. For example, $${individual set: Thing\User} can extract all user instances. Second, extract only the specified attribute value of all individuals of a specified class, with the syntax defined as $${individual set: class.attribute}, used to return the single attribute value of all individuals under the specified class. For example, $${individual set: Thing\User.Name} is used to extract the names of all users. Third, extract the individual set of relation objects of the class, with the syntax defined as $${individual set: class.relation}, used to return the set of object variables pointed to by all individuals under the specified class through a specific relationship. Finally, extract the attribute of a specified relation object from all individual data of a specified class, with the syntax defined as $${individual set: class.relation.attribute}, realizing cross-entity information extraction. For example, $${individual set: Thing\work order.associated customer.name} represents extracting the set of attribute variables of customers associated with the work order class.
[0071] Table 4
[0072]
[0073] Specifically, the syntax and definition of the class set item are shown in Table 4. Table 4 defines the variable form for extracting data from all subclasses (including subclasses of subclasses) of a specified class, with the syntax structure $${class set: class}. This variable can obtain the complete inheritance hierarchy of a class in the ontology, including entity classification, class hierarchy, and the attributes and relationships of concepts. For example, in the telecommunications domain ontology, using the variable ${class set: Thing\work order} can extract all related subclass sets, including "Thing\work order" itself, "Thing\work order\preprocessing", "Thing\work order\complaint", and "Thing\work order\extra-level complaint", thus providing a precise business classification scope background for the large model.
[0074] Table 5
[0075]
[0076] Specifically, the syntax structure and definition of class names are shown in Table 5. Table 5 defines the syntax for four extraction dimensions, including extracting a specified class or individual, extracting the attribute values of a specified class or individual, extracting objects connected by relationships, and further extracting the attribute values of relational objects. The explanation column on the right side of the table further illustrates its application logic through an example of the "work order" ontology. For example, through the variable $${object: Thing\work order\escalation complaint.synonym}, the system can directly obtain the synonym "escalation complaint" defined in the ontology for this class. This demonstrates the use of ontology variables to achieve semantic and structural unity, and the use of ontology hierarchy and relationship networks (such as classes, attributes, and relationships) to enhance the accuracy and standardization of prompt word generation, thereby avoiding the limitations of traditional variables that require manual value definition.
[0077] Specifically, the triple includes a variable string in the prompt word template that starts with $$ and is identified as a "triple". It is used to extract the relationship between the classification system obtained by the architecture layer sub-variable and the specific data obtained by the data layer sub-variable in the domain ontology. For example, for $${triple: (Subject, property: Property, Value) pattern: the property of Subject is Value}, when the triple variable is assigned a value, the variable indicates that all instances of the extraction class "Product" and its subclasses are extracted from the domain ontology and natural language is generated according to the style of "the property of Subject is Value".
[0078] In this embodiment, the context assignment variable is instantiated and assigned a value based on the user request and context data. The process is as follows:
[0079] Parse the context data in the user request, and identify and extract the attribute values or relational objects in the context data;
[0080] Based on the semantic structure defined by the context assignment variable, unstructured attribute values or relational objects extracted from the context data are mapped to instances that conform to the semantic structure.
[0081] The instance that conforms to the semantic structure is assigned to the context assignment variable, thus completing the instantiation assignment of the context assignment variable.
[0082] Specifically, after parsing the context data in the user request, the method further includes identifying entities in the context data based on entity feature definitions in the domain ontology; the entity feature definitions in the domain ontology include class names, class descriptions, class attributes, class relationships, and individual names, individual attributes, and individual relationships under each class.
[0083] Specifically, the identification and extraction of attribute values or relation objects in the context data also includes extraction according to the semantic structure of entity-attribute-attribute value and entity-relation object;
[0084] Specifically, taking work order text as an example, the context data in a user request includes the input work order text, documents, etc. Semantic parsing is performed on this data, identifying a batch of work order texts uploaded by the user as instances of the "Thing\Work Order" class, thus transforming the raw data into structured instance data conforming to the ontology definition. Next, the system parses the semantic structure of predefined scene variables (i.e., context-assigned variables) in the prompt word template. This structure specifies the data navigation path, including class-level, attribute-level, relation-level, or cross-entity relation attribute-level paths, such as ${individual set: Thing\Work Order.Associated Customer.Name}. Finally, the system strictly follows the parsed semantic path, performing targeted retrieval in the mapped instance data or graph traversal through ontology relationships. It extracts the corresponding attribute values or relation objects according to structures such as entity-attribute-attribute value and entity-relationship object, and assigns these extracted specific business data to the corresponding scene variables in the template in real time, thereby completing the instantiation and filling of variable placeholders in the prompt words.
[0085] In this embodiment, the ontology data extraction type variable extracts background knowledge data from the domain ontology of the requested application scenario, and injects the background knowledge data into the background knowledge submodule in the prompt word template. The process is as follows:
[0086] Parse the sub-variables of the architecture layer and extract the complete classification system, concept definitions and their hierarchical structure involved in the request application scenario from the domain ontology;
[0087] Use data layer sub-variables to traverse specific instance data belonging to the above architecture layer sub-variables from the domain ontology;
[0088] By utilizing the relationship layer sub-variables, the classification system obtained from the architecture layer sub-variables is extracted, and the specific data obtained from the data layer sub-variables is used to form complete background knowledge data;
[0089] Background knowledge data is injected into the prompt word template in natural language form, and the ontology data extraction variables in the scene variables are assigned values.
[0090] Specifically, the concept definition includes concept attributes and relationships.
[0091] Specifically, the ontology variable system also includes an inheritance mechanism and a value constraint mechanism: the inheritance mechanism indicates that the variables of the subclass in the domain ontology automatically inherit the attribute variable structure and relation variable structure defined by the parent class, without having to redefine them for the subclass; the value constraint mechanism restricts the value type of the variable at instantiation to the data type defined by the corresponding attribute in the domain ontology.
[0092] Specifically, regarding the inheritance mechanism, if a parent class variable ${individual:Thing\work order.source} is defined, then for the subclass "complaint work order" (Thing\work order\complaint), the system automatically identifies and supports the variable path ${individual:Thing\work order\complaint.source} without manual intervention. This is in stark contrast to traditional variables, which typically lack contextual constraints, rely on naming conventions, and often require manual copying of the variable structure to different business objects.
[0093] Specifically, taking the analysis of work order content in the telecommunications field as an example, the structural definition of the ontology variable system and its instantiation relationship are shown in the following diagram. Figure 2 As shown, Figure 2 The leftmost "Work Order" node represents the parent class concept, from which three subclass nodes—"Preprocessing," "Ascending Complaint," and "Complaint"—are derived, reflecting the class inheritance hierarchy of the ontology. The diagram also defines the core semantic relationships between classes: the "Work Order" class and its subclasses point to the "User" class through the "Associated Customer" relationship, and to the "Product" class through the "Associated Product" relationship. This establishes the semantic path for cross-entity reference variables (such as ${individual set: Work Order.Associated Customer}). The center of the diagram displays a timestamp identifier (i.e....). Figure 2 The specific work order instance "202301031030055543" belongs to the "Extra-level Complaint" subclass. Based on the "Associated Customer" and "Associated Product" relationship structure defined in the ontology, it specifically points to the instance "Zhang San" of the "User" class and the instance "Mobile Phone" of the "Product" class. This vividly illustrates how the system instantiates the abstract variable path into specific business data (i.e., the customer associated with the work order is Zhang San, and the associated product is Mobile Phone) according to the ontology structure during the prompt word generation process.
[0094] Specifically, regarding the value constraint mechanism, the system uses standard data types such as xsd:string, xsd:integer, and xsd:date to constrain variables. When the system parses context data and attempts to assign values to variables, it performs validation based on the ontology definition. For example, if the ontology defines the "work order quantity" attribute as an integer, then the variable cannot accept non-numeric text values. This differs from the traditional variable's "direct definition" and "lack of background constraints."
[0095] Example 3
[0096] This embodiment proposes a dynamic prompt word generation system based on domain ontology. In this embodiment, the system is used to implement a dynamic prompt word generation method based on domain ontology. The structural diagram is shown below. Figure 3 As shown, it includes:
[0097] The scenario variable matching module is used to receive user requests, determine the requested application scenario based on the user requests, and match pre-set prompt word templates and scenario variables based on the requested application scenario;
[0098] The scene variable semantic structure definition module is used to construct an ontology variable system based on the domain ontology structure of the current application scenario, and to define the semantic structure of scene variables based on the ontology variable system.
[0099] The scenario variable assignment module is used to extract and interpret the context data of the current session in which the user request is located and the domain ontology of the request application scenario, and to assign values to the scenario variables in real time based on the semantic structure of the defined scenario variables.
[0100] The prompt word generation module is used to dynamically generate prompt words using the assigned scene variables.
[0101] Example 4
[0102] In this embodiment, a computer device 100 is proposed, which includes a memory 101, a processor 102, and a computer program stored in the memory 101 that can be executed by the processor. The processor 102 executes the computer program to implement a method for dynamically generating prompt words based on domain ontology. A schematic diagram of the device structure is shown below. Figure 4 As shown.
[0103] In this embodiment, a computer storage medium is also proposed, on which a computer program is stored. The computer program includes program instructions, which, when executed by a computer, cause the computer to execute the aforementioned method for dynamically generating prompts based on domain ontology.
[0104] Obviously, the above embodiments of the present invention are merely examples for clearly illustrating the present invention, and are not intended to limit the implementation of the present invention. Those skilled in the art can make other variations or modifications based on the above description. It is neither necessary nor possible to exhaustively describe all embodiments here. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the scope of protection of the claims of the present invention.
Claims
1. A domain ontology-based prompt word dynamic generation method, characterized in that, The method comprises the following steps: receiving a user request, determining a request application scenario according to the user request, and matching a pre-set prompt word template and a scenario variable based on the request application scenario; based on the domain ontology structure of the current application scenario field, constructing an ontology variable system, and defining the semantic structure of the scenario variable based on the ontology variable system; the ontology variable system includes context assignment type variables and ontology data extraction type variables; the context assignment type variables and the ontology data extraction type variables are jointly used as scenario variables in the prompt word template corresponding to a certain request application scenario, and are inserted into the prompt word template as placeholders, and the scenario variables are dynamically assigned during the prompt word generation process; the ontology variable system includes context assignment type variables and ontology data extraction type variables; the context assignment type variables and the ontology data extraction type variables are jointly used as scenario variables in the prompt word template corresponding to a certain request application scenario, and are inserted into the prompt word template as placeholders, and the scenario variables are dynamically assigned during the prompt word generation process; The semantic structure of the ontology data extraction type variable supports multi-level structure definition, including: architecture layer sub-variables, data layer sub-variables and connection layer sub-variables; the architecture layer sub-variables are used to extract the classification system and concept definition of the ontology, the data layer sub-variables are used to extract the data list of a specific category under the classification system of the ontology, and the connection layer sub-variables are used to extract the connection between the classification system obtained by the architecture layer sub-variables and the specific data obtained by the data layer sub-variables, to obtain a complete knowledge description; extract and interpret the context data of the current session of the user request and the domain ontology of the request application scenario, and assign the scenario variables in real time based on the defined semantic structure of the scenario variables; generate the prompt word dynamically using the assigned scenario variables.
2. The method of claim 1, wherein, The prompt word template includes a role definition sub-module, a task instruction sub-module, a background knowledge sub-module, and an output requirement sub-module; The role definition sub-module sets the identity of the large model in the current session; the task instruction sub-module is used to describe the specific requirements of the business; the background knowledge sub-module provides background information in the professional field; and the output requirement sub-module defines the output format requirements of the generated data to complete the instruction requirements. 3.The domain ontology-based prompt word dynamic generation method of claim 1, wherein, The context assignment type variable is instantiated and assigned based on the user request and the context data, and the process is as follows: parsing the context data in the user request, identifying and extracting the attribute values or relationship objects in the context data; based on the semantic structure defined by the context assignment type variable, mapping the unstructured attribute values or relationship objects extracted from the context data into instances conforming to the semantic structure; assign the instances conforming to the semantic structure to the context assignment type variable to complete the instantiation and assignment of the context assignment type variable.
4. The method of claim 1, wherein the method further comprises: The ontology data extraction type variable extracts background knowledge data from the domain ontology of the request application scenario, and injects the background knowledge data into the background knowledge sub-module in the prompt word template, and the process is as follows: The architecture layer sub-variable is parsed, and a complete classification system, concept definition and hierarchical structure involved in the application scene are extracted from the domain ontology; The data layer sub-variable is used to traverse specific instance data belonging to the architecture layer sub-variable from the domain ontology; The contact layer sub-variable is used to extract the contact between the classification system obtained by the architecture layer sub-variable and the specific data obtained by the data layer sub-variable, and form complete background knowledge data; The background knowledge data is injected into the prompt word template in the form of natural language to complete the assignment of the ontology data extraction type variable in the scene variable.
5. A domain ontology-based prompt word dynamic generation system, characterized in that, It comprises: A scene variable matching module is configured to receive a user request, determine an application scene of the user request based on the user request, and match a pre-set prompt word template and a scene variable based on the application scene. A scene variable semantic structure definition module is configured to construct an ontology variable system based on a domain ontology structure, and define a semantic structure of a scene variable based on the ontology variable system; the ontology variable system comprises a context assignment type variable and an ontology data extraction type variable, and the context assignment type variable and the ontology data extraction type variable are jointly used as scene variables in a prompt word template corresponding to a certain request application scene and are inserted into the prompt word template as placeholders, and the scene variables are dynamically assigned in a prompt word generation process; the ontology variable system comprises a context assignment type variable and an ontology data extraction type variable, and the context assignment type variable and the ontology data extraction type variable are jointly used as scene variables in a prompt word template corresponding to a certain request application scene and are inserted into the prompt word template as placeholders, and the scene variables are dynamically assigned in a prompt word generation process; The semantic structure of the ontology data extraction type variable supports multi-level structure definition, and comprises an architecture layer sub-variable, a data layer sub-variable and a contact layer sub-variable; the architecture layer sub-variable is used to extract a classification system and concept definition of an ontology, the data layer sub-variable is used to extract a data list of a certain specific category under the classification system of the ontology, and the contact layer sub-variable is used to extract the contact between the classification system obtained by the architecture layer sub-variable and the specific data obtained by the data layer sub-variable, and obtain complete knowledge description; A scene variable assignment module is configured to assign context data and interpretation of a current session of a user request based on a defined semantic structure of a scene variable. A prompt word generation module is configured to dynamically generate a prompt word by using the assigned scene variable value.
6. A computer device, comprising: The computer device comprises a memory, a processor and a computer program stored on the memory and executable by the processor, the processor executes the computer program to implement the prompt word dynamic generation method based on the domain ontology according to any one of claims 1-4.
7. A computer storage medium, characterized in that The computer program comprises program instructions, and when the program instructions are executed by a computer, the computer executes the prompt word dynamic generation method based on the domain ontology according to any one of claims 1-4.
Citation Information
Patent Citations
Data generation method and device, equipment, storage medium and product
CN119337918A
Methods and systems for ontology construction with ai-mediated crowdsourcing and concept mining for high-level activity understanding
US20240112044A1