Code positioning method and device, electronic equipment and storage medium

By dividing mixed text into regions and mapping indexes, the problems of formatting failure and low positioning efficiency in existing technologies are solved, realizing intelligent formatting and fast code positioning, thus improving development efficiency.

CN121833468APending Publication Date: 2026-04-10CHINA UNICOM ONLINE INFORMATION TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-26
Publication Date
2026-04-10

AI Technical Summary

Technical Problem

Existing technologies suffer from problems such as formatting failures, semantic errors, and low location efficiency when processing mixed text, especially log records containing both structured and unstructured data, which particularly impacts development efficiency in microservice architectures.

Method used

By dividing mixed text into regions, identifying structured data regions and ordinary text regions, employing configurable formatting processing, and establishing an index mapping relationship between text content and code location, precise and fuzzy matching analysis is achieved to locate the target code.

Benefits of technology

It implements intelligent formatting, preserving the original layout of plain text, and quickly and accurately locating related code, thereby improving development efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121833468A_ABST
    Figure CN121833468A_ABST
Patent Text Reader

Abstract

The invention provides a code positioning method and device, electronic equipment and a storage medium, and relates to the technical field of data processing. The method comprises the following steps of: dividing a structured data region and a common text region of an input mixed text, respectively processing, analyzing a target code library, establishing index mapping between the text and a code position, carrying out query matching based on the mapping, and returning code position information. The problems that in the prior art, formatting fails or semantic errors are caused due to the fact that structured data and unstructured texts cannot be distinguished, and log checking is low in efficiency due to lack of a log exclusive searching and indexing mechanism can be solved. The technical effects that intelligent formatting is achieved, original typesetting of a common text is reserved, and associated codes are rapidly positioned to improve the development efficiency are achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of data processing technology, and in particular to a code location method and apparatus, electronic device and storage medium. Background Technology

[0002] JSON, as an important data exchange format in the software development field, is widely used in scenarios such as logging, configuration management, and front-end / back-end communication. Among related technologies, a hybrid text processing framework has been constructed through the collaborative operation of regular expression matching and stacked bracket matching algorithms. Specifically, this technical system covers the entire process from log collection to code location, including key aspects such as log annotation scanning, JSON region partitioning, and formatting engine adaptation. While the formatting scheme based on the Gson parsing engine has formed a basic technical architecture, existing systems still have significant limitations when processing unstructured logs.

[0003] However, existing JSON formatting methods directly employ a complete structure matching strategy without establishing an intelligent recognition mechanism for mixed text. This can lead to formatting interruptions or damage to the original layout. Specifically, traditional tools, when parsing mixed text containing non-JSON content such as timestamps and thread numbers, lack the ability to segment regions and therefore cannot achieve selective formatting, resulting in distorted log semantics. Furthermore, log code location systems typically rely on manual search and navigation, lacking a multi-stage matching mechanism that incorporates exact matching and the Levenshtein distance algorithm. This leads to low location efficiency and an inability to handle log variations such as parameter changes. This technical deficiency is particularly pronounced in microservice architectures, causing developers to spend significant debugging time on log analysis and impacting overall software development efficiency. Summary of the Invention

[0004] This disclosure provides a code location method and apparatus, electronic device, and storage medium. Its main objective is to at least partially solve one of the technical problems in the related art.

[0005] According to a first aspect of this disclosure, a code location method is provided, comprising: The input mixed text is divided into content regions to identify data regions and ordinary text regions that conform to a preset structured format in the mixed text; Configurable formatting is performed on the structured data area while maintaining the original layout of the plain text area; By parsing the text output statements in the target code library, an index mapping relationship is established between the text content and the corresponding code location; The system receives query text input by the user, performs content matching analysis based on the index mapping relationship, and returns the associated code location information to the user for locating the target code.

[0006] Optionally, the step of dividing the input mixed text into content regions includes: Regular expressions are used to perform preliminary pattern matching on the text to identify candidate regions that conform to the structured data format; The candidate regions are validated using a stack structure to ensure the integrity and legality of their syntax.

[0007] Optionally, performing configurable formatting on the structured data region includes: Generate formatting styles based on user-defined indentation and line break rules; During the formatting process, visual distinguishing markers are added to the structured data area, while all original characters and layouts of the ordinary text area are preserved.

[0008] Optionally, establishing the index mapping relationship between text content and corresponding code positions includes: Scan the code file for text output annotations and extract all text output annotations and their code location information. The extracted text output annotations and the code location information are stored as key-value pairs to form an index database.

[0009] Optionally, the content matching analysis based on the index mapping relationship includes: Perform a full-text exact match search in the indexed database; If no exact match is found, a fuzzy matching mechanism is activated to filter out the code location information that meets the threshold conditions through similarity calculation.

[0010] Optionally, the similarity calculation in the fuzzy matching mechanism adopts the string edit distance algorithm. When the similarity calculation result exceeds a preset threshold, the corresponding code location information is included in the returned result set.

[0011] Optionally, after establishing the index mapping relationship between text content and corresponding code positions, the following may also be included: Establish a change monitoring mechanism for the code repository. When a code file is added, modified, or deleted, an update to the index database is automatically triggered.

[0012] According to a second aspect of this disclosure, a code locating device is provided, comprising: The segmentation unit is used to segment the input mixed text into content regions and identify the data regions and ordinary text regions that conform to a preset structured format in the mixed text. The processing unit is configured to perform configurable formatting on the structured data area while maintaining the original layout of the plain text area. The establishment unit is used to establish an index mapping relationship between text content and corresponding code positions by parsing the text output statements in the target code library; The return unit is used to receive the query text input by the user, perform content matching analysis based on the index mapping relationship, and return the associated code location information to the user for locating the target code.

[0013] Optionally, the partitioning unit is also used for: Regular expressions are used to perform preliminary pattern matching on the text to identify candidate regions that conform to the structured data format; The candidate regions are validated using a stack structure to ensure the integrity and legality of their syntax.

[0014] Optionally, the processing unit is also used for: Generate formatting styles based on user-defined indentation and line break rules; During the formatting process, visual distinguishing markers are added to the structured data area, while all original characters and layouts of the ordinary text area are preserved.

[0015] Optionally, the creation unit is also used for: Scan the code file for text output annotations and extract all text output annotations and their code location information. The extracted text output annotations and the code location information are stored as key-value pairs to form an index database.

[0016] Optionally, the return unit is also used for: Perform a full-text exact match search in the indexed database; If no exact match is found, a fuzzy matching mechanism is activated to filter out the code location information that meets the threshold conditions through similarity calculation.

[0017] Optionally, the similarity calculation in the fuzzy matching mechanism adopts the string edit distance algorithm. When the similarity calculation result exceeds a preset threshold, the corresponding code location information is included in the returned result set.

[0018] Optional, also includes: The update unit is used to establish a change monitoring mechanism for the code library after establishing the index mapping relationship between text content and corresponding code position. When the addition, modification or deletion of code files is detected, the update of the index database is automatically triggered.

[0019] According to a third aspect of this disclosure, an electronic device is provided, comprising: At least one processor; and A memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the method described in the first aspect above.

[0020] According to a fourth aspect of this disclosure, a non-transitory computer-readable storage medium is provided storing computer instructions, wherein the computer instructions are configured to cause the computer to perform the method described in the first aspect above.

[0021] According to a fifth aspect of this disclosure, a computer program product is provided, comprising a computer program that, when executed by a processor, implements the method described in the first aspect above.

[0022] The code location method, apparatus, electronic device, and storage medium disclosed herein divide the input mixed text into structured data regions and ordinary text regions, process and parse them separately, establish an index mapping between text and code locations in the target code library, and perform query matching based on this mapping to return code location information. Therefore, it can solve the problems in the prior art where the inability to distinguish between structured data and unstructured text leads to formatting failure or semantic errors, and the lack of a dedicated log search and indexing mechanism leads to inefficient log investigation. It achieves the technical effect of intelligent formatting while preserving the original layout of ordinary text and quickly locating related code to improve development efficiency.

[0023] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of this disclosure, nor is it intended to limit the scope of this disclosure. Other features of this disclosure will become readily apparent from the following description. Attached Figure Description

[0024] The accompanying drawings are provided to better understand this solution and do not constitute a limitation of this disclosure. Wherein: Figure 1 A flowchart illustrating a code location method provided in an embodiment of this disclosure; Figure 2 This is a schematic diagram of the structure of a code locating device provided in an embodiment of the present disclosure; Figure 3 A schematic block diagram of an example electronic device provided for embodiments of this disclosure. Detailed Implementation

[0025] The exemplary embodiments of this disclosure are described below with reference to the accompanying drawings, including various details of the embodiments to aid understanding, and should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of this disclosure. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.

[0026] The code location method and apparatus, electronic device and storage medium of embodiments of the present disclosure are described below with reference to the accompanying drawings.

[0027] Figure 1 This is a flowchart illustrating a code location method provided in an embodiment of the present disclosure.

[0028] like Figure 1 As shown, the method includes the following steps: Step 101: Divide the input mixed text into content regions and identify the data regions and ordinary text regions that conform to the preset structured format in the mixed text.

