Exemplo n.º 1
0
 /**
  * Parse the given file for apprentices and mentors.
  *
  * @param string $file Path to the File to parse.
  *
  * @return array
  */
 public function parse($file)
 {
     $return = array('mentors' => array(), 'apprentices' => array());
     $content = file_Get_contents($file);
     $content = str_Replace('<local-time', '<span tag="local-time"', $content);
     $content = str_Replace('</local-time', '</span', $content);
     $content = str_Replace('<time', '<span tag="time"', $content);
     $content = str_Replace('</time', '</span', $content);
     $this->dom = new \DomDocument('1.0', 'UTF-8');
     $this->dom->strictErrorChecking = false;
     libxml_use_internal_errors(true);
     $this->dom->loadHTML('<?xml encoding="UTF-8" ?>' . $content);
     libxml_use_internal_errors(false);
     $xpathMentors = new \DOMXPath($this->dom);
     $mentors = $xpathMentors->query('//a[@id="user-content-mentors-currently-accepting-an-apprentice"]/../following-sibling::ul[1]/li');
     foreach ($mentors as $mentor) {
         $user = $this->parseUser($mentor);
         if (!$user) {
             continue;
         }
         $user['type'] = 'mentor';
         $return['mentors'][] = $user;
     }
     $xpathApprentices = new \DOMXPath($this->dom);
     $apprentices = $xpathApprentices->query('//a[@id="user-content-apprentices-currently-accepting-mentors"]/../following-sibling::ul[1]/li');
     foreach ($apprentices as $apprentice) {
         $user = $this->parseUser($apprentice);
         if (!$user) {
             continue;
         }
         $user['type'] = 'apprentice';
         $return['apprentices'][] = $user;
     }
     return $return;
 }
Exemplo n.º 2
0
 public static function provider()
 {
     return array_map(function ($file) {
         $text = file_get_contents($file);
         $expected = file(substr($file, 0, -3) . 'expected', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
         $summary = file_Get_contents(substr($file, 0, -3) . 'summary', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
         return [$text, $expected, trim($summary)];
     }, glob(__DIR__ . "/fixtures/*.txt"));
 }
Exemplo n.º 3
0
 /** @dataProvider provider */
 public function testAll($path)
 {
     $dir = __DIR__ . '/tmp/' . substr(basename($path), 0, -4);
     @mkdir($dir);
     require $path;
     $fixtures = glob(substr($path, 0, -4) . "/*");
     $generated = glob($dir . "/*");
     $this->assertEquals(count($fixtures), count($generated));
     foreach ($fixtures as $file) {
         $base = substr($file, strlen($path) - 4);
         $this->assertTrue(is_file($dir . '/' . $base));
         $xml = preg_replace('/>\\W+</', '><', file_Get_contents($file));
         $xml = str_replace('%date%', date('c'), $xml);
         $this->assertEquals($xml, file_get_contents($dir . '/' . $base));
     }
 }
Exemplo n.º 4
0
<?php

$filecontent1 = file_get_contents('/home/nlp/corpus_wei/europarl_clean_1-9000.en');
$filecontent2 = file_Get_contents('/home/nlp/corpus_wei/europarl_clean_1-9000.fr');
/*
$filecontent1 = file_get_contents('/home/nlp/corpus_wei/easy.en');
$filecontent2=file_Get_contents('/home/nlp/corpus_wei/easy.fr');*/
$english_words = preg_split('/[\\s]+/', $filecontent1, -1, PREG_SPLIT_NO_EMPTY);
//print_r($words);
//print "words[182128]:"+ $words[0];
$foreign_words = preg_split('/[\\s]+/', $filecontent2, -1, PREG_SPLIT_NO_EMPTY);
$combine_words_array = array_merge($english_words, $foreign_words);
print_r($combine_words_array);
print "=============================";
$combine_arr_size = count($combine_words_array);
//echo $combine_arr_size;
//===============================
$servername = "localhost";
$username = "******";
$password = "******";
$dbname = "testdb";
$s = microtime(true);
mysql_connect($servername, $username, $password) or die(mysql_error());
mysql_select_db($dbname);
$counter = 0;
$execute_count = 9000;
$sql = "INSERT INTO EM (source,target) VALUES ";
/*
$res = array();
foreach($combine_words_array as $v1) {
  foreach($combine_words_array as $v2) {
Exemplo n.º 5
0
</head>
<body>
<?php 
require '../' . $section . '/pages.inc.php';
echo '<a href="../' . $section . '/index.php?' . $req_lang . '" target="_top">';
get_text('back_to_chapters');
echo '</a>';
foreach ($_pages as $file => $title) {
    if ($req_lang != 'en' && file_exists('../' . $section . '/' . $req_lang . '/' . $file)) {
        $string = file_get_contents('../' . $section . '/' . $req_lang . '/' . $file);
    } else {
        if ($req_lang != 'en') {
            ?>
		<div style="margin: 20px auto; border: 1px solid #aaf; padding: 4px; text-align: center; background-color: #eef;">
			<?php 
            get_text('page_not_translated');
            ?>
		</div>
		<?php 
            $string = file_get_contents('../' . $section . '/' . $file);
        } else {
            $string = file_Get_contents('../' . $section . '/' . $file);
        }
    }
    $patterns = array('#<a href="(?!http)([[:alnum:].?/_-]+)"([^>]*)>([^<]+)</a>#is', '#<a href="http://([[:alnum:]./_-]+)"([^>]*)>([^<]+)</a>#i');
    $replacements = array('<strong><u>$3</u></strong>', '<strong><u>$3</u></strong> [$1]');
    echo preg_replace($patterns, $replacements, $string);
}
?>
</body>
</html>