Encoding adaptation method and device based on double feature fusion, equipment and medium
Patent Information
- Application Number
- CN202611324475.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-28
- Publication Date
- 2026-10-30
AI Technical Summary
[0005]基于此,有必要针对现有技术中多语言资源文件因编码格式不统一及缺乏自动识别机制而导致界面文本乱码的技术问题,提出了一种基于双特征融合的编码适配方法、装置、设备及介质
[0010]与现有技术相比,本申请通过获取当前操作系统的运行环境信息和目标语言标识生成对应的候选编码列表,并提取资源文件前部字节作为检测样本进行字节顺序标记检测;在不存在字节顺序标记的情况下,利用候选编码列表对检测样本进行解码,进一步通过对解码文本的非法序列指示状态、可打印字符率、语言特征匹配度以及锚点关键词命中状态进行多个维度的特征验证并进行加权评分,最终筛选出综合得分最高的编码作为读取资源文件的目标编码。本申请利用运行环境信息缩小了初始的编码推测范围,并通过对文本实际内容在字符合法性、语言特征区间以及业务关键词等多维度的定量验证,代替了现有技术中固定指定编码的传统方式,即使在资源文件编码格式混杂且缺失字节顺序标记的情况下,也能够自适应地探测并确定出文件的真实编码,从而准确地将异构资源文件转换为内部统一编码进行界面渲染,有效避免了跨区域部署时因编码错配引发的文本乱码问题,提升了系统的兼容性与自动化水平。
Smart Images

Figure CN123013848A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of automotive electronics technology, and in particular to a coding adaptation method, apparatus, device and medium based on dual feature fusion. Background Technology
[0002] Automotive diagnostic software typically needs to support multiple languages to meet the usage requirements of different countries and regions. In the process of implementing multilingual support, the translated text for each language is usually stored as a separate resource file. When the software starts, the system loads the resource file for the corresponding language based on the current locale settings.
[0003] In practical applications, due to differences in development tools, resource files within the same project often have different encoding formats. For example, some language files are saved in 8-bit Unicode Transformation Format (UTF-8), while others are saved in Chinese Internal Code Extension Specification (GBK) or Shift Japanese Industrial Standards (Shift-JIS). Furthermore, some UTF-8 files do not include byte order markers when saved. When the target operating system reads these files without byte order markers and with inconsistent encoding formats, it will default to using the operating system's native code page for decoding. For example, when loading a UTF-8 formatted Japanese resource file without byte order markers on a Japanese operating system that defaults to the Shift-JIS code page, the operating system will parse it according to the Shift-JIS format, resulting in garbled text in the interface. Existing solutions typically specify a fixed reading encoding at the system level or rely on operations personnel to manually check and correct the file encoding format during deployment.
[0004] The above methods lack a mechanism to automatically identify the encoding status based on the file content. When faced with resource files with heterogeneous encodings, they often cannot correctly parse the text, reducing the efficiency of software deployment across regions. Summary of the Invention
[0005] Based on this, it is necessary to address the technical problem of garbled text in the interface of multilingual resource files due to inconsistent encoding formats and lack of automatic recognition mechanisms in the existing technology. Therefore, a coding adaptation method, device, equipment and medium based on dual feature fusion is proposed.
[0006] Firstly, a coding adaptation method based on dual-feature fusion is provided, comprising: Obtain the current operating system's runtime environment information and the target language identifier for the multilingual interface, and generate a corresponding candidate encoding list based on the runtime environment information and the target language identifier; Read the first few bytes of the target language resource file to obtain the raw byte stream, and use the raw byte stream as a detection sample; Perform byte order mark detection on the test samples; If a byte order marker exists in the detected sample, the target encoding is determined based on the byte order marker. If there is no byte order mark in the detected sample, the candidate encoding list is traversed, and the detected sample is decoded according to each candidate encoding in the candidate encoding list to obtain the corresponding decoded text; The decoded text is subjected to feature verification to obtain text features in multiple dimensions; the text features include illegal sequence indication state, printable character rate, language feature matching degree, and anchor keyword hit state; Each candidate code is weighted and scored based on the text features of the multiple dimensions to obtain a comprehensive score for each candidate code. The candidate codes with the highest comprehensive scores and scores greater than zero are selected and used as the target codes. The target language resource file is read according to the target encoding, the read text is converted into an internal unified encoding, and the interface is rendered according to the internal unified encoding.
[0007] Secondly, a multilingual encoding automatic detection and adaptation device based on the fusion of operating environment and text features is provided, the device comprising: The information acquisition and list generation module is used to acquire the current operating system's runtime environment information and the target language identifier of the multilingual interface, and generate a corresponding candidate encoding list based on the runtime environment information and the target language identifier. The sample reading module is used to read the first bytes of the target language resource file, obtain the raw byte stream, and use the raw byte stream as a detection sample. A marker detection module is used to perform byte order marker detection on the detection sample; if a byte order marker exists in the detection sample, the target encoding is determined based on the byte order marker. The candidate decoding module is used to, if there is no byte order mark in the detected sample, traverse the candidate encoding list and decode the detected sample according to each candidate encoding in the candidate encoding list to obtain the corresponding decoded text; The feature verification module is used to perform feature verification on the decoded text to obtain text features in multiple dimensions; the text features include illegal sequence indication state, printable character rate, language feature matching degree, and anchor keyword hit state; The weighted scoring module is used to assign a weighted score to each candidate code based on the text features of the multiple dimensions, and obtain a comprehensive score for each candidate code. The coding filtering module is used to filter out the candidate codes with the highest comprehensive score and a score greater than zero; and to use the filtered candidate codes as the target codes. The reading and rendering module is used to read the target language resource file according to the target encoding; convert the read text into an internal unified encoding; and perform interface rendering according to the internal unified encoding.
[0008] Thirdly, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the above-described encoding adaptation method based on dual feature fusion.
[0009] Fourthly, a computer-readable storage medium is provided, the computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the above-described coding adaptation method based on dual-feature fusion.
[0010] Compared with existing technologies, this application generates a candidate encoding list by obtaining the current operating system's runtime environment information and target language identifiers, and extracts the first bytes of the resource file as a detection sample for byte order mark detection. In the absence of byte order marks, the candidate encoding list is used to decode the detection sample. Further, multiple dimensions of feature verification are performed, including illegal sequence indication status, printable character rate, language feature matching degree, and anchor keyword hit status, and weighted scoring is applied. Finally, the encoding with the highest comprehensive score is selected as the target encoding for reading the resource file. This application narrows the initial encoding speculation range by utilizing runtime environment information and replaces the traditional method of fixed encoding in existing technologies by quantitatively verifying the actual text content in multiple dimensions such as character legality, language feature range, and business keywords. Even when the resource file encoding format is mixed and byte order marks are missing, it can adaptively detect and determine the file's true encoding, thereby accurately converting heterogeneous resource files into an internally unified encoding for interface rendering. This effectively avoids text garbled characters caused by encoding mismatch during cross-regional deployment, improving system compatibility and automation. Attached Figure Description
[0011] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0012] in: Figure 1 This is an application environment diagram of a coding adaptation method based on dual feature fusion in one embodiment; Figure 2 This is a flowchart of a coding adaptation method based on dual-feature fusion in one embodiment; Figure 3 This is a structural block diagram of a multilingual encoding automatic detection and adaptation device based on the fusion of operating environment and text features in one embodiment; Figure 4 This is a structural block diagram of a computer device in one embodiment. Detailed Implementation
[0013] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0014] Figure 1 An exemplary system architecture for the dual-feature fusion-based encoding adaptation method applicable to this application is shown.
[0015] Specifically, the system architecture includes: a diagnostic terminal 100, a cloud server 101, and a target vehicle 102. The diagnostic terminal 100 can be an automotive aftermarket repair tool, a smart diagnostic instrument, or a portable computing device equipped with vehicle diagnostic software; the target vehicle 102 is the physical vehicle to be troubleshooted or used for data exchange; and the cloud server 101 is used to uniformly store and distribute diagnostic program update packages containing multilingual resource files to networks in various locations.
[0016] The cloud server 101 sends a diagnostic software package containing heterogeneous encoded language resource files to a diagnostic terminal 100 located in a specific country or region. When the diagnostic terminal 100 starts the diagnostic software and prepares to establish a communication connection with the target vehicle 102, it calls the operating system interface to obtain the current operating environment information and the target language identifier specified by the maintenance personnel. Subsequently, the diagnostic terminal 100 executes the method provided in this embodiment to read the first byte of the downloaded multilingual resource files and perform multi-level feature scoring verification, automatically identifying the correct resource file encoding. After determining the target encoding, the diagnostic terminal 100 correctly converts the resource files into its internal unified encoding and renders a diagnostic operation interface without garbled characters. Finally, through this operation interface, the diagnostic terminal 100 accurately displays the vehicle status and fault data read from the target vehicle 102 to the maintenance personnel, completing the vehicle diagnostic interaction process in a cross-language environment.
[0017] The AI-based intelligent question-answering method provided in this application can be applied to, for example... Figure 1 In this application environment, the client communicates with the server via a network. The server can receive user questions from the client and retrieve multiple candidate questions from a pre-defined standard question library. The candidate questions are then sorted according to their semantic matching, resulting in a first sort. The entity alignment between the user question and each candidate question is determined. The first sort is adjusted based on the entity alignment, resulting in a second sort. In the second sort, misaligned candidate questions are placed after aligned ones, while aligned candidate questions retain their original order. A predetermined number of candidate questions are selected from the first position in the second sort sequence as matching questions. Finally, the matching answers are selected to respond to the user question and sent back to the client. In this application, for complex insurance entities such as insurance business, an entity alignment optimization scheme for the question-answering engine is used. First, a coarse sort is performed based on semantic matching, then the sort is adjusted based on entity alignment. The top-ranked matching questions are selected to obtain the corresponding answers, effectively avoiding the model's generalization limitations and significantly improving entity matching efficiency, thus enhancing the question-answering engine's performance. The client can be, but is not limited to, various personal computers, laptops, smartphones, tablets, and portable wearable devices. The server can be implemented using a standalone server or a server cluster consisting of multiple servers. The following detailed description uses specific embodiments to illustrate this application.
[0018] Please see Figure 2 As shown, Figure 2A flowchart illustrating an artificial intelligence-based intelligent question-answering processing method provided in this application embodiment includes the following steps: S1: Obtain the current operating system's runtime environment information and the target language identifier for the multilingual interface, and generate a corresponding candidate encoding list based on the runtime environment information and the target language identifier; Specifically, during diagnostic startup, the system calls the operating system's low-level API interfaces to obtain global runtime environment information (such as the default language and default code page). Simultaneously, it retrieves the target language identifier for the multilingual interface to be loaded from user configuration or file attributes, and combines these two information to generate a priority-sorted list of candidate encodings in the background.
[0019] By combining system regional configuration with target language identifiers, the global system environment and specific business requirements can be effectively decoupled, eliminating the discrepancy between system-level regional configuration and the user's actual intent.
[0020] For example, a Chinese engineer's PC system environment has a default language of zh-CN and a default code page of CP936. If this engineer needs to debug vehicles exported to Japan, the diagnostic software needs to read Japanese resources. If only relying on the system environment, a list of [UTF-8, GBK, GB2312] will be generated incorrectly. This embodiment achieves an intent coverage mechanism by obtaining the target language identifier "ja-JP", accurately generating a candidate list containing [UTF-8, Shift-JIS, EUC-JP], fundamentally improving the accuracy of encoding detection.
[0021] S2: Read the first bytes of the target language resource file to obtain the raw byte stream, and use the raw byte stream as a detection sample; Specifically, without specifying any particular character set encoding format, a specified length of data at the beginning of the target language resource file is read in pure binary format and used as a clean data source for subsequent analysis.
[0022] Preserving the complete original byte sequence avoids data decoding pollution caused by the forced specification of incorrect encoding format in the early stages of file reading by traditional tools, thus ensuring the authenticity of subsequent feature extraction.
[0023] For example, for the file messages_ja.properties, the first N bytes (N=1024 recommended) are read as a raw byte stream and used as a detection sample. At this stage, the file is not pre-determined to be GBK or UTF-8; instead, these 1024 bytes are cached in memory for detection.
[0024] S3: Perform byte order mark detection on the detection sample. If a byte order mark exists in the detection sample, determine the target encoding directly based on the byte order mark. Specifically, the process involves examining the first few byte sequences of the original byte stream to determine if they conform to a specific byte sequence format defined in the Unicode encoding standard. If a match is found, the character set and byte storage order of the file are directly determined, terminating the subsequent complex calculation process.
[0025] The Byte Order Mark (BOM) is a security contract for cross-platform exchange of text files. When a resource file contains a BOM, directly using the encoding indicated by this mark not only prevents system misjudgment but also greatly improves file loading efficiency.
[0026] For example, if the first 3 bytes of a file are detected to be EFBBBF, then its unique corresponding UTF-8 encoding is directly determined; if the first 2 bytes are FFFE, then the target encoding is determined to be UTF-16 little-endian; if it is FEFF, then the target encoding is determined to be UTF-16 big-endian. Once confirmed, subsequent heuristic detection can be skipped.
[0027] S4: If there is no byte order mark in the detected sample, traverse the candidate encoding list, and decode the detected sample according to each candidate encoding in the candidate encoding list to obtain the corresponding decoded text; Specifically, for files without a BOM identifier, each code is used in turn to perform experimental parsing on clean test samples according to the priority order in the candidate code list generated by S1, thereby generating multiple sets of preliminary decoded text.
[0028] It solves the technical pain point that UTF-8 files without BOM are easily misidentified as local ANSI encoding in Windows systems. By exhaustively listing high-probability candidate encodings, it provides sufficient comparative data for subsequent rationality verification.
[0029] For example, for a German configuration file that lacks a BOM, since the generated candidate encoding list is [UTF-8, ISO-8859-1, CP1252], the system will initiate three decoding processes respectively, using these three encodings to parse the first 1024 bytes of the sample and generate three text segments for subsequent scoring and verification.
[0030] S5: Perform feature verification on the decoded text to obtain text features in multiple dimensions; the text features include illegal sequence indication state, printable character rate, language feature matching degree, and anchor keyword hit state; Specifically, by using multiple preset judgment rules, the rationality of each piece of text decoded in the experiment is evaluated in multiple dimensions. Quantitative indicators such as abnormal error rate, statistical distribution characteristics, and semantic business attributes are extracted, solving the problem of misidentification that is easily caused by a single judgment condition, and making the encoding detection process rigorously interpretable.
[0031] For example, verify whether the decoding process throws an invalid byte exception (illegal sequence indication state), determine whether the proportion of printable characters in the decoded text reaches more than 85% (printable character rate), check whether it contains target language such as German-specific ä, ö, ü, ß (language feature matching degree), and whether it hits business terms specific to the diagnostic field (anchor keyword hit state).
[0032] S6: Weight each candidate code according to the text features of the multiple dimensions to obtain the comprehensive score of each candidate code; Specifically, the multi-dimensional text features extracted in step S5 are input into a multi-dimensional weighted scoring formula. A total score is determined by assigning different weights to each feature based on its importance in judging the true encoding.
[0033] By mathematically unifying hard error checking (illegal sequences), statistical features (printability rate), and semantic features (language characters and business keywords), the originally vague garbled character checking process is transformed into precise algorithmic feature matching.
[0034] For example, the final score = Σ(scores for each dimension). If the decoded code contains an illegal sequence, a veto mechanism is triggered, resulting in a -100-point rejection; if the printable character rate meets the standard, a +20-point score is awarded; if it contains target language characteristic characters, a +30-point score is awarded; and if it hits a preset keyword, a +40-point score is awarded. Adding these scores together yields the quantified score for the candidate code.
[0035] S7: Select the candidate code with the highest comprehensive score and a score greater than zero, and use the selected candidate code as the target code; Specifically, by comparing the overall scores after decoding all the tests, all encodings that contain illegal bytes or have an excessively high rate of garbled characters (i.e., scores less than or equal to zero) are eliminated, and the encoding with the highest score among the remaining results is officially recognized as the true character encoding of the file.
[0036] Through a dual guarantee mechanism of absolute threshold (greater than zero) and relative best (highest score), the final selected code is ensured to be the only solution that best fits the current business context.
[0037] For example, when reading a German file strings_de.xml without a BOM in a Brazilian Portuguese environment (Locale=pt-BR, default CP1252), the traditional solution of reading by the system default CP1252 would result in a very low score and was therefore eliminated in this case. In contrast, UTF-8 decoding can correctly hit the German-specific "Ü" and "ü" and also hit the anchor word "Diagnose". Therefore, UTF-8 has the highest overall score and was selected as the target encoding.
[0038] S8: Read the target language resource file according to the target encoding, convert the read text into the internal unified encoding, and render the interface according to the internal unified encoding.
[0039] Specifically, after confirming the actual encoding format, the resource file is fully read using the optimal target encoding, and then uniformly converted into a wide character encoding standard supported by the software's internal rendering engine before being output to the interface for display.
[0040] It completely solves the problem of garbled characters in multiple language interfaces such as Chinese, English, German, Japanese, and Korean that often occur in cross-border delivery and actual deployment, and achieves zero manual intervention in the entire adaptation process.
[0041] For example, after locking the target encoding to UTF-8, the system reads strings_de.xml in UTF-8 format and converts it to the UTF-16 encoding used internally for UI rendering, ultimately displaying the German text "Überprüfung" correctly on the interface instead of the garbled "Überprüfung". Actual test data shows that this mechanism reduced the multilingual garbled text rate of a certain OEM's global after-sales platform from 12.7% to 0.3%.
[0042] This application generates a candidate encoding list by obtaining the current operating system's runtime environment information and target language identifiers, and extracts the first bytes of the resource file as a detection sample for byte order mark detection. In the absence of byte order marks, the candidate encoding list is used to decode the detection sample. Further, multiple dimensions of feature verification are performed, including illegal sequence indication status, printable character rate, language feature matching degree, and anchor keyword hit status, and weighted scoring is applied. Finally, the encoding with the highest comprehensive score is selected as the target encoding for reading the resource file. This application narrows the initial encoding speculation range by utilizing runtime environment information and replaces the traditional method of fixed encoding in existing technologies by quantitatively verifying the actual text content in multiple dimensions such as character legality, language feature range, and business keywords. Even when the resource file encoding format is mixed and byte order marks are missing, it can adaptively detect and determine the file's true encoding, thereby accurately converting heterogeneous resource files into an internally unified encoding for interface rendering. This effectively avoids text garbled characters caused by encoding mismatch during cross-region deployment, improving system compatibility and automation.
[0043] In some embodiments, obtaining the target language identifier of the multilingual interface and generating a corresponding candidate encoding list based on the runtime environment information and the target language identifier specifically includes: obtaining the filename of the target language resource file and identifying the language identifier character in the filename; using the language identifier character as the target language identifier; obtaining a preset global standard encoding format; obtaining the local default code page corresponding to the runtime environment information; obtaining the historical legacy standard encoding corresponding to the target language identifier; and generating the candidate encoding list by sequentially sorting the global standard encoding format, the local default code page, and the historical legacy standard encoding.
[0044] Specifically, language identifiers are explicitly extracted from the naming conventions of diagnostic resource files, and the priority rules of candidate codes are fixedly divided into three levels: those with high industry universality and standardization are ranked first, those with operating system native code pages are ranked second, and those with specific historical legacy standards are ranked last.
[0045] Following the principle of least surprise, which states that explicit user commands (filename identifiers) should have higher priority than implicit system default configurations, this rule makes the code list generated in the background extremely accurate.
[0046] For example, if the resource file is named strings_de.json, the system extracts the target language as 'de', overriding the current system locale. Following a hierarchical generation logic, UTF-8, as the de facto modern cross-platform standard, has the highest priority and is ranked first; next are the native code pages of German within this system locale (such as CP1252); and finally, historical standards such as ISO-8859-1. The resulting candidate encoding list is in the order [UTF-8, ISO-8859-1, CP1252].
[0047] In some embodiments, determining the target encoding based on the byte order marker specifically includes: extracting the preceding byte sequence of the byte order marker; if the preceding byte sequence is a first preset sequence, then determining the target encoding as a first format encoding; if the preceding byte sequence is a second preset sequence, then determining the target encoding as a second format encoding; if the preceding byte sequence is a third preset sequence, then determining the target encoding as a third format encoding; wherein, the first preset sequence is EFBBBF, the first format encoding is UTF-8, the second preset sequence is FFFE, the second format encoding is little-endian UTF-16, the third preset sequence is FEFF, and the third format encoding is big-endian UTF-16.
[0048] Specifically, a fast determination channel is provided for specification documents containing byte order markers. By extracting the first 2 to 3 hexadecimal bytes and hard-coding them against a pre-defined mapping table, the character set type can be accurately identified.
[0049] In addition to indicating the character encoding, it also explicitly indicates the byte storage order of the underlying hardware, ensuring consistency of multi-byte encoding when reading data across platform architectures.
[0050] For example, when the parsing engine finds that the extracted preceding byte sequence is the first preset sequence EFBBBF at the very beginning of the byte stream, it means that the text conforms to the optional BOM specification of UTF-8, and immediately returns its corresponding first format encoding (UTF-8) to the main process, and the system no longer wastes resources to make heuristic inferences about subsequent content.
[0051] In some embodiments, the step of performing feature verification on the decoded text to obtain text features in multiple dimensions specifically includes: extracting each character in the decoded text; determining whether the character falls within a preset character set interval corresponding to the target language identifier; obtaining the interval character ratio based on the number of characters falling within the preset character set interval; using the interval character ratio as the language feature matching degree; and pre-configuring multiple sets of preset character set intervals corresponding to Chinese text, Japanese text, and German text, respectively.
[0052] Specifically, after performing preliminary decoding on a sample, the statistical characteristics of linguistics are utilized to check the physical section where the generated character is located in the Unicode encoding table, and the frequency of characters that conform to the inherent character distribution of the specific language is counted.
[0053] The unique encoding distribution rule of each language is utilized, such that even in the absence of complete service context, it is possible to efficiently and intuitively reflect whether the candidate encoding parsing result is correct.
[0054] Exemplarily, if the target language to be detected is Chinese, it is verified whether the decoded text contains a large number of Chinese characters located in the Unicode range U+4E00–U+9FFF; if the target language is Japanese, the Kana in the interval U+3040–U+30FF is scanned as a priority. The more characters that hit this interval, the higher the language feature matching score of the candidate encoding will be.
[0055] In some embodiments, the performing feature verification on the decoded text to obtain multi-dimensional text features specifically further includes: acquiring a pre-set service term dictionary; extracting anchor keywords corresponding to the target language identifier from the service term dictionary; performing vocabulary retrieval in the decoded text; if the anchor keyword is retrieved, determining the hit status of the anchor keyword as hit; if the anchor keyword is not retrieved, determining the hit status of the anchor keyword as non-hit.
[0056] Specifically, a multi-language high-frequency vocabulary list for a specific industry (such as the automotive after-sales OTA platform) is pre-built, and string comparison and retrieval are performed in the short text obtained by test decoding, to verify whether these core service vocabularies appear therein.
[0057] The method jumps from underlying statistical features to the semantic cognition level, and greatly improves the determination confidence through strongly associated service anchors, which is especially applicable to edge scenarios where character sets are similar and difficult to distinguish by relying solely on interval distribution.
[0058] Exemplarily, the pre-set service term dictionary includes the English anchor word "Diagnostic", the Chinese anchor word "诊断", and the Japanese anchor word "診断". In the text obtained by decoding using a certain candidate encoding, if the text pattern matching algorithm successfully finds the phrase "诊断", the corresponding hit status of the anchor keyword will be triggered, and this candidate encoding will obtain a high weight bonus in subsequent scoring.
[0059] In some embodiments, the step of weighting and scoring each candidate code based on the multiple dimensions of text features to obtain a comprehensive score for each candidate code specifically includes: obtaining the illegal sequence indication state; if the illegal sequence indication state indicates the presence of illegal bytes, determining that the corresponding candidate code has failed to decode, and assigning a negative score to the candidate code that failed to decode; if the illegal sequence indication state indicates the absence of illegal bytes, obtaining a preset set of feature weights; and weighting and summing the printable character rate, the language feature matching degree, and the anchor keyword hit state according to the set of feature weights to obtain the comprehensive score.
[0060] Specifically, a multi-dimensional weighted scoring function is set up. First, a hard error-checking barrier based on illegal sequences is established (i.e., a veto). Only if the legality indicator function is met is the other three positive verification indicators (printability rate, language segment, and business vocabulary) called, multiplied by their pre-assigned weights, and summed.
[0061] By integrating hard-scanning with positive probability inference at the algorithm level, invalid encoding formats that appear to be normal in some parts but contain a large amount of underlying error data can be filtered out with high accuracy.
[0062] For example, the negative score for a veto is set to -100, the printable character rate has a weight of 20, the language feature matching degree has a weight of 30, and the anchor keyword hit status has a weight of 40. If a candidate code throws an exception during decoding, its score of -100 is immediately discarded; if decoding is smooth and it falls into the target language segment and hits the keyword, its final score is 0+20+30+40=90 points, thus securing its position as the top scorer and being adopted.
[0063] In some embodiments, the method further includes: obtaining the file path of the target language resource file; combining the file path, the target encoding, and the target language identifier into a cache record; writing the cache record into a local database; obtaining the file modification status of the current resource file during the next diagnostic startup; if the file modification status is unmodified, querying the corresponding cache record in the local database; directly extracting and using the target encoding of the current file based on the queried cache record; if the file modification status is modified, returning to execute the reading of the first few bytes of the target language resource file to redetermine the target encoding of the target language resource file.
[0064] Specifically, after successfully completing a complex encoding recognition and analysis, the recognition results and their corresponding file fingerprints (such as the last modification timestamp or file hash value) are persistently saved to lightweight local storage for quick retrieval in subsequent processes.
[0065] A non-intrusive caching acceleration mechanism is introduced, which greatly reduces the performance loss caused by the execution of the coding inference algorithm every time the diagnostic software starts, and can ensure the ultimate startup efficiency when supporting embedded diagnostic terminals.
[0066] For example, after the detection is completed, the file path, detection encoding as UTF-8, and target language as de is written to the local SQLite database. When the technician opens the software again the next day, the system first compares the timestamp of the resource file. Finding no changes, it directly reads the file using the cached UTF-8 encoding, skipping the duplicate detection process (actual single-file detection time is less than 15ms), ensuring smooth software startup. If the developer later modifies and saves the resource file, and the system detects the modification, the current cached record is invalidated, and the system automatically returns to rereading the first 1024 bytes of samples and performing multi-level feature scoring verification, achieving adaptive hot update capability.
[0067] Please see Figure 3 As shown, in one embodiment, a multilingual encoding automatic detection and adaptation device based on the fusion of operating environment and text features is provided. The device includes: The information acquisition and list generation module 201 is used to acquire the current operating system's runtime environment information; acquire the target language identifier of the multilingual interface; and generate a corresponding candidate encoding list based on the runtime environment information and the target language identifier. The sample reading module 202 is used to read the first few bytes of the target language resource file; obtain the original byte stream by reading the first few bytes; and use the original byte stream as a detection sample. The marker detection module 203 is used to perform byte order marker detection on the detection sample; if a byte order marker exists in the detection sample, the target encoding is directly determined based on the byte order marker. The candidate decoding module 204 is used to traverse the candidate encoding list if there is no byte order mark in the detected sample; decode the detected sample according to each candidate encoding in the candidate encoding list; and obtain the corresponding decoded text through the decoding operation. The feature verification module 205 is used to perform feature verification on the decoded text to obtain text features in multiple dimensions; the text features include illegal sequence indication state, printable character rate, language feature matching degree, and anchor keyword hit state; The weighted scoring module 206 is used to perform weighted scoring on each candidate code based on the text features of the multiple dimensions to obtain a comprehensive score for each candidate code. The coding filtering module 207 is used to filter out the candidate codes with the highest comprehensive score and a score greater than zero; and to use the filtered candidate codes as the target codes. The reading and rendering module 208 is used to read the target language resource file according to the target encoding; convert the read text into an internal unified encoding; and perform interface rendering according to the internal unified encoding.
[0068] In one embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 4 As shown, the computer device includes a processor, memory, network interface, and database connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile and / or volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and database. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The network interface is used to communicate with external clients via a network connection. When executed by the processor, the computer program implements the functions or steps of a coding adaptation method based on dual-feature fusion.
[0069] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the computer program, performs the following steps: Obtain the current operating system's runtime environment information, obtain the target language identifier for the multilingual interface, and generate a corresponding candidate encoding list based on the runtime environment information and the target language identifier; Read the first few bytes of the target language resource file to obtain the raw byte stream; use the raw byte stream as a detection sample. Perform byte order mark detection on the test samples; If a byte order marker exists in the detected sample, the target encoding is determined based on the byte order marker. If there is no byte order marker in the detected sample, the candidate encoding list is traversed; the detected sample is decoded according to each candidate encoding in the candidate encoding list to obtain the corresponding decoded text; The decoded text is subjected to feature verification to obtain text features in multiple dimensions; the text features include illegal sequence indication state, printable character rate, language feature matching degree, and anchor keyword hit state; Each candidate code is weighted and scored based on the text features of the multiple dimensions to obtain a comprehensive score for each candidate code. The candidate codes with the highest comprehensive scores and scores greater than zero are selected and used as the target codes. The target language resource file is read according to the target encoding, the read text is converted into an internal unified encoding, and the interface is rendered according to the internal unified encoding.
[0070] This application generates a candidate encoding list by obtaining the current operating system's runtime environment information and target language identifiers, and extracts the first bytes of the resource file as a detection sample for byte order mark detection. In the absence of byte order marks, the candidate encoding list is used to decode the detection sample. Further, multiple dimensions of feature verification are performed, including illegal sequence indication status, printable character rate, language feature matching degree, and anchor keyword hit status, and weighted scoring is applied. Finally, the encoding with the highest comprehensive score is selected as the target encoding for reading the resource file. This application narrows the initial encoding speculation range by utilizing runtime environment information and replaces the traditional method of fixed encoding in existing technologies by quantitatively verifying the actual text content in multiple dimensions such as character legality, language feature range, and business keywords. Even when the resource file encoding format is mixed and byte order marks are missing, it can adaptively detect and determine the file's true encoding, thereby accurately converting heterogeneous resource files into an internally unified encoding for interface rendering. This effectively avoids text garbled characters caused by encoding mismatch during cross-region deployment, improving system compatibility and automation.
[0071] In one embodiment, a computer-readable storage medium is provided that stores a computer program, which, when executed by a processor, performs the following steps: Obtain the current operating system's runtime environment information, obtain the target language identifier for the multilingual interface, and generate a corresponding candidate encoding list based on the runtime environment information and the target language identifier; Read the first few bytes of the target language resource file to obtain the raw byte stream; use the raw byte stream as a detection sample. Perform byte order mark detection on the test samples; If a byte order marker exists in the detected sample, the target encoding is determined based on the byte order marker. If there is no byte order marker in the detected sample, the candidate encoding list is traversed; the detected sample is decoded according to each candidate encoding in the candidate encoding list to obtain the corresponding decoded text; The decoded text is subjected to feature verification to obtain text features in multiple dimensions; the text features include illegal sequence indication state, printable character rate, language feature matching degree, and anchor keyword hit state; Each candidate code is weighted and scored based on the text features of the multiple dimensions to obtain a comprehensive score for each candidate code. The candidate codes with the highest comprehensive scores and scores greater than zero are selected and used as the target codes. The target language resource file is read according to the target encoding, the read text is converted into an internal unified encoding, and the interface is rendered according to the internal unified encoding.
[0072] This application generates a candidate encoding list by obtaining the current operating system's runtime environment information and target language identifiers, and extracts the first bytes of the resource file as a detection sample for byte order mark detection. In the absence of byte order marks, the candidate encoding list is used to decode the detection sample. Further, multiple dimensions of feature verification are performed, including illegal sequence indication status, printable character rate, language feature matching degree, and anchor keyword hit status, and weighted scoring is applied. Finally, the encoding with the highest comprehensive score is selected as the target encoding for reading the resource file. This application narrows the initial encoding speculation range by utilizing runtime environment information and replaces the traditional method of fixed encoding in existing technologies by quantitatively verifying the actual text content in multiple dimensions such as character legality, language feature range, and business keywords. Even when the resource file encoding format is mixed and byte order marks are missing, it can adaptively detect and determine the file's true encoding, thereby accurately converting heterogeneous resource files into an internally unified encoding for interface rendering. This effectively avoids text garbled characters caused by encoding mismatch during cross-region deployment, improving system compatibility and automation.
[0073] It should be noted that the functions or steps that can be implemented by the computer-readable storage medium or computer device described above can be referred to the relevant descriptions on the server side and client side in the foregoing method embodiments. To avoid repetition, they will not be described one by one here.
[0074] Those skilled in the art will understand that all or part of the processes in the methods of 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, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), Rambus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0075] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is used as an example. In practical applications, the above functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.
[0076] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be included within the protection scope of this application.
Claims
1. A coding adaptation method based on dual-feature fusion, characterized in that, The term includes: Obtain the current operating system's runtime environment information and the target language identifier for the multilingual interface, and generate a corresponding candidate encoding list based on the runtime environment information and the target language identifier; Read the first bytes of the target language resource file to obtain the raw byte stream, and use the raw byte stream as a detection sample; Perform byte order mark detection on the test samples; If a byte order marker exists in the detected sample, the target encoding is determined based on the byte order marker. If there is no byte order mark in the detected sample, the candidate encoding list is traversed, and the detected sample is decoded according to each candidate encoding in the candidate encoding list to obtain the corresponding decoded text; The decoded text is subjected to feature verification to obtain text features in multiple dimensions; the text features include illegal sequence indication state, printable character rate, language feature matching degree, and anchor keyword hit state; Each candidate code is weighted and scored based on the text features of the multiple dimensions to obtain a comprehensive score for each candidate code. The candidate codes with the highest comprehensive scores and scores greater than zero are selected and used as the target codes. The target language resource file is read according to the target encoding, the read text is converted into an internal unified encoding, and the interface is rendered according to the internal unified encoding.
2. The coding adaptation method based on dual-feature fusion according to claim 1, characterized in that, The target language identifier of the multilingual interface is obtained; Based on the runtime environment information and the target language identifier, a corresponding candidate encoding list is generated, specifically including: Obtain the filename of the target language resource file and identify the language identifier characters in the filename; Use the language identifier characters as the target language identifier; Obtain the preset global standard encoding format; Obtain the local default code page corresponding to the runtime environment information; Obtain the historical legacy standard code corresponding to the target language identifier; The candidate encoding list is generated by sequentially sorting the global standard encoding format, the local default code page, and the historical legacy standard encoding.
3. The coding adaptation method based on dual-feature fusion according to claim 1, characterized in that, The step of determining the target encoding based on the byte order mark specifically includes: Extract the preceding byte sequence of the byte order marker; If the preceding byte sequence is a first preset sequence, then the target encoding is determined to be a first format encoding; If the preceding byte sequence is a second preset sequence, then the target encoding is determined to be a second format encoding; If the preceding byte sequence is a third preset sequence, then the target encoding is determined to be a third format encoding; Wherein, the first preset sequence is EFBBBF, the first format encoding is UTF-8, the second preset sequence is FFFE, the second format encoding is little-endian UTF-16, the third preset sequence is FEFF, and the third format encoding is big-endian UTF-16.
4. The coding adaptation method based on dual feature fusion according to claim 1, characterized in that, The step of performing feature verification on the decoded text to obtain text features in multiple dimensions specifically includes: Extract each character from the decoded text; Determine whether the character falls within the preset character set range corresponding to the target language identifier; The percentage of characters in a given character set is obtained based on the number of characters falling within that set. The proportion of characters in the specified interval is used as the language feature matching degree; The preset character set ranges are pre-configured to correspond to Chinese text, Japanese text, and German text, respectively.
5. The coding adaptation method based on dual feature fusion according to claim 1, characterized in that, The step of performing feature verification on the decoded text to obtain text features in multiple dimensions further includes: Retrieve a pre-set dictionary of business terms; Extract the anchor keywords corresponding to the target language identifier from the business terminology dictionary; Perform vocabulary retrieval in the decoded text; If the anchor keyword is found, the anchor keyword hit status is determined to be a hit; If the anchor keyword is not found, the anchor keyword hit status is determined as not hit.
6. The coding adaptation method based on dual feature fusion according to claim 1, characterized in that, The step of weighting and scoring each candidate code based on the multiple dimensions of text features to obtain a comprehensive score for each candidate code specifically includes: Obtain the illegal sequence indication status; If the illegal sequence indicates the presence of illegal bytes, the corresponding candidate code is determined to have failed to decode, and a negative score is assigned to the candidate code that failed to decode. If the illegal sequence indication state is that there are no illegal bytes, obtain the preset feature weight set; Based on the set of feature weights, the printable character rate, the language feature matching degree, and the anchor keyword hit status are weighted and summed to obtain the comprehensive score.
7. The coding adaptation method based on dual-feature fusion according to claim 1, characterized in that, The method further includes: Obtain the file path of the target language resource file; Combine the file path, the target encoding, and the target language identifier into a single cache record; Write the cached records to the local database; The next time diagnostics are initiated, the file modification status of the current resource files will be retrieved; If the file modification status is "unmodified", query the corresponding cache record in the local database; based on the queried cache record, directly extract and use the target encoding of the current file; If the file modification status is "modified", return to the step of reading the first few bytes of the target language resource file to redetermine the target encoding of the target language resource file.
8. A multilingual encoding automatic detection and adaptation device based on the fusion of operating environment and text features, characterized in that, The device includes: The information acquisition and list generation module is used to acquire the current operating system's runtime environment information and the target language identifier of the multilingual interface, and generate a corresponding candidate encoding list based on the runtime environment information and the target language identifier. The sample reading module is used to read the first bytes of the target language resource file, obtain the raw byte stream, and use the raw byte stream as a detection sample. A marker detection module is used to perform byte order marker detection on the detection sample; if a byte order marker exists in the detection sample, the target encoding is determined based on the byte order marker. The candidate decoding module is used to, if there is no byte order mark in the detected sample, traverse the candidate encoding list and decode the detected sample according to each candidate encoding in the candidate encoding list to obtain the corresponding decoded text; The feature verification module is used to perform feature verification on the decoded text to obtain text features in multiple dimensions; the text features include illegal sequence indication state, printable character rate, language feature matching degree, and anchor keyword hit state; The weighted scoring module is used to assign a weighted score to each candidate code based on the text features of the multiple dimensions, and obtain a comprehensive score for each candidate code. The coding filtering module is used to filter out the candidate codes with the highest comprehensive score and a score greater than zero; and to use the filtered candidate codes as the target codes. The reading and rendering module is used to read the target language resource file according to the target encoding; convert the read text into an internal unified encoding; and perform interface rendering according to the internal unified encoding.
9. A computer device, characterized in that, The computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the coding adaptation method based on dual feature fusion as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the coding adaptation method based on dual feature fusion as described in any one of claims 1 to 7.
