Thanks for all of your useful comments ppl

Here is my basic code (very un-commented at present) and not very elagent.

It doesnt do anything with the 'attributes' yet.. this will be looking up in the database (finding objects of class=Attribute name={value})

Please dont hold back and rip apart/suggest/improve where applicable.

$qtys{'the'}=0; $qtys{'some'}=20; $qtys{'bunch'}=30; $qtys{'pile'}=40; $qtys{'many'}=50; $qtys{'heaps'}=100; $qtys{'heap'}=100; print &parse_obj('a small white fluffy cat called sam'); print &parse_obj('a pile of sticks made of wood'); print &parse_obj('an old orange'); print &parse_obj('the broken golden cup of plenty'); print &parse_obj('a player called bob'); print &parse_obj('3 blind mice'); print &parse_obj('a piece of old triangular wooden boat called fred'); print &parse_obj('a kind of mouse'); print &parse_obj('some roses'); sub parse_obj { my $this_obj = $_[0]; if($this_obj =~ /(.+) made of (.+)/i) { $this_obj = $1; $material=$2; }else{ } $this_obj =~ /(\w+)\s?(.+)/; my $qty = $1; my $rest = $2; my $pre=''; my $class=''; my $name = ''; my $qty_type=''; my $attribs=''; my $material=''; if($qty =~ /the/i) { # handle special named one off objects 'the void' 'the sword of ligh +t' # check for specially typed objects.. if($rest =~ /(.+) of (.+)/i){ $pre=$1; $name='of '.$2; }else{ $pre=$rest; } }elsif($rest =~ /(.+) of (.+)/i){ $pre=$1; $class=$2; if($pre =~ /(.+) (.+)/){ $pre = $1; $qty_type=$2; }else{ $qty_type=$pre; $pre =''; } }else{ $pre=$rest; } $pre .= ' '.$class; if(($pre =~ /(.+) called (\w+)/)||($pre =~ /(.+) named (\w+)/)){ $pre = $1; $name = $2; $class=''; } if($pre =~ /(.+) (\w+)/){ $attribs=$1; $class=$2; }else{ if($name ne ''){ $class=$pre; $attribs=''; }else{ $class=$pre; } } if($qtys{$qty_type} ne ''){ # convert 'a pile of' into 'pile' = 30 $qty = $qtys{$qty_type}; $qty_type=''; } $qty=($qtys{$qty} eq '') ? 1 : $qtys{$qty}; return "\n-----------------\n>>$this_obj\n qty[$qty] size=[$size] typ +[$qty_type] att[$attribs] mat=[$material] class[$class] name[$name]\n +"; }
___ /\__\ "What is the world coming to?" \/__/ www.wolispace.com

In reply to Re: Re: Parsing english by wolis
in thread Parsing english by wolis

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.