Debian Codegraph @

doc/source/reference/commands/extract.md

raw symbols SCIP
1 <!-- groonga-command -->
2 <!-- database: commands_extract -->
3
4 # `extract`
5
6 ## Summary
7
8 ```{versionadded} 16.0.3
9
10 ```
11
12 ```{note}
13 This is an experimental feature. Currently, this feature is still not stable.
14 ```
15
16 `extract` command extracts plain text or values from structured data
17 such as HTML and JSON by the specified extractors.
18
19 There is no need to create a table to use `extract` command. It is
20 useful for you to check the results of extractors before you attach
21 them to a lexicon by the {ref}`table-create-extractors` option of
22 {doc}`table_create`.
23
24 See {doc}`/reference/extractors` for details of extractors.
25
26 ## Syntax
27
28 This command takes two parameters.
29
30 Both `extractors` and `value` are required:
31
32 ```
33 extract extractors
34 value
35 ```
36
37 ## Usage
38
39 Here is an example that extracts text content from HTML by
40 {doc}`/reference/extractors/extractor_html`. It removes HTML tags and
41 expands character references:
42
43 <!-- groonga-command -->
44
45 ```{include} ../../example/reference/commands/extract/html.md
46 extract \
47 --extractors 'ExtractorHTML' \
48 --value "<html><body>He&lt;ll&gt;o</body></html>"
49 ```
50
51 Here is an example that extracts values from JSON by
52 {doc}`/reference/extractors/extractor_json`. The `$.tags[*]` JSONPath
53 matches all elements of the `tags` array:
54
55 <!-- groonga-command -->
56
57 ```{include} ../../example/reference/commands/extract/json.md
58 extract \
59 --extractors 'ExtractorJSON("path", "$.tags[*]")' \
60 --value '{"tags": ["groonga", "search", "engine"], "title": "ignored"}'
61 ```
62
63 ## Parameters
64
65 This section describes parameters of `extract`.
66
67 ### Required parameters
68
69 There are required parameters, `extractors` and `value`.
70
71 (extract-extractors)=
72
73 #### `extractors`
74
75 Specifies extractors separated by `,`. `extract` command applies the
76 extractors to `value` in order. The output of an extractor is passed
77 to the next extractor as its input.
78
79 See {doc}`/reference/extractors` for all extractors.
80
81 (extract-value)=
82
83 #### `value`
84
85 Specifies the value that you want to extract plain text or values
86 from.
87
88 If you want to include spaces in `value`, you need to quote `value` by
89 single quotation (`'`) or double quotation (`"`).
90
91 ## Return value
92
93 ```
94 [HEADER, {"extracted": EXTRACTED_VALUE}]
95 ```
96
97 `HEADER`
98 : See {doc}`/reference/command/output_format` about `HEADER`.
99
100 `EXTRACTED_VALUE`
101 : The value extracted by the specified extractors. It's a single value
102 when the extractors return a single value such as
103 {doc}`/reference/extractors/extractor_html`. It's an array when the
104 extractors return multiple values such as
105 {doc}`/reference/extractors/extractor_json`.
106
107 ## See also
108
109 - {doc}`/reference/extractors`
110 - {doc}`table_create`
111 - {doc}`/reference/command/output_format`