##========================================================================
## POD DOCUMENTATION, auto-generated by podextract.perl

##========================================================================
## NAME
=pod

=head1 NAME

DiaColloDB::Relation::Cofreqs - diachronic collocation db, profiling relation: native fixed-window co-frequency index

=cut

##========================================================================
## ALIASES
=pod

=head1 ALIASES

=over 4

=item DiaColloDB::Relation::Cofreqs

=item DiaColloDB::Cofreqs

=back

=cut

##========================================================================
## SYNOPSIS
=pod

=head1 SYNOPSIS

 ##========================================================================
 ## PRELIMINARIES
 
 use DiaColloDB::Relation::Cofreqs;
 
 ##========================================================================
 ## Constructors etc.
 
 $cof = $CLASS_OR_OBJECT->new(%args);
 
 ##========================================================================
 ## I/O: open/close
 
 $cof_or_undef = $cof->open($base,$flags);
 $cof_or_undef = $cof->close();
 $bool = $cof->opened();
 
 ##========================================================================
 ## I/O: header
 
 @keys = $cof->headerKeys();
 $bool = $cof->loadHeaderData($hdr);
 
 ##========================================================================
 ## I/O: text
 
 $cof  = $cof->loadTextFh($fh,%opts)
 $bool = $cof->saveTextFh($fh,%opts);
 
 ##========================================================================
 ## Relation API: creation
 
 $cof = $CLASS_OR_OBJECT->create($coldb,$tokdat_file,%opts);
 $cof = CLASS_OR_OBJECT->union($coldb, \@pairs, %opts);
 
 ##========================================================================
 ## Relation API: default
 
 \%slice2prf = $cof->subprofile1(\@tids, \%opts);
 \%slice2prf = $cof->subprofile2(\%slice2prf, \%opts);
 \%slice2prf = $cof->subextend(\%slice2prf, \%opts);
 
 \%qinfo = $rel->qinfo($coldb, %opts);
 

=cut

##========================================================================
## DESCRIPTION
=pod

=head1 DESCRIPTION

DiaColloDB::Relation::Cofreqs
is a L<DiaColloDB::Relation|DiaColloDB::Relation> subclass for
native indices over collocation frequencies within a fixed-length window of context words
using a pair of L<DiaColloDB::PackedFile|DiaColloDB::PackedFile> objects
for low-level index data.

Only simple queries expressed as a disjunction of single-term conditions
(i.e. those queries which evaluate to a set of term-tuples) are supported.
Likewise, only C<groupby> conditions over literal indexed term-attributes are supported.

=cut

##----------------------------------------------------------------
## DESCRIPTION: DiaColloDB::Relation::Cofreqs: Globals & Constants
=pod

=head2 Globals & Constants

=over 4

=item Variable: @ISA

DiaColloDB::Relation::Cofreqs inherits from
L<DiaColloDB::Relation|DiaColloDB::Relation>.

=item Variable: $WANT_XS

Attempt to use optimized L<DiaColloDB::XS::CofUtils|DiaColloDB::XS::CofUtils> subroutines?
Default: C<undef>: use XS if available.

=back

=cut

##----------------------------------------------------------------
## DESCRIPTION: DiaColloDB::Relation::Cofreqs: Constructors etc.
=pod

=head2 Constructors etc.

=over 4

=item new

 $cof = CLASS_OR_OBJECT->new(%args);

