package BNC::Meta;

use strict;
use warnings;

use base qw(Exporter);
our @EXPORT = qw(%TextCat %SpkrCat find_code find_code_or_die catRef_code text_cat_table speaker_cat_table process_catrefs);

=head1 NAME

BNC::Meta - BNC metadata: categories for text and speaker classification


=head1 SYNOPSIS

  use BNC::Meta;  # exports all functions and hashes by default

  $long_name = $TextCat{"ALLTYP"}{DESC};  # taxonomy of text types
  $short_name = $TextCat{"ALLTYP"}{NAME}; # short name (more readable than BNC code)
  $cat_list = $TextCat{"ALLTYP"}{CATS}    # list of cateogries for this taxonomy
  foreach $cat (@$cat_list) {
	$long_name = $cat->{DESC};    # description of category 
	$short_name = $cat->{NAME};   # short "speaking" name, e.g. spoken_context
	$numeric_code = $cat->{NUM};  # numeric code for category, e.g. 2
	$bnc_code = $cat->{CODE};     # code used in BNC, e.g. ALLTYP2
	$taxonomy = $cat->{TAX};      # taxonomy this code belongs to, here always ALLTYP
  }
  $cat = find_code_or_die($taxonomy, $bnc_code); # look up category by BNC code

  $SpkrCat{"ageGroup"}{...};      # same for speaker classification
  $cat = find_code_or_die($attribute, $bnc_code); # look up speaker attribute category by BNC code
  
  $cat = catRef_code($code);      # find category object for given BNC catRef code
  $taxonomy = $cat->{TAX};
  $numeric = $cat->{NUM};
  $cat = $TextCat{$taxonomy}{CATS}[$numeric];
  
  $value_hash = text_cat_table();    # hash mapping taxonomy names to values (texts/speaker)
  $value_hash = speaker_cat_table(); # all values are initialised to "N/A" codes

  process_catrefs($value_hash, @values); # process catRef data and add to $value_hash

=head1 DESCRIPTION

B<TODO>: Short description of what the module does

=head2 Data Structures

Description of the C<%TextCat> and C<%SpkrCat> data structures, in particular the hash "objects" holding category information.

=cut

our %TextCat = ();    # see synopsis above for data structures
our %SpkrCat = ();
our %catRef =
  map { $_ => 1 }
  qw(ALLTIM ALLTYP SCGDOM SDEAGE SDECLA SDESEX SPOLOG SPOREG WRIAAG WRIAD WRIASE WRIATY WRIAUD WRIDOM WRILEV WRIMED WRIPP WRISAM WRISTA WRITAS allava textMode)
  ;                   # taxonomies encoded in catRef
our %CatByCode = ();  # $CatByCode{$bnc_code} = $cat_data (reference to category object)

## temporary: load category information from external file
use CWB;

sub read_cat_from_data {
    my $Cat                = shift;
    my $last_tax           = undef;
    my $last_tax_in_catref = 0;
    while (<DATA>) {
        last if /^==========/; # separator line (between text and speaker categories)
        chomp;
        my ($tax, @F) = split /\t/;
        if ($tax ne "") {    # unindented line starts new taxonomy
            die "BNC::Meta: internal error - duplicate taxonomy '$tax'.\n"
              if exists $Cat->{$tax};
            die "BNC::Meta: format error in __DATA__ section:\n\t>>$_<<\n" unless @F == 2;
            $Cat->{$tax} = {CODE => $tax, NAME => $F[0], DESC => $F[1], CATS => [], CODEHASH => {}};
            $last_tax           = $Cat->{$tax};
            $last_tax_in_catref = defined $catRef{$tax};
        }
        else {
            die "BNC::Meta: format error in __DATA__ section:\n\t>>$_<<\n" unless @F == 4;
            my ($code, $num, $name, $desc) = @F;
            die "BNC::Meta: internal error - duplicate numeric code $num for category '$code'.\n"
              if defined $last_tax->{CATS}[$num];
            my $cat_info = {CODE => $code, NUM => $num, NAME => $name, DESC => $desc, TAX => $last_tax->{CODE}};
            $last_tax->{CATS}[$num] = $cat_info;
            die "BNC::Meta: internal error - duplicate category code '$code' in taxonomy '" . $last_tax->{NAME} . "'\n"
              if exists $last_tax->{CODEHASH}{$code};
            $last_tax->{CODEHASH}{$code} = $cat_info;
            if ($last_tax_in_catref) {
                die "BNC::Meta: internal error - duplicate category code '$code'.\n"
                  if exists $CatByCode{$code};
                $CatByCode{$code} = $cat_info;
            }
            if ($code =~ /^UNDEF_/) {
                die "BNC::Meta: internal error - N/A code '$code' doesn't match taxonomy name.\n"
                  unless $' eq $last_tax->{CODE};
                $last_tax->{UNDEF} = $cat_info;
            }
        }
    }
    my @no_undef = sort grep { not defined $Cat->{$_}{UNDEF} } keys %$Cat;
    die "BNC::Meta: internal error - no N/A category for taxonomies: @no_undef\n" if @no_undef;
}

