A method and system for parsing a syntax

By using a bidirectional long short-term memory network and a graph neural network in syntactic processing, the problems of inaccurate clause boundary identification and semantic absurdity in traditional syntax analysis are solved. Robust handling of punctuation misidentification and intelligent completion of incomplete sentences are achieved, improving the accuracy of syntax analysis and user experience.

CN123140031APending Publication Date: 2026-11-20读书郎教育科技有限公司
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202611210889.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-11
Publication Date
2026-11-20

AI Technical Summary

Technical Problem

In existing technologies, grammatical analysis methods rely excessively on punctuation rules, resulting in inaccurate sentence boundary recognition, a lack of deep semantic verification mechanisms, an inability to effectively identify semantically absurd sentences, and an inability to intelligently complete incomplete sentences.

Method used

Text processing is performed using a bidirectional long short-term memory network combined with an attention mechanism. The segmentation probability is dynamically calculated and segmentation points are generated. A pre-trained language model and a graph neural network are combined to comprehensively evaluate grammatical accuracy, semantic rationality, and contextual coherence. The graph neural network is used to predict missing grammatical components and generate completion strategies.

Benefits of technology

It improved sentence segmentation accuracy, reduced semantic misjudgment rate, significantly improved the success rate of structured processing of incomplete sentences, and enhanced the robustness of grammatical analysis and user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123140031A_ABST
    Figure CN123140031A_ABST
Patent Text Reader

Abstract

The present application relates to the technical field of computer, and especially relates to a syntax analysis method and system, which realizes intelligent syntax analysis through a three-level neural network collaborative architecture, a dynamic segmentation layer adopts a bidirectional LSTM combined with an attention mechanism to process an input text stream, dynamically calculates a segmentation probability and generates a sentence boundary, so as to resist punctuation symbol misrecognition noise; a semantic verification layer calculates a sentence coherence comprehensive score from three dimensions of grammatical correctness, semantic rationality and contextual coherence by using a pre-trained language model, and filters sentences that are grammatically correct but semantically absurd; a structure completion layer predicts missing components and generates candidate completion strategies based on a syntax component dependency relation graph through a graph neural network. The present application also integrates a multi-language processing module, a handwriting adaptation module and a streaming real-time processing module to support mixed language filtering, handwriting noise anti-interference and real-time speech segmentation, effectively improving the sentence segmentation accuracy, semantic filtering capability and incomplete sentence processing success rate.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer technology, and in particular to a syntax analysis method and system. Background Technology

[0002] When performing grammatical analysis, traditional methods for intelligent learning devices typically rely solely on punctuation rules for text segmentation, which has significant limitations. Traditional methods cannot effectively handle situations where punctuation is scanned multiple times or missed; for example, scanning the same punctuation mark multiple times can lead to incorrect grammatical analysis results. Current technologies lack mechanisms to verify the semantic coherence of the segmented text, making it difficult to identify grammatically correct but semantically absurd sentences. When encountering incomplete sentences, existing systems often only provide error messages and cannot perform intelligent completion. These problems are particularly pronounced in complex scenarios such as mixed-language text and handwriting recognition, severely impacting the accuracy of grammatical analysis and user experience.

[0003] Chinese Patent Publication No. CN121255203A discloses a syntax analysis method and system based on phased checking, including initialization, lexical analysis, syntax analysis, error handling, and report generation stages. The initialization stage loads the code of the file to be analyzed and completes the analyzer resource initialization before passing it to the lexical analyzer. A lazy loading strategy is used to load the file and a file index table is established to record the dependencies between files. The lexical analysis stage uses a double-buffer design to perform streaming processing on the file code character stream, identifies and classifies token sequences using a finite state machine, and generates token sequences, which are then passed to the syntax analyzer. The syntax analysis stage verifies the correctness of the token sequence syntax structure based on predefined syntax rules and constructs an abstract syntax tree. The error handling stage collects error information in real time, determines whether it is a fatal error based on a three-level error handling mechanism, stops analysis if it is, and continues execution after error recovery processing if not. The report generation stage generates an error report based on the error information, determines the error location based on a token stream position tracking algorithm, and provides a repair strategy in conjunction with an error pattern library.