%args, object structure:

 ##-- user options
 class    => $class,      ##-- optional, useful for debugging from header file
 base     => $basename,   ##-- file basename (default=undef:none); use files "${base}.dba1", "${base}.dba2", "${base}.dba3", "${base}.hdr"
 flags    => $flags,      ##-- fcntl flags or open-mode (default='r')
 perms    => $perms,      ##-- creation permissions (default=(0666 &~umask))
 dmax     => $dmax,       ##-- maximum distance for co-occurrences (default=5)
 fmin     => $fmin,       ##-- minimum pair frequency (default=0)
 pack_i   => $pack_i,     ##-- pack-template for IDs (default='N')
 pack_f   => $pack_f,     ##-- pack-template for frequencies (default='N')
 pack_d   => $pack_d,     ##-- pack-tempalte for dates (default='n')
 keeptmp  => $bool,       ##-- keep temporary files? (default=false)
 logCompat => $level,     ##-- log-level for compatibility warnings (default='warn')
 logXS     => $level,     ##-- log-level for XS/PP dispatch (default='trace')
 ##
 ##-- size info (after open() or load())
 size1    => $size1,      ##-- == $r1->size()
 size2    => $size2,      ##-- == $r2->size()
 size3    => $size2,      ##-- == $r3->size()
 ##
 ##-- low-level data
 r1 => $r1,               ##-- pf: [$end2]            @ $i1				: constant (logical index)
 r2 => $r2,               ##-- pf: [$end3,$d1,$f1]*   @ end2($i1-1)..(end2($i1+1)-1)	: sorted by $d1 for each $i1
 r3 => $r3,               ##-- pf: [$i2,$f12]*        @ end3($d1-1)..(end3($d1+1)-1)	: sorted by $i2 for each ($i1,$d1)
 N  => $N,                ##-- sum($f1)
 version => $version,     ##-- file version, for compatibility checks

=item DESTROY

Destructor implicitly calls close().

=back

=cut

##----------------------------------------------------------------
## DESCRIPTION: DiaColloDB::Relation::Cofreqs: I/O: open/close
=pod

=head2 I/O: open/close

=over 4

=item open

 $cof_or_undef = $cof->open($base,$flags);
 $cof_or_undef = $cof->open($base)
 $cof_or_undef = $cof->open()

Opens underlying index files.

=item close

 $cof_or_undef = $cof->close();

Closes underlying index files.
Implicitly calls flush() if index is opened for writing.

=item opened

 $bool = $cof->opened();

Returns true iff index is opened.

=back

=cut

##----------------------------------------------------------------
## DESCRIPTION: DiaColloDB::Relation::Cofreqs: I/O: header
=pod

=head2 I/O: header

See also L<DiaColloDB::Persistent|DiaColloDB::Persistent>.

=over 4

=item headerKeys

 @keys = $cof->headerKeys();

keys to save as header

=item loadHeaderData

 $bool = $cof->loadHeaderData($hdr);

instantiates header data from $hdr;
overrides L<DiaColloDB::Persistent|DiaColloDB::Persistent> implementation.

=back

=cut

##----------------------------------------------------------------
## DESCRIPTION: DiaColloDB::Relation::Cofreqs: I/O: text
=pod

=head2 I/O: text

=over 4

=item loadTextFh

 $cof = $cof->loadTextFh($fh,%opts)

loads from text file as saved by L<saveTextFh|/saveTextFh>();
lines of the form:

 N                       ##-- 1 field : N
 FREQ ID1 DATE           ##-- 3 fields: un-collocated portion of f(ID1,DATE)
 FREQ ID1 DATE ID2       ##-- 4 fields: co-frequency pair (ID2 >= 0)
 FREQ ID1 DATE ID2 DATE2 ##-- 5 fields: redundant date (used by create(); DATE2 is ignored)

=over 4

=item *

supports semi-sorted input: input fh must be sorted numerically by C<($i1,$d1)>,
and all C<$i2> for each C<($i1,$d1)>-pair must be adjacent (i.e. no intervening C<$j1 != $i1>)

=item *

supports multiple lines for collocation-triples C<($i1,$d1,$i2)> provided the above conditions hold

=item *

supports loading of C<$cof-E<gt>{N}> from single-value lines

=item *

uses optimized L<DiaColloDB::XS::CofUtils::loadTextFhXS|DiaColloDB::XS::CofUtils/loadTextFhXS> if available,
otherwise pure-perl fallback C<loadTextFhPP()> in this package.

=item *

C<%opts>: clobber C<%$cof>

=back



=item loadTextFile_create

 $cof = $cof->loadTextFile_create($fh,%opts);

backwards-compatible alias for L<loadTextFh()|/loadTextFh>.


