Mailing List Archive

r3675 - in trunk: c_src/KinoSearch/Highlight perl/lib perl/lib/KinoSearch/Highlight perl/t
Author: creamyg
Date: 2008-07-29 20:39:39 -0700 (Tue, 29 Jul 2008)
New Revision: 3675

Modified:
trunk/c_src/KinoSearch/Highlight/HeatMap.bp
trunk/c_src/KinoSearch/Highlight/HeatMap.c
trunk/c_src/KinoSearch/Highlight/HighlightSpan.bp
trunk/c_src/KinoSearch/Highlight/HighlightSpan.c
trunk/c_src/KinoSearch/Highlight/Highlighter.c
trunk/perl/lib/KinoSearch.pm
trunk/perl/lib/KinoSearch/Highlight/HighlightSpan.pm
trunk/perl/t/303-highlighter.t
trunk/perl/t/309-highlight_span.t
trunk/perl/t/310-heat_map.t
Log:
Rename HighlightSpan's "start_offset" member to "offset".


Modified: trunk/c_src/KinoSearch/Highlight/HeatMap.bp
===================================================================
--- trunk/c_src/KinoSearch/Highlight/HeatMap.bp 2008-07-30 03:29:12 UTC (rev 3674)
+++ trunk/c_src/KinoSearch/Highlight/HeatMap.bp 2008-07-30 03:39:39 UTC (rev 3675)
@@ -16,12 +16,6 @@
static HeatMap*
init(HeatMap *self, VArray *spans, u32_t window = 133);

- /** Compare two (pointers-to) HighlightSpans, first by start_offset, then
- * by length.
- */
- static int
- compare_spans(const void *va, const void *vb);
-
/** Reduce/slice overlapping spans. Say we have two spans:
*
* Span 1: positions 11-20, score .3
@@ -34,7 +28,7 @@
* Span 3: positions 20-30, score .5
*
* @param spans An array of HighlightSpans. The spans must be sorted by
- * start_offset then length.
+ * offset then length.
*/
incremented VArray*
Flatten_Spans(HeatMap *self, VArray *spans);
@@ -51,7 +45,7 @@
* each pair that yields a non-zero proximity boost.
*
* @param spans An array of HighlightSpans. The spans must be sorted by
- * start_offset then length.
+ * offset then length.
*/
incremented VArray*
Generate_Proximity_Boosts(HeatMap *self, VArray *spans);

Modified: trunk/c_src/KinoSearch/Highlight/HeatMap.c
===================================================================
--- trunk/c_src/KinoSearch/Highlight/HeatMap.c 2008-07-30 03:29:12 UTC (rev 3674)
+++ trunk/c_src/KinoSearch/Highlight/HeatMap.c 2008-07-30 03:39:39 UTC (rev 3675)
@@ -44,7 +44,7 @@
}