[0004] Existing text segmentation methods rely excessively on punctuation rules, making them unable to effectively resist noise interference such as misidentification of punctuation (e.g., multiple scans, missed scans), leading to inaccurate sentence boundary identification. Existing grammar detection technologies lack in-depth semantic coherence verification mechanisms, failing to effectively identify and filter invalid sentences with correct grammatical structure but absurd semantic logic. Existing analysis systems lack effective grammatical component prediction mechanisms when faced with incomplete sentences, failing to intelligently complete missing grammatical structures. Summary of the Invention

[0005] To address these issues, this invention provides a grammatical analysis method to solve the problems in existing technologies, such as inaccurate sentence boundary identification due to over-reliance on punctuation rules, inability to filter semantically absurd sentences due to lack of deep semantic verification mechanisms, and lack of effective grammatical component prediction and intelligent completion mechanisms when faced with structurally incomplete sentences.

[0006] To achieve the above objectives, the present invention provides a syntax analysis method, comprising:

[0007] The text stream is processed through a bidirectional long short-term memory network combined with an attention mechanism, and contextual semantic features are extracted character by character using a window sliding method.

[0008] Based on the contextual semantic features, the segmentation probability of the current character position is dynamically calculated. When the segmentation probability exceeds a preset threshold, a segmentation point is generated to segment the input text stream into sentences at different segmentation points.

[0009] For each segmentation point, a pre-trained language model is used to calculate the probability scores from three dimensions: grammatical accuracy, semantic reasonableness probability, and contextual coherence probability. The scores are then weighted to obtain the overall sentence coherence score.

[0010] Based on the corresponding sentence coherence comprehensive score and the preset threshold, it is determined whether to retain the sentence or generate an error correction candidate strategy;

[0011] If a candidate error correction strategy is determined, it is used to identify incomplete sentences with incomplete structures for sentences that have not been retained, and to establish a grammatical component dependency graph.

[0012] The dependency graph is processed by a graph neural network, and combined with word frequency statistics from the corpus, missing grammatical components are predicted and candidate completion strategies are generated in order of confidence.

[0013] In the dynamic segmentation unit, the segmentation probability is calculated according to the following formula:

[0014]

[0015] Where W is the trainable weight matrix obtained through model training. σ is the hidden state output by the bidirectional long short-term memory network at time step t. The hidden state integrates the contextual semantic information before and after the current position. σ is the sigmoid activation function, which is used to map the calculation result to the interval [0,1] to represent the probability value.

[0016] In the semantic verification layer, the sentence coherence score is calculated according to the following formula:

[0017]

[0018] Wherein, α, β, and γ are the preset weight coefficients corresponding to grammatical correctness, semantic rationality, and contextual coherence, respectively; P_grammar is determined by the grammatical structure score output by the pre-trained language model and is used to represent the probability that the clause conforms to the grammatical rules of the target language; P_semantic is determined by the semantic matching score output by external knowledge graph inference and is used to represent the probability that the clause is logically reasonable; P_context is determined by the encoding output of the pre-trained language model of the context and is used to represent the probability that the clause is semantically coherent with the preceding and following text.

[0019] In the structure completion layer, the graph neural network makes predictions according to the following formula:

[0020]

[0021] Wherein, D is a dependency graph, where nodes represent grammatical components and connections between nodes represent dependency relationships between grammatical components; E is an edge feature, where edge features represent the type of dependency relationship; the graph neural network predicts the type and location of missing grammatical components by iteratively updating the node and edge states in the dependency graph, and generates one or more candidate completion strategies by combining the word frequency statistics results of the corpus.

[0022] The method further includes at least one of the following extended processing modules:

[0023] The multilingual processing module is used to add a language recognition branch to the semantic verification layer, automatically detect and identify the target language type of the input text, and mark and filter or replace non-target language content to support the processing of mixed language text.

[0024] The handwriting adaptation module is used to incorporate a handwriting recognition error model into the dynamic segmentation layer and generate multiple handwriting font variants through adversarial training to expand the training dataset and resist character noise interference introduced during the handwriting recognition process.

[0025] The real-time processing module is used to set the dynamic segmentation layer to streaming processing mode, supporting the input text to be sent in segment by segment in the form of a data stream and the segmentation results to be output in real time, so as to meet the continuous speech segmentation requirements of real-time speech transcription scenarios.

[0026] The present invention also provides a three-level neural network collaborative analysis device, comprising:

[0027] The dynamic segmentation unit is used to implement the function of the dynamic segmentation layer as described above.

