Searching

From Wenlin Guide

Jump to: navigation, search

Wenlin 216x93.png Chapter 10 of the Wenlin User’s Guide

This chapter describes all of Wenlin’s searching capabilities, including the commands in the Search menu and the ▷search buttons in dictionary entries.

You can conduct searches to find practically any string of text, in any window, file, or collection of files. And when you are editing, you can use search and replace to find a string of text and replace it with another.

Wenlin offers two kinds of searches: local and global. A local search takes place within the active window. A global search can go through an entire collection of files (Search Files...) or through the dictionaries (Search Dictionaries...), both of which are good ways to find examples of vocabulary usage in context.

Contents

Local Searches: Searching Within the Active Window

Wenlin provides the following commands for local searches:

  • Find...
  • Find Again
  • Replace
  • Replace and Find Again
  • Replace All
  • Find Fix:

You can choose the commands from the Search menu or you can use keyboard shortcuts. As a precaution, Replace All has no keyboard shortcut. The replacement commands are only available when editing is enabled in the active window.

The primary command is Find... , which opens a dialog box prompting you for information. All the other commands (except Find Fix:) rely on the information you specify in the Find... dialog box.

The text you search for can be any sequence, or string, of characters. It is called the search string.

For example, if you want to search for a particular word, simply choose Find... , type the word you wish to find, and choose OK. Wenlin then conducts a forward search from the current position of the insertion point. If the word is found, Wenlin automatically scrolls to where it is and highlights it. Suppose you want to find the next instance of the word. There is no need to type the word again. You can use the Find Again command. The Find... dialog box stores the search string, and the Find Again command searches for the next instance of the same search string.

The Find... command is also used in combination with the replacement commands. From the Find... dialog box you can specify both the search string and the string of text to replace it with. You then have all kinds of options available. You can choose Replace All (taking appropriate precautions!) or you can judiciously go through the document and make replacement decisions on an individual basis. Here you might use a combination of commands. First you use Find... . When the search string is found, it is highlighted. You can then choose Replace and be satisfied, or you can choose Replace and Find Again to continue forward. If you don’t want to replace the highlighted string, you can choose Find Again and continue forward without replacing it.

The Find Fix: command has a very specific purpose, related to the Make Transformed Copy... command in the Edit menu. It is described in Chapter 8.

The Insertion Point and Local Searches

The insertion point plays a crucial role in all the local search commands. Wenlin always searches forward, starting from the current position of the insertion point in the window. Therefore, if you want to search an entire document, you may want to start with the insertion point at its very beginning. However, the Find and Find Again commands, when reaching the end of a document, present a dialog offering to continue searching from the beginning of the document.

Whenever the search string is found, it will be highlighted and visible. Highlighted text is also the selection, and it acts as the insertion point. Therefore, when editing is enabled, the highlighted text can be easily replaced by choosing Replace or by pressing any keystroke that would normally cause text to appear (or disappear) at the insertion point. The insertion point is described in detail in Chapter 1.

The Find Dialog Box

When you choose Find..., this dialog box is displayed:

Find-dialog.jpg

There are two text boxes, one for the search string, another for the replacement string. Depending on your purpose, you put text in one or both of these boxes. To move the insertion point between boxes, press the Tab key, or point to the box of interest and click.

Normally, if you search for a word like “cat”, Wenlin also finds any occurrence of “CAT” or “Cat”, regardless of whether it is written in capital or small letters. Similarly, if you search for a Chinese word or phrase, Wenlin finds it regardless of whether it is written in simple or full form characters: if you search for 见 (jiàn ‘see’), Wenlin also finds any occurrence of 見 (or vice-versa). Usually, this is very helpful. Occasionally, however, you might want to search for a string written exactly as you specify it. In that case, you can click on the check box:

Find-dialog-fullsimp.jpg

Normally, the Full=simple check box has a mark in it. If you un-check it (remove the mark), the search will be exact, that is, 见 won’t match 見, 猫 won’t match 貓, and “cat” won’t match “Cat”.

There is a second check box for regular expressions, explained later in this chapter.

The Find dialog box accepts any text that you would normally be able to place on the screen by typing, pasting, or using the Grabber. You are only limited by the size of the Find dialog text boxes.

Wenlin will find the string inside another, larger string. For example, if you look for the string “the” it will be found inside the strings “theory” and “mother”.

Examples of Local Searching

Below we give instructions for using Find... and the other local search commands, in some typical situations.

By local we mean that you are searching within a file that is currently open in a Wenlin window or sub-window (in contrast to global searches discussed below).

Finding a String

To find a string of text in a window:

• Choose Find... from the Search menu
• Place the search string in the dialog box
• Choose OK

