Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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.

In reply to Re: natural language sentence construction by dimmesdale
in thread natural language sentence construction by thpfft

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-03-28 23:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found