CardWorld version 2, August 2012 – Author: James A. Mason
Like CardWorld1, CardWorld2 illustrates use of ASDParser with an ASD grammar (Cardgram2.grm) to implement an application that understands English in limited ways. It extends the original CardWorld by permitting the user to refer to cards by their permanent properties: ranks (Ace, 2, 3, ... , 10, Jack, Queen, King), suits (Clubs, Diamonds, Hearts, Spades), colors (red or black), and standings (spot, face, or Joker). It also allows pointing to and deictic reference to more than one card or pile per command. These notes deal with the extensions from CardWorld1a to CardWorld 2. See the earlier documentation of CardWorld1 for other details of how CardWorld1 and CardWorld2 work.
Actions: Commands can request the agent to shuffle, spread out, or stack (or pile) up cards and piles of cards, or to turn cards or piles of cards face up, face down or over, optionally at a place that has been pointed to. A command can also be to put a card or cards or a pile or piles at a place that has been pointed to.
References to objects: Individual cards and piles of cards can be referred to
by clicking on them with a mouse (or other pointing device) and using deictic determiners or pronouns in the noun phrase of the command: “this”, “that”, “these”, “those”, “it”, “them”, or the definite determiner “the”;
by using anaphoric determiners or pronouns – the same as the deictic ones or definite ones but without pointing – to refer to a card or pile(s) most recently attended to (Note: The object(s) most recently attended to may not necessarily have been referred to explicitly in an utterance. A pile referred to anaphorically by "it" could, for example, be the result of stacking two or more piles having just been stacked together by the Card Agent.
by using quantified definite reference in various ways:
with the unique quantifier determiner “the” (without pointing) and the noun “pile” (i.e., the noun phrase “the pile”) to refer to the only pile of two or more cards on the card table top, assuming there is only one such pile.
with the unique quantifier determiner “the” (without pointing) with the noun “card” (i.e., “the card”) to refer to the only card which is not in a pile with other cards, assuming there is only one such card.
by using a universal quantifier “all”, “each” or “every”. “All” can be modified further with adverbs “separately” or “together”. “Each” and “every” imply “separately”, but “separately” can also be used explicitly with them.
[Extension for CardWorld2:] by using descriptive adjectives or nouns, along with one of the means of reference listed above. The adjectives used can describe a card's suit ("club(s)", "diamond(s)", "heart(s)", or "spade(s)"), rank ("ace(2)", "two(s)" or "2(s)", ... , "ten(s)" or "10s", "jack(s)", "queen(s)", or "king(s)"), color ("black" or "red"), or standing ("face", "spot", or "joker").
References to places: A place on the "card table" surface can be referred to by clicking on the green surface, or on a card image (which also indicates the card or its pile), and using a deictic adverb "here" or "there". A place can also be referred to anaphorically, by using "there" (without pointing) to refer to the last place that was referred to.
Notice that it is a non-trivial task to resolve references to objects, because pointing to a card may involve reference to the card or to its pile, and because direct manipulation permits piles to be changed between input sentences. Also, it is not trivial to resolve references to places, because pointing to a card may also involve pointing to the place where it lies. In addition, when a deictic reference to the cards in a pile is combined with descriptive adjectives, it refers only to the cards that match the description.
The syntax of commands understood by the card agent is specified by the ASD grammar Cardgram2.grm . (Cardgram2.grm is all in a single grammar module, but it can be viewed in two screens, using ASDEditor, by viewing the singleton nodes separately from the non-singleton nodes.) A command may consist of one clause or of two clauses conjoined by “and”. The vocabulary of words recognized by the card agent is as listed here, where NUMBER is the token used by ASDParser to match any "word" which is a string of digits:
10s, 2s, 3s, 4s, 5s, 6s, 7s, 8s, 9s, ace, aces, all, also, and, black, card, cards, club, clubs, diamond, diamonds, down, each, eight, eights, every, face, five, fives, four, fours, heart, hearts, here, it, jack, jacks, joker, jokers, king, kings, next, nine, nines, now, NUMBER, of, one, out, over, pile, piles, put, queen, queens, red, separately, seven, sevens, shuffle, six, sixes, spade, spades, spot, spread, stack, stacks, ten, tens, that, the, them, then, there, these, this, those, three, threes, together, turn, too, two, twos, up
Of course, only the NUMBERs 2 through 10 are accepted as rank descriptions in CardWorld2.
Examples of valid commands are:
As in CardWorld1:
shuffle the cards
spread them out face down
turn this pile over and stack it here [with pointing to a pile and a place]
now turn each of the piles face up
shuffle each pile and stack it separately face down
shuffle the piles and stack them together here [with pointing to a place]
turn every card over and spread them all out together
turn over this card [with pointing to a card]
spread out this pile [with pointing to a card in a pile]
turn down each of the piles
shuffle all the cards and spread them out face up here [with pointing to a place]
[move a card away from the pile] stack the pile here
Extensions for CardWorld2:
[point to two or more cards] turn over those cards
[point to two or more piles] stack each of those piles
[move several cards to form a new pile] spread out those cards
turn over the kings
turn the ace of spades face down
turn over the diamonds
turn over the heart face cards
turn all the black cards over and also pile them here [pointing to a place]
stack all of the diamond cards here [pointing to a place]
spread out the red face cards there [pointing to a place]
turn over those kings [referring anaphorically to the pile last attended to]
shuffle the black spot cards together and spread them out here face up
[pointing to a place]
put the red aces here face up [pointing to a place]
[point to a pile containing a single joker among other cards] turn over that joker
[point to a pile containing some 10s among other cards] turn over those tens
The implementation consists mainly of the following Java classes
CardWorld – the driver class
Card, AbstractPlayingCard, and PlayingCard – to represent the cards
CardGroup, CardPile, and PlayingCardDeck – to represent collections of cards
CardTable – to represent the table top and the positions of the cards and piles on it. CardTable has been modified slightly from the version in CardWorld for CardWorld 2, to permit CardAgent2 more easily to determine which piles contain specified cards, where several of the cards may belong to the same pile.
CardAgent2, CardAgent2Effectors, and Cardgram2Semantics – to represent the card agent, its abilities to operate on the card table, and its ability to understand commands in English related to the Card World. Note: Cardgram2Semantics contains all of the functions that implement semantic action and semantic value fields in Cardgrm1.grm.
CardWorldFrame2 – to implement the window interface between the Card World and the user.
[Extension for CardWorld2:] AbstractPlayingCardIdea – to represent a possibly incomplete description of a playing card, such as "red ace" or "club face card"
Due to subtleties in the semantics of English, the logic for finding the referent(s) of a noun phrase is the most complicated part of the implementation. That logic is expressed mainly in the instance functions with names beginning findReferents... in the class CardAgent2. As in the implementation of CardWorld1a, the findReferents function uses a decision network (file CardDecisionNet2.grm – the result of merging two component decision networks, CardDecisionNet2a.grm and CardDecisionNet2b.grm) which selects one of the following sixteen different referent types depending on the values of the twenty different syntactic, semantic, and pragmatic decision variables enumerated below.
CardAgent2 extends the referent-finding logic of CardAgent1a in several ways. In doing so, it uses two new methods, listCardsInPiles and listPilesContainingCards, to shift its attention from piles to cards (wholes to parts) and from cards to piles (parts to wholes). After CardAgent2 finds an appropriate referent type and applies it to the current situation to select a candidate collection of cards or piles being referred to, deictically, anaphorically, or quantified, then CardAgent2 invokes one of its methods isConsistentWith... of AbstractPlayingCardIdea to determine which of the cards among the candidate cards or in the candidate piles are consistent with the instance of AbstractPlayingCardIdea that describes the card(s) being referred to.
[The abbreviations Dx, Qx and Ax are used in comments to label appropriate parts of the source code in CardWorld2 (class CardAgent2, the functions findReferents...). They are also used to label final nodes in the decision networks CardDecisionNet2a.grm and CardDecisionNet2b.grm.], which have been revised a bit from the decision networks used in CardWorld1a.
Deictic (i.e., with pointing):
D1. the (possibly described) card most recently pointed to or moved (e.g. "that card" or "that queen")
D2. the single pile containing the card(s) most recently attended to (e.g. "that pile")
D3. each (possibly described) card in the pile containing the card most recently attended to (e.g. "each of those cards", "each of those red kings")
D4. all of the (possibly described) cards in the pile containing the card most recently attended to (e.g. "all those cards", "all of those black face cards")
D5. the two or more piles containing the two or more cards most recently attended to (e.g. "those piles")
Quantified, universally or uniquely (i.e., all instances of or unique instances of a type):
Q1. each (possibly described) card on the table separately (e.g. "each card", "each of the red cards", "every card", "every jack")
Q2. all of the (possibly described) cards on the table together (e.g. "all [together]", "[all] [of] the [red spot] cards")
Q3. each pile on the table separately (e.g. "each [pile] [separately]", "every pile", "each of the piles", "all [of] the piles [separately]")
Q4. all of the piles on the table together (e.g. "all [of] the piles together")
Q5. the only card that the command would sensibly refer to (e.g. "the card" when there is only one card by itself, the others being in multi-card piles)
Q6. the only pile that the command would sensibly refer to (e.g. "shuffle it" or "turn the pile over" when there is only one pile containing more than one card, or "turn it over" when there is only one pile on the table, or "turn them over" when all of the cards on the table are in a single pile)
Anaphoric (i.e., backward reference without further pointing):
A1. the last card referred to (e.g. "it", or "that [card]" without pointing)
A2. the last pile referred to (e.g. "it", or "that [pile]" without pointing)
A3. the last cards referred to, separately ("them", "those [cards] [separately]")
A4. the last piles referred to, separately ("them", "those [piles] [separately]")
A5. the last cards referred to, together ("them", "those [cards] [together]")
A6. the last piles referred to, together ("them", "those [piles] [together]")
Some of these are used in the decision networks CardDecisionNet2a.grm and CardDecisionNet2b.grm; others are incorporated into the logic of the findReferents... methods of CardAgent2.
?1. Is the current clause the first in its sentence?
?2. Has a card been pointed to since the last sentence?
?3. Has the explicit type "card" been used in the current clause?
?4. Has the explicit type "pile" been used in the current clause?
?5. Was the previous type unexpressed, "card", or "pile"?
?6. Is the noun or pronoun in the current clause singular or plural?
?7. Is the quantity of referents expressed in the current clause one or more than one?
?8. Is a deictic pronoun or determiner ("this", "that", "these", or "those") used in the current clause? [Note: Those words may also be used anaphorically, or even as unique quantifiers.]
?9. Is an anaphoric pronoun ("it", "them") used in the current clause? [Note: Those words may also be used deictically, or even as unique quantifiers.]
?10. Has "each", "every", or "separately" been used in the current clause?
?11. Has the adverb "together" been used in the current clause?
?12. Has separate aggregation (originally expressed by "each", "every", or "separately") continued to be used in the most recent preceding clause?
?13. Can the verb in the current command apply to single cards or only to collections of two or more cards?
?14. Was there a single last card referred to before this clause?
?15. Was there a single last pile referred to before this clause?
?16. Were there two or more piles referred to before this clause?
?17. Was the last operation performed on all CARDS on the table (as opposed to all of the piles, or just some of the cards)?
?18. Is there only one pile on the table?
?19. Is there only one multi-card pile on the table?
?20. Is there only one singleton card on the table?
See FurtherNotesAboutCardWorld for more details.
last updated 2012