Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: natural language sentence construction

by dimmesdale (Friar)
on Jun 17, 2001 at 20:10 UTC ( #89175=note: print w/replies, xml ) Need Help??

in reply to natural language sentence construction

My view about feasibility is near impossible. Well, depending on what you want to do. Parsing natural language and attempting to make it more "friendly" to your users is (a)highly unique to your particular application, and (b)requires many, *many*, special case situations. There is a CPAN module for making a word its plural, and that can be useful. . . but as for parsing an english sentence, that is near impossible with current technology--if only for the reason that language is abigous, even to native speakers at times(how often do people ask others to repeat what they said?). There was a node on this a short time ago, I believe, when someone asked if there was a module for grammar checking: called English/Grammer or something similar if I remember. As for helping you with your code, there is one area where I see it could be made clearer:
foreach my $i (0..$#$types) { if ($i && $i == $#$types) { $sentence .= ($matches > 1) ? ' and ' : ' or '; } elsif ($i) { $sentence .= ', '; }
This can be written more clearer(I hope) as:
for(@$types) { if($_ eq $types->[-1]) { $sentence .= $matches>1 ? ' and ' : ' or ' } else { $sentence .= ', ' }
Maybe it's just me, but it took a couple looks to see why you were doing what you were doing. This way, hopefully, the -1 signifies that you're checking it against the last element. But, there's more than one way to do it.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://89175]
and God said, "Let Newton be!"...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2017-08-19 08:37 GMT
Find Nodes?
    Voting Booth?
    Who is your favorite scientist and why?

    Results (310 votes). Check out past polls.