List<TermTuple> body = new ArrayList<TermTuple>();
Map<ATermAppl, AtomVariable> varToVar = new HashMap<ATermAppl, AtomVariable>();
for ( RuleAtom atom : rule.getBody() ) {
atom.accept( filter );
if ( filter.isSafe() ) {
TermTuple bodyTerm = translator.translateAtom( atom, ds );
if ( bodyTerm != null ) {
body.add( bodyTerm );
for ( AtomVariable atomVar : VariableUtils.getVars( atom ) ) {
Pair<ATermAppl, DependencySet> translatedVar = translator.translateAtomObject( atomVar );
ATermAppl var = translatedVar.first;
varToVar.put( var, atomVar );
vars.add( var );
}
}
}
}
List<ATermAppl> headTerms = new ArrayList<ATermAppl>();
headTerms.add( VARBINDING );
headTerms.add( ruleID );
headTerms.add( DUMMY );
headTerms.add( DUMMY ); // Space fillers so generated atoms don't collide with the triple-based rules
headTerms.addAll( vars );
List<TermTuple> head = Collections.singletonList( new TermTuple( DependencySet.INDEPENDENT, headTerms ) );
List<AtomVariable> ruleVars = new ArrayList<AtomVariable>( vars.size() );
for ( ATermAppl var : vars )
ruleVars.add( varToVar.get( var ) );