Simplified and modularized metadata processing

Change-Id: I63e78fd5994126c954263324bcfc2fd9d51e39ea
diff --git a/t/sgbr/base.t b/t/sgbr/base.t
index 6eb7d62..718a0ba 100644
--- a/t/sgbr/base.t
+++ b/t/sgbr/base.t
@@ -14,7 +14,7 @@
   path => $path . '/'
 ), 'Create Document');
 
-ok($doc->parse, 'Parse document');
+ok($doc->parse('Sgbr'), 'Parse document');
 
 ok(my $tokens = KorAP::XML::Tokenizer->new(
   path => $doc->path,
diff --git a/t/sgbr/meta.t b/t/sgbr/meta.t
index c5f9b60..a1c15c0 100644
--- a/t/sgbr/meta.t
+++ b/t/sgbr/meta.t
@@ -11,7 +11,8 @@
 my $path = catdir(dirname(__FILE__), 'TEST', 'BSP', 1);
 
 ok(my $doc = KorAP::XML::Krill->new(
-  path => $path . '/'
+  path => $path . '/',
+  meta_type => 'Sgbr'
 ), 'Create Document');
 
 ok($doc->parse, 'Parse document');
@@ -23,46 +24,48 @@
 is($doc->doc_sigle, 'TEST_BSP', 'ID-doc');
 is($doc->corpus_sigle, 'TEST', 'ID-corpus');
 
-is($doc->title, 'Sommerüberraschung', 'title');
-is($doc->author, 'TEST.BSP.Autoren.1', 'Author');
-is($doc->store('sgbrAuthorAgeClass'), 'X', 'AgeClass');
+my $meta = $doc->meta;
 
-is($doc->store('sgbrAuthorSex'), 'M', 'Sex');
-is($doc->store('sgbrKodex'), 'M', 'Kodex');
+is($meta->{title}, 'Sommerüberraschung', 'title');
+is($meta->{author}, 'TEST.BSP.Autoren.1', 'Author');
+is($meta->{'sgbr_author_age_class'}, 'X', 'AgeClass');
 
-is($doc->doc_title, 'Beispielkorpus', 'Doc: title');
-is($doc->doc_sub_title, 'Subkorpus Beispieltext', 'Doc: subtitle');
+is($meta->{'sgbr_author_sex'}, 'M', 'Sex');
+is($meta->{'sgbr_kodex'}, 'M', 'Kodex');
 
-is($doc->language, 'de', 'Language');
+is($meta->{doc_title}, 'Beispielkorpus', 'Doc: title');
+is($meta->{doc_sub_title}, 'Subkorpus Beispieltext', 'Doc: subtitle');
 
-ok(!$doc->publisher, 'Publisher');
-ok(!$doc->editor, 'Editor');
-ok(!$doc->text_type, 'Text Type');
-ok(!$doc->text_type_art, 'Text Type Art');
-ok(!$doc->text_type_ref, 'Text Type Ref');
-ok(!$doc->text_column, 'Text Column');
-ok(!$doc->text_domain, 'Text Domain');
-ok(!$doc->creation_date, 'Creation Date');
-ok(!$doc->license, 'License');
-ok(!$doc->pages, 'Pages');
-ok(!$doc->file_edition_statement, 'File Edition Statement');
-ok(!$doc->bibl_edition_statement, 'Bibl Edition Statement');
-ok(!$doc->reference, 'Reference');
+is($meta->{language}, 'de', 'Language');
 
-ok(!$doc->doc_editor, 'Doc: editor');
-ok(!$doc->doc_author, 'Doc: author');
+ok(!$meta->{publisher}, 'Publisher');
+ok(!$meta->{editor}, 'Editor');
+ok(!$meta->{text_type}, 'Text Type');
+ok(!$meta->{text_type_art}, 'Text Type Art');
+ok(!$meta->{text_type_ref}, 'Text Type Ref');
+ok(!$meta->{text_column}, 'Text Column');
+ok(!$meta->{text_domain}, 'Text Domain');
+ok(!$meta->{creation_date}, 'Creation Date');
+ok(!$meta->{license}, 'License');
+ok(!$meta->{pages}, 'Pages');
+ok(!$meta->{file_edition_statement}, 'File Edition Statement');
+ok(!$meta->{bibl_edition_statement}, 'Bibl Edition Statement');
+ok(!$meta->{reference}, 'Reference');
 
-ok(!$doc->corpus_title, 'Corpus: title');
-ok(!$doc->corpus_sub_title, 'Corpus: subtitle');
-ok(!$doc->corpus_editor, 'Corpus: editor');
-ok(!$doc->corpus_author, 'Corpus: author');
+ok(!$meta->{doc_editor}, 'Doc: editor');
+ok(!$meta->{doc_author}, 'Doc: author');
+
+ok(!$meta->{corpus_title}, 'Corpus: title');
+ok(!$meta->{corpus_sub_title}, 'Corpus: subtitle');
+ok(!$meta->{corpus_editor}, 'Corpus: editor');
+ok(!$meta->{corpus_author}, 'Corpus: author');
 
 my $hash = $doc->to_hash;
 is($hash->{title}, 'Sommerüberraschung', 'Corpus title');
-is($hash->{store}->{sgbrAuthorSex}, 'M', 'store');
+is($hash->{sgbrAuthorSex}, 'M', 'additional');
 
 # Sgbr specific keywords
-is($doc->keywords_string, 'sgbrAuthorAgeClass:X sgbrAuthorSex:M sgbrKodex:M');
+is($meta->keywords('keywords'), 'sgbrAuthorAgeClass:X sgbrAuthorSex:M sgbrKodex:M');
 
 
 done_testing;
diff --git a/t/sgbr/meta_duden.t b/t/sgbr/meta_duden.t
index 7cae3c5..c808022 100644
--- a/t/sgbr/meta_duden.t
+++ b/t/sgbr/meta_duden.t
@@ -11,7 +11,8 @@
 my $path = catdir(dirname(__FILE__), 'PRO-DUD', 'BSP-2013-01', 32);
 
 ok(my $doc = KorAP::XML::Krill->new(
-  path => $path . '/'
+  path => $path . '/',
+  meta_type => 'Sgbr'
 ), 'Create Document');
 
 ok($doc->parse, 'Parse document');
@@ -20,57 +21,57 @@
 
 # Metdata
 is($doc->text_sigle, 'PRO-DUD_BSP-2013-01.32', 'ID-text');
-
 is($doc->doc_sigle, 'PRO-DUD_BSP-2013-01', 'ID-doc');
 is($doc->corpus_sigle, 'PRO-DUD', 'ID-corpus');
 
-is($doc->title, 'Nur Platt, kein Deutsch', 'title');
-ok(!$doc->sub_title, 'no subtitle');
+my $meta = $doc->meta;
+is($meta->{title}, 'Nur Platt, kein Deutsch', 'title');
+ok(!$meta->{sub_title}, 'no subtitle');
 
-is($doc->publisher, 'Dorfblatt GmbH', 'Publisher');
-is($doc->pub_date, '20130126');
-is($doc->store('sgbrDate'), '2013-01-26');
-is($doc->pub_place, 'Stadtingen');
+is($meta->{publisher}, 'Dorfblatt GmbH', 'Publisher');
+is($meta->{pub_date}, '20130126');
+is($meta->{sgbr_date}, '2013-01-26');
+is($meta->{pub_place}, 'Stadtingen');
 
-is($doc->doc_title, 'Korpus zur Beobachtung des Schreibgebrauchs im Deutschen', 'Doc title');
-is($doc->doc_sub_title, 'Subkorpus Ortsblatt, Jahrgang 2013, Monat Januar', 'Doc Sub title');
+is($meta->{doc_title}, 'Korpus zur Beobachtung des Schreibgebrauchs im Deutschen', 'Doc title');
+is($meta->{doc_sub_title}, 'Subkorpus Ortsblatt, Jahrgang 2013, Monat Januar', 'Doc Sub title');
 
-is($doc->store('funder'), 'Bundesministerium für Bildung und Forschung', 'Funder');
+is($meta->{'funder'}, 'Bundesministerium für Bildung und Forschung', 'Funder');
 
-is($doc->author, 'unbekannt', 'Author');
-ok(!$doc->store('sgbrAuthorSex'), 'No Sex');
-is($doc->store('sgbrKodex'), 'T', '');
+is($meta->{author}, 'unbekannt', 'Author');
+ok(!$meta->{'sgbr_author_sex'}, 'No Sex');
+is($meta->{'sgbr_kodex'}, 'T', '');
 
-is($doc->keywords_string, 'sgbrKodex:T');
+is($meta->keywords('keywords'), 'sgbrKodex:T');
 
-is($doc->language, 'de', 'Language');
+is($meta->{language}, 'de', 'Language');
 
-ok(!$doc->editor, 'Editor');
+ok(!$meta->{editor}, 'Editor');
 
-ok(!$doc->text_type, 'Text Type');
-ok(!$doc->text_type_art, 'Text Type Art');
-ok(!$doc->text_type_ref, 'Text Type Ref');
-ok(!$doc->text_column, 'Text Column');
-ok(!$doc->text_domain, 'Text Domain');
-ok(!$doc->creation_date, 'Creation Date');
-ok(!$doc->license, 'License');
-ok(!$doc->pages, 'Pages');
-ok(!$doc->file_edition_statement, 'File Edition Statement');
-ok(!$doc->bibl_edition_statement, 'Bibl Edition Statement');
-ok(!$doc->reference, 'Reference');
+ok(!$meta->{text_type}, 'Text Type');
+ok(!$meta->{text_type_art}, 'Text Type Art');
+ok(!$meta->{text_type_ref}, 'Text Type Ref');
+ok(!$meta->{text_column}, 'Text Column');
+ok(!$meta->{text_domain}, 'Text Domain');
+ok(!$meta->{creation_date}, 'Creation Date');
+ok(!$meta->{license}, 'License');
+ok(!$meta->{pages}, 'Pages');
+ok(!$meta->{file_edition_statement}, 'File Edition Statement');
+ok(!$meta->{bibl_edition_statement}, 'Bibl Edition Statement');
+ok(!$meta->{reference}, 'Reference');
 
 
-ok(!$doc->doc_editor, 'Doc: editor');
-ok(!$doc->doc_author, 'Doc: author');
+ok(!$meta->{doc_editor}, 'Doc: editor');
+ok(!$meta->{doc_author}, 'Doc: author');
 
-ok(!$doc->corpus_title, 'Corpus: title');
-ok(!$doc->corpus_sub_title, 'Corpus: subtitle');
-ok(!$doc->corpus_editor, 'Corpus: editor');
-ok(!$doc->corpus_author, 'Corpus: author');
+ok(!$meta->{corpus_title}, 'Corpus: title');
+ok(!$meta->{corpus_sub_title}, 'Corpus: subtitle');
+ok(!$meta->{corpus_editor}, 'Corpus: editor');
+ok(!$meta->{corpus_author}, 'Corpus: author');
 
 my $hash = $doc->to_hash;
 is($hash->{title}, 'Nur Platt, kein Deutsch', 'Corpus title');
-is($hash->{store}->{sgbrKodex}, 'T', 'store');
+is($hash->{sgbrKodex}, 'T', 'store');
 
 
 done_testing;
diff --git a/t/sgbr/meta_ids.t b/t/sgbr/meta_ids.t
index 4128f5d..b040e09 100644
--- a/t/sgbr/meta_ids.t
+++ b/t/sgbr/meta_ids.t
@@ -11,7 +11,8 @@
 my $path = catdir(dirname(__FILE__), 'CMC-TSK', '2014-09', '2843');
 
 ok(my $doc = KorAP::XML::Krill->new(
-  path => $path . '/'
+  path => $path . '/',
+  meta_type => 'Sgbr'
 ), 'Create Document');
 
 ok($doc->parse, 'Parse document');
@@ -24,61 +25,62 @@
 is($doc->doc_sigle, 'CMC-TSK_2014-09', 'ID-doc');
 is($doc->corpus_sigle, 'CMC-TSK', 'ID-corpus');
 
-is($doc->title, '@ Koelle_am_Rhing 10:18', 'title');
+my $meta = $doc->meta;
 
-ok(!$doc->sub_title, 'no subtitle');
+is($meta->{title}, '@ Koelle_am_Rhing 10:18', 'title');
 
-is($doc->publisher, 'tagesschau.de', 'Publisher');
+ok(!$meta->{sub_title}, 'no subtitle');
 
-is($doc->pub_date, '20140930');
+is($meta->{publisher}, 'tagesschau.de', 'Publisher');
 
-ok(!$doc->pub_place, 'No pub place');
+is($meta->{pub_date}, '20140930');
 
-is($doc->doc_title, 'Korpus zur Beobachtung des Schreibgebrauchs im Deutschen', 'Doc title');
-is($doc->doc_sub_title, 'Subkorpus Internettexte, Subkorpus Leserkommentare Tagesschau, Subkorpus September 2014, Subkorpus Beispielauszug', 'Doc Sub title');
+ok(!$meta->{pub_place}, 'No pub place');
 
-is($doc->store('funder'), 'Bundesministerium für Bildung und Forschung', 'Funder');
+is($meta->{doc_title}, 'Korpus zur Beobachtung des Schreibgebrauchs im Deutschen', 'Doc title');
+is($meta->{doc_sub_title}, 'Subkorpus Internettexte, Subkorpus Leserkommentare Tagesschau, Subkorpus September 2014, Subkorpus Beispielauszug', 'Doc Sub title');
 
-is($doc->author, 'privat23', 'Author');
-ok(!$doc->store('sgbrAuthorSex'), 'No Sex');
-ok(!$doc->store('sgbrKodex'), 'No kodex');
-is($doc->reference, 'http://meta.tagesschau.de/node/090285#comment-1732187', 'Publace ref');
+is($meta->{'funder'}, 'Bundesministerium für Bildung und Forschung', 'Funder');
 
-is($doc->keywords_string, '');
+is($meta->{author}, 'privat23', 'Author');
+ok(!$meta->{'sgbr_author_sex'}, 'No Sex');
+ok(!$meta->{'sgbr_kodex'}, 'No kodex');
+is($meta->{reference}, 'http://meta.tagesschau.de/node/090285#comment-1732187', 'Publace ref');
 
-is($doc->language, 'de', 'Language');
+is($meta->keywords('keywords'), '');
 
-ok(!$doc->editor, 'Editor');
+is($meta->{language}, 'de', 'Language');
 
-ok(!$doc->text_type, 'Text Type');
-ok(!$doc->text_type_art, 'Text Type Art');
-ok(!$doc->text_type_ref, 'Text Type Ref');
-ok(!$doc->text_column, 'Text Column');
-ok(!$doc->text_domain, 'Text Domain');
-ok(!$doc->creation_date, 'Creation Date');
-ok(!$doc->license, 'License');
-ok(!$doc->pages, 'Pages');
-ok(!$doc->file_edition_statement, 'File Edition Statement');
-ok(!$doc->bibl_edition_statement, 'Bibl Edition Statement');
+ok(!$meta->{editor}, 'Editor');
 
-ok(!$doc->doc_editor, 'Doc: editor');
-ok(!$doc->doc_author, 'Doc: author');
+ok(!$meta->{text_type}, 'Text Type');
+ok(!$meta->{text_type_art}, 'Text Type Art');
+ok(!$meta->{text_type_ref}, 'Text Type Ref');
+ok(!$meta->{text_column}, 'Text Column');
+ok(!$meta->{text_domain}, 'Text Domain');
+ok(!$meta->{creation_date}, 'Creation Date');
+ok(!$meta->{license}, 'License');
+ok(!$meta->{pages}, 'Pages');
+ok(!$meta->{file_edition_statement}, 'File Edition Statement');
+ok(!$meta->{bibl_edition_statement}, 'Bibl Edition Statement');
 
-ok(!$doc->corpus_title, 'Corpus: title');
-ok(!$doc->corpus_sub_title, 'Corpus: subtitle');
-ok(!$doc->corpus_editor, 'Corpus: editor');
-ok(!$doc->corpus_author, 'Corpus: author');
+ok(!$meta->{doc_editor}, 'Doc: editor');
+ok(!$meta->{doc_author}, 'Doc: author');
+
+ok(!$meta->{corpus_title}, 'Corpus: title');
+ok(!$meta->{corpus_sub_title}, 'Corpus: subtitle');
+ok(!$meta->{corpus_editor}, 'Corpus: editor');
+ok(!$meta->{corpus_author}, 'Corpus: author');
 
 my $hash = $doc->to_hash;
 is($hash->{title}, '@ Koelle_am_Rhing 10:18', 'Corpus title');
 
-
 # Second document
-
 $path = catdir(dirname(__FILE__), 'CMC-TSK', '2014-09', '3401');
 
 ok($doc = KorAP::XML::Krill->new(
-  path => $path . '/'
+  path => $path . '/',
+  meta_type => 'Sgbr'
 ), 'Create Document');
 
 ok($doc->parse, 'Parse document');
@@ -91,51 +93,53 @@
 is($doc->doc_sigle, 'CMC-TSK_2014-09', 'ID-doc');
 is($doc->corpus_sigle, 'CMC-TSK', 'ID-corpus');
 
-is($doc->title, '@fitnessfrosch', 'title');
 
-ok(!$doc->sub_title, 'no subtitle');
+$meta = $doc->meta;
+is($meta->{title}, '@fitnessfrosch', 'title');
 
-is($doc->publisher, 'tagesschau.de', 'Publisher');
+ok(!$meta->{sub_title}, 'no subtitle');
 
-is($doc->pub_date, '20141001');
-is($doc->store('sgbrDate'), '2014-10-01 00:50:00');
+is($meta->{publisher}, 'tagesschau.de', 'Publisher');
 
-ok(!$doc->pub_place, 'No pub place');
+is($meta->{pub_date}, '20141001');
+is($meta->{'sgbr_date'}, '2014-10-01 00:50:00');
 
-is($doc->doc_title, 'Korpus zur Beobachtung des Schreibgebrauchs im Deutschen', 'Doc title');
-is($doc->doc_sub_title, 'Subkorpus Internettexte, Subkorpus Leserkommentare Tagesschau, Subkorpus September 2014, Subkorpus Beispielauszug', 'Doc Sub title');
+ok(!$meta->{pub_place}, 'No pub place');
 
-is($doc->store('funder'), 'Bundesministerium für Bildung und Forschung', 'Funder');
+is($meta->{doc_title}, 'Korpus zur Beobachtung des Schreibgebrauchs im Deutschen', 'Doc title');
+is($meta->{doc_sub_title}, 'Subkorpus Internettexte, Subkorpus Leserkommentare Tagesschau, Subkorpus September 2014, Subkorpus Beispielauszug', 'Doc Sub title');
 
-is($doc->author, 'weltoffen', 'Author');
-ok(!$doc->store('sgbrAuthorSex'), 'No Sex');
-ok(!$doc->store('sgbrKodex'), 'No kodex');
-is($doc->reference, 'http://meta.tagesschau.de/node/090308#comment-1732754', 'Publace ref');
+is($meta->{'funder'}, 'Bundesministerium für Bildung und Forschung', 'Funder');
 
-is($doc->keywords_string, '');
+is($meta->{author}, 'weltoffen', 'Author');
+ok(!$meta->{'sgbr_author_sex'}, 'No Sex');
+ok(!$meta->{'sgbr_kodex'}, 'No kodex');
+is($meta->{reference}, 'http://meta.tagesschau.de/node/090308#comment-1732754', 'Publace ref');
 
-is($doc->language, 'de', 'Language');
+is($meta->keywords('keywords'), '');
 
-ok(!$doc->editor, 'Editor');
+is($meta->{language}, 'de', 'Language');
 
-ok(!$doc->text_type, 'Text Type');
-ok(!$doc->text_type_art, 'Text Type Art');
-ok(!$doc->text_type_ref, 'Text Type Ref');
-ok(!$doc->text_column, 'Text Column');
-ok(!$doc->text_domain, 'Text Domain');
-ok(!$doc->creation_date, 'Creation Date');
-ok(!$doc->license, 'License');
-ok(!$doc->pages, 'Pages');
-ok(!$doc->file_edition_statement, 'File Edition Statement');
-ok(!$doc->bibl_edition_statement, 'Bibl Edition Statement');
+ok(!$meta->{editor}, 'Editor');
 
-ok(!$doc->doc_editor, 'Doc: editor');
-ok(!$doc->doc_author, 'Doc: author');
+ok(!$meta->{text_type}, 'Text Type');
+ok(!$meta->{text_type_art}, 'Text Type Art');
+ok(!$meta->{text_type_ref}, 'Text Type Ref');
+ok(!$meta->{text_column}, 'Text Column');
+ok(!$meta->{text_domain}, 'Text Domain');
+ok(!$meta->{creation_date}, 'Creation Date');
+ok(!$meta->{license}, 'License');
+ok(!$meta->{pages}, 'Pages');
+ok(!$meta->{file_edition_statement}, 'File Edition Statement');
+ok(!$meta->{bibl_edition_statement}, 'Bibl Edition Statement');
 
-ok(!$doc->corpus_title, 'Corpus: title');
-ok(!$doc->corpus_sub_title, 'Corpus: subtitle');
-ok(!$doc->corpus_editor, 'Corpus: editor');
-ok(!$doc->corpus_author, 'Corpus: author');
+ok(!$meta->{doc_editor}, 'Doc: editor');
+ok(!$meta->{doc_author}, 'Doc: author');
+
+ok(!$meta->{corpus_title}, 'Corpus: title');
+ok(!$meta->{corpus_sub_title}, 'Corpus: subtitle');
+ok(!$meta->{corpus_editor}, 'Corpus: editor');
+ok(!$meta->{corpus_author}, 'Corpus: author');
 
 $hash = $doc->to_hash;
 is($hash->{title}, '@fitnessfrosch', 'Corpus title');