read_cat_from_data(\%TextCat);
die "BNC::Meta: internal error - can't find speaker metadata in __DATA__ section\n" if eof(DATA);
read_cat_from_data(\%SpkrCat);
die "BNC::Meta: internal error - reading metadata from __DATA__ section failed (incomplete)\n" unless eof(DATA);
close(DATA);

=head2 Functions

=over 4

=item $cat = find_code($taxonomy, $code);

=item $cat = find_code_or_die($taxonomy, $code);

Look up category code in specified text taxonomy / speaker attribute.  Returns reference to category description hash, or B<undef> if code cannot be found.
The B<find_code_or_die> method B<die>s if I<$code> cannot be found, so return values do not have to be tested.

=cut

sub find_code ( $$ ) {
    my ($tax_name, $code) = @_;
    my $tax = $TextCat{$tax_name} || $SpkrCat{$tax_name};
    die "find_code(): '$tax_name' is neither a text taxonomy nor a speaker attribute.\n" unless defined $tax;
    return $tax->{CODEHASH}{$code};
}

sub find_code_or_die ( $$ ) {
  my ($tax_name, $code) = @_;
  my $desc = find_code($tax_name, $code);
  die "find_code('$tax_name', '$code'): specified code not found in category.\n"
    unless defined $desc;
  return $desc;
}

=item $cat = catRef_code($code);

Look up category code used to specify text classification in C<catRef> element.  Returns reference to category description (see L<"Data Structures"> above for details on the hash structure), or B<undef> if code cannot be found.

=cut

sub catRef_code ( $ ) {
    my $code = shift;
    return $CatByCode{$code};
}

=item $value_hash = text_cat_table();

Returns hash with names of text taxonomies as keys and category descriptions (see L<"Data Structures"> above) as values, which can be used to fill in category information extracted from the C<catRef> string (most easily using the function B<process_catrefs> described below).  All values are initialised to the "undefined" category C<N/A>.

=cut

sub text_cat_table ( ) {
    return {map { $_ => $TextCat{$_}{UNDEF} } keys %TextCat};
}

=item $value_hash = speaker_cat_table();

Returns has with names of speaker attributes as keys and attribute descriptions (see L<"Data Structures"> above) as values, which can be used to fill in metadata from a speaker description.  All values are initialised as C<N/A> ("undefined").

=cut

sub speaker_cat_table ( ) {
    return {map { $_ => $SpkrCat{$_}{UNDEF} } keys %SpkrCat};
}

=item process_catrefs($value_hash, @catRef_codes);

=item process_catrefs($value_hash, $catRef_string);

Parse C<catRef> string (I<$catRef_string>) or list of codes (I<@catRef_codes>) and add recognised values to I<$value_hash>.  The function B<die>s if an unknown category code is encountered.

=cut

sub process_catrefs ( $@ ) {
    my $vtable = shift;
    my @codes = split " ", "@_";
    foreach my $code (@codes) {
        my $cat = catRef_code($code);
        die "BNC::Meta: Unknown catRef code '$code' -- program aborted\n" unless defined $cat;
        $vtable->{$cat->{TAX}} = $cat;
    }
}

=back

=head1 DETAILS

B<TODO>: Describe how information about the text taxonomies / speaker attributes and available categories was extracted from the C<bncHdr.xml> and manually corrected / extended.


=head1 AUTHOR

Stefan Evert E<lt>stefan.evert@uos.deE<gt>

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2007-2008 by Stefan Evert

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

=cut

1;

__DATA__
ALLTIM	publication_date	Publication date
	ALLTIM0	0	unknown	Unknown
	ALLTIM1	1	1960-1974	1960-1974
	ALLTIM2	2	1975-1984	1975-1984
	ALLTIM3	3	1985-1993	1985-1993
	UNDEF_ALLTIM	4	---	N/A