If the string is in the window (somewhere following the insertion point), Wenlin scrolls to where the string is and highlights it. If the string isn’t found, the computer emits a beep. Wenlin always searches to the very end of the document, not just the visible portion in the window.

To find the next instance of the same string, choose Find Again from the Search menu.

Replacing a String

To find a string and replace it with another string:

• Choose Find... from the Search menu
• Place the search string in the dialog box
• Place the replacement string in the dialog box
• Choose OK

If the string is in the window, Wenlin scrolls to where it is and highlights it. You can then choose any of the following commands from the Search menu:

Replace to replace the highlighted string with the replacement string</li>
Replace and Find Again to replace the highlighted string and then search for the next instance of the search string
Find Again to search for the next instance of the search string

Replacing All

To replace every instance of the search string:

• Position the insertion point where you want the replacements to start
• Choose Find... from the Search menu
• Place the search string in the dialog box
• Place the replacement string in the dialog box
• Choose OK

When the first instance of the search string is found,

• Choose Replace All from the Search menu

Wenlin then makes all subsequent replacements and tells you how many instances were replaced. If a replacement string is not stored in the Find dialog box, every instance of the search string will be replaced with nothing, that is, deleted! Use caution with Replace All. Before you make wholesale replacements in a document, make sure that you have a copy saved on disk. If you want, you can open up a duplicate, read-only window to use later for comparison.

After you have placed the search string and/or the replacement string in the dialog box, you are free to choose any of the other commands at any time. For example, you can select some text yourself (using the mouse or keyboard) and then choose Replace. Moreover, text needn’t be highlighted to use Replace – Wenlin always inserts the replacement string at the current position of the insertion point. The search string and the replacement string will remain in the Find dialog box until you change them, delete them, or quit the program.

Regular Expressions

For programmer-linguists, Wenlin supports regular expression (regex) searching. The Find dialog box includes a check box:

Find-dialog-regex.jpg

When the check box has a mark in it, Wenlin treats the search string as a regular expression pattern, using the PCRE (Perl-Compatible Regular Expression) library. If you'd like to learn about regular expression grammar and syntax is beyond the scope of this guide, please see the [Wikipedia], [perl.org] and [pcre.org] websites, or try a web search for “learning regular expressions”.

Here are a few examples:

[东南西北][亚美欧非]

(Find any of the first four characters immediately followed by any of the last four characters, including continents like 东亚 East Asia, 南亚 South Asia, 北美 North America.)

不.+数

(Find expressions in which 不 is followed by 数, with anything in between, such as 不计其数, 不可胜数, 不可数, 不算数, 不可约分数, 不名数, 不在少数.)

y[īi]

(Find either yī or yi, with or without the tone mark.)

\[U\+([0-9a-f]{4,5})\]