[0028] The semantic verification unit is used to implement the functions of the semantic verification layer as described above.

[0029] The structural completion unit is used to implement the function of the structural completion layer as described above.

[0030] The dynamic segmentation unit, the semantic verification unit, and the structural completion unit are cascaded in sequence, with the output of the previous unit serving as the input of the next unit, forming a collaborative processing architecture of a three-level neural network.

[0031] The invention also provides an electronic device 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 method described above.

[0032] The present invention also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the method described above.

[0033] The method is applicable to at least one of the following application scenarios:

[0034] Mixed-language text analysis scenario: When the input text contains multiple languages, the multilingual processing module automatically identifies and filters non-target language content, and outputs pure target language sentence segmentation results;

[0035] In the digitization of handwritten notes: when performing syntactic analysis on the handwriting recognition result text, the handwriting adaptation module eliminates character noise introduced by handwriting recognition through an error model, thereby improving the accuracy of sentence segmentation and semantic verification;

[0036] Real-time spoken transcription analysis scenario: When processing the text stream generated from continuous speech transcription in real time, the real-time processing module dynamically segments the speech text in a streaming mode, supporting the real-time response requirements of transcription and analysis simultaneously.

[0037] The beneficial effects of this invention are as follows: This invention achieves robust handling of punctuation misidentification through a three-level neural network collaborative architecture. The dynamic segmentation layer uses a bidirectional LSTM combined with an attention mechanism to calculate segmentation probabilities in real time, enabling dynamic merging of continuous punctuation noise into single sentences and labeling them with abnormal features, significantly improving sentence segmentation accuracy compared to traditional rule-based methods. The semantic verification layer based on the SVE scoring system comprehensively quantifies and evaluates sentence segmentation from three dimensions: grammatical correctness, semantic rationality, and contextual coherence. This effectively identifies and filters grammatically correct but semantically absurd sentences, significantly reducing the semantic misjudgment rate. The structural completion layer uses a graph neural network to iteratively process the dependency graph, accurately predicting missing grammatical components and generating candidate completion strategies ranked by confidence, significantly improving the success rate of structuring incomplete sentences. Attached Figure Description

[0038] Figure 1This is a schematic diagram of the structure of the syntax analysis system according to an embodiment of the present invention;

[0039] Figure 2 This is a flowchart illustrating the steps of the syntax analysis method according to an embodiment of the present invention;

[0040] Figure 3 This is a schematic diagram of the BiLSTM+Attention structure of the dynamic segmentation layer in an embodiment of the present invention;

[0041] Figure 4 This is a block diagram of the dependency relationship in the GNN processing of the structural completion layer in an embodiment of the present invention. Detailed Implementation

[0042] To make the objectives and advantages of the present invention clearer, the present invention will be further described below with reference to embodiments; it should be understood that the specific embodiments described herein are merely for explaining the present invention and are not intended to limit the present invention.

[0043] Preferred embodiments of the present invention will now be described with reference to the accompanying drawings. Those skilled in the art should understand that these embodiments are merely illustrative of the technical principles of the present invention and are not intended to limit the scope of protection of the present invention.

[0044] Please see Figure 1 This is a schematic diagram of the structure of the syntax analysis system according to an embodiment of the present invention. The system described in the embodiment includes:

[0045] The dynamic segmentation unit is used to process the input text stream through a bidirectional long short-term memory network combined with an attention mechanism. It extracts contextual semantic features character by character in a window sliding manner, dynamically calculates the segmentation probability of the current character position, and generates a segmentation point when the segmentation probability exceeds a preset threshold. This is used to segment the input text stream into sentences and to merge continuous punctuation noise caused by misidentification of punctuation marks and label abnormal features.

[0046] A semantic verification unit, connected to the dynamic segmentation unit, is used to calculate probability scores for each sentence output by the dynamic segmentation layer from three dimensions: grammatical correctness, semantic rationality, and contextual coherence, using a pre-trained language model. The scores are then weighted and fused according to preset weight coefficients to obtain a comprehensive sentence coherence score. If the comprehensive sentence coherence score exceeds a preset threshold, the sentence is retained; otherwise, the sentence is filtered and a candidate error correction strategy is generated.