[0029] In the embodiments of this disclosure, to address the problem in the prior art where it is difficult to accurately distinguish between structured data regions and ordinary text regions when processing mixed text containing structured data and ordinary text, leading to deviations or failures in subsequent processing operations (such as formatting and analysis), this technical solution performs a content region segmentation operation on the input mixed text: First, a preset structured format judgment standard is determined. This standard can cover various format types with clear data organization rules (not limited to a specific structured format). Then, based on the judgment standard, each part of the mixed text is detected and its features are matched one by one. Finally, the structured data regions in the mixed text that meet the preset structured format judgment standard and the ordinary text regions that do not meet the judgment standard are identified, thus achieving a clear definition of the two types of regions. As one implementation method, the preset structured format can be set to JSON format. In this case, regular expression matching combined with a stacked bracket matching algorithm can be used to process the mixed text, thereby completing the identification and segmentation of JSON structured data regions and non-JSON ordinary text regions.

[0030] It can accurately distinguish between structured data regions and ordinary text regions in mixed text, effectively avoiding subsequent processing deviations caused by the inability to distinguish between the two types of regions. This lays a reliable foundation for carrying out differentiated processing for different types of regions (such as formatting structured data and preserving the original layout of ordinary text), and significantly improves the accuracy and targeting of mixed text processing.

[0031] Step 102: Perform configurable formatting on the structured data area while maintaining the original layout of the ordinary text area.

[0032] In the embodiments of this disclosure, to address the problems in existing technologies where formatting structured data during mixed text processing easily disrupts the layout of ordinary text, or where fixed formatting parameters fail to adapt to diverse needs, this technical solution, after identifying and separating structured data regions and ordinary text regions in mixed text, performs differentiated processing on the two types of regions: For structured data regions, configurable formatting rules are used, which can cover adjustments to core parameters during formatting (such as content indentation specifications, line break logic, etc.) to adapt to the display and reading needs of structured data in different scenarios; for ordinary text regions, no formatting intervention is applied, preserving their original layout (including character order, space distribution, line break positions, etc.) to ensure that the semantic integrity and original presentation state of the ordinary text are not affected. As one implementation method, when the structured data region is in JSON format, the number of indentation spaces and line break methods can be configured through a custom formatter to format the JSON region while maintaining the original text layout of the non-JSON ordinary text region.

[0033] By allowing configurable formatting of structured data areas while preserving the original layout of ordinary text areas, this approach avoids semantic errors or layout chaos caused by the inability to distinguish between the two types of areas in existing technologies. Furthermore, the configurability of formatting parameters meets the diverse needs of different users for structured data display formats, significantly improving the flexibility and accuracy of mixed text processing.

[0034] Step 103: By parsing the text output statements in the target code library, establish an index mapping relationship between the text content and the corresponding code position.

[0035] In the embodiments of this disclosure, to address the problem in the prior art where it is impossible to quickly establish the association between text output content and corresponding code location, leading to low efficiency in subsequent code location based on text content, this technical solution performs specialized processing on the target code library: First, the text output statements contained in the target code library are comprehensively parsed. These text output statements cover various statements used to generate output text in the code library (not limited to specific types of output statements). During the parsing process, the text content information corresponding to the text output statement and the specific code location information of the statement in the target code library (such as the file path, line number, etc.) are extracted simultaneously. Then, based on the extracted text content information and code location information, an index mapping relationship between the two is constructed, forming index data that can be used for subsequent fast query matching. This index mapping relationship can realize the direct association between text content and corresponding code location. As one implementation method, the text output statement can specifically be a log output statement. In this case, the parsing process can scan the classes in the target code library containing log annotations such as @Slf4j and @Log4j, identify the log output statements within them, and simultaneously optimize the identification of inner class log statements by judging whether they contain inner classes, thereby establishing an index mapping between log text content and corresponding code location.

[0036] By parsing the text output statement and establishing an index mapping between text content and code location, the problem of difficulty in locating the code due to the lack of correlation between the two in the existing technology is effectively solved. This provides efficient index support for quickly finding the corresponding code location based on the text content, and significantly improves the efficiency and accuracy of locating the code location from the text content.

[0037] Step 104: Receive the query text input by the user, perform content matching analysis based on the index mapping relationship, and return the associated code location information to the user for locating the target code.

[0038] In the embodiments of this disclosure, to address the problem of inefficiency and insufficient accuracy in locating code positions based on text content in existing technologies due to the lack of query criteria directly related to the text content, this technical solution implements the following processing: First, it receives the query text input by the user for locating the target code. Then, based on a pre-constructed "text content-code position" index mapping relationship, it performs content matching analysis on the query text and the text content stored in the index mapping relationship (the matching analysis can cover various logics such as exact matching and fuzzy matching based on similarity judgment to adapt to the query accuracy requirements in different scenarios). Then, it filters out the code position information corresponding to the text content that matches the query text from the index mapping relationship. Finally, it feeds back the filtered code position information to the user, providing direct guidance for locating the target code. As one implementation method, an exact matching can be performed on the query text first. If no matching result is obtained, the similarity between the query text and the text content in the index is calculated using a specific algorithm, and only the code position information corresponding to the text content with a similarity reaching a preset threshold is returned to the user.

