Tuesday, June 23, 2009

otowl : From relational data representation to object data representation || Du model relationel au model objet

English:

For those who recall a previous post about a project without any name, now i have a name and something to show ! I decided to call this project otowl. otowl stand in a way for "auto-owl" because the goal is to automatically convert relational data into an ontological, object representation. Yesterday, i finally successfully manage to independently form the original context, convert a boolean set of data (understand, the properties for the individuals are true or false) into a hierarchical, ontology represented by an owl/xml file. I am actually working on an online demo that will hit the web soon, keep you updated.
Stay tuned.

Francais:

Pour ceux qui se rappelleront un precedent billet concernant un projet sans nom, il en a maintenant un et utilisable ! J'ai ainsi decide de l'appeler otowl. otowl en partie signifie "auto-owl" car le but de ce projet est de propose un mecanism de convertion automatique de donnees sous forme relationnel vers un model ontologique, objet. J'ai finalement reussit hier a convertir un ensemble de donnees relationelles bouleennes (a comprendre que les proprietes d'un individu sont vraies ou fausses) vers un ensemble hierarchise, ontologique sous la forme d'un fichier owl/xml. Je travaille en ce moment sur une demo qui devrais arriver sur la toile tres prochainement.

Sunday, June 21, 2009

IE8 javascript & css quick fix || resolution rapide de probleme de javascript et css avec IE8

English:

I experienced some compatibility issue with some old js under IE8. For example, prototype.js's users, try new Element('div',{'class' : 'my_css_class'}). Yes, the style is not loading and don't throw any error. Troublesome isn't it ?

Therefor you can use  <meta content="IE=EmulateIE7" http-equiv="X-UA-Compatible" /> that will force IE8 to emulate 7 and will run accordingly.


Francais:

J'ai recement experimente quelques problemes de compatibilite entre IE8 et quelques vieux javascript. 
Par exemple, les utilisateurs de prototype.js pouront essayer new Element('div',{'class' : 'my_css_class'}). Et oui, le style ne charge pas. problematique non ?

Ansi, la directive  <meta content="IE=EmulateIE7" http-equiv="X-UA-Compatible" /> va forcer IE8 a emuler 7 et executer les commandes de la meme maniere.

Tuesday, June 9, 2009

manipulation de chaines de caractere japonaise en php | japanese string manipulation in php

*English version, go to the bottom of this post.

Francais:

Tout developeurs qui a eu la malchance de travailler au/avec le Japon s'est tres vite rendu compte que manipuler des chaines de caractere n'est aussi facile qu'qvec la langue de Moliere ou de Shakespeare. Encore plus malheureux sont les gens qui sont sur des projets php ou mes fonction mb_* ne fonctionnent pas aussi bien. Certain caracteres font 1 octet, d'autre 2 et voir meme pour certain 3. Cependant, j'ai lus (il y a maintenant un bout de temps) cet article en japonais http://phpspot.org/blog/archives/2005/11/php_17.html . L'expression reguliere presentee doit, en theorie, decouper en morepheme un texte en japonais. Autant vous dire que le linguiste qui est en moi, est en totale desaccord avec ce qu'avance son auteur. Neanmois, j'y ai vu la un interessant point de depart pour la manipulation de chaine de charactere japonaise et tout particulierement celle en SJIS. En modifiant un peu l'expression reguliere, j'ai obtenue un bon vieux tokenizer a 1 caractere des familles. Cela faisant, j'ai pu reimplementer tout les fonctions de base mais au combien pratiques comme substr, strpos, strlen etc...

English:

Every php developer who work in japan realized that mb_* function don’t work that good with SJIS encoded string. Some characters are considered as 1 byte length, or as 2 bytes and some as 3 bytes |-| ; Not really useful in the end. i recently discovered this article (in Japanese : http://phpspot.org/blog/archives/2005/11/php_17.html). The presented regEx is supposed to split a Japanese string into word. Linguistic-wise, I’m completely disagree with the results, but it was an interesting starting point for Japanese string manipulation and specially SJIS encoded ones :> . then i changed a little bit the regEx in order to obtain a one-character tokenizer. This regEx allow me afterward to re implement the basic but really useful string manipulation commands as substring, str_replace, strpos, strlen etc…

<?php

/*implementtation of the most basic string manipulation function for japanese, work the same way as the monobytes ones*/

class processJ
{
public function __construct()
{
mb_regex_encoding("SJIS");
}
public function __destruct()
{
}

//this method split a sjis encoded japanese string by character an return an array
public function charSpliter($str)
{
$token = array();
while(1)
{
     $bytes = mb_ereg("[一-龠]|[ぁ-ん]|[ァ-ヴー]|[a-zA-Z0-9]|[a-zA-Z0-9]", $str, $match);
     if ($bytes === false) {
       break;
     } else {
         $match = $match[0];
         $token[] = $match;
     }
     $pos = strpos($str, $match);
     $str = substr($str, $pos+$bytes);
}
return $token;
}
public function substrJ($str, $start, $lenght = NULL)
{
$strToken = $this->charSpliter($str);
$end = !empty($lenght) ? $lenght : count($strToken);
$substr = "";
for($i = $start; $i < $end; $i++)
{
$substr .= $strToken[$i];
}
return $substr;
}
public function strlenJ($str)
{
$strlen = $this->charSpliter($str);
return count($strlen);
}
public function strposJ($haystack, $needle)
{
$strToken = $this->charSpliter($haystack);
$needleToken = $this->charSpliter($needle);
$tokenLen = count($strToken);
$needleLen = count($needleToken);
for($i = 0; $i < $tokenLen; $i++)
{
if($strToken[$i] == $needleToken[0])
{
for($j = 0; $j < $needleLen; $j++)
{
if($needleToken[$j] !== $strToken[($i+$j)])
{
continue 2;
}
}
return $i;
}
}
}
public function str_replaceJ($search, $replace, $subject)
{
return $this->substrJ($subject,0,$this->strposJ($subject,$search)).$replace.$this->substrJ($subject,($this->strposJ($subject,$search)+$this->strlenJ($search)),$this->strlenJ($subject));
}
}

$test = new processJ(); print($test->substrJ("ようこそcyberblogへ漢字",0,4));  //> "ようこそ"
print($test->strlenJ("ようこそcyberblogへ漢字")); //> 16 
print($test->strposJ("ようこそcyberblogへ漢字", "cyber")); //> 4 
print($test->str_replaceJ("cyberblog","サイバーブログ","ようこそcyberblogへ漢字")); //> "ようこそサイバーブログへ漢字" 
?>