[0047] A structural completion unit, connected to the structural completion unit, is used to establish a grammatical component dependency graph for incomplete sentences that have passed the semantic verification layer. The dependency graph is then processed by a graph neural network, and combined with word frequency statistics from the corpus, missing grammatical components are predicted and candidate completion strategies are generated in order of confidence.

[0048] Please see Figure 2 This is a flowchart illustrating the steps of the syntax analysis method according to an embodiment of the present invention. The method described in the embodiment includes:

[0049] Step S1: Process the text stream through a bidirectional long short-term memory network combined with an attention mechanism, and extract contextual semantic features character by character using a window sliding method;

[0050] Specifically, the system receives the input text stream and processes it using a bidirectional long short-term memory network (BiLSTM) combined with an attention mechanism.

[0051] Please see Figure 3 This is a schematic diagram of the dynamic cut-layer BiLSTM+Attention structure in an embodiment of the present invention. In this embodiment, the input text stream is input into the bidirectional long short-term memory network character by character. The system sets the window size to 5 characters and processes the character sequence from both forward and backward directions. At each time step, the hidden state that fuses bidirectional contextual information is output. This hidden state is the contextual semantic feature of the current position.

[0052] Taking the input text "Hello world! ! !" as an example, the system processes the character sequence in both forward and backward directions. When processing the character 'd', the forward LSTM captures the contextual information of "Hello world," and the backward LSTM captures the contextual information of the subsequent punctuation sequence "! ! !". These two sequences are concatenated to form a hidden state that integrates complete contextual information; this state serves as the contextual semantic feature for the character 'd' position. Through this method, the system extracts the contextual semantic features of each position character by character, providing a feature base for subsequent dynamic sentence segmentation.

[0053] By using a bidirectional long short-term memory network to process character sequences simultaneously from both directions, the hidden state at each position can be integrated with complete contextual semantic information, overcoming the shortcomings of traditional methods that rely only on local punctuation marks and ignore the context. By setting the window size to 5 characters, the model takes into account both local details and global context when extracting features, providing accurate and rich feature inputs for the subsequent calculation of dynamic segmentation probabilities, thus ensuring the accuracy of sentence segmentation decisions from the source.

[0054] Step S2: Based on the contextual semantic features, dynamically calculate the segmentation probability of the current character position. When the segmentation probability exceeds a preset threshold, generate a segmentation point to segment the input text stream into sentences at different segmentation points.

[0055] Specifically, the hidden state output from step S1 is input into a fully connected layer in the neural network for linear transformation, and the transformation result is mapped to the interval between 0 and 1 using a sigmoid activation function to output the segmentation probability of the current character position. The system preset threshold is 0.7. Based on the comparison between the segmentation probability corresponding to each character position and the preset threshold, a segmentation point is generated when the segmentation probability is greater than 0.7, thereby determining all segmentation points in the input text stream. According to the position of each segmentation point in the input text stream, the input text stream is divided into several sentence units. At the same time, continuous punctuation noise caused by misidentification of punctuation marks is merged.

[0056] When the system encounters consecutive punctuation noise (!!), the model calculates a segmentation probability of 0.87 based on the contextual semantic features of each character position. Since 0.87 exceeds the preset threshold of 0.7, the system determines that this consecutive punctuation sequence should not be segmented into multiple sentences and dynamically merges it into a single sentence. That is, "Hello world!!" is preserved as a complete sentence unit, instead of being segmented into "Hello world!", "!", and "!" at the "!" position. The system labels the output with punctuation anomaly features so that subsequent processing modules can understand that the sentence previously contained punctuation noise.

[0057] By mapping contextual semantic features to segmentation probabilities between 0 and 1, and quantifying the confidence of each character position as the sentence boundary with probability values, this method effectively overcomes the technical problem of inaccurate sentence boundary recognition caused by noise interference such as multiple or missed punctuation scans in traditional methods. By dynamically merging continuous punctuation sequence into a single sentence and labeling it with abnormal feature tags, this method achieves effective filtering of punctuation noise and traceability of abnormal information, providing accurate and reliable sentence segmentation unit input for subsequent semantic verification.

[0058] Step S3: For each segmentation point, use a pre-trained language model to calculate the probability scores of each sentence from three dimensions: grammatical accuracy, semantic rationality probability, and contextual coherence probability. Then, perform a weighted calculation to obtain the comprehensive sentence coherence score.

