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:
' '
), tabs ('\t'
), and newlines ('\n'
).'a'
, 'e'
, 'i'
, 'o'
, and 'u'
.'y'
is a consonant.'h'
, 'q'
, and 'w'
are not used in Lojban."ssabe"
is not a word). 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) |
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.
Lojban
as the project name, and click Finish.lojban
(all lower case) as the package name. Click Finish.Lojban
as the object name. Also select SentenceGenerator
and SentenceRecognizer
) in the same way (make sure they are in the lojban package), but without main
methods.println("coi.")
to your main
method.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")) } }
.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.