Exemple #1
0
 public function updateSearchFields($name, $book, $chapter)
 {
     $database_bibles = Database_Bibles::getInstance();
     $database_config_bible = Database_Config_Bible::getInstance();
     $usfm = $database_bibles->getChapter($name, $book, $chapter);
     $stylesheet = $database_config_bible->getExportStylesheet($name);
     // Data to store.
     $usfmraw = array();
     $usfmlower = array();
     $plainraw = array();
     $plainlower = array();
     // Get the verses in the chapter.
     $verses = Filter_Usfm::getVerseNumbers($usfm);
     $verses = array_unique($verses);
     sort($verses, SORT_NUMERIC);
     // One column contains the raw USFM as it is, and another one the lowercase text.
     foreach ($verses as $verse) {
         $raw = Filter_Usfm::getVerseText($usfm, $verse);
         $lower = mb_convert_case($raw, MB_CASE_LOWER);
         $usfmraw[$verse] = $raw;
         $usfmlower[$verse] = $lower;
     }
     // Text filter for getting the plain text.
     $filter_text = new Filter_Text($name);
     $filter_text->text_text = new Text_Text();
     $filter_text->initializeHeadingsAndTextPerVerse();
     $filter_text->addUsfmCode($usfm);
     $filter_text->run($stylesheet);
     // Get the clean verse texts.
     $texts = $filter_text->getVersesText();
     foreach ($texts as $verse => $text) {
         if (!isset($plainraw[$verse])) {
             $plainraw[$verse] = "";
         }
         $plainraw[$verse] .= "{$text}\n";
     }
     // Add any clean headings.
     $headings = $filter_text->verses_headings;
     foreach ($headings as $verse => $heading) {
         if (!isset($plainraw[$verse])) {
             $plainraw[$verse] = "";
         }
         $plainraw[$verse] .= "{$heading}\n";
     }
     // Create the lower case plain text.
     foreach ($plainraw as $verse => $raw) {
         $plainlower[$verse] = mb_convert_case($raw, MB_CASE_LOWER);
     }
     // Get all possible verses.
     $allverses = array_merge(array_keys($usfmraw), array_keys($plainraw));
     $allverses = array_unique($allverses);
     // Store everything.
     Database_SQLite::exec($this->db, "BEGIN;");
     $name = Database_SQLiteInjection::no($name);
     $book = Database_SQLiteInjection::no($book);
     $chapter = Database_SQLiteInjection::no($chapter);
     $query = "DELETE FROM bibles WHERE bible = '{$name}' AND book = {$book} AND chapter = {$chapter};";
     Database_SQLite::exec($this->db, $query);
     foreach ($allverses as $verse) {
         if ($verse == "") {
             $verse = 0;
         }
         $verse = (int) $verse;
         @($ur = Database_SQLiteInjection::no($usfmraw[$verse]));
         @($ul = Database_SQLiteInjection::no($usfmlower[$verse]));
         @($pr = Database_SQLiteInjection::no($plainraw[$verse]));
         @($pl = Database_SQLiteInjection::no($plainlower[$verse]));
         $query = "INSERT INTO bibles (bible, book, chapter, verse, usfmraw, usfmlower, plainraw, plainlower) VALUES ('{$name}', {$book}, {$chapter}, {$verse}, '{$ur}', '{$ul}', '{$pr}', '{$pl}');";
         Database_SQLite::exec($this->db, $query);
     }
     Database_SQLite::exec($this->db, "COMMIT;");
 }