(Find Unicode hexadecimal digits given in Wenlin's “[U+xxxx]” bracketed USV notation, storing the digits in the variable $1 for use in the Replace slot.)

$1 through $9 (only) in the replacement string stand for matched parenthesized sub-expressions.

When regular expressions are enabled, the Capital=small (ABC=abc) check box is still supported for case-insensitivity. However, simple and full form characters (like 马 and 馬) are not treated as equivalent. You can explicitly search for 马|馬 to match either 马 or 馬.

Searching is done one line at a time. Patterns can't include newline characters; ^ matches start-of-line and $ matches end-of-line.

As an alternative to checking the check box, you can obtain the same result by typing “re=” before the search string.

Regular expressions are powerful and complex. You can accomplish a lot with them, and also easily make mistakes, so please cautious with your important files, especially if you use the Replace All command.

Regular expressions can also be used for the Search Files and Search Dictionaries commands (described below).

Common Mistakes when Using Find

  • You used the wrong spelling, or the wrong tone mark.
  • You did not correctly position the insertion point. Searches always take place forward of the insertion point.
  • You inadvertently placed a space before or after the search string.
  • You forgot that pressing the Return or Enter key deletes highlighted text when editing is enabled.

Creative Uses of the Search Features

You can count how many times a certain word or character appears in a document by replacing it with itself. Wenlin will report the number of instances found (and replaced).

You can type more efficiently by using abbreviations and then replacing them later. For example, instead of repeatedly typing in an expression, phrase or title, etc., you can use a short string that never occurs normally. Later, you can use Replace All to substitute the full text for your abbreviation.

Global Searches: Searching a Collection of Files

When you study vocabulary, it’s helpful to see concrete examples of usage, especially examples in an interesting context. Ideally, you would want examples from a variety of literary sources. Global searches provide that capability.

You can also use a global search as a way of locating a file. Perhaps you have forgotten the name of the file but remember some of its contents. Instead of opening up all kinds of different files and looking around (trial and error), you can conduct a search. All you need is an identifiable string – some phrase or expression that is unlikely to appear in other files.

You can initiate a global search two ways: by pressing a ▷search files button inside a dictionary entry, or by choosing Search Files... from the Search menu. All dictionary entries include search buttons. For example, the entry for 的 contains this button:

▷search files for 的

The menu command Search Files is more general: it enables you to search for practically any string of text, even if it’s not a word or phrase in the dictionary. With either method, you can specify the collection of files to search, or you can simply accept the default collection.

Since each ▷search files button is simply a special case of the more general purpose menu command, we describe the menu command first.

The Search Files Menu Command

To conduct a global search:

• Choose Search Files... from the Search menu
A dialog box appears
• Enter the search string in the dialog box
A window appears showing the search options
• Customize any of the search options you would like
• Press the ▷begin search button to begin the search

Below, we describe these steps in detail.

Find-dialog-searchfiles.jpg

When you choose Search Files..., a dialog box prompts you for the text to search for. Just as in the Find dialog box described earlier, you can specify any text for the search string. The check box: Full=simple... has the same effect here that it has for the Find dialog (described above). After you choose OK, a window appears showing the search options.

▷begin search
▷search for: 汉英
▷folder to search: /Users/username/WenlinTushuguan/
[x] Full=simple (見=见), Capital=small (ABC=abc)
[x] Search next file after 3 matches
▷default file format: UTF-8

New in 4.2 The interface has been made more flexible in Wenlin version 4.2. Previous versions displayed a fixed sequence of dialog boxes for the options. Now you can simply accept the default options shown in the window, or customize them in whatever sequence you would like.

Specifying What Files to Search

You can accept the default file specification or you can supply your own. The default behavior is to search all text files in the Tushuguan folder. (The Tushuguan folder is described in Appendix C.) To search a different folder, press the triangle button labeled folder to search:. Then a dialog box will appear enabling you to choose a folder. The dialog box looks and behaves differently, depending on the operating system (MS-Windows or Mac OS). In any case, it resembles the dialog box for opening a document with the Open... command (as described in Chapter 3).

MS-Windows:

Searchfiles-filesdialog-win.png

Mac OS:

Searchfiles-filesdialog-mac.png

Navigate just as you would to open a document. When the folder you want to search is open, click on the button that says Open or Choose.

Any folders (subdirectories) inside the folder (directory) you specify are included in the search; and any folders inside those folders are also searched, and so on, however deeply the folders are nested. (Technically, we say that the search is recursive.) Therefore, you can easily search through a whole bunch of folders all at once, if they are all located inside a single high-level folder.

More Search Options

The check box: Full=simple... has the same effect here that it has for the Find dialog (described above).

The check box: Search next file after 3 matches normally it has a mark in it, which means that Wenlin won’t look for more than three occurrences in any single document; after finding three occurrences of the search string in a single document, it will go on to search the next document. This way, for a common word, you’ll obtain examples from a wider variety of contexts, instead of seeing a whole lot of examples all from the same document. If you prefer to conduct a thorough search of every single occurrence in every file, however, you can un-check the check box by clicking on it.

The default file format: triangle button enables you to specify a default file format. This setting doesn’t matter if the files are all Unicode, or if they all have extensions that indicate their formats (such as “.gb”, “.b5”, “.u8”, “.wenlin”, as described in Chapter 3). For searching the text files supplied with Wenlin, this setting doesn’t matter. When Wenlin can’t tell automatically what a file’s format (encoding) is, it uses the default format that you specify here. This is important if you have your own collection of text files, and they aren’t Unicode, and they don’t have extensions that indicate their formats.

While a Global Search is in Progress

Searchfiles-progress.jpg

After you specify the search criteria, the search begins. A dialog box shows the search progress. It tells you the name of the current file being searched along with the total number of occurrences found so far. If you don’t have time for a complete search, or the search has already yielded plenty of examples, you can interrupt the search at any time by choosing the Suspend button. You can easily resume the search as described below.

Results of a Global Search

When the search is over, or when you suspend it, a window displays the name of each file, the position of the occurrence (numbers which you can ignore), and the line that contains the occurrence.

When a single file contains more than three occurrences, if the Search next file after 3 matches check box was checked, then a line saying ... may have more is shown after the third occurrence. You can always open the file and conduct a local search to find additional occurrences in that file.

Suppose you were interested in archeology; you might search through issues of an electronic Chinese magazine downloaded from the internet for 考古学 (kǎogǔxué ‘archeology’). The search window might look as follows, if you suspend the search for 考古学 after 13 occurrences have been found.

Search /HXWZ/ for 考古学
▷"/HXWZ/1993/cm9308b.gb" [40396-40405]:
互相释证,凡属于考古学及上古史之作,如《殷卜辞中所见先公先王
▷"/HXWZ/1993/cm9312a.gb" [5370-5379]:
里的古代文化遗址和墓葬群,是整个中国考古学文化链条上不可缺少的重要
▷"/HXWZ/1994/cm9412c.gb" [6328-6337]:
于93年3月被首次发现。另据12月11日报道,考古学家最近证实,在
▷"/HXWZ/1995/cm9504a.gb" [20409-20418]:
的小子时,村子里来了几个所谓的考古学家(以现在的老练得多的学术的眼
▷"/HXWZ/1995/cm9504a.gb" [20502-20511]:
光看,这些人根本够不上什么考古学家,至多只是乡下人经常见到的那些偶
▷"/HXWZ/1995/cm9504a.gb" [21072-21081]:
成群的孩子跟在这几个穿中山装的“考古学家”后面,卫护着那几只缺沿掉耳的
(cm9504a.gb may have more)
▷"/HXWZ/1995/cm9504c.gb" [46637-46646]:
  在我的考古学的经验中,文明的兴衰乃是常事:彩陶文化忽然在很短的
▷"/HXWZ/1995/cm9504c.gb" [47119-47128]:
此再好不过的生动解说了。当然从纯视觉的角度看,从考古学家那习惯了器
▷"/HXWZ/1995/cm9508b.gb" [33061-33070]:
景当然足以令我心情复杂,而即使是英美等国的考古学者,谁又能对这样的
▷"/HXWZ/1995/cm9508b.gb" [33157-33166]:
情形保持平静呢?事实是,最近几年的民族与考古学界,“历史是谁的历
▷"/HXWZ/1995/cm9508b.gb" [34035-34044]:
…这些古老文明的心脏,几乎没有一个逃得出列强考古学家的染指。而这些
(cm9508b.gb may have more)
▷"/HXWZ/1995/cm9511b1.gb" [3441-3450]:
★ 十月三十一日报道,中国考古学家在山西省皋平市(译音)发现一坑
▷"/HXWZ/1995/cm9511b1.gb" [5226-5235]:
★ 十一月三日报道,中国考古学家在陕西西安附近发掘了数百冢战国和前
Search suspended. So far 13 occurrences of "考古学" in 7 files.
▷Resume search (373 files already searched, 631 files remain)

To open a file and see the full context of an occurrence, press the ▷triangle button next to the file name. The document will be opened in a new window, which automatically scrolls to show the occurrence, which is highlighted.

Resuming a Search

If you suspend a search, you can always resume it later by pressing the triangle button ▷Resume search, located at the bottom of the search window. For instance, suspending a search for 考古学 could result in a message like this:

Search suspended. So far 13 occurrences of "考古学" in 7 files.
▷Resume search (373 files already searched, 631 files remain)

When you resume the search, it picks up where it left off – it does not duplicate the work already done. The original search window is updated to reflect the results of the resumed search. You can suspend and resume as many times as you like.

Search Files Buttons

Wenlin provides ▷search files buttons inside three types of dictionary entries: Zìdiǎn, Cídiǎn, and Yīng-Hàn. For example:

▷search files for '大'
▷search files for '大家'
▷search files for 'big'

Each button is programmed to search for a particular vocabulary item. Pressing it is equivalent to choosing Search Files from the Search menu and entering that vocabulary item in the first dialog box. You will then be prompted to specify the files to search, exactly as we described earlier for the menu command.

Searching in the Dictionaries

Search in the dictionaries is very similar to searching in files. It is another kind of global search. Not only headwords, but also words occurring in example sentences and definitions can be found this way. It is slower than simply looking up a headword by the methods described in Chapter 5.

Choose Search Dictionaries... from the Search menu and enter the vocabulary item or other string of text for which you want to search. The Cídiǎn, Yīng-Hàn, and Zìdiǎn dictionaries will be searched, in that order. Suspending and resuming are essentially the same as for the Search Files command described above.

Search dict.png

Search Dictionaries Buttons

Wenlin provides ▷search dictionaries buttons inside three types of dictionary entries: Zìdiǎn, Cídiǎn, and Yīng-Hàn. For example:

▷search dictionaries for '大'
▷search dictionaries for '大家'
▷search dictionaries for 'big'

Each button is programmed to search for a particular vocabulary item. Pressing it is equivalent to choosing Search Dictionaries... from the Search menu and entering that vocabulary item in the first dialog box.

Zhao3.jpg

zhǎo ‘seek’

From 扌(手 shǒu) 'hand' and 戈 () ‘spear’.

“A 戈 lance in hand: seek an enemy” --Karlgren.


Mouse pointer finger right.jpg | Previous: 9. Editing the Dictionaries | Next: 11. Pronunciation | Contents |

Personal tools