Method and system for identifying source code files into structured data
By converting JavaScript script files into structured data, the problem of JavaScript scripts being difficult to recognize in low-code development platforms is solved, enabling automatic recognition and intuitive display of script content, making it easier for users to use.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- 金现代信息产业股份有限公司
- Filing Date
- 2022-08-19
- Publication Date
- 2026-04-21
AI Technical Summary
In low-code development platforms, JavaScript scripts are difficult to directly identify and use due to their complex comments and syntax.
A method and system are provided to convert JavaScript script files into structured data through format conversion, annotation recognition, and valid content filtering. The process includes obtaining the script file, format conversion, identifying annotation content, deleting invalid content, filtering valid content, and outputting structured data.
It enables automatic recognition and intuitive display of JavaScript script content, simplifies the user's secondary development process, and facilitates the functional expansion of the low-code development platform.
Smart Images

Figure CN115331250B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of script content recognition technology, and in particular to a method and system for recognizing source code files as structured data. Background Technology
[0002] The statements in this section merely refer to the background art related to this invention and do not necessarily constitute prior art.
[0003] In low-code development platform usage scenarios, to expand the platform's secondary development capabilities and meet users' needs for referencing external JavaScript scripts, it's essential to integrate JavaScript, the most popular scripting language on the internet, which can implement more complex business functions. Therefore, integrating user-relevant JavaScript scripts is a necessary feature for product secondary development.
[0004] JavaScript code is a string of characters in Java, making it impossible to directly recognize. Furthermore, JavaScript supports various types of comments; commenting out an entire method disables that method from being used on the web page. The syntax of script comments also increases the difficulty of recognizing JavaScript code. Summary of the Invention
[0005] To address the shortcomings of existing technologies, this invention provides a method and system for recognizing source code files as structured data. Users simply need to place the script in a designated directory, and the system will automatically recognize the script content, displaying the script's methods, parameters, and corresponding descriptions in a list format for intuitive selection and use.
[0006] In a first aspect, the present invention provides a method for recognizing source code files as structured data;
[0007] Methods for recognizing source code files as structured data include:
[0008] Get the JavaScript script file;
[0009] Perform format conversion on the content of JavaScript script files; convert multi-line text into single-line text after format conversion.
[0010] Based on the encoding specifications of JavaScript script files, identify the commented text content in a single line of text; for the identified content, delete the invalid content to obtain the string after removing the invalid content;
[0011] The string after removing invalid content is filtered to extract valid content from the JavaScript script file.
[0012] Filter out structured data from the valid content of JavaScript script files.
[0013] Secondly, this invention provides a system for recognizing source code files as structured data;
[0014] Systems that recognize source code files as structured data include:
[0015] The module is configured to retrieve JavaScript files.
[0016] The format conversion module is configured to: convert the format of the contents of JavaScript script files; and convert multi-line text into single-line text after format conversion.
[0017] The content recognition module is configured to: identify the commented text content in a single line of text according to the encoding specifications of the JavaScript script file; and delete invalid content from the identified content to obtain a string after removing invalid content.
[0018] The valid content filtering module is configured to filter the valid content of the string after removing invalid content, and filter out the valid content of the JavaScript script file.
[0019] The structured data filtering module is configured to filter out structured data from valid content in JavaScript script files.
[0020] Thirdly, the present invention also provides an electronic device, comprising:
[0021] Memory, used for non-transitory storage of computer-readable instructions; and
[0022] Processor, for executing the computer-readable instructions,
[0023] When the computer-readable instructions are executed by the processor, they perform the method described in the first aspect above.
[0024] Fourthly, the present invention also provides a storage medium for non-transitory storage of computer-readable instructions, wherein, when the non-transitory computer-readable instructions are executed by a computer, the instructions for the method described in the first aspect are executed.
[0025] Fifthly, the present invention also provides a computer program product, including a computer program that, when run on one or more processors, is used to implement the method described in the first aspect above.
[0026] Compared with the prior art, the beneficial effects of the present invention are:
[0027] By automatically recognizing JavaScript script content, the methods, parameters, and corresponding comments are displayed in an organized list format, making them easy for users to use intuitively. Attached Figure Description
[0028] The accompanying drawings, which form part of this invention, are used to provide a further understanding of the invention. The illustrative embodiments of the invention and their descriptions are used to explain the invention and do not constitute an improper limitation of the invention.
[0029] Figure 1 This is a flowchart of the method in Example 1. Detailed Implementation
[0030] It should be noted that the following detailed descriptions are exemplary and intended to provide further illustration of the invention. Unless otherwise specified, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains.
[0031] It should be noted that the terminology used herein is for the purpose of describing particular embodiments only and is not intended to limit the exemplary embodiments of the present invention. As used herein, unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. Furthermore, it should be understood that the terms “comprising” and “having”, and any variations thereof, are intended to cover non-exclusive inclusion, for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0032] Where there is no conflict, the embodiments and features in the embodiments of the present invention can be combined with each other.
[0033] All data acquisition in this embodiment is carried out in accordance with laws and regulations and with user consent, and the data is used legally.
[0034] Terminology Explanation:
[0035] JavaScript: Abbreviated as "JS", is a lightweight, interpreted or just-in-time (JIT) programming language with a function-first approach.
[0036] Secondary development: When users use the product, the existing basic functions cannot meet their business needs, so they need to use the product's advanced functions to achieve the desired results. However, some advanced functions require users to have certain programming skills.
[0037] Java: A computer programming language, specifically an object-oriented programming language.
[0038] Example 1
[0039] This embodiment provides a method for recognizing source code files as structured data;
[0040] like Figure 1 As shown, methods for recognizing source code files as structured data include:
[0041] S101: Get the JavaScript script file;
[0042] S102: Perform format conversion on the content of a JavaScript script file; convert the converted multi-line text into single-line text;
[0043] S103: Based on the encoding specifications of JavaScript script files, identify the commented text content in a single line of text; delete invalid content from the identified content to obtain the string after removing invalid content;
[0044] S104: Filter the string after removing invalid content to extract the valid content of the JavaScript script file;
[0045] S105: Filter out structured data from the valid content of JavaScript script files.
[0046] Furthermore, S101: obtaining JavaScript script files specifically refers to traversing the instruction directory and identifying all JavaScript script files by their file extension (.js).
[0047] Furthermore, S102: converting the format of the JavaScript script file means converting the content of the JavaScript script file into a string in UTF-8 encoding format.
[0048] It should be understood that the benefit of format conversion is to unify the encoding format of the file content and prevent the read content from being garbled.
[0049] Further, step S103: Identifying the commented text content in the script according to the encoding specifications of the JavaScript script file; specifically including:
[0050] Identify the explanation of methods based on multi-line comment symbols in a JavaScript script file;
[0051] Identify comments within a method body based on single-line comment symbols in a JavaScript script file;
[0052] Identify code blocks based on the documentation comment symbols in the JavaScript script file.
[0053] It should be understood that, according to the coding standards of JavaScript script files, the commented-out text content in the script should be identified. Script file commenting methods include: multi-line comments " / ** / ", single-line comments " / / ", and documentation comments: / **……* / . Multi-line comments are often used to explain methods, such as method descriptions and parameter descriptions; single-line comments are often used for comments within the method body; and documentation comments are often used for comments within code blocks.
[0054] Further, in S103: the identified content is deleted of invalid content to obtain a string after removing invalid content; wherein, invalid content includes: comments and code blocks within the method body.
[0055] Further, S104: The string after removing invalid content is then filtered for valid content to extract the valid content from the JavaScript script file; specifically including:
[0056] Using Java's regular expressions (regex, also known as rule expressions, is a powerful text matching pattern used to find substrings in a string that match specific rules), and setting the matching rules as follows: (function)(\\s*)(\\S+)(\\((.*?)\\)), the `matcher` method of the `Pattern` object is called to filter out the methods defined in the file. Similarly, the following operations filter out the method descriptions, parameter descriptions, and other content of the methods;
[0057] At the same time, line breaks and space removal are applied to valid content.
[0058] It should be understood that line breaks and spaces should be removed to prevent useless spaces or line breaks from being recognized as valid content.
[0059] Further, in step S105: the valid content of the JavaScript script file is filtered to extract structured data; wherein, the structured data includes method description, detailed method description, and parameter description.
[0060] Based on the @name annotation, filter out the method descriptions from the valid content of the JavaScript script file;
[0061] Based on the @description annotation, the detailed description of the methods is filtered out from the valid content of the JavaScript script file;
[0062] Based on the @param annotation, the parameter descriptions are filtered out from the valid content of the JavaScript script file.
[0063] JavaScript coding standards include several annotations, with commonly used ones including `@name`, `@description`, and `@param`, which respectively describe the method, provide a detailed description of the method, and describe the parameters. Therefore, regex technology and corresponding annotations can be used to identify the relevant content of the corresponding methods. Besides identifying valid methods and parameters in a script, it can also identify descriptions of methods and parameters added by users within the script.
[0064] Furthermore, the method also includes:
[0065] The recognized data will be output according to the set data format.
[0066] Most software programs interact in the form of data, and this solution also uses data interaction. Therefore, developers of low-code development platforms need to define the data format, assemble the recognition results into the defined data format, and then use it interactively.
[0067] Example 2
[0068] This embodiment provides a system for recognizing source code files as structured data;
[0069] Systems that recognize source code files as structured data include:
[0070] The module is configured to retrieve JavaScript files.
[0071] The format conversion module is configured to: convert the format of the contents of JavaScript script files; and convert multi-line text into single-line text after format conversion.
[0072] The content recognition module is configured to: identify the commented text content in a single line of text according to the encoding specifications of the JavaScript script file; and delete invalid content from the identified content to obtain a string after removing invalid content.
[0073] The valid content filtering module is configured to filter the valid content of the string after removing invalid content, and filter out the valid content of the JavaScript script file.
[0074] The structured data filtering module is configured to filter out structured data from valid content in JavaScript script files.
[0075] It should be noted that the acquisition module, format conversion module, content recognition module, effective content filtering module, and structured data filtering module mentioned above correspond to steps S101 to S105 in Embodiment 1. The examples and application scenarios implemented by the above modules and their corresponding steps are the same, but they are not limited to the content disclosed in Embodiment 1. It should be noted that the above modules, as part of the system, can be executed in a computer system such as a set of computer-executable instructions.
[0076] The descriptions of each embodiment in the above embodiments have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.
[0077] The proposed system can be implemented in other ways. For example, the system embodiments described above are merely illustrative, and the division of modules described above is only a logical functional division. In actual implementation, there may be other division methods. For example, multiple modules may be combined or integrated into another system, or some features may be ignored or not executed.
[0078] Example 3
[0079] This embodiment also provides an electronic device, including: one or more processors, one or more memories, and one or more computer programs; wherein, the processor is connected to the memory, and the one or more computer programs are stored in the memory. When the electronic device is running, the processor executes the one or more computer programs stored in the memory to cause the electronic device to perform the method described in Embodiment 1.
[0080] It should be understood that in this embodiment, the processor can be a central processing unit (CPU), or it can be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor, etc.
[0081] Memory may include read-only memory and random access memory, and provides instructions and data to the processor. A portion of memory may also include non-volatile random access memory. For example, memory may also store information about the device type.
[0082] In the implementation process, each step of the above method can be completed by the integrated logic circuits in the processor hardware or by software instructions.
[0083] The method in Embodiment 1 can be directly implemented by a hardware processor, or implemented by a combination of hardware and software modules within the processor. The software modules can reside in readily available storage media in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, or registers. This storage medium is located in memory; the processor reads information from the memory and, in conjunction with its hardware, completes the steps of the above method. To avoid repetition, a detailed description is not provided here.
[0084] Those skilled in the art will recognize that the units and algorithm steps described in connection with the various examples of this embodiment can be implemented in electronic hardware or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this invention.
[0085] Example 4
[0086] This embodiment also provides a computer-readable storage medium for storing computer instructions, which, when executed by a processor, complete the method described in Embodiment 1.
[0087] The above description is merely a preferred embodiment of the present invention and is not intended to limit the invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A method for recognizing source code files as structured data, characterized by: include: Get the JavaScript script file; Perform format conversion on the contents of JavaScript script files; Convert multi-line text with formatting changes into single-line text; Based on the JavaScript script file encoding standards, identify the commented text content in a single line of text, specifically including: Identify the explanation of methods based on multi-line comment symbols in a JavaScript script file; Identify comments within a method body based on single-line comment symbols in a JavaScript script file; Based on the documentation comment symbols of the JavaScript script file, identify the code block; remove invalid content from the identified content to obtain the string after removing invalid content; After removing invalid content, the string is filtered for valid content to extract the valid content from the JavaScript file, specifically including: Using Java's regular expressions (regex) and setting matching rules, the `matcher` method of the `Pattern` object is called to filter out the methods defined in the file. Filter out structured data from the valid content of JavaScript script files.
2. The method for recognizing source code files as structured data as described in claim 1, characterized in that, Retrieving JavaScript script files specifically means traversing the command directory and identifying all JavaScript script files by their file extensions.
3. The method for recognizing source code files as structured data as described in claim 1, characterized in that, Converting the format of a JavaScript file means converting the content of the JavaScript file into a string encoded in UTF-8.
4. The method for recognizing source code files as structured data as described in claim 1, characterized in that, For the identified content, invalid content is removed to obtain the string after invalid content removal; where invalid content includes: comments and code blocks within the method body.
5. The method for recognizing source code files as structured data as described in claim 1, characterized in that, Filter the valid content of JavaScript script files to extract structured data; the structured data includes method descriptions, detailed method descriptions, and parameter descriptions. Based on the @name annotation, filter out the method descriptions from the valid content of the JavaScript script file; Based on the @description annotation, the detailed description of the methods is filtered out from the valid content of the JavaScript script file; Based on the @param annotation, the parameter descriptions are filtered out from the valid content of the JavaScript script file.
6. A system that recognizes source code files as structured data, characterized by: include: The module is configured to retrieve JavaScript files. The format conversion module is configured to: convert the format of the contents of JavaScript script files; and convert multi-line text into single-line text after format conversion. The content recognition module is configured to: identify the commented text content in a single line of text according to the encoding specifications of the JavaScript script file, specifically including: Identify the explanation of methods based on multi-line comment symbols in a JavaScript script file; Identify comments within a method body based on single-line comment symbols in a JavaScript script file; Based on the documentation comment symbols of the JavaScript script file, identify the code block; remove invalid content from the identified content to obtain the string after removing invalid content; The valid content filtering module is configured to filter the valid content of the string after removing invalid content, specifically including: Using Java's regular expressions (regex) and setting matching rules, the `matcher` method of the `Pattern` object is called to filter out the methods defined in the file. The structured data filtering module is configured to filter out structured data from valid content in JavaScript script files.
7. An electronic device, characterized in that it comprises: Memory is used to store computer-readable instructions in a non-transitory manner. as well as Processor, for executing the computer-readable instructions, When the computer-readable instructions are executed by the processor, they perform the method described in any one of claims 1-5.
8. A storage medium, characterized in that, The computer-readable instructions are stored non-transitory, wherein when the non-transitory computer-readable instructions are executed by a computer, the instructions of the method according to any one of claims 1-5 are executed.
Citation Information
Patent Citations
Aviation display control method based on user-defined scripts
CN108132780A
Method and device for extracting structured information of PDF (Portable Document Format) file
CN114510547A