Пример #1
0
function formatTex()
{
    $fileName = BASE_PATH . "wiki2tex/tex/content/data/macros_raw.tex";
    $file_array = file($fileName, FILE_IGNORE_NEW_LINES);
    $fOutput = fopen("tex/content/data/macros.tex", "w+");
    //var_dump($file_array);
    foreach ($file_array as $line) {
        if (startsWith("\\item \\wikiref", $line)) {
            $line = formatter::toTex($line);
        } else {
            $line = formatter::toTex($line);
        }
        fwrite($fOutput, $line . PHP_EOL);
    }
    fclose($fOutput);
}
Пример #2
0
 /**
  * @expectedException \Exception
  */
 public function testFormatSizeThrowsExceptionWhenNotNumericValuePassed()
 {
     formatter::formatSize('test');
 }
Пример #3
0
 $macroTex .= '\\input{../../../101dev/tools/texgenerator/tex/ttc/data/' . $ttcTexTit . '}' . PHP_EOL;
 $s = new Page($title);
 // adding to ttcs.tex
 if ($s->discussion != '') {
     $ttcsTex .= '\\ttcdwiki{' . $pureTitle . '}' . PHP_EOL;
 } else {
     if ($s->technologies != '') {
         $ttcsTex .= '\\ttcdtwiki{' . $pureTitle . '}' . PHP_EOL;
     } else {
         $ttcsTex .= '\\ttcwiki{' . $pureTitle . '}' . PHP_EOL;
     }
 }
 $fTtcMacro = fopen($ttcsFolder . $ttcTexTit, 'w+');
 echo 'Saving macro for "' . $title . '"... ';
 $ttcMacroTex = $s->toTexMacro();
 $ttcMacroTex = formatter::intLinks($ttcMacroTex, $titles);
 $ttcMacroTex .= "\\newcommand{\\" . str_replace('_', '', str_replace(' ', '', $s->getTitle())) . "TtcLabel}{" . str_replace('_', '', str_replace(' ', '', $s->getTitle())) . "}" . PHP_EOL;
 //var_dump($links);
 fwrite($fTtcMacro, $ttcMacroTex);
 fclose($fTtcMacro);
 echo 'DONE' . PHP_EOL;
 echo 'Getting BibTex... ';
 foreach ($s->bibs as $bib) {
     $newbib = '';
     $i = 0;
     foreach (preg_split('/\\r\\n|\\r|\\n/', $bib) as $bibline) {
         if ($i != 0 && startsWith('title', ltrim($bibline))) {
             $bibline = preg_replace('/([A-Z]+)/', '{\\1}', $bibline);
         }
         $newbib .= $bibline . PHP_EOL;
         $i += 1;
Пример #4
0
 /**
  * @desc     Using the Strategy Design Pattern - to separate the formatting features into distinct and manageable classes
  * @param    object $formatter  Reference to the formatter 'strategy' class object to be used 
  * @return   mixed              Depending on formatter strategy, could be an formatted display, or excel export file
  */
 function generate_report($type)
 {
     $formatter =& formatter::factory($type);
     return $formatter->format_report($this);
 }
Пример #5
0
     // $cluster1->displayMostFrequentBinTerms($q);
     echo '</div><div class="span5"><h2>Results</h2>';
     // Print Cluser Term Results
     $aggregator1->printResultSetAggCluster(isset($_GET['term']) ? $_GET['term'] : ($_GET['term'] = ''));
     // end of DIV
     echo '</div></div> <!-- End of Class row -->';
     // Query Timer
     $time_post = microtime(true);
     $exec_time = $time_post - $time_pre;
     echo '</br>Query Time: ' . $exec_time;
 } else {
     if ($_SESSION['clust_op'] == 'b') {
         // Instantiate a new API
         $api1 = new api();
         // Instantiate a new formatter with the 3 result sets as properties
         $formatter1 = new formatter(new resultSet(), new resultSet(), new resultSet());
         // Google Results
         for ($i = 0; $i < $_SESSION['results'] / 10; $i++) {
             // Get offset
             $offset = 1 + $i * 10;
             // Call Google API
             $api1->googleApi($query1, $offset);
             // Set Google JSON Data
             $formatter1->setGoogleJson($api1->returnGoogleJsonData(), $api1->returnGoogleJsonResultFlag());
             $formatter1->formatGoogleJson($_SESSION['results'], $i * 10);
         }
         // Bing Results
         for ($i = 0; $i < ($_SESSION['results'] > 50 ? 2 : 1); $i++) {
             // Get offset
             $offset = 1 + $i * 50;
             // Call Bing API
Пример #6
0
 public static function toTex($text)
 {
     if ($text == '') {
         return '';
     }
     if ($text == null) {
         return '';
     }
     //var_dump($text);
     $pattern = '/(\\[\\[(Category:)((\\w|\\d|\\s|\\/|\\-|\\.|\\#)+)\\]\\])/';
     preg_match($pattern, $text, $out);
     if (count($out) > 0) {
         $replacement = '';
         $text = preg_replace($pattern, $replacement, $text);
     }
     $pattern = '/\\[\\[(:)?((\\w|\\d|\\s|\\/|\\-|\\.|\\#)+):((\\w|\\d|\\s|\\/|\\-|\\.|\\#)+)\\|((\\w|\\d|\\s|\\/|\\-|\\.|\\#|\')+)\\]\\]/';
     $replacement = '\\wikiref{\\2:\\4}{\\6}';
     $text = preg_replace($pattern, $replacement, $text);
     $pattern = '/\\[\\[(:)?((\\w|\\d|\\s|\\/|\\-|\\.|\\#)+):((\\w|\\d|\\s|\\/|\\-|\\.|\\#)+)\\|((\\w|\\d|\\s|\\/|\\-|\\.|\\#|\')+)\\]\\]/';
     $replacement = '\\wikiref{\\2:\\4}{\\6}';
     $text = preg_replace($pattern, $replacement, $text);
     //  --- recognize specific links ---
     $pattern = '/\\[\\[(Technology:)((\\w|\\d|\\s|\\/|\\-|\\.|\\#)+)\\]\\]/';
     $replacement = '\\wikitref{\\2}';
     $text = preg_replace($pattern, $replacement, $text);
     $pattern = '/\\[\\[(Language:)((\\w|\\d|\\s|\\/|\\-|\\.|\\#)+)\\]\\]/';
     $replacement = '\\wikilref{\\2}';
     $text = preg_replace($pattern, $replacement, $text);
     $pattern = '/\\[\\[(101feature:)((\\w|\\d|\\s|\\/|\\-|\\.|\\#)+)\\]\\]/';
     $replacement = '\\wikifref{\\2}';
     $text = preg_replace($pattern, $replacement, $text);
     $pattern = '/\\[\\[(101implementation:)((\\w|\\d|\\s|\\/|\\-|\\.|\\#)+)\\]\\]/';
     $replacement = '\\wikiiref{\\2}';
     $text = preg_replace($pattern, $replacement, $text);
     $pattern = '/\\[\\[(101companies:)((\\w|\\d|\\s|\\/|\\-|\\.|\\#)+)\\]\\]/';
     $replacement = '\\wikicref{\\2}';
     $text = preg_replace($pattern, $replacement, $text);
     //----------------------------------------------------------
     $pattern = '/\\[\\[(:)?((\\w|\\d|\\s|\\/|\\-|\\.|\\#)+):((\\w|\\d|\\s|\\/|\\-|\\.|\\#)+)\\]\\]/';
     $replacement = '\\wikiref{\\2:\\4}{\\4}';
     $text = preg_replace($pattern, $replacement, $text);
     $pattern = '/\\[\\[((\\w|\\d|\\s|\\/|\\-|\\.|\\#)+)\\]\\]/';
     $replacement = '\\wikiref{\\1}{\\1}';
     $text = preg_replace($pattern, $replacement, $text);
     $pattern = '/\\[\\[((\\w|\\d|\\s|\\/|\\-|\\.|\\#)+)\\|((\\w|\\d|\\s|\\/|\\-|\\.|\\#)+)\\]\\]/';
     $replacement = '\\wikiref{\\1}{\\3}';
     $text = preg_replace($pattern, $replacement, $text);
     $pattern = '/\\[http\\:\\/\\/(([^\\s])*)\\s*(.+)\\]/';
     $replacement = '\\href{http://\\1}{\\3}';
     $text = preg_replace($pattern, $replacement, $text);
     $pattern = '/\\[http\\:\\/\\/(([^\\s])*)\\]/';
     $replacement = '\\href{http://\\1}{http://\\1}';
     $text = preg_replace($pattern, $replacement, $text);
     $pattern = '/<pre>((\\s*|.|\\s)*)<\\/pre>/';
     preg_match($pattern, $text, $out);
     if (count($out) > 0) {
         $fname = uniqid("f") . ".ext";
         global $filesFolder;
         $f = fopen($filesFolder . $fname, "w+");
         fwrite($f, trim($out[1]));
         fclose($f);
         $pattern = '/<pre>((\\s*|.|\\s)*)<\\/pre>/';
         $replacement = '\\lstinputlisting[xleftmargin=20pt]{\\texgen/files/' . $fname . "}";
         /*
                 \begin{lstlisting}
                   put your code here
                 \end{lstlisting}
                 
                 $replacement = "\begin{lstlisting}" + trim($out[1]) + "end{lstlisting}"; */
         $text = preg_replace($pattern, $replacement, $text);
     }
     $pattern = '/<syntaxhighlight lang=\\"make" enclose=\\"none\\">(.*)<\\/syntaxhighlight>/';
     $replacement = '\\begin{ttfamily}\\1\\end{ttfamily}';
     $text = preg_replace($pattern, $replacement, $text);
     $sfURL = 'https://github.com/101companies/101implementations/blob/master/';
     $text = str_replace(" line>", ">", $text);
     $pattern = '/<syntaxhighlight lang=\\"([a-zA-Z]*)\\"(\\s*(source=\\"(.*)\\")?\\s*)>((\\s*|.|\\s)*)<\\/syntaxhighlight>/';
     preg_match_all($pattern, $text, $matches, PREG_SET_ORDER);
     foreach ($matches as $match) {
         //var_dump($matches);
         //echo PHP_EOL;
         $fname = uniqid("f") . ".ext";
         global $filesFolder;
         $sourceText = '';
         #if ($match[4] != null && $match[4]!= ''){
         #  $link = $sfURL.$match[4];
         #  $name = end(explode('/',$match[4]));
         #  $sourceText = ', caption={\\href{'.$link.'}{'.$name.'}}';
         #}
         $f = fopen($filesFolder . $fname, "w+");
         fwrite($f, trim($match[5]));
         fclose($f);
         $pattern = '<syntaxhighlight lang="' . $match[1] . '"' . $match[2] . '>' . $match[5] . '</syntaxhighlight>';
         // removed style attribute from the line below: , style=' . $match[1] . '
         // we need javascript support for the 101explorer paper
         if ($match[1] == "javascript") {
             $replacement = '\\lstinputlisting[xleftmargin=20pt language=javascript ' . $sourceText . ']{\\texgen/files/' . $fname . "}";
             //, language=' . $match[1] .$sourceText. //../../files/
         } else {
             $replacement = '\\lstinputlisting[xleftmargin=20pt ' . $sourceText . ']{\\texgen/files/' . $fname . "}";
             //, language=' . $match[1] .$sourceText. //../../files/
             #$replacement = "\begin{lstlisting}" + trim($match[5]) + "end{lstlisting}";
         }
         $text = str_replace($pattern, $replacement, $text);
     }
     /*
     $text = str_replace($pattern, $match[5], $text); //av: quick fix by Thomas
     $text = str_replace('lang="haskell" enclose="none">','lang="haskell">', $text);
     $text = str_replace('lang="haskell"  enclose="none">','lang="haskell">', $text);
     */
     $pattern = '/(<syntaxhighlight lang=\\"([a-zA-Z]*)\\" enclose=\\"none\\">)((\\s*|.|:|=|>|<|\\s|\\(|\\)|\\[|\\]|\\{|\\})*)(<\\/syntaxhighlight>)/';
     preg_match_all($pattern, $text, $matches, PREG_SET_ORDER);
     foreach ($matches as $match) {
         //var_dump($match);
         $replacement = '\\begin{ttfamily}' . $match[3] . '\\end{ttfamily}';
         $text = str_replace($match[0], $replacement, $text);
     }
     $text = str_replace('&', '\\&', $text);
     $text = str_replace('<nowiki>', '', str_replace('</nowiki>', '', $text));
     $text = str_replace('$', '\\$', $text);
     $text = formatter::handleCites($text);
     $text = formatter::handleBoldAndItalicSpecialCase($text);
     //we need this because regex cannot handle -> '''
     $text = formatter::italic2Textit($text);
     $text = formatter::handleBold($text);
     $text = str_replace('->', '$\\rightarrow$', $text);
     $text = str_replace('=>', '$\\Rightarrow$', $text);
     $text = str_replace('<', '$<$', $text);
     $text = str_replace('>', '$>$', $text);
     $text = str_replace('%', '\\%', $text);
     $text = str_replace("<references>", "", $text);
     $text = str_replace("<references/>", "", $text);
     $text = str_replace('^', '\\^', $text);
     $text = formatter::nestedList($text);
     $text = formatter::subsubsubsections($text);
     $text = formatter::subsubsections($text);
     $text = escape($text);
     $res = handleUmlauts($text);
     //var_dump($res);
     return trim($res);
 }
Пример #7
0
 function toTexMacro()
 {
     $tex = "\\newcommand{\\" . getTexCommandName($this->getTitle()) . "FeatureTitle}{" . $this->getTitle() . "}" . PHP_EOL;
     $tex .= "\\newcommand{\\" . getTexCommandName($this->getTitle()) . "FeatureIntent}{" . formatter::toTex($this->intent) . "}" . PHP_EOL;
     $tex .= "\\newcommand{\\" . getTexCommandName($this->getTitle()) . "FeatureDescription}{" . formatter::toTex($this->description) . "}" . PHP_EOL;
     $tex .= "\\newcommand{\\" . getTexCommandName($this->getTitle()) . "FeatureIllustration}{" . formatter::toTex($this->illustration) . "}" . PHP_EOL;
     return $tex;
 }