blob: b65d9f6d984765afdf2cb683270f5150a7ecd493 [file] [log] [blame]
Akron4763ea62016-11-02 19:36:18 +01001use Test::More;
Akrone0201942016-11-26 01:11:31 +01002use Test::Krawfish;
Akron4763ea62016-11-02 19:36:18 +01003use strict;
4use warnings;
Akron4763ea62016-11-02 19:36:18 +01005
6use_ok('Krawfish::Koral');
7use_ok('Krawfish::Index');
8
9my $index = Krawfish::Index->new;
10
Akron56422cf2017-08-16 14:17:01 +020011ok_index($index, '<1:opennlp/c=NP>[Der][hey]</1>', 'Add new document');
Akron4763ea62016-11-02 19:36:18 +010012
13my $koral = Krawfish::Koral->new;
14
15my $builder = $koral->query_builder;
16
Akronddf077a2016-11-05 15:00:00 +010017# isAround(<opennlp/c=NP>, Der)
Akron6621e112016-11-05 17:21:39 +010018my $query = $builder->position(
Akron4763ea62016-11-02 19:36:18 +010019 ['isAround'],
20 $builder->span('opennlp/c=NP'),
21 $builder->token('Der')
22);
Akron655a10a2017-09-11 14:13:18 +020023ok(!$query->is_anywhere, 'Is anywhere');
Akron4763ea62016-11-02 19:36:18 +010024ok(!$query->is_optional, 'Isn\'t optional');
25ok(!$query->is_null, 'Isn\'t null');
26ok(!$query->is_negative, 'Isn\'t negative');
27ok(!$query->is_extended, 'Isn\'t extended');
Akron17c0a3d2017-06-11 23:19:16 +020028is($query->to_string, 'constr(pos=isAround:<opennlp/c=NP>,[Der])', 'Stringification');
29ok($query = $query->normalize, 'Normalize');
Akronc5529372017-06-21 15:56:18 +020030is($query->to_string, 'constr(pos=isAround:<opennlp/c=NP>,Der)', 'Stringification');
Akron6621e112016-11-05 17:21:39 +010031ok(!$query->has_error, 'Builder has no error');
Akron5864cf02017-08-02 19:38:41 +020032ok($query = $query->identify($index->dict), 'Optimize');
Akron92d9f672017-08-16 12:23:11 +020033is($query->to_string, "constr(pos=isAround:#3,#2)", 'Stringification');
Akron5864cf02017-08-02 19:38:41 +020034ok($query = $query->optimize($index->segment), 'Optimize');
Akron92d9f672017-08-16 12:23:11 +020035is($query->to_string, "constr(pos=128:#3,#2)", 'Stringification');
Akron5864cf02017-08-02 19:38:41 +020036
37
Akronddf077a2016-11-05 15:00:00 +010038
39#####################
40# Test 0 as element #
41#####################
Akron2083bc42016-11-13 21:07:32 +010042# isAround(<opennlp/c=NP>,0)
Akron6621e112016-11-05 17:21:39 +010043$query = $builder->position(
Akronddf077a2016-11-05 15:00:00 +010044 ['isAround'],
45 $builder->span('opennlp/c=NP'),
46 $builder->null
47);
Akron655a10a2017-09-11 14:13:18 +020048ok(!$query->is_anywhere, 'Is anywhere');
Akronddf077a2016-11-05 15:00:00 +010049ok(!$query->is_optional, 'Isn\'t optional');
50ok(!$query->is_null, 'Isn\'t null');
51ok(!$query->is_negative, 'Isn\'t negative');
52ok(!$query->is_extended, 'Isn\'t extended');
Akronc5529372017-06-21 15:56:18 +020053is($query->to_string, 'constr(pos=isAround:<opennlp/c=NP>,-)', 'Stringification');
Akronc048b182017-06-13 01:29:03 +020054ok($query = $query->normalize, 'Normalize');
Akron6621e112016-11-05 17:21:39 +010055ok(!$query->has_error, 'Builder has no error');
Akronc048b182017-06-13 01:29:03 +020056is($query->to_string, '<opennlp/c=NP>', 'Stringification');
Akron5864cf02017-08-02 19:38:41 +020057ok($query = $query->identify($index->dict)->optimize($index->segment), 'Optimize');
Akron92d9f672017-08-16 12:23:11 +020058is($query->to_string, "#3", 'Planned Stringification');
Akronddf077a2016-11-05 15:00:00 +010059
Akron1fe979b2017-07-25 14:58:47 +020060
Akronddf077a2016-11-05 15:00:00 +010061#####################
62# Test 0 as element #
63#####################
Akron2083bc42016-11-13 21:07:32 +010064# isAround(<opennlp/c=NP>,0)
Akron6621e112016-11-05 17:21:39 +010065$query = $builder->position(
Akronddf077a2016-11-05 15:00:00 +010066 ['isWithin'],
67 $builder->span('opennlp/c=NP'),
68 $builder->null
69);
Akron1fe979b2017-07-25 14:58:47 +020070
Akron655a10a2017-09-11 14:13:18 +020071ok(!$query->is_anywhere, 'Is anywhere');
Akronddf077a2016-11-05 15:00:00 +010072ok(!$query->is_optional, 'Isn\'t optional');
73ok(!$query->is_null, 'Isn\'t null');
74ok(!$query->is_negative, 'Isn\'t negative');
75ok(!$query->is_extended, 'Isn\'t extended');
Akronc5529372017-06-21 15:56:18 +020076is($query->to_string, 'constr(pos=isWithin:<opennlp/c=NP>,-)', 'Stringification');
Akronc048b182017-06-13 01:29:03 +020077ok(!$query->normalize, 'Normalize');
Akron6621e112016-11-05 17:21:39 +010078ok($query->has_error, 'Builder has error');
Akronddf077a2016-11-05 15:00:00 +010079
80
Akronded01ae2016-11-23 13:43:54 +010081##########################
82# Test freq=0 as element #
83##########################
84# isAround(<opennlp/c=NP>,Bus)
85$query = $builder->position(
86 ['isWithin'],
87 $builder->span('opennlp/c=NP'),
88 $builder->token('Bus')
89);
Akronc048b182017-06-13 01:29:03 +020090is($query->to_string, 'constr(pos=isWithin:<opennlp/c=NP>,[Bus])', 'Stringification');
91ok($query = $query->normalize, 'Normalize');
Akronc5529372017-06-21 15:56:18 +020092is($query->to_string, 'constr(pos=isWithin:<opennlp/c=NP>,Bus)', 'Stringification');
Akron5864cf02017-08-02 19:38:41 +020093ok($query = $query->identify($index->dict)->optimize($index->segment), 'Normalize');
Akronc048b182017-06-13 01:29:03 +020094is($query->to_string, '[0]', 'Stringification');
Akronded01ae2016-11-23 13:43:54 +010095
96
Akronbc7dd432017-07-18 14:21:51 +020097TODO: {
98 local $TODO = "Test further";
Akron655a10a2017-09-11 14:13:18 +020099 # extendedLeft, extendedRight, negative, anywhere, optional ...
Akronbc7dd432017-07-18 14:21:51 +0200100};
101
Akron4763ea62016-11-02 19:36:18 +0100102
103done_testing;
104__END__
105