Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Perl and Morphology

by ChOas (Curate)
on Mar 14, 2002 at 11:27 UTC ( #151647=note: print w/ replies, xml ) Need Help??


in reply to Perl and Morphology


Think this might be a start ? .. only tested on your data: ;))

#!/usr/bin/perl -w use strict; sub FindRoot; my %Word=map {chomp;split /,/} <>; for (keys %Word) { print "Word: $_, etc: $Word{$_}\n"; }; my $Root=FindRoot("Longest",keys %Word); my @Words=map {split} (values %Word); my $Word=FindRoot("Shortest",@Words); print "\n---\n$Root:$Word\n"; for (keys %Word) { print "-",substr($_,length$Root),":"; print "",substr($Word{$_},0,rindex($Word{$_},$Word)),"\n"; }; sub FindRoot { my $Order=shift; my %Container; my $Min="xxxxxxxxxxxxxxx"; print "Finding $Order\n"; if ($Order eq "Shortest") { $Min=""; $Min=((length $_)>(length $Min))?$_:$Min for (@_); } else { $Min=((length $_)<(length $Min))?$_:$Min for (@_); }; for my $Word (@_) { $Container{substr lc $Word,0,$_}++ for(2..length $Min); }; my $Root=""; $Min=0; my @List=sort keys %Container; @List=reverse@List if ($Order eq "Longest"); print "List: @List\n"; for (@List) { if ($Container{$_}>$Min) { $Root=$_; $Min=$Container{$_}; }; }; return $Root; };

It`s probably not the cleanest code, but it was fun to do, so
I thought I`d post it :)))
I figure you can use this as a start to really solve your
problem, it shouldn`t be too hard to once you got the Root,
take the substring out of the hash, and start looking for the next
one (using that FindRoot sub) which would give you `lar` ,
making the next root `BasLar` ...

Hmmmmm... actually I think I got that to work here...
Looking forward to more test-data :))

GreetZ!,
    ChOas

print "profeth still\n" if /bird|devil/;


Comment on Re: Perl and Morphology
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://151647]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2014-09-02 03:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (18 votes), past polls