> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-fix-nav-issues.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> 自然言語処理 (NLP) 関数のドキュメント

# 自然言語処理 (NLP) 関数

export const CloudNotSupportedBadge = () => {
  return <div className="cloudNotSupportedBadge">
            <div className="cloudNotSupportedIcon">
            <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
                <path strokeWidth="1.5" d="M6.33366 12.6666L12.3739 12.6667C13.6593 12.6667 14.7073 11.6187 14.7073 10.3334C14.7073 9.04804 13.6593 8.00003 12.3739 8.00003C12.3739 8.00003 12.3337 7.66659 12.0003 7.33325M10.667 5.33322C8.00033 2.33325 4.45395 4.78537 4.14195 6.68203C2.55728 6.7627 1.29395 8.06203 1.29395 9.6667C1.29395 11.3234 2.66699 12.6666 4.00033 12.6666" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" />
                <path strokeWidth="1.5" d="M2.66699 14L12.0003 4.66663" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" />
            </svg>

        </div>
            Not supported in ClickHouse Cloud
        </div>;
};

export const ExperimentalBadge = () => {
  return <div className="experimentalBadge">
            <div className="experimentalIcon">
            <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
                <path strokeWidth="1.25" d="M5.5 2H10.5" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" />
                <path strokeWidth="1.25" d="M9.50015 2V6.19625L13.4283 12.7425C13.4738 12.8183 13.4985 12.9049 13.4996 12.9934C13.5008 13.0818 13.4785 13.169 13.435 13.246C13.3914 13.323 13.3283 13.3871 13.2519 13.4317C13.1755 13.4764 13.0886 13.4999 13.0002 13.5H3.00015C2.91164 13.5 2.8247 13.4766 2.74822 13.432C2.67174 13.3874 2.60847 13.3233 2.56487 13.2463C2.52126 13.1693 2.49889 13.082 2.50004 12.9935C2.50119 12.905 2.52582 12.8184 2.5714 12.7425L6.50015 6.19625V2" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" />
                <path strokeWidth="1.25" d="M4.47656 9.56754C5.30344 9.41254 6.47656 9.47942 7.99969 10.25C10.0153 11.2707 11.4216 11.0569 12.2184 10.7282" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" />
            </svg>
        </div>
            Experimental feature. <u><a href="/docs/beta-and-experimental-features#experimental-features">Learn more.</a></u>
        </div>;
};

{/*AUTOGENERATED_START*/}

<div id="detectCharset">
  ## detectCharset
</div>

導入バージョン: v22.2.0

UTF-8 以外でエンコードされた入力文字列の文字セットを検出します。

<Warning>
  この関数は実験的機能であり、今後のリリースで予期しない後方互換性のない変更が加えられる可能性があります。
  有効にするには、`allow_experimental_nlp_functions = 1` を設定してください。
</Warning>

**構文**

```sql theme={null}
detectCharset(s)
```

**引数**

* `s` — 解析対象のテキスト。[`String`](/ja/reference/data-types/string)

**戻り値**

検出された文字セットのコードを表す文字列を返します [`String`](/ja/reference/data-types/string)

**例**

**基本的な使い方**

```sql title=Query theme={null}
SELECT detectCharset('Ich bleibe für ein paar Tage.')
```

```response title=Response theme={null}
WINDOWS-1252
```

<div id="detectLanguage">
  ## detectLanguage
</div>

導入バージョン: v22.2.0