ALLTYP	text_type	Text type
	ALLTYP1	1	spoken_demographic	Spoken demographic
	ALLTYP2	2	spoken_context	Spoken context-governed
	ALLTYP3	3	written_books_periodicals	Written books and periodicals
	ALLTYP4	4	written-to-be-spoken	Written-to-be-spoken
	ALLTYP5	5	written_misc	Written miscellaneous
	UNDEF_ALLTYP	6	---	N/A
SCGDOM	context	Spoken context
	SCGDOM1	1	educational	Educational/Informative
	SCGDOM2	2	business	Business
	SCGDOM3	3	public	Public/Institutional
	SCGDOM4	4	leisure	Leisure
	UNDEF_SCGDOM	5	---	N/A
SDEAGE	respondent_age	Age-group of respondent
	SDEAGE1	1	0-14	Respondent Age 0-14
	SDEAGE2	2	15-24	Respondent Age 15-24
	SDEAGE3	3	25-34	Respondent Age 25-34
	SDEAGE4	4	35-44	Respondent Age 35-44
	SDEAGE5	5	45-59	Respondent Age 45-59
	SDEAGE6	6	60+	Respondent Age 60+
	UNDEF_SDEAGE	7	---	N/A
SDECLA	respondent_class	Social class of respondent (NRS social grades)
	SDECLA0	0	unknown	Unknown class
	SDECLA1	1	AB	AB respondent (middle class or higher)
	SDECLA2	2	C1	C1 respondent (lower middle class)
	SDECLA3	3	C2	C2 respondent (skilled working class)
	SDECLA4	4	DE	DE respondent (working class and lower)
	UNDEF_SDECLA	5	---	N/A
SDESEX	respondent_sex	Sex of respondent
	SDESEX0	0	unknown	Respondent sex unknown
	SDESEX1	1	male	Male respondent
	SDESEX2	2	female	Female respondent
	UNDEF_SDESEX	3	---	N/A
SPOLOG	interaction_type	Interaction type
	SPOLOG1	1	monologue	Monologue
	SPOLOG2	2	dialogue	Dialogue
	UNDEF_SPOLOG	3	---	N/A
SPOREG	region	Region
	SPOREG0	0	unknown	Unknown
	SPOREG1	1	south	South
	SPOREG2	2	midlands	Midlands
	SPOREG3	3	north	North
	UNDEF_SPOREG	4	---	N/A
WRIAAG	author_age	Author age-group
	WRIAAG0	0	unknown	Author age unknown
	WRIAAG1	1	0-14	Author age 0-14
	WRIAAG2	2	15-24	Author age 15-24
	WRIAAG3	3	25-34	Author age 25-34
	WRIAAG4	4	35-44	Author age 35-44
	WRIAAG5	5	45-59	Author age 45-59
	WRIAAG6	6	60+	Author age 60+
	UNDEF_WRIAAG	7	---	N/A
WRIAD	author_domicile	Domicile of author
	WRIAD0	0	unknown	Author domicile Unknown
	WRIAD1	1	UK	Author domicile UK and Ireland
	WRIAD2	2	Commonwealth	Author domicile Commonwealth
	WRIAD3	3	Europe	Author domicile Continental Europe
	WRIAD4	4	USA	Author domicile USA
	WRIAD5	5	other	Author domicile Elsewhere
	UNDEF_WRIAD	6	---	N/A
WRIASE	author_sex	Sex of author
	WRIASE0	0	unknown	Author sex Unknown
	WRIASE1	1	male	Author sex Male
	WRIASE2	2	female	Author sex Female
	WRIASE3	3	mixed	Author sex Mixed
	UNDEF_WRIASE	4	---	N/A
WRIATY	author_type	Author type
	WRIATY0	0	unknown	Unknown author
	WRIATY1	1	corporate	Corporate author
	WRIATY2	2	multiple	Multiple authors
	WRIATY3	3	sole	Sole author
	UNDEF_WRIATY	4	---	N/A
WRIAUD	audience_age	Audience age
	WRIAUD1	1	child	Child audience
	WRIAUD2	2	teen	Teenager audience
	WRIAUD3	3	adult	Adult audience
	WRIAUD4	4	any	Any audience
	UNDEF_WRIAUD	5	---	N/A
