jueves, 29 de abril de 2010

Google translator para language detection

Ref: google apis

Prueba con inglés:

pablo@pablo-desktop:~$ curl -e http://www.fcwm.cl \
'http://ajax.googleapis.com/ajax/services/language/detect?v=1.0&
q=hello%20world'
{"responseData": {"language":"en","isReliable":false,"confidence":0.114892714}, "responseDetails": null, "responseStatus": 200}

Prueba con italiano:

pablo@pablo-desktop:~$ curl -e http://www.fcwm.cl \
'http://ajax.googleapis.com/ajax/services/language/detect?v=1.0&
q=ciao+a+tutti'
{"responseData": {"language":"it","isReliable":false,"confidence":0.29042974}, "responseDetails": null, "responseStatus": 200}

Prueba con español:

pablo@pablo-desktop:~$ curl -e http://www.fcwm.cl \
'http://ajax.googleapis.com/ajax/services/language/detect?v=1.0&
q=hola+a+todos'
{"responseData": {"language":"es","isReliable":false,"confidence":0.28695157}, "responseDetails": null, "responseStatus": 200}

Prueba de detección de español con mayor "confidence" al agregar más palabras:

pablo@pablo-desktop:~$ curl -e http://www.fcwm.cl \
'http://ajax.googleapis.com/ajax/services/language/detect?v=1.0&
q=hola+a+todos+los+cabros+de+la+cuadra'
{"responseData": {"language":"es","isReliable":true,"confidence":0.6409442}, "responseDetails": null, "responseStatus": 200}

Cómo setear el content-type y el charset en la respuesta de un restlet

Papita:

@Override
public Representation getRepresentation(Variant variant) {
if (MediaType.TEXT_XML.equals(variant.getMediaType())) {
...
StringRepresentation representation = new StringRepresentation(xmlText,
MediaType.TEXT_XML, Language.ENGLISH, CharacterSet.UTF_8);
return representation;
}
}

jueves, 22 de abril de 2010

Whole word search en java usando regex


Pattern myPattern = Pattern.compile("\\bSebastián Piñera\\b",
Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.MULTILINE
| Pattern.UNICODE_CASE | Pattern.CANON_EQ);

String text;
Matcher matcher;

text = "de la pradera camión\nSebastián Piñera";
matcher = myPattern.matcher(text);
System.out.println(matcher.find());

text = "clorox de la pradera Sebastián Piñera jaja";
matcher.reset(text);
System.out.println(matcher.find());

text = "clorox de la pradera jaja";
matcher.reset(text);
System.out.println(matcher.find());


(Ojo con el uso eficiente del "matcher" mediante el método "reset")

Imprimirá:


true
true
false


Ref: http://www.regular-expressions.info/java.html

lunes, 12 de abril de 2010

Export en shell para que java tenga output en UTF8

Hay que hacer un declare de LANG, para que aparezca en el export de la sgte manera:


$ export
...
declare -x LANG="en_US.UTF-8"

miércoles, 31 de marzo de 2010

PHP - cómo darse cuenta de un error de insert por duplicate key


$result = mysql_query($query);
if (!$result) {
if (mysql_errno()==1062) { //Duplicate entry
log_info("user already created");
}
else {
throw new Exception("Invalid query, error: " . mysql_error(),$query);
}
}

miércoles, 24 de marzo de 2010

Cómo generar un jar de json

1. Download http://www.json.org/java/json.zip from json.org. Save it in a some directory, which I'll call %DOWNLOAD_HOME%.

2. Unzip it. Be sure you preserve the archive's directory structure (/org/json/) when you unzip the file.

3. Change directory into %DOWNLOAD_HOME%\org\json

4. Compile the files by running “javac *.java”. At least, this worked for me. There is no build.xml or anything, and it just seemed to compile into classes nicely.

5. CD back into %DOWNLOAD_HOME%

6. Create a jar file called json.jar. The syntax is something like:

jar -cvf json.jar org\json\*.class

Ref: http://processing.org/discourse/yabb2/YaBB.pl?board=Integrate;action=display;num=1163101573

miércoles, 10 de marzo de 2010

SQL - cómo separar las condiciones de join de las condiciones de negocio

Típica consulta:

SELECT r.nombre, c.nombre
FROM Region r, Ciudad c
WHERE r.idregion=c.idregion AND c.fechafundacion>='1810-01-01'


En ella, el where mezcla condiciones de join (r.idregion=c.idregion) y de negocio (c.fechafundacion>='1810-01-01'):


En la sgte consulta, en el join+using aislamos las condiciones de join. En el where aislamos las condiciones de negocio:


SELECT r.nombre, c.nombre
FROM Region r JOIN Ciudad c USING (idregion)
WHERE c.fechafundacion>='1810-01-01'