Linear text stream serialization method, apparatus and storage medium
By generating an ASCII directory structure diagram and using strong delimiters to standardize and encapsulate file content, the problems of illusion and logic recognition errors in large model-assisted programming are solved, and the structured, ordered, and traceable linear text stream serialization of engineering projects is realized.
Patent Information
- Application Number
- CN202611177552.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-04
- Publication Date
- 2026-11-24
AI Technical Summary
In existing technologies, large model-assisted programming is prone to illusions and logical recognition errors. This is mainly because the three-dimensional structural features of engineering projects are lost due to the flattening of structural semantics during cloud-based reasoning and computation, making it difficult for the model to distinguish the boundaries of the modules to which the code belongs and the boundaries of nested directories.
By generating an ASCII directory structure diagram, setting the unique identifier and file size of the target file to form a directory index area, and using strong delimiters to standardize and encapsulate the file content, a cross-regional logical index relationship is established between the directory index area and the file content area. Finally, the directory index area is placed at the beginning and the file content area is placed at the end for linear concatenation to form the target linear text stream.
It achieves precise association between file content and topological location during large model-assisted programming, solves the problems of illusion and logical recognition errors, and ensures the structured, ordered and traceable nature of model input.
Smart Images

Figure CN123157181A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of large language model applications, and in particular to linear text stream serialization methods, apparatus and storage media. Background Technology
[0002] With the rapid development of technologies such as large-scale model-assisted programming, long-context code understanding, and enhanced code retrieval, utilizing cloud-based large-scale models to perform local engineering code analysis, code completion, defect detection, and logic refactoring has become a mainstream R&D support solution. In practical implementation, it is necessary to submit local structured and hierarchical engineering project code in batches to cloud-based large-scale models for inference calculations.
[0003] Currently, existing code input methods for cloud computing generally adopt a simple linear concatenation strategy of file content, which leads to a "flattening loss" of structural semantics between the three-dimensional structured features of engineering projects and the linear text input form required by large models. When the engineering project is an extremely long text sequence, it is also easy to cause problems such as model reasoning illusion and logical recognition errors.
[0004] There is currently no effective solution to the problem of hallucinations and logical recognition errors that can easily occur during large-model-assisted programming in related technologies. Summary of the Invention
[0005] This embodiment provides a linear text stream serialization method, apparatus, and storage medium to address the problems of illusion and logical recognition errors that are easily generated during large model-assisted programming in related technologies.
[0006] Firstly, this embodiment provides a linear text stream serialization method, including:
[0007] Iterate through the pre-selected set of target files to generate an ASCII directory structure diagram;
[0008] In each leaf node of the ASCII directory structure diagram, a unique identifier and file size of each target file are set to form a directory index area;
[0009] The content of each target file and its unique identifier are standardized and encapsulated using a preset strong delimiter to form a file content area; wherein, the preset strong delimiter is a symbol used to define the start and end positions of the target file;
[0010] Based on the unique identifier of each target file, a one-to-one cross-regional logical index relationship is established between the directory index area and the file content area;
[0011] Based on the index relationship, the directory index area is placed at the beginning and the file content area is placed at the end for linear concatenation to obtain the target linear text stream.
[0012] In some embodiments, setting a unique identifier and file size for each target file in each leaf node of the ASCII directory structure graph to form a directory index area includes:
[0013] Based on the pre-selected set of target files, a target file sequence table is constructed, wherein the file sequence table includes the file size of each target file and the unique identifier of each target file;
[0014] Obtain the unique identifier of each target file and the file size of each target file from the target file sequence list;
[0015] The unique identifier and file size of each target file are set in each leaf node of the ASCII directory structure diagram to form a directory index area.
[0016] In some embodiments, the standardization and encapsulation of the content of each target file and the unique identifier of each target file using a preset strong delimiter to form a file content area includes:
[0017] Read the file size and unique identifier of each target file from the target file sequence list;
[0018] Determine whether the file size of each target file is greater than a preset file threshold;
[0019] If so, then a placeholder is generated based on the target file, and the text content of the target file is replaced by the placeholder; otherwise, the text content of the target file is obtained.
[0020] The placeholders and / or text content of each target file and its unique identifier are encapsulated using a preset strong delimiter to form the file content area.
[0021] In some embodiments, the process of encapsulating the placeholders and / or text content of each target file with a preset strong delimiter to form the file content area includes:
[0022] For a single target file, the preset strong delimiter is set at the beginning of the target file;
[0023] Placeholders for the target file and / or the text content of the target file are set in the body of the target file;
[0024] The preset strong delimiter is set at the end of the target file to obtain the encapsulation structure of the single target file;
[0025] The encapsulation structures of each individual target file are sequentially assembled to form the file content area.
[0026] In some embodiments, prior to traversing the preselected set of target files, the method further includes:
[0027] Obtain an initial file set, traverse the initial file set, and generate an initial ASCII directory structure diagram, wherein each initial file in the initial file set is a candidate file in the initial ASCII directory structure diagram;
[0028] The target file is selected from the initial ASCII directory structure diagram to obtain the pre-selected target file set.
[0029] In some embodiments, selecting target files from the initial ASCII directory structure graph to obtain the pre-selected set of target files includes:
[0030] Obtain the selected initial target file set from the initial ASCII directory structure diagram, and filter each initial target file in the initial target file set according to a preset filtering strategy to obtain the pre-selected target file set.
[0031] In some embodiments, traversing the preselected set of target files to generate an ASCII directory structure graph includes:
[0032] The pre-selected set of target files is traversed, and the ASCII directory structure diagram is generated using a recursive algorithm.
[0033] In some embodiments, the target linear text stream includes the file paths of each target file, and the receiving end uses the file paths of each target file to reconstruct the original folder structure of each target file.
[0034] Secondly, this embodiment provides a linear text stream serialization device, including: a directory index area construction module, a file content area construction module, and a linear stream synthesis module;
[0035] The directory index area construction module is used to traverse the pre-selected set of target files and generate an ASCII directory structure diagram; in each leaf node of the ASCII directory structure diagram, a unique identifier and file size of each target file are set to form a directory index area.
[0036] The file content area construction module is used to standardize and encapsulate the content of each target file and the unique identifier of each target file using a preset strong delimiter to form a file content area; wherein, the preset strong delimiter is a symbol used to define the start and end positions of the target file;
[0037] The linear stream synthesis module is used to establish a one-to-one cross-regional logical index relationship between the directory index area and the file content area based on the unique identifier of each target file; and to perform linear concatenation by placing the directory index area at the beginning and the file content area at the end according to the index relationship to obtain the target linear text stream.
[0038] Thirdly, this embodiment provides a storage medium storing a computer program that, when executed by a processor, implements the linear text stream serialization method described in the first aspect above.
[0039] Compared with related technologies, the linear text stream serialization method provided in this embodiment generates an ASCII directory structure diagram by traversing a pre-selected set of target files; in each leaf node of the ASCII directory structure diagram, a unique identifier and file size of each target file are set to form a directory index area; the content and unique identifier of each target file are standardized and encapsulated using a preset strong delimiter to form a file content area; wherein, the preset strong delimiter is a symbol used to limit the start and end positions of the target files; based on the unique identifier of each target file, a one-to-one cross-region logical index relationship is established between the directory index area and the file content area; according to the index relationship, the directory index area is placed at the beginning and the file content area is placed at the end for linear concatenation to obtain the target linear text stream, which solves the problem of illusion and logical recognition errors that are easy to occur in the process of large model-assisted programming.
[0040] Details of one or more embodiments of this application are set forth in the following drawings and description to make other features, objects and advantages of this application more readily apparent. Attached Figure Description
[0041] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings:
[0042] Figure 1 This is a hardware structure block diagram of the terminal for the linear text stream serialization method in this embodiment.
[0043] Figure 2 This is a flowchart of the linear text stream serialization method in this embodiment.
[0044] Figure 3 This is a GUI interface and a schematic diagram of the serialization result of the linear text stream serialization method in this embodiment.
[0045] Figure 4This is a flowchart of another linear text stream serialization method in this embodiment.
[0046] Figure 5 This is a diagram of an example of a linear text stream output by the linear text stream serialization method implemented in this paper.
[0047] Figure 6 This is a structural block diagram of the linear text stream serialization device in this embodiment. Detailed Implementation
[0048] To better understand the purpose, technical solution, and advantages of this application, the application is described and explained below in conjunction with the accompanying drawings and embodiments.
[0049] Unless otherwise defined, the technical or scientific terms used in this application shall have the general meaning understood by a person skilled in the art to which this application pertains. Words such as “a,” “an,” “an,” “the,” “the,” and “these” used in this application do not indicate quantitative limitation and may be singular or plural. The terms “comprising,” “including,” “having,” and any variations thereof used in this application are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or device that comprises a series of steps or modules (units) is not limited to the listed steps or modules (units) but may include steps or modules (units) not listed, or may include other steps or modules (units) inherent to these processes, methods, products, or devices. Words such as “connected,” “linked,” and “coupled” used in this application are not limited to physical or mechanical connections but may include electrical connections, whether direct or indirect. “Multiple” used in this application refers to two or more. “And / or” describes the relationship between related objects, indicating that three relationships may exist; for example, “A and / or B” can represent: A alone, A and B simultaneously, or B alone. Normally, the character " / " indicates that the objects before and after it are in an "or" relationship. The terms "first," "second," "third," etc., used in this application are merely to distinguish similar objects and do not represent a specific order of objects.
[0050] The method embodiments provided in this example can be executed on a terminal, computer, or similar computing device. For example, it can run on a terminal. Figure 1 This is a hardware structure block diagram of the terminal for the linear text stream serialization method in this embodiment. For example... Figure 1 As shown, a terminal may include one or more ( Figure 1Only one is shown in the diagram. A processor 102 and a memory 104 for storing data are also included. The processor 102 may be, but is not limited to, a microprocessor (MCU) or a programmable logic device (FPGA). The terminal may also include a transmission device 106 for communication functions and an input / output device 108. Those skilled in the art will understand that… Figure 1 The structure shown is for illustrative purposes only and does not limit the structure of the terminal described above. For example, the terminal may also include components that are larger than... Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown are illustrated.
[0051] The memory 104 can be used to store computer programs, such as application software programs and modules, like the computer program corresponding to the linear text stream serialization method in this embodiment. The processor 102 executes various functional applications and data processing by running the computer programs stored in the memory 104, thereby implementing the aforementioned method. The memory 104 may include high-speed random access memory and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include memory remotely located relative to the processor 102, and these remote memories can be connected to the terminal via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0052] The transmission device 106 is used to receive or send data via a network. This network includes a wireless network provided by the terminal's communication provider. In one example, the transmission device 106 includes a Network Interface Controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In another example, the transmission device 106 can be a Radio Frequency (RF) module used for wireless communication with the Internet.
[0053] This embodiment provides a linear text stream serialization method. Figure 2 This is a flowchart of the linear text stream serialization method in this embodiment, as follows: Figure 2 As shown, the process includes the following steps:
[0054] Step S201: Traverse the pre-selected target file set to generate an ASCII directory structure diagram.
[0055] Specifically, in large-scale assisted programming scenarios, when submitting complex local project code to a cloud model, existing technologies often simply involve "file content concatenation." This means that after traversing the target file set, the original text of each file is directly read and concatenated with newlines or simple delimiters to form a continuous text that is then fed into the model context. This processing completely strips away the native tree topology of the file system, forcibly flattening the multi-level nested directory structure and losing the spatial semantics brought by the directory hierarchy. In project scenarios with files and subdirectories with the same name across multiple modules, this deficiency is drastically amplified. If a project contains both a business source code module (src / utils / ) and a test module (tests / utils / ), these two directories may contain scripts, utility functions, and constant definitions with the same name. When only plain content concatenation is performed, two texts from completely different sources and belonging to different business modules are arranged consecutively, no longer carrying information about their paths, parent and child directories, or sibling files. For a large model, the input consists only of fragmented code text. The model cannot distinguish whether a piece of utility code belongs to the business source code module or the test module. In addition, the model cannot identify which level of parent directory a file belongs to, is unclear about the boundaries of nested directories, and loses sibling dependency relationships. Without the above topological semantics, the large model struggles to distinguish the boundaries of the code's module, frequently resulting in directory confusion and file ownership errors in scenarios such as parsing relative paths, generating import statements, and cross-file logic deduction, thus inducing persistent illusions.
[0056] Therefore, in this embodiment, a directory structure graph is first constructed based on the target file set selected by the user. The construction of the directory structure graph in this embodiment adopts a context engineering strategy of tree traversal + structured topology serialization. First, project nodes are filtered, and a set of valid project nodes is determined based on the target files selected by the user. Then, based on the determined set of valid nodes, a recursive algorithm is used to traverse the entire project topology. The algorithm takes the project root directory as the traversal entry point, initializes the root node's nesting depth to 0, and uses it as the unique origin reference for the entire spatial coordinate system. The traversal follows the standard depth-first rule, prioritizing recursive access to all subdirectory nodes under the current directory until a leaf node with no lower-level children is reached, then backtracking to traverse the remaining nodes at the same level, fully replicating the actual nesting order and arrangement logic of the physical file system, enumerating all valid directories and file entities one by one. During the traversal, core parameter calculations are performed simultaneously: each time a subdirectory is entered, the node level depth is automatically incremented by 1 to quantify the vertical nesting span; at the same time, the core topological attributes of each node are recorded in real time, including the complete absolute path of the current node, node type (directory / file), parent node index, and set of sibling nodes at the same level, fully preserving the subordinate and parallel relationships of nodes, and realizing the full collection and quantitative archiving of physical topological information.
[0057] After completing topology data acquisition and hierarchical quantization, a standardized ASCII character dynamic rendering algorithm is used to transform the quantized topology data into a visual, linearly parsable ASCII directory structure diagram, ultimately completing the construction of a dedicated engineering space coordinate system for the large model. During the rendering phase, layout is achieved based on real-time node depth values, using a fixed indentation width to match the depth of a single level. The greater the depth, the more white space is left in front of the indentation, visually distinguishing vertical nesting levels through indentation differences. Simultaneously, based on the arrangement of sibling nodes, a standardized ASCII border character set ("...") is dynamically matched. , , For non-last sibling nodes, use " Prefix and last sibling nodes use " The prefix, used in multi-level nested scenarios, is " The characters continue the vertical line structure of the upper layer, restoring the peer boundaries and parent-child subordination boundaries of each node. This rendering method generates the data in real time through a traversal algorithm, without any static hard-coded text. All indentation, lines, and node arrangements are strictly aligned with the physical file system topology. The final generated ASCII directory structure diagram constructs a software engineering spatial coordinate system with a clear dimension, unique topology, and reversible structure, using the root directory as the spatial origin, the hierarchical depth as the vertical dimension, and the peer node arrangement as the horizontal dimension. The traversal algorithm can also be implemented using an iterative + stack-based DFS approach; this embodiment does not specifically limit this method.
[0058] This ASCII directory structure diagram enables a lossless mapping from a non-linear tree structure to a linear text structure. All subsequent input file code content can be precisely anchored and topologically matched using this coordinate system, thus solving the problem of topological semantic loss caused by traditional flat splicing at the structural level.
[0059] Step S202: In each leaf node of the ASCII directory structure diagram, set the unique identifier and file size of each target file to form a directory index area.
[0060] Specifically, after constructing the ASCII directory structure graph, this embodiment generates a globally unique reference ID (Ref-ID) in real time for each valid file leaf node during traversal and identification. This identifier is generated based on the complete file path and file hash characteristics, and is unique within the entire scope of the current project. It can serve as a fixed addressing index for single file entities, avoiding the identification confusion caused by files with the same name or homogeneous directories. Simultaneously, a lightweight metadata summary of the leaf node is collected, which includes the file's physical size, file extension type, and core file identification information. For code files, highly concise feature information such as the first-level key class name and core function name can be extracted. Only structured summary data is extracted throughout the process; the complete source code content of the file is not loaded or concatenated, avoiding contextual redundancy and expansion.
[0061] Based on Ref-ID and standardized metadata digests, the Ref-ID and physical attribute information of each target file are embedded and solidified in all leaf nodes of the ASCII directory structure diagram, forming a directory index area. This directory index area is deeply coupled and corresponds one-to-one with the preceding ASCII topology structure. While preserving the original hierarchical indentation, parent-child subordination, and peer-to-peer topological relationships, it supplements each file entity with a searchable and globally unique structured index dimension. From a structural construction logic perspective, the topology view is responsible for restoring the spatial hierarchy of the project, while the directory index area is responsible for solidifying the unique identity and basic attributes of a single file entity. The two work together to complete the two-layer modeling of the project structure, providing standardized index support for the subsequent large model to accurately associate file content, match topological locations, and trace file entities. The final index text block is generated, with a Project Context Map identifier in the header, serving as the "map" part of the Prompt.
[0062] Here is an example of a text block in the directory index area:
[0063] .
[0064] Step S203: Standardize and encapsulate the content of each target file and the unique identifier of each target file using a preset strong delimiter to form a file content area; wherein, the preset strong delimiter is a symbol used to limit the start and end positions of the target file.
[0065] Specifically, based on the completion of the two-layer structure modeling of the engineering topology coordinate system and the leaf node index area, this embodiment further implements standardized and structured grouping of discrete file text content through a custom strong delimiter encapsulation mechanism, constructs a file content area that maps one-to-one with the directory index area, and finally achieves strong binding and resolvable association between the three elements of "topology structure - file index - entity content".
[0066] Unlike traditional content splicing methods that lack separators, have weak separators, or rely on natural line breaks, this embodiment employs a pre-defined, dedicated, collision-resistant strong delimiter system that can be recognized by large models. It standardizes and encapsulates the original content of each target file and its corresponding unique Ref-ID, so that each file content has an independent, closed-loop, and traceable structured boundary. The strong delimiter defines the start and end positions of the target file, thereby solving the problems of crosstalk, blurred boundaries, and misattribution of multiple file contents in long context scenarios.
[0067] For each file leaf node assigned a globally unique Ref-ID, the system independently initiates a content encapsulation unit. This unit uses a custom-designed strong delimiter to achieve bidirectional anchoring at the beginning and end. The encapsulated files then form the file content area. The header anchor point marks the beginning of the content boundary and fully carries the file start marker, the global Ref-ID, and the complete physical path. For example, the standardized format is as follows:
[0068] ;
[0069] The trailing anchor point marks the end of the content and carries the file end marker and the same-origin Ref-ID. For example, the standardized format is as follows:
[0070] .
[0071] The same Ref-ID is reused for identification and alignment at both the beginning and end, so that each segment of file content forms a closed-loop structure in the text stream. This establishes a one-to-one mapping relationship between the index coordinates in the preceding ASCII engineering map and the actual file content, achieving precise anchoring between structured "spatial coordinates" and entity "code content".
[0072] For example, the following is an example of a text block encapsulated in the file content area:
[0073] .
[0074] This embodiment selects " and "As a strong delimiter in this embodiment, firstly, this type of multi-symbol aggregation marker generally corresponds to conflict boundary scenarios of conflict markers (Git) in mainstream large-scale model training corpora. The model has solidified its prior semantics of strong boundaries, strong isolation, and paragraph termination during the pre-training stage, and can stably identify it as a content segmentation boundary. It can form highly consistent parsing rules without additional fine-tuning, and its adherence to boundary semantics is significantly better than weak segmentation methods such as ordinary line breaks, blank lines, and single-symbol separation. Secondly, " "The combination of symbols can be parsed into a single independent token by mainstream word segmenters without character-level splitting. In scenarios such as large-scale file injection and extremely long project contexts, it can maximize the compression of the token consumption of the delimiter itself, and use all the limited context quota to carry effective topology information and code content."
[0075] Meanwhile, this strong delimiter combination rarely appears naturally in regular code, comments, documentation, configuration files and other project texts, with an extremely low probability of content collision. It can effectively avoid parsing anomalies where the main text of the file is misidentified as boundary markers, and ensure the robustness of structured encapsulation.
[0076] In addition, to address the common issues of attention drift, context decay, and boundary memory ambiguity in scenarios with over 100k long contexts, this embodiment employs a tail-based same-origin ID rewriting mechanism. This mechanism can re-anchor the attribution index at the end of each file content segment, assisting the model in continuously locking the topological node coordinates corresponding to the current content in the ultra-long linear text stream. This suppresses the problems of long text context confusion and boundary loss, ensuring that each piece of code content is always constrained within the predetermined engineering space coordinate system and index system, thus completing the construction of a fully structured, traceable, and strongly isolated file content area.
[0077] Step S204: Based on the unique identifier of each target file, establish a one-to-one cross-regional logical index relationship between the directory index area and the file content area; according to the index relationship, place the directory index area at the beginning and the file content area at the end for linear concatenation to obtain the target linear text stream.
[0078] Specifically, after completing the independent structured construction of the directory index area and the file content area, this embodiment connects the two areas using a linear stream. The linear stream synthesis used in this embodiment is based on a fixed physical order of concatenation. The final output linear text stream = complete index area text + delimiter newline character + complete content area text, following a global concatenation order of index first, then content.
[0079] The specific binding and addressing mechanism is as follows: each file leaf node entry in the directory index area is explicitly labeled with its corresponding Ref-ID and basic file metadata; each closed-loop file content structure in the file content area is aligned by using Ref-IDs that are consistent within the same source as the header and footer delimiters. In the overall linear text flow, the structured topology entries in the index area and the corresponding file content blocks in the content area form a one-to-one cross-reference relationship. Based on the unified Ref-ID, the model accurately maps the previously established global topology information, such as engineering space coordinates, module affiliation, and hierarchical relationships, to the corresponding specific file content, achieving precise logical linkage between the "topology map" and the "file reality." This synthesis method, through the standardized mechanism of structural partitioning, sequence constraints, and cross-regional references, realizes the structured, ordered, and traceable modeling of the software engineering context.
[0080] Specifically, this embodiment employs a sequential append mechanism for composition, unlike the traditional tree-structured embedding method. In this embodiment, the structured content blocks of each file in the content area are not interleaved or embedded below the physical location of the corresponding leaf node in the index tree. The index area and content area always maintain an independent, sequential arrangement, with the two areas physically isolated, fully preserved, and not nested. Under this dual-area separation architecture, the globally unique Ref-ID becomes the core logical reference key connecting the two areas, serving as the core function of a precise cross-area pointer and establishing a non-physically nested bidirectional logical association.
[0081] By linearly concatenating the two regions, the overall fusion of the two regions is completed, ultimately generating a complete target linear text stream that is adapted to the input of a large model.
[0082] Through steps S201 to S204 above, the pre-selected set of target files is traversed to generate an ASCII directory structure diagram. In each leaf node of the ASCII directory structure diagram, the unique identifier and file size of each target file are set to form a directory index area. The content and unique identifier of each target file are standardized and encapsulated using preset strong delimiters to form a file content area. The preset strong delimiters are symbols used to limit the start and end positions of the target files. Based on the unique identifier of each target file, a one-to-one cross-region logical index relationship is established between the directory index area and the file content area. According to the index relationship, the directory index area is placed at the beginning and the file content area is placed at the end for linear concatenation to obtain the target linear text stream. Compared to existing technologies that use simple linear concatenation of file content to obtain a linear text stream, this embodiment annotates each file leaf node entry in the index area with a corresponding Ref-ID and file basic metadata. It also encapsulates each segment of file content structure in the content area using strong delimiters and Ref-IDs. Furthermore, through Ref-IDs in the overall linear text stream, it establishes a one-to-one cross-reference relationship between the structured topology entries in the index area and the corresponding file content blocks in the content area. This accurately maps the previously established global topology information, such as engineering space coordinates, module affiliation, and hierarchical relationships, to the corresponding specific file content in the subsequent stage. This achieves precise logical linkage between the "topology map" and the "file reality," solving the problems of illusions and logical recognition errors that are easily generated during large model-assisted programming.
[0083] In some embodiments, a unique identifier and file size for each target file are set in each leaf node of the ASCII directory structure graph to form a directory index area, including:
[0084] Based on the pre-selected set of target files, a target file sequence table is constructed, which includes the file size of each target file and the unique identifier of each target file;
[0085] Obtain the unique identifier and file size of each target file from the target file sequence list;
[0086] In the leaf nodes of the ASCII directory structure diagram, a unique identifier and file size for each target file are set to form a directory index area.
[0087] Specifically, based on the pure virtual candidate tree obtained after the above screening, the system initiates a human-machine collaborative secondary screening process and starts a real-time status monitoring mechanism to dynamically capture the user's node selection and cancellation operations on the GUI. It maintains a globally unique target file sequence list (SelectedNodeList) in memory in real time. This list serves as the only reliable data source for all subsequent structured modeling processes, and summarizes the information of all target files selected by the user in real time. It records the absolute physical path, file storage size, and temporary globally unique identifier dynamically allocated by the system for each valid file. The entire process is based on memory read and write with no disk redundancy, ensuring the real-time nature of the screening status and data consistency.
[0088] After the target file sequence list is constructed, the system extracts the unique identifier and corresponding file size attribute of each target file in batches. Using the aforementioned ASCII directory topology rendering system, these structured parameters are synchronously embedded and bound to the leaf nodes of each file in the directory tree. This ensures that each leaf topology node possesses hierarchical location information, a unique identifier, and physical attribute information, ultimately generating a standardized directory index area with searchable, traceable, and mappable characteristics. Through this mechanism, the visualized hierarchical structure of the topology tree is fully coupled with the structured metadata of the file entities, achieving precise binding between the spatial location of the engineering topology and the unique identity information of the file. This provides a stable and unified indexing benchmark for cross-regional content association, file content encapsulation, and linear stream synthesis.
[0089] In another embodiment, a preset strong delimiter is used to standardize and encapsulate the content of each target file and the unique identifier of each target file to form a file content area, including:
[0090] Read the file size and unique identifier of each target file from the target file sequence list;
[0091] Determine whether the file size of each target file exceeds a preset file threshold;
[0092] If so, then generate placeholders based on the target file and replace the text content of the target file with the placeholders; otherwise, obtain the text content of the target file.
[0093] The placeholders and / or text content of each target file are encapsulated with a preset strong delimiter to form the file content area.
[0094] Specifically, the process involves encapsulating placeholders and / or text content of each target file with their unique identifier using preset strong delimiters to form the file content area. This includes: for a single target file, setting a preset strong delimiter at the beginning of the target file; setting placeholders and / or text content of the target file in the body of the target file; setting a preset strong delimiter at the end of the target file to obtain the encapsulation structure of a single target file; and concatenating the encapsulation structures of each single target file sequentially to form the file content area.
[0095] Specifically, the system first reads the file size attribute of the target file being traversed and compares it with a preset file capacity threshold. For large files exceeding the threshold, the system activates a content suppression mechanism, refraining from disk I / O read operations to prevent large text from consuming context quotas. Instead, it directly generates standardized placeholder text, annotating the file size, the reason for exceeding the threshold, and the status of omitted content. This method conserves valuable token resources while preserving the file's physical presence and topological position within the project structure, preventing the model from misjudging the file's non-existence or structural incompleteness due to missing content, thus avoiding illusions. For regular text files whose size does not exceed the threshold, the system calls the standard disk I / O interface to fully read the original text content, ensuring that detailed information in regular code, configuration, and documentation files is complete and parsable.
[0096] After loading differentiated content or generating placeholders, the system uses a pre-defined strong delimiter system to complete closed-loop semantic encapsulation, achieving strong binding and anchoring between file entity content and unique Ref-ID. The encapsulation structure is a standard three-segment structure: header semantic anchor, main content area, and tail closing anchor. The header strong delimiter carries the file start identifier, globally unique Ref-ID, and complete physical path, as well as the topology node corresponding to the associated directory index area. The main content area dynamically carries the actual file text content or standardized over-limit placeholders based on the threshold determination result. The tail strong delimiter reuses the same-origin Ref-ID to complete boundary closure verification, strengthening the content ownership anchoring in long text scenarios. For example, the encapsulation structure of a target file is as follows:
[0097] head: ;
[0098] Body: File content / placeholders;
[0099] Tail: .
[0100] After single-file encapsulation is completed, the system performs the same processing logic on all target files one by one in a pre-selected order, and finally concatenates all structured file blocks in an orderly manner to form a complete file content area that is structurally sound, clearly defined, controllable, and traceable. This differentiated encapsulation mechanism not only ensures the inference integrity of small file content, but also achieves lightweight noise reduction for large files, balancing the inference accuracy of large models with the utilization rate of context tokens.
[0101] In some embodiments, before traversing the pre-selected target file set, the method further includes: obtaining an initial file set, traversing the initial file set, generating an initial ASCII directory structure diagram, wherein each initial file in the initial file set is a candidate in the initial ASCII directory structure diagram; selecting a target file from the initial ASCII directory structure diagram to obtain the pre-selected target file set.
[0102] Specifically, before topology traversal modeling, this embodiment includes a human-machine collaborative file set pre-selection process. This pre-selection process comprises two core stages: initial topology rendering and interactive optimization. The system first reads the local physical file system's entire directory and file resources to obtain the initial file set for the project. It then performs a preliminary tree traversal of the entire resource set, replicating the nested topology relationships of the physical file system, and automatically generates a complete initial ASCII directory structure diagram. In this initial ASCII directory tree, all initial files and directory nodes are uniformly marked as candidate nodes.
[0103] Based on this initial candidate topology, the system combines built-in configuration rules with a manual selection mechanism to perform dual filtering, accurately locking in the pre-selected target file set. At the manual interaction level, a GUI interface visually renders the initial ASCII directory tree, allowing users to independently select, retain, and remove corresponding directories and file nodes based on task requirements. Finally, from the initial candidate file set across the entire domain, a set of valid target files suitable for the current large-scale model task scenario is selected. The selected parent directory automatically selects all its child files. Figure 3 This is a GUI interface and a schematic diagram of the serialization result of the linear text stream serialization method in this embodiment, as shown below. Figure 3 As shown, the left side of the interface displays the user's selected checkboxes, and the right side displays the generated serialized target file text. Figure 3 The English text in the text refers to filenames, directory names, and text content in the actual business scenario. Figure 3 Only one GUI interface and a schematic diagram of the serialization result are provided.
[0104] In another embodiment, target files are selected from the initial ASCII directory structure diagram to obtain a pre-selected set of target files, including:
[0105] Obtain the selected initial target file set from the initial ASCII directory structure diagram, and filter each initial target file in the initial target file set according to the preset filtering strategy to obtain the pre-selected target file set.
[0106] Specifically, after the user selects the initial target file set, this embodiment filters the initial target file set by performing batch automatic cleaning through a preset filtering strategy. The specific filtering strategies include: filtering and removing invalid directories such as .git, node_modules, and venv that only store metadata, environment dependencies, and version information through a directory blacklist to avoid interference from redundant architectures; or performing compliance verification through file extensions to uniformly filter out non-text files with extensions such as .exe, .dll, and .jpg to exclude unresolvable binary resources from the source; or using file magic number detection to identify and remove hidden binary files disguised as text files by reading the first 4100 bytes of data in the file header and matching the Magic Bytes signature, thus solving the context pollution problem of pseudo-text resources and obtaining a purified target file set.
[0107] By employing filtering strategies, effective modeling data sources are extracted from the original physical file system, avoiding interference from redundant files, invalid directories, and binary resources on engineering topology modeling. Low-value and high-consumption files are automatically intercepted, ensuring that every token is spent on core logic code. This provides a precise, controllable, and low-redundancy input foundation for subsequent hierarchical measurement, index binding, content encapsulation, and linear stream synthesis.
[0108] In some embodiments, the target linear text stream includes the file paths of each target file, and the receiving end can reconstruct the original folder structure of each target file through the file paths of each target file.
[0109] Specifically, the target linear text stream constructed in this embodiment is not simply a one-way input text for large model inference, but a reversible structured storage format that integrates complete path topology, content boundary identifiers, and unique index identifiers. During the synthesis process, the entire text stream retains the complete absolute path information of each target file. Through path hierarchy data, it fully preserves the original project's folder nesting structure and module distribution relationships, implicitly carrying discrete physical file system topology information within the linearized text stream. Compared to the shortcomings of traditional flattened text splicing, which only retains fragmented content and completely loses architectural information, the linear text stream output in this embodiment solidifies structured information such as file paths, hierarchical nesting, and node affiliation in the delimiter header anchor point, providing complete data source support for reverse parsing and topology reconstruction at the receiving end.
[0110] Among these features, the complete file path can accurately locate the hierarchical affiliation and storage location of each file, restoring the overall structure of nested parent and child directories and parallel sibling directories; the standardized [FILE_START] and [FILE_END] strong boundary markers can accurately cut each independent file data block, achieving unobfuscated splitting of multi-file content; and the globally unique Ref-ID can complete the secondary verification and matching of the index area and content area, ensuring the uniqueness and accuracy of the parsing process. Based on the above structured features, the receiving end can reverse decompose the target linear text stream through a rule-based parsing algorithm, automatically stripping the index area and content area data, and reconstructing the path and restoring the content of each file node one by one. Finally, in a remote environment, it can completely and losslessly restore the folder hierarchy structure and file content system that is completely consistent with the original project, enabling the context text stream to have the dual capabilities of model inference input and project structured backup and cross-environment restoration.
[0111] This embodiment also provides a linear text stream serialization method. Figure 4 This is a flowchart of another linear text stream serialization method in this embodiment, such as... Figure 4 As shown, the process includes the following steps:
[0112] Step S401: Obtain the initial file set, traverse the initial file set, and generate the initial ASCII directory structure diagram. In the initial ASCII directory structure diagram, each initial file in the initial file set is a candidate state.
[0113] Step S402: Obtain the selected initial target file set in the initial ASCII directory structure diagram, and filter each initial target file in the initial target file set according to the preset filtering strategy to obtain the pre-selected target file set;
[0114] Step S403: Traverse the pre-selected target file set to generate an ASCII directory structure diagram; based on the pre-selected target file set, construct a target file sequence table, wherein the file sequence table includes the file size of each target file and the unique identifier of each target file;
[0115] Step S404: Obtain the unique identifier and file size of each target file from the target file sequence list; simultaneously execute steps S405 and S406.
[0116] Step S405: Set the unique identifier and file size of each target file in each leaf node of the ASCII directory structure diagram to form a directory index area; execute step S410.
[0117] Step S406: Determine whether the file size of the target file is greater than the preset file threshold; if yes, proceed to step S407; otherwise, proceed to step S408.
[0118] Step S407: Generate placeholders based on the target file, and replace the text content of the target file with the placeholders; then proceed to step S409.
[0119] Step S408: Obtain the text content of the target file;
[0120] Step S409: Use a preset strong delimiter to encapsulate the placeholders and / or text content of each target file with the unique identifier of each target file to form a file content area;
[0121] Step S410: Based on the unique identifier of each target file, the directory index area and the file content area are linearly combined to obtain the target linear text stream.
[0122] For example, Figure 5 This is a diagram of an example of a linear text stream output by the linear text stream serialization method implemented in this paper.
[0123] Through steps S401 to S410, compared to the existing technology that uses simple linear concatenation of file content to obtain a linear text stream, this embodiment first cleans invalid resources through filtering rules, then manually selects and filters the set of valid files using a GUI, and generates a standardized ASCII directory topology index through tree traversal. This establishes a global spatial coordinate system for the model and a unique file index mapping, replacing the traditional unstructured flattened content concatenation method. Simultaneously, it uses highly adaptable, low-loss strong delimiters to encapsulate file content, and combines file threshold judgment to achieve differentiated content loading, accurately isolating multiple file boundaries and eliminating contextual interference. Through a dual-regional synthesis mechanism of first using topology index and then entity content, cross-regional logical associations are established with unique identifiers. This allows the model to complete path resolution and module attribution determination based on a standardized engineering structure, effectively solving problems such as long contextual attention drift, file location misjudgment, and false content generation, and suppressing the illusion and logical recognition bias in large model programming reasoning.
[0124] This embodiment also provides a linear text stream serialization device for implementing the above embodiments and preferred embodiments; details already described will not be repeated. The terms "module," "unit," "subunit," etc., used below refer to combinations of software and / or hardware that perform predetermined functions. Although the device described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.
[0125] Figure 6 This is a structural block diagram of the linear text stream serialization device in this embodiment, as shown below. Figure 6 As shown, the device includes: a directory index area construction module 61, a file content area construction module 62, and a linear stream synthesis module 63;
[0126] The directory index area construction module 61 is used to traverse the pre-selected set of target files and generate an ASCII directory structure diagram; in each leaf node of the ASCII directory structure diagram, the unique identifier and file size of each target file are set to form the directory index area;
[0127] The file content area construction module 62 is used to standardize and encapsulate the content of each target file and the unique identifier of each target file using preset strong delimiters to form a file content area; wherein, the preset strong delimiters are symbols used to limit the start and end positions of the target files;
[0128] The linear stream synthesis module 63 is used to establish a one-to-one cross-regional logical index relationship between the directory index area and the file content area based on the unique identifier of each target file; according to the index relationship, the directory index area is placed at the beginning and the file content area is placed at the end for linear concatenation to obtain the target linear text stream.
[0129] It should be noted that the above modules can be functional modules or program modules, and can be implemented through software or hardware. For modules implemented through hardware, the above modules can reside in the same processor; or the above modules can be located in different processors in any combination.
[0130] Furthermore, in conjunction with the linear text stream serialization method provided in the above embodiments, this embodiment can also provide a storage medium for implementation. This storage medium stores a computer program; when executed by a processor, the computer program implements any of the linear text stream serialization methods described in the above embodiments.
[0131] It should be understood that the specific embodiments described herein are merely illustrative of the application and not intended to limit it. All other embodiments derived by those skilled in the art based on the embodiments provided in this application without inventive effort are within the scope of protection of this application.
[0132] Obviously, the accompanying drawings are merely some examples or embodiments of this application. Those skilled in the art can apply this application to other similar situations based on these drawings without any creative effort. Furthermore, it is understood that although the work done in this development process may be complex and lengthy, for those skilled in the art, certain design, manufacturing, or production modifications made based on the technical content disclosed in this application are merely conventional technical means and should not be considered as insufficient disclosure of this application.
[0133] The term "embodiment" in this application refers to a specific feature, structure, or characteristic described in connection with an embodiment that may be included in at least one embodiment of this application. The appearance of this phrase in various places in the specification does not necessarily imply the same embodiment, nor does it imply that it is mutually exclusive with or independent of other embodiments. It will be clearly or implicitly understood by those skilled in the art that the embodiments described in this application may be combined with other embodiments without conflict.
[0134] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments described above. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, etc., and are not limited to these.
[0135] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of patent protection. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the appended claims.
Claims
1. A method for serializing linear text streams, characterized in that, include: Iterate through the pre-selected set of target files to generate an ASCII directory structure diagram; In each leaf node of the ASCII directory structure diagram, a unique identifier and file size of each target file are set to form a directory index area; The content of each target file and its unique identifier are standardized and encapsulated using a preset strong delimiter to form a file content area; wherein, the preset strong delimiter is a symbol used to define the start and end positions of the target file; Based on the unique identifier of each target file, a one-to-one cross-regional logical index relationship is established between the directory index area and the file content area; Based on the index relationship, the directory index area is placed at the beginning and the file content area is placed at the end for linear concatenation to obtain the target linear text stream.
2. The linear text stream serialization method according to claim 1, characterized in that, The step of setting a unique identifier and file size for each target file in each leaf node of the ASCII directory structure diagram to form a directory index area includes: Based on the pre-selected set of target files, a target file sequence table is constructed, wherein the file sequence table includes the file size of each target file and the unique identifier of each target file; Obtain the unique identifier of each target file and the file size of each target file from the target file sequence list; The unique identifier and file size of each target file are set in each leaf node of the ASCII directory structure diagram to form a directory index area.
3. The linear text stream serialization method according to claim 2, characterized in that, The process of standardizing and encapsulating the content of each target file and its unique identifier using a preset strong delimiter to form a file content area includes: Read the file size and unique identifier of each target file from the target file sequence list; Determine whether the file size of each target file is greater than a preset file threshold; If so, then a placeholder is generated based on the target file, and the text content of the target file is replaced by the placeholder; otherwise, the text content of the target file is obtained. The placeholders and / or text content of each target file and its unique identifier are encapsulated using a preset strong delimiter to form the file content area.
4. The linear text stream serialization method according to claim 3, characterized in that, The process of encapsulating the placeholders and / or text content of each target file with their unique identifiers using preset strong delimiters to form the file content area includes: For a single target file, the preset strong delimiter is set at the beginning of the target file; Placeholders for the target file and / or the text content of the target file are set in the body of the target file; The preset strong delimiter is set at the end of the target file to obtain the encapsulation structure of the single target file; The encapsulation structures of each individual target file are sequentially assembled to form the file content area.
5. The linear text stream serialization method according to claim 1, characterized in that, Before traversing the preselected set of target files, the method further includes: Obtain an initial file set, traverse the initial file set, and generate an initial ASCII directory structure diagram, wherein each initial file in the initial file set is a candidate file in the initial ASCII directory structure diagram; The target file is selected from the initial ASCII directory structure diagram to obtain the pre-selected target file set.
6. The linear text stream serialization method according to claim 5, characterized in that, The step of selecting target files from the initial ASCII directory structure diagram to obtain the pre-selected target file set includes: Obtain the selected initial target file set from the initial ASCII directory structure diagram, and filter each initial target file in the initial target file set according to a preset filtering strategy to obtain the pre-selected target file set.
7. The linear text stream serialization method according to claim 1, characterized in that, The process of traversing the pre-selected set of target files to generate an ASCII directory structure diagram includes: The pre-selected set of target files is traversed, and the ASCII directory structure diagram is generated using a recursive algorithm.
8. The linear text stream serialization method according to claim 1, characterized in that, The target linear text stream includes the file paths of each target file, and the receiving end can restore the original folder structure of each target file through the file paths of each target file.
9. A linear text stream serialization device, characterized in that, include: The module for building the directory index area, the module for building the file content area, and the module for synthesizing linear streams; The directory index area construction module is used to traverse the pre-selected set of target files and generate an ASCII directory structure diagram; in each leaf node of the ASCII directory structure diagram, a unique identifier and file size of each target file are set to form a directory index area. The file content area construction module is used to standardize and encapsulate the content of each target file and the unique identifier of each target file using a preset strong delimiter to form a file content area; wherein, the preset strong delimiter is a symbol used to define the start and end positions of the target file; The linear stream synthesis module is used to establish a one-to-one cross-regional logical index relationship between the directory index area and the file content area based on the unique identifier of each target file. Based on the index relationship, the directory index area is placed at the beginning and the file content area is placed at the end for linear concatenation to obtain the target linear text stream.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the linear text stream serialization method according to any one of claims 1 to 8.
