duplicates

J

julia_2683

I would like to find and delete duplicates to reduce the number of
entries I have for each word. Need your help to achieve that.
Input
dog -> doggy
dog -> dogs
want -> wants
want -> wanting
want -> wanted
eat -> eaten
eat -> eating
eat -> eated
output
dog -> doggy dogs
want -> wants wanting wanted.

Thanks
 
P

Paul Lalli

I would like to find and delete duplicates to reduce the number of
entries I have for each word. Need your help to achieve that.
Input
dog -> doggy
dog -> dogs
want -> wants
want -> wanting
want -> wanted
eat -> eaten
eat -> eating
eat -> eated
output
dog -> doggy dogs
want -> wants wanting wanted.

What have you tried so far? How did it not meet your expectations?
From where does this data come, and in what structure do you have it
stored? Have you searched the FAQ?

$ perldoc -q duplicate
Found in /opt2/Perl5_8_4/lib/perl5/5.8.4/pod/perlfaq4.pod
How can I remove duplicate elements from a list or array?


Paul Lalli
 
B

Billy N. Patton

I would like to find and delete duplicates to reduce the number of
entries I have for each word. Need your help to achieve that.
Input
dog -> doggy
dog -> dogs
want -> wants
want -> wanting
want -> wanted
eat -> eaten
eat -> eating
eat -> eated
output
dog -> doggy dogs
want -> wants wanting wanted.

Thanks
put into a hash
if exists
$hash{dog} .= " dogs";
 
U

usenet

I would like to find and delete duplicates to reduce the number of
entries I have for each word. Need your help to achieve that.

How about this:

#!/usr/bin/perl

use strict;
use warnings;

my %word;
while (<DATA>) {
chomp;
my ($word1, $word2) = split (/ -> /, $_);
push @{$word{$word1}}, $word2;
}
print($_," -> ",join(" ",@{$word{$_}}),"\n") for keys %word;

__DATA__
dog -> doggy
dog -> dogs
want -> wants
want -> wanting
want -> wanted
eat -> eaten
eat -> eating
eat -> eated

OUTPUT
eat -> eaten eating eated
want -> wants wanting wanted
dog -> doggy dogs


eated???
 
J

jeevs

How about this:

#!/usr/bin/perl

use strict;
use warnings;

my %word;
while (<DATA>) {
chomp;
my ($word1, $word2) = split (/ -> /, $_);
push @{$word{$word1}}, $word2;
}
print($_," -> ",join(" ",@{$word{$_}}),"\n") for keys %word;

__DATA__
dog -> doggy
dog -> dogs
want -> wants
want -> wanting
want -> wanted
eat -> eaten
eat -> eating
eat -> eated

OUTPUT
eat -> eaten eating eated
want -> wants wanting wanted
dog -> doggy dogs


eated???


Hi David .. Sorry but i dint follow the syntax you used

like you used

push (@{$hash{$key}}, $value);

How does this work.. I mean i can understand when one uses @{$arr_ref}
to derefenciate an array ref.
but what does @{$hash{$key}} stands for... IF you can point me to some
data or link that will be fine too...
 
P

Paul Lalli

Hi David .. Sorry but i dint follow the syntax you used

like you used

push (@{$hash{$key}}, $value);

How does this work.. I mean i can understand when one uses @{$arr_ref}
to derefenciate an array ref.
but what does @{$hash{$key}} stands for...

It's exactly the same thing - @{REF} dereferences the array reference
REF. In @{$arr_ref}, $arr_ref is the array reference. In
@{$hash{$key}}, $hash{$key} is the array reference. That is, the
value of %hash whose key is $key is a reference to an array. Hashes
and arrays can store *any* kind of scalar variable - integers, floats,
strings, and references too.
IF you can point me to some
data or link that will be fine too...

perldoc perllol
perldoc perldsc

Paul Lalli
 
T

Tad McClellan

jeevs said:
Sorry but i dint follow the syntax you used

like you used

push (@{$hash{$key}}, $value);

How does this work.. I mean i can understand when one uses @{$arr_ref}
to derefenciate an array ref.
but what does @{$hash{$key}} stands for...


It stands for the same thing, only the array ref is stored
in $hash{$key} rather than in $arr_ref.

IF you can point me to some
data or link that will be fine too...


perldoc perlreftut
 
M

Michele Dondi

push (@{$hash{$key}}, $value);

How does this work.. I mean i can understand when one uses @{$arr_ref}
to derefenciate an array ref.
but what does @{$hash{$key}} stands for... IF you can point me to some

It's the same as

my $arr_ref=$hash{$key};
push @{$arr_ref}, $value;
data or link that will be fine too...

perldoc perlref

is the starting point.


Michele
 
U

usenet

Hi David .. Sorry but i dint follow the syntax you used
like you used

push (@{$hash{$key}}, $value);

How does this work.. I mean i can understand when one uses @{$arr_ref}
to derefenciate an array ref.
but what does @{$hash{$key}} stands for...

$hash{$key} has a value, which must (if defined) be a scalar. In this
case, the scalar value is an array reference, so we are creating a
hash of arrays (HoA), or, more specifically (and correctly), a hash of
array references.

perldoc perlreftut
perldoc perlref
 
B

Bart Lateur

I would like to find and delete duplicates to reduce the number of
entries I have for each word. Need your help to achieve that.
Input
dog -> doggy
dog -> dogs
want -> wants
want -> wanting
want -> wanted
eat -> eaten
eat -> eating
eat -> eated
output
dog -> doggy dogs
want -> wants wanting wanted.

What you appear to be after, is finding the stem of words. I believe the
author of the search engine index module KinoSearch, Marvin Humphrey AKA
creamygoodness, also supports a stemmer module on CPAN, which BTW gets
used by the indexer -- but you can use it independently, too.

Home page: http://www.rectangular.com/kinosearch/
CPAN page: http://search.cpan.org/dist/KinoSearch/

The basic stemmer module is Lingua::Stem::Snowball,
http://search.cpan.org/perldoc?Lingua::Stem::Snowball
 
M

Michele Dondi

I wasn't trying to be elitist. Some regulars on clpm frown on simply

I know. In fact I was "complaining" you weren't. The rationale being
that clpmisc regulars do not give fishes, period! ;-)
My apologies if I offended anybody.

No, you didn't!


Michele
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top