====== Program Generator ====== ''**public class ProgramGenerator**'' This class generates EDB (Extensional Database) and translate the schema constraints into a DLV program ===== Class Attributes ===== No attributes for this class ===== Class Constructor ===== No constructor for this class ===== Class Methods ===== For better comprehension of the class, the figure underlying illustrates the dependencies between methods. {{ :magik-demo:developer:class:core:generateprogram.png?nolink&850 |}} ---- ==== generateProgram ==== public static java.util.ArrayList generateProgram (Query relQ, java.util.ArrayList tcs, boolean semantics, Schema schema, boolean isThereComparisons ) throws CycleException, PrimaryKeyViolationException This method managing all the process of generation of the DLV program. **Parameters:** * relQ - query that we want to analyze * tcs - TC-statements selected * semantics - //TRUE// if distinct-set semantics, //FALSE// if none-multiset semantics * isThereComparison **Returns:** * DLV program associated to the parameters given **Exceptions:** * CycleException * PrimaryKeyViolationException ---- ---- ---- ==== makeEDB ==== private static java.lang.String makeEDB (Query relQ, boolean isUnfolding) An internal auxiliary function, needed for conversion of query to prototypical EDB. **Parameters:** * relQ - query that we want to analyze * isUnfolding - //TRUE// if unfolding needed, //FALSE// no unfolding **Returns:** * String with the extensional database definition ---- ==== makeP_TC ==== private static java.util.ArrayList makeP_TC (java.util.ArrayList tcs, boolean isUnfolding) Creates the line of the program related to a list of rules out of a set of TC statements **Parameters:** * relQ - query that we want to analyze * isUnfolding - //TRUE// if unfolding needed, //FALSE// no unfolding **Returns:** * List of line of program related to TC-Statements given ---- ==== makeQ_a ==== private static java.lang.String makeQ_a (Query Q, boolean semantics, boolean isUnfolding) This method generates line of program for a given query **Parameters:** * Q - query that we want to generate the program * semantics - //TRUE// if distinct-set semantics, //FALSE// if none-multiset semantics * isUnfolding - //TRUE// if unfolding needed, //FALSE// no unfolding **Returns:** * line of program associated to the query ---- ==== makeFDC_Rules ==== private static java.util.ArrayList makeFDC_Rules ( java.util.ArrayList fdcs) This method generates the lines of program for all the finite domain constraints selected. **Parameter:** * fdcs - finite domain constraints to convert **Returns:** * list of lines of program for the finite domain constraints given ---- ==== createValFunctionalityContraint ==== private static java.lang.String createValFunctionalityContraint () **Returns:** * String of val functionality ---- ==== generatePredicateOriginal ==== public static java.lang.String generatePredicateOriginal (Query query) This method generates the lines of program for the original predicate. **Parameter:** * query - query that has to be converted **Returns:** * list of lines of program for the original predicate of the query ---- ---- ---- ==== makeEDB_Atom ==== static java.lang.String makeEDB_Atom (Atom atom, boolean isUnfolding) An internal auxiliary function, needed for conversion of atoms of the query to prototypical EDB. **Parameters:** * atom - atom that we want to convert * isUnfolding - //TRUE// if unfolding needed, //FALSE// no unfolding **Return** * String with the extensional database definition of the atom ---- ==== TCToString ==== private static java.lang.String TCToString (TCStatement tc, boolean isUnfolding) An internal auxiliary function converts TCStatement into a string readable by DLV as a rule TC = (R(s),G) is converted into R_a(s) :- R(s), G; **Parameters:** * atom - atom that we want to convert * isUnfolding - //TRUE// if unfolding needed, //FALSE// no unfolding **Return** * String with the TC-statement convert into line of code ---- ==== makeBodyAtom ==== static Atom makeBodyAtom (Atom atom, boolean semantics, boolean isUnfolding, java.util.ArrayList distinguished) **Parameters:** * atom - atom * semantics - //TRUE// if distinct-set semantics, //FALSE// if none-multiset semantics * isUnfolding - //TRUE// if unfolding needed, //FALSE// no unfolding * distiguished - list of the terms distinguished **Return** * Atom with the distinguished terms ---- ==== make_a(Atom) ==== static Atom make_a (Atom atom) This function takes an atom and return the same one but with _a prefix to the name **Parameters:** * atom - atom that we want to convert **Return** * atom with _a prefix to the name ---- ==== make_Q_a_vals ==== static java.lang.String make_Q_a_vals (Atom atom, Atom unfoldedAtom, boolean semantics, boolean isUnfolding, java.util.ArrayList distinguished) **Parameters:** * atom - atom that we want to convert * unfoldedAtom - atom unfolded * semantics - //TRUE// if distinct-set semantics, //FALSE// if none-multiset semantics * isUnfolding - //TRUE// if unfolding needed, //FALSE// no unfolding * distiguished - list of terms distinguished **Return** * String with val in query Q_a ---- ==== makeSkolemRule ==== public static java.util.ArrayList makeSkolemRule (ForeignKey fk, boolean isUnfolding) Apply Skolem rule to foreign key **Parameters:** * fk - foreign key * isUnfolding - //TRUE// if unfolding needed, //FALSE// no unfolding **Return** * list of ... ---- ==== makeAuxRule ==== public static java.lang.String makeAuxRule (ForeignKey fk, boolean isUnfolding) Create aux rule from a foreign key **Parameters:** * fk - foreign key to convert * isUnfolding - //TRUE// if unfolding needed, //FALSE// no unfolding **Return** * Line of code for aux rule for foreign key ---- ==== makeEDB_Atom ==== public static java.lang.String makeCopyRule (ForeignKey fk, boolean isUnfolding) Make the copy rule for a given foreign key **Parameters:** * fk - foreign key that needs the copy rule * isUnfolding - //TRUE// if unfolding needed, //FALSE// no unfolding **Return** * Line of code for copy rule related to the foreign key ---- ---- ---- ==== unfoldTC_Atom ==== static java.lang.String unfoldTC_Atom (Atom atom, boolean isUnfolding) Creates the line of code related to unfolded atom of the TC-statement **Parameters:** * atom - atom that we want to unfold * isUnfolding - //TRUE// if unfolding needed, //FALSE// no unfolding **Return** * Line of code generated for the unfolded atom ---- ==== make_a (String) ==== static java.lang.String make_a (java.lang.String atom){ This function takes an atom (in String format) and return the same one but with _a prefix to the name **Parameters:** * atom - atom that we want to convert **Return** * String of the atom with the _a prefix ---- ==== makeDoubleVal ==== static java.lang.String makeDoubleVal (Term a, Term b) **Parameters:** * a - term * b - term **Return** * String ---- ==== makeVal ==== static java.lang.String makeVal (Term a, Term b) Create the val line of code for two terms **Parameters:** * a - term * b - associated term to assign to term a **Return** * Val rule for the term a assigned the value of the term b ---- ==== createMaybe_V_vector_Y ==== private static java.lang.StringBuilder createMaybe_V_vector_Y (boolean isUnfolding, int keyTarget) **Parameters:** * isUnfolding - //TRUE// if unfolding needed, //FALSE// no unfolding * keyTarget - key taget **Return** * String Builder ---- ==== create_vector_Y ==== private static StringBuilder create_vector_Y (int keyTarget) **Parameters:** * keyTarget - index of the key target **Return** * String Builder [[magik-demo:developer:class:core:programgenerator|Back to Top]] | [[magik-demo:start|Back to Home Page]]