Table of Contents

Goals

To create a simple grammar that can interpret common console commands in English.

It needs to be able to handle common operations such as move, edit, and delete.

Words

The grammar understands that while both larger_than and older_than specify a restriction on files, the former must be in terms of filesize and the latter a measure of time.

Additionally, it knows that “them” must only be used if files have previously been specified previously in the sentence.

It can handle common operations such as move, edit, and delete.

Verbs:

  • find
  • delete
  • move
  • edit

Since all sentences are commands given to the computer, the subject of the sentences is implicit.

Nouns

As this grammar is largely intended for file manipulatation, the only two nouns it understands are:

  • file/s
  • directory

“Extension”, while a noun in English, is not treated as such here, to prevent over-generalization (such as “Move the extension”). It is created as a new category which modifies a file.

Notes:Issues

This grammar has a problem with overproduction. In short, I could not figure out how to only allow strings which matched full sentences.

It determines if “them” is acceptable by only allowing it in a sentence following an “and”. It should also only allow it when “find” is found in the first part of the sentence, as “Delete the files and delete them does not make much sense”

Source

##### commandline.ccg #####
#
# A grammar for understanding file manipulation in English.
# Andrew Harp, April 2007
#
########## Features ##########
feature {
  case<2>: nom acc;
  num<2>: sg pl;
  pers<2>: non-3rd {1st 2nd} 3rd;
  tense<E>: past pres;
  sem-num<X>: sg-X pl-X;
  specifies<2>: nonspec spec;  

  ontology: sem-obj {
              phys-obj {
                animate-being {
                  person
                }
                thing
              }
              situation {
                change {
                  action
                }
                state
              }
            };
  measurement<2>:size date;

}

########### Words ############

def noun(Sing, Plur, Class) {
  word Sing:N(Class) {
    *: sg sg-X;
    Plur: pl pl-X;
  }
}

def verb(Non3rd, 3rd, TransIntrans) {
  word Non3rd: TransIntrans: pres non-3rd sg;
  word 3rd: TransIntrans: pres pl;
}

word this:Det: spec;

word the:Det;
word a:Det: sg;

word in:Prep;
word into:Prep;

word and:Conj;

word text:Adj;
word binary:Adj;

word parent:Adj;
word child:Adj;

word all:Quant;
word them:Ref;

word with:QualSpec;
word owner:QualCat;
word extension:QualCat;
word example:Quality;

word newer_than:Spec:date;
word older_than:Spec:date;

word larger_than:Spec:size;
word smaller_than:Spec:size;

word one:   Number;
word two:   Number;
word three: Number;
word four:  Number;
word five:  Number;
word six:   Number;
word seven: Number;
word eight: Number;
word nine:  Number;
word ten:   Number;

word day:Unit:date;
word week:Unit:date;
word month:Unit:date;
word year:Unit:date;

word KB:Unit:size;
word MB:Unit:size;

verb(list, lists, TransV)
verb(edit, edits, TransV)
verb(delete, deletes, TransV)
verb(copy, copies, TransV)
verb(rename, renames, TransV)
verb(move, moves, TransV)
verb(find, finds, TransV)

noun(directory, directories, thing)
noun(file, files, thing)

########### Rules ############

#### Lexicon/Categories ######
family IntransV(V) {
  entry: s<1> \ np<2> [nom];
}

family Number {
  entry: num;
}

family Unit {
  entry: quantity<2> \^ num<2>;
}

family Spec {
  entry: np<1> \^ np /^ quantity<2>;
}

# Refers to something previously declared ("them").
family Ref {
  entry: ref;
}

family QualSpec {
  entry: np<1> \^ np /^ qual;
}

family QualCat {
  entry: qual /^ qualval;
}

family Quality {
  entry: qualval;
}

family N {
  entry: n<2>[X]: X:sem-obj(*);
}

family Conj {
  entry: s / s2 \ s;
}

family Adj {
  entry: n /^ n;
}

family Prep {
  entry: pp /^ np; 
  entry: (np \^ np) /^ np;
  entry: (vp \^ np) /^ np;
}

family Quant {
  entry: np / np[num=pl];
}

family Det {
  entry: np<2>[X PERS=3rd] /^ n<2>[X]:
         X:sem-obj(<det>*);
}

family Pro {
  entry: np<2> [X]: X:sem-obj(*);
}

family TransV(V) {
  entry: s<1> [E] \ np<2> [X nom] / np<3> [Y acc];
  entry: s<1> / np<3> [Y acc];
  entry: s2 / ref;
}

########## Testbed ###########
testbed {
  edit a file: 1;
  delete all the files: 1;
  move all the files: 1;
  the files in this directory: 1;
  all the files in this directory: 1;
  move all the files in this directory: 1;
  move all the files in the parent directory: 1;
  move all the files in the child directories into the parent directory: 1;
  find all the files in this directory and delete them: 1;
  move all the files in this directory into the parent directory: 1;
  find the files with extension example: 1;
  delete all the files older_than one day: 1;
  delete all the file: 0;
  delete them and delete them: 0;
  find a files: 0;
  find a file larger_than one day: 0;
  find a file older_than one MB: 0;
  edit the file with extension file: 0;
}

 
openccg/grammars/commandline.txt · Last modified: 2007/04/26 06:27 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki