Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Jerry to list the idioms used in Jin Yong's novels

Shulou Source: shulou.com Published: 2022-06-02 04:24:56 10月04日 Update

This article mainly explains "how to use Jerry to list the idioms used in Jin Yong's novels". Interested friends might as well take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use Jerry to list the idioms used in Jin Yong's novels.

Jerry briefly talks about the principle of implementation. There is a text file in the Web app that maintains all Chinese idioms separated by semicolons.

At run time, this content is loaded into memory and built into a tree, as shown in the following figure:

The leaf node is distinguished by the attribute end as true.

The core logic of idiom retrieval lies in the search function. Let's use a loud slogan in "The Smiling、Proud Wanderer" to debug and understand its realization logic step by step.

Enter the outer while loop on line 165and then enter the inner for loop on line 173to see if there is an idiom that begins with the first character "day" of the test string. Because the idiom is made up of four characters, you need to use the inner for loop to explore one by one. If you encounter an element whose tblCur.end is true, you have found an idiom in the test string.

The following figure shows the tblCur content after the inner for loop is executed for the first time:

The inner loop executes a second time, when tblCur points to a tree made up of all the idioms that begin with "sun and moon":

Perform the third iteration of the inner loop, because there is no "god" node under the "sun-moon" branch of the tree, so end the current inner loop, return to the outer while loop through break, and do a new round of trials to enter the second character "month" of the string, and so on.

Finally, starting from the character "thousand", passing through the path "Qiu-Wan" along the tree in memory, and finally coming to the leaf node "load" whose end attribute is true, write down the offset of "thousand" in the input string and save it in an array arrMatch.

After all the input strings are tested, the corresponding strings are highlighted according to the offset stored in arrMatch, and the retrieval is completed.

Tree as a data structure has a perfect performance in the implementation of this requirement.

At this point, I believe you have a deeper understanding of "how to use Jerry to list the idioms used in Jin Yong's novels". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Characters idioms loops inner layers strings content novels Jin Yong novels Jin Yong nodes input memory outer layer attributes beginning sun and moon jianghu logic offset learning Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Shulou Information Shulou Tech Info Linux Apple