| Akron | 7dacd01 | 2020-05-27 12:18:57 +0200 | [diff] [blame^] | 1 | package KorAP::VirtualCorpus::DocVec; |
| 2 | use strict; |
| 3 | use warnings; |
| 4 | use base 'KorAP::VirtualCorpus::Doc'; |
| 5 | |
| 6 | # Constructor |
| 7 | sub new { |
| 8 | my $class = shift; |
| 9 | bless { |
| 10 | key => shift, |
| 11 | match => 'eq', |
| 12 | type => 'string', |
| 13 | value => [] |
| 14 | }, $class; |
| 15 | }; |
| 16 | |
| 17 | # Return object type |
| 18 | sub koral_type { |
| 19 | return 'DocVec'; |
| 20 | }; |
| 21 | |
| 22 | # Get or set value |
| 23 | sub value { |
| 24 | my $self = shift; |
| 25 | if (@_) { |
| 26 | $self->{value} = [@_]; |
| 27 | return $self; |
| 28 | }; |
| 29 | return $self->{value}; |
| 30 | }; |
| 31 | |
| 32 | # Stringify fragment |
| 33 | sub _to_fragment { |
| 34 | my $self = shift; |
| 35 | my $json = '{'; |
| 36 | $json .= '"@type":"koral:doc",'; |
| 37 | $json .= '"type":"type:' . $self->type . '",'; |
| 38 | $json .= '"match":"match:' . $self->match . '",'; |
| 39 | $json .= '"key":"' . $self->key . '",'; |
| 40 | $json .= '"value":[' . join(',', map { $self->quote($_) } @{$self->value}) . ']'; |
| 41 | |
| 42 | # Set at the end, when all comments are done |
| 43 | $json .= $self->_commentparam_to_string; |
| 44 | return $json . '}'; |
| 45 | }; |
| 46 | |
| 47 | |
| 48 | 1; |