public AbstractNode createFromConjunctionClauses ( Map < String , AttributeInfo > intervals ) throws MIDDParsingException , MIDDException { if ( intervals == null || intervals . size ( ) == 0 ) { return ExternalNode . newInstance ( ) ; // return true-value external node } // Create edges from intervals Map < Integer , AbstractEdge < ? > > edges = new HashMap < Integer , AbstractEdge < ? > > ( ) ; for ( String attrId : intervals . keySet ( ) ) { int varId = attrMapper . getVariableId ( attrId ) ; Interval < ? > interval = intervals . get ( attrId ) . getInterval ( ) ; Class < ? > type = interval . getType ( ) ; AbstractEdge < ? > e = EdgeUtils . createEdge ( interval ) ; edges . put ( varId , e ) ; } List < Integer > lstVarIds = new ArrayList < Integer > ( edges . keySet ( ) ) ; Collections . sort ( lstVarIds ) ; // create a MIDD path from list of edges, start from lowest var-id InternalNode < ? > root = null ; InternalNode < ? > currentNode = null ; AbstractEdge < ? > currentEdge = null ; Iterator < Integer > lstIt = lstVarIds . iterator ( ) ; while ( lstIt . hasNext ( ) ) { Integer varId = lstIt . next ( ) ; AbstractEdge < ? > e = edges . get ( varId ) ; // default is NotApplicable, unless the "MustBePresent" is set to "true" String attrId = attrMapper . getAttributeId ( varId ) ; boolean isAttrMustBePresent = intervals . get ( attrId ) . isMustBePresent ; InternalNodeState nodeState = new InternalNodeState ( isAttrMustBePresent ? DecisionType . Indeterminate : DecisionType . NotApplicable ) ; InternalNode < ? > node = NodeUtils . createInternalNode ( varId , nodeState , e . getType ( ) ) ; if ( root == null ) { root = node ; // root points to the start of the MIDD path currentNode = node ; currentEdge = e ; } else { currentNode . addChild ( currentEdge , node ) ; currentNode = node ; currentEdge = e ; } } // the tail points to the true clause currentNode . addChild ( currentEdge , ExternalNode . newInstance ( ) ) ; // add a true-value external node return root ; }
Create a MIDD from conjunctions of intervals