=item saveTextFh

 $bool = $cof->saveTextFh($fh,%opts);

save to text filehandle with lines of the form:

 N                       ##-- 1 field : N
 FREQ ID1 DATE           ##-- 3 fields: un-collocated portion of f(ID1,DATE)
 FREQ ID1 DATE ID2       ##-- 4 fields: co-frequency pair (ID2 >= 0)

%opts:

 i2s  => \&CODE,   ##-- code-ref for formatting indices; called as $s=CODE($i)
 i2s1 => \&CODE,   ##-- code-ref for formatting item1 indices (overrides 'i2s')
 i2s2 => \&CODE,   ##-- code-ref for formatting item2 indices (overrides 'i2s')

=back

=cut

##----------------------------------------------------------------
## DESCRIPTION: DiaColloDB::Relation::Cofreqs: Relation API: creation
=pod

=head2 Relation API: creation

=over 4

=item create

 $cof = $CLASS_OR_OBJECT->create($coldb,$tokdat_file,%opts);

populates co-frequency index from $tokdat_file,
a tt-style text file with lines of the form:

 TID DATE	##-- single token
 "\n"		##-- blank line ~ EOS (hard co-occurrence boundary)

C<%opts>: clobber C<%$cof>.



=item union

 $cof = CLASS_OR_OBJECT->union($coldb, \@pairs, %opts);

merge multiple co-frequency indices into new object.
C<@pairs> is an array of pairs C<([$argcof,\@ti2u],...)>
of co-frequency relations C<$argcof> and tuple-id maps C<\@ti2u> for C<$argcof>.
implicitly flushes the new index.

%opts: clobber %$cof

=back

=cut

##----------------------------------------------------------------
## DESCRIPTION: DiaColloDB::Relation::Cofreqs: Relation API: default: profiling
=pod

=head2 Relation API: default

=over 4

=item subprofile1

 \%slice2prf = $ug->subprofile1(\@tids,\%opts);

Get slice-wise co-frequency profile(s) for tuple-IDs C<@tids>.
C<$cof> must be opened.
%opts: as for L<DiaColloDB::Relation::subprofile1|DiaColloDB::Relation/subprofile1>().

=item subprofile2

 \%slice2prf = $rel->subprofile2(\%slice2prf, %opts);

Populate independent collocate frequencies in C<%slice2prf> values.
C<$cof> must be opened.
%opts: as for L<DiaColloDB::Relation::subprofile2|DiaColloDB::Relation/subprofile2>().


=item subextend

 \%slice2prf = $rel->subextend(\%slice2prf,\%opts);

Populate independent collocate frequencies in C<%slice2prf> values;
wraps L<subprofile2()|/subprofile2>.


=item qinfo

 \%qinfo = $rel->qinfo($coldb, %opts);

get query-info hash for profile administrivia (ddc hit links).

%opts: as for L<DiaColloDB::Relation::profile|DiaColloDB::Relation/profile>(), additionally:

 qreqs => \@qreqs,      ##-- as returned by $coldb->parseRequest($opts{query})
 gbreq => \%groupby,    ##-- as returned by $coldb->groupby($opts{groupby})

=back

=cut


##========================================================================
## END POD DOCUMENTATION, auto-generated by podextract.perl

##======================================================================
## Footer
##======================================================================
=pod

=head1 AUTHOR

Bryan Jurish E<lt>moocow@cpan.orgE<gt>

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2015-2020 by Bryan Jurish

This package is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.14.2 or,
at your option, any later version of Perl 5 you may have available.

=head1 SEE ALSO

L<DiaColloDB::Relation(3pm)|DiaColloDB::Relation>,
L<DiaColloDB::Relation::Unigrams(3pm)|DiaColloDB::Relation::Unigrams>,
L<DiaColloDB::Relation::TDF(3pm)|DiaColloDB::Relation::TDF>,
L<DiaColloDB::Relation::DDC(3pm)|DiaColloDB::Relation::DDC>,
L<DiaColloDB(3pm)|DiaColloDB>,
L<perl(1)|perl>,
...



=cut