Exemple #2
0
 $verses = Filter_Usfm::getVerseNumbers($chapterUsfm);
 if ($check_versification) {
     Checks_Versification::verses($bible, $book, $chapter, $verses);
 }
 foreach ($verses as $verse) {
     $verseUsfm = Filter_Usfm::getVerseText($chapterUsfm, $verse);
     if ($check_double_spaces_usfm) {
         Checks_Space::doubleSpaceUsfm($bible, $book, $chapter, $verse, $verseUsfm);
     }
 }
 $filter_text = new Filter_Text($bible);
 $filter_text->initializeHeadingsAndTextPerVerse();
 $filter_text->addUsfmCode($chapterUsfm);
 $filter_text->run($stylesheet);
 $verses_headings = $filter_text->verses_headings;
 $verses_text = $filter_text->getVersesText();
 if ($check_full_stop_in_headings) {
     Checks_Headers::noPunctuationAtEnd($bible, $book, $chapter, $verses_headings, $center_marks, $end_marks);
 }
 if ($check_space_before_punctuation) {
     Checks_Space::spaceBeforePunctuation($bible, $book, $chapter, $verses_text);
 }
 if ($check_sentence_structure || $check_paragraph_structure) {
     $checks_sentences->initialize();
     if ($check_sentence_structure) {
         $checks_sentences->check($verses_text);
     }
     if ($check_paragraph_structure) {
         $checks_sentences->paragraphs($verses_text, $filter_text->paragraph_start_positions);
     }
     $results = $checks_sentences->getResults();
Exemple #3
0
    public function testEmbeddedTextOne()
    {
        $usfm = <<<'EOD'
\c 1
\p
\v 1 He said: I will sing \add to the \+nd Lord\+nd*\add*.
\v 2 The \nd Lord\nd* is my strength.
EOD;
        $filter_text = new Filter_Text("phpunit");
        $filter_text->initializeHeadingsAndTextPerVerse();
        $filter_text->addUsfmCode($usfm);
        $filter_text->run("Standard");
        $text = $filter_text->getVersesText();
        $standard = array(1 => "He said: I will sing to the Lord.", 2 => "The Lord is my strength.");
        $this->assertEquals($standard, $text);
    }
Exemple #4
0
// Create the updated chapter USFM as a string.
$updatedUsfm = implode("\n", $usfmArray);
// Text filter for getting the new plain text from the new USFM.
// This is for search/replace in plain text, not in USFM.
if ($searchplain) {
    $filter_text = new Filter_Text($bible);
    $filter_text->text_text = new Text_Text();
    $filter_text->initializeHeadingsAndTextPerVerse();
    $filter_text->addUsfmCode($updatedUsfm);
    $filter_text->run($stylesheet);
}
// Get the updated plain text of the correct verse of the updated USFM.
// This is for search/replace in plain text, not in USFM.
if ($searchplain) {
    $updatedPlainText = "";
    $texts = $filter_text->getVersesText();
    foreach ($texts as $vs => $text) {
        if ($vs == $verse) {
            $updatedPlainText .= "{$text}\n";
        }
    }
    $headings = $filter_text->verses_headings;
    foreach ($headings as $vs => $heading) {
        if ($vs == $verse) {
            $updatedPlainText .= "{$heading}\n";
        }
    }
}
// Check that the standard and real number of replacements, and the standard and new texts, are the same.
// This is for search/replace in plain text, not in USFM.
$replacementOkay = true;
Exemple #5
0
$chapters = $database_bibles->getChapters($bible, $book);
foreach ($chapters as $chapter) {
    // The text filter for this chapter.
    $filter_text_chapter = new Filter_Text($bible);
    // Basic USFM for this chapter.
    $filter_text_chapter->initializeHeadingsAndTextPerVerse();
    // Get the USFM code for the current chapter.
    $chapter_data = $database_bibles->getChapter($bible, $book, $chapter);
    $chapter_data = trim($chapter_data);
    // Add the chapter's USFM code to the Text_* filter for the book, and for the chapter.
    // Use small chunks of USFM at a time. This provides much better performance.
    $filter_text_book->addUsfmCode($chapter_data);
    $filter_text_chapter->addUsfmCode($chapter_data);
    // Convert the chapter
    $filter_text_chapter->run($stylesheet);
    // Deal with basic USFM.
    if ($chapter > 0) {
        $verses_text = $filter_text_chapter->getVersesText();
        $basicUsfm = "\\c {$chapter}\n";
        $basicUsfm .= "\\p\n";
        foreach ($verses_text as $verse => $text) {
            $basicUsfm .= "\\v {$verse} {$text}\n";
        }
        file_put_contents($usfmFilename, $basicUsfm, FILE_APPEND);
    }
}
// Convert the book.
$filter_text_book->run($stylesheet);
// Save the text export.
$filter_text_book->text_text->save($textFilename);
$database_logs->log($bible . " " . Export_Logic::baseBookFileName($book) . ": " . Locale_Translate::_("Exported to basic USFM and text"), Filter_Roles::TRANSLATOR_LEVEL);