[0059] The semantic verification unit in this embodiment integrates a BERT model interface and a knowledge graph interface. The sentence segment is input into the pre-trained language model BERT. After encoding the sentence by the BERT model, the output vector of the marker bits is extracted as the feature basis for grammatical discrimination. After mapping through a fully connected layer, the grammatical accuracy is obtained. Key entities and relations in the sentence are input into an external knowledge graph for reasoning. Based on whether a reasonable semantic association path exists in the knowledge graph, the semantic reasonableness probability is calculated. The sentence, its preceding and subsequent sentences are input into the pre-trained language model BERT for comprehensive encoding. The encoded output of the current sentence is concatenated with the encoded outputs of the preceding and subsequent sentences. After mapping through a fully connected layer, the contextual coherence probability is obtained. The probability scores of the three dimensions are weighted and fused according to the formula SVE = α·P_grammar + β·P_semantic + γ·P_context to obtain the comprehensive sentence coherence score.

[0060] The example demonstrates semantic verification of the sentence "I drink knowledge". The BERT model calculates a grammatical accuracy of 0.92, indicating a correct grammatical structure. ConceptNet knowledge graph inference calculates a semantic plausibility probability of 0.3, indicating no logical semantic connection between "drink" and "knowledge" in the knowledge graph, and an abnormal verb-object collocation. Context encoding results calculate a contextual coherence probability of 0.8. Substituting the scores from the three dimensions into weighted coefficients α=0.4, β=0.5, and γ=0.1, the overall sentence coherence score SVE is calculated as: SVE = 0.4×0.92 + 0.5×0.3 + 0.1×0.8 = 0.598. This score comprehensively reflects the overall situation where the sentence is grammatically correct but semantically abnormal.

[0061] By calculating probability scores from three dimensions—grammatical accuracy, semantic rationality, and contextual coherence—and then weighting and fusing them according to preset weight coefficients, a multi-dimensional semantic verification scoring system (SVE) was constructed. This enables the system to conduct a comprehensive and quantitative quality assessment of sentences. By introducing external knowledge graphs for semantic rationality reasoning, the system compensates for the shortcomings of pure language models in common sense reasoning and logical judgment. This gives the system the ability to identify grammatically correct but semantically absurd sentences, significantly reducing the semantic misjudgment rate.

[0062] Step S4: Based on the corresponding sentence coherence comprehensive score and preset threshold, determine whether to retain the sentence or generate an error correction candidate strategy;

[0063] Specifically, the sentence coherence score (SVE) calculated in step S3 is compared with a preset threshold (0.5 in this embodiment). When the SVE is greater than or equal to 0.5, the sentence is determined to have passed semantic verification, the system retains the sentence, and outputs a semantic error correction candidate scheme. When the SVE is less than 0.5, the sentence is determined to have failed semantic verification, is filtered out, and a corresponding error correction candidate scheme is generated.

[0064] The sentence "I drink knowledge" has a Semantic Verbal Equation (SVE) score of 0.598. The system compares 0.598 with a preset threshold of 0.5. Since 0.598 > 0.5, the sentence passes semantic verification and is retained by the system. Simultaneously, based on the probability score distribution across various dimensions, the system identifies the verb-object collocation of "drink" and "knowledge" as an anomalous feature unit, outputting a candidate solution for semantic mismatch, recommending replacing "drink" with "learn" to form the correct expression "learn knowledge". Sentences with an SVE score below 0.5 are filtered out by the system and not processed further.

[0065] By comparing the overall sentence coherence score with a preset threshold, the system achieves automated screening of sentence quality. This retains high-quality sentences for downstream tasks while filtering out low-quality sentences to avoid interference with subsequent analysis. While retaining sentences, the system proactively outputs semantic error correction candidate solutions, enabling users to identify specific semantic problems in sentences and receive improvement suggestions, thus enhancing the system's usability and user experience.

[0066] Step S5: If a candidate error correction strategy is determined, it is used to identify incomplete sentences with incomplete structures for sentences that have not been retained, and to establish a grammatical component dependency graph.

[0067] Specifically, for incomplete sentences determined to be structurally incomplete after semantic verification in step S4, the system performs grammatical component analysis and establishes a grammatical component dependency graph D. The nodes in the dependency graph represent grammatical components, and the edge features E between nodes represent the grammatical relationship type between the grammatical components. Identified nodes are represented by solid lines, and missing nodes are represented by dashed lines.

