Sensor value matching method and device, medium and program product
By constructing a collection of node structures and obtaining the target node structure, the problem of inefficient matching of sensor numerical data is solved, efficient matching of numerical data and rules is achieved, and real-time requirements for IoT data processing are met.
Patent Information
- Application Number
- CN202411671880.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-21
- Publication Date
- 2025-03-11
- Estimated Expiration
- 2044-11-21
AI Technical Summary
When processing large amounts of sensor numerical data, the matching efficiency is inefficient and cannot meet the real-time requirements of IoT data processing.
By constructing a collection of node structures, the target node structure corresponding to the value to be matched is obtained, and the corresponding rule link list is obtained based on the structure, thereby determining the rule matching result.
It greatly improves the matching efficiency of numerical data and rules, reduces the consumption of computing resources, and improves real-time and reliability.
Smart Images

Figure CN119598216A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of rule matching, and in particular to a sensor value matching method, device, medium and program product. Background Art
[0002] In the IoT scenario, it is usually necessary to perform real-time analysis and processing of a large amount of sensor data, and to implement functions such as event response and abnormal alarm by matching rules and monitoring values of these data.
[0003] Sensor data is mainly divided into string type data and numeric type data. For string type data, it can be processed using traditional multi-mode matching algorithms. However, for sensor data in numeric form such as temperature, humidity, and pressure, there is currently no multi-mode matching algorithm specifically for this type of numeric data.
[0004] At present, in the process of matching numerical data, it is necessary to traverse and match the values to be matched with the preset rules one by one. When a large amount of sensor data needs to be processed or there are many preset rules, the above traditional matching scheme not only consumes a lot of computing resources, but also has low matching efficiency and cannot meet the real-time requirements of IoT data processing. Summary of the invention
[0005] The purpose of the embodiments of the present application is to provide a sensor value matching method, device, medium and program product to improve the matching efficiency between numerical data and rules.
[0006] In a first aspect, an embodiment of the present application provides a sensor value matching method, including:
[0007] In response to a rule matching request for a value to be matched, a target node structure corresponding to the value to be matched is obtained from a pre-constructed node structure set; wherein the node structure set includes node structures corresponding to all value nodes of the rule set to be matched, and each of the node structures includes a plurality of value ranges and a rule linked list corresponding to each value range;
[0008] Determine a target value range of the to-be-matched value relative to the target node structure, obtain a rule linked list corresponding to the target value range from the target node structure, and determine a rule matching result corresponding to the to-be-matched value based on the rule linked list.
[0009] In an embodiment of the present application, a structure corresponding to each numerical node is constructed based on matching rules. When matching a numerical value, the structure corresponding to the numerical value is first matched, and then the corresponding rule linked list is obtained from the structure as the matching result based on the relationship between the numerical value and the structure. This eliminates the need to traverse and match all rules, thereby greatly improving the efficiency of numerical matching.
[0010] In some possible embodiments, the method for obtaining the node structure includes:
[0011] Obtain all the to-be-matched rules that currently need to be matched, and determine all the value nodes corresponding to each of the to-be-matched rules;
[0012] Determine a plurality of value ranges corresponding to each of the value nodes, and determine a rule linked list for each value range based on a matching condition between each of the to-be-matched rules and each of the value ranges;
[0013] A node structure corresponding to each numerical node is generated based on a plurality of numerical ranges corresponding to each numerical node and a rule linked list corresponding to each numerical range.
[0014] In an embodiment of the present application, by obtaining the numerical nodes of all the rules to be matched, and determining the corresponding rule linked list according to the matching situation between the rules to be matched and the numerical range, a node structure corresponding to each numerical node is constructed, thereby effectively improving the efficiency of numerical matching.
[0015] In some possible embodiments, determining a number of value ranges corresponding to each of the value nodes includes:
[0016] Arrange all the value nodes corresponding to the set of rules to be matched in order of small to large node values;
[0017] For the first numerical node with the smallest node value, determining the corresponding numerical ranges includes the following three items: a value equal to the node value itself, a value greater than the node value and less than the next node value, and a value less than the node value;
[0018] For the third numerical node with the largest node value, the corresponding numerical ranges are determined to include the following three items: a value equal to the node value itself, a value less than the node value and greater than the previous node value, and a value greater than the node value;
[0019] For the second numerical node other than the first numerical node and the third numerical node, determining the corresponding several numerical ranges includes the following three items: a value equal to the node value itself, a value less than this node value and greater than the previous node value, and a value greater than this node value and less than the next node value.
[0020] In an embodiment of the present application, different numerical range types are constructed for the minimum and maximum node values and the node values between the minimum and maximum node values, thereby reducing the amount of rule matching calculations in the process of constructing the node structure, thereby improving the efficiency of constructing the rule structure.
[0021] In some possible embodiments, in response to a rule matching request for a value to be matched, obtaining a target node structure corresponding to the value to be matched from a pre-built node structure set includes:
[0022] In response to a rule matching request for a value to be matched, determining whether the rule matching request meets a preset quick matching condition;
[0023] If yes, then obtaining a target node structure corresponding to the value to be matched from a pre-built node structure set;
[0024] If not, the to-be-matched values are matched one by one based on all the to-be-matched rules that currently need to be matched, so as to obtain a rule matching result corresponding to the to-be-matched values.
[0025] In the embodiment of the present application, different rule matching strategies are adopted according to whether the current numerical value match meets the fast matching condition, thereby further improving the flexibility of the numerical value matching.
[0026] In some possible embodiments, the determining whether the rule matching request meets a preset quick matching condition includes at least one of the following:
[0027] When the number of to-be-matched values currently to be processed exceeds a preset first threshold, determining that the rule matching request meets a preset quick matching condition;
[0028] When the number of to-be-matched rules that currently need to be matched exceeds a preset second threshold, it is determined that the rule matching request meets a preset quick matching condition.
[0029] In the embodiment of the present application, by judging whether the quick matching condition is met according to the data amount of the numerical value to be matched or the number of rules to be matched, the flexibility of the numerical value matching is further improved.
[0030] In some possible embodiments, obtaining a target node structure corresponding to the to-be-matched value from a pre-built node structure set includes:
[0031] Arrange all the value nodes corresponding to the rule set to be matched in ascending order of node value, and construct a value sequence to be matched based on the arranged value nodes;
[0032] Using a binary search method to determine the sequence position of the to-be-matched value relative to the to-be-matched value sequence, and taking one of the value nodes in the to-be-matched value sequence corresponding to the sequence position as a target value node;
[0033] A node structure corresponding to the target value node is obtained from a pre-constructed node structure set as a target node structure corresponding to the value to be matched.
[0034] In the embodiment of the present application, the binary search method is used to quickly locate and obtain the target node structure corresponding to the current value to be matched, thereby further improving the efficiency of value matching.
[0035] In some possible embodiments, the sensor value matching method further includes:
[0036] When an update event of the to-be-matched rule set is detected, the node structure set is updated based on the updated to-be-matched rule set.
[0037] In the embodiment of the present application, by monitoring the update events of the rules to be matched and updating the node structure in time when the rules are changed, the timeliness and reliability of the value matching are further improved.
[0038] In a second aspect, an embodiment of the present application provides a sensor value matching device, including:
[0039] A structure acquisition module, for responding to a rule matching request for a value to be matched, acquiring a target node structure corresponding to the value to be matched from a pre-built node structure set; wherein the node structure set includes node structures corresponding to all value nodes of the rule set to be matched, and each of the node structures includes a plurality of value ranges and a rule linked list corresponding to each value range;
[0040] A rule matching module is used to determine a target value range of the to-be-matched value relative to the target node structure, obtain a rule linked list corresponding to the target value range from the target node structure, and determine a rule matching result corresponding to the to-be-matched value based on the rule linked list.
[0041] In a third aspect, an embodiment of the present application provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor can implement the method described in any embodiment of the first aspect when executing the program.
[0042] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the method described in any embodiment of the first aspect can be implemented.
[0043] In a fifth aspect, an embodiment of the present application provides a computer program product, wherein the computer program product includes a computer program, wherein when the computer program is executed by a processor, the method described in any embodiment of the first aspect can be implemented. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments of the present application will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0045] Figure 1 A schematic diagram of a flow chart of a sensor value matching method provided in an embodiment of the present application;
[0046] Figure 2 A schematic diagram of the structure of a sensor value matching device provided in an embodiment of the present application;
[0047] Figure 3 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0048] The technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application.
[0049] It should be noted that similar reference numerals and letters represent similar items in the following drawings, so once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings. At the same time, in the description of this application, the terms "first", "second", etc. are only used to distinguish the description and cannot be understood as indicating or implying relative importance.
[0050] It should be noted that in rule matching technology, the existing multi-mode matching algorithms are mainly used to process string-type data. However, in scenarios such as the Internet of Things, there are a large number of sensor data, which usually exist in the form of numerical types. Since the existing multi-mode matching algorithms are not suitable for processing numerical data, it is often necessary to traverse and match all rules with the matching values, resulting in low matching efficiency. Especially when it is necessary to process massive numerical data, frequent type conversion and comparison operations not only increase the additional computing overhead, but also with the increase in the number of IoT devices, the number of rules also grows exponentially. The existing matching strategy is difficult to cope with the real-time processing requirements of large-scale data streams.
[0051] In response to the problems existing in the above-mentioned prior art, an embodiment of the present application provides a sensor value matching method, which replaces the traditional form of traversing and matching the value with all rules with a form of screening the corresponding node structure according to the value and obtaining the rule linked list therefrom, thereby eliminating the need to traverse all rules, thereby greatly improving the efficiency of value matching.
[0052] like Figure 1 As shown, the embodiment of the present application provides a sensor value matching method, which may include the steps of:
[0053] S1. In response to a rule matching request for a value to be matched, a target node structure corresponding to the value to be matched is obtained from a pre-constructed node structure set; wherein the node structure set includes node structures corresponding to all value nodes of the rule set to be matched, and each node structure includes several value ranges and a rule linked list corresponding to each value range.
[0054] Furthermore, the method for obtaining the node structure may include:
[0055] S101, obtaining all the to-be-matched rules that currently need to be matched, and determining all the value nodes corresponding to each to-be-matched rule;
[0056] S102, determining a plurality of value ranges corresponding to each value node, and determining a rule linked list of each value range based on the matching conditions between each to-be-matched rule and each value range;
[0057] S103 , generating a node structure corresponding to the numerical node based on a number of numerical ranges corresponding to each numerical node and a rule linked list corresponding to each numerical range.
[0058] It should be noted that before performing value matching, a node structure set may be first constructed according to the set of rules to be matched.
[0059] Specifically, the set of rules to be matched is a set of several rules to be matched that are currently required to be matched. Exemplarily, a plurality of node structure sets may be stored in the system, each node structure set corresponding to a set of rules to be matched; according to the sensor type of the value to be matched that is currently required to be matched, the node structure set corresponding to the sensor type may be obtained.
[0060] The set of rules to be matched is the set of all rules to be matched that the current value to be matched needs to match. It is understandable that each rule to be matched contains at least one numerical node. For example, for rule a to be matched: "value greater than 2", its numerical node is 2; for rule b to be matched: "value greater than 1 and less than 2.5", its numerical nodes are 1 and 2.5. For all numerical nodes corresponding to all rules to be matched in the set of rules to be matched, a corresponding node structure can be formed. For example, the above two rules to be matched can include the following three node structures: a node structure corresponding to numerical node 1, a node structure corresponding to numerical node 2, and a node structure corresponding to numerical node 2.5.
[0061] Exemplarily, each node structure can be a data body in the form of a table, which includes at least two types of fields: a numerical range and a rule list (or rule set); and the content of the numerical range field corresponds to the content of the rule list field one by one. Among them, the content of the numerical range field is used to indicate the numerical range corresponding to the entry, and the content of the rule list field indicates the list of IDs of rules to be matched that match the corresponding data range. Exemplarily, the rules to be matched that match the data range refer to the numerical range that has a relationship of inclusion or inclusion with the numerical range indicated by the rules to be matched. For example, when the content of the numerical range field is "greater than 2 and less than 2.5", since the numerical range has an inclusion relationship with the above-mentioned rule b to be matched "a value greater than 1 and less than 2.5", b is added to the rule list corresponding to the content of the numerical range field.
[0062] For example, the node structure of the numerical node s may be as shown in Table 1 below:
[0063] Table 1, node structure of numerical node N
[0064]
[0065] After the node structure set is constructed, the node structure set can be used to match the sensor data. It is understandable that in IoT scenarios such as smart home systems, it is often necessary to match rules based on the values collected by sensors, and trigger corresponding processing strategies based on the matched different rules, such as abnormal alarms or multi-device linkage operations.
[0066] After collecting each sensor value, you can choose to execute different matching strategies for the sensor value (value to be matched): 1. According to the traditional form, traverse and match the value to be matched with all rules one by one; 2. Use the matching strategy of the embodiment of the present application to match the corresponding node structure and obtain the corresponding rule matching result.
[0067] When the second matching strategy described above is selected, the system can obtain the target node structure corresponding to the value to be matched from the pre-built node structure set in response to the rule matching request for the value to be matched. Specifically, the numerical nodes corresponding to all node structures can be traversed and compared with the value to be matched, and the node structure corresponding to the numerical node with the smallest difference between the two is used as the target node structure corresponding to the value to be matched. Exemplarily, assuming that the current value to be matched is "2.1", and the node structure set contains four node structures whose numerical nodes are 1, 2, 2.5 and 3, respectively, then by traversing and comparing the difference between "2.1" and the four numerical nodes, the node structure corresponding to "2" with the smallest difference is used as the target node structure corresponding to the value to be matched.
[0068] S2. Determine a target value range of the value to be matched relative to the target node structure, obtain a rule linked list corresponding to the target value range from the target node structure, and determine a rule matching result corresponding to the value to be matched based on the rule linked list.
[0069] Specifically, after obtaining the target node structure, first compare the contents of all the value range fields in the target node structure with the value to be matched to determine the target value range that matches the value to be matched. Exemplarily, assuming that the node structure set contains four node structures whose value nodes are 1, 2, 2.5 and 3, respectively, for the node structure corresponding to the value node "2", since the current value node to be matched is "2.1", it can be determined that the value range of "greater than this node value and less than the next node value" in the node structure, that is, "(2, 2.5)", matches "2.1", so the value range of "greater than this node value and less than the next node value" is determined as the target value range of the value to be matched relative to the target node structure.
[0070] Then, the rule chain list corresponding to the target numerical range is obtained from the target node structure, and the rule ID corresponding to the rule chain list is used as the rule matching result corresponding to the value to be matched. For example, in the node structure corresponding to the numerical node "2", the rule chain list corresponding to the numerical range "(2, 2.5)" is "acd", so it can be determined that the rule matching results corresponding to the value to be matched are a, c and d, that is, the rules that match the value to be matched are three rules to be matched with IDs a, c and d respectively.
[0071] Based on this, there is no need to traverse and match the value to be matched with all the rules. It is only necessary to match the node structure corresponding to the value to be matched, and then obtain the rule linked list corresponding to the value range from the node structure according to the value range relationship between the value to be matched and the node structure to obtain the matching result, thereby improving the efficiency of value matching. Especially when the number of rules to be matched is large, the embodiment of the present application can greatly save the computing resources required for value matching and improve the real-time performance of value matching.
[0072] In some possible embodiments, in step S102, a number of value ranges corresponding to each value node are determined, including:
[0073] Arrange all the numerical nodes corresponding to the rule set to be matched in order of node value from small to large;
[0074] For the first numerical node with the smallest node value, determining the corresponding numerical ranges includes the following three items: a value equal to the node value itself, a value greater than the node value and less than the next node value, and a value less than the node value;
[0075] For the third numerical node with the largest node value, the corresponding numerical ranges are determined to include the following three items: a value equal to the node value itself, a value less than the node value and greater than the previous node value, and a value greater than the node value;
[0076] For the second numerical node other than the first numerical node and the third numerical node, determining the corresponding several numerical ranges includes the following three items: a value equal to the node value itself, a value less than this node value and greater than the previous node value, and a value greater than this node value and less than the next node value.
[0077] It should be noted that before constructing the node structure, all numerical nodes are first extracted according to all the rules to be matched, and then these numerical nodes are arranged in order from small to large. It should be noted that in order to avoid duplication, after all numerical nodes are extracted, these numerical nodes can be deduplicated. For example, assuming that the set of rules to be matched includes rule a "value greater than 2" and rule b "value less than 2", then after extracting two numerical nodes with a value of "2", deduplication can be performed first, and finally only one node structure with a numerical node of "2" can be constructed.
[0078] In the process of constructing the node structure, for the first numerical node with the smallest node value, since there is no numerical node smaller than the first numerical node, the node structure of the numerical node does not have the numerical range of "a value less than this node value and greater than the previous node value", and the numerical range of "a value greater than this node value" has repeated numerical ranges with the node structures of other numerical nodes. Therefore, based on the above Table 1, the two numerical ranges of "a value less than this node value and greater than the previous node value" and "a value greater than this node value" and their corresponding rule linked lists can be omitted to obtain the simplified node structure corresponding to the first numerical node, as shown in Table 2 below:
[0079] Table 2, node structure of the first numerical node
[0080]
[0081] For the third numerical node with the largest node value, since there is no numerical node larger than the third numerical node, the node structure of the numerical node does not have the numerical range of "value greater than this node value and less than the next node value", and the numerical range of "value less than this node value" has repeated numerical ranges with the node structures of other numerical nodes. Therefore, based on the above Table 1, the two numerical ranges of "value greater than this node value and less than the next node value" and "value less than this node value" and their corresponding rule linked lists can be omitted to obtain the simplified node structure corresponding to the third numerical node, as shown in the following Table 3:
[0082] Table 3, node structure of the third numerical node
[0083]
[0084] For the second numerical nodes other than the first numerical node and the third numerical node, that is, other numerical nodes other than the maximum value and the minimum value, since the two numerical ranges of "value less than this node value" and "value greater than this node value" of these numerical nodes have repeated numerical ranges with the node structures of other numerical nodes, therefore, based on the above Table 1, the two numerical ranges of "value less than this node value" and "value greater than this node value" and their corresponding rule linked lists can be omitted, and the node structure corresponding to the simplified second numerical node is obtained, as shown in the following Table 4:
[0085] Table 4, node structure of the second value node
[0086]
[0087] Based on this, by constructing different node structures for the minimum and maximum node values and the node values between the two, there is no need to perform rule matching on repeated value ranges between different node structures, thereby reducing the amount of calculation in the process of constructing the node structure and improving the efficiency of regular structure construction.
[0088] In some possible embodiments, step S1, in response to a rule matching request for a value to be matched, obtaining a target node structure corresponding to the value to be matched from a pre-built node structure set, may include:
[0089] S111, in response to a rule matching request for a value to be matched, determining whether the rule matching request meets a preset quick matching condition;
[0090] S112: If yes, obtain the target node structure corresponding to the value to be matched from the pre-built node structure set;
[0091] S113: If not, then match the to-be-matched values one by one based on all the to-be-matched rules that currently need to be matched, to obtain a rule matching result corresponding to the to-be-matched value.
[0092] It should be noted that when responding to a rule matching request for a value to be matched, it can be first determined whether the current rule matching request meets the preset quick matching conditions. If it meets the conditions, a quick matching method based on a node structure is adopted; if it does not meet the conditions, a traditional method of traversing and matching based on all rules to be matched is adopted.
[0093] By setting fast matching conditions and adopting different matching methods according to whether the conditions are met, it is possible to flexibly adopt appropriate rule matching methods, thereby further improving the efficiency of value matching.
[0094] In some possible embodiments, in S111, determining whether the rule matching request meets the preset quick matching condition may include at least one of the following:
[0095] When the number of to-be-matched values currently to be processed exceeds a preset first threshold, determining that the rule matching request meets the preset quick matching condition;
[0096] When the number of to-be-matched rules that currently need to be matched exceeds a preset second threshold, it is determined that the rule matching request meets the preset quick matching condition.
[0097] Specifically, judging whether a rule matching request meets the preset quick matching conditions may include the following two situations: 1. Whether the number of values to be matched that need to be processed is large enough; 2. Whether the number of rules to be matched that need to be matched is large enough. It is understandable that when a large number of values to be matched need to be processed or a large number of rules to be matched need to be matched, the matching method based on the node structure can significantly improve the matching efficiency; otherwise, when there are fewer values to be matched or only a small number of rules to be matched need to be matched, the matching method based on the node structure cannot significantly improve the matching efficiency. At this time, the traditional matching method of traversing all rules can be preferred to further improve the flexibility of value matching.
[0098] In some possible embodiments, in step S1, obtaining a target node structure corresponding to the value to be matched from a pre-built node structure set may include:
[0099] S121, arranging all the numerical nodes corresponding to the to-be-matched rule set in ascending order of node value, and constructing a to-be-matched numerical sequence based on the arranged numerical nodes;
[0100] S122, using a binary search method to determine the sequence position of the to-be-matched value relative to the to-be-matched value sequence, and taking one of the value nodes in the to-be-matched value sequence corresponding to the sequence position as the target value node;
[0101] S123. Obtain a node structure corresponding to the target numerical node from a pre-constructed node structure set as a target node structure corresponding to the value to be matched.
[0102] It should be noted that after obtaining the value to be matched, the target node structure corresponding to the value to be matched can be quickly determined and screened out based on the dichotomy method.
[0103] Specifically, firstly, all numerical nodes are arranged in order from small to large according to the node value, and an array (which can be called the sequence of numerical values to be matched) consisting of all numerical nodes (in order from small to large) is obtained; then, the binary search method can be used to quickly determine the position (sequence position) of the numerical value to be matched in the array. Exemplarily, the middle element in the array is first obtained (the middle ranking in the array or near the ranking, for example, for an array of 5 elements, the middle element is the 3rd element; for an array of 4 elements, the middle element is the 2nd or 3rd), and the size relationship between the numerical value to be matched and the middle element is compared. If the numerical value to be matched is greater than the middle element, the middle element is re-obtained based on the middle element and the maximum value in the array, and so on, until there are no other numerical node elements between the two elements found at the end.
[0104] It should be noted that after determining the sequence position of the value to be matched relative to the sequence of values to be matched, there may be two value nodes or only one value node based on the sequence position: when the sequence position of the value to be matched is between two value node elements, the sequence position corresponds to two value nodes; when the sequence position of the value to be matched is greater than all value nodes or less than all value nodes, the sequence position corresponds to one value node.
[0105] Exemplarily, when the value to be matched is greater than (or less than) all value nodes in the value sequence to be matched, the largest (or smallest) value node can be directly obtained as the target value node corresponding to the value to be matched.
[0106] Exemplarily, when the sequence position of the value to be matched is between two value node elements, one of the two value nodes corresponding to the sequence position can be arbitrarily obtained as the target value node corresponding to the value to be matched.
[0107] Then, a node structure corresponding to the target value node is obtained from a pre-constructed node structure set as a target node structure corresponding to the value to be matched.
[0108] It can be understood that when the sequence position of the value to be matched is between two value node elements, the value range of "smaller than this node value and larger than the previous node value" in the node structure of the larger value node is compared with the value range of "larger than this node value and smaller than the next node value" in the node structure of the smaller value node. The corresponding rule linked lists of the two are consistent. Please refer to the specific example below for details.
[0109] In some possible embodiments, the sensor value matching method may further include the steps of:
[0110] S3. When an update event of the to-be-matched rule set is detected, the node structure set is updated based on the updated to-be-matched rule set.
[0111] It should be noted that when the rules of the to-be-matched rule set change, such as adding new rules, deleting rules, or when the values or symbols in the rules change, the node structure set needs to be updated based on the updated to-be-matched rule set.
[0112] Based on this, by monitoring the update events of the rules to be matched and updating the node structure in time when the rules change, the timeliness and reliability of value matching can be improved.
[0113] The following specific examples are given to explain the sensor value matching method of the present application in detail:
[0114] Assume that the IoT system needs to match the values collected by a sensor with rules and execute the corresponding configured policies according to the matched rules. Since the values of this sensor type need to match a large number of rule values, in order to avoid traversing all rules, a node structure-based matching method is used to obtain the rule matching results (the rule ID that matches the value to be matched).
[0115] 1. Constructing the node structure:
[0116] The current sensor's to-be-matched rules include the following four (the number of rules in actual applications is usually much larger than this number, and this example only uses four rules for convenience):
[0117] Rule a: Value greater than 2
[0118] Rule b: Values greater than 3
[0119] Rule c: Values greater than 1 and less than 2.5
[0120] Rule d: Values less than or equal to 3
[0121] Get all the values contained in all the above matching rules: 2, 3, 1, 2.5, 3. Remove duplicates from these values and sort them from small to large, and the resulting value nodes are: 1, 2, 2.5, 3.
[0122] According to the predefined node structure format (such as shown in Table 1), a node structure set including 4 node structures is constructed, wherein the 4 node structures correspond to the above four numerical nodes respectively. For the convenience of description, the 4 node structures are respectively represented as: a node structure with a node value of 1, a node structure with a node value of 2, a node structure with a node value of 2.5, and a node structure with a node value of 3.
[0123] Specifically, for a node structure with a node value of 1, since "1" is the smallest of all numerical nodes, there is no "previous node value" smaller than 1, so in this node structure, the rule linked list corresponding to the numerical range of "values less than this node value and greater than the previous node value" is marked as NULL (no value assigned); at the same time, since the numerical range of "values greater than this node value" is repeated with the numerical range of other numerical nodes, the rule linked list corresponding to the numerical range of "values greater than this node value" is marked as NULL. In other embodiments, the above two numerical ranges and their corresponding rule linked list items can also be directly omitted.
[0124] Then, traverse and analyze all the rules to be matched, and add the rules that match each numerical range to the corresponding rule linked list. Specifically, for the numerical range of "equal to the value of the node itself", since there is no rule related to "equal to 1" in all the rules, it is marked as NULL; for the numerical range of "greater than this node value and less than the next node value", that is, "1 < x < 2", since in all the rules, it is judged that both rule c and rule d contain this numerical range, the rule linked list corresponding to this numerical range is "c - d". For the numerical range of "less than this node value", that is, "x < 1", since only rule d contains this numerical range, the rule linked list corresponding to this numerical range is "d". Based on this, the node structure corresponding to the node value of 1 is obtained, as shown in Table 4:
[0125] Table 5, Node Structure with Node Value of 1
[0126]
[0127]
[0128] In the same way, by analogy, perform rule linked list matching for each node structure to obtain the node structures corresponding to each numerical node, as shown in Tables 6 to 8 below:
[0129] Table 6, Node Structure with Node Value of 2
[0130]
[0131] Table 7, Node Structure with Node Value of 2.5
[0132]
[0133]
[0134] Table 8, Node Structure with Node Value of 3
[0135]
[0136] II. Perform Rule Matching on the Numerical Values to be Matched:
[0137] Collect sensor data in real time, and perform rule matching on each collected value (numerical value to be matched). Specifically, assume that the currently collected sensor value is 2.1. First, use the binary search method to quickly find the position of this value in the array {1, 2, 2.5, 3} composed of numerical nodes. It can be understood that if the number of numerical nodes is small, the traditional method of comparing the numerical value to be matched with each numerical node value one by one can also be used. Through position matching, it can be determined that 2.1 is between the two elements "2" and "2.5" in the array.
[0138] Then, one of the numerical nodes "2" and "2.5" is selected as the target numerical node corresponding to the value to be matched, and the corresponding node structure is obtained from the node structure set. For example, the node structure with a node value of 2 can be obtained, and the size relationship between 2.1 and 2 can be compared. Since "2<2.1<2.5", it can be determined that the numerical range of 2.1 relative to the node structure with a node value of 2 is "a value greater than this node value and less than the next node value". The rule linked list corresponding to the numerical range is found in the node structure as "acd", so it can be determined that the rule matching results that match the value 2.1 to be matched are three rules with IDs a, c and d respectively.
[0139] Compared with the prior art, since there is no need to traverse and match the to-be-matched value with all the rules, the matching efficiency can be greatly improved when the number of to-be-matched rules is huge. In terms of real-time monitoring and data processing, the matching method of the embodiment of the present application can quickly locate the rule set that meets the conditions, greatly reducing the computing overhead and resource waste, and effectively improving the real-time response capability and reliability of the system. Especially when the Internet of Things devices are deployed on a large scale, the matching method of the embodiment of the present application can effectively support the real-time processing of massive data streams, significantly reduce operating costs, and improve the performance and stability of the overall system.
[0140] Please refer to Figure 2 , Figure 2 FIG. 1 is a block diagram showing the composition of the sensor value matching device provided by some embodiments of the present application. It should be understood that the sensor value matching device is similar to the above-mentioned Figure 1 Corresponding to the method embodiment, each step involved in the above method embodiment can be executed. The specific functions of the sensor value matching device can be found in the description above. To avoid repetition, the detailed description is appropriately omitted here.
[0141] Figure 2 The sensor value matching device includes at least one software function module that can be stored in a memory or fixed in the sensor value matching device in the form of software or firmware, and the sensor value matching device includes:
[0142] The structure acquisition module 210 is used to respond to the rule matching request for the value to be matched, and obtain the target node structure corresponding to the value to be matched from the pre-built node structure set; wherein the node structure set includes node structures corresponding to all value nodes of the rule set to be matched, and each node structure includes a plurality of value ranges and a rule linked list corresponding to each value range;
[0143] The rule matching module 220 is used to determine the target value range of the value to be matched relative to the target node structure, obtain the rule linked list corresponding to the target value range from the target node structure, and determine the rule matching result corresponding to the value to be matched based on the rule linked list.
[0144] It can be understood that the above-mentioned device embodiment corresponds to the method embodiment of the present invention. A sensor value matching device provided by the embodiment of the present invention can implement the sensor value matching method provided by any method embodiment of the present invention.
[0145] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the device described above can refer to the corresponding process in the aforementioned method, and will not be described in detail here.
[0146] like Figure 3 As shown, some embodiments of the present application provide an electronic device 300, which includes: a memory 310, a processor 320, and a computer program stored in the memory 310 and executable on the processor 320, wherein the processor 320 reads the program from the memory 310 through the bus 330 and executes the program to implement a method of any embodiment included in the above-mentioned sensor value matching method.
[0147] Processor 320 can process digital signals and can include various computing structures, such as complex instruction set computer structure, reduced instruction set computer structure, or a structure that implements a combination of multiple instruction sets. In some examples, processor 320 can be a microprocessor.
[0148] The memory 310 may be used to store instructions executed by the processor 320 or data related to the execution of instructions. These instructions and / or data may include codes for implementing some or all functions of one or more modules described in the embodiments of the present application. The processor 320 of the disclosed embodiment may be used to execute instructions in the memory 310 to implement the method shown above. The memory 310 includes a dynamic random access memory, a static random access memory, a flash memory, an optical memory, or other memory known to those skilled in the art.
[0149] Some embodiments of the present application further provide a computer-readable storage medium having a computer program stored thereon. The computer program is executed by a processor to execute the method described in the method embodiment.
[0150] Some embodiments of the present application further provide a computer program product, which, when executed on a computer, enables the computer to execute the method described in the method embodiment.
[0151] It should be noted that each embodiment in this specification is described in a progressive manner, and each embodiment focuses on the differences from other embodiments, and the same or similar parts between the embodiments can be referred to each other. For the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0152] In several embodiments provided by the present application, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely schematic. For example, the flowcharts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the devices, methods and computer program products according to multiple embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the module, a program segment or a part of a code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of boxes in the block diagram and / or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.
[0153] In addition, the functional modules in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
[0154] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0155] The above description is only an embodiment of the present application and is not intended to limit the scope of protection of the present application. For those skilled in the art, the present application may have various changes and variations. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application should be included in the scope of protection of the present application. It should be noted that similar reference numerals and letters represent similar items in the following drawings, so once an item is defined in one drawing, it does not need to be further defined and explained in the subsequent drawings.
[0156] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
[0157] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
Claims
1. A sensor value matching method, characterized in that: include: In response to a rule matching request for a value to be matched, a target node structure corresponding to the value to be matched is obtained from a pre-constructed node structure set; wherein the node structure set includes node structures corresponding to all value nodes of the rule set to be matched, and each of the node structures includes a plurality of value ranges and a rule linked list corresponding to each value range; Determine a target value range of the to-be-matched value relative to the target node structure, obtain a rule linked list corresponding to the target value range from the target node structure, and determine a rule matching result corresponding to the to-be-matched value based on the rule linked list.
2. The sensor value matching method according to claim 1, characterized in that: The method for obtaining the node structure includes: Obtain all the to-be-matched rules that currently need to be matched, and determine all the value nodes corresponding to each of the to-be-matched rules; Determine a plurality of value ranges corresponding to each of the value nodes, and determine a rule linked list for each value range based on a matching condition between each of the to-be-matched rules and each of the value ranges; A node structure corresponding to each numerical node is generated based on a plurality of numerical ranges corresponding to each numerical node and a rule linked list corresponding to each numerical range.
3. The sensor value matching method according to claim 2, characterized in that: The determining of a plurality of value ranges corresponding to each of the value nodes comprises: Arrange all the value nodes corresponding to the set of rules to be matched in order of small to large node values; For the first numerical node with the smallest node value, determining the corresponding numerical ranges includes the following three items: a value equal to the node value itself, a value greater than the node value and less than the next node value, and a value less than the node value; For the third numerical node with the largest node value, the corresponding numerical ranges are determined to include the following three items: a value equal to the node value itself, a value less than the node value and greater than the previous node value, and a value greater than the node value; For the second numerical node other than the first numerical node and the third numerical node, determining the corresponding several numerical ranges includes the following three items: a value equal to the node value itself, a value less than this node value and greater than the previous node value, and a value greater than this node value and less than the next node value.
4. The sensor value matching method according to claim 1, characterized in that: The step of obtaining, in response to a rule matching request for a value to be matched, a target node structure corresponding to the value to be matched from a pre-built node structure set comprises: In response to a rule matching request for a value to be matched, determining whether the rule matching request meets a preset quick matching condition; If yes, then obtaining a target node structure corresponding to the value to be matched from a pre-built node structure set; If not, the to-be-matched values are matched one by one based on all the to-be-matched rules that currently need to be matched, so as to obtain a rule matching result corresponding to the to-be-matched values.
5. The sensor value matching method according to claim 4, characterized in that: The determining whether the rule matching request meets the preset quick matching condition includes at least one of the following: When the number of to-be-matched values currently to be processed exceeds a preset first threshold, determining that the rule matching request meets a preset quick matching condition; When the number of to-be-matched rules that currently need to be matched exceeds a preset second threshold, it is determined that the rule matching request meets a preset quick matching condition.
6. The sensor value matching method according to claim 1, characterized in that: The step of obtaining a target node structure corresponding to the to-be-matched value from a pre-built node structure set includes: Arrange all the value nodes corresponding to the rule set to be matched in ascending order of node value, and construct a value sequence to be matched based on the arranged value nodes; Using a binary search method to determine the sequence position of the to-be-matched value relative to the to-be-matched value sequence, and taking one of the value nodes in the to-be-matched value sequence corresponding to the sequence position as a target value node; A node structure corresponding to the target value node is obtained from a pre-constructed node structure set as a target node structure corresponding to the value to be matched.
7. The sensor value matching method according to any one of claims 1 to 6, characterized in that: Also includes: When an update event of the to-be-matched rule set is detected, the node structure set is updated based on the updated to-be-matched rule set.
8. An electronic device, characterized in that: The method comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the sensor value matching method according to any one of claims 1 to 7 can be implemented when the processor executes the program.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the sensor value matching method according to any one of claims 1 to 7 is executed.
10. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the sensor value matching method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
High-efficiency filtering method for data packets
CN103338155A
Security event association analysis method and device
CN109255237A
Method and system for realizing Internet-of-things industry usage statistics based on rule engine
CN113468239A
Work order allocation method and device, storage medium and electronic equipment
CN115965196A
Customer group query method and device, computer equipment and storage medium
CN116910115A