quinta-feira, 26 de janeiro de 2012

Limite de Memoria SUSE

Tive um problema de out of memory em uma aplicação Java. Em uma máquina menos potente o sistema funcionou e em uma máquina com mais memória e processador a aplicação não funcionou. Os dois equipamentos estavam com SO OpenSUSE.

Verificando a memória com o comando:

ulimit -a

e alterando

ulimit -v unlimited

Funcionou. Dica do Sergio Matos

terça-feira, 17 de janeiro de 2012

Edição HTML com AJAX

O estilo apresentado abaixo permite a edição de um campo em uma página HTML, ou seja, permite a edição em uma página de relatório.


HTML 
<input
name="" 
onchange="javascript:ajaxCampoResposta(this.value,1,5 )" 

value="teste"
style="width: 100%; background: none repeat scroll 0% 0% transparent; border: 0px none;"

onmouseout="this.style.border="0px none""

onmouseover="this.style.border="1px solid #000000""

maxlength="255"

onkeyup=" { document.getElementById("botao_salvar").style.display="";document.getElementById("botao_cancelar").style.display="";this.parentNode.parentNode.firstChild.firstChild.title="*";} this.value = this.value.replace(/\d/g,"").toUpperCase();"
>


JavaScript - Codigo JavaScript que faz chamada para um Ajax de atualização de Campo.


function ajaxCampoResposta(oiac_objeto, id_dicionario, id)
{
 /*
 alert(oiac_objeto+campo);
 return true;
 //*/
 var xmlHttp;
 try
 {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
 }
 catch (e)
 {
  // Internet Explorer
  try
  {
   xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
  catch (e)
  {
   try
   {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
   }
   catch (e)
   {
    alert("Seu navegador não suporta AJAX!");
    return false;
   }
  }
 }
 xmlHttp.onreadystatechange=function()
 {
  if(xmlHttp.readyState==4)
  {
   // document.getElementById("resultado_ajax").innerHTML=xmlHttp.responseText;
   //alert("Kadu");
   alert(xmlHttp.responseText);
  }
 }
 xmlHttp.open("GET","tab_seletor_campos_ajax_resposta.php?p_conteudo="+escape(oiac_objeto)+'&id_dicionario='+id_dicionario+'&id='+id,true);
 xmlHttp.send(null);
}


segunda-feira, 16 de janeiro de 2012

Algorítimo de DICE



"Dice's coefficient, named after Lee Raymond Dice and also known as the Dice coefficient, is a similarity measure over sets."


Código para PSQL (POSTGRESQL)


CREATE OR REPLACE FUNCTION cgu_planilha.dice(texto1 character varying, texto2 character varying)
  RETURNS double precision AS
$BODY$
DECLARE
        qtde1 integer;
        qtde2 integer;
        tam_texto1 integer;
        tam_texto2 integer;
        tam_texto integer;
        nt float;
        nx float;
        ny float;
        ch1 varchar;
        ch2 varchar;
t1 varchar;
t2 varchar;
BEGIN
    qtde1 := 0;
    t1 := lower(texto1);
    t2 := lower(texto2);
    t1 := translate(t1, 'áéíóúàèìòùãõâêîôôäëïöüçÁÉÍÓÚÀÈÌÒÙÃÕÂÊÎÔÛÄËÏÖÜÇ', 'aeiouaeiouaoaeiooaeioucAEIOUAEIOUAOAEIOOAEIOUC');
    t2 := translate(t2, 'áéíóúàèìòùãõâêîôôäëïöüçÁÉÍÓÚÀÈÌÒÙÃÕÂÊÎÔÛÄËÏÖÜÇ', 'aeiouaeiouaoaeiooaeioucAEIOUAEIOUAOAEIOOAEIOUC');

    tam_texto1 := length(t1);
    tam_texto2 := length(t2);
    nx = tam_texto1-1;
    ny = tam_texto2-1;
 
    if (tam_texto2 > tam_texto1)  then
       tam_texto := tam_texto1;
    else
       tam_texto := tam_texto2;
    end if;
    nt := 0;
    LOOP
           ch1 = substr(t1, qtde1, 2);
           ch2 = substr(t2, qtde1, 2);
           if (ch1 = ch2) then
              nt := nt +1;
           end if;
           qtde1 := qtde1 + 1;
           IF qtde1 > tam_texto THEN
              EXIT;  -- exit loop
           END IF;
        END LOOP;
    RETURN (2*nt)/(nx+ny);
END;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION cgu_planilha.dice(character varying, character varying) OWNER TO postgres;


Aplicação do algoritmo para uma frase

CREATE OR REPLACE FUNCTION dice_frase2(texto1 character varying, texto2 character varying)
  RETURNS boolean AS
$BODY$
DECLARE
        alvo_pesquisa varchar;
t1 varchar;
t2 varchar;
tamanho2 integer;
tamanho1 integer;
i integer;
j integer;
texto_original varchar;
BEGIN
   -- determinando o tamanho da segunda palavra
   tamanho2:=length(texto2);
   tamanho1:=length(texto1);
   -- pesquisando na primeira frase
   i := 1;
   texto_original := texto1;
   loop
        alvo_pesquisa := substr(texto_original, i, tamanho2);
        insert into lixo values(alvo_pesquisa, texto2, dice(alvo_pesquisa, texto2));
        if (dice(alvo_pesquisa, texto2)>0.75) then
             return true;
         end if;
i := i+1;
if (tamanho1 <= i) then
  exit;
end if;
   end loop;
   return false;
END;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100

Aplicação do algoritmo para um conjunto de palavras em qualquer ordem

CREATE OR REPLACE FUNCTION dice_frase3(texto1 character varying, texto2 character varying)
  RETURNS boolean AS
$BODY$
DECLARE
        ch2 varchar;
        t1 varchar;
t2 varchar;
i integer;
j integer;
k integer;
BEGIN
   j := 1;
   k := 1;
   loop
t2 = split_part(texto2, ' ',j);
if  (length(t2)=0) then
   exit;
end if;
i:=1;
loop
t1 = split_part(texto1, ' ',i);
if  (length(t1)=0) then
   exit;
end if;
insert into lixo values (t1, t2, i ||' '|| j || ' '|| k);
if (dice(t1, t2)>0.75) then
   k := k+1;
   exit;
end if;
i := i+1;
end loop;
j := j+1;
   end loop;
   if (j = k) then
        return true;
   else    
return false;
   end if;
END;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION dice_frase(character varying, character varying)
  OWNER TO postgres;