CIT 591 Assignment 5: Lojban
Fall 2013, David Matuszek

Purposes of this assignment

General idea of the assignment

Lojban is an artificial human language, based on predicate logic and designed to be syntactically unambiguous. It is an "open source" version of an earlier copyrighted (!) language, called Loglan. This assignment is based on a Loglan assignment I found on the web (Loglan--A Logical Language), and may not be entirely accurate for modern Lojban.

This assignment uses a small subset of the rules of the language, and is in two parts:

Details

Sentence components

Sentence grammar

Word Definition
Sentence
is a
Statement or a Predclaim
Predclaim
is a
Predname BA Preds or a DA Preds
Preds
is a
Predstring or a Preds A Predstring
Predname
is a
LA Predstring or a NAME
Predstring
is a
PRED or a Predstring PRED
Statement
is a
Predname Verbpred Predname or a Predname Verbpred
Verbpred
is a
MOD Predstring
A
is
"a" or "e" or "i" or "o" or "u"
MOD
is
"ga" or "ge" or "gi" or "go" or "gu"
BA
is
"ba" or "be" or "bi" or "bo" or "bu"
DA
is
"da" or "de" or "di" or "do" or "du"
LA
is
"la" or "le" or "li" or "lo" or "lu"
NAME
is
Any name (ends in a consonant)
PRED
is
Any predicate (CCVCV or CVCCV)

Detailed specification

Implement three objects: Lojban, SentenceGenerator, and SentenceRecognizer.

Lojban should have a main method which will allow you to "converse" with the program (of course, you will both be speaking nonsense, but who's to know?). It should begin by printing "coi." ("Hello"). After that you and the computer take turns speaking "Lojban" to each other. When you enter something that isn't a proper Lojban sentence, the program should respond "i mi na jimpe." ("I don't understand"). To end the program, enter the sentence "co'o." ("Goodbye"). Note: These words and phrases are not in the subset of Lojban described by the above rules, but that's okay.

SentenceGenerator should have the following methods (along with any others you may choose to write): makeSentence, makePredclaim, makePreds, makePredname, makePredstring, makeStatement, makeVerbpred, makeA, makeMOD, makeBA, makeDA, makeLA, makeNAME, and makePRED. Each of these will take no arguments, and will return a random string of the correct Lojban type. The strings returned by makeSentence should not end with a period.

SentenceRecognizer should have the following methods (along with any others you may choose to write): isSentence, isPredclaim, isPreds, isPredname, isPredstring, isStatement, isVerbpred, isA, isMOD, isBA, isDA, isLA, isNAME, and isPRED. Each of these will take one string argument, and return true if the string is of the correct type. The isSentence predicate should accept correctly formed sentences, whether or not they end in a period (that is, ignore the period, if present).

Recognizing sentences is somewhat more challenging than generating them.

You may, of course, have any additional methods, especially if it helps you to avoid writing similar code over and over.

Because some of you seem to be addicted to the return statement, even when it is totally unnecessary, I am banning its use for this assignment.

Getting started with Eclipse

  1. Start Eclipse (in a terminal window, enter scala-ide).
  2. In the upper-right corner there is a list of "Perspectives." Make sure "Scala" is selected.
  3. Go to File → New → Scala Project, enter Lojban as the project name, and click Finish.
  4. Make sure Lojban is selected in the Package Explorer tab.
  5. Go to File → New → Package. You should get a dialog that shows Lojban/src as the Source folder. Enter lojban (all lower case) as the package name. Click Finish.
  6. With the lojban package selected in the Package Explorer, go to File → New → Scala Object and enter Lojban as the object name. Also select public static void main(String[] args). Click Finish.
  7. Create the other two objects (SentenceGenerator and SentenceRecognizer) in the same way (make sure they are in the lojban package), but without main methods.
  8. Click on the Lojban.scala tab, and in the editor window, add the line println("coi.") to your main method.
  9. To run your program for the first time, make sure Lojban.scala is selected in the Package Explorer, then choose Run → Run As → Scala Application.
  10. Later on, you can run your program the same way, or by clicking the White triangle inside a green disk symbol in the task bar.

Testing

We haven't had a chance yet to talk about Scalatest, but here are some (hopefully enough!) of the essentials.

Scalatest does not come with the Scala IDE, and is not installed in the lab. You can get it from http://www.scalatest.org/download. Scroll down and click Download ScalaTest 1.9.2 Jar. Save the jar file anyplace that you can easily find it again.

In Eclipse, go to Project → Properties → Java Build Path → Libraries. Unless it's already there, add scalatest_2.10-1.9.2.jar as an external JAR. (You will have to do this again for each new project.)

Here is a very brief example of a test file (test is a method; you can add more calls to it). You should be able to run this by selecting Run → Run As → Scala Test - File.

package lojban

import org.scalatest.FunSuite
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner

@RunWith(classOf[JUnitRunner])
class SentenceRecognizerTest extends FunSuite {

  test("Recognize MOD") {
    for (word <- List("ga", "ge", "gi", "go", "gu")) {
      assert(SentenceRecognizer.isMOD(word))
    } 
    assert(! SentenceRecognizer.isMOD("gb"))
    assert(! SentenceRecognizer.isMOD("ba"))
    assert(! SentenceRecognizer.isMOD("gat"))
  }
}

Due date

Submit your team's program, as a single .zip file, to Canvas by 6am next Friday, October 4. Decide which of you is going to turn in the assignment, and make only one submission for the two of you. Make sure both of your names are in comments at the top of each file.