[0039] It effectively solves the problem of low code search efficiency caused by the lack of a dedicated text-code location mechanism in existing technologies. It can quickly complete the association and matching of query text and code location based on the preset index mapping relationship, accurately return the target code location information, significantly improve the efficiency of users to locate target code, and reduce the time cost in the code location process.

[0040] The code location method disclosed herein divides the input mixed text into structured data regions and ordinary text regions, processes and parses them separately, establishes an index mapping between text and code locations in the target code library, and performs query matching based on this mapping to return code location information. Therefore, it can solve the problems in the prior art where the inability to distinguish between structured data and unstructured text leads to formatting failures or semantic errors, and the lack of a dedicated log search and indexing mechanism leads to inefficient log investigation. It achieves the technical effect of intelligent formatting while preserving the original layout of ordinary text and quickly locating related code to improve development efficiency.

[0041] As a specific implementation of this disclosure, based on the basic scheme, the content region segmentation of the input mixed text is further defined as follows: using regular expressions to perform preliminary pattern matching on the text to identify candidate regions that conform to the structured data format; and using a stack structure to perform nested hierarchical verification on the candidate regions to ensure the integrity and legality of their syntactic structure.

[0042] Specifically, when dividing the input mixed text into content regions, regular expressions are first used to perform preliminary pattern matching: based on the typical format features of structured data (such as JSON), a regular expression is constructed that includes structured data start markers (such as "{" and "["), end markers (such as "}" and "]") and key-value pair separators (such as ":" and ","). The mixed text is scanned segment by segment using this regular expression to filter out segments that contain the above feature markers and may conform to the structured data format as candidate regions, and ordinary text segments without structured features are initially excluded. Then, a stack structure is used to verify the nesting level of the candidate regions: an empty stack is initialized, and the contents of the candidate regions are traversed character by character. When a left nested symbol ("{" or "[") is encountered, the symbol is pushed onto the stack and its position is recorded. When a right nested symbol ("}" or "]") is encountered, if the stack is not empty and the symbol at the top of the stack is the corresponding left nested symbol ("}" corresponds to "{", "]" corresponds to "["), then the symbol at the top of the stack is popped. If the stack is empty or the symbol at the top of the stack does not match, then the candidate region is determined to have an incomplete syntax structure. After the traversal is completed, only the candidate regions with empty stacks are retained to confirm that their syntax structure is complete and valid, and these are used as the finally identified structured data regions.

[0043] By combining "preliminary regular expression matching + stack structure hierarchical verification", we can quickly identify potential structured regions by leveraging the efficiency of regular expressions and avoiding the efficiency loss of complex full-text verification. At the same time, we can accurately verify the legality of nested levels through stack structure, effectively eliminate pseudo-structured fragments with incomplete syntax, significantly improve the accuracy and reliability of structured data region identification, and provide a precise region division basis for subsequent differential processing.

[0044] As a specific implementation of this disclosure, based on the basic solution, the configurable formatting process performed on the structured data area is further defined, including: generating a formatting style according to the user-defined indentation size and line break rules; adding visual distinguishing marks to the structured data area during the formatting process, while retaining all the original characters and layout of the ordinary text area.

[0045] Specifically, when performing configurable formatting on a structured data area, the system first obtains the formatting parameters preset by the user. The indentation size can be selected by the user (such as 2 spaces, 4 spaces, or 1 tab). The line break rules can be set to force line breaks after key-value pair separation, automatically break lines when nesting levels are progressive, and break lines one by one for array elements. Based on these parameters, the system generates a custom formatting style through a custom formatter. This formatter does not depend on external libraries and ensures the accuracy of style application only by recording the character position range of each key-value pair within the structured data area. During the formatting process, relying on the constructed tree data structure (used to store key-value pairs and their position offsets), and combining the IDE's editor interaction components with the source code structured access capabilities provided by the PSI tree interface, visual distinguishing markers are added to the structured data area—specifically, the key name part can be rendered in blue, the value part in green (or other user-customizable color combinations). At the same time, no formatting adjustments are made to the ordinary text area, and all its original characters (including spaces, special symbols, comment text, etc.) and original layout (such as line break positions, paragraph spacing, etc.) are completely preserved, ensuring that the semantic integrity and presentation of the ordinary text are not affected by the structured data formatting operation.

[0046] The user-configurable indentation and line break rules meet the personalized needs of different developers for the display of structured data; the addition of visual distinguishing markers, combined with precise positioning, makes the boundary between structured data areas and ordinary text areas clearer, improving the readability of mixed text; and the complete preservation of the original characters and layout of ordinary text completely avoids semantic errors in unstructured content caused by formatting operations, further ensuring the accuracy of mixed text processing.