[0068] The clause "Yesterday..." received a SVE score higher than 0.5 after semantic verification, indicating structural incompleteness and prompting the system to proceed to the structural completion layer. The system then performed grammatical component analysis on the incomplete sentence, identifying the time adverbial node "Yesterday" as an existing grammatical component, and also identifying the missing predicate verb node. The system established an "adverbial-predicate relationship" edge between the time adverbial node and the missing predicate verb node, indicating that the grammatical relationship between them is an adverbial-predicate relationship. Through this method, the system completed the construction of the grammatical component dependency graph for the incomplete sentence, which includes one identified node, one missing node, and one edge.

[0069] By performing grammatical component analysis on incomplete sentences and establishing dependency graphs, the internal structure of incomplete sentences is explicitly modeled in the form of graph structures, providing structured input for subsequent processing of graph neural networks. By distinguishing between identified nodes and missing nodes with solid and dashed lines, the model can clearly identify the structural gaps in the current sentence, providing clear target guidance for predicting the type and location of missing components.

[0070] Step S6: Process the dependency graph using a graph neural network, combine it with corpus word frequency statistics, predict missing grammatical components, and generate candidate completion strategies sorted by confidence level.

[0071] Please see Figure 4 This is a flowchart illustrating the dependency relationship processing of the GNN in the structural completion layer of this invention. The embodiment completes the construction of the grammatical component dependency graph for the incomplete sentence. The dependency graph D constructed in step S5 and the edge features E are input into the graph neural network (GNN) to predict the missing grammatical components. The GNN performs multiple rounds of updates between nodes through a message passing mechanism, predicting the type and location of the missing grammatical components. Combined with the word frequency statistics of the corpus, it generates one or more candidate completion strategies ranked by confidence.

[0072] Following the example from step S5, the system inputs a dependency graph containing the time adverbial node "Yesterday" and the missing predicate verb node into the graph neural network. The graph neural network iterates through multiple rounds using a message-passing mechanism. Based on the state of the time adverbial node and its "adverbial-predicate relationship" edge features with the missing predicate verb, it predicts that the predicate verb node has an 86% probability of needing to connect to the past tense form of the verb. After determining the type and location of the missing component, the system combines the word frequency statistics from the corpus to filter high-frequency past tense verbs, calculating the probability of each candidate word: visited (62%), went (28%), and arrived (10%). The system sorts these by confidence level from high to low and finally outputs three completion suggestions: visited, went, and arrived. visited is selected as the optimal recommendation strategy, thus completing the incomplete sentence "Yesterday..." into "Yesterdayvisited...".

[0073] By iteratively processing the dependency graph using a graph neural network, and fully integrating the state of the node itself, the state of neighboring nodes, and edge features through message passing mechanism in multiple rounds of updates, the model can accurately predict the type and location of missing grammatical components. By combining the word frequency statistics results of the corpus to rank the candidate completion schemes, the completion results not only meet the requirements of grammatical structure, but also conform to the actual language usage habits, significantly improving the success rate of structured processing of incomplete sentences.

[0074] The technical solution of the present invention has been described above with reference to the preferred embodiments shown in the accompanying drawings. However, it will be readily understood by those skilled in the art that the scope of protection of the present invention is obviously not limited to these specific embodiments. Without departing from the principles of the present invention, those skilled in the art can make equivalent changes or substitutions to the relevant technical features, and the technical solutions after these changes or substitutions will all fall within the scope of protection of the present invention.

Claims

1. A syntax analysis method, characterized in that, include: The text stream is processed through a bidirectional long short-term memory network combined with an attention mechanism, and contextual semantic features are extracted character by character using a window sliding method. Based on the contextual semantic features, the segmentation probability of the current character position is dynamically calculated. When the segmentation probability exceeds a preset threshold, a segmentation point is generated to segment the input text stream into sentences at different segmentation points. For each segmentation point, a pre-trained language model is used to calculate the probability scores from three dimensions: grammatical accuracy, semantic reasonableness probability, and contextual coherence probability. The scores are then weighted to obtain the overall sentence coherence score. Based on the corresponding sentence coherence comprehensive score and the preset threshold, it is determined whether to retain the sentence or generate an error correction candidate strategy; If a candidate error correction strategy is determined, it is used to identify incomplete sentences with incomplete structures for sentences that have not been retained, and to establish a grammatical component dependency graph. The dependency graph is processed by a graph neural network, and combined with word frequency statistics from the corpus, missing grammatical components are predicted and candidate completion strategies are generated in order of confidence.

