-
Notifications
You must be signed in to change notification settings - Fork 2
Replacing Orbital with AIMA in S Match
Aima (https://code.google.com/p/aima-java/) is a Java implementation of some AI algorithms.
We propose to replace Orbital with AIMA because:
-
It provides the same functionality of converting to CNF.
-
It is available in a public Maven repository.
- Remove the dependency on orbital-Core and orbital-ext.
- Add the AIMA dependency:
<dependency> <groupId>com.googlecode.aima-java</groupId> <artifactId>aima-core</artifactId> <version>0.10.5</version> </dependency>
- In the CNFContextClassifier class, we change these two lines in the toCNF() method from:
Formula f = (Formula) (cl.createExpression(tmpFormula)); Formula cnf = ClassicalLogic.Utilities.conjunctiveForm(f);
to
Sentence f = (Sentence) parser.parse(tmpFormula); Sentence cnf = transformer.transform(f);
- Change the input string (tmpFormula) from using &, | and ~ to use AND, OR and NOT. Then return them back after the transformation.
code for changing from (&, |, ~) to (AND, OR, NOT):
tmpFormula = tmpFormula.replace("&", "AND"); tmpFormula = tmpFormula.replace("|", "OR"); tmpFormula = tmpFormula.replace("~", "NOT");
code for changing back:
tmpFormula = tmpFormula.replace("AND", "&"); tmpFormula = tmpFormula.replace("OR", "|"); tmpFormula = tmpFormula.replace("NOT", "~");
- We need to enclose the input formula with brackets:
tmpFormula = "(" + tmpFormula + ")";
I tested AIMA as a replacement for Orbital on this unit test:
Source Context:
neve luogo
codice
nome
nome breve
quota
latitudine
longitudine
Target Context:
luogo
nome
latitudine
longitudine
Result is exactly the same as the one we got with Orbital:
\neve luogo < \luogo
\neve luogo\nome < \luogo\nome
\neve luogo\nome breve < \luogo\nome
\neve luogo\latitudine < \luogo\latitudine
\neve luogo\longitudine < \luogo\longitudine
The input to the transform function in AIMA should include only binary operators. I.e. an input like
n28.3 AND n28.4 AND n28.5 AND n28.6
is not accepted and must be converted to
(n28.3 AND n28.4) AND (n28.5 AND n28.6)
see http://code.google.com/p/aima-java/issues/detail?id=72
To prepare the input to AIMA, we call the method encloseWithParentheses() in class DefaultContextPreprocessor to enclose the items with parenteses as shown below before passing them to AIMA.
-
[n1.0]becomes[n1.0] -
[n1.0, n2.0]becomes[n1.0, n2.0] -
[n1.0, n2.0, n3.0]becomes[ [n1.0, n2.0], [n3.0] ] -
[n1.0, n2.0, n3.0, n4.0]becomes[ [n1.0, n2.0], [n3.0, n4.0] ] -
[n1.0, n2.0, n3.0, n4.0, n5.0]becomes[ [[n1.0, n2.0], [n3.0, n4.0] ], [n5.0] ]
and so on.