[0047] As a specific implementation of this disclosure, based on the basic scheme, the establishment of the index mapping relationship between text content and corresponding code position is further defined as follows: scanning the text output annotations contained in the code file, extracting all text output annotations and their code position information in the code; storing the extracted text output annotations and the code position information as a key-value pair structure to form an index database.

[0048] Specifically, when establishing the index mapping relationship between text content and corresponding code locations, the scanning process is initiated during the project loading phase. A background thread of the system traverses and scans all code files in the target code library, focusing on capturing text output annotations contained in the code files. These text output annotations specifically cover annotation types commonly used to identify log output functions, such as @Slf4j and @Log4j. During the scanning process, in addition to extracting the basic information of the above-mentioned text output annotations, the code location details corresponding to each annotation are also collected simultaneously, including the complete path of the code file, the name of the class to which it belongs (including the name of the inner class), and the specific line number in the file. At the same time, by adding a judgment logic of "whether it contains an inner class", text output annotations contained in inner classes are specifically identified to avoid annotation omissions caused by failure to distinguish between inner and outer classes. After the scan is completed, the extracted text output annotations (and the text output content features associated with the annotations) are used as "keys", and the corresponding code location information (file path, class name, line number) are used as "values" to construct a one-to-one key-value pair data structure. All key-value pairs are summarized and stored to form an index database that supports fast querying.

[0049] By targeting and scanning text output annotations and combining them with inner class judgment optimization, the system effectively avoids omissions in the recognition of text output annotations in inner classes, ensuring the comprehensiveness of the index data coverage. The key-value pair structured index database enables direct association between text content and code location, significantly shortening the data retrieval time during subsequent matching queries and providing accurate data support for efficient code location.

[0050] As a specific implementation of this disclosure, based on the basic scheme, the content matching analysis based on the index mapping relationship is further defined as follows: performing full-text precise matching search in the index database; if no complete match is found, a fuzzy matching mechanism is activated to filter out the code location information that meets the threshold conditions through similarity calculation.

[0051] Specifically, when performing content matching analysis based on the index mapping relationship, the query text input by the user is used as the basis. In the index database storing text output annotations and corresponding code position key-value pairs, a full-text exact match search is performed on the index key (i.e., the text content associated with the text output annotation). The query text and the content of the index key are compared character by character. If an index key with a completely identical character sequence exists, the code position information (such as file path, class name, line number) mapped by that index key is directly extracted as the matching result. If no completely matching index item is found after the exact match search, a fuzzy matching mechanism is immediately activated: the Levenshtein distance algorithm is used to calculate the edit distance between the query text and each index key in the index database. The similarity value between the two is obtained by converting the edit distance and the total length of the text. Then, index keys with a similarity value greater than a preset threshold of 0.6 are selected. The code position information corresponding to these index keys that meet the threshold condition is further extracted to form the final fuzzy matching result.

[0052] The "exact match priority" approach ensures the efficiency and accuracy of code location in scenarios with no input bias, avoiding unnecessary calculations. Meanwhile, the Levenshtein distance algorithm combined with threshold-based fuzzy matching effectively covers scenarios where there are subtle differences in the query text (such as missing characters or character order deviations). This not only eliminates invalid results with low similarity but also avoids location failures caused by minor input errors, significantly improving the applicability and success rate of content matching analysis.

[0053] As a specific implementation of this disclosure, based on the basic scheme, the similarity calculation in the fuzzy matching mechanism is further limited to a string edit distance algorithm. When the similarity calculation result exceeds a preset threshold, the corresponding code location information is included in the returned result set.

[0054] Specifically, when performing similarity calculation in the fuzzy matching mechanism, the query text input by the user and the index keys stored in the index database (i.e., the text content associated with the text output annotations) are first preprocessed to remove irrelevant and interfering information that may be contained in the query text (such as thread numbers and timestamps in logs), ensuring that the text content involved in the calculation focuses on the core and effective information. Then, a string edit distance algorithm (specifically the Levenshtein distance algorithm) is used to calculate the similarity. This algorithm obtains the edit distance between the two by statistically analyzing the minimum number of character insertion, deletion, and replacement operations required to convert the query text into an index key. Then, the edit distance is converted into the total character length of the longer text in the two texts to obtain a similarity value that represents the degree of text similarity (the smaller the edit distance, the higher the similarity value). At the same time, a similarity threshold (such as 0.6) is preset, and the calculated similarity value is compared with this threshold. If the similarity calculation result exceeds the preset threshold, it is determined that the code location information corresponding to the index key is related to the query requirement, and it is included in the returned result set for subsequent feedback to the user for locating the target code.

[0055] The Levenshtein distance algorithm can accurately quantify the similarity between the query text and the index key, avoiding the bias caused by subjective judgment in fuzzy matching. The preset threshold setting can effectively filter irrelevant code location information with low similarity, reduce the interference of invalid results to users, and cover scenarios where there are slight input errors in the query text (such as missing or mistyped single characters), ensuring the relevance and usability of the matching results, and further improving the success rate of code location.

