update_language_profiles.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.include.internationalization
  5. */
  6. /**
  7. * Code
  8. */
  9. $_current_dir = str_replace('\\', '/', realpath(dirname(__FILE__))).'/';
  10. $_sys_code_path = str_replace('\\', '/', realpath($_current_dir.'../../../../')).'/';
  11. $_sys_include_path = $_sys_code_path.'inc/';
  12. $_sys_library_path = $_sys_code_path.'inc/lib/';
  13. require_once $_sys_include_path.'global.inc.php';
  14. header('Content-Type: text/html; charset=UTF-8');
  15. $_SESSION['_user']['user_id'] = 1;
  16. function read_file($file_name) {
  17. $handle = fopen($file_name, 'rb');
  18. $string = fread($handle, filesize($file_name));
  19. fclose($handle);
  20. return $string;
  21. }
  22. function write_file($file_name, $text) {
  23. $handle = fopen($file_name, "w");
  24. fwrite($handle, $text);
  25. fclose($handle);
  26. }
  27. function get_directory_content($path) {
  28. $exceptions = array('.', '..', 'CVS', '.htaccess', '.svn', '_svn', 'index.html');
  29. $result = array();
  30. $path = realpath($path);
  31. if (!is_dir($path)) return $result;
  32. if (!$handle = opendir($path)) return $result;
  33. while (($dir_entry = readdir($handle)) !== false) {
  34. if (api_in_array_nocase($dir_entry, $exceptions)) continue;
  35. $dir_entry_full_path = $path .'/'. $dir_entry;
  36. if (filetype($dir_entry_full_path) != 'dir') {
  37. $result[] = str_replace("\\", '/', $dir_entry_full_path);
  38. }
  39. }
  40. closedir($handle);
  41. asort($result);
  42. return $result;
  43. }
  44. $files = get_directory_content($_current_dir.'sample_texts/');
  45. echo 'Updating language profiles...<br />';
  46. echo '<br />';
  47. foreach ($files as $file) {
  48. $language = basename($file, '.txt');
  49. echo $language.'<br />';
  50. write_file($_current_dir.'language_profiles/'.$language.'.txt', join("\n", _api_generate_n_grams(read_file($file), 'UTF-8', 400, 4)));
  51. }
  52. echo '<br />';
  53. echo 'Done.<br />';