Parser
Text search parsers are responsible for splitting raw document text into tokens and identifying each token's type, where the set of types is defined by the parser itself. Note that a parser does not modify the text at all — it simply identifies plausible word boundaries. Because of this limited scope, there is less need for application-specific custom parsers than there is for custom dictionaries.
Currently, DWS provides the following built-in parsers: pg_catalog.default for English configuration, and pg_catalog.ngram, pg_catalog.zhparser, and pg_catalog.pound for full text search in texts containing Chinese, or both Chinese and English.
The built-in parser is named pg_catalog.default. It recognizes 23 token types, shown in Table 1.
| Alias | Description | Examples |
|---|---|---|
| asciiword | Word, all ASCII letters | elephant |
| word | Word, all letters | mañana |
| numword | Word, letters and digits | beta1 |
| asciihword | Hyphenated word, all ASCII | up-to-date |
| hword | Hyphenated word, all letters | lógico-matemática |
| numhword | Hyphenated word, letters and digits | postgresql-beta1 |
| hword_asciipart | Hyphenated word part, all ASCII | postgresql in the context postgresql-beta1 |
| hword_part | Hyphenated word part, all letters | lógico or matemática in the context lógico-matemática |
| hword_numpart | Hyphenated word part, letters and digits | beta1 in the context postgresql-beta1 |
| | Email address | foo@example.com |
| protocol | Protocol head | http:// |
| url | URL | example.com/stuff/index.html |
| host | Host | example.com |
| url_path | URL path | /stuff/index.html, in the context of a URL |
| file | File or path name | /usr/local/foo.txt, if not within a URL |
| sfloat | Scientific notation | -1.23E+56 |
| float | Decimal notation | -1.234 |
| int | Signed integer | -1234 |
| uint | Unsigned integer | 1234 |
| version | Version number | 8.3.0 |
| tag | XML tag | <a href="dictionaries.html"> |
| entity | XML entity | & |
| blank | Space symbols | (any whitespace or punctuation not otherwise recognized) |
Note: For the parser, the concept of a "letter" is determined by the database's locale setting, i.e., the lc_ctype setting. Words containing only basic ASCII letters are reported as a separate token type, as such words sometimes need to be distinguished. In most European languages, the token types word and asciiword are handled similarly.
email does not support certain valid email characters defined by RFC 5322. Specifically, the non-alphanumeric characters that can be used in an email username include only periods, hyphens, and underscores.
The parser may produce overlapping tokens for the same content. For example, a word containing a hyphen will be reported as a whole, and its components will also be reported separately:
1 2 3 4 5 6 7 8 9 | SELECT alias, description, token FROM ts_debug('english','foo-bar-beta1'); alias | description | token -----------------+------------------------------------------+--------------- numhword | Hyphenated word, letters and digits | foo-bar-beta1 hword_asciipart | Hyphenated word part, all ASCII | foo blank | Space symbols | - hword_asciipart | Hyphenated word part, all ASCII | bar blank | Space symbols | - hword_numpart | Hyphenated word part, letters and digits | beta1 |
This behavior is necessary because it supports searching for both the entire compound word and its individual components. Here is another example:
1 2 3 4 5 6 7 | SELECT alias, description, token FROM ts_debug('english','http://example.com/stuff/index.html'); alias | description | token ----------+---------------+------------------------------ protocol | Protocol head | http:// url | URL | example.com/stuff/index.html host | Host | example.com url_path | URL path | /stuff/index.html |
N-gram is a mechanical word segmentation method suitable for Chinese word segmentation scenarios without semantic analysis. The N-gram segmentation method ensures completeness of segmentation. However, in order to cover all possibilities, many unnecessary words are also added to the index, resulting in an increased number of index entries. N-gram supports Chinese encodings including GBK and UTF-8. It has 6 built-in token types, as shown in Table 2.
| Alias | Description |
|---|---|
| zh_words | chinese words |
| en_word | english word |
| numeric | numeric data |
| alnum | alnum string |
| grapsymbol | graphic symbol |
| multisymbol | multiple symbol |
Zhparser is a dictionary-based semantic word segmentation method. The bottom-layer calls the Simple Chinese Word Segmentation (SCWS) algorithm (https://github.com/hightman/scws), which applies to Chinese segmentation scenarios. SCWS is a term frequency and dictionary-based mechanical Chinese words engine. It can split a whole paragraph Chinese text into words. The two Chinese coding formats, GBK and UTF-8, are supported. The 26 built-in token types are shown in Table 3.
| Alias | Description |
|---|---|
| A | Adjective |
| B | Differentiation |
| C | Conjunction |
| D | Adverb |
| E | Exclamation |
| F | Position |
| G | Lexeme |
| H | Preceding element |
| I | Idiom |
| J | Acronyms and abbreviations |
| K | Subsequent element |
| L | Common words |
| M | Numeral |
| N | Noun |
| O | Onomatopoeia |
| P | Preposition |
| Q | Quantifiers |
| R | Pronoun |
| S | Space |
| T | Time |
| U | Auxiliary word |
| V | Verb |
| W | Punctuation |
| X | Unknown |
| Y | Interjection |
| Z | Status words |
Pound is a fixed-format word segmentation method suitable for Chinese and English word segmentation scenarios where the text to be parsed has no semantic meaning but is separated by fixed delimiters. It supports Chinese encodings including GBK and UTF-8, and English encodings including ASCII. It has 6 built-in token types, as shown in Table 4, and supports 5 delimiter types, as shown in Table 5. If the user does not customize the settings, the default delimiter is #. Pound restricts the length of a single token to no more than 256 characters.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot