Introduced squote as an util method
diff --git a/lib/Krawfish/Koral/Corpus/Field.pm b/lib/Krawfish/Koral/Corpus/Field.pm
index 3401fbf..0d26046 100644
--- a/lib/Krawfish/Koral/Corpus/Field.pm
+++ b/lib/Krawfish/Koral/Corpus/Field.pm
@@ -5,7 +5,10 @@
use strict;
use warnings;
-# TODO: Check for valid parameters
+# TODO:
+# - Check for valid parameters
+# - Only support positive terms
+# - Wrap in negative field!
sub new {
my $class = shift;
@@ -21,6 +24,7 @@
sub is_leaf { 1 };
+# Equal
sub eq {
my $self = shift;
$self->{match} = 'eq';
@@ -28,6 +32,8 @@
return $self;
};
+
+# Not equal
sub ne {
my $self = shift;
$self->{match} = 'eq';
@@ -36,6 +42,8 @@
return $self;
};
+
+# Check for negativity
sub is_negative {
my $self = shift;
if (scalar @_ == 1) {
@@ -81,6 +89,8 @@
return $self;
};
+
+# Contains the value in multi-token field
sub contains {
my $self = shift;
$self->{match} = 'contains';
@@ -88,6 +98,8 @@
return $self;
};
+
+# Does not contain the value in multi-token field
sub excludes {
my $self = shift;
$self->{match} = 'excludes';
@@ -95,6 +107,9 @@
return $self;
};
+sub can_toggle_negativity {
+};
+
sub plan_for {
my ($self, $index) = @_;
diff --git a/lib/Krawfish/Koral/Corpus/Negation.pm b/lib/Krawfish/Koral/Corpus/Negation.pm
new file mode 100644
index 0000000..9421b0c
--- /dev/null
+++ b/lib/Krawfish/Koral/Corpus/Negation.pm
@@ -0,0 +1,35 @@
+package Krawfish::Koral::Corpus::Negation;
+use parent 'Krawfish::Koral::Corpus';
+use strict;
+use warnings;
+use constant DEBUG => 0;
+
+sub new {
+ my $class = shift;
+ bless {
+ operand => shift
+ }, $class;
+};
+
+sub type {
+ 'neg';
+};
+
+sub operand {
+ $_[0]->{operand};
+};
+
+sub is_negative {
+ 1;
+};
+
+sub has_classes {
+ $_[0]->{operand}->has_classes;
+};
+
+sub to_koral_fragment {
+ my $self = shift;
+};
+
+
+1;
diff --git a/lib/Krawfish/Koral/Meta/Builder.pm b/lib/Krawfish/Koral/Meta/Builder.pm
index 785517c..a7098b9 100644
--- a/lib/Krawfish/Koral/Meta/Builder.pm
+++ b/lib/Krawfish/Koral/Meta/Builder.pm
@@ -34,4 +34,17 @@
$self;
};
+sub limit {
+ my $self = shift;
+ if (@_ == 2) {
+ $self->start_index(shift());
+ $self->items_per_page(shift());
+ }
+ else {
+ $self->start_index(0);
+ $self->items_per_page(shift());
+ };
+ $self;
+};
+
1;
diff --git a/lib/Krawfish/Koral/Query/Builder.pm b/lib/Krawfish/Koral/Query/Builder.pm
index c4471b0..4ae34bc 100644
--- a/lib/Krawfish/Koral/Query/Builder.pm
+++ b/lib/Krawfish/Koral/Query/Builder.pm
@@ -17,6 +17,7 @@
# TODO: Not all constraints need to be wrapped
use Krawfish::Koral::Query::Constraint::Position;
use Krawfish::Koral::Query::Constraint::ClassDistance;
+use Krawfish::Koral::Query::Constraint::NotBetween;
sub new {
my $class = shift;
@@ -118,6 +119,11 @@
Krawfish::Koral::Query::Constraint::ClassDistance->new(@_);
};
+sub c_not_between {
+ shift;
+ Krawfish::Koral::Query::Constraint::NotBetween->new(@_);
+};
+
sub length {
shift;
Krawfish::Koral::Query::Length->new(@_);
diff --git a/lib/Krawfish/Koral/Query/Constraint/NotBetween.pm b/lib/Krawfish/Koral/Query/Constraint/NotBetween.pm
new file mode 100644
index 0000000..72c5eda
--- /dev/null
+++ b/lib/Krawfish/Koral/Query/Constraint/NotBetween.pm
@@ -0,0 +1,25 @@
+package Krawfish::Koral::Query::Constraint::NotBetween;
+use Krawfish::Query::Constraint::NotBetween;
+use Krawfish::Util::String qw/squote/;
+use strict;
+use warnings;
+
+sub new {
+ my $class = shift;
+ bless {
+ query => shift
+ }, $class;
+};
+
+sub to_string {
+ my $self = shift;
+ return 'notBetween=' . squote($self->{query}->to_string);
+};
+
+sub plan_for {
+ my ($self, $index) = @_;
+ my $query = $self->{query}->plan_for($index);
+ Krawfish::Query::Constraint::NotBetween->new($query);
+};
+
+1;
diff --git a/lib/Krawfish/Koral/Query/Sequence.pm b/lib/Krawfish/Koral/Query/Sequence.pm
index b2d2682..053e2c7 100644
--- a/lib/Krawfish/Koral/Query/Sequence.pm
+++ b/lib/Krawfish/Koral/Query/Sequence.pm
@@ -7,6 +7,8 @@
# TODO: Optimize if there is an identical subquery
# in a direct sequence - make this a repetition!!!
+# Todo: Check for queries like "Der {[pos!=ADJ]*} Mann"
+
use constant DEBUG => 0;
sub new {
diff --git a/lib/Krawfish/Koral/Util/BooleanTree.pm b/lib/Krawfish/Koral/Util/BooleanTree.pm
index d034e68..9063e89 100644
--- a/lib/Krawfish/Koral/Util/BooleanTree.pm
+++ b/lib/Krawfish/Koral/Util/BooleanTree.pm
@@ -8,10 +8,14 @@
use constant DEBUG => 1;
+# TODO:
+# To simplify this, it may be useful to use Negation instead of is_negative().
+# This means, fields with "ne" won't be "ne"-fields, but become not(term).
+# It's also easier to detect double negation.
+
# To disjunctive normal form / DNF
sub _normalize {
-
};
# TODO:
@@ -113,8 +117,11 @@
# - function: TF_Idempotent -> DONE
+# TODO:
+# This should return a cloned query instead of in-place creation
sub planned_tree {
my $self = shift;
+
foreach my $op (@{$self->operands}) {
if ($op && $op->type eq $self->type) {
$op->planned_tree