[0056] As a specific implementation of this disclosure, based on the basic solution, it is further limited to establishing an index mapping relationship between text content and corresponding code location, and then establishing a change monitoring mechanism for the code library. When a code file is added, modified, or deleted, an update to the index database is automatically triggered.

[0057] Specifically, to address the inefficiencies of existing technologies where index data easily becomes outdated after code changes and requires manual refreshing, this technical solution initiates a continuous dynamic index maintenance mechanism after the initial index construction. The core of this mechanism is the establishment of a multi-source change monitoring mechanism, which includes two levels of monitoring: First, a monitoring mechanism based on the Virtual File System (VFS) of the Integrated Development Environment (IDE), capable of detecting underlying change events such as file creation, deletion, and movement within the project directory structure; second, a monitoring mechanism combined with the editor document monitoring mechanism, capturing in real-time changes to the specific content of code documents opened, modified, and saved by the user in the IDE editor. Through the collaboration of these two monitoring channels, the system can comprehensively and reliably capture code file change events. To avoid frequent invalid index rebuilds due to high-frequency, fragmented change operations (such as continuous input), this solution introduces a background task scheduling system (such as an alarm-based delayed task) to delay and merge multiple change events captured within a short period, and then uniformly schedule and execute update tasks after the code editing activity has stabilized. When performing an update, the system calls the index update logic, locates the specific code file affected by the change event, and performs incremental index updates (such as updating, inserting or deleting corresponding key-value pairs) only on the text output statements involved in that file, instead of rebuilding the index of the entire project, thereby maintaining the real-time performance of the index database with extremely low overhead.

[0058] Furthermore, in addition to the basic solution, the steps to detect project branch switching in order to maintain index accuracy are further defined.

[0059] Specifically, in software development projects that support version control (such as Git), developers frequently switch between different functional branches, and the code status (including log output statements) of each branch may differ. To address the issue of index mismatch caused by branch switching, this technical solution adds branch switching awareness and index reconstruction capabilities. This step specifically includes: monitoring changes to the branch pointer file in the version control system (e.g., monitoring changes to the content of the .git / HEAD file), and / or periodically checking the branch to which the current project belongs (by polling using the version control plugin API). When a branch switching event is detected, the system immediately triggers a full scan of the codebase for the new branch to rebuild the index mapping relationship. This full scan process specifically includes: first, clearing or marking the original index database as expired to prevent querying the wrong branch code location; then, based on the aforementioned method for establishing the index mapping relationship (such as scanning annotations like @Slf4j), rescanning the code files under the new branch, extracting text output annotations and code location information, and building a new index database. This mechanism ensures that no matter which branch a developer switches to, the index data relied upon by the log-code location function is always strictly synchronized with the code state of the currently active branch, guaranteeing the absolute accuracy of the location results.

[0060] By introducing the aforementioned dynamic index update and branch-aware reconstruction mechanism, this technical solution effectively addresses the pain points of static and easily outdated indexes in traditional solutions, achieving "real-time awareness, accurate updates, and seamless switching" of index data. This significantly improves the practicality and reliability of the system in agile development and continuous integration environments, and further consolidates the core technical effect of quickly locating related code to improve development efficiency.

[0061] It should be noted that the embodiments of this disclosure may include multiple steps. For ease of description, these steps are numbered, but these numbers are not a limitation on the execution time slots or execution order between the steps; these steps can be implemented in any order, and the embodiments of this disclosure do not limit this.

[0062] Corresponding to the code location method described above, this disclosure also proposes a code location device. Since the device embodiments of this disclosure correspond to the method embodiments described above, details not disclosed in the device embodiments can be referred to the method embodiments described above, and will not be repeated here.

[0063] Figure 2 This is a schematic diagram of the structure of a code locating device provided in an embodiment of this disclosure, as shown below. Figure 2 As shown, it includes: The segmentation unit 21 is used to segment the input mixed text into content regions and identify the data regions and ordinary text regions that conform to a preset structured format in the mixed text. Processing unit 22 is configured to perform configurable formatting on the structured data area while maintaining the original layout of the ordinary text area. Unit 23 is established to establish an index mapping relationship between text content and corresponding code position by parsing the text output statements in the target code library; The return unit 24 is used to receive the query text input by the user, perform content matching analysis based on the index mapping relationship, and return the associated code location information to the user for locating the target code.

[0064] The code location device disclosed herein divides the input mixed text into structured data regions and ordinary text regions, processes and parses them separately, establishes an index mapping between text and code locations in the target code library, performs query matching based on this mapping, and returns code location information. Therefore, it can solve the problems in the prior art where the inability to distinguish between structured data and unstructured text leads to formatting failures or semantic errors, and the lack of a dedicated log search and indexing mechanism leads to inefficient log investigation. It achieves the technical effect of intelligent formatting while preserving the original layout of ordinary text and quickly locating related code to improve development efficiency.