/* Create all the spans needed by HeatMap_Flatten_Spans, based on the source
- * start offsets and end offsets... but leave the scores at 0. */
+ * offsets and lengths... but leave the scores at 0. */
static VArray*
flattened_but_empty_spans(VArray *spans)
{
@@ -58,8 +58,8 @@
/* Assemble a list of all unique start/end boundaries. */
for (i = 0; i < num_spans; i++) {
HighlightSpan *span = (HighlightSpan*)VA_Fetch(spans, i);
- bounds[i] = span->start_offset;
- bounds[i + num_spans] = span->start_offset + span->length;
+ bounds[i] = span->offset;
+ bounds[i + num_spans] = span->offset + span->length;
}
qsort(bounds, num_spans * 2, sizeof(u32_t), compare_u32);
for (i = 0, num_bounds = 0, last = U32_MAX; i < num_spans * 2; i++) {
@@ -101,14 +101,14 @@
for (i = 0; i < spans->size; i++) {
HighlightSpan *source_span = (HighlightSpan*)VA_Fetch(spans, i);
u32_t j;
- u32_t source_span_end = source_span->start_offset + source_span->length;
+ u32_t source_span_end = source_span->offset + source_span->length;

/* Get the location of the flattened span that shares the source
- * span's start_offset. */
+ * span's offset. */
for ( ; dest_tick < flattened->size; dest_tick++) {
HighlightSpan *dest_span
= (HighlightSpan*)VA_Fetch(flattened, dest_tick);
- if (dest_span->start_offset == source_span->start_offset)
+ if (dest_span->offset == source_span->offset)
break;
}

@@ -116,7 +116,7 @@
for (j = dest_tick; j < flattened->size; j++) {
HighlightSpan *dest_span
= (HighlightSpan*)VA_Fetch(flattened, j);
- if (dest_span->start_offset == source_span_end)
+ if (dest_span->offset == source_span_end)
break;
else {
dest_span->weight += source_span->weight;
@@ -147,8 +147,8 @@
int comparison = HLSpan_compare(&span1, &span2);
HighlightSpan *lower = comparison <= 0 ? span1 : span2;
HighlightSpan *upper = comparison >= 0 ? span1 : span2;
- i32_t lower_end_offset = lower->start_offset + lower->length;
- i32_t distance = (i32_t)upper->start_offset - lower_end_offset;
+ i32_t lower_end_offset = lower->offset + lower->length;
+ i32_t distance = (i32_t)upper->offset - lower_end_offset;

/* If spans overlap, set distance to 0. */
if (distance < 0) distance = 0;
@@ -183,9 +183,9 @@
break;
}
else {
- u32_t length = (span2->start_offset - span1->start_offset)
+ u32_t length = (span2->offset - span1->offset)
+ span2->length;
- HighlightSpan *boost_span = HLSpan_new(span1->start_offset,
+ HighlightSpan *boost_span = HLSpan_new(span1->offset,
length, prox_score);
VA_Push(boosts, (Obj*)boost_span);
REFCOUNT_DEC(boost_span);

Modified: trunk/c_src/KinoSearch/Highlight/HighlightSpan.bp
===================================================================
--- trunk/c_src/KinoSearch/Highlight/HighlightSpan.bp 2008-07-30 03:29:12 UTC (rev 3674)
+++ trunk/c_src/KinoSearch/Highlight/HighlightSpan.bp 2008-07-30 03:39:39 UTC (rev 3675)
@@ -3,15 +3,15 @@
class KinoSearch::Highlight::HighlightSpan cnick HLSpan
extends KinoSearch::Obj {

- u32_t start_offset;
+ u32_t offset;
u32_t length;
float weight;

static incremented HighlightSpan*
- new(u32_t start_offset, u32_t length, float weight);
+ new(u32_t offset, u32_t length, float weight);

static HighlightSpan*
- init(HighlightSpan *self, u32_t start_offset, u32_t length,
+ init(HighlightSpan *self, u32_t offset, u32_t length,
float weight);

static int

Modified: trunk/c_src/KinoSearch/Highlight/HighlightSpan.c
===================================================================
--- trunk/c_src/KinoSearch/Highlight/HighlightSpan.c 2008-07-30 03:29:12 UTC (rev 3674)
+++ trunk/c_src/KinoSearch/Highlight/HighlightSpan.c 2008-07-30 03:39:39 UTC (rev 3675)
@@ -4,19 +4,19 @@


HighlightSpan*
-HLSpan_new(u32_t start_offset, u32_t length, float weight)
+HLSpan_new(u32_t offset, u32_t length, float weight)
{
HighlightSpan *self = (HighlightSpan*)CREATE(NULL, HIGHLIGHTSPAN);
- return HLSpan_init(self, start_offset, length, weight);
+ return HLSpan_init(self, offset, length, weight);
}

HighlightSpan*
-HLSpan_init(HighlightSpan *self, u32_t start_offset, u32_t length,
+HLSpan_init(HighlightSpan *self, u32_t offset, u32_t length,
float weight)
{
- self->start_offset = start_offset;
- self->length = length;
- self->weight = weight;
+ self->offset = offset;
+ self->length = length;
+ self->weight = weight;
return self;
}

@@ -25,7 +25,7 @@
{
HighlightSpan *a = *(HighlightSpan**)va;
HighlightSpan *b = *(HighlightSpan**)vb;
- int comparison = a->start_offset - b->start_offset;
+ int comparison = a->offset - b->offset;
if (comparison == 0) comparison = a->length - b->length;
return comparison;
}

Modified: trunk/c_src/KinoSearch/Highlight/Highlighter.c
===================================================================
--- trunk/c_src/KinoSearch/Highlight/Highlighter.c 2008-07-30 03:29:12 UTC (rev 3674)
+++ trunk/c_src/KinoSearch/Highlight/Highlighter.c 2008-07-30 03:39:39 UTC (rev 3675)
@@ -114,7 +114,7 @@
for (i = heat_map->spans->size; i--; ) {
HighlightSpan *span = (HighlightSpan*)VA_Fetch(heat_map->spans, i);
if (span->weight >= max_score) {
- retval = span->start_offset;
+ retval = span->offset;
max_score = span->weight;
}
}
@@ -331,11 +331,11 @@

for (i = 0; i < spans->size; i++) {
HighlightSpan *span = (HighlightSpan*)VA_Fetch(spans, i);
- if (span->start_offset < top) {
+ if (span->offset < top) {
continue;
}
else {
- i32_t relative_start = span->start_offset - top;
+ i32_t relative_start = span->offset - top;
i32_t relative_end = relative_start + span->length;

if (relative_start > last_end) {

Modified: trunk/perl/lib/KinoSearch/Highlight/HighlightSpan.pm
===================================================================
--- trunk/perl/lib/KinoSearch/Highlight/HighlightSpan.pm 2008-07-30 03:29:12 UTC (rev 3674)
+++ trunk/perl/lib/KinoSearch/Highlight/HighlightSpan.pm 2008-07-30 03:39:39 UTC (rev 3675)
@@ -7,8 +7,8 @@
__AUTO_XS__

{ "KinoSearch::Highlight::HighlightSpan" => {
- make_getters => [qw( start_offset length weight )],
- make_setters => [qw( start_offset length weight )],
+ make_getters => [qw( offset length weight )],
+ make_setters => [qw( offset length weight )],
make_constructors => ["new"],
}
}
@@ -29,14 +29,14 @@
=head2 new

my $highlighter = KinoSearch::Highlight::Highlighter->new(
- start_offset => 75,
- length => 7,
- weight => 1,
+ offset => 75,
+ length => 7,
+ weight => 1,
);

Constructor.

-=head2 get_start_offset
+=head2 get_offset

Accessor method.


Modified: trunk/perl/lib/KinoSearch.pm
===================================================================
--- trunk/perl/lib/KinoSearch.pm 2008-07-30 03:29:12 UTC (rev 3674)
+++ trunk/perl/lib/KinoSearch.pm 2008-07-30 03:39:39 UTC (rev 3675)
@@ -413,7 +413,7 @@
$args{spans} = to_kino( $args{spans} );
my $self = $either->_new(%args);
my $locations = $heat_map{$$self}
- = { map { ( $_->get_start_offset => $_->get_weight ) }
+ = { map { ( $_->get_offset => $_->get_weight ) }
@{ $self->get_spans->to_perl } };

# Sort by temperature, lowest to highest.

Modified: trunk/perl/t/303-highlighter.t
===================================================================
--- trunk/perl/t/303-highlighter.t 2008-07-30 03:29:12 UTC (rev 3674)
+++ trunk/perl/t/303-highlighter.t 2008-07-30 03:39:39 UTC (rev 3675)
@@ -329,9 +329,9 @@
my $spans = KinoSearch::Util::VArray->new( capacity => @_ / 2 );
for my $span_spec (@_) {
my $hl_span = KinoSearch::Highlight::HighlightSpan->new(
- start_offset => $span_spec->[0],
- length => $span_spec->[1],
- weight => 1,
+ offset => $span_spec->[0],
+ length => $span_spec->[1],
+ weight => 1,
);
$spans->push($hl_span);
}

Modified: trunk/perl/t/309-highlight_span.t
===================================================================
--- trunk/perl/t/309-highlight_span.t 2008-07-30 03:29:12 UTC (rev 3674)
+++ trunk/perl/t/309-highlight_span.t 2008-07-30 03:39:39 UTC (rev 3675)
@@ -7,20 +7,20 @@
use KinoSearch::Highlight::HighlightSpan;

my $span = KinoSearch::Highlight::HighlightSpan->new(
- start_offset => 2,
- length => 3,
- weight => 7,
+ offset => 2,
+ length => 3,
+ weight => 7,
);

-is( $span->get_start_offset, 2, "get_start_offset" );
-is( $span->get_length, 3, "get_length" );
-is( $span->get_weight, 7, "get_weight" );
+is( $span->get_offset, 2, "get_offset" );
+is( $span->get_length, 3, "get_length" );
+is( $span->get_weight, 7, "get_weight" );

-$span->set_start_offset(10);
+$span->set_offset(10);
$span->set_length(1);
$span->set_weight(4);

-is( $span->get_start_offset, 10, "set_start_offset" );
-is( $span->get_length, 1, "set_length" );
-is( $span->get_weight, 4, "set_weight" );
+is( $span->get_offset, 10, "set_offset" );
+is( $span->get_length, 1, "set_length" );
+is( $span->get_weight, 4, "set_weight" );


Modified: trunk/perl/t/310-heat_map.t
===================================================================
--- trunk/perl/t/310-heat_map.t 2008-07-30 03:29:12 UTC (rev 3674)
+++ trunk/perl/t/310-heat_map.t 2008-07-30 03:39:39 UTC (rev 3675)
@@ -16,11 +16,11 @@
span2 => make_span( 5, 4, 1.0 )
);
my $smaller_boost = $heat_map->calc_proximity_boost(
- span1 => make_span( 0, 10, 1.0 ),
+ span1 => make_span( 0, 10, 1.0 ),
span2 => make_span( 100, 10, 1.0 )
);
my $zero_boost = $heat_map->calc_proximity_boost(
- span1 => make_span( 0, 10, 1.0 ),
+ span1 => make_span( 0, 10, 1.0 ),
span2 => make_span( 150, 10, 1.0 )
);
is( $big_boost, $equally_big_boost,
@@ -57,10 +57,10 @@
$flattened = $heat_map->flatten_spans($spans);
is_deeply(
spans_to_arg_array($flattened),
- [ [ 10, 4, 1.0 ],
- [ 14, 2, 5.0 ],
- [ 16, 2, 7.0 ],
- [ 18, 2, 3.0 ],
+ [ [ 10, 4, 1.0 ],
+ [ 14, 2, 5.0 ],
+ [ 16, 2, 7.0 ],
+ [ 18, 2, 3.0 ],
[ 20, 10, 2.0 ]
],
"flatten three overlapping spans"
@@ -88,9 +88,9 @@
);

$spans = make_spans(
- [ 10, 10, 1.0 ],
+ [ 10, 10, 1.0 ],
[ 16, 4, 4.0 ],
- [ 16, 14, 2.0 ],
+ [ 16, 14, 2.0 ],
[ 230, 10, 10.0 ]
);
$flattened = $heat_map->flatten_spans($spans);
@@ -104,9 +104,9 @@

sub make_span {
return KinoSearch::Highlight::HighlightSpan->new(
- start_offset => $_[0],
- length => $_[1],
- weight => $_[2],
+ offset => $_[0],
+ length => $_[1],
+ weight => $_[2],
);
}

@@ -122,8 +122,7 @@
my $spans = shift;
my @out;
for (@$spans) {
- push @out,
- [ $_->get_start_offset, $_->get_length, $_->get_weight ];
+ push @out, [ $_->get_offset, $_->get_length, $_->get_weight ];
}
return \@out;
}


_______________________________________________
kinosearch-commits mailing list
kinosearch-commits@rectangular.com
http://www.rectangular.com/mailman/listinfo/kinosearch-commits