syntactic / JSGFTools

Some tools for JSGF grammar expansion. Generate sentences from a JSGF Grammar. I originally wrote this over the course of a week, so I settled for many simple but inefficient solutions in many areas. When I have some time I will go back and work on improving the efficiency.
MIT License
16 stars 12 forks source link

Question mark at the end of the sentence crashes DeterministicGenerator.py #1

Closed awesomebytes closed 6 years ago

awesomebytes commented 7 years ago

Given a grammar that has some question mark at the end of a sentence it crashes with:

Traceback (most recent call last):
  File "DeterministicGenerator.py", line 129, in <module>
    expansions = processRHS(rule.rhs)
  File "DeterministicGenerator.py", line 114, in processRHS
    return processSequence(rhs)
  File "DeterministicGenerator.py", line 68, in processSequence
    componentSets.append(processRHS(component))
  File "DeterministicGenerator.py", line 116, in processRHS
    return processDisjunction(rhs)
  File "DeterministicGenerator.py", line 90, in processDisjunction
    disjunctExpansions.extend(processRHS(disjunct))
  File "DeterministicGenerator.py", line 120, in processRHS
    return processNonTerminal(rhs)
  File "DeterministicGenerator.py", line 76, in processNonTerminal
    return processRHS(grammar.getRHS(nt))
  File "/home/sam/magiclab/sentences_generator/JSGFTools/JSGFGrammar.py", line 153, in getRHS
    raise ValueError("Rule not defined for " + str(nt))
ValueError: Rule not defined for <objq0>

A minimal example of crashing grammar:

#JSGF V1.0;

grammar crashtest;

<crashconcept> = will this crash?;

public <command> = <crashconcept>;  

And my bigger crashing grammar:

#JSGF V1.0;

grammar objectsquestions;

<aobject>=Cloth|Paper|Sponge|Towel|Bag|Basket|Coffeecup|Plate|Red bowl|White bowl|Fork|Spoon|Knife|Banana milk|Cappucino|Coke|Orange drink|Water|Bread|Cornflakes|Crackers|Cereals|Noodles|Paprika|Peas|Pepper|Potato|Potato soup|Tomato pasta|Salt|Apple|Lemon|Pear|Egg|Chocolate cookies|Party cracker|Pringles;

<gesture>=waving|rising left arm|rising right arm|pointing left|pointing right;

<beacon>=dinner table|Sofa|Desk|Bar|TV|Bed;

<object>=Cloth|Paper|Sponge|Towel|Bag|Basket|Coffeecup|Plate|Red bowl|White bowl|Fork|Spoon|Knife|Banana milk|Cappucino|Coke|Orange drink|Water|Bread|Cornflakes|Crackers|Cereals|Noodles|Paprika|Peas|Pepper|Potato|Potato soup|Tomato pasta|Salt|Apple|Lemon|Pear|Egg|Chocolate cookies|Party cracker|Pringles;

<location>=dinner table|cabinet|bookshelf|Sofa|Couch table|Kitchencounter|Side table|Stove|Desk|Bar|TV|Bed|Closet;

<male>=Noah|Liam|Mason|Jacob|William|Ethan|James|Alexander|Michael|Benjamin;

<room>=dining room|living room|kitchen|bedroom;

<category>=Cleaning stuff|Container|Cutlery|Drink|Food|Fruit|Snack;

<question>=What city are we in?|What is the name of your team?|Name the big hairy creature in Star Wars.|Who wrote the three laws of robotics?|From what series do you know Rosie the robot?|From what series do you know the baby Bam Bam?|Who is the main character of The Matrix?|Name the two RoboCup@Home standard platforms.|Where do you store your memories?|Where is your team located?;

<placement>=dinner table|cabinet|bookshelf|Couch table|Kitchencounter|Side table|Stove|Desk|Bar|Closet;

<female>=Emma|Olivia|Sophia|Ava|Isabella|Mia|Abigail|Emily|Charlotte|Harper;

<kobject>=Cloth|Paper|Sponge|Towel|Bag|Basket|Coffeecup|Plate|Red bowl|White bowl|Fork|Spoon|Knife|Banana milk|Cappucino|Coke|Orange drink|Water|Bread|Cornflakes|Crackers|Cereals|Noodles|Paprika|Peas|Pepper|Potato|Potato soup|Tomato pasta|Salt|Apple|Lemon|Pear|Egg|Chocolate cookies|Party cracker|Pringles;

<name>=Emma|Olivia|Sophia|Ava|Isabella|Mia|Abigail|Emily|Charlotte|Harper|Noah|Liam|Mason|Jacob|William|Ethan|James|Alexander|Michael|Benjamin;

<objq0> = Where can I find a <object> ?;
<objq1> = How many <category> there are?;
<objq2> = What's the colour of the <kobject>?;
<objq3> = How many (<category> | objects) are in the <placement>?;
<objq4> = What objects are stored in the <placement>?;
<objq5> = Where can I find a (<object> | <category>)?;
<objq6> = To which category belong the <object>?;
<objq7> = Do the {object 1} and {object 2} belong to the same category?;
<objq8> = Which is the <adja> (<category> | object)?;
<objq9> = Between the {object 1} and {object 2}, which one is <adjr>?;
<adja> =  (heaviest | smallest | biggest | lightest);
<adjr> =  (heavier | smaller | bigger | lighter);
public <command> = <objq0>| <objq1> |<objq2>|<objq3>|<objq4>|<objq5>|<objq6>|<objq7>|<objq8>|<objq9>;