Newsgroups: rec.arts.int-fiction
Subject: Re: [TADS] Adding 'her' as an adjective
From: gdighton@geocities.com (Garth Dighton)
References: <3bb3a22c$1_5@goliath2.newsgroups.com> <_owt7.13888$UE4.5731851@nnrp5-w.sbc.net> <_Zxt7.62682$L%5.41472162@news1.rdc1.sfba.home.com>
User-Agent: Xnews/03.04.11
X-no-productlinks: yes
Message-ID: <3bba1817_1@goliath2.newsgroups.com>
Date: 2 Oct 2001 14:40:07 -0500
Lines: 170
X-Authenticated-User: gdighton
X-Comments: This message was posted through Newsfeeds.com
X-Comments2: IMPORTANT: Newsfeeds.com does not condone, nor support,  spam or any illegal or copyrighted postings.
X-Comments3: IMPORTANT: Under NO circumstances will postings containing illegal or copyrighted material through this service be tolerated!!
X-Report: Please report illegal or inappropriate use to <abuse@newsfeeds.com> You may also use our online abuse reporting from: http://www.newsfeeds.com/abuseform.htm
X-Abuse-Info: Please be sure to forward a copy of ALL headers, INCLUDING the body (DO NOT SEND ATTACHMENTS)
Organization: Newsfeeds.com http://www.newsfeeds.com 73,000+ UNCENSORED Newsgroups.
Path: news.duke.edu!newsgate.duke.edu!nntp-out.monmouth.com!newspeer.monmouth.com!news.maxwell.syr.edu!feed2.uncensored-news.com!propagator!feed2.newsfeeds.com!newsfeeds.com!goliath2.newsgroups.com
Xref: news.duke.edu rec.arts.int-fiction:93103

I've taken Kevin's function, adding it together with Mike's suggestion of
checking the boxes location, plus a couple of other things. Here's the
result, which I post freely for anyone's use:

Again, thank you both, Mike and Kevin!


// parseNounPhrase function by Kevin Forchione and Mike Roberts, in
// response to a request made on rai-f.

// Modified to handle 'his' (though not 'my' or other possessives) by Garth
// Dighton. Also modified to check that the objects exist within a valid
// person (ideally the current 'her' or 'him').
parseNounPhrase: function(wordList, typeList, current_index,
                            complain_on_no_match, is_actor_check)
{
    local i, next_index, next_token, ret, lst = [];
	local pos = parserGetObj(PO_HER);
	local found = nil;
	local gender = &isHer;

    /* let the parser handle noun phrases that don't start with 'her' */
    if (wordList[current_index] != 'R'
    	    	and wordList[current_index] != 'his')
        return PNP_USE_DEFAULT;

	if (wordList[current_index] != 'R') {
		pos = parserGetObj(PO_HIM);
		gender = &isHim;
	}

    /*
     *  'her' is the last word of the noun phrase, so it is not
     *  being used as a possessive pronoun.
     */
    if (length(wordList) == current_index)
        return PNP_USE_DEFAULT;

    /* set the next_index */
    next_index = current_index + 1;

    /* get the next word's type */
    next_token = typeList[next_index];

    /*
     *  If the next word is an article then 'her' is not being used as a
     *  possessive pronoun.
     */
    if ((next_token & PRSTYP_ARTICLE) != 0)
        return PNP_USE_DEFAULT;
    /*
     *  If the next word cannot be an adjective, noun, or plural then
     *  'her' is not being used as a possessive pronoun.
     */
    if ((next_token & PRSTYP_ADJ) == 0
    && (next_token & PRSTYP_NOUN) == 0
    && (next_token & PRSTYP_PLURAL) == 0)
        return PNP_USE_DEFAULT;

    ret = parseNounList(wordList, typeList, next_index,
                       nil, nil, nil);

    /*
     *  We don't have a syntactically valid noun phrase, so assume
     *  that 'her' is not being used as a possessive pronoun.
     */
    if (ret == nil)
        return PNP_USE_DEFAULT;

    /*
     *  There are 2 cases to examine: no noun phrase or a syntactically
     *  valid noun phrase, but with no matching objects.
     */
    if (length(ret) == 1)
        /*
         *  No noun phrase. The first word isn't a noun, adjective,
         *  article, etc.
         */
        if (ret[1] == current_index)
            return PNP_USE_DEFAULT;
        else {
			goto noObjects;
        }

    /*
     *  We have a valid noun phrase, let's assume that 'her' is being
     *  used as a possessive. We'll restructure the return from
     *  parseNounList() so that it can be returned from
     *  parseNounPhrase().
     */
    lst += ret[1];

	/*	First we see if there are any objects within the current "her"
	 *	object. If so, we will return those possible objects only.
	 */
    for (i = 3; i <= length(ret[2]); i += 2) {
		if (not ret[2][i].isIn(pos)) continue;
        lst += ret[2][i];
		lst += ret[2][i+1];
		found = true;
	}

	/*   If there weren't any valid objects within 'her', check for
    	 *   objects within _any_ person of the right gender.
	 */
	if (not found) {
		for (i = 3; i < length(ret[2]); i += 2) {
			if (ret[2][i].location == nil
    	    	    	    	or not ret[2][i].location.(gender))
				continue;
			lst += ret[2][i];
			lst += ret[2][i+1];
			found = true;
		}
	}

	if (not found) goto noObjects;

	return lst;

// Note: moved this code down here because it's used twice.
noObjects:
	/*
	 *  Syntactically valid noun phrase with no matching objects!
	 */
	"I don't see any ";
	for (i = next_index; i <= length(wordList); ++i)
	{
		say(wordList[i]);
		" ";
	}
	"here. ";
	return PNP_ERROR;

}

parseDisambig: function(str, lst)
{
	local i, tot, cnt;
	local mystr = str;

	// Remove possessives (R, his, my, and words ending in 's) from the
    	// noun phrase before asking. This is particularly necessary in the
    	// case of R, because "Which R box do you mean..." is particularly
    	// annoying!

	local match = reSearch('R |his |my |%<%w*\'s%>', str);
	if (match) {
		// using length(str) for the length of the second substr will
		// guarantee that it goes to the end-of-string. A hack, but
    	    	// easier than calculating.
		mystr = substr(str, 1, match[1]-1) +
			substr(str, match[1]+match[2], length(str));

	}
	"Which << mystr >> do you mean, ";
	for (i = 1, cnt = length(lst) ; i <= cnt ; ++i)
	{
	   lst[i].thedesc;
	   if (i < cnt) ", ";
	   if (i + 1 == cnt) "or ";
	}
	"?";
}


-----=  Posted via Newsfeeds.Com, Uncensored Usenet News  =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
 Check out our new Unlimited Server. No Download or Time Limits!
-----==  Over 80,000 Newsgroups - 19 Different Servers!  ==-----