WRIDOM	domain	Written domain
	WRIDOM1	1	imaginative	Imaginative
	WRIDOM2	2	natural_science	Informative: natural & pure science
	WRIDOM3	3	applied_science	Informative: applied science
	WRIDOM4	4	social_science	Informative: social science
	WRIDOM5	5	world_affairs	Informative: world affairs
	WRIDOM6	6	commerce_finance	Informative: commerce & finance
	WRIDOM7	7	arts	Informative: arts
	WRIDOM8	8	belief_thought	Informative: belief & thought
	WRIDOM9	9	leisure	Informative: leisure
	UNDEF_WRIDOM	10	---	N/A
WRILEV	difficulty	Written difficulty
	WRILEV1	1	low	Low difficulty
	WRILEV2	2	medium	Medium difficulty
	WRILEV3	3	high	High difficulty
	UNDEF_WRILEV	4	---	N/A
WRIMED	medium	Written medium
	WRIMED1	1	book	Book
	WRIMED2	2	periodical	Periodical
	WRIMED3	3	misc_published	Miscellaneous published
	WRIMED4	4	misc_unpublished	Miscellaneous unpublished
	WRIMED5	5	to-be-spoken	To-be-spoken
	UNDEF_WRIMED	6	---	N/A
WRIPP	publication_place	Publication place
	WRIPP0	0	unknown	Unknown publication place
	WRIPP1	1	UK	UK (unspecific) publication
	WRIPP2	2	Ireland	Ireland publication
	WRIPP3	3	UK_north	UK: North (north of Mersey-Humber line) publication
	WRIPP4	4	UK_midlands	UK: Midlands (north of Bristol Channel-Wash line) publication
	WRIPP5	5	UK_south	UK: South (south of Bristol Channel-Wash line) publication
	WRIPP6	6	USA	United States publication
	UNDEF_WRIPP	7	---	N/A
WRISAM	sampling_type	Sampling type
	WRISAM0	0	unknown	Unknown sampling
	WRISAM1	1	whole	Whole text
	WRISAM2	2	beginning	Beginning sample
	WRISAM3	3	middle	Middle sample
	WRISAM4	4	end	End sample
	WRISAM5	5	composite	Composite sample
	UNDEF_WRISAM	6	---	N/A
WRISTA	circulation	Estimated circulation size
	WRISTA0	0	unknown	Unknown circulation
	WRISTA1	1	low	Low circulation
	WRISTA2	2	medium	Medium circulation
	WRISTA3	3	high	High circulation
	UNDEF_WRISTA	4	---	N/A
WRITAS	audience_sex	Audience sex
	WRITAS0	0	unknown	Unknown audience
	WRITAS1	1	male	Male audience
	WRITAS2	2	female	Female audience
	WRITAS3	3	mixed	Mixed audience
	UNDEF_WRITAS	4	---	N/A
allava	availability	Availability
	ALLAVA0	0	unclaimed	Ownership unclaimed
	ALLAVA2	2	cleared	Worldwide rights cleared
	UNDEF_allava	3	---	N/A
derivedTextType	derived_type	Text class
	ACPROSE	0	academic	Academic prose
	FICTION	1	fiction	Fiction and verse
	NONAC	2	prose	Non-academic prose and biography
	NEWS	3	newspaper	Newspapers
	OTHERPUB	4	misc_published	Other published written material
	UNPUB	5	unpublished	Unpublished written material
	CONVRSN	6	spoken_conversation	Spoken conversation
	OTHERSP	7	spoken_other	Other spoken material
	UNDEF_derivedTextType	8	---	N/A
textMode	mode	Text mode
	WRI	1	written	Written
	SPO	2	spoken	Transcribed speech
	UNDEF_textMode	3	---	N/A
DLee	genre	David Lee's genre classification
	S brdcast discussn	1	S:brdcast:discussn	Spoken: TV or radio discussions
	S brdcast documentary	2	S:brdcast:documentary	Spoken: TV documentaries
	S brdcast news	3	S:brdcast:news	Spoken: TV or radio news broadcasts
	S classroom	4	S:classroom	Spoken: non-tertiary classroom discourse
	S consult	5	S:consult	Spoken: (mainly) medical and legal consultations
	S conv	6	S:conv	Spoken: face-to-face spontaneous conversations
	S courtroom	7	S:courtroom	Spoken: legal presentations or debates
	S demonstratn	8	S:demonstratn	Spoken: 'live' demonstrations
	S interview	9	S:interview	Spoken: job interviews and other types
	S interview oral history	10	S:interview:oral_history	Spoken: oral history interviews/narratives, some broadcast
	S lect commerce	11	S:lect:commerce	Spoken: lectures on economics, commerce and finance
	S lect humanities arts	12	S:lect:humanities_arts	Spoken: lectures on humanities and arts subjects
	S lect nat science	13	S:lect:nat_science	Spoken: lectures on the natural sciences
	S lect polit law edu	14	S:lect:polit_law_edu	Spoken: lectures on politics, law or education
	S lect soc science	15	S:lect:soc_science	Spoken: lectures on the social and behavioural sciences
	S meeting	16	S:meeting	Spoken: business or committee meetings
	S parliament	17	S:parliament	Spoken: BNC-transcribed parliamentary speeches
	S pub debate	18	S:pub_debate	Spoken: public debates, discussions, meetings
	S sermon	19	S:sermon	Spoken: religious sermons
	S speech scripted	20	S:speech:scripted	Spoken: planned speech (dialogue or monologue)
	S speech unscripted	21	S:speech:unscripted	Spoken: unprepared speech (dialogue or monologue)
	S sportslive	22	S:sportslive	Spoken: 'live' sports commentaries and discussions
	S tutorial	23	S:tutorial	Spoken: university-level tutorials
	S unclassified	24	S:unclassified	Spoken: miscellaneous spoken genres
	W ac:humanities arts	25	W:ac:humanities_arts	Written: academic prose: humanities
	W ac:medicine	26	W:ac:medicine	Written: academic prose: medicine
	W ac:nat science	27	W:ac:nat_science	Written: academic prose: natural sciences
	W ac:polit law edu	28	W:ac:polit_law_edu	Written: academic prose: politics, law, education
	W ac:soc science	29	W:ac:soc_science	Written: academic prose: social and behavioural sciences
	W ac:tech engin	30	W:ac:tech_engin	Written: academic prose: technology, computing, engineering
	W admin	31	W:admin	Written: administrative and regulatory texts (in-house use)
	W advert	32	W:advert	Written: print advertisements
	W biography	33	W:biography	Written: biographies and autobiographies
	W commerce	34	W:commerce	Written: commerce and finance, economics
	W email	35	W:email	Written: e-mail sports discussion list
	W essay school	36	W:essay:school	Written: school essays
	W essay univ	37	W:essay:univ	Written: university essays
	W fict drama	38	W:fict:drama	Written: excerpts from two modern drama scripts
	W fict poetry	39	W:fict:poetry	Written: collections of poems (single and multiple authors)
	W fict prose	40	W:fict:prose	Written: novels and short stories
	W hansard	41	W:hansard	Written: Hansard/parliamentary proceedings
	W institut doc	42	W:institut_doc	Written: official documents, annual reports, etc.
	W instructional	43	W:instructional	Written: instructional texts and DIY
	W letters personal	44	W:letters:personal	Written: personal letters, postcards, notes
	W letters prof	45	W:letters:prof	Written: professional and business letters
	W misc	46	W:misc	Written: miscellaneous texts
	W news script	47	W:news_script	Written: TV autocue data
	W newsp brdsht nat: arts	48	W:newsp:brdsht_nat:arts	Written: broadsheet national newspapers: arts and cultural material
	W newsp brdsht nat: commerce	49	W:newsp:brdsht_nat:commerce	Written: broadsheet national newspapers: commerce and finance
	W newsp brdsht nat: editorial	50	W:newsp:brdsht_nat:editorial	Written: broadsheet national newspapers: editorials and letters to the editor
	W newsp brdsht nat: misc	51	W:newsp:brdsht_nat:misc	Written: broadsheet national newspapers: miscellaneous material
	W newsp brdsht nat: report	52	W:newsp:brdsht_nat:report	Written: broadsheet national newspapers: home and foreign news reportage
	W newsp brdsht nat: science	53	W:newsp:brdsht_nat:science	Written: broadsheet national newspapers: science material
	W newsp brdsht nat: social	54	W:newsp:brdsht_nat:social	Written: broadsheet national newspapers: lifestyle, leisure, belief and thought
	W newsp brdsht nat: sports	55	W:newsp:brdsht_nat:sports	Written: broadsheet national newspapers: sports material
	W newsp other: arts	56	W:newsp:other:arts	Written: regional and local newspapers: arts
	W newsp other: commerce	57	W:newsp:other:commerce	Written: regional and local newspapers: commerce and finance
	W newsp other: report	58	W:newsp:other:report	Written: regional and local newspapers: home and foreign news reportage
	W newsp other: science	59	W:newsp:other:science	Written: science material
	W newsp other: social	60	W:newsp:other:social	Written: regional and local newspapers: lifestyle, leisure, belief and thought
	W newsp other: sports	61	W:newsp:other:sports	Written: sports material
	W newsp tabloid	62	W:newsp:tabloid	Written: tabloid newspapers
	W nonAc: humanities arts	63	W:non_ac:humanities_arts	Written: non-academic: humanities
	W nonAc: medicine	64	W:non_ac:medicine	Written: non-academic: medical and health matters
	W nonAc: nat science	65	W:non_ac:nat_science	Written: non-academic: natural sciences
	W nonAc: polit law edu	66	W:non_ac:polit_law_edu	Written: non-academic: politics, law, education
	W nonAc: soc science	67	W:non_ac:soc_science	Written: non-academic: social and behavioural sciences
	W nonAc: tech engin	68	W:non_ac:tech_engin	Written: non-academic: technology, computing, engineering
	W pop lore	69	W:pop_lore	Written: non-academic: popular magazines
	W religion	70	W:religion	Written: non-academic: religious texts, excluding philosophy
	UNDEF_DLee	71	---	N/A
======================================================================
ageGroup	age_group	Age-group of speaker
	X	0	unknown	Unknown
	Ag0	1	0-14	Speaker age 0-14
	Ag1	2	15-24	Speaker age 15-24
	Ag2	3	25-34	Speaker age 25-34
	Ag3	4	35-44	Speaker age 35-44
	Ag4	5	45-59	Speaker age 45-59
	Ag5	6	60+	Speaker age 60+
	UNDEF_ageGroup	7	---	N/A
dialect	dialect	Dialect of speaker
	NONE	0	none	No accent recorded
	CAN	1	Canadian	Canadian
	XDE	2	German	German
	XEA	3	East_Anglian	East Anglian
	XFR	4	French	French
	XHC	5	Home_Counties	Home Counties
	XHM	6	Humberside	Humberside
	XIR	7	Irish	Irish
	XIS	8	Indian	Indian subcontinent
	XLC	9	Lancashire	Lancashire
	XLO	10	London	London
	XMC	11	central_Midlands	Central Midlands
	XMD	12	Merseyside	Merseyside
	XME	13	NE_Midlands	North-east Midlands
	XMI	14	Midlands	Midlands
	XMS	15	S_Midlands	South Midlands
	XMW	16	NW_Midlands	North-west Midlands
	XNC	17	central_Northern_England	Central Northern England
	XNE	18	NE_England	North-east England
	XNO	19	Northern_England	Northern England
	XOT	20	Other	Other or unidentifiable
	XSD	21	Scottish	Scottish
	XSL	22	lower_SW_England	Lower south-west England
	XSS	23	central_SW_England	Central south-west England
	XSU	24	upper_SW_England	Upper south-west England
	XUR	25	European	European
	XUS	26	American	American (US)
	XWA	27	Welsh	Welsh
	XWE	28	West Indian	West Indian
	UNDEF_dialect	29	---	N/A
firstLang	first_language	First language of speaker
	XX-XXX	0	unknown	Unknown
	DE-DEU	1	German	German
	FR-FRA	2	French	French
	EN-GBR	3	British	British English
	EN-USA	4	American	North American English
	XX-IND	5	Indian	Unknown Indian language
	UNDEF_firstLang	6	---	N/A
educ	education	Age at which speaker ceased full-time education
	X	0	unknown	Unknown
	Ed0	1	in_school	Still in education
	Ed1	2	14-	Left school aged 14 or under
	Ed2	3	15-16	Left school aged 15 or 16
	Ed3	4	17-18	Left school aged 17 or 18
	Ed4	5	19+	Education continued until age 19 or over
	UNDEF_educ	6	---	N/A
soc	class	Social class of the speaker
	UU	0	unknown	Unknown
	AB	1	AB	AB (middle class or higher)
	C1	2	C1	C1 (lower middle class)
	C2	3	C2	C2 (skilled working class)
	DE	4	DE	DE (working class and lower)
	UNDEF_soc	5	---	N/A
sex	sex	Sex of speaker
	u	0	unknown	Speaker sex unknown
	m	1	male	Male speaker
	f	2	female	Female speaker
	UNDEF_sex	3	---	N/A
