Remove to_term_string
Change-Id: I9ad4bd51d163a69d9f450acba42b4e22116084f4
diff --git a/lib/Krawfish/Koral.pm b/lib/Krawfish/Koral.pm
index 38f1872..61cf369 100644
--- a/lib/Krawfish/Koral.pm
+++ b/lib/Krawfish/Koral.pm
@@ -412,40 +412,19 @@
sub to_string {
- my $self = shift;
+ my ($self, $id) = @_;
my $str = '';
my @list = ();
if ($self->compile) {
- push @list, 'compile=[' . $self->compile->to_string . ']';
+ push @list, 'compile=[' . $self->compile->to_string($id) . ']';
};
if ($self->corpus) {
- push @list, 'corpus=[' . $self->corpus->to_string . ']';
+ push @list, 'corpus=[' . $self->corpus->to_string($id) . ']';
};
if ($self->query) {
- push @list, 'query=[' . $self->query->to_string . ']';
- };
-
- return join(',', @list);
-};
-
-
-
-sub to_term_string {
- my $self = shift;
- my $str = '';
-
- my @list = ();
-
- if ($self->compile) {
- push @list, 'compile=[' . $self->compile->to_term_string . ']';
- };
- if ($self->corpus) {
- push @list, 'corpus=[' . $self->corpus->to_term_string . ']';
- };
- if ($self->query) {
- push @list, 'query=[' . $self->query->to_term_string . ']';
+ push @list, 'query=[' . $self->query->to_string($id) . ']';
};
return join(',', @list);
diff --git a/lib/Krawfish/Koral/Compile.pm b/lib/Krawfish/Koral/Compile.pm
index edf6cb9..65a7708 100644
--- a/lib/Krawfish/Koral/Compile.pm
+++ b/lib/Krawfish/Koral/Compile.pm
@@ -46,14 +46,8 @@
};
sub to_string {
- my $self = shift;
- # warn 'DEPRECATED'
- return join(',', map { $_->to_string } $self->operations);
-};
-
-sub to_term_string {
- my $self = shift;
- return join(',', map { $_->to_term_string } $self->operations);
+ my ($self, $id) = @_;
+ return join(',', map { $_->to_string($id) } $self->operations);
};
sub to_id_string {
diff --git a/lib/Krawfish/Koral/Compile/Aggregate.pm b/lib/Krawfish/Koral/Compile/Aggregate.pm
index 484c8ab..ab3029c 100644
--- a/lib/Krawfish/Koral/Compile/Aggregate.pm
+++ b/lib/Krawfish/Koral/Compile/Aggregate.pm
@@ -108,17 +108,11 @@
sub to_string {
- my $self = shift;
- # warn 'DEPRECATED'
- return 'aggr=[' . join(',', map { $_->to_string } @$self) . ']';
+ my ($self, $id) = @_;
+ return 'aggr=[' . join(',', map { $_->to_string($id) } @$self) . ']';
};
-sub to_term_string {
- my $self = shift;
- return 'aggr=[' . join(',', map { $_->to_term_string } @$self) . ']';
-};
-
sub to_id_string {
my $self = shift;
return 'aggr=[' . join(',', map { $_->to_id_string } @$self) . ']';
diff --git a/lib/Krawfish/Koral/Compile/Aggregate/Fields.pm b/lib/Krawfish/Koral/Compile/Aggregate/Fields.pm
index 0ff8e3e..31da48e 100644
--- a/lib/Krawfish/Koral/Compile/Aggregate/Fields.pm
+++ b/lib/Krawfish/Koral/Compile/Aggregate/Fields.pm
@@ -74,9 +74,8 @@
sub to_string {
- # warn 'DEPRECATED';
- my $self = shift;
- return 'fields:[' . join(',', map { defined $_ ? $_->to_string : '?' } @$self) . ']';
+ my ($self, $id) = @_;
+ return 'fields:[' . join(',', map { defined $_ ? $_->to_string($id) : '?' } @$self) . ']';
};
@@ -86,12 +85,4 @@
};
-sub to_term_string {
- my $self = shift;
- return 'fields:[' . join(',', map { defined $_ ? $_->to_term_string : '?' } @$self) . ']';
-};
-
-
-
-
1;
diff --git a/lib/Krawfish/Koral/Compile/Aggregate/Values.pm b/lib/Krawfish/Koral/Compile/Aggregate/Values.pm
index ed2f469..e8eefcd 100644
--- a/lib/Krawfish/Koral/Compile/Aggregate/Values.pm
+++ b/lib/Krawfish/Koral/Compile/Aggregate/Values.pm
@@ -66,9 +66,8 @@
sub to_string {
- # warn 'DEPRECATED'
- my $self = shift;
- return 'values:[' . join(',', map { $_->to_string } @$self) . ']';
+ my ($self, $id) = @_;
+ return 'values:[' . join(',', map { $_->to_string($id) } @$self) . ']';
};
@@ -77,11 +76,6 @@
return 'values:[' . join(',', map { $_->to_id_string } @$self) . ']';
};
-sub to_term_string {
- my $self = shift;
- return 'values:[' . join(',', map { $_->to_term_string } @$self) . ']';
-};
-
sub optimize {
my ($self, $segment) = @_;
diff --git a/lib/Krawfish/Koral/Compile/Node/Aggregate.pm b/lib/Krawfish/Koral/Compile/Node/Aggregate.pm
index 16196e6..f2d8b77 100644
--- a/lib/Krawfish/Koral/Compile/Node/Aggregate.pm
+++ b/lib/Krawfish/Koral/Compile/Node/Aggregate.pm
@@ -68,11 +68,10 @@
# Stringification
sub to_string {
-# warn 'DEPRECATED';
- my $self = shift;
+ my ($self, $id) = @_;
return 'aggr(' .
- join(',', map { $_->to_string } @{$self->{aggregates}}) .
- ':' . $self->{query}->to_string . ')';
+ join(',', map { $_->to_string($id) } @{$self->{aggregates}}) .
+ ':' . $self->{query}->to_string($id) . ')';
};
@@ -84,11 +83,4 @@
};
-sub to_term_string {
- my $self = shift;
- return 'aggr(' .
- join(',', map { $_->to_term_string } @{$self->{aggregates}}) .
- ':' . $self->{query}->to_term_string . ')';
-};
-
1;
diff --git a/lib/Krawfish/Koral/Compile/Node/Enrich/Fields.pm b/lib/Krawfish/Koral/Compile/Node/Enrich/Fields.pm
index 2b4c4cc..cb52160 100644
--- a/lib/Krawfish/Koral/Compile/Node/Enrich/Fields.pm
+++ b/lib/Krawfish/Koral/Compile/Node/Enrich/Fields.pm
@@ -17,10 +17,9 @@
sub to_string {
- # warn 'DEPRECATED'
- my $self = shift;
- return 'fields(' . join(',', map { $_->to_string } @{$self->{fields}}) .
- ':' . $self->{query}->to_string . ')';
+ my ($self, $id) = @_;
+ return 'fields(' . join(',', map { $_->to_string($id) } @{$self->{fields}}) .
+ ':' . $self->{query}->to_string($id) . ')';
};
@@ -31,12 +30,6 @@
};
-sub to_term_string {
- my $self = shift;
- return 'fields(' . join(',', map { $_->to_term_string } @{$self->{fields}}) .
- ':' . $self->{query}->to_term_string . ')';
-};
-
# This will identify the query and create a list of sorted fields ids
sub identify {
diff --git a/lib/Krawfish/Koral/Compile/Node/Group/Fields.pm b/lib/Krawfish/Koral/Compile/Node/Group/Fields.pm
index 5aa8255..fe5af0d 100644
--- a/lib/Krawfish/Koral/Compile/Node/Group/Fields.pm
+++ b/lib/Krawfish/Koral/Compile/Node/Group/Fields.pm
@@ -17,10 +17,9 @@
sub to_string {
- # warn 'DEPRECATED';
- my $self = shift;
- return 'gFields(' . join(',', map { $_->to_string } @{$self->{fields}}) .
- ':' . $self->{query}->to_string . ')';
+ my ($self, $id) = @_;
+ return 'gFields(' . join(',', map { $_->to_string($id) } @{$self->{fields}}) .
+ ':' . $self->{query}->to_string($id) . ')';
};
@@ -31,12 +30,6 @@
};
-sub to_term_string {
- my $self = shift;
- return 'gFields(' . join(',', map { $_->to_term_string } @{$self->{fields}}) .
- ':' . $self->{query}->to_term_string . ')';
-};
-
# This will identify the query and create a list of sorted fields ids
sub identify {
diff --git a/lib/Krawfish/Koral/Compile/Node/Sort.pm b/lib/Krawfish/Koral/Compile/Node/Sort.pm
index 59819b9..3682b57 100644
--- a/lib/Krawfish/Koral/Compile/Node/Sort.pm
+++ b/lib/Krawfish/Koral/Compile/Node/Sort.pm
@@ -141,9 +141,8 @@
# Stringification
sub to_string {
- my $self = shift;
- # warn 'DEPRECATED';
- my $str = $self->{sort}->to_string;
+ my ($self, $id) = @_;
+ my $str = $self->{sort}->to_string($id);
if ($self->{top_k}) {
$str .= ';k=' . $self->{top_k};
@@ -153,7 +152,7 @@
$str .= ';sortFilter'
};
- return 'sort(' . $str . ':' . $self->{query}->to_string . ')';
+ return 'sort(' . $str . ':' . $self->{query}->to_string($id) . ')';
};
@@ -173,22 +172,6 @@
return 'sort(' . $str . ':' . $self->{query}->to_id_string . ')';
};
-# Stringification
-sub to_term_string {
- my $self = shift;
- my $str = $self->{sort}->to_term_string;
-
- if ($self->{top_k}) {
- $str .= ';k=' . $self->{top_k};
- };
-
- if ($self->{filter}) {
- $str .= ';sortFilter'
- };
-
- return 'sort(' . $str . ':' . $self->{query}->to_term_string . ')';
-};
-
1;
diff --git a/lib/Krawfish/Koral/Compile/Sort/Field.pm b/lib/Krawfish/Koral/Compile/Sort/Field.pm
index 1eee088..a5e0a95 100644
--- a/lib/Krawfish/Koral/Compile/Sort/Field.pm
+++ b/lib/Krawfish/Koral/Compile/Sort/Field.pm
@@ -60,9 +60,9 @@
sub to_string {
- # warn 'DEPRECATED'
- my $str = 'field=' . $_[0]->{field}->to_string;
- $str .= ($_[0]->{desc} ? '>' : '<');
+ my ($self, $id) = @_;
+ my $str = 'field=' . $self->{field}->to_string($id);
+ $str .= ($self->{desc} ? '>' : '<');
$str;
};
@@ -73,10 +73,5 @@
$str;
};
-sub to_term_string {
- my $str = 'field=' . $_[0]->{field}->to_term_string;
- $str .= ($_[0]->{desc} ? '>' : '<');
- $str;
-};
1;
diff --git a/lib/Krawfish/Koral/Compile/Type/Key.pm b/lib/Krawfish/Koral/Compile/Type/Key.pm
index b34b83f..b1c80e0 100644
--- a/lib/Krawfish/Koral/Compile/Type/Key.pm
+++ b/lib/Krawfish/Koral/Compile/Type/Key.pm
@@ -47,12 +47,10 @@
sub to_string {
- my $self = shift;
-# warn 'DEPRECATED';
- if ($self->{term}) {
- return squote($self->{term});
- };
- return '#' . $self->{term_id};
+ my ($self, $id) = @_;
+ return '#' . $self->{term_id} if $id;
+
+ return squote($self->{term});
};
@@ -62,12 +60,5 @@
};
-sub to_term_string {
- my $self = shift;
- if ($self->{term}) {
- return squote($self->{term});
- };
-};
-
1;
diff --git a/lib/Krawfish/Koral/Corpus/Anywhere.pm b/lib/Krawfish/Koral/Corpus/Anywhere.pm
index 628f9ab..f01e84f 100644
--- a/lib/Krawfish/Koral/Corpus/Anywhere.pm
+++ b/lib/Krawfish/Koral/Corpus/Anywhere.pm
@@ -37,9 +37,6 @@
$_[0]->to_string;
};
-sub to_term_string {
- $_[0]->to_string;
-};
sub operands {
return;
diff --git a/lib/Krawfish/Koral/Document.pm b/lib/Krawfish/Koral/Document.pm
index d8b9514..f16437e 100644
--- a/lib/Krawfish/Koral/Document.pm
+++ b/lib/Krawfish/Koral/Document.pm
@@ -75,8 +75,14 @@
# Stringification
sub to_string {
+ my ($self, $id) = @_;
+ return '[' . $self->fields->to_string($id) . ']' . $self->stream->to_string($id);
+};
+
+# Stringification
+sub to_id_string {
my $self = shift;
- return '[' . $self->fields->to_string . ']' . $self->stream->to_string;
+ return '[' . $self->fields->to_string . ']' . $self->stream->to_id_string;
};
diff --git a/lib/Krawfish/Koral/Document/Stream.pm b/lib/Krawfish/Koral/Document/Stream.pm
index 0209dd7..26b38f3 100644
--- a/lib/Krawfish/Koral/Document/Stream.pm
+++ b/lib/Krawfish/Koral/Document/Stream.pm
@@ -21,12 +21,6 @@
return $self->[$pos];
};
-
-sub to_string {
- my $i = 0;
- return join '', map { '(' . ($i++) . ')' . ($_->to_string // '') } @{$_[0]}
-};
-
sub length {
@{$_[0]};
};
@@ -43,4 +37,15 @@
};
+sub to_string {
+ my ($self, $id) = @_;
+ my $i = 0;
+ return join '', map { '(' . ($i++) . ')' . ($_->to_string($id) // '') } @$self
+};
+
+sub to_id_string {
+ my $i = 0;
+ return join '', map { '(' . ($i++) . ')' . ($_->to_id_string // '') } @{$_[0]}
+};
+
1;
diff --git a/lib/Krawfish/Koral/Document/Subtoken.pm b/lib/Krawfish/Koral/Document/Subtoken.pm
index aaf9a2b..06ae0b4 100644
--- a/lib/Krawfish/Koral/Document/Subtoken.pm
+++ b/lib/Krawfish/Koral/Document/Subtoken.pm
@@ -73,10 +73,11 @@
my ($self, $dict) = @_;
# This is the final subtoken that's only required for preceding bytes
- return $self unless $self->{subterm};
$self->{preceding_enc} = $self->{preceding};
+ return $self unless $self->{subterm};
+
my $term = SUBTERM_PREF . $self->{subterm};
$self->{subterm_id} = $dict->add_term($term);
@@ -88,21 +89,13 @@
};
-# Stringification
-sub to_string {
- my $self = shift;
- return $self->to_id_string // $self->to_term_string;
-};
-
-
sub to_id_string {
my $self = shift;
- return unless defined $self->{subterm_id};
my $str = '<' . $self->preceding_enc . '>';
$str .= '[';
- $str .= '#' . $self->{subterm_id};
+ $str .= $self->{subterm_id} ? '#' . $self->{subterm_id} : '##';
if (@{$self->{anno}}) {
$str .= ';' . join(';', map { $_->to_string } (@{$self->{anno}}));
@@ -111,18 +104,31 @@
return "$str]";
};
-# TODO:
-# Differ between to_term_string and to_id_string
-sub to_term_string {
- my $self = shift;
- return unless defined $self->{subterm};
- my $str = '<' . $self->preceding . '>';
+# Stringification
+sub to_string {
+ my ($self, $id) = @_;
+
+# if ($id) {
+# return unless defined $self->{subterm_id};
+# }
+# else {
+# return unless defined $self->{subterm};
+# };
+
+ my $str = '<' . ($id ? $self->preceding_enc : $self->preceding) . '>';
$str .= '[';
- $str .= squote($self->{subterm});
+
+ if ($id) {
+ $str .= $self->{subterm_id} ? '#' . $self->{subterm_id} : '##';
+ }
+
+ else {
+ $str .= $self->{subterm} ? squote($self->{subterm}) : "''";
+ };
if (@{$self->{anno}}) {
- $str .= ';' . join(';', map { $_->to_string } (@{$self->{anno}}));
+ $str .= ';' . join(';', map { $_->to_string($id) } (@{$self->{anno}}));
};
return "$str]";
diff --git a/lib/Krawfish/Koral/Query/Filter.pm b/lib/Krawfish/Koral/Query/Filter.pm
index a80a1b4..26ab516 100644
--- a/lib/Krawfish/Koral/Query/Filter.pm
+++ b/lib/Krawfish/Koral/Query/Filter.pm
@@ -133,12 +133,11 @@
sub to_string {
- # warn 'DEPRECATED'
- my $self = shift;
+ my ($self, $id) = @_;
my $str = 'filter(';
- $str .= $self->operand->to_string;
+ $str .= $self->operand->to_string($id);
$str .= ',';
- $str .= $self->corpus->to_string;
+ $str .= $self->corpus->to_string($id);
return $str . ')';
};
@@ -152,16 +151,6 @@
};
-sub to_term_string {
- my $self = shift;
- my $str = 'filter(';
- $str .= $self->operand->to_term_string;
- $str .= ',';
- $str .= $self->corpus->to_term_string;
- return $str . ')';
-};
-
-
sub to_koral_fragment {
my $self = shift;
return {
diff --git a/lib/Krawfish/Koral/Query/Sequence.pm b/lib/Krawfish/Koral/Query/Sequence.pm
index 7c32b8f..171456f 100644
--- a/lib/Krawfish/Koral/Query/Sequence.pm
+++ b/lib/Krawfish/Koral/Query/Sequence.pm
@@ -152,9 +152,8 @@
# Stringification
sub to_string {
- # warn 'DEPRECATED'
- my $self = shift;
- return join '', map { $_->to_string } @{$self->operands};
+ my ($self, $id) = @_;
+ return join '', map { $_->to_string($id) } @{$self->operands};
};
@@ -164,12 +163,6 @@
return join '', map { $_->to_id_string } @{$self->operands};
};
-# Stringification
-sub to_term_string {
- my $self = shift;
- return join '', map { $_->to_term_string } @{$self->operands};
-};
-
sub from_koral {
my $class = shift;
diff --git a/lib/Krawfish/Koral/Query/Term.pm b/lib/Krawfish/Koral/Query/Term.pm
index 6316cfd..617fceb 100644
--- a/lib/Krawfish/Koral/Query/Term.pm
+++ b/lib/Krawfish/Koral/Query/Term.pm
@@ -268,7 +268,7 @@
# stringify term
sub to_string {
- my ($self, $fragment) = @_;
+ my ($self, $id, $fragment) = @_;
return '-' if $self->is_null;
@@ -306,10 +306,6 @@
};
-sub to_term_string {
- $_[0]->to_string;
-};
-
sub to_neutral {
return $_[0]->to_term;
};
diff --git a/lib/Krawfish/Koral/Query/Token.pm b/lib/Krawfish/Koral/Query/Token.pm
index 154608f..7da6893 100644
--- a/lib/Krawfish/Koral/Query/Token.pm
+++ b/lib/Krawfish/Koral/Query/Token.pm
@@ -152,7 +152,7 @@
# Stringify
sub to_string {
- my $self = shift;
+ my ($self, $id) = @_;
my $string = '[';
@@ -184,11 +184,6 @@
};
-# Stringify
-sub to_term_string {
- $_[0]->to_string;
-};
-
sub maybe_unsorted { 0 };
sub from_koral {
diff --git a/lib/Krawfish/Koral/Result/Enrich/Snippet.pm b/lib/Krawfish/Koral/Result/Enrich/Snippet.pm
index 1672094..45012d6 100644
--- a/lib/Krawfish/Koral/Result/Enrich/Snippet.pm
+++ b/lib/Krawfish/Koral/Result/Enrich/Snippet.pm
@@ -24,16 +24,17 @@
# Stringification
sub to_string {
- my $self = shift;
- return 'snippet:' . join(',', map { $_->to_string } @{$self->{hit_ids}});
+ my ($self, $id) = @_;
+ return 'snippet:' . join(',', map { $_->to_string($id) } @{$self->{hit_ids}});
};
# Stringification
-sub to_term_string {
+sub to_id_string {
my $self = shift;
- return 'snippet:' . join(',', map { $_->to_term_string } @{$self->{hit_ids}});
+ return 'snippet:' . join(',', map { $_->to_id_string } @{$self->{hit_ids}});
};
+
1;
diff --git a/lib/Krawfish/Koral/Result/Match.pm b/lib/Krawfish/Koral/Result/Match.pm
index 84e22f2..a931ba3 100644
--- a/lib/Krawfish/Koral/Result/Match.pm
+++ b/lib/Krawfish/Koral/Result/Match.pm
@@ -43,7 +43,7 @@
# Stringification
sub to_string {
- my $self = shift;
+ my ($self, $id) = @_;
my $str = '[';
# Identical to Posting
@@ -56,14 +56,14 @@
};
foreach (@{$self->{enrichments}}) {
- $str .= '|' . $_->to_string;
+ $str .= '|' . $_->to_string($id);
};
return $str . ']';
};
-sub to_term_string {
+sub to_id_string {
my $self = shift;
my $str = '[';
@@ -77,7 +77,7 @@
};
foreach (@{$self->{enrichments}}) {
- $str .= '|' . $_->to_term_string;
+ $str .= '|' . $_->to_id_string;
};
return $str . ']';