blob: 613710b94429b48c276356e6f60b556cd490c55c [file] [log] [blame]
Akron7dacd012020-05-27 12:18:57 +02001package KorAP::VirtualCorpus::And;
2use strict;
3use warnings;
4use base 'KorAP::VirtualCorpus';
5
6
7# TODO:
8# Support comments!
9
10
11# Constructor
12sub new {
13 my $class = shift;
14 bless { ops => [@_] }, $class;
15};
16
17
18# Get koral type
19sub koral_type {
20 return 'And';
21};
22
23
24# Get operands
25sub operands {
26 shift->{ops};
27};
28
29
30# Flatten group
31sub flatten {
32 my $self = shift;
33
34 my @ops;
35
36 foreach (@{$self->{ops}}) {
37 if ($_->koral_type eq 'And') {
38 push @ops, @{$_->operands};
39 }
40
41 else {
42 push @ops, $_->flatten;
43 };
44 };
45
46 $self->{ops} = \@ops;
47
48 return $self;
49};
50
51
52# Serialize fragment
53sub _to_fragment {
54 my $self = shift;
55 my $json = '{';
56 $json .= '"@type":"koral:docGroup",';
57 $json .= '"operation":"operation:and",';
58 $json .= '"operands":[';
59 $json .= join(',', map { $_->_to_fragment } @{$self->{ops}});
60 $json .= ']';
61
62 # Set at the end, when all comments are done
63 $json .= $self->_commentparam_to_string;
64 $json .= '}';
65 return $json;
66};
67
68
691;