Wiki‎ > ‎Tweaking Philologic‎ > ‎

Mk_art2object.pl

This script written by Mark creates an index file called artid2pg.idx which links DIV ids to page numbers and allows you to generate links to pages from DIV-level search results. art2object.pl comes in the goodies directory of Philologic.

If you would also like to include page numbers next to KWIC results, please see KwicPageNumbers.


Cookbook

A brief description of how to get page numbers to display after headwords or other DIV-level object searches.


Get art2object.pl

Copy mk_art2object.pl from the goodies directory of your Philologic install into the $SYSDIR (the install directory) for the database you are working on. For example:

cp /var/lib/philologic/goodies/art2object.pl /var/lib/philologic/databases/mydictionary/

Run art2object.pl

Execute the script from within the $SYSDIR of your database like so:

cd /var/lib/philologic/databases/mydictionary/
ls TEXTS/ | perl mk_art2object.pl > artid2pg.idx

Modify DivDisplayLine in philosubs.pl

Change DivDisplayLine in philosubs.pl to look something like this:

sub DivDisplayLine {
local ($thedivline, $results, $rtn, $subresults);
$thedivline = $_[0];
@results=split(/\t/, $thedivline);
$rtn .= "<br><a href=\"";
$rtn .= $PHILOGETOBJECT . "?c." . $results[0];
$rtn .= "." . $dbname . "\">";
$rtn .= "$results[1]</a>";
@subresults = split(":", $results[0]);
#$rtn .= &getbiblioLine($subresults[0], "link");

$pagelink = DivPageLink($results[0]);
return ($rtn . " " . $pagelink);
}

Add DivPageLink to philosubs.pl

Add a new subroutine to philosubs.pl that looks like this:

# -----------------------------------------------------------------------
# DivPageLink: Using mk_art2object.pl to create artid2pg.idx, then
# using this subroutine enables you to get a page link from
# your div search results
# -----------------------------------------------------------------------

sub DivPageLink {
local ($objectid, $rtn, $IMGSVR, $art2pgfil, $linin, $ress, $imgfilname);
$IMGSVR = "http://artfl.uchicago.edu/cgi-bin/philologic/moreripag.pl?";
$objectid = $_[0];

$objectid =~ s/^(\d+:)\d+:/\1/;

#print "<br><br>objectid: $objectid<br><br>";

if (!$readartid2pg) {
$art2pgfil = $SYSTEM_DIR . "artid2pg.idx";
open (ART2PG, "$art2pgfil");
while ($linin = <ART2PG>) {
@ress = split("\t", $linin);
$obj2internalpage{$ress[1]} = $ress[2];
$obj2realpage{$ress[1]} = $ress[4];
$readartid2pg++;
}
close (ART2PG);
}

$internalpage = $obj2internalpage{$objectid};


$realpage = $obj2realpage{$objectid};

$realpage =~ s/^0*//;
chop($realpage);
#print "real: $realpage<br>";

return "(page <a href='/cgi-bin/philologic/getobject.pl?p." . $internalpage . ".$dbname'>" . $realpage . "</a>)";


}


Variant or Possible Bugfix

A new version of mk_art2object.pl was generated for use a project where it was noticed that the first two objects on each page were incorrectly being linked to the previous page. Here's a diff of the old script on the left and new script on the right:

<     $div = 0;
---
> $div = -1;
49c49
< if (/<div/) {
---
> if (/<div2/) {

These differences between this script and the stock one that comes with Philologic 3 are simple. First, we only increment $div when we see <div2, not just <div, because only <div2 signifies a new entry in DSAL dicos. Secondly, we start $div at -1 instead of 1, because the first object is index 0 and we incremement before writing out the index.

Do all databases need that? We're not sure right now.

Subpages (1): Artid2pg.idx
Comments