Data-Edit-Xml-Reuse
view release on metacpan or search on metacpan
lib/Data/Edit/Xml/Reuse.pm view on Meta::CPAN
#!/usr/bin/perl -I/home/phil/r/salesForce/perl/ -I/home/phil/perl/cpan/DataEditXml/lib -I/home/phil/perl/cpan/DataTableText/lib -I/home/phil/perl/cpan/DitaGBStandard/lib -I/home/phil/perl/cpan/DataEditXmlToDita/lib -I/home/phil/perl/cpan/DataEditXml...
#-------------------------------------------------------------------------------
# Reuse Xml via Dita conrefs.
# Philip R Brenan at gmail dot com, Appa Apps Ltd Inc, 2019
#-------------------------------------------------------------------------------
# podDocumentation
package Data::Edit::Xml::Reuse;
our $VERSION = 20200503;
use v5.26;
use warnings FATAL => qw(all);
use strict;
use Carp qw(confess cluck);
use Data::Dump qw(dump);
use Data::Edit::Xml;
use Data::Edit::Xml::Xref;
use Data::Table::Text qw(:all);
use Dita::GB::Standard;
use Storable qw(store retrieve);
use Time::HiRes qw(time);
use utf8;
#D1 Reuse Xml # Reuse Xml via Dita conrefs.
sub newReuse(%) #P Create a new cross reuser.
{my (%attributes) = @_; # Attributes
my $reuse = genHash(__PACKAGE__, # Attributes used by the reuser.
dictionary => undef, #I The dictionary file into which to store the duplicate L<Xml>.
fileExtensions => [qw(.dita .ditamap .xml .fodt)], #I The extensions of the L<Xml> files to examine in the L<inputFolder>.
getFileUrl => qq(/cgi-bin/uiSelfServiceXref/client.pl?getFile=), #I An optional url to retrieve a specified file from the server running xref used in generating html reports. The complete url is obtained by appending the fully qualifie...
htmlFolder => undef, #I Folder into which to write reports as html.
inputFiles => [], # The files selected from L<inputFolder> for analysis because their extensions matched L<fileExtensions>.
inputFolder => undef, #I A folder containing the L<xml> files with extensions named in L<fileExtensions> to be analyzed for reuse.
matchBlocks => [], # [[md5, content]*] blocks of content that match with the confidence level expressed by L<matchSimilarContent>
matchInBlock => {}, # {md5 => matchBlocks} : index into L<matchBlocks> by md5 sum.
matchSimilarTagContent => 0.5, #I Confidence level between 0 and 1: match content under L<tags> with this level of confidence.
maximumColumnWidth => 180, #I Truncate columns in text reports to this length or allow any width if B<undef>.
minimumLength => 16, #I The minimum length content must have to be considered for matching.
minimumReferences => 2, #I The minimum number of references content must have before it can be reused.
outputFolder => undef, #I A folder into which to write the deduplicated L<Xml>.
reportsFolder => undef, #I A folder into which reports will be written.
reusableContent => {}, # {tag}{md5sum}{content}++ potentially reusable content.
tags => {p=>1}, #I {tag=>1} only consider tags that appear as keys in this hash with truthful values.
timeEnded => undef, # Time the run ended.
timeStart => undef, # Time the run started.
);
loadHash($reuse, @_); # Load attributes complaining about any invalid ones
} # newReuse
sub reuse(%) # Check Xml for reuse opportunities.
{my (%attributes) = @_; # Reuse attributes
my $reuse = newReuse(%attributes); # Create the reuser
$reuse->timeStart = time; # Start time
for my $attr(qw(inputFolder outputFolder reportsFolder))
{$reuse->{$attr} or confess "Please supply a value for: $attr";
}
$reuse->dictionary //= fpe($reuse->outputFolder, qw(dictionary xml)); # Default dictionary
lll "Reuse started on input folder:", $reuse->inputFolder; # Title
my @series = # Must be done in series at the start
(q(loadInputFiles),
q(analyzeInputFiles),
q(conRef),
);
if (1) # Perform phases in series that must be run in series
{my @times;
for my $phase(@series) # Each phase in series
{my $startTime = time;
lll "Reuse phase $phase";
( run in 1.136 second using v1.01-cache-2.11-cpan-751830e7986 )