mirror of
https://github.com/php/doc-ja.git
synced 2026-04-29 02:53:11 +02:00
145 lines
4.6 KiB
XML
145 lines
4.6 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 873f4a3d5027bd1b584f1d1e590e22cd4a08ae84 Maintainer: hirokawa Status: ready -->
|
|
<!-- CREDITS: shimooka,mumumu -->
|
|
<refentry xml:id="function.similar-text" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>similar_text</refname>
|
|
<refpurpose>二つの文字列の間の類似性を計算する</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>int</type><methodname>similar_text</methodname>
|
|
<methodparam><type>string</type><parameter>string1</parameter></methodparam>
|
|
<methodparam><type>string</type><parameter>string2</parameter></methodparam>
|
|
<methodparam choice="opt"><type>float</type><parameter role="reference">percent</parameter><initializer>&null;</initializer></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
この関数は、&book.programming.classics; に記述されたように二つの文字列の間の類似性を計算します。
|
|
この実装は Oliver の擬似コードの様にスタックを使用せず、
|
|
プロセス全体の速度が改善されるかどうかにかかわらず再帰呼び出しを行うことに注意してください。
|
|
このアルゴリズムの計算量は、O(N**3) であることにも注意してください。
|
|
ただし、N は最も長い文字列の長さです。
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>string1</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
最初の文字列。
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>string2</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
次の文字列。
|
|
</para>
|
|
<note>
|
|
<para>
|
|
<parameter>string1</parameter> と
|
|
<parameter>string2</parameter> を入れ替えると、
|
|
結果は異なるものになります;
|
|
例を参照ください。
|
|
</para>
|
|
</note>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>percent</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
3 番目の引数としてリファレンスを渡すことにより、
|
|
<function>similar_text</function> は類似性をパーセントで計算します。
|
|
これは、<function>similar_text</function> の結果を、
|
|
与えられた文字列の長さの平均を
|
|
<literal>100</literal> 倍した値で割ることで出しています。
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
両方の文字列でマッチした文字の数を返します。
|
|
</para>
|
|
<para>
|
|
マッチする文字数は、
|
|
最初の共通最長部分文字列を探し、
|
|
同じことをその文字列の 前後の文字列に対して再帰的に行うことで計算されます。
|
|
そうして見つかった全ての共通部分文字列の長さが追加されます。
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<example xml:id="similar_text.example.swapping">
|
|
<title><function>similar_text</function> で、引数を入れ替えた場合の例</title>
|
|
<para>
|
|
以下のコードは、
|
|
<parameter>string1</parameter> と
|
|
<parameter>string2</parameter> を入れ替えると、異なる結果になる可能性を示しています。
|
|
</para>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$sim = similar_text('bafoobar', 'barfoo', $perc);
|
|
echo "類似度: $sim ($perc %)\n";
|
|
$sim = similar_text('barfoo', 'bafoobar', $perc);
|
|
echo "類似度: $sim ($perc %)\n";
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs.similar;
|
|
<screen>
|
|
<![CDATA[
|
|
類似度: 5 (71.428571428571 %)
|
|
類似度: 3 (42.857142857143 %)
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>levenshtein</function></member>
|
|
<member><function>metaphone</function></member>
|
|
<member><function>soundex</function></member>
|
|
</simplelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
</refentry>
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|