Component selection method and device, equipment, storage medium and program product
By extracting functional description information from the component's knowledge graph, calculating text similarity, and utilizing clustering algorithms and comprehensive scoring methods, the system automatically selects replacement components, solving the problem of low efficiency in manual selection and achieving high efficiency and accuracy in component replacement.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- CHINA MOBILEHANGZHOUINFORMATION TECH CO LTD
- Filing Date
- 2024-11-05
- Publication Date
- 2026-05-08
AI Technical Summary
In existing technologies, manually selecting replacements for license-risk components in open-source software is inefficient and results in long replacement times.
By extracting functional description information from the component's knowledge graph, calculating text similarity, and utilizing clustering algorithms and comprehensive scoring methods, alternative components with similar functions are automatically selected.
It improves the efficiency of component replacement, ensures that the replacement component is functionally similar to the component to be replaced, and reduces manual analysis time.
Smart Images

Figure CN121996797A_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of data security technology, and in particular relates to a component selection method, apparatus, device, storage medium and program product. Background Technology
[0002] Open-source software authors can set open-source licenses for components in their software through open-source license agreements. When using open-source software, users can manually select alternative components to replace those with licensing risks, thereby avoiding the risk of using non-compliant components.
[0003] However, when manually selecting alternative components, it is necessary to manually analyze the licensing agreement of each component and select compliant components that have the same function as the components with licensing risks. This process takes a long time and results in low replacement efficiency. Summary of the Invention
[0004] This application provides a method, apparatus, device, storage medium, and program product for component selection. These can improve component replacement efficiency.
[0005] In a first aspect, embodiments of this application provide a method for selecting components, including:
[0006] The functional description information of the component is obtained from the knowledge graph corresponding to the component, and the functional description information is used to represent the function of the component;
[0007] Calculate the text similarity between the component to be replaced and the component based on the functional description information;
[0008] Components whose text similarity is greater than a preset threshold are selected as candidate components.
[0009] In one possible implementation, after selecting components with text similarity greater than a preset threshold as candidate components, the method further includes:
[0010] The candidate components are clustered using a clustering algorithm to obtain a clustered component set;
[0011] For each component in the clustering component set, a judgment matrix is constructed based on a preset scaling value table and preset indicators. The judgment matrix includes elements representing the relative importance between every two preset indicators.
[0012] Calculate the eigenvalues of the judgment matrix;
[0013] The eigenvalues of the judgment matrix are used as the weights of the preset index;
[0014] Based on the weights, the preset scoring table, and the parameter values of the preset indicators, the comprehensive score of the component is calculated.
[0015] The component with the highest overall score will be used as the replacement component.
[0016] In one possible implementation, constructing the judgment matrix of the component based on a preset scaling value table and preset indicators includes:
[0017] Obtain the importance value of the preset indicator;
[0018] For each preset indicator, the importance value of the preset indicator is compared with that of other preset indicators to obtain the comparison result;
[0019] The judgment matrix is constructed based on the comparison results and the preset scaling value table.
[0020] In one possible implementation, the number of preset indicators is multiple; the calculation of the comprehensive score of the component based on the weights, the preset scoring table, and the parameter values of the preset indicators includes:
[0021] For each component in the clustering component set, the parameter value of the preset indicator is obtained from the knowledge graph corresponding to the component;
[0022] Find the preset scoring standard corresponding to the preset indicator in the preset scoring table;
[0023] The score corresponding to the parameter value of the preset indicator is calculated according to the preset scoring criteria;
[0024] For each preset indicator, calculate the product of the weight of the preset indicator and the score corresponding to the preset indicator to obtain the target product;
[0025] The comprehensive score is obtained by summing the products of the objectives corresponding to each preset indicator.
[0026] In one possible implementation, before obtaining the parameter value of the preset indicator from the knowledge graph corresponding to the component, the method further includes:
[0027] Obtain the text information and code of the component, wherein the text information includes functional description information and comment information;
[0028] Valid text information is obtained from the text information and the component code, and the valid text information includes parameter values of multiple preset indicators;
[0029] Based on the annotation information, the calling relationship between methods and functions in the component code is obtained;
[0030] The functional description information and the valid text information are used as the attribute information of the component, and a knowledge graph corresponding to the component is constructed based on the calling relationship between methods and functions in the component code.
[0031] In one possible implementation, calculating the text similarity between the component to be replaced and the component based on the functional description information includes:
[0032] Extract the keywords corresponding to the components from the functional description information of the components;
[0033] For each component, the text similarity between the component to be replaced and the component is calculated using the keywords.
[0034] Secondly, embodiments of this application provide a component selection apparatus, comprising:
[0035] The acquisition module is used to acquire the functional description information of the component from the knowledge graph corresponding to the component, and the functional description information is used to represent the function of the component;
[0036] The calculation module is used to calculate the text similarity between the component to be replaced and the component based on the functional description information;
[0037] The determination module is used to select components whose text similarity is greater than a preset threshold as candidate components.
[0038] Thirdly, embodiments of this application provide an electronic device, the device comprising: a processor and a memory storing computer program instructions;
[0039] When the processor executes the computer program instructions, it implements the component selection method as described in any one of the first aspects.
[0040] Fourthly, embodiments of this application provide a computer-readable storage medium storing computer program instructions that, when executed by a processor, implement the component selection method as described in any one of the first aspects.
[0041] Fifthly, embodiments of this application provide a computer program product in which instructions, when executed by a processor of an electronic device, cause the electronic device to perform a component selection method as described in any one of the first aspects.
[0042] This application discloses a method, apparatus, device, storage medium, and program product for component selection. It obtains functional description information of the component from a knowledge graph corresponding to the component, whereby the functional description information describes the component's function. Then, it calculates the text similarity of keywords between the component to be replaced and other components using the functional description information. The higher the text similarity, the more similar the functions of the components. Therefore, components with a text similarity greater than a preset threshold are selected as candidate components. Thus, by calculating the text similarity between keywords, the degree of functional similarity between different components can be determined, and candidate components with a text similarity greater than the preset threshold are selected as replacement components for the component to be replaced. Replacing the component to be replaced with a replacement component improves the replacement efficiency. Attached Figure Description
[0043] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments of this application will be briefly introduced below. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0044] Figure 1 This is a flowchart illustrating a component selection method provided in an embodiment of this application;
[0045] Figure 2 This is a flowchart illustrating a method for constructing a knowledge graph according to an embodiment of this application;
[0046] Figure 3 This is a flowchart illustrating a method for calculating a comprehensive score provided in an embodiment of this application;
[0047] Figure 4 This is a flowchart illustrating another method for calculating a comprehensive score provided in an embodiment of this application;
[0048] Figure 5 This is an exemplary schematic diagram of a component selection method provided in an embodiment of this application;
[0049] Figure 6 This is a schematic diagram of the structure of a component selection device provided in an embodiment of this application;
[0050] Figure 7 This is a schematic diagram of the structure of an electronic device provided in another embodiment of this application. Detailed Implementation
[0051] The features and exemplary embodiments of various aspects of this application will be described in detail below. To make the objectives, technical solutions, and advantages of this application clearer, the application will be further described in detail below with reference to the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only intended to explain this application and not to limit it. For those skilled in the art, this application can be implemented without some of these specific details. The following description of the embodiments is merely to provide a better understanding of this application by illustrating examples.
[0052] It should be noted that, in this document, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising..." does not exclude the presence of additional identical elements in the process, method, article, or apparatus that includes said element.
[0053] To address the problems existing in the prior art, embodiments of this application provide a method, apparatus, device, storage medium, and program product for component selection, firstly based on... Figure 1 This application introduces a method for selecting components, such as... Figure 1 As shown, the method includes:
[0054] S101. Obtain the functional description information of the component from the knowledge graph corresponding to the component.
[0055] The functional description information represents the function of the component. Each component corresponds to a knowledge graph, which includes multiple nodes and the connections between them. Each node contains attribute information, which describes the characteristics of the node.
[0056] In one example, in the knowledge graph corresponding to a component, nodes represent the methods and functions corresponding to that component, connections represent the calling relationships between methods and functions, and the attribute information of a node represents the functionality of the method and function corresponding to that node, as well as the parameters required to call that method and function.
[0057] Specifically, the method for constructing the knowledge graph corresponding to the component will be described in detail in subsequent embodiments.
[0058] S102. Calculate the text similarity between the component to be replaced and the components based on the functional description information.
[0059] The functional description information is text information and is used to represent the function of the component. By calculating the text similarity between the functional description information of the component to be replaced and the functional description information of the component, the component with similar function to the component to be replaced can be identified.
[0060] S103. Select components with text similarity greater than a preset threshold as candidate components.
[0061] The preset threshold is set based on experience.
[0062] Understandably, when the text similarity is greater than a preset threshold, the candidate component and the component to be replaced have the same function. Therefore, the candidate component can be used as the replacement component.
[0063] Using the above method, functional description information of the component is obtained from the knowledge graph corresponding to the component.
[0064] The functional description information describes the function of the component. Then, the text similarity of keywords between the component to be replaced and other components is calculated using this information. Higher text similarity indicates more similar functions. Therefore, components with text similarity greater than a preset threshold are selected as candidate components. In this way, by calculating the text similarity between keywords, the degree of functional similarity between different components can be determined, and candidate components with text similarity greater than a preset threshold are used as replacement components for the component to be replaced. Replacing the component to be replaced with a replacement component improves the replacement efficiency.
[0065] In some embodiments of this application, before obtaining the functional description information of the component from the knowledge graph corresponding to the component in S101 above, a knowledge graph corresponding to each component is constructed. Specifically, the method for constructing the knowledge graph is as follows: Figure 2 As shown, the method includes:
[0066] S201. Obtain the component's text information and component code.
[0067] The text information includes functional descriptions and comments. Comments provide detailed descriptions of the functions and methods within the component code. Electronic devices can obtain the text information and component code of open-source software components from component code databases provided by third-party platforms.
[0068] S202. Obtain valid text information from text information and component code.
[0069] The valid text information includes parameter values for multiple preset indicators.
[0070] Specifically, the text information can be the documentation corresponding to the component code, such as README files, commit history, and issue tracking.
[0071] The text information is preprocessed into character form. Static code analysis tools are then used to parse the component code, identifying elements such as methods, functions, classes, and variables. Finally, the processed text information and valid text information from the component code are extracted.
[0072] The valid text information also includes basic component information, which is used as the component's attribute information. Basic component information includes license information, language information, update frequency, number of favorites, number of followers, number of contributors, and usage count. It should be noted that the above basic component information is only an example; in actual implementations, the types and number of basic component information are not limited to this.
[0073] S203. Based on the annotation information, obtain the calling relationship between methods and functions in the component code.
[0074] The comments are used to indicate the function of each method in the component code and the calling relationship between the methods.
[0075] S204. Use functional description information and valid text information as the component's attribute information, and construct the component's corresponding knowledge graph based on the calling relationship between methods and functions in the component code.
[0076] Specifically, the method functions in the component code are used as nodes, the valid text information is used as the attribute information of the nodes in the knowledge graph, the functional description information is used as the attribute information of the component, and then the connection relationship in the nodes is determined according to the calling relationship to construct the knowledge graph corresponding to the component.
[0077] Using the method provided in this application embodiment, the text information includes a functional summary of the component, i.e., the aforementioned functional description information. Further, the electronic device acquires the text information and valid text information from the component code. The valid text information includes parameter values for multiple preset indicators. Subsequently, the functional description information and the valid text information can be used as the component's attribute information. Based on the method function call relationships included in the annotation information, a knowledge graph corresponding to the component can be constructed. The attribute information in the knowledge graph corresponding to the component can be used to describe the component's function and the functions of each method function of the component. This facilitates the electronic device in subsequently determining candidate components based on the component's corresponding attribute information.
[0078] It should be noted that the functional description information is extracted by the electronic device from the functional summary information. Specifically, the method for extracting functional description information from the functional summary information is as follows:
[0079] The text information is parsed to obtain chapter information, and the chapter information with preset tags is searched in the chapter information according to preset tags; the functional description information of the component is obtained from the chapter information with preset tags.
[0080] The chapter information is used to indicate different modules within the component. Preset labels are pre-defined based on experience.
[0081] Specifically, the text information can be the README file corresponding to the component. The electronic device can obtain information about each section of the component's code using a text parsing tool. Then, the electronic device uses preset tags to search for the preset-tag section information containing functional descriptions, thereby obtaining the component's corresponding functional description information from the preset-tag section information.
[0082] It should be noted that after extracting the function description information as described above, the text information is preprocessed in a unified manner to remove invalid information from the text information, that is, to extract the valid text information from the text information.
[0083] Electronic devices can retrieve component code and its corresponding text information from a component code database. By parsing the text information, they can obtain chapter information and, through preset tags, chapter information with preset tags. This preset tag chapter information includes functional descriptions. Thus, electronic devices can quickly find the functional descriptions within the text information using these preset tags.
[0084] It should be noted that after the electronic device obtains text information from the component code database, the text information includes invalid information. Therefore, the electronic device can remove the invalid information and extract the valid text information from the text information. Based on this, the above-mentioned S202, extracting the text information and the valid text information from the component code, can be implemented as follows:
[0085] Step 1: Convert the text information and component code into vector form to obtain the text vector.
[0086] Specifically, text information and component code are converted into vector form through word embedding to obtain text vectors.
[0087] The text vector includes vectors corresponding to text information and vectors corresponding to component code.
[0088] Step 2: Extract features from the text vector to obtain the text feature vector.
[0089] Among them, electronic devices can extract text feature vectors from text vectors through machine learning.
[0090] Step 3: Use a feature selection algorithm to extract target text features from the text feature vector.
[0091] The feature selection algorithm can be a random forest algorithm. It should be noted that this application does not limit the feature selection algorithm used in its embodiments.
[0092] Step 4: Determine effective text information based on the features of the target text.
[0093] The target text features include target features corresponding to text vectors and target features corresponding to component code. Target text features are used to characterize the functionality of each method function within the component.
[0094] Specifically, electronic devices can decode the target text features using machine learning models to obtain the effective text information corresponding to the target text features.
[0095] The method provided in this application converts text information and component code into vector form to obtain text vectors. Feature extraction can then be performed on these text vectors to obtain text feature vectors. These text feature vectors reflect the data features within the text information and component code. Furthermore, a feature selection algorithm can be used to select target text features from the text feature vectors. These target text features are those with high importance within the text feature vectors. Therefore, the effective text information subsequently determined based on the target text features can effectively reflect the features and functions within the text information and component code.
[0096] In some embodiments of this application, the calculation of the text similarity between the component to be replaced and the components based on the functional description information in S102 can be specifically implemented as follows:
[0097] Extract keywords from the functional descriptions of the components. For each component, calculate the text similarity between the component to be replaced and other components using the keywords.
[0098] The functional description information is text information, and the electronic device can use keyword extraction algorithms or neural network models to extract keywords from the text information. This application does not limit the methods for extracting keywords from text information.
[0099] In one example, the Term Frequency-Inverse Document Frequency (TF-IDF) method can be used to extract keywords from the functional description information.
[0100] It should be noted that after the electronic device extracts the keywords corresponding to each component, it can calculate the text similarity between the keywords corresponding to each component. Specifically, the embodiments of this application do not limit the method of calculating text similarity.
[0101] Using the method provided in this application, keywords corresponding to components can be extracted by extracting keywords from functional description information. The extracted keywords represent the functions that the components can perform. Thus, by calculating the textual similarity of keywords between different components and the component to be replaced, components with similar functions to the component to be replaced can be quickly identified, improving the efficiency of finding functionally similar components.
[0102] Based on the knowledge graph corresponding to the components constructed above, electronic devices can adopt... Figure 1 The method shown identifies the replacement component for the component to be replaced from the knowledge graph corresponding to the component.
[0103] Specifically, the user can input multiple preset metrics, that is, the number of the aforementioned preset metrics can be multiple, such as... Figure 3 As shown, after step S105 above, where components with text similarity greater than a preset threshold are selected as candidate components, the method further includes:
[0104] S301. Cluster the candidate components using a clustering algorithm to obtain a clustered component set.
[0105] Among them, the clustering algorithm can be the Compound Fuzzy Clustering Optimization Network Algorithm (CABON).
[0106] S302. For each component in the cluster component set, construct the component's judgment matrix based on the preset scaling value table and preset indicators.
[0107] The judgment matrix includes elements representing the relative importance between any two preset indicators.
[0108] Specifically, the preset scaling value table is pre-set based on experience. After comparing the relative importance of preset indicators among electronic devices, the corresponding preset scaling value is looked up in the preset scaling value table according to the relative importance obtained from the comparison. The found preset scaling value is used as the value of the element in the judgment matrix, thereby obtaining the judgment matrix corresponding to the component.
[0109] S303. Calculate the eigenvalues of the judgment matrix.
[0110] S304. Use the eigenvalues of the judgment matrix as the weights of the preset indicators.
[0111] S305. Based on the weights, preset scoring table, and preset indicator parameter values, calculate the comprehensive score of the component.
[0112] The preset scoring table is pre-set based on experience. The preset scoring criteria include the scoring standards corresponding to each preset indicator.
[0113] Specifically, after obtaining the parameter values of preset indicators from the knowledge graph, the electronic device can look up the corresponding scoring criteria in a preset scoring table according to the preset indicator, and then calculate the score of the preset indicator using the parameter values and the corresponding scoring criteria. Finally, the electronic device calculates a comprehensive score based on the calculated score and the weights corresponding to the preset indicator.
[0114] S306. Use the component with the highest overall score as the replacement component.
[0115] Using the method provided in this application, there can be multiple candidate components. Clustering algorithms are used to cluster the candidate components, allowing for secondary screening and obtaining a set of clustered components. Then, a judgment matrix for the components is constructed using a preset scaling table and preset indicators. The judgment matrix yields the weight of each preset indicator. Based on the calculated weights, the preset scoring table, and the parameter values of the preset indicators in the knowledge graph, a comprehensive score for the component can be calculated. Thus, using clustering algorithms and comprehensive score calculations to screen candidate components improves the accuracy of the calculated replacement components. That is, the replacement components and the components to be replaced are more functionally similar.
[0116] It should be noted that the electronic device stores the importance value of each preset indicator. That is, after the electronic device obtains the preset indicator input by the user, it obtains the importance value of the preset indicator, and then compares the importance value of each preset indicator with other preset indicators to obtain the comparison result. Based on the comparison result and the preset scaling value table, a judgment matrix is constructed.
[0117] Specifically, electronic devices can obtain the relative importance of preset indicators by calculating the difference in the importance values of preset indicators, i.e., the comparison result mentioned above. Then, using the comparison result, the corresponding scale value is found in the preset scale value table to obtain the value of the preset indicator in the judgment matrix.
[0118] In one example, if the number of preset indicators is n, then the judgment matrix is an n×n matrix, and the element in the i-th row and j-th element of the matrix is used to characterize the relative importance of preset indicator i compared to preset indicator j.
[0119] The judgment matrix A is shown below:
[0120]
[0121] Where, if the importance values of preset indicator i and preset indicator j are the same, then a ij =a ji =1; If the preset indicator i is more important than the preset indicator j, that is, the relative importance of preset indicator i compared to preset indicator j is greater than 1, then a ij Greater than 1.
[0122] Specifically, the preset scale values are shown in Table 1:
[0123] Table 1
[0124]
[0125] The electronic device stores the importance value of each preset indicator. By comparing the importance values of the preset indicators, the relative importance of the preset indicators can be determined. Then, based on the correspondence between relative importance and preset scale values, the scale value corresponding to the preset indicator is determined. Finally, the electronic device determines the value of the element corresponding to the preset indicator in the judgment matrix based on the scale value corresponding to the preset indicator, thereby constructing the judgment matrix.
[0126] For example, if the importance value of preset indicator 1 is 3 and the importance value of preset indicator 2 is 5, then the relative importance value between preset indicator 1 and preset indicator 2 is 2. Based on the correspondence between relative importance values and preset scale values, the scale value corresponding to preset indicator 1 is determined to be 3. The electronic device will use the 'a' in the above judgment matrix... 12 The value is set to 3.
[0127] Thus, since the electronic device pre-stores the importance values of each preset indicator, after obtaining the preset indicators input by the user, the more important preset indicators can be determined by comparing their importance values. Then, based on the importance of the preset indicators and a preset scaling value table, the value of each element in the judgment matrix is determined, thereby constructing the judgment matrix. In this way, the elements in the judgment matrix represent the relative importance of the preset indicators. The eigenvalues of the subsequently calculated judgment matrix can be used to represent the weights of each preset indicator, thereby assigning weights to each preset indicator in this business scenario according to actual business needs. Thus, the comprehensive score calculated using weights better reflects business requirements.
[0128] It should be noted that after determining the values of the elements in the judgment matrix, a consistency check needs to be performed on these values. Specifically, the consistency index is... Where λ maxTo determine the largest eigenvalue of the judgment matrix, n represents the number of elements in the judgment matrix. After calculating the consistency index, the consistency ratio of the judgment matrix is calculated. Here, RI is the average random consistency index, which is pre-set based on the dimension of the judgment matrix. By adjusting the parameter values in the judgment matrix, CR is ensured to be less than 0.1, thus guaranteeing the consistency of the judgment matrix and improving the accuracy of the calculation results.
[0129] The following explains how to calculate the overall score for each component, such as... Figure 4 As shown, the method for calculating the comprehensive score is as follows:
[0130] S401. For each component in the clustering component set, obtain the parameter values of preset indicators from the knowledge graph corresponding to the component.
[0131] Specifically, the electronic device obtains parameter values from the attribute information of the knowledge graph of each component according to preset indicators.
[0132] S402. Find the preset scoring standard corresponding to the preset indicator in the preset scoring table.
[0133] The preset scoring table is set up in advance based on experience. The preset scoring criteria include the correspondence between preset scoring standards and preset indicators.
[0134] S403. Calculate the score corresponding to the parameter value of the preset index according to the preset scoring standard.
[0135] Specifically, the preset scoring table is shown in Table 2:
[0136] Table 2
[0137]
[0138]
[0139] The similarity score in the preset scoring table is the same as the text similarity score mentioned above.
[0140] Specifically, the electronic device retrieves the parameter values corresponding to preset indicators from the attribute information of the knowledge graph corresponding to the component, and looks up the scoring criteria corresponding to the preset indicators in the aforementioned preset scoring table. The score corresponding to the preset indicator is then calculated based on the obtained scoring criteria.
[0141] The functional point similarity can be calculated using the following method:
[0142] Electronic devices acquire attribute information of each method function in the knowledge graph corresponding to the component, extract functional keywords of each method function from the attribute information using a keyword extraction algorithm, calculate the text similarity of functional keywords corresponding to different components, and take the method function with a text similarity greater than a preset similarity threshold as a similar method function.
[0143] Then, the electronic device determines the function point similarity based on the ratio of the number of similar method functions to the total number of method functions in the component.
[0144] In one example, the preset metrics include update frequency, feature similarity, and number of followers. If the update frequency is within the last month, the feature similarity is 70%, and the number of followers is 2000, then the electronic device will receive a score of 100 for update frequency, 70 for feature similarity, and 100 for the number of followers, calculated according to the preset scoring table.
[0145] Furthermore, after the aforementioned electronic device determines the scores of each component on preset indicators according to a preset scoring table, a structure matrix can be constructed based on the scores.
[0146] For example, an electronic device calculates the scores of K components on n preset indicators and outputs an n×K result matrix R, where R is the score of K components on n preset indicators. ij It is the score of the i-th component on the j-th preset index.
[0147] The preset indicators in the above preset scoring table are only examples. In actual implementation, the number and types of preset indicators are not limited to these.
[0148] S404. For each preset indicator, calculate the product of the preset indicator's weight and the corresponding score to obtain the target product.
[0149] S405. Accumulate and calculate the product of the objectives corresponding to each preset indicator to obtain a comprehensive score.
[0150] Specifically, the formula for calculating the overall score is as follows:
[0151]
[0152] Among them, S i W represents the overall score. j R represents the weight corresponding to the preset indicator. ij This indicates the score corresponding to the preset indicator.
[0153] Using the method provided in this application, after scoring the parameter values of preset indicators using preset scoring criteria, a score corresponding to each preset indicator can be obtained. Then, the scores of each preset indicator are weighted and summed using preset weights to obtain the comprehensive score of the component. Thus, by using weights to weight and sum the scores of each preset indicator, since the weights are determined based on the importance of the preset indicators, the calculated comprehensive score is more closely aligned with actual needs, improving the accuracy of the calculation results.
[0154] The following combination Figure 5 This application describes a method for selecting components, as shown in the embodiments. Figure 5 As shown, the electronic device extracts code information, semantic information, and structured information. Specifically, regarding code information, the electronic device can remove invalid information, extract comment information, standardize identifiers, extract data structure and parameter information, and obtain function call relationships. The code information refers to the information corresponding to the code of the aforementioned components.
[0155] Based on semantic information, electronic devices can extract information such as submission frequency, annotation information, and documentation.
[0156] For structured information, electronic devices can extract language information and licensing information, among others. Semantic information and structured information refer to the aforementioned text information.
[0157] The electronic device constructs a knowledge graph based on the information obtained above. The knowledge graph corresponding to each component is input into a ranking model, which calculates a comprehensive score for each component. The component with the highest comprehensive score is then recommended to the user.
[0158] Specifically, the method for calculating the comprehensive score of each component using the ranking model is described in the relevant embodiments above, and will not be repeated here.
[0159] Based on the same concept, this application also provides a component selection device, such as... Figure 6 As shown, the device includes:
[0160] The acquisition module 601 is used to acquire the functional description information of the component from the knowledge graph corresponding to the component, wherein the functional description information is used to represent the function of the component;
[0161] Calculation module 602 is used to calculate the text similarity between the component to be replaced and the component based on the functional description information;
[0162] The determination module 603 is used to select components whose text similarity is greater than a preset threshold as candidate components.
[0163] In one possible implementation, module 603 is specifically used for:
[0164] The candidate components are clustered using a clustering algorithm to obtain a clustered component set;
[0165] For each component in the clustering component set, a judgment matrix is constructed based on a preset scaling value table and preset indicators. The judgment matrix includes elements representing the relative importance between every two preset indicators.
[0166] Calculate the eigenvalues of the judgment matrix;
[0167] The eigenvalues of the judgment matrix are used as the weights of the preset index;
[0168] Based on the weights, the preset scoring table, and the parameter values of the preset indicators, the comprehensive score of the component is calculated.
[0169] The component with the highest overall score will be used as the replacement component.
[0170] In one possible implementation, module 603 is specifically used for:
[0171] Obtain the importance value of the preset indicator;
[0172] For each preset indicator, the importance value of the preset indicator is compared with that of other preset indicators to obtain the comparison result;
[0173] The judgment matrix is constructed based on the comparison results and the preset scaling value table.
[0174] In one possible implementation, module 603 is specifically used for:
[0175] For each component in the clustering component set, the parameter value of the preset indicator is obtained from the knowledge graph corresponding to the component;
[0176] Find the preset scoring standard corresponding to the preset indicator in the preset scoring table;
[0177] The score corresponding to the parameter value of the preset indicator is calculated according to the preset scoring criteria;
[0178] For each preset indicator, calculate the product of the weight of the preset indicator and the score corresponding to the preset indicator to obtain the target product;
[0179] The comprehensive score is obtained by summing the products of the objectives corresponding to each preset indicator.
[0180] In one possible implementation, the device further includes:
[0181] The acquisition module 601 is further configured to acquire the text information and component code of the component before acquiring the functional description information of the component from the knowledge graph corresponding to the component, wherein the text information includes functional description information and annotation information;
[0182] The acquisition module 601 is further configured to acquire valid text information from the text information and the component code, wherein the valid text information includes parameter values of multiple preset indicators;
[0183] Based on the annotation information, the calling relationship between methods and functions in the component code is obtained;
[0184] The functional description information and the valid text information are used as the attribute information of the component, and a knowledge graph corresponding to the component is constructed based on the calling relationship between methods and functions in the component code.
[0185] In one possible implementation, the computing module 602 is specifically used for:
[0186] Extract the keywords corresponding to the components from the functional description information of the components;
[0187] For each component, the text similarity between the component to be replaced and the component is calculated using the keywords.
[0188] It should be noted that the device for selecting components is the same as the device used in the above-described method for selecting components. All implementation methods in the above-described method embodiments are applicable to the embodiments of this device and can achieve the same technical effect.
[0189] Figure 7 A schematic diagram of the hardware structure of the electronic device provided in an embodiment of this application is shown.
[0190] An electronic device may include a processor 701 and a memory 702 storing computer program instructions.
[0191] Specifically, the processor 701 may include a central processing unit (CPU), an application-specific integrated circuit (ASIC), or one or more integrated circuits that can be configured to implement the embodiments of this application.
[0192] Memory 702 may include mass storage for data or instructions. For example, and not limitingly, memory 702 may include a hard disk drive (HDD), floppy disk drive, flash memory, optical disk, magneto-optical disk, magnetic tape, or Universal Serial Bus (USB) drive, or a combination of two or more of these. Where appropriate, memory 702 may include removable or non-removable (or fixed) media. Where appropriate, memory 702 may be internal or external to the integrated gateway disaster recovery device. In a particular embodiment, memory 702 is non-volatile solid-state memory.
[0193] Memory may include read-only memory (ROM), random access memory (RAM), disk storage media devices, optical storage media devices, flash memory devices, and electrical, optical, or other physical / tangible memory storage devices. Therefore, typically, memory includes one or more tangible (non-transitory) computer-readable storage media (e.g., memory devices) encoded with software including computer-executable instructions, and when the software is executed (e.g., by one or more processors), it is operable to perform the operations described with reference to the methods according to one aspect of this disclosure.
[0194] The processor 701 implements any of the component selection methods in the above embodiments by reading and executing computer program instructions stored in the memory 702.
[0195] In one example, the electronic device may also include a communication interface 703 and a bus 704. Wherein, as... Figure 7 As shown, the processor 701, memory 702, and communication interface 703 are connected through bus 704 and complete communication with each other.
[0196] The communication interface 703 is mainly used to realize communication between various modules, devices, units and / or equipment in the embodiments of this application.
[0197] Bus 704 includes hardware, software, or both, that couples components of an electronic device together. For example, and not limitingly, the bus may include an Accelerated Graphics Port (AGP) or other graphics bus, an Enhanced Industry Standard Architecture (EISA) bus, a Front Side Bus (FSB), HyperTransport (HT) interconnect, an Industry Standard Architecture (ISA) bus, an Infinite Bandwidth Interconnect, a Low Pin Count (LPC) bus, a memory bus, a Microchannel Architecture (MCA) bus, a Peripheral Component Interconnect (PCI) bus, a PCI-Express (PCI-X) bus, a Serial Advanced Technology Attachment (SATA) bus, a Video Electronics Standards Association Local (VLB) bus, or other suitable buses, or combinations of two or more of these. Where appropriate, bus 704 may include one or more buses. Although specific buses are described and illustrated in embodiments of this application, any suitable bus or interconnect is contemplated herein.
[0198] Furthermore, in conjunction with the component selection methods in the above embodiments, this application embodiment can provide a computer storage medium for implementation. This computer storage medium stores computer program instructions; when these computer program instructions are executed by a processor, they implement any of the component selection methods in the above embodiments.
[0199] In conjunction with the component selection methods in the above embodiments, this application embodiment can provide a computer program product in which the instructions in the computer program product are executed by the processor of an electronic device, causing the electronic device to perform any of the component selection methods in the above embodiments.
[0200] It should be clarified that this application is not limited to the specific configurations and processes described above and shown in the figures. For the sake of brevity, detailed descriptions of known methods are omitted here. In the above embodiments, several specific steps are described and shown as examples. However, the method process of this application is not limited to the specific steps described and shown. Those skilled in the art can make various changes, modifications, and additions, or change the order of steps, after understanding the spirit of this application.
[0201] The functional blocks shown in the above-described structural diagram can be implemented as hardware, software, firmware, or a combination thereof. When implemented in hardware, they can be, for example, electronic circuits, application-specific integrated circuits (ASICs), appropriate firmware, plug-ins, function cards, etc. When implemented in software, the elements of this application are programs or code segments used to perform the required tasks. Programs or code segments can be stored on a machine-readable medium or transmitted over a transmission medium or communication link via data signals carried on a carrier wave. "Machine-readable medium" can include any medium capable of storing or transmitting information. Examples of machine-readable media include electronic circuits, semiconductor memory devices, ROM, flash memory, erasable ROM (EROM), floppy disks, CD-ROMs, optical disks, hard disks, fiber optic media, radio frequency (RF) links, etc. Code segments can be downloaded via computer networks such as the Internet, intranets, etc.
[0202] It should also be noted that the exemplary embodiments mentioned in this application describe methods or systems based on a series of steps or apparatus. However, this application is not limited to the order of the above steps; that is, the steps can be performed in the order mentioned in the embodiments, or in a different order, or several steps can be performed simultaneously.
[0203] The aspects of this disclosure have been described above with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this disclosure. It should be understood that each block in the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing apparatus to produce a machine such that these instructions, executable via the processor of the computer or other programmable data processing apparatus, enable the implementation of the functions / actions specified in one or more blocks of the flowchart illustrations and / or block diagrams. Such a processor can be, but is not limited to, a general-purpose processor, a special-purpose processor, a special application processor, or a field-programmable logic circuit. It is also understood that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can also be implemented by special-purpose hardware performing the specified functions or actions, or can be implemented by a combination of special-purpose hardware and computer instructions.
[0204] The above description is merely a specific implementation of this application. Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, modules, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here. It should be understood that the protection scope of this application is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in this application, and these modifications or substitutions should all be covered within the protection scope of this application.
Claims
1. A method for selecting components, characterized in that, include: The functional description information of the component is obtained from the knowledge graph corresponding to the component, and the functional description information is used to represent the function of the component; Calculate the text similarity between the component to be replaced and the component based on the functional description information; Components whose text similarity is greater than a preset threshold are selected as candidate components.
2. The method according to claim 1, characterized in that, After selecting components with text similarity greater than a preset threshold as candidate components, the method further includes: The candidate components are clustered using a clustering algorithm to obtain a clustered component set; For each component in the clustering component set, a judgment matrix is constructed based on a preset scaling value table and preset indicators. The judgment matrix includes elements representing the relative importance between every two preset indicators. Calculate the eigenvalues of the judgment matrix; The eigenvalues of the judgment matrix are used as the weights of the preset index; Based on the weights, the preset scoring table, and the parameter values of the preset indicators, the comprehensive score of the component is calculated. The component with the highest overall score will be used as the replacement component.
3. The method according to claim 2, characterized in that, The step of constructing the judgment matrix of the component based on a preset scaling value table and preset indicators includes: Obtain the importance value of the preset indicator; For each preset indicator, the importance value of the preset indicator is compared with that of other preset indicators to obtain the comparison result; The judgment matrix is constructed based on the comparison results and the preset scaling value table.
4. The method according to claim 2, characterized in that, The comprehensive score of the component is calculated based on the parameter values of the weights, the preset scoring table, and the preset indicators, including: For each component in the clustering component set, the parameter value of the preset indicator is obtained from the knowledge graph corresponding to the component; Find the preset scoring standard corresponding to the preset indicator in the preset scoring table; The score corresponding to the parameter value of the preset indicator is calculated according to the preset scoring criteria; For each preset indicator, calculate the product of the weight of the preset indicator and the score corresponding to the preset indicator to obtain the target product; The comprehensive score is obtained by summing the products of the objectives corresponding to each preset indicator.
5. The method according to claim 1, characterized in that, Before obtaining the functional description information of the component from the knowledge graph corresponding to the component, the method further includes: Obtain the text information and component code of the component, wherein the text information includes functional description information and comment information; Valid text information is obtained from the text information and the component code, and the valid text information includes parameter values of multiple preset indicators; Based on the annotation information, the calling relationship between methods and functions in the component code is obtained; The functional description information and the valid text information are used as the attribute information of the component, and a knowledge graph corresponding to the component is constructed based on the calling relationship between methods and functions in the component code.
6. The method according to claim 1, characterized in that, The step of calculating the text similarity between the component to be replaced and the component based on the functional description information includes: Extract the keywords corresponding to the components from the functional description information of the components; For each component, the text similarity between the component to be replaced and the component is calculated using the keywords.
7. A component selection device, characterized in that, include: The acquisition module is used to acquire the functional description information of the component from the knowledge graph corresponding to the component, and the functional description information is used to represent the function of the component; The calculation module is used to calculate the text similarity between the component to be replaced and the component based on the functional description information; The determination module is used to select components whose text similarity is greater than a preset threshold as candidate components.
8. An electronic device, characterized in that, The device includes: a processor and a memory storing computer program instructions; When the processor executes the computer program instructions, it implements the component selection method as described in any one of claims 1-6.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer program instructions that, when executed by a processor, implement the component selection method as described in any one of claims 1-6.
10. A computer program product, characterized in that, When the instructions in the computer program product are executed by the processor of the electronic device, the electronic device causes the electronic device to perform the component selection method as described in any one of claims 1-6.