Permalink
Browse files

summarize long abstracts.

git-svn-id: svn://svn.mongueurs.net/act/trunk@2277 67b57a05-4208-db11-a765-00306e02d86a
  • Loading branch information...
maddingue committed Jul 14, 2011
1 parent 3ce6df9 commit 27ad7039fec32fa9b56ca3e6a49aa70e53aa141a
Showing with 36 additions and 1 deletion.
  1. +36 −1 lib/Act/Handler/Talk/Proceedings.pm
@@ -6,12 +6,19 @@ use Act::Talk;
use Act::User;
+#
+# handler()
+# -------
sub handler {
# retrieve talks and speaker info
my $talks = Act::Talk->get_talks( conf_id => $Request{conference} );
for my $talk (@$talks) {
- $talk->{chunked_abstract} = Act::Abstract::chunked( $talk->abstract );
+ # make the User object for the speaker
$talk->{user} = Act::User->new( user_id => $talk->user_id );
+
+ # make a summary of the abstract (some people write long abstracts)
+ my $abstract = Act::Abstract::chunked( $talk->abstract );
+ $talk->{chunked_abstract} = text_summary($abstract, 400);
}
# sort talks
@@ -36,6 +43,34 @@ sub handler {
$template->process("talk/proceedings");
}
+
+#
+# text_summary()
+# ------------
+sub text_summary {
+ my ($text, $limit) = @_;
+
+ # extract the first paragraph
+ my $para = substr($text, 0, index($text, "\n"));
+
+ # if it's still too long, extract as many phrases as possible,
+ # while keeping below $limit characters
+ if (length($para) > $limit) {
+ my @chunks = split /([.?!] +|[.?!]\z)/, $para;
+ my $str = "";
+
+ while (@chunks and (length($str) + length($chunks[0])) < $limit) {
+ $str .= shift @chunks;
+ $str .= shift @chunks;
+ }
+
+ $para = "$str [...]";
+ }
+
+ return $para
+}
+
+
1;
__END__

0 comments on commit 27ad703

Please sign in to comment.