Skip to content

split words on dots #29

@Lamprecht

Description

@Lamprecht

This SO post raised a question about words with embedded periods not being split. Here the behavior was undesired. I examined and found, that Pod::Wordlist leaves dots in place to account for abbreviations which are returned untouched and can be fed to the spellchecker. However aspell makes no difference between 'e.g.' and 'e g' (both passing) or 'Ph.D.' and 'Ph D' (both failing).

So is this really needed?

The possibility to add a stopword like 'html' guarding all sorts of 'passing_aspell.html' occurences in the text (example in SO posting) seems more useful to me.

Subject: [PATCH] split on dots

---
 lib/Pod/Wordlist.pm | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/lib/Pod/Wordlist.pm b/lib/Pod/Wordlist.pm
index 68fa6a5..2624a7f 100644
--- a/lib/Pod/Wordlist.pm
+++ b/lib/Pod/Wordlist.pm
@@ -158,19 +158,15 @@ sub _strip_a_word {
 	if ($self->is_stopword($word) ) {
 		$remainder = '';
 	}
-	# internal period could be abbreviations, so check with
-	# trailing period restored and drop or keep on that basis
-	elsif ( index($word, '.') >= 0 ) {
-		my $abbr = "$word.";
-		$remainder = $self->is_stopword($abbr) ? '' : $abbr;
-	}
-	# check individual parts of hyphenated word, keep whatever isn't a
-	# stopword as individual words
-	elsif ( index($word, '-') >= 0 ) {
+	# check individual parts of hyphenated or period separated word,
+	# keep whatever isn't a stopword as individual words
+	# aspell will accept split words for abbreviations as well
+	# 'e.g' passes like 'e g' does; 'Ph.D.' does not pass as 'Ph D' does not
+	elsif ( $word =~ /-|\./ ) {
 		my @keep;
-		for my $part ( split /-/, $word ) {
+		for my $part ( split /-|\./, $word ) {
 			push @keep, $part if ! $self->is_stopword( $part );
-		}
+	       	}
 		$remainder = join(" ", @keep) if @keep;
 	}
 	# otherwise, we just keep it
-- 
2.25.1


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions