Class subordination relation distinguishing method and device
By heterogeneously transforming the category tree into a category array and using a binary search method based on hierarchical and structural parameters, subordinate category nodes can be quickly located, thus solving the high time complexity problem in the existing technology and achieving efficient category affiliation determination.
Patent Information
- Application Number
- CN202410346893.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-25
- Publication Date
- 2025-09-26
AI Technical Summary
The existing method for determining the affiliation between categories traverses the category tree by brute force, resulting in high time complexity and inability to efficiently determine the affiliation between categories.
The category tree is heterogeneously transformed into a category array. The category nodes are traversed in a preset order to form a category array. The hierarchy and structural parameters of the category tree are used to determine the serial number range of a specific category node in the array, and the subordinate category nodes are quickly located through binary search.
The time complexity of calculating the category affiliation is reduced, and the efficiency of discrimination is improved. In particular, when the category tree structure is fixed, discrimination can be completed with a time complexity close to constant.
Smart Images

Figure CN120707204A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method and device for determining category affiliation. Background Art
[0002] In real-world scenarios, it may be necessary to determine the affiliation between two categories. For example, after a user purchases an item in a certain category, the service provider needs to determine whether the category belongs to a pre-set specific category. The service provider then needs to perform a pre-set action (such as issuing virtual resources like points or coupons) when the user's category belongs to the specific category. However, specific categories often exist in a category tree with a large number of category nodes. Existing methods for determining whether a relationship exists typically brute-force traversal of the category tree and comparison with the user's category, resulting in high time complexity. Summary of the Invention
[0003] In view of this, an embodiment of the present invention provides a method and apparatus for determining category affiliation, which performs category affiliation determination after heterogeneously converting a category tree into a category array, thereby reducing the time complexity of calculating category affiliation.
[0004] To achieve the above object, according to one aspect of the present invention, a method for determining category affiliation is provided.
[0005] The method for determining the category subordination relationship of an embodiment of the present invention includes: traversing the category nodes in a pre-established category tree in a preset order; placing the category nodes into a preset array to form a category array; wherein the category nodes include category identities; obtaining the identifier of the category to be determined and the category identity of a specific category node in the category tree, determining the sequence number range corresponding to the level of the specific category node in the category array according to the level of the specific category node in the category tree, and determining the specific sequence number of the specific category node in the sequence number range; wherein the sequence number range is a plurality of consecutively arranged sequence numbers; obtaining the target sequence number of the subordinate category node of the specific category node in the category array based on the specific sequence number and the structural parameters of the category tree, and determining the subordinate category node in the category array using the target sequence number; in response to the identifier of the category to be determined being consistent with the category identity of any subordinate category node, determining that the category to be determined is subordinate to the specific category node.
[0006] Optionally, traversing the category nodes in the pre-established category tree in a preset order includes: traversing the category nodes in the category tree in a layer-by-layer order.
[0007] Optionally, determining the specific serial number of the specific category node in the serial number range includes: comparing the category identity of the specific category node with the category identity of the category nodes indicated by the serial number range, and determining the serial number corresponding to the category node whose category identity is consistent with the category identity of the specific category node as the specific serial number.
[0008] Optionally, the comparison of the category identity of the specific category node with the category identity of the category nodes indicated by the serial number range includes: dividing the category nodes indicated by the serial number range into multiple node sets; the category nodes in the same node set are child nodes of the same category node, and the category identities of the category nodes in the same node set are arranged monotonically increasing or monotonically decreasing; and performing the comparison operation based on the binary search method in parallel on the multiple node sets.
[0009] Optionally, obtaining the target serial number of the subordinate category node of the specific category node in the category array based on the specific serial number and the structural parameters of the category tree includes: obtaining the target serial number of the first-level subordinate category node of the specific category node in the category array based on the specific serial number and the structural parameters; obtaining the target serial number of the next-level subordinate category node of the specific category node in the category array based on the target serial number of the current-level subordinate category node and the structural parameters, until the target serial number of the subordinate category node as a leaf node is obtained.
[0010] Optionally, the method is executed in a preset cache; the method further includes: storing key-value pair data with the category tree as value in the cache; and the category to be determined and the category tree belong to the major category indicated by the key in the key-value pair data.
[0011] Optionally, the method further includes: in response to the identifier of the category to be determined being inconsistent with the category identifier of each subordinate category node, determining that the category to be determined is not subordinate to the specific category node.
[0012] To achieve the above-mentioned object, according to another aspect of the present invention, a device for determining category affiliation is provided.
[0013] The device for determining the category affiliation of the embodiment of the present invention may include: a heterogeneous unit for traversing the category nodes in a pre-established category tree in a preset order; placing the category nodes into a preset array to form a category array; wherein the category nodes include category identifiers; a specific sequence number determination unit for obtaining the identifier of the category to be determined and the category identifier of the specific category node in the category tree, determining the sequence number range corresponding to the level in the category array according to the level of the specific category node in the category tree, and determining the sequence number in the sequence number range. The specific serial number of the specific category node; wherein the serial number range is a plurality of serial numbers arranged continuously; a subordinate node determination unit, used to obtain the target serial number of the subordinate category node of the specific category node in the category array based on the specific serial number and the structural parameters of the category tree, and determine the subordinate category node in the category array using the target serial number; a subordinate relationship determination unit, used to: in response to the identity of the category to be determined being consistent with the category identity of any subordinate category node, determine that the category to be determined is subordinate to the specific category node.
[0014] To achieve the above objective, according to another aspect of the present invention, an electronic device is provided.
[0015] An electronic device of the present invention includes: one or more processors; a storage device for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors implement the method for determining category affiliation provided by the present invention.
[0016] To achieve the above objective, according to another aspect of the present invention, a computer-readable storage medium is provided.
[0017] A computer-readable storage medium of the present invention stores a computer program, which, when executed by a processor, implements the method for determining category affiliation provided by the present invention.
[0018] According to the technical solution of the present invention, the embodiments of the above invention have the following advantages or beneficial effects:
[0019] The category nodes in the category tree are traversed in advance according to a preset order and placed into an array to form a category array; when it is necessary to determine whether the category to be determined belongs to a specific category node in the category tree, first determine the serial number range corresponding to the level of the specific category node in the category tree in the category array, and determine the specific serial number of the specific category node by comparing the category identity within the serial number range; then, based on the specific serial number and the structural parameters of the category tree, obtain the target serial number of the subordinate category node of the specific category node in the category array, and use the target serial number to determine the subordinate category node in the category array; finally, if it is determined that the identifier of the category to be determined is consistent with the category identity of a subordinate category node, it is determined that the category to be determined belongs to the specific category node. In this way, the category tree is heterogeneously transformed into an array according to a preset order, and the position of a specific category node and its subordinate nodes in the category array is quickly calculated based on structural parameters such as the depth and number of forks of the category tree, thereby avoiding traversing a large number of category nodes in the category tree, thereby reducing the time complexity of calculating the category subordination relationship. In addition, when determining the position of a specific category node in the category array, the corresponding serial number range in the category array can be selected based on the hierarchy of the specific category node in the category tree. Thereafter, the category nodes in the serial number range are classified according to the node subordination relationship and then searched in parallel by category based on a binary search method, further improving the search efficiency.
[0020] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with specific embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] The accompanying drawings are provided for a better understanding of the present invention and are not intended to limit the present invention.
[0022] Figure 1 Schematic diagram of the main steps of the method for determining category affiliation in an embodiment of the present invention;
[0023] Figure 2 Schematic diagram of specific execution steps of the method for determining category affiliation in an embodiment of the present invention;
[0024] Figure 3 is a schematic diagram of a category tree according to an embodiment of the present invention;
[0025] Figure 4 is a schematic diagram of a category array according to an embodiment of the present invention;
[0026] Figure 5 Schematic diagram of components of a device for determining category affiliation in an embodiment of the present invention;
[0027] Figure 6 is an exemplary system architecture diagram in which embodiments of the present invention may be applied;
[0028] Figure 72 is a schematic diagram of the structure of an electronic device used to implement the method for determining the category affiliation in an embodiment of the present invention. DETAILED DESCRIPTION
[0029] The following description of exemplary embodiments of the present invention is made in conjunction with the accompanying drawings, in which various details of the embodiments of the present invention are included to facilitate understanding. These details should be considered as merely exemplary. Therefore, it should be appreciated by those skilled in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.
[0030] It should be pointed out that, in the absence of conflict, the embodiments of the present invention and the technical features therein may be combined with each other.
[0031] Figure 1 1 is a schematic diagram of the main steps of the method for determining category affiliation in an embodiment of the present invention.
[0032] like Figure 1 As shown, the method for determining the category affiliation in the embodiment of the present invention can be executed by a server or computing device (hereinafter collectively referred to as a server) that performs relevant calculations, and is specifically executed in the following steps:
[0033] Step S101: traverse the category nodes in the pre-established category tree in a preset order; place the category nodes into a preset array to form a category array.
[0034] In the embodiment of the present invention, category refers to the categories of different granularities to which an item belongs, and category nodes at different levels constitute a category tree. Generally, each category node contains a corresponding category identifier. In practical applications, corresponding category trees can be set for different major categories (i.e., categories at a preset coarser granularity) to characterize the relationship between categories under the major categories. The preset order can be a fixed traversal order of breadth-first or depth-first, or other custom traversal order.
[0035] In this step, the server traverses the category tree based on a preset order and places the obtained category nodes into an array to form a category array. The following calculation of category affiliation will be mainly performed based on the category array.
[0036] Step S102: Obtain the identifier of the category to be identified and the category identifier of the specific category node in the category tree, determine the sequence number range corresponding to the level in the category array according to the level of the specific category node in the category tree, and determine the specific sequence number of the specific category node in the sequence number range.
[0037] In specific applications, after determining the identity of the category to be identified from external input, the server first determines the category tree to which the category to be identified belongs. It then determines whether the category to be identified belongs to a specific category node in the above category tree. The above specific category nodes are pre-configured based on application requirements. For example, in one scenario, the service provider determines whether to issue virtual resources to a user based on whether the category of the item purchased by the user belongs to a designated category. In this case, the category of the item purchased by the user is the category to be identified, and the designated category is the specific category.
[0038] In this step, the server first obtains the level of the specific category node in the category tree, and determines the serial number range corresponding to the level in the category array based on the level of the specific category node in the category tree, and finally determines the specific serial number of the specific category node in the serial number range, thereby realizing the positioning of the specific category node in the category array. It can be understood that since the structure of the category tree is fixed, the serial numbers of the category nodes at each level based on the fixed traversal order are fixed, so the corresponding serial number range can be obtained according to the level of the specific category node, and then the specific serial number of the specific category node can be determined within the serial number range, thereby improving the search efficiency. It can be understood that corresponding to the case of using breadth-first or level-order traversal in step S101, the above serial number range is a plurality of serial numbers arranged continuously.
[0039] Step S103: Obtain the target sequence number of the subordinate category node of the specific category node in the category array according to the specific sequence number and the structural parameters of the category tree, and use the target sequence number to determine the subordinate category node in the category array.
[0040] Since the category tree structure and traversal order are fixed, after determining the specific serial number of a specific category node in the category array, the server can obtain the target serial number of each subordinate category node of the specific category node in the category array based on the specific serial number and structural parameters such as the depth and number of forks of the category tree, and then use the target serial number to determine the subordinate category node in the category array. It should be noted that the above subordinate category nodes can be the first-level subordinate nodes of the specific category node, or they can be multi-level subordinate nodes of the specific category node. The above multi-level subordinate nodes can include child nodes (first-level subordinate nodes), grandchild nodes (second-level subordinate nodes), great-grandchild nodes (third-level subordinate nodes), etc. until the leaf node.
[0041] Step S104: In response to the identifier of the category to be determined being consistent with the category identifier of any subordinate category node, it is determined that the category to be determined belongs to a specific category node.
[0042] After obtaining the subordinate category nodes of each level of the specific category node based on the category array, the subordinate relationship between the categories can be determined by comparing the node identifiers. If the identifier of the category to be determined is consistent with the category identifier of a subordinate category node, the server can determine that the category to be determined is subordinate to the specific category node; if the identifier of the category to be determined is inconsistent with the category identifier of each subordinate category node, the server determines that the category to be determined is not subordinate to the specific category node. It can be understood that in actual applications, after determining a certain level of subordinate category nodes of a specific category node from top to bottom (i.e., in the order of increasing levels), the category identifier of the category to be determined is compared with the category identifier of the subordinate category node of that level. If there is a consistent subordinate category node, the calculation of the subordinate category node of the next level is stopped. If there is no consistent subordinate category node, the calculation of the subordinate category node of the next level continues until the leaf node is reached.
[0043] Through the above steps, the traditional category tree traversal is optimized to accurate node positioning based on the category array. Since the category tree structure is fixed, the serial numbers of specific category nodes and their subordinate category nodes in the category array have strong regularity. Therefore, the positions of specific category nodes and their subordinate category nodes can be accurately calculated according to the above rules and then the category identification comparison can be performed, thereby reducing the time complexity of the category affiliation calculation.
[0044] Figure 2 This is a schematic diagram of the specific execution steps of the method for determining the category affiliation in an embodiment of the present invention, see Figure 2 .
[0045] Step S201: The server pre-structures the category tree of each major category into a category array. In this step, the server can traverse the category nodes in the category tree in a preset order and place the category nodes into a preset array to form a category array. The category tree and category array are respectively as follows: Figure 3 and Figure 4 As shown, Figure 3 and Figure 4 The numbers in each node are the category identifications. Figure 4 The numbers above the array are the sequence numbers of each category node in the category array. As a preferred solution, the server traverses the category nodes in the category tree in a hierarchical order to form a category array. In one embodiment, each category tree and category array can be stored in a preset cache to achieve high-speed data search. The above cache can store key-value pair data with the category tree as the value, and the key in the key-value pair data is the identifier of the major category to which the category tree belongs.
[0046] Step S202: The server determines the category identifier to be identified and the category tree of its major category. In this step, the server obtains the externally input category identifier to be identified and determines the corresponding category tree based on the major category to which the category identifier belongs. That is, the server uses the major category identifier as the key to search the cache for the category tree in the corresponding value.
[0047] Step S203: The server determines a predetermined specific category node identifier in the corresponding category tree, and then determines whether the category to be determined belongs to the specific category node.
[0048] Step S204: The server obtains the level of the category to be identified in the category tree. In actual scenarios, the server can determine the level of the category to be identified in the category tree based on the identification of the category to be identified.
[0049] Step S205: The server calculates the serial number range corresponding to the level in the category array. In this step, the server can determine the serial number range corresponding to the above levels based on the structural parameters of the category tree, such as depth and number of forks (i.e., the number of child nodes of each node). Taking the category tree as a full binary tree as an example, the serial number range of the first level is 1, the serial number range of the second level is 2, 3, and the serial number range of the third level is 4, 5, 6, 7, that is, the serial number range of the nth level is [2 n-1 ,2 n -1].
[0050] Step S206: The server divides the category nodes indicated by the sequence number range into multiple node sets. In this step, the server may divide the category nodes indicated by the sequence number range into multiple node sets, so that the category nodes in the same node set are treated as child nodes of the same category node, and the category identifiers of the category nodes in the same node set are arranged in a monotonically increasing or monotonically decreasing order.
[0051] Step S207: The server performs a binary search on multiple node sets in parallel to obtain the specific sequence number of the specific category node in the category array. In this step, the server performs a binary search-based category identification comparison operation on each node set in parallel to quickly locate the specific category node in the category array.
[0052] It is understood that steps S206 and S207 are not required. In actual scenarios, other methods, such as traversal, can be used to determine the specific category node from the category nodes indicated by the sequence number range. That is, the server compares the category identifier of the specific category node with the category identifiers of the category nodes indicated by the sequence number range, and determines the sequence number corresponding to the category node whose category identifier matches the category identifier of the specific category node as the specific sequence number.
[0053] Step S208: The server calculates the target sequence number of the subordinate category node of the specific category node in the category array based on the specific sequence number and the structural parameters of the category tree. In this step, the server can obtain the target sequence number of the first-level subordinate category node of the specific category node in the category array based on the specific sequence number of the specific category node in the category array and the structural parameters of the category tree; thereafter, the server obtains the target sequence number of the next-level subordinate category node of the specific category node in the category array based on the target sequence number and structural parameters of the subordinate category node of the current level, until the target sequence number of the subordinate category node as the leaf node is obtained. In actual applications, the target sequence number of subordinate category nodes at all levels is determined by the sequence number of the upper-level node to which they belong and the structural parameters of the category tree. Taking a full binary tree as an example, the child node sequence numbers of the node with sequence number m are 2m and 2m+1 respectively.
[0054] Step S209: The server uses the target sequence number to determine the subordinate category node in the category array.
[0055] Step S210: The server compares the identity of the category to be determined with the category identities of each subordinate category node to determine whether the category to be determined belongs to the specific category node. In actual applications, the server identifies subordinate category nodes at the same level as the specific category node in ascending order of hierarchy and compares the identity of the category to be determined with the category identities of the subordinate category nodes at that level. If a consistent subordinate category node exists, the server determines that the category to be determined belongs to the specific category node and stops calculating the subordinate category nodes at the next level. If a consistent subordinate category node does not exist, the server continues calculating the subordinate category nodes at the next level until a consistent subordinate category node is found or until a leaf node is reached without finding a consistent subordinate category node.
[0056] Step S211: The server executes a preset action to determine whether the category to be determined belongs to a specific category node. After determining that the category to be determined belongs to a specific category node, the server may execute a preset action such as allocating virtual resources to the user.
[0057] In the technical solution of the embodiment of the present invention, the category tree is heterogeneously transformed into an array according to a preset order, and the position of a specific category node and its subordinate nodes in the category array is quickly calculated based on structural parameters such as the depth and number of forks of the category tree, thereby avoiding traversing a large number of category nodes in the category tree, thereby reducing the time complexity of calculating the category affiliation.
[0058] A specific embodiment of the present invention is described below.
[0059] In various promotional, equity, and reward systems, rewards are distributed based on the items purchased by the user. For example, in medal rewards, the operational side sets the medal redemption rules, requiring the user to purchase multiple items in a specific category. The business system then needs to determine whether the user has met the redemption conditions. To improve request response speed, database data is typically processed heterogeneously and stored in a cache. Existing heterogeneous methods include multitrees and hash tables.
[0060] The business system needs to determine whether the item category A purchased by the user is a subcategory of the pre-specified item category B. The specific steps are to first find category B in the category tree, and then determine whether category A is category B or a subordinate category of category B. The result judgment of the two existing heterogeneous methods requires recursion from the root category downward until the category B node is found. Thereafter, the subordinate nodes of the category B node are recursively traversed to find category A. The time complexity required for this process is O(N), where N is the total number of category tree nodes. It can be seen that the existing heterogeneous method cannot fully utilize the information of each category node, and only performs brute force traversal based on the category, which has a high time complexity. This embodiment aims to provide a new data heterogeneous method to reconstruct the category tree, thereby reducing the time complexity of hit judgment.
[0061] like Figure 3 、 4 As shown, the logical category tree can be first traversed in hierarchical order to be heterogeneous into a category array, and then according to the level CategoryLevelb of category B in the category tree, the sequence number range of category B in the category array is directly located. (CategoryLevelb-1) to 2 CategoryLevelb -1, and then compare the category identification within the sequence number range. Since the array can be accessed with O(1) time complexity based on the sequence number, the process of unordered traversal starting from the root node is omitted.
[0062] Next, we traverse category B and its subordinate categories to determine whether the user's purchased category A is among them. Category B's index in the array indicates that its subcategories are indexed at 2*indexB and 2*indexB+1. We identify the categories with these two indexes and recursively search down to see if the user's purchased category A exists, thus reducing the time complexity of data search to a constant level.
[0063] The above is a special case where the category tree is a binary tree. When the category subdivision is more complex, the n-ary tree can be heterogeneously transformed into a layer-order traversal array. The child nodes of each node can be arranged from left to right in ascending order according to the category identifier. In this way, after locating the serial number range according to the level of category B, binary searches can be performed in parallel for multiple node sets indicated by the serial number range, thereby further reducing time complexity. In practical applications, a key-value pair data corresponding to a major category can be stored in the cache. The key of the key-value pair data is the identifier of the major category, and the value is the corresponding category tree. After purchasing an item, the user can locate the category tree through the identifier of the major category to which the item belongs, thereby executing the aforementioned step of determining the category affiliation.
[0064] This embodiment aims to determine whether the category purchased by the user belongs to a specific category and then execute rewards. During the determination process, a logical category tree is implemented in the form of a category array, which can quickly locate the specific category and its subordinate categories with a time complexity close to a constant to achieve determination, and uses a binary search method using the local numerical sequence of sibling category nodes to further improve the search efficiency.
[0065] It should be noted that the collection, collection, updating, analysis, processing, use, transmission, and storage of user personal information that may be involved in the technical solution of the present invention all comply with the provisions of relevant laws and regulations, are used for legitimate purposes, and do not violate public order and good morals. Necessary measures are taken with respect to user personal information to prevent unauthorized access to user personal information data and to maintain the security of user personal information, network security, and national security.
[0066] For ease of description, the aforementioned method embodiments are described as a series of actions. However, those skilled in the art should be aware that the present invention is not limited to the order of the actions described, and certain steps can actually be performed in other orders or simultaneously. In addition, those skilled in the art should also be aware that the embodiments described in this specification are preferred embodiments, and the actions and modules involved are not necessarily required to implement the present invention.
[0067] In order to better implement the above solutions of the embodiments of the present invention, relevant devices for implementing the above solutions are also provided below.
[0068] See also Figure 5 As shown, the category affiliation determination device 500 provided by the embodiment of the present invention may include: a heterogeneous unit 501 , a specific sequence number determination unit 502 , a subordinate node determination unit 503 and a subordinate relationship determination unit 504 .
[0069] Among them, the heterogeneous unit 501 is used to traverse the category nodes in the pre-established category tree in a preset order; place the category nodes into a preset array to form a category array; wherein the category node includes a category identity; the specific serial number determination unit 502 is used to obtain the identifier of the category to be determined and the category identity of the specific category node in the category tree, determine the serial number range corresponding to the level in the category array according to the level of the specific category node in the category tree, and determine the specific serial number of the specific category node in the serial number range; wherein the serial number range is a plurality of consecutively arranged serial numbers; the subordinate node determination unit 503 is used to obtain the target serial number of the subordinate category node of the specific category node in the category array based on the specific serial number and the structural parameters of the category tree, and use the target serial number to determine the subordinate category node in the category array; the subordinate relationship determination unit 504 is used to: in response to the identifier of the category to be determined being consistent with the category identity of any subordinate category node, determine that the category to be determined is subordinate to the specific category node.
[0070] In an embodiment of the present invention, the heterogeneous unit 501 may be further configured to: traverse the category nodes in the category tree in a hierarchical order.
[0071] Preferably, the specific serial number determination unit 502 can be further used to: compare the category identity of the specific category node with the category identity of the category nodes indicated by the serial number range, and determine the serial number corresponding to the category node whose category identity is consistent with the category identity of the specific category node as the specific serial number.
[0072] As a preferred solution, the specific serial number determination unit 502 can be further used to: divide the category nodes indicated by the serial number range into multiple node sets; the category nodes in the same node set are child nodes of the same category node, and the category identities of the category nodes in the same node set are arranged monotonically increasing or monotonically decreasing; and perform the comparison operation based on the binary search method in parallel for the multiple node sets.
[0073] In a specific application, the subordinate node determination unit 503 can be further used to: obtain the target serial number of the first-level subordinate category node of the specific category node in the category array based on the specific serial number and the structural parameters; obtain the target serial number of the next-level subordinate category node of the specific category node in the category array based on the target serial number of the current-level subordinate category node and the structural parameters, until the target serial number of the subordinate category node as a leaf node is obtained.
[0074] In actual application, the device is set in a preset cache; the device further includes: a storage unit for storing key-value pair data with the category tree as the value in the cache; and the category to be determined and the category tree belong to the major category indicated by the key in the key-value pair data.
[0075] In addition, in an embodiment of the present invention, the subordination relationship determination unit 504 may be further configured to: in response to the identifier of the category to be determined being inconsistent with the category identifier of each subordinate category node, determine that the category to be determined is not subordinate to the specific category node.
[0076] According to the technical solution of an embodiment of the present invention, the category tree is heterogeneously transformed into an array in a preset order, and the position of a specific category node and its subordinate nodes in the category array is quickly calculated based on structural parameters such as the depth and number of forks of the category tree, thereby avoiding traversing a large number of category nodes in the category tree, thereby reducing the time complexity of calculating the category affiliation.
[0077] Figure 6 An exemplary system architecture 600 is shown to which the method for determining category affiliation or the apparatus for determining category affiliation according to an embodiment of the present invention may be applied.
[0078] like Figure 6 As shown, system architecture 600 may include terminal devices 601, 602, and 603, a network 604, and a server 605 (this architecture is merely an example, and the components included in the specific architecture may be adjusted according to the specific circumstances of the invention). Network 604 is used to provide a medium for communication links between terminal devices 601, 602, and 603 and server 605. Network 604 may include various connection types, such as wired or wireless communication links or fiber optic cables.
[0079] Users can use terminal devices 601, 602, 603 to interact with server 605 via network 604 to receive or send messages, etc. Various client applications can be installed on terminal devices 601, 602, 603, such as a category affiliation determination application (only as an example).
[0080] The terminal devices 601 , 602 , and 603 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers.
[0081] The server 605 may be a server that provides various services, such as a backend server (for example only) that supports a category affiliation determination application operated by a user using the terminal devices 601, 602, and 603. The backend server may process a received request for calculating a category affiliation and provide feedback of the processing result (for example, whether a dependency exists—for example only) to the terminal devices 601, 602, and 603.
[0082] It should be noted that the method for determining category affiliation provided in the embodiment of the present invention is generally executed by the server 605 . Accordingly, the device for determining category affiliation is generally disposed in the server 605 .
[0083] It should be understood that Figure 6 The number of terminal devices, networks and servers in the embodiment is merely illustrative. Any number of terminal devices, networks and servers may be provided as required.
[0084] The present invention also provides an electronic device. The electronic device in an embodiment of the present invention includes: one or more processors; and a storage device configured to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the method for determining category affiliation provided by the present invention.
[0085] Reference below Figure 7 , which shows a schematic structural diagram of a computer system 700 of an electronic device suitable for implementing an embodiment of the present invention. Figure 7 The electronic device shown is only an example and should not limit the functions and scope of use of the embodiments of the present invention.
[0086] like Figure 7 As shown, the computer system 700 includes a central processing unit (CPU) 701, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 702 or a program loaded from a storage unit 708 into a random access memory (RAM) 703. Various programs and data required for the operation of the computer system 700 are also stored in the RAM 703. The CPU 701, the ROM 702, and the RAM 703 are connected to each other via a bus 704. An input / output (I / O) interface 705 is also connected to the bus 704.
[0087] The following components are connected to the I / O interface 705: an input section 706 including a keyboard, a mouse, and the like; an output section 707 including devices such as a cathode ray tube (CRT), a liquid crystal display (LCD), and a speaker; a storage section 708 including a hard disk and the like; and a communication section 709 including a network interface card such as a LAN card or a modem. The communication section 709 performs communication processing via a network such as the Internet. A drive 710 is also connected to the I / O interface 705 as needed. A removable medium 711, such as a magnetic disk, an optical disk, a magneto-optical disk, or a semiconductor memory, is installed in the drive 710 as needed so that computer programs read therefrom can be installed in the storage section 708 as needed.
[0088] In particular, according to embodiments disclosed herein, the processes described in the main step diagrams above can be implemented as computer software programs. For example, embodiments of the present invention include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for executing the methods shown in the main step diagrams. In the above embodiments, the computer program can be downloaded and installed from a network via the communication section 709 and / or installed from removable media 711. When the computer program is executed by the central processing unit 701, the above-described functions defined in the system of the present invention are performed.
[0089] It should be noted that the computer-readable medium described in the present invention may be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or component, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to, an electrical connection having one or more conductors, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, device, or component. In the present invention, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport a program for use by or in conjunction with an instruction execution system, apparatus, or device. Program code embodied on a computer-readable medium may be transmitted using any suitable medium, including but not limited to wireless, wireline, optical cable, RF, or any suitable combination thereof.
[0090] The flowcharts and block diagrams in the accompanying drawings illustrate the possible implementation architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present invention. In this regard, each box in the flowchart or block diagram can represent a module, program segment, or a part of code, and the above-mentioned module, program segment, or a part of 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 an order different from that marked in the accompanying drawings. For example, two boxes represented in succession 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 or flowchart, and the combination of boxes in the block diagram or flowchart, can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0091] The units involved in the embodiments of the present invention may be implemented in software or hardware. The units described may also be provided in a processor. For example, they may be described as follows: a processor comprising: a heterogeneous unit, a specific sequence number determination unit, a subordinate node determination unit, and a subordinate relationship determination unit. The names of these units do not, in some cases, constitute limitations on the units themselves. For example, a heterogeneous unit may also be described as a "unit that provides a category array to a specific sequence number determination unit."
[0092] As another aspect, the present invention further provides a computer-readable medium, which may be included in the device described in the above embodiment; or may exist independently without being assembled into the device. The above-mentioned computer-readable medium carries one or more programs. When the above-mentioned one or more programs are executed by the device, the steps executed by the device include: traversing the category nodes in a pre-established category tree in a preset order; placing the category nodes into a preset array to form a category array; wherein the category nodes include category identifiers; obtaining the identifier of the category to be determined and the category identifier of a specific category node in the category tree, determining the sequence number range corresponding to the level in the category array according to the level of the specific category node in the category tree, and determining the specific sequence number of the specific category node in the sequence number range; wherein the sequence number range is a plurality of consecutively arranged sequence numbers; obtaining the target sequence number of the subordinate category node of the specific category node in the category array based on the specific sequence number and the structural parameters of the category tree, and determining the subordinate category node in the category array using the target sequence number; in response to the identifier of the category to be determined being consistent with the category identifier of any subordinate category node, determining that the category to be determined is subordinate to the specific category node.
[0093] In the technical solution of the embodiment of the present invention, the category tree is heterogeneously transformed into an array according to a preset order, and the position of a specific category node and its subordinate nodes in the category array is quickly calculated based on structural parameters such as the depth and number of forks of the category tree, thereby avoiding traversing a large number of category nodes in the category tree, thereby reducing the time complexity of calculating the category affiliation.
[0094] The above specific embodiments do not limit the scope of protection of the present invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions may occur depending on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention are intended to be included within the scope of protection of the present invention.
Claims
1. A method for determining category affiliation, characterized in that: include: Traverse the category nodes in the pre-established category tree in a preset order; Placing the category nodes into a preset array to form a category array; wherein the category nodes include category identifications; Obtaining an identifier of a category to be identified and a category identifier of a specific category node in the category tree, determining a sequence number range corresponding to the level of the specific category node in the category array based on the level of the specific category node in the category tree, and determining a specific sequence number of the specific category node within the sequence number range; wherein the sequence number range is a plurality of consecutively arranged sequence numbers; Obtaining a target sequence number of a subordinate category node of the specific category node in the category array according to the specific sequence number and a structural parameter of the category tree, and determining the subordinate category node in the category array using the target sequence number; In response to the identifier of the category to be determined being consistent with the category identifier of any subordinate category node, it is determined that the category to be determined is subordinate to the specific category node.
2. The method according to claim 1, characterized in that The traversing of the category nodes in the pre-established category tree in a preset order includes: Traverse the category nodes in the category tree in a hierarchical order.
3. The method according to claim 1, characterized in that Determining the specific serial number of the specific category node in the serial number range includes: The category identifier of the specific category node is compared with the category identifiers of the category nodes indicated by the sequence number range, and the sequence number corresponding to the category node whose category identifier is consistent with the category identifier of the specific category node is determined as the specific sequence number.
4. The method according to claim 3, characterized in that The comparing the category identifier of the specific category node with the category identifiers of the category nodes indicated by the sequence number range includes: The category nodes indicated by the sequence number range are divided into multiple node sets; the category nodes in the same node set are child nodes of the same category node, and the category identities of the category nodes in the same node set are arranged in monotonically increasing or monotonically decreasing order; The comparison operation based on the binary search method is performed in parallel on the multiple node sets.
5. The method according to claim 1, wherein The step of obtaining the target sequence number of the subordinate category node of the specific category node in the category array according to the specific sequence number and the structural parameters of the category tree includes: Obtaining a target sequence number of a first-level subordinate category node of the specific category node in the category array according to the specific sequence number and the structural parameter; The target sequence number of the subordinate category node at the next level of the specific category node in the category array is obtained according to the target sequence number of the subordinate category node at the current level and the structural parameter, until the target sequence number of the subordinate category node as the leaf node is obtained.
6. The method according to claim 1, wherein The method is executed in a preset cache; the method further comprises: storing key-value pair data with the category tree as a value in the cache; and, The category to be determined and the category tree belong to the major category indicated by the key in the key-value pair data.
7. The method according to claim 1, characterized in that The method further comprises: In response to the identifier of the category to be determined being inconsistent with the category identifier of each subordinate category node, it is determined that the category to be determined is not subordinate to the specific category node.
8. A device for determining category affiliation, characterized in that: include: A heterogeneous unit, configured to traverse the category nodes in a pre-established category tree in a preset order; Placing the category nodes into a preset array to form a category array; wherein the category nodes include category identifications; a specific sequence number determination unit, configured to obtain an identifier of a category to be determined and a category identifier of a specific category node in the category tree, determine a sequence number range corresponding to the level of the specific category node in the category array according to the level of the specific category node in the category tree, and determine a specific sequence number of the specific category node within the sequence number range; wherein the sequence number range is a plurality of consecutively arranged sequence numbers; a subordinate node determining unit, configured to obtain a target sequence number of a subordinate category node of the specific category node in the category array according to the specific sequence number and a structural parameter of the category tree, and determine the subordinate category node in the category array using the target sequence number; The subordinate relationship determination unit is configured to: in response to the identifier of the category to be determined being consistent with the category identifier of any subordinate category node, determine that the category to be determined is subordinate to the specific category node.
9. An electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.