From work on OT PDF producer

This commit is contained in:
Henry Whitney 2019-01-17 18:30:06 -05:00
parent 7487dd50a9
commit d2e755ed0c
1 changed files with 204 additions and 0 deletions

View File

@ -0,0 +1,204 @@
# Routine to take missing.log entries and link to UGNT and ULB.KJV.Strongs
use 5.12.0;
use File::Slurp;
$| = "\n";
use utf8;
#use open IN => ":utf8", OUT => ":utf8";
use open IO => ":utf8";
use File::Find ;
use Cwd ;
binmode(STDOUT, "encoding(UTF-8)");
say "not adapted for OT yet"; die;
my ($outputFiles, $topDir, $xmlFile, $txtFile, $lbsBk, $dataFile, $doFlag) = (
"/Users/Henry/Documents/git.Door43/en_tw/bible/",
"/Users/Henry/Documents/git.Door43/en_tw/bible",
"",
"/Users/Henry/Google Drive/WA/Test/data/ULB.NASB.Strongs.txt",
"",
"/Users/Henry/Google Drive/WA/Test/data/tW.work.dat"
);
my ($missingLine, $bk, $ch, $vs, $ref, $url, $strong, $word, $flag, $putative, $tNid, $abbr);
open LOG, ">:utf8", "/Users/Henry/Google Drive/WA/Test/out/mine.log.log" or die;
#open OUT, ">:utf8", $outputFile or die;
ParseLine();
FindURL();
FindVerse($ref);
ChecktWPages($word);
Finish();
#close OUT;
close LOG;
print "\n\tDone.\n\n";
sub ParseLine {
say "\n\n\033[0;1;31mEnter line from missing.log:\033[m\n";
$missingLine = <STDIN>; # I moved chomp to a new line to make it more readable
chomp $missingLine; # Get rid of newline character at the end
exit 0 if ($missingLine eq ""); # If empty string, exit.
#$missingLine = "Mark 11:6 kt/command";
if ($missingLine =~ /^(([^:]*) (\d+):(\d+))\t([^\/]*\/([^\t]*))/) {
($ref, $bk, $ch, $vs, $url, $putative) = ($1, $2, $3, $4, $5, $6);
$outputFiles .= "${url}.md ";
say LOG "\$bk: $bk";
open (my $file, "<:utf8", "$dataFile") or die "$dataFile:\n$!";
while (my $line = <$file>) {
chomp $line;
if ($line =~ /^(# )?([^\t]*)\t([^\t]*)\t([^\t]*)$/) {
my ($fullBk, $numBk, $abr) = ($2, $3, $4);
say LOG "\$fullBk: |$fullBk|, \$numBk: $numBk, \$abr: $abr, \$bk: |$bk|";
if ($fullBk eq $bk) {
say LOG "\$fullBk: |$fullBk|, \$bk: |$bk|";
$lbsBk = $abr;
if ($numBk =~ /(\d\d)-(...)/) {
$abbr = lc $2;
say LOG "\$abbr: $abbr";
my $mxl;
if ($bk eq "Psalms?") {$mxl = 3}
else {$mxl = 2}
while (length $ch < $mxl) {$ch =~ s/^/0/}
while (length $vs < $mxl) {$vs =~ s/^/0/}
}
$xmlFile = "/Users/Henry/Google Drive/WA/OSHB/${numBk}.xml";
say LOG "\$abbr/\$ch/\$vs: $abbr/$ch/$vs";
system `open -a /Applications/BBEdit.app /Users/Henry/Documents/git.Door43/en_tn/$abbr/$ch/$vs.md`;
}
}
}
close $file;
} else {
die "\n\tInput unreadable.\n"
}
say LOG "Looking for $putative in $xmlFile";
say LOG "\$missingLine: $missingLine, \$ref: $ref, \$bk: $bk, \$ch: $ch, \$vs: $vs, \$url: $url\n\n";
#system `open -a /Applications/Logos.app "logosres:esv;ref=BibleESV.$lbsBk${ch}.$vs"`;
system `open -a /Applications/Logos.app "logos4:TextComparison;ref=BibleESV.$lbsBk${ch}.$vs;res=esv,niv2011,niv,nasb95,nrsv,gs-netbible,nlt,leb,kjv1900"
`;
}
sub FindURL {
my ($thisChap, $thisVers);
open (my $file, "<:utf8", "$xmlFile") or die "$xmlFile:\n$!";
while (my $line = <$file>) {
chomp $line;
if ($line =~ /\\mt (.*)$/) {
my $thisBook = $1;
if ($thisBook eq $bk) {
say LOG "\$thisBook: $thisBook\t\$bk: $bk";
$doFlag = 1;
} else {
say LOG "\nThe wrong book is being searched.\n"
}
} elsif ($doFlag && $line =~ /^\\c (\d+)$/) {
$thisChap = $1
} elsif ($doFlag && $line =~ /^\\v (\d+)$/) {
$thisVers = $1
} elsif ($doFlag && $thisChap == $ch && $thisVers == $vs) {
say LOG "$thisChap:$thisVers $line";
if ($line =~ /strong="([GH]....)(.).*$url/) {
say "\n\$line:\n$line\n";
$strong = $1;
my $test = $2;
if ($test ne "0") {die "\n\t\tStrong's number won't work.\n\n"}
unless ($strong =~ /^.+$/) {die "\nThe Strong's number <$strong> is not found.\n"}
while ($strong =~ s/([GH])0/$1/) {}
if ($strong =~ /^.+$/) {
say "\033[0;1;31m$strong\033[m\n";
last
}
} elsif ($line =~ /\\k-s[^\n]*$url/) {
say "\n\t$url is part of a phrase\n";
$flag = 1;
}
} elsif ($line =~ /\\mt (.*)$/) {
$doFlag = 0
}
}
close $file;
}
sub FindVerse {
my $fileText = read_file("$txtFile", binmode => 'utf8');
say LOG "FindVerse |$strong|.";
if ($flag && $fileText =~ /$ref\t[^\n]*\n[^\n]*\n/) {
say LOG "$ref\n$&";
say $&;
exit 0;
} else {
if ($fileText =~ /$ref([^\n]*\n )([^\n]*<)$strong(.?>[^\n]*)/) {
my ($fore, $precon, $aft) = ($1, $2, $3);
say LOG "\$ref: $ref\n\$fore: $fore\n\$precon:\n$precon\n\$aft: $aft";
my $preprecon;
if ($precon =~ /^(.*([,>\w\'\"\- —;] |['";\.\?\!]))([\w\-]+) (<[^<>]*> )?<$/) {
($preprecon, $word) = ($1, $3);
say LOG "\$&: $&\n\$preprecon: $preprecon\n\$word: $word";
}
say "$ref$fore$preprecon\033[0;0;32m$word\033[m <\033[0;1;31m$strong\033[m$aft\n";
}
else {
say "\n\nThe Strong's code <<$strong>> is not found in $ref.\n\n";
system ("bbfind -g \"${ref}\\t[^\\n]*\\n[^\\n]*\" '/Users/Henry/Google Drive/WA/Test/data/ULB.NASB.Strongs.txt'") or die "$!";
system ("find $topDir -name \"*.md\" -exec grep -H --color \"$strong\[, \\n\\r\]\" {} \\;");
#system ("find $topDir -name \"*.md\" -exec grep -H --color \"$strong\$\" {} \\;");
}
}
return $word;
}
sub ChecktWPages{
say LOG "<<$word>>";
die "\n\$word is empty.\n" if $word eq "";
my $topDir = "/Users/Henry/Documents/git.Door43/en_tw/bible";
my @filesToRun = ();
my $filePattern = '*.md' ;
find( sub { push @filesToRun, $File::Find::name if ( m/^(.*)$filePattern$/ ) }, $topDir) ;
foreach my $file ( @filesToRun ) {
my $fileText = read_file("$file", binmode => 'utf8');
# While finds entries and Strong's numbers
while ($fileText =~ /($strong)[^\d]|^(# [^\n]*\b$word\b)/g) {
#system `clear`;
my $abb = $file;
$abb =~ s/.md$//;
say "\033[0;1;31m$abb\033[m";
$outputFiles .= "$file "
}
}
}
sub Finish {
say "\nLooking for $strong.";
# find $topDir -name "*.md" -exec grep -H '($strong[^\d]|$strong$)' {} +
system ("find $topDir -name \"*.md\" -exec grep -H --color \"$strong\[, \\n\\r\]\" {} \\;");
system ("find $topDir -name \"*.md\" -exec grep -H --color \"$strong\$\" {} \\;");
#system ("find $topDir -name \"*.md\" -exec grep -H --color \"\($strong\[, \\n\\r\]\|$strong\$\)\" {} \\;");
say "\nLooking for $putative.";
#system ("find $topDir -name \"*.md\" -exec grep -Hi --color \"^# $putative\[^A-Za-z\]\" {} \\;");
#system ("find $topDir -name \"*.md\" -exec grep -Hi --color \"^# .*\[^A-Za-z\]$putative\[^A-Za-z\]\" {} \\;");
system ("find $topDir -name \"*.md\" -exec egrep -Hi --color \"^# (.*\[^A-Za-z\])?$putative\[^A-Za-z\]\" {} \\;");
say "\nLooking for $word.";
#system ("find $topDir -name \"*.md\" -exec grep -Hi --color \"^#$word\[^A-Za-z\]\" {} \\;");
#system ("find $topDir -name \"*.md\" -exec grep -Hi --color \"^# .*\[^A-Za-z\]$word\[^A-Za-z\]\" {} \\;");
system ("find $topDir -name \"*.md\" -exec egrep -Hi --color \"^# (.*\[^A-Za-z\])?$word\[^A-Za-z\]\" {} \\;");
say "Opening .md files.";
system `open -a /Applications/Firefox.app https://www.blueletterbible.org/lang/lexicon/lexicon.cfm?strongs=$strong`;
system `open -a /Applications/BBEdit.app $outputFiles`;
}