UTF-8 でエンコードされた入力文字列の言語を検出します。
この関数は検出に [CLD2 ライブラリ](https://github.com/CLD2Owners/cld2) を使用し、2 文字の ISO 言語コードを返します。

入力が長いほど、言語検出の精度は高くなります。

<Warning>
  この関数は実験的機能であり、今後のリリースで予測できない後方互換性のない変更が加えられる可能性があります。
  有効にするには `allow_experimental_nlp_functions = 1` を設定してください。
</Warning>

**構文**

```sql theme={null}
detectLanguage(s)
```

**引数**

* `text_to_be_analyzed` — 解析対象のテキスト。[`String`](/ja/reference/data-types/string)

**戻り値**

検出された言語の2文字の ISO コードを返します。その他に返される可能性がある値: `un` = 不明 (どの言語も検出できない) 、`other` = 検出された言語に2文字コードがない。[`String`](/ja/reference/data-types/string)

**例**

**複数言語が混在するテキスト**

```sql title=Query theme={null}
SELECT detectLanguage('Je pense que je ne parviendrai jamais à parler français comme un natif. Where there\'s a will, there\'s a way.')
```

```response title=Response theme={null}
fr
```

<div id="detectLanguageMixed">
  ## detectLanguageMixed
</div>

導入バージョン: v22.2.0

[`detectLanguage`](#detectLanguage) 関数と似ていますが、`detectLanguageMixed` は、テキスト内で各言語が占める割合を、2 文字の言語コードをキーとする `Map` として返します。

<Warning>
  この関数は 実験的機能 であり、今後のリリースで予測不可能な後方互換性のない変更が加えられる可能性があります。
  有効にするには、`allow_experimental_nlp_functions = 1` を設定してください。
</Warning>

**構文**

```sql theme={null}
detectLanguageMixed(s)
```

**引数**

* `s` — 解析対象のテキスト [`String`](/ja/reference/data-types/string)

**戻り値**

キーが 2 文字の ISO コードで、対応する値がその言語として検出されたテキストの割合を表すマップを返します [`Map(String, Float32)`](/ja/reference/data-types/map)

**例**

**複数の言語が混在する場合**

```sql title=Query theme={null}
SELECT detectLanguageMixed('二兎を追う者は一兎をも得ず二兎を追う者は一兎をも得ず A vaincre sans peril, on triomphe sans gloire.')
```

```response title=Response theme={null}
{'ja':0.62,'fr':0.36}
```

<div id="detectLanguageUnknown">
  ## detectLanguageUnknown
</div>

導入バージョン: v22.2.0

[`detectLanguage`](#detectLanguage) 関数と似ていますが、detectLanguageUnknown 関数は UTF-8 以外のエンコーディングの文字列を扱える点が異なります。
文字セットが UTF-16 または UTF-32 の場合は、こちらのバージョンを優先して使用してください。

<Warning>
  この関数は 実験的機能 であり、今後のリリースで予測不能な後方互換性のない変更が加えられる可能性があります。
  有効にするには `allow_experimental_nlp_functions = 1` を設定してください。
</Warning>

**構文**

```sql theme={null}
detectLanguageUnknown('s')
```

**引数**

* `s` — 分析対象のテキスト。[`String`](/ja/reference/data-types/string)

**戻り値**

検出された言語の 2 文字の ISO コードを返します。その他に返される可能性がある値: `un` = 不明 (どの言語も検出できない) 、`other` = 検出された言語に 2 文字のコードがありません。[`String`](/ja/reference/data-types/string)

**例**

**基本的な使い方**

```sql title=Query theme={null}
SELECT detectLanguageUnknown('Ich bleibe für ein paar Tage.')
```

```response title=Response theme={null}
de
```

<div id="detectTonality">
  ## detectTonality
</div>

導入バージョン: v22.2.0

指定されたテキストデータのセンチメントを判定します。

<Info>
  **制限事項**

  現時点でこの関数は、埋め込みの感情辞書を使用しており、ロシア語でのみ動作します。
</Info>

<Warning>
  この関数は実験的機能であり、今後のリリースで予測不能な後方互換性のない変更が加えられる可能性があります。
  有効にするには `allow_experimental_nlp_functions = 1` を設定してください。
</Warning>

**構文**

```sql theme={null}
detectTonality(s)
```

**引数**

* `s` — 解析するテキスト。[`String`](/ja/reference/data-types/string)

**戻り値**

テキスト内の単語の平均感情値を返します。[`Float32`](/ja/reference/data-types/float)

**例**

**ロシア語の感情分析**

```sql title=Query theme={null}
SELECT
    detectTonality('Шарик - хороший пёс'),
    detectTonality('Шарик - пёс'),
    detectTonality('Шарик - плохой пёс')
```

```response title=Response theme={null}
0.44445, 0, -0.3
```

<div id="lemmatize">
  ## lemmatize
</div>

導入バージョン: v21.9.0

指定した単語に対してレンマ化を行います。
この関数を使用するには辞書が必要です。辞書は [github](https://github.com/vpodpecan/lemmagen3/tree/master/src/lemmagen3/models) から取得できます。
ローカルファイルから辞書を読み込む方法の詳細については、["Dictionary の定義"](/ja/reference/statements/create/dictionary/sources/local-file) ページを参照してください。

<Warning>
  この関数は実験的機能であり、今後のリリースで予測不能な後方互換性のない変更が加えられる可能性があります。
  有効にするには、`allow_experimental_nlp_functions = 1` を設定してください。
</Warning>

**構文**

```sql theme={null}
lemmatize(lang, word)
```

**引数**

* `lang` — 適用するルールの言語。[`String`](/ja/reference/data-types/string)
* `word` — レンマ化する対象の小文字の単語。[`String`](/ja/reference/data-types/string)

**戻り値**

単語のレンマ形を返します。[`String`](/ja/reference/data-types/string)

**例**

**英語のレンマ化**

```sql title=Query theme={null}
SELECT lemmatize('en', 'wolves')
```

```response title=Response theme={null}
wolf
```

<div id="stem">
  ## stem
</div>

導入バージョン: v21.9.0

Snowball アルゴリズムを使用して、単語または単語の配列に対してステミングを行います。
各入力文字列は、小文字の単一の単語である必要があります。空白を含む文字列を指定すると例外が発生します。
大文字を含めると、結果は未定義になります。
スカラー入力 (FixedString を含む) に対しては String を返し、配列入力に対しては Array(String) を返します。
String および FixedString の Nullable と LowCardinality のバリアントをサポートします。

**構文**

```sql theme={null}
stem(word, language)
```

**引数**

* `word` — ステミングする単一の小文字の単語 (または単語の配列) 。小文字である必要があります。大文字が含まれていると、結果は未定義になります。String、FixedString、Array(String)、Array(FixedString)、Array(Nullable(String))、または Array(Nullable(FixedString)) を受け付けます。[`String`](/ja/reference/data-types/string) or [`FixedString`](/ja/reference/data-types/fixedstring) or [`Array(String)`](/ja/reference/data-types/array) or [`Array(FixedString)`](/ja/reference/data-types/array)
* `language` — ステミング規則を適用する言語。2 文字の ISO 639-1 コード (例: 'en'、'de'、'fr') を使用してください。[https://en.wikipedia.org/wiki/List\&#95;of\&#95;ISO\&#95;639\&#95;language\&#95;codes](https://en.wikipedia.org/wiki/List\&#95;of\&#95;ISO\&#95;639\&#95;language\&#95;codes) を参照してください。[`String`](/ja/reference/data-types/string)

**戻り値**

単語のステミング後の形式 (String) 、またはステミング後の単語の配列 (Array(String)) 。[`String`](/ja/reference/data-types/string) or [`Array(String)`](/ja/reference/data-types/array)

**例**

**単一の単語をステミングする**

```sql title=Query theme={null}
SELECT stem('blessing', 'en') AS res
```

```response title=Response theme={null}
bless
```

**単語配列のステミング**

```sql title=Query theme={null}
SELECT stem(['blessing', 'disguise'], 'en') AS res
```

```response title=Response theme={null}
['bless','disguis']
```

**FixedString のステミング**

```sql title=Query theme={null}
SELECT stem(toFixedString('blessing', 10), 'en') AS res
```

```response title=Response theme={null}
bless
```

**Nullableな単語のステミング**

```sql title=Query theme={null}
SELECT stem(toNullable('blessing'), 'en') AS res
```

```response title=Response theme={null}
bless
```

<div id="synonyms">
  ## synonyms
</div>

導入バージョン: v21.9.0

指定した単語の同義語を見つけます。

同義語の拡張機能には 2 種類あります。

* `plain`
* `wordnet`

`plain` 拡張機能タイプでは、シンプルなテキストファイルへのパスを指定する必要があります。このファイルでは、各行が特定の同義語セットに対応します。
この行内の単語は、スペースまたはタブ文字で区切る必要があります。

`wordnet` 拡張機能タイプでは、WordNet シソーラスを含むディレクトリへのパスを指定する必要があります。
シソーラスには WordNet の sense index が含まれている必要があります。

<Warning>
  この関数は実験的機能であり、今後のリリースで予測不能な後方互換性のない変更が加えられる可能性があります。
  有効にするには `allow_experimental_nlp_functions = 1` を設定してください。
</Warning>

**構文**

```sql theme={null}
synonyms(ext_name, word)
```

**引数**

* `ext_name` — 検索対象の拡張機能名。[`String`](/ja/reference/data-types/string)
* `word` — 拡張機能内で検索する単語。[`String`](/ja/reference/data-types/string)

**戻り値**

指定した単語の同義語の配列を返します。[`Array(String)`](/ja/reference/data-types/array)

**例**

**同義語を検索する**

```sql title=Query theme={null}
SELECT synonyms('list', 'important')
```

```response title=Response theme={null}
['important','big','critical','crucial']
```
