@ Override public void visit ( LowLevelAbstractionDefinition def ) throws ProtempaException { LOGGER . log ( Level . FINER , "Creating rule for {0}" , def ) ; try { /* * If there are no value definitions defined, we might still have an * inverseIsA relationship with another low-level abstraction * definition. */ if ( ! def . getValueDefinitions ( ) . isEmpty ( ) ) { Rule rule = new Rule ( def . getId ( ) ) ; Pattern sourceP = new Pattern ( 2 , 1 , PRIM_PARAM_OT , "" ) ; Set < String > abstractedFrom = def . getAbstractedFrom ( ) ; String [ ] abstractedFromArr = abstractedFrom . toArray ( new String [ abstractedFrom . size ( ) ] ) ; Set < String > subtrees = this . cache . collectPropIdDescendantsUsingInverseIsA ( abstractedFromArr ) ; sourceP . addConstraint ( new PredicateConstraint ( new PropositionPredicateExpression ( subtrees ) ) ) ; Pattern resultP = new Pattern ( 1 , 1 , ARRAY_LIST_OT , "result" ) ; resultP . setSource ( new Collect ( sourceP , new Pattern ( 1 , 1 , ARRAY_LIST_OT , "result" ) ) ) ; resultP . addConstraint ( new PredicateConstraint ( new CollectionSizeExpression ( 1 ) ) ) ; rule . addPattern ( resultP ) ; String contextId = def . getContextId ( ) ; if ( contextId != null ) { Pattern sourceP2 = new Pattern ( 4 , 1 , CONTEXT_OT , "context" ) ; sourceP2 . addConstraint ( new PredicateConstraint ( new PropositionPredicateExpression ( contextId ) ) ) ; Pattern resultP2 = new Pattern ( 3 , 1 , ARRAY_LIST_OT , "result2" ) ; resultP2 . setSource ( new Collect ( sourceP2 , new Pattern ( 3 , 1 , ARRAY_LIST_OT , "result" ) ) ) ; resultP2 . addConstraint ( new PredicateConstraint ( new CollectionSizeExpression ( 1 ) ) ) ; rule . addPattern ( resultP2 ) ; } Algorithm algo = this . algorithms . get ( def ) ; rule . setConsequence ( new LowLevelAbstractionConsequence ( def , algo , this . derivationsBuilder ) ) ; rule . setSalience ( TWO_SALIENCE ) ; this . ruleToAbstractionDefinition . put ( rule , def ) ; rules . add ( rule ) ; } } catch ( InvalidRuleException e ) { throw new AssertionError ( e . getClass ( ) . getName ( ) + ": " + e . getMessage ( ) ) ; } }
Translates a low - level abstraction definition into rules .