use of org.w3._2007.rif.Formula in project hale by halestudio.
the class TestModelRifToRifTranslator method checkAndChildren.
private void checkAndChildren(And and) {
assertNotNull(and.getFormula());
assertTrue(and.getFormula().size() >= 1);
for (Formula formula : and.getFormula()) {
if (formula.getMember() != null) {
checkMemberElement(formula.getMember());
} else if (formula.getFrame() != null) {
// checkPropertyFrame(formula.getFrame());
}
}
}
use of org.w3._2007.rif.Formula 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.Formula 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);
}
}
}
}
use of org.w3._2007.rif.Formula in project hale by halestudio.
the class ModelRifToRifTranslator method processChildren.
private void processChildren(ModelSentence s, final Exists exists, Do do1) {
Formula existsFormula = factory.createFormula();
And and = factory.createAnd();
existsFormula.setAnd(and);
exists.setFormula(existsFormula);
Actions actions = factory.createDoActions();
do1.setActions(actions);
for (RifVariable instanceVariable : s.getVariables(Type.INSTANCE)) {
// source instance variables
if (!instanceVariable.isActionVar()) {
recurseChildren(exists, do1, instanceVariable, s, true);
} else // target instance variables
{
recurseChildren(exists, do1, instanceVariable, s, false);
}
}
Map<RifVariable, Frame> map = new LinkedHashMap<RifVariable, Frame>();
for (PropertyMapping mapping : s.getPropertyMappings()) {
RifVariable contextVariable = mapping.getTarget().getContextVariable();
Frame match = map.get(contextVariable);
if (match == null) {
map.put(contextVariable, initialiseFrame(contextVariable));
}
}
for (StaticAssignment staticAssignment : s.getStaticAssignments()) {
RifVariable contextVariable = staticAssignment.getTarget().getContextVariable();
Frame match = map.get(contextVariable);
if (match == null) {
map.put(contextVariable, initialiseFrame(contextVariable));
}
}
for (PropertyMapping mapping : s.getPropertyMappings()) {
Frame frame = map.get(mapping.getTarget().getContextVariable());
createAssignmentSlot(mapping, frame);
}
for (StaticAssignment staticAssignment : s.getStaticAssignments()) {
Frame frame = map.get(staticAssignment.getTarget().getContextVariable());
createStaticAssignmentSlot(staticAssignment, frame);
}
for (ModelRifMappingCondition mappingCondition : s.getMappingConditions()) {
createFilter(exists.getFormula().getAnd().getFormula(), mappingCondition);
}
for (Frame frame : map.values()) {
Assert assert1 = factory.createAssert();
Target target = factory.createAssertTarget();
target.setFrame(frame);
assert1.setTarget(target);
actions.getACTION().add(assert1);
}
}
use of org.w3._2007.rif.Formula in project hale by halestudio.
the class ModelRifToRifTranslator method createLogicalFilter.
private void createLogicalFilter(List<Formula> list, ModelRifMappingCondition mappingCondition) {
// $NON-NLS-1$
log.fine("Creating logical filter");
Formula logicFilterFormula = factory.createFormula();
if (mappingCondition.getLogicalType().equals(NOT)) {
INeg negation = factory.createINeg();
logicFilterFormula.setINeg(negation);
// Formula subNegationFormula = factory.createFormula();
List<Formula> notList = new ArrayList<Formula>();
// notList.add(subNegationFormula);
createChildFilters(mappingCondition, notList);
negation.setFormula(notList.get(0));
// $NON-NLS-1$
log.fine("Filter is a NOT filter");
} else {
if (mappingCondition.getLogicalType().equals(AND)) {
And and1 = factory.createAnd();
logicFilterFormula.setAnd(and1);
createChildFilters(mappingCondition, and1.getFormula());
// $NON-NLS-1$
log.fine("Filter is an AND filter");
} else if (mappingCondition.getLogicalType().equals(OR)) {
Or or = factory.createOr();
logicFilterFormula.setOr(or);
createChildFilters(mappingCondition, or.getFormula());
// $NON-NLS-1$
log.fine("Filter is an OR filter");
}
}
list.add(logicFilterFormula);
}
Aggregations