[0065] Furthermore, in one possible implementation of this embodiment, the partitioning unit 21 is also used for: Regular expressions are used to perform preliminary pattern matching on the text to identify candidate regions that conform to the structured data format; The candidate regions are validated using a stack structure to ensure the integrity and legality of their syntax.

[0066] Furthermore, in one possible implementation of this embodiment, the processing unit 22 is further configured to: Generate formatting styles based on user-defined indentation and line break rules; During the formatting process, visual distinguishing markers are added to the structured data area, while all original characters and layouts of the ordinary text area are preserved.

[0067] Furthermore, in one possible implementation of this embodiment, the establishing unit 23 is also used for: Scan the code file for text output annotations and extract all text output annotations and their code location information. The extracted text output annotations and the code location information are stored as key-value pairs to form an index database.

[0068] Furthermore, in one possible implementation of this embodiment, the return unit 24 is also used for: Perform a full-text exact match search in the indexed database; If no exact match is found, a fuzzy matching mechanism is activated to filter out the code location information that meets the threshold conditions through similarity calculation.

[0069] Furthermore, in one possible implementation of this embodiment, the similarity calculation in the fuzzy matching mechanism adopts a string edit distance algorithm. When the similarity calculation result exceeds a preset threshold, the corresponding code location information is included in the returned result set.

[0070] Furthermore, in one possible implementation of this embodiment, it also includes: The update unit 25 is used to establish a change monitoring mechanism for the code library after establishing the index mapping relationship between text content and corresponding code position. When the addition, modification or deletion of code files is detected, the update of the index database is automatically triggered.

[0071] It should be noted that the foregoing explanation of the method embodiments also applies to the apparatus of this embodiment, and the principle is the same, so it is not limited in this embodiment.

[0072] According to embodiments of this disclosure, this disclosure also provides an electronic device, a readable storage medium, and a computer program product.

[0073] Figure 3 A schematic block diagram of an example electronic device 300 that can be used to implement embodiments of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the present disclosure described and / or claimed herein.

[0074] like Figure 3 As shown, the electronic device 300 includes a computing unit 301, which can perform various appropriate actions and processes based on a computer program stored in ROM (Read-Only Memory) 302 or a computer program loaded from storage unit 308 into RAM (Random Access Memory) 303. The RAM 303 may also store various programs and data required for the operation of the electronic device 300. The computing unit 301, ROM 302, and RAM 303 are interconnected via a bus 304. An I / O (Input / Output) interface 305 is also connected to the bus 304.

[0075] Multiple components in electronic device 300 are connected to I / O interface 305, including: input unit 306, such as keyboard, mouse, etc.; output unit 307, such as various types of displays, speakers, etc.; storage unit 308, such as disk, optical disk, etc.; and communication unit 309, such as network card, modem, wireless transceiver, etc. Communication unit 309 allows electronic device 300 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.

[0076] The computing unit 301 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 301 include, but are not limited to, CPUs (Central Processing Units), GPUs (Graphics Processing Units), various special-purpose AI (Artificial Intelligence) computing chips, various computing units running machine learning model algorithms, DSPs (Digital Signal Processors), and any suitable processor, controller, microcontroller, etc. The computing unit 301 performs the various methods and processes described above, such as code location methods. For example, in some embodiments, the code location method may be implemented as a computer software program tangibly contained in a machine-readable medium, such as storage unit 308. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 300 via ROM 302 and / or communication unit 309. When the computer program is loaded into RAM 303 and executed by the computing unit 301, one or more steps of the methods described above may be performed. Alternatively, in other embodiments, the computing unit 301 may be configured to perform the aforementioned code location method by any other suitable means (e.g., by means of firmware).

[0077] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, FPGAs (Field Programmable Gate Arrays), ASICs (Application-Specific Integrated Circuits), ASSPs (Application-Specific Standard Products), SOCs (System-on-Chips), CPLDs (Complex Programmable Logic Devices), computer hardware, firmware, software, and / or combinations thereof. These various implementations may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.

[0078] The program code used to implement the methods of this disclosure may be written in any combination of one or more programming languages. This program code may be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing apparatus, such that when executed by the processor or controller, the program code causes the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The program code may be executed entirely on a machine, partially on a machine, as a standalone software package partially on a machine and partially on a remote machine, or entirely on a remote machine or server.

[0079] In the context of this disclosure, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, RAM, ROM, EPROM (Electrically Programmable Read-Only Memory) or flash memory, optical fiber, CD-ROM (Compact Disc Read-Only Memory), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.

