Sophie

Sophie

distrib > Mandriva > 2008.1 > i586 > by-pkgid > 703d980c580707c382b4e43e25965bc5 > files > 7508

php-manual-pt_BR-5.2.4-1mdv2008.1.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>levenshtein</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="Manual do PHP"
HREF="index.html"><LINK
REL="UP"
TITLE="String"
HREF="ref.strings.html"><LINK
REL="PREVIOUS"
TITLE="join"
HREF="function.join.html"><LINK
REL="NEXT"
TITLE="localeconv"
HREF="function.localeconv.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=UTF-8"></HEAD
><BODY
CLASS="refentry"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Manual do PHP</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="function.join.html"
ACCESSKEY="P"
>Anterior</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.localeconv.html"
ACCESSKEY="N"
>Próxima</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.levenshtein"
></A
>levenshtein</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN219545"
></A
><P
>    (PHP 3 &#62;= 3.0.17, PHP 4 &#62;= 4.0.1, PHP 5)</P
>levenshtein&nbsp;--&nbsp;
     Calcula a distância Levenshtein entre duas strings
    </DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN219548"
></A
><H2
>Descrição</H2
>int <B
CLASS="methodname"
>levenshtein</B
> ( string str1, string str2 )<BR
></BR
>int <B
CLASS="methodname"
>levenshtein</B
> ( string str1, string str2, int cost_ins, int cost_rep, int cost_del )<BR
></BR
>int <B
CLASS="methodname"
>levenshtein</B
> ( string str1, string str2, function cost )<BR
></BR
><P
>&#13;     Retorna a Levenshtein-Distance entre duas strings argumentos
     ou -1, se nenhuma das strings argumentos é mais longa que o
     o limite de 255 caracteres (255 seria mais do que o bastante
     para o nome ou comparação de dicionário, e 
     ninguém sério estaria fazendo análises genéticas com PHP).
    </P
><P
>&#13;     A distância Levenshtein é definida como o número mínimo de 
     caracteres que você tem para substituir, inserir ou apagar
     para transformar
     <CODE
CLASS="parameter"
>str1</CODE
> dentro de <CODE
CLASS="parameter"
>str2</CODE
>.
     A complexidade do algoritmo é <TT
CLASS="literal"
>O(m*n)</TT
>,
     onde <TT
CLASS="literal"
>n</TT
> e <TT
CLASS="literal"
>m</TT
> são o comprimento
     da <CODE
CLASS="parameter"
>str1</CODE
> e
     <CODE
CLASS="parameter"
>str2</CODE
> (rather good when compared to
     <A
HREF="function.similar-text.html"
><B
CLASS="function"
>similar_text()</B
></A
>, which is O(max(n,m)**3),
     but still expensive).
    </P
><P
>&#13;     Na sua forma mais simples a função pegará apenas as duas 
     strings como parâmetros e calculará apenas o número de operações de
     inserção, substituição e deletação necessárias para transformar
     <CODE
CLASS="parameter"
>str1</CODE
> em <CODE
CLASS="parameter"
>str2</CODE
>.
    </P
><P
> 
     Uma segunda variante pegará três parâmetros adicionais que 
     definem o custo das operações de inserção, substituição e
     deletação. Esta é a mais geral e adapatável do que a 
     variante um, mas não tão eficiente.
    </P
><P
> 
     A terceira variante (que ainda não é implementada) será a mais 
     geral e adaptável, mas também a alternativa mais lenta. Ela
     chamará uma função de usuário fornecida que determinará o custo 
     para cada possível operação.
    </P
><P
>&#13;     A função de usuário fornecida(The user-supplied function) será chamada com os seguintes argumentos:
     <P
></P
><UL
><LI
><P
>&#13;        operation to apply: 'I', 'R' ou 'D'
       </P
></LI
><LI
><P
>&#13;        actual character in string 1
       </P
></LI
><LI
><P
>&#13;        actual character in string 2
       </P
></LI
><LI
><P
>&#13;        position in string 1
       </P
></LI
><LI
><P
>&#13;        position in string 2
       </P
></LI
><LI
><P
>&#13;        remaining characters in string 1
       </P
></LI
><LI
><P
>&#13;        remaining characters in string 2
       </P
></LI
></UL
>
     The user-supplied function has to return a positive integer
     describing the cost for this particular operation, but it may
     decide to use only some of the supplied arguments.
    </P
><P
> 
     The user-supplied function approach offers the possibility to
     take into account the relevance of and/or difference between
     certain symbols (characters) or even the context those symbols
     appear in to determine the cost of insert, replace and delete
     operations, but at the cost of losing all optimizations done
     regarding cpu register utilization and cache misses that have
     been worked into the other two variants.
    </P
><P
>&#13;     Veja também <A
HREF="function.soundex.html"
><B
CLASS="function"
>soundex()</B
></A
>,
     <A
HREF="function.similar-text.html"
><B
CLASS="function"
>similar_text()</B
></A
>, e
     <A
HREF="function.metaphone.html"
><B
CLASS="function"
>metaphone()</B
></A
>.
    </P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="function.join.html"
ACCESSKEY="P"
>Anterior</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Principal</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.localeconv.html"
ACCESSKEY="N"
>Próxima</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>join</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ref.strings.html"
ACCESSKEY="U"
>Acima</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>localeconv</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>