use of org.w3._2007.rif.Sentence in project hale by halestudio.
the class TestModelRifToRifTranslator method checkDeclareElement.
private And checkDeclareElement(Sentence actualSentence) {
List<Declare> declareList = actualSentence.getImplies().getIf().getExists().getDeclare();
assertNotNull(declareList);
assertTrue(declareList.size() >= 1);
for (Declare d : declareList) {
assertNotNull(d);
assertNotNull(d.getVar());
assertNotNull(d.getVar().getContent());
assertThat(d.getVar().getContent().size(), is(equalTo(1)));
assertNotNull(d.getVar().getContent().get(0));
}
assertNotNull(actualSentence.getImplies().getIf().getExists().getFormula());
And and = actualSentence.getImplies().getIf().getExists().getFormula().getAnd();
assertNotNull(and);
return and;
}
use of org.w3._2007.rif.Sentence in project hale by halestudio.
the class ModelRifToRifTranslator method createTargetInstanceMembershipFormula.
private Assert createTargetInstanceMembershipFormula(Actions actions, ModelSentence sentence, RifVariable instanceVariable) {
Assert assert1 = factory.createAssert();
Target target = factory.createAssertTarget();
Member member = factory.createMember();
Instance instance = factory.createInstance();
Var var = factory.createVar();
var.getContent().add(instanceVariable.getName());
instance.setVar(var);
member.setInstance(instance);
org.w3._2007.rif.Class clazz = factory.createClass();
Const const1 = factory.createConst();
// $NON-NLS-1$
const1.setType("rif:iri");
const1.getContent().add(instanceVariable.getClassName());
clazz.setConst(const1);
member.setClazz(clazz);
target.setMember(member);
assert1.setTarget(target);
return assert1;
}
use of org.w3._2007.rif.Sentence in project hale by halestudio.
the class ModelRifToRifTranslator method createSourceInstanceMembershipFormula.
private Formula createSourceInstanceMembershipFormula(ModelSentence sentence, RifVariable instanceVariable) {
Formula result = factory.createFormula();
Member member = factory.createMember();
Instance instance = factory.createInstance();
Var var = factory.createVar();
String name = sentence.getSourceClass().getName();
var.getContent().add(name);
Const const1 = factory.createConst();
// $NON-NLS-1$
const1.setType("rif:iri");
const1.getContent().add(instanceVariable.getClassName());
org.w3._2007.rif.Class clazz = factory.createClass();
instance.setVar(var);
clazz.setConst(const1);
member.setInstance(instance);
member.setClazz(clazz);
result.setMember(member);
return result;
}
use of org.w3._2007.rif.Sentence in project hale by halestudio.
the class ModelRifToRifTranslator method buildSentence.
private Sentence buildSentence(ModelSentence s) {
// sort variables within sentence
final Sentence sentence = factory.createSentence();
final Implies implies = factory.createImplies();
sentence.setImplies(implies);
final If if1 = factory.createIf();
implies.setIf(if1);
final Exists exists = factory.createExists();
if1.setExists(exists);
ThenPart then = factory.createThenPart();
implies.setThen(then);
Do do1 = factory.createDo();
then.setDo(do1);
processChildren(s, exists, do1);
return sentence;
}
use of org.w3._2007.rif.Sentence in project hale by halestudio.
the class ModelRifToRifTranslator method recurseChildren.
private void recurseChildren(final Exists exists, Do do1, RifVariable variable, ModelSentence sentence, boolean isSource) {
List<RifVariable> children = sentence.findChildren(variable);
if (isSource) {
exists.getDeclare().add(createSourceDeclare(variable));
if (variable.getType().equals(Type.INSTANCE)) {
exists.getFormula().getAnd().getFormula().add(createSourceInstanceMembershipFormula(sentence, variable));
}
} else {
// if (!children.isEmpty()) // problem?
do1.getActionVar().add(createTargetVariableDeclare(variable));
if (variable.getType() == Type.INSTANCE) {
do1.getActions().getACTION().add(createTargetInstanceMembershipFormula(do1.getActions(), sentence, variable));
}
}
if (!children.isEmpty()) {
if (isSource) {
Frame frame = initialiseFrame(variable);
for (RifVariable child : children) {
recurseChildren(exists, do1, child, sentence, isSource);
createBindingSlot(child, frame);
}
Formula frameFormula = factory.createFormula();
frameFormula.setFrame(frame);
exists.getFormula().getAnd().getFormula().add(frameFormula);
} else {
for (RifVariable child : children) {
recurseChildren(exists, do1, child, sentence, isSource);
}
}
}
}
Aggregations