2. The syntax analysis method according to claim 1, characterized in that, The process of extracting contextual semantic features includes: The input text stream is fed into the Bidirectional Long Short-Term Memory (BiLSTM) network character by character, with the system window size set to 5 characters. The character sequence is processed in both forward and backward directions. At each time step, the hidden state that incorporates bidirectional contextual information is output, which is the contextual semantic feature of the current position.

3. The syntax analysis method according to claim 2, characterized in that, The process of dynamically calculating the segmentation probability of the current character position includes: The hidden state is input into a fully connected layer in the neural network for linear transformation, and the transformation result is mapped to the interval between 0 and 1 through the sigmoid activation function to output the segmentation probability of the current character position.

4. The syntax analysis method according to claim 3, characterized in that, The process of segmenting the input text stream into sentences at different points includes: Based on the comparison between the segmentation probability corresponding to each character position and the preset threshold, a segmentation point is generated when the segmentation probability is greater than the system preset threshold, thereby determining all segmentation points in the input text stream; Based on the position of each of the segmentation points in the input text stream, the input text stream is divided into several sentence units.

5. The syntax analysis method according to claim 4, characterized in that, The process of calculating each probability score includes: The sentence is input into the pre-trained language model BERT. After the sentence is encoded by the BERT model, the output vector of the marker bit is extracted as the feature basis for grammar discrimination. After mapping through a fully connected layer, the grammar accuracy is obtained. The key entities and relationships in the sentences are input into an external knowledge graph for reasoning. The semantic rationality probability is calculated based on whether there is a reasonable semantic association path in the knowledge graph. The sentence, its preceding and subsequent sentences are input into the pre-trained language model BERT for comprehensive encoding. The encoded output of the current sentence is concatenated with the encoded outputs of the preceding and subsequent sentences. After mapping through a fully connected layer, the context coherence probability is obtained.

6. The syntax analysis method according to claim 5, characterized in that, Strategies for determining whether to retain clauses or generate error correction candidates include: The overall score for sentence coherence is compared with a preset threshold; When the overall sentence coherence score is greater than or equal to the preset threshold, the sentence is determined to have passed semantic verification, the system retains the sentence, and outputs a semantic error correction candidate strategy; when the overall sentence coherence score is less than the preset threshold, the sentence is determined to have failed semantic verification, is filtered, and a corresponding error correction candidate strategy is generated.

7. The syntax analysis method according to claim 6, characterized in that, The process of constructing a grammatical component dependency graph includes: For incomplete sentences that are determined to be structurally incomplete, grammatical component analysis is performed to establish a grammatical component dependency graph D. The nodes of the dependency graph represent grammatical components, and the edge features E between the nodes represent the grammatical relationship types between the grammatical components. The dependency graph D and the edge features E are input into a graph neural network (GNN) to predict the missing grammatical components.

8. A system applying the syntax analysis method according to any one of claims 1-6, characterized in that, include: The dynamic segmentation unit is used to process the input text stream through a bidirectional long short-term memory network (BiLSTM) combined with an attention mechanism. It extracts contextual semantic features character by character in a window sliding manner, dynamically calculates the segmentation probability of the current character position, and generates a segmentation point when the segmentation probability exceeds a preset threshold. This is used to segment the input text stream into sentences and to merge continuous punctuation noise caused by misidentification of punctuation marks, and to label abnormal features. The semantic verification unit is used to calculate probability scores for each sentence output by the dynamic segmentation layer from three dimensions: grammatical correctness, semantic rationality, and contextual coherence, using a pre-trained language model. The scores are then weighted and fused according to preset weight coefficients to obtain a comprehensive sentence coherence score. If the comprehensive sentence coherence score exceeds a preset threshold, the sentence is retained; otherwise, the sentence is filtered and a candidate error correction strategy is generated. The structural completion unit is used to establish a grammatical component dependency graph for incomplete sentences that have passed the semantic verification layer. The dependency graph is then processed by a graph neural network, and combined with word frequency statistics from the corpus, the missing grammatical components are predicted and candidate completion strategies are generated in order of confidence.

Citation Information

Patent Citations

  • Grammar analysis method and system based on staged inspection

    CN121255203A