[0080] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device for displaying information to the user (e.g., a CRT (Cathode-Ray Tube) or LCD (Liquid Crystal Display) monitor); and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the computer. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).

[0081] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or computing systems that include middleware components (e.g., application servers), or computing systems that include frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include LANs (Local Area Networks), WANs (Wide Area Networks), the Internet, and blockchain networks.

[0082] Computer systems can include clients and servers. Clients and servers are generally geographically separated and typically interact via communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. A server can be a cloud server, also known as a cloud computing server or cloud host, a hosting product within the cloud computing service system that addresses the shortcomings of traditional physical hosts and VPS (Virtual Private Server) services, such as high management difficulty and weak business scalability. Servers can also be servers for distributed systems or servers incorporating blockchain technology.

[0083] It's important to note that artificial intelligence (AI) is the study of enabling computers to simulate certain human thought processes and intelligent behaviors (such as learning, reasoning, thinking, and planning). It encompasses both hardware and software technologies. AI hardware technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, and big data processing. AI software technologies primarily include computer vision, speech recognition, natural language processing, machine learning / deep learning, big data processing, and knowledge graph technologies.

[0084] The various numerical designations such as "first," "second," etc., used in this disclosure are merely for ease of description and are not intended to limit the scope of the embodiments of this disclosure, nor do they indicate a sequential order.

[0085] At least one of the features described in this disclosure can also be described as one or more, and multiple features can be two, three, four or more, and this disclosure does not impose any limitations. In the embodiments of this disclosure, for a technical feature, the technical features in that technical feature are distinguished by "first", "second", "third", "A", "B", "C" and "D", etc., and there is no sequential order or size order among the technical features described by "first", "second", "third", "A", "B", "C" and "D".

[0086] It should be understood that the various forms of processes shown above can be used to rearrange, add, or delete steps. For example, the steps described in this disclosure can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution disclosed in this disclosure can be achieved, and this is not limited herein.

[0087] The specific embodiments described above do not constitute a limitation on the scope of protection of this disclosure. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this disclosure should be included within the scope of protection of this disclosure.

Claims

1. A code location method, characterized in that, include: The input mixed text is divided into content regions to identify data regions and ordinary text regions that conform to a preset structured format in the mixed text; Configurable formatting is performed on the structured data area while maintaining the original layout of the plain text area; By parsing the text output statements in the target code library, an index mapping relationship is established between the text content and the corresponding code location; The system receives query text input by the user, performs content matching analysis based on the index mapping relationship, and returns the associated code location information to the user for locating the target code.

2. The method according to claim 1, characterized in that, The process of dividing the input mixed text into content regions includes: Regular expressions are used to perform preliminary pattern matching on the text to identify candidate regions that conform to the structured data format; The candidate regions are validated using a stack structure to ensure the integrity and legality of their syntax.

3. The method according to claim 1, characterized in that, The configurable formatting process performed on the structured data region includes: Generate formatting styles based on user-defined indentation and line break rules; During the formatting process, visual distinguishing markers are added to the structured data area, while all original characters and layouts of the ordinary text area are preserved.

4. The method according to claim 1, characterized in that, The process of establishing an index mapping relationship between text content and corresponding code positions includes: Scan the code file for text output annotations and extract all text output annotations and their code location information. The extracted text output annotations and the code location information are stored as key-value pairs to form an index database.

5. The method according to claim 1, characterized in that, The content matching analysis based on the index mapping relationship includes: Perform a full-text exact match search in the indexed database; If no exact match is found, a fuzzy matching mechanism is activated to filter out the code location information that meets the threshold conditions through similarity calculation.

6. The method according to claim 5, characterized in that, The similarity calculation in the fuzzy matching mechanism adopts the string edit distance algorithm. When the similarity calculation result exceeds the preset threshold, the corresponding code location information is included in the returned result set.

7. The method according to claim 4, characterized in that, After establishing the index mapping relationship between text content and corresponding code locations, it also includes: Establish a change monitoring mechanism for the code repository. When a code file is added, modified, or deleted, an update to the index database is automatically triggered.

8. A code positioning device, characterized in that, include: The segmentation unit is used to segment the input mixed text into content regions and identify the data regions and ordinary text regions that conform to a preset structured format in the mixed text. The processing unit is configured to perform configurable formatting on the structured data area while maintaining the original layout of the plain text area. The establishment unit is used to establish an index mapping relationship between text content and corresponding code positions by parsing the text output statements in the target code library; The return unit is used to receive the query text input by the user, perform content matching analysis based on the index mapping relationship, and return the associated code location information to the user for locating the target code.

9. An electronic device, characterized in that, include: At least one processor; as well as A memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-7.

10. A non-transitory computer-readable storage medium storing computer instructions, characterized in that, The computer instructions are used to cause the computer to perform the method according to any one of claims 1-7.