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

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

=head1 NAME

DiaColloDB::Relation::Unigrams - diachronic collocation db, profiling relation: native unigram index

=cut

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

=head1 ALIASES

=over 4

=item DiaColloDB::Relation::Unigrams

=item DiaColloDB::Unigrams

=back

=cut

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

=head1 SYNOPSIS

 ##========================================================================
 ## PRELIMINARIES
 
 use DiaColloDB::Relation::Unigrams;
 
 ##========================================================================
 ## Constructors etc.
 
 $ug = $CLASS_OR_OBJECT->new(%args);
 
 ##========================================================================
 ## API: disk usage
 
 @files = $obj->diskFiles();

 ##========================================================================
 ## I/O: open/close
 
 $ug_or_undef = $ug->open($base,$flags);
 $ug_or_undef = $ug->close();
 $bool = $ug->opened();
 
 ##========================================================================
 ## I/O: header
 
 @keys = $ug->headerKeys();
 $bool = $ug->loadHeaderData($hdr);
 
 ##========================================================================
 ## I/O: text
 
 $ug = $ug->loadTextFh($fh,%opts)
 $ug = $ug->saveTextFh($fh,%opts);
 
 ##========================================================================
 ## Relation API: create
 
 $ug = $CLASS_OR_OBJECT->create($coldb,$tokdat_file,%opts);
 
 ##========================================================================
 ## Relation API: union
 
 $ug = $CLASS_OR_OBJECT->union($coldb, \@pairs, %opts);
 
 ##========================================================================
 ## Relation API: default: profiling
 
 \%slice2prf = $rel->subprofile1(\@tids,\%opts);
 
 ##========================================================================
 ## Relation API: default: query info
 
 \%qinfo = $rel->qinfo($coldb, %opts);

=cut


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

=head1 DESCRIPTION

DiaColloDB::Relation::Unigrams
is a L<DiaColloDB::Relation|DiaColloDB::Relation> subclass for
native indices over attribute-tuple unigrams
using the L<DiaColloDB::PackedFile|DiaColloDB::PackedFile> API
for low-level index data.

=cut

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

=head2 Globals & Constants

=over 4

=item Variable: @ISA

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

=back

=cut

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

=head2 Constructors etc.

=over 4

=item new

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

%args, object structure:

 ##-- user options
 base     => $basename,   ##-- file basename (default=undef:none); use files "${base}.dba1", "${base}.dba2", "${base}.hdr"
 flags    => $flags,      ##-- fcntl flags or open-mode (default='r')
 perms    => $perms,      ##-- creation permissions (default=(0666 &~umask))
 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')
 ##
 ##-- size info (after open() or load())
 size1    => $size1,      ##-- == $r1->size()
 size2    => $size2,      ##-- == $r2->size()
 ##
 ##-- low-level data
 r1 => $r1,               ##-- pf: [$end2]      @ $i1				: constant (logical index)
 r2 => $r2,               ##-- pf: [$d1,$f1]*   @ end2($i1-1)..(end2($i1+1)-1)	: sorted by $d1 for each $i1
 N  => $N,                ##-- sum($f1)
 version => $version,     ##-- file version, for compatibility checks

=item DESTROY

destructor implicitly calls L<close|/close>().

=back

=cut

##----------------------------------------------------------------
## DESCRIPTION: DiaColloDB::Relation::Unigrams: API: disk usage
=pod

=head2 API: disk usage

=over 4

=item diskFiles

 @files = $obj->diskFiles();

returns disk storage files, used by du() and timestamp()

=back

=cut

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

=head3 I/O: open/close

=over 4

=item open

 $ug_or_undef = $ug->open($base,$flags);
 $ug_or_undef = $ug->open($base);
 $ug_or_undef = $ug->open();

Opens underlying index files.

=item close

 $ug_or_undef = $ug->close();

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

=item opened

 $bool = $ug->opened();

Returns true iff index is opened.

=back

=cut

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

=head3 I/O: header

=over 4

=item headerKeys

 @keys = $ug->headerKeys();

keys to save as header

=item loadHeaderData

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

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

=back

=cut

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

=head3 I/O: text

=over 4

=item loadTextFh

 $ug = $ug->loadTextFh($fh,%opts);

=over 4

=item *

loads from text file as saved by L<saveTextFh|/saveTextFh>().

=item *

input fh must be sorted numerically by C<($i1,$d1)>.

=item *

supports multiple lines for pairs C<($i1,$d1)> provided the above condition(s) hold.

=item *

supports loading of C<$ug-E<gt>{N}> from single-component lines.

=item *

%opts: clobber %$ug

=back



=item saveTextFh

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

save as text with lines of the form:

 N                 ##-- 1 field : N
 FREQ ID1 DATE     ##-- 3 fields: unigram frequency for (ID1,DATE)

%opts:

 i2s => \&CODE,    ##-- code-ref for formatting indices; called as $s=CODE($i)

=back

=cut


##----------------------------------------------------------------
## DESCRIPTION: DiaColloDB::Relation::Unigrams: Relation API: create
=pod

=head2 Relation API: create

=over 4

=item create

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

populates unigram database 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)

%opts: clobber %$ug

=back

=cut

##----------------------------------------------------------------
## DESCRIPTION: DiaColloDB::Relation::Unigrams: Relation API: union
=pod

=head2 Relation API: union

=over 4

=item union

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

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

%opts: clobber %$ug

=back

=cut

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

=head2 Relation API: default: profiling

=over 4

=item subprofile1

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

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

=back

=cut

##----------------------------------------------------------------
## DESCRIPTION: DiaColloDB::Relation::Unigrams: Relation API: default: query info
=pod

=head2 Relation API: default: query info

=over 4

=item qinfo

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

get query-info hash for profile administrivia (ddc hit links)
%opts: as for 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-2016 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::Cofreqs(3pm)|DiaColloDB::Relation::Cofreqs>,
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
