A method for detecting string expression, electronic device and storage medium
Get Cron expressions and execution time text through the graphical user interface, and use the detection model to extract and classify features, solving the problem of Cron expression detection complexity in the existing technology, realizing intelligent detection and coding accuracy of Cron expressions The judgment is suitable for beginners and improves operation and maintenance efficiency and system security.
Patent Information
- Application Number
- CN202411366730.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-29
- Publication Date
- 2024-12-24
- Estimated Expiration
- 2044-09-29
AI Technical Summary
The prior art is difficult to effectively detect and verify the correctness of Cron expressions, especially for beginners, the detection process is complicated and not intuitive, making it difficult to determine whether the expression is correct.
The graphical user interface obtains the Cron expression and execution time text input by the user, uses the pre-trained detection model to extract and classify features, and judges the encoding accuracy of the expression, including special marker annotation, word segmentation processing and vectors on the input text. Build, input feature extractors and classifiers to output detection results.
It realizes intelligent detection of Cron expressions, reduces the testing burden of programmers, and is suitable for beginners who have imperfect understanding of Cron expressions, improving operation and maintenance efficiency and system security.
Smart Images

Figure CN118886413B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a method for detecting a string expression, an electronic device, and a storage medium. Background Art
[0002] Cron expressions are an important tool for setting periodic task execution. During the development and operation process, detecting and verifying the correctness of Cron expressions becomes an important and complex task.
[0003] Although there are auxiliary tools for intelligent Cron expression detection on the market, their principle is to print out multiple execution times of Cron expressions. Not only is the number of prints limited, but it is also difficult for technicians to determine whether the expression is correct based on the printed execution time. Complex calculations or time unit conversions are also required. For beginners, it is even more difficult to detect the correctness of Cron expressions.
[0004] Therefore, developing and deploying tools that can automatically detect and verify Cron expressions is of great significance for improving operation and maintenance efficiency and ensuring system security. Summary of the invention
[0005] The purpose of the embodiments of the present application is to provide a method for detecting a string expression, an electronic device, and a storage medium, so as to realize the detection of Cron expression encoding in a scheduled task, thereby reducing the testing burden of programmers and being suitable for beginners who have an incomplete understanding of Cron expressions.
[0006] In a first aspect, the present invention provides a method for detecting a string expression, the method comprising obtaining a Cron expression of a scheduled task input by a user and a first execution time text through a graphical user interface, wherein the first execution time text is used to describe the required execution time of the scheduled task; parsing a second execution time text based on the obtained Cron expression; inputting the first execution time text and the second execution time text into a pre-trained detection model to obtain a detection result output by the detection model, the detection result being used to indicate whether the first execution time text and the second execution time text indicate the same execution time; determining whether the Cron expression is correctly encoded according to the detection result; wherein the steps of inputting the first execution time text and the second execution time text into a pre-trained detection model to obtain the detection result output by the detection model specifically include: marking the first execution time text and the second execution time text with special markers; inputting the marked first execution time text and the second execution time text into a feature extractor to extract sentence vectors and word vectors corresponding to the feature markers; constructing a first fusion vector based on the sentence vector and word vector corresponding to the first execution time text, and constructing a second fusion vector based on the sentence vector and word vector corresponding to the second execution time text; inputting the first fusion vector and the second fusion vector into a classifier to determine and output the detection result.
[0007] In an optional embodiment, the special marker includes a mask marker, a sentence start marker and a sentence end marker, and the first execution time text and the second execution time text are marked with special markers in the following manner: the first execution time text and the second execution time text are respectively reconstructed according to a preset format; a first word segmentation marker sequence corresponding to the reconstructed first execution time text and a second word segmentation marker sequence corresponding to the second execution time text are obtained; based on the degree of matching between the first word segmentation marker sequence and the second word segmentation marker sequence, it is determined whether there is a target phrase pair, each target phrase pair including a first phrase in the first execution time text and a second phrase in the second execution time text; if a target phrase pair exists, a sentence start marker is added to the beginning of the first execution time text and the second execution time text respectively; a sentence end marker is added between the first execution time text and the second execution time text; and the first phrase and the second phrase in the first execution time text and the second execution time text are replaced by the mask marker.
[0008] In an optional embodiment, the preset format includes a second domain, a minute domain, a time domain, a day domain, a month domain, a week domain and a year domain arranged in order, and the steps of reconstructing the first execution time text and the second execution time text according to the preset format respectively include: inputting the first execution time text and the second execution time text into the word segmentation model respectively to obtain the word segmentation result of the first execution time text and the word segmentation result of the second execution time text output by the word segmentation model, the word segmentation result including the phrase division of the execution time text and the domain category corresponding to the phrase; for the divided phrases, adding each phrase to the domain corresponding to the domain category to combine the reconstructed first execution time text and second execution time text.
[0009] In an optional embodiment, the step of determining whether there is a target phrase pair based on the degree of matching between the first word segmentation mark sequence and the second word segmentation mark sequence specifically includes: determining in turn whether the word segmentation marks at the same position in the first word segmentation mark sequence and the second word segmentation mark sequence are consistent; if not, determining the first phrase and the second phrase corresponding to the word segmentation mark as the target phrase pair.
[0010] In an optional embodiment, a first sentence vector corresponding to a sentence start marker in a first execution time text and a first word vector corresponding to at least one mask marker are extracted to construct a first fusion vector; a second sentence vector corresponding to a sentence start marker in a second execution time text and a second word vector corresponding to at least one mask marker are extracted to construct a second fusion vector; wherein the first / second fusion vectors are constructed in the following manner: an average value vector of at least one first / second word vector is calculated; and the first / second sentence vector is concatenated with the average value vector of the first / second word vector to construct a first / second fusion vector.
[0011] In an optional embodiment, if the target phrase pair does not exist, a sentence start marker is added to the beginning of the first execution time text and the second execution time text respectively; a sentence end marker is added between the first execution time text and the second execution time text; and the phrase at the same random position in the first execution time text and the second execution time text is replaced by a mask marker.
[0012] In an optional implementation, based on the acquired Cron expression, the step of parsing the second execution time text specifically includes: determining the target format of the Cron expression; matching the corresponding execution time text template from the database based on the target format; and for the field on the target domain in the Cron expression, adding the time parameter indicated by the field to the corresponding position in the execution time text template to generate the second execution time text.
[0013] In a second aspect, the present invention provides a device for detecting a string expression, the device comprising:
[0014] An acquisition module, used to acquire a Cron expression of a scheduled task and a first execution time text input by a user through a graphical user interface, wherein the first execution time text is used to describe the required execution time of the scheduled task;
[0015] A parsing module, used for parsing a second execution time text based on the acquired Cron expression;
[0016] A detection module is used to input the first execution time text and the second execution time text into a pre-trained detection model to obtain a detection result output by the detection model, wherein the detection result is used to indicate whether the first execution time text and the second execution time text indicate the same execution time; wherein the detection result is obtained in the following manner: the first execution time text and the second execution time text are annotated with special markers; the annotated first execution time text and the second execution time text are input into a feature extractor to extract sentence vectors and word vectors corresponding to the feature markers; a first fusion vector is constructed based on the sentence vector and word vector corresponding to the first execution time text, and a second fusion vector is constructed based on the sentence vector and word vector corresponding to the second execution time text; the first fusion vector and the second fusion vector are input into a classifier to determine and output the detection result;
[0017] The determination module is used to determine whether the Cron expression is encoded correctly according to the detection result.
[0018] In a third aspect, the present invention provides an electronic device comprising: a processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor. When the electronic device is running, the processor and the memory communicate through the bus, and the processor executes the machine-readable instructions to perform the steps of the method for detecting a string expression as described in any of the aforementioned implementations.
[0019] In a fourth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the steps of the method for detecting a string expression in any of the aforementioned implementations are executed.
[0020] The present application provides a method for detecting a string expression, an electronic device, and a storage medium, wherein the method includes obtaining a Cron expression of a scheduled task input by a user and a first execution time text through a graphical user interface, wherein the first execution time text is used to describe the required execution time of the scheduled task; parsing a second execution time text based on the obtained Cron expression; inputting the first execution time text and the second execution time text into a pre-trained detection model to obtain a detection result output by the detection model, wherein the detection result is used to indicate whether the first execution time text and the second execution time text indicate the same execution time; and determining whether the Cron expression is correctly encoded based on the detection result. Among them, the step of inputting the first execution time text and the second execution time text into a pre-trained detection model to obtain the detection result output by the detection model specifically includes: marking the first execution time text and the second execution time text with special markers; inputting the marked first execution time text and the second execution time text into a feature extractor to extract sentence vectors and word vectors corresponding to the feature markers; constructing a first fusion vector based on the sentence vector and word vector corresponding to the first execution time text, and constructing a second fusion vector based on the sentence vector and word vector corresponding to the second execution time text; inputting the first fusion vector and the second fusion vector into a classifier to determine and output the detection result, thereby realizing intelligent detection of Cron expression encoding in scheduled tasks, reducing the testing burden of programmers, and being suitable for beginners who have an incomplete understanding of Cron expressions. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments of the present application will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0022] Figure 1 A flowchart of a method for detecting a string expression provided in an embodiment of the present application;
[0023] Figure 2 A flowchart of a test result prediction step provided in an embodiment of the present application;
[0024] Figure 3 A flowchart of a text annotation step provided in an embodiment of the present application;
[0025] Figure 4 A schematic diagram of the structure of a device for detecting a string expression provided in an embodiment of the present application;
[0026] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0027] First, the application scenario of the present application is described. The technical solution of the present application is applicable to the verification of Cron expressions in scheduled task programming. The testing of scheduled tasks usually requires verification of the correctness, security, and compatibility of the scheduled task code. Among them, Cron expressions are an important part of scheduled tasks, and the correctness of Cron expressions is the key to the stable operation of the program.
[0028] However, the format of Cron expressions is relatively complex, and it is difficult for beginners to master them in a short period of time. The existing Cron expression detection method usually prints out multiple execution times of Cron expressions, which not only has a limited number of printouts, but also makes it difficult for technicians to determine whether the expression is correct based on the printed execution time, and requires complex calculations or time unit conversions, etc.
[0029] Based on this, the present application provides a method for detecting a string expression, an electronic device and a storage medium to reduce the testing burden of programmers, and can be suitable for beginners who have an incomplete understanding of Cron expressions.
[0030] The technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application.
[0031] Embodiment 1
[0032] In one embodiment of the present application, a tool for detecting the correctness of a Cron expression may be provided, which is used to automatically detect whether the Cron expression is correct by only filling in the Cron expression to be detected and the description text of the required execution time.
[0033] Figure 1 A flowchart of a method for detecting a string expression provided in an embodiment of the present application. Figure 1 As shown, a method for detecting a string expression provided in an embodiment of the present application can be executed by a detection tool, specifically including:
[0034] S1. Obtaining, through a graphical user interface, a Cron expression of a scheduled task and a first execution time text input by a user.
[0035] The graphical user interface here may be provided with a first input box and a second input box. The first input box is used to obtain the Cron expression of the scheduled task input by the user, such as "0 0 12 * * ?", "0 15 10 * * ? 2005". The second input box is used to obtain the first execution time text input by the user. The first execution time text is used to describe the required execution time of the scheduled task, that is, the correct execution time description entered by the user according to the needs of the scheduled task. For example, "trigger every 5 minutes between 2 pm and 2:55 pm and between 6 pm and 6:55 pm every day" and "execute once every Wednesday at 12 noon".
[0036] A detection control may also be provided on the graphical user interface. After the user clicks the detection control, a detection request is generated, and the detection request is responded to and step S1 is started.
[0037] S2. Based on the obtained Cron expression, parse out the second execution time text.
[0038] Here, the acquired Cron expression is converted into a second execution time text in a preset format, where the second execution time text is used to describe the Cron expression input by the user in a preset format.
[0039] Here, step S2 may include:
[0040] Determine the target format of the Cron expression. Match the corresponding execution time text template from the database based on the target format. For the field on the target domain in the Cron expression, add the time parameter indicated by the field to the corresponding position in the execution time text template to generate a second execution time text.
[0041] In one embodiment of the present application, multiple sets of conversion templates for execution time text can be preset based on the structural principle of Cron expression. For example, the expression format of the first part can be matched based on whether the field on each domain is 0. Then, based on whether the remaining domain is "*", the expression format of the second part is filtered out from the expression format of the first part. Then, based on whether the remaining domain is "?", the expression format of the second part is filtered out from the expression format of the first part.
[0042] For example, if the Cron expression is "0 0 / 5 14,18 * * ?", the first part of the expression format can be matched as "0 X1 X2 X3 X4", where Xn indicates that the field here can be other characters except 0. Then the second part of the expression format can be matched as "0 X1 X2 * *". Then the third part of the expression format can be matched as "0 X1 X2 * *, where X1=0 / x1". Furthermore, the corresponding conversion template can be obtained as "execute once every x1 minutes at X2 every day". When X1=x1, the corresponding conversion template is "execute once every x1 minutes at X2 every day".
[0043] For example, the Cron expression is "0 15 10 ? * 6L", and the converted second execution time text is "executed at 10:15 am on the 4th Friday of every month", while the first execution time text is "executed at 5:15 am on the last Friday of every month".
[0044] It should be noted that the parsing and de-parsing of Cron expressions have been widely used in the prior art, so the second execution time text conversion can also be achieved through other algorithms, which will not be described in detail here.
[0045] S3. Input the first execution time text and the second execution time text into a pre-trained detection model to obtain a detection result output by the detection model, where the detection result is used to indicate whether the first execution time text and the second execution time text indicate the same execution time.
[0046] S4. According to the detection result, determine whether the Cron expression is encoded correctly.
[0047] Since the first execution time text input by the user and the second execution time text obtained by parsing have differences in grammatical expressions, words and different character types, such as "Friday and Friday", "10 hours and ten o'clock", "the last week of each month and the fourth week of each month", therefore, in order to further verify whether the execution time expressed by the first execution time text and the second execution time text is consistent, it is considered here to use natural language processing technology to eliminate the differences between the grammatical expressions, and then accurately test whether the Cron expression is compiled correctly.
[0048] Specifically, semantic extraction and classification may be performed using a pre-trained detection model to obtain a classification result and determine whether the first execution time text and the second execution time text express the same execution time.
[0049] The present application provides a method for detecting a string expression, which realizes intelligent detection of Cron expression compilation in a scheduled task, reduces the testing burden of programmers, and is suitable for beginners who have an incomplete understanding of Cron expressions.
[0050] Embodiment 2
[0051] In one embodiment of the present application, a solution for implementing execution time text pair recognition is provided.
[0052] Figure 2 A flowchart of a test result prediction step provided in an embodiment of the present application. Figure 2 As shown, in step S3, the step of inputting the first execution time text and the second execution time text into a pre-trained detection model to obtain the detection result output by the detection model may include:
[0053] S30: Mark the first execution time text and the second execution time text with special markers.
[0054] Special markers include mask marker [MASK], sentence start marker [CLS] and sentence end marker [SEP]. In step S30, in order to eliminate the semantic impact of grammatical differences and similar word differences, the time text is converted according to the format of Cron expression, and then the similar parts are masked, and vectors are extracted in a targeted manner to obtain more accurate recognition results.
[0055] Exemplarily, the first execution time text and the second execution time text may be in the format of "every month / last Friday / 10:00 / 15:00 / executed, every month / fourth Friday / 10:00 / 15:00 / executed", where " / " is used to separate phrases in different domains and is not involved in calculations in actual implementation.
[0056] The annotated first execution time text and second execution time text may be “[CLS1] every month / [MASK1] / 10:00 / 15:00 / executed[SEP] [CLS2] every month / [MASK2] / 10:00 / 15:00 / executed”. Here, [SEP] is used to separate the two execution time texts.
[0057] S31. Input the annotated first execution time text and the second execution time text into a feature extractor to extract sentence vectors and word vectors corresponding to the feature markers.
[0058] For example, the sentence vectors corresponding to [CLS1] and [CLS2], and the word vectors corresponding to [MASK1] [MASK2] can be obtained respectively.
[0059] S32: construct a first fusion vector based on the sentence vector and the word vector corresponding to the first execution time text, and construct a second fusion vector based on the sentence vector and the word vector corresponding to the second execution time text.
[0060] Specifically, a first sentence vector corresponding to the sentence start marker in the first execution time text and a first word vector corresponding to at least one mask marker can be extracted to construct a first fused vector. A second sentence vector corresponding to the sentence start marker in the second execution time text and a second word vector corresponding to at least one mask marker can be extracted to construct a second fused vector. The first / second fused vector can be constructed in the following manner:
[0061] Calculate at least one average vector of the first / second word vector. Concatenate the first / second sentence vector with the average vector of the first / second word vector to construct a first / second fusion vector.
[0062] Taking the first execution time text as an example, the vectors corresponding to [CLS1] and [MASK1] can be fused by weighted fusion, concatenation, etc. to generate the corresponding first fused vector. The construction principle of the second fused vector is similar to that of the first fused vector. When there are multiple [MASKn] word vectors, the mean vector of multiple [MASKn] word vectors can be calculated and then concatenated with [CLS1]. Here, n is used to indicate the number of word vectors, or the number of target phrase pairs.
[0063] S33: Input the first fusion vector and the second fusion vector into a classifier to determine and output a detection result.
[0064] In a specific embodiment, the classifier here can use a binary classification algorithm, and the final output detection result includes 0 or 1. Among them, 0 is used to indicate that the first execution time text and the second execution time text indicate different execution times, and 1 is used to indicate that the first execution time text and the second execution time text indicate the same execution time. In this way, according to whether the detection result is 0 or 1, it can be determined whether the Cron expression is encoded correctly.
[0065] Figure 3 A flowchart of an execution text annotation step provided in an embodiment of the present application. Further, in step S30, the first execution time text and the second execution time text may be annotated with a special marker in the following manner:
[0066] S300: Reconstruct the first execution time text and the second execution time text respectively according to preset formats.
[0067] It is understandable that the compilation rules of Cron expressions are: seconds, minutes, hours, date, month, week, and sometimes six or seven fields including the year.
[0068] Therefore, the Chinese text of the execution time can be expressed in the format of an expression here. The advantage of this is that while determining the position of the [MASK] mask, the format of the expression can also be verified.
[0069] Taking the seven domains as an example, the preset format includes the second domain, minute domain, hour domain, day domain, month domain, week domain, and year domain arranged in sequence. The steps of reconstructing the first execution time text and the second execution time text according to the preset format respectively may include:
[0070] S3000: Input the first execution time text and the second execution time text into the word segmentation model respectively to obtain the word segmentation results of the first execution time text and the second execution time text output by the word segmentation model. The word segmentation results include the phrase division of the execution time text and the domain category corresponding to the phrase.
[0071] The word segmentation model here is trained to divide the execution time text into time domains. Exemplarily, the first execution time text is "Execute at 10:15 on the last Friday of each month", and the divided result can be "each month / last Friday / ten o'clock / fifteen / execute". The second execution time text is "Execute at 10:15 am on the 4th Friday of each month", and the divided result can be "of each month / fourth Friday / ten o'clock in the morning / fifteen minutes / execute".
[0072] Taking the second execution time text as an example, the domain category corresponding to "of each month" is the month domain, "the fourth Friday" is the week domain, "ten o'clock in the morning" is the hour domain, "fifteen minutes" is the minute domain, and "execute" is not processed and can also be used as other domain categories.
[0073] It should be noted that when there are numbers or English expressions in the execution time text, they need to be converted into Chinese before the word segmentation step. For example, "10:15" can be converted into "ten fifteen", and "the 10th day" can be converted into "the tenth day".
[0074] S3001: For the divided phrases, add each phrase to the domain corresponding to the domain category to combine the reconstructed first execution time text and the second execution time text.
[0075] In step S3001, taking the first execution time text as an example, "fifteen / ten o'clock / each month / last Friday / execute" can be obtained. Taking the second execution time text as an example, according to the preset order, each phrase is recombined, and then "fifteen minutes / ten o'clock in the morning / of each month / fourth Friday / execute" can be obtained.
[0076] In this way, the execution time text is rearranged according to the format of the Cron expression. Through the sentence vector indicated by the sentence start [CLS] vector, the compiled values between the various fields of the Cron expression can be detected from the overall arrangement.
[0077] S301: Obtain a first word segmentation token sequence corresponding to a reconstructed first execution time text and a second word segmentation token sequence corresponding to a second execution time text.
[0078] Here, the BEMS word-part marking method can be used to mark the execution time text. For example, if the reconstructed first execution time text is "15th / 10 o'clock / every month / last Friday / execution", the corresponding first word segmentation mark sequence can be "BE / BE / BE / BMMEBE / BE".
[0079] The reconstructed second execution time text is “fifteen minutes / ten o'clock in the morning / the fourth Friday of every month / executed”, and the corresponding second word segmentation token sequence can be obtained as “BES / BEBE / BES / BMEBME / BE”.
[0080] S302: Determine whether there is a target phrase pair based on the matching degree between the first word segmentation token sequence and the second word segmentation token sequence, each target phrase pair including a first phrase in the first execution time text and a second phrase in the second execution time text.
[0081] In step S302, based on the matching degree between the first word segmentation token sequence and the second word segmentation token sequence, the step of determining whether there is a target phrase pair specifically includes:
[0082] It is determined in turn whether the segmentation marks at the same position in the first segmentation mark sequence and the second segmentation mark sequence are consistent. If they are inconsistent, the first phrase and the second phrase corresponding to the segmentation mark are determined as the target phrase pair.
[0083] Specifically, one-to-one matching can be performed according to the division of phrases in different domains. For example, if the second domain is empty, the tag segment in the first word segmentation tag sequence in the sub-domain is "BE", and the tag segment in the second word segmentation tag sequence is "BES", then the similarity between "BE" and "BES" can be calculated.
[0084] The similarity calculation here may be calculated by using Levenshtein distance, Jaccard similarity or other algorithms, which are not limited here.
[0085] For a marker segment whose similarity is less than a preset value, it can be determined that the corresponding phrases are the first phrase and the second phrase. For example, "BMMEBE" corresponds to "the last Friday" and "BMEBME" corresponds to "the fourth Friday".
[0086] S303. If a target phrase pair exists, a sentence start marker is added to the beginning of the first execution time text and the second execution time text respectively, and a sentence end marker is added between the first execution time text and the second execution time text, and the first phrase and the second phrase in the first execution time text and the second execution time text are replaced by a mask marker.
[0087] It is understandable that the number of target phrase pairs can be one or more. When a target phrase pair exists, it indicates that there are similar phrases between the first execution time text and the second execution time text, and the phrases in the target phrase pair need to be replaced by the [MASK] tag. In this way, the corresponding word vectors can be focused on during classification, which can improve the recognition accuracy of the detection model.
[0088] S304. If the target phrase pair does not exist, a sentence start marker is added to the beginning of the first execution time text and the second execution time text respectively, and a sentence end marker is added between the first execution time text and the second execution time text, and the phrases at the same random position in the first execution time text and the second execution time text are replaced by a mask marker.
[0089] When the target phrase does not exist, a phrase can be randomly selected to extract the word vector. Alternatively, one or more phrase pairs with high similarity can be selected and marked.
[0090] The execution time text recognition scheme provided in the embodiment of the present application has been verified from the aspects of the combination rules of multiple domains and the threshold of a single domain, and can avoid the reduction of recognition accuracy caused by synonyms, providing a good foundation for the automatic detection of Cron formulas.
[0091] Embodiment 3
[0092] In an embodiment of the present application, in order to better capture the structure and semantic information of the text and more accurately understand the execution time text, a training generation step of a word segmentation model is provided here to identify the mapping relationship between the execution time text and each field in the Cron expression.
[0093] Specifically, a preset number of correct description texts corresponding to Cron expressions in the network can be collected as sample time texts. It is understandable that the collected sample time texts need to be preprocessed, such as Chinese-English conversion, number-Chinese character conversion, etc.
[0094] In order to further improve the robustness of the model word segmentation and make it suitable for the text format reconstructed in this application, the phrases in different domains in the sample time text can also be shuffled and rearranged. For example, "execute once every Wednesday at 12 noon" can be expanded to "every Wednesday / execute once / 12 noon", and "every month / last Friday / 10 o'clock / 15th / execute" can be expanded to "last Friday / 15th / 10 o'clock / every month / execute".
[0095] Each sample time text can be manually or by using the pyltp tool to annotate the segmentation identifier and named entity. For example, if the sample time text is "executed once every Wednesday at 12 noon", it can be segmented into "every Wednesday / 12 noon / executed once", where the entity corresponding to "every Wednesday" is the week domain, the entity corresponding to "12 noon" is the time domain, and the entity corresponding to "executed once" is other.
[0096] Next, a statistical machine learning method can be selected to convert the annotated sample time text into a coding sequence. The coding conversion here can adopt the aforementioned BEMS word position tagging method or other coding methods.
[0097] For the selection of word segmentation, the common hidden Markov model (HMM) can be selected. Each sample time text is input into the HMM model in turn to predict the most likely state sequence. According to the inverse encoding of the state sequence, the corresponding word segmentation result can be output. The expected value and variance value can be iterated by the Baum-Welch algorithm to update the parameters of the HMM model.
[0098] For the selection of word segmenter, other algorithms such as support vector machine method, logistic regression, etc. can also be selected, and there is no limitation here.
[0099] In this embodiment, a special word segmentation model based on the Cron expression structure principle is created, which can segment the execution time text according to the categories of second domain, minute domain, time domain, day domain, month domain, week domain and year domain, and can also have a good word segmentation effect on the reconstructed text with disrupted phrase order.
[0100] Embodiment 4
[0101] In an embodiment of the present application, considering the structural particularity of the Cron expression, a detection model is provided for performing targeted testing on the execution time text corresponding to the Cron expression, specifically testing whether the compiled execution time is correct and whether the structure is correct.
[0102] The first step is to collect sample data, where the sample time text in the above embodiment can be used.
[0103] The sample time text is marked with special markers. Here, a sentence vector containing the entire sequence information can be selected, and in order to improve the recognition effect of synonyms, a word vector is also selected specifically. The specific marking method can refer to steps S300 to S304 in the aforementioned embodiment. It can be understood that here, [MASK] mask marking is performed on the semantically similar target phrase pairs, so that these phrases can be focused on in the model encoding process. Selecting the [CLS] sentence start marking can better learn the dependencies between contexts, and then reflect whether the structures between the various domains of the Cron expression are compiled correctly.
[0104] For the extraction and fusion of sentence vectors and word vectors, in a specific embodiment, the BERT algorithm can be selected to extract vectors and spliced through a fully connected layer, so that the characteristics of the two different vectors can be better preserved. Then the spliced vector is input into the Flatten layer for dimensionality reduction. Finally, sigmoid is used for binary classification. If the value of sigmoid output is greater than 0.6, then 0 can determine that the Cron expression is encoded correctly.
[0105] Embodiment 5
[0106] Figure 4 A schematic diagram of a structure of a detection device for a string expression provided in an embodiment of the present application. Figure 4 As shown, the present application provides a device 40 for detecting a string expression, the device comprising:
[0107] An acquisition module 410 is used to acquire a Cron expression of a scheduled task and a first execution time text input by a user through a graphical user interface, wherein the first execution time text is used to describe a required execution time of the scheduled task;
[0108] A parsing module 420, configured to parse the second execution time text based on the acquired Cron expression;
[0109] The detection module 430 is used to input the first execution time text and the second execution time text into a pre-trained detection model to obtain a detection result output by the detection model, and the detection result is used to indicate whether the first execution time text and the second execution time text indicate the same execution time; wherein the detection result is obtained in the following manner: the first execution time text and the second execution time text are annotated with special markers; the annotated first execution time text and the second execution time text are input into a feature extractor to extract sentence vectors and word vectors corresponding to the feature markers; a first fusion vector is constructed based on the sentence vector and word vector corresponding to the first execution time text, and a second fusion vector is constructed based on the sentence vector and word vector corresponding to the second execution time text; the first fusion vector and the second fusion vector are input into a classifier to determine and output the detection result;
[0110] The determination module 440 is used to determine whether the Cron expression is encoded correctly according to the detection result.
[0111] In an optional embodiment, the special markers include a mask marker, a sentence start marker and a sentence end marker, and the detection module 430 marks the first execution time text and the second execution time text with special markers in the following manner: reconstructing the first execution time text and the second execution time text respectively according to a preset format; obtaining a first word segmentation marker sequence corresponding to the reconstructed first execution time text and a second word segmentation marker sequence corresponding to the second execution time text; based on the degree of matching between the first word segmentation marker sequence and the second word segmentation marker sequence, determining whether there is a target phrase pair, each target phrase pair including a first phrase in the first execution time text and a second phrase in the second execution time text; if there is a target phrase pair, adding a sentence start marker to the beginning of the first execution time text and the second execution time text respectively; adding a sentence end marker between the first execution time text and the second execution time text; replacing the first phrase and the second phrase in the first execution time text and the second execution time text with a mask marker.
[0112] In an optional embodiment, the preset format includes a second domain, a minute domain, a time domain, a day domain, a month domain, a week domain and a year domain arranged in sequence, and the detection module 430 is also used to input the first execution time text and the second execution time text into the word segmentation model respectively to obtain the word segmentation result of the first execution time text and the word segmentation result of the second execution time text output by the word segmentation model, the word segmentation result including the phrase division of the execution time text and the domain category corresponding to the phrase; for the divided phrases, the phrases are added respectively to the domain corresponding to the domain category to combine the reconstructed first execution time text and the second execution time text.
[0113] In an optional implementation, the detection module 430 is also used to determine in turn whether the segmentation marks at the same position in the first segmentation mark sequence and the second segmentation mark sequence are consistent; if not, the first phrase and the second phrase corresponding to the segmentation mark are determined as the target phrase pair.
[0114] In an optional embodiment, the detection module 430 is also used to extract a first sentence vector corresponding to a sentence start marker in a first execution time text, and a first word vector corresponding to at least one mask marker, to construct a first fusion vector; extract a second sentence vector corresponding to a sentence start marker in a second execution time text, and a second word vector corresponding to at least one mask marker, to construct a second fusion vector; wherein the first / second fusion vector is constructed in the following manner: calculating an average value vector of at least one first / second word vector; concatenating the first / second sentence vector with the average value vector of the first / second word vector to construct a first / second fusion vector.
[0115] In an optional embodiment, the detection module 430 is also used to add a sentence start marker to the beginning of the first execution time text and the second execution time text respectively if the target phrase pair does not exist; add a sentence end marker between the first execution time text and the second execution time text; and replace the phrase at the same random position in the first execution time text and the second execution time text with a mask marker.
[0116] In an optional implementation, the parsing module 420 is specifically used to: determine the target format of the Cron expression; match the corresponding execution time text template from the database based on the target format; and for the field on the target domain in the Cron expression, add the time parameter indicated by the field to the corresponding position in the execution time text template to generate a second execution time text.
[0117] See also Figure 5 , Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Figure 5 As shown in , the electronic device 500 includes a processor 510 , a memory 520 and a bus 530 .
[0118] The memory 520 stores machine-readable instructions executable by the processor 510. When the electronic device 500 is running, the processor 510 communicates with the memory 520 via the bus 530. When the machine-readable instructions are executed by the processor 510, the above-mentioned Figure 1 The steps of a method for detecting a string expression in the method embodiment shown are specifically implemented in the method embodiment and will not be described in detail here.
[0119] The present application also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the computer program can execute the above-mentioned Figure 1 The steps of a method for detecting a string expression in the method embodiment shown are specifically implemented in the method embodiment and will not be described in detail here.
[0120] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0121] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.
[0122] In addition, the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0123] Furthermore, the functional modules in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
[0124] It should be noted that if the function is implemented in the form of a software function module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk, and other media that can store program codes.
[0125] In this document, relational terms such as first and second, etc. are used merely to distinguish one entity or operation from another entity or operation, but do not necessarily require or imply any such actual relationship or order between these entities or operations.
[0126] The above description is only an embodiment of the present application and is not intended to limit the protection scope of the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
Claims
1. A method for detecting a string expression, characterized in that: The method comprises: Acquire, through a graphical user interface, a Cron expression of a scheduled task input by a user and a first execution time text, wherein the first execution time text is used to describe a required execution time of the scheduled task; Based on the acquired Cron expression, a second execution time text is parsed, specifically including determining a target format of the Cron expression, matching a corresponding execution time text template from a database based on the target format, and for a field on a target domain in the Cron expression, adding a time parameter indicated by the field to a corresponding position in the execution time text template to generate the second execution time text; Inputting the first execution time text and the second execution time text into a pre-trained detection model to obtain a detection result output by the detection model, wherein the detection result is used to indicate whether the first execution time text and the second execution time text indicate the same execution time; Determine whether the Cron expression is correctly encoded according to the detection result; The step of inputting the first execution time text and the second execution time text into a pre-trained detection model to obtain the detection result output by the detection model specifically includes: Marking the first execution time text and the second execution time text with special markers; Inputting the annotated first execution time text and second execution time text into a feature extractor to extract sentence vectors and word vectors corresponding to the feature markers; Constructing a first fused vector based on the sentence vector and the word vector corresponding to the first execution time text, and constructing a second fused vector based on the sentence vector and the word vector corresponding to the second execution time text; Inputting the first fusion vector and the second fusion vector into a classifier to determine and output a detection result; The special markers include a mask marker, a sentence start marker, and a sentence end marker, and the first execution time text and the second execution time text are marked with special markers in the following manner: Reconstructing the first execution time text and the second execution time text according to preset formats respectively; Obtain a first word segmentation token sequence corresponding to the reconstructed first execution time text and a second word segmentation token sequence corresponding to the second execution time text; Based on the matching degree between the first word segmentation mark sequence and the second word segmentation mark sequence, determining whether there is a target phrase pair, each target phrase pair includes a first phrase in the first execution time text and a second phrase in the second execution time text; If the target phrase pair exists, adding a sentence start marker to the beginning of the first execution time text and the second execution time text respectively; Adding a sentence end marker between the first execution time text and the second execution time text; The first phrase and the second phrase in the first execution time text and the second execution time text are replaced by a mask marker.
2. The method according to claim 1, characterized in that The preset format includes a second field, a minute field, a time field, a day field, a month field, a week field, and a year field arranged in sequence. The step of reconstructing the first execution time text and the second execution time text according to the preset format includes: Inputting the first execution time text and the second execution time text into a word segmentation model respectively, to obtain a word segmentation result of the first execution time text and a word segmentation result of the second execution time text output by the word segmentation model, wherein the word segmentation result includes a phrase division of the execution time text and a domain category corresponding to the phrase; For the divided phrases, each phrase is added to the domain corresponding to the domain category to combine the reconstructed first execution time text and second execution time text.
3. The method according to claim 2, characterized in that The step of determining whether there is a target phrase pair based on the degree of matching between the first word segmentation tag sequence and the second word segmentation tag sequence specifically includes: Determine in sequence whether the word segmentation marks at the same position in the first word segmentation mark sequence and the second word segmentation mark sequence are consistent; If they are inconsistent, the first phrase and the second phrase corresponding to the word segmentation mark are determined as the target phrase pair.
4. The method according to claim 1, characterized in that: Extracting a first sentence vector corresponding to a sentence start marker and a first word vector corresponding to at least one mask marker in the first execution time text to construct a first fusion vector; Extracting a second sentence vector corresponding to the sentence start marker and a second word vector corresponding to at least one mask marker in the text at the second execution time to construct a second fused vector; The first fusion vector is constructed in the following way: Calculate an average vector of at least one first word vector; Concatenate the first sentence vector with the average vector of the first word vector to construct a first fusion vector; And, construct the second fusion vector in the following way: Calculate an average vector of at least one second word vector; The second sentence vector is concatenated with the average vector of the second word vector to construct a second fused vector.
5. The method according to claim 2, characterized in that: If the target phrase pair does not exist, adding a sentence start marker to the beginning of the first execution time text and the second execution time text respectively; Adding a sentence end marker between the first execution time text and the second execution time text; The phrase at the same random position in the first execution time text and the second execution time text is replaced by a mask marker.
6. A detection device for a string expression, characterized in that: The device comprises: An acquisition module, used to acquire a Cron expression of a scheduled task and a first execution time text input by a user through a graphical user interface, wherein the first execution time text is used to describe the required execution time of the scheduled task; A parsing module, for parsing a second execution time text based on the acquired Cron expression, specifically including determining a target format of the Cron expression; matching a corresponding execution time text template from a database based on the target format; and, for a field on a target domain in the Cron expression, adding a time parameter indicated by the field to a corresponding position in the execution time text template to generate the second execution time text; A detection module, used for inputting the first execution time text and the second execution time text into a pre-trained detection model to obtain a detection result output by the detection model, wherein the detection result is used to indicate whether the first execution time text and the second execution time text indicate the same execution time; wherein the detection result is obtained in the following manner: marking the first execution time text and the second execution time text with special markers; inputting the marked first execution time text and the second execution time text into a feature extractor to extract sentence vectors and word vectors corresponding to the feature markers; constructing a first fusion vector based on the sentence vector and word vector corresponding to the first execution time text, and constructing a second fusion vector based on the sentence vector and word vector corresponding to the second execution time text; inputting the first fusion vector and the second fusion vector into a classifier to determine and output the detection result; The special markers include a mask marker, a sentence start marker and a sentence end marker. The detection module marks the first execution time text and the second execution time text with special markers in the following manner: reconstructing the first execution time text and the second execution time text respectively according to a preset format; obtaining a first word segmentation marker sequence corresponding to the reconstructed first execution time text and a second word segmentation marker sequence corresponding to the second execution time text; determining whether there is a target phrase pair based on the degree of matching between the first word segmentation marker sequence and the second word segmentation marker sequence, each target phrase pair including a first phrase in the first execution time text and a second phrase in the second execution time text; if there is a target phrase pair, adding a sentence start marker to the beginning of the first execution time text and the second execution time text respectively; adding a sentence end marker between the first execution time text and the second execution time text; replacing the first phrase and the second phrase in the first execution time text and the second execution time text with a mask marker; and a determination module, for determining whether the Cron expression is correctly encoded according to the detection result.
7. An electronic device, characterized in that: include: A processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor communicates with the memory via the bus, and the processor executes the machine-readable instructions to perform the steps of the method for detecting a string expression as described in any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the method for detecting a string expression as claimed in any one of claims 1 to 5 are executed.
Citation Information
Patent Citations
Equipment control method and device based on Internet of Things, electronic equipment and storage medium
CN114650310A
Text coding method and device, computer equipment and storage medium
CN116050352A
