1 | package felix.main; |
2 | |
3 | |
4 | import java.util.HashMap; |
5 | import java.util.HashSet; |
6 | |
7 | |
8 | |
9 | import tuffy.db.RDB; |
10 | import tuffy.mln.Clause; |
11 | import tuffy.mln.Predicate; |
12 | import tuffy.ra.ConjunctiveQuery; |
13 | import tuffy.util.ExceptionMan; |
14 | import tuffy.util.Timer; |
15 | import felix.compiler.StaticAnalyzer; |
16 | import felix.dstruct.ExecutionPlan; |
17 | import felix.dstruct.FelixQuery; |
18 | import felix.dstruct.OperatorBucketGraph; |
19 | import felix.dstruct.StatOperator; |
20 | import felix.executor.Executor; |
21 | import felix.optimizer.Scheduler; |
22 | import felix.parser.FelixCommandOptions; |
23 | import felix.util.FelixConfig; |
24 | import felix.util.FelixUIMan; |
25 | |
26 | /** |
27 | * |
28 | * |
29 | * @deprecated |
30 | * @author Ce Zhang |
31 | * |
32 | */ |
33 | public class OnlineFelix { |
34 | |
35 | /** |
36 | * Felix's query, which consists of program, query and evidence. |
37 | */ |
38 | FelixQuery fq; |
39 | |
40 | /** |
41 | * Static Analyzer, which analyzes the property of each predicates according to rules. |
42 | */ |
43 | StaticAnalyzer sa; |
44 | |
45 | /** |
46 | * Database connection. |
47 | */ |
48 | RDB db; |
49 | |
50 | /** |
51 | * Command line option. |
52 | */ |
53 | FelixCommandOptions options; |
54 | |
55 | /** |
56 | * Whether this Felix object run has loaded evidences. |
57 | */ |
58 | public boolean hasLoadedEvidence = false; |
59 | |
60 | /** |
61 | * Return Felix's query. |
62 | * @return |
63 | */ |
64 | public FelixQuery getFelixQuery(){ |
65 | return fq; |
66 | } |
67 | |
68 | /** |
69 | * Clear static parameters and initialize variables. |
70 | */ |
71 | public void init(){ |
72 | |
73 | ConjunctiveQuery.clearIndexHistory(); |
74 | |
75 | Clause.mappingFromID2Const = new HashMap<Integer, String>(); |
76 | Clause.mappingFromID2Desc = new HashMap<String, String>(); |
77 | |
78 | } |
79 | |
80 | /** |
81 | * Load Felix query from program and query file. If -useEvid |
82 | * is used, evidence file will also be loaded by this function. |
83 | */ |
84 | public void parseFelixQuery(){ |
85 | |
86 | FelixUIMan.println(">>> Connecting to RDBMS at " + FelixConfig.db_url); |
87 | |
88 | fq = new FelixQuery(); |
89 | |
90 | if(options.fquery == null && options.queryAtoms == null){ |
91 | System.err.println("Please specify queries with -q or -queryFiles"); |
92 | return; |
93 | } |
94 | |
95 | FelixConfig.verbose_level = options.verboseLevel; |
96 | |
97 | String prog = options.fprog; |
98 | fq.parseProgFromString(prog); |
99 | |
100 | if(options.fquery != null){ |
101 | String[] queryFiles = options.fquery.split(","); |
102 | fq.loadQueries(queryFiles); |
103 | } |
104 | |
105 | if(options.queryAtoms != null){ |
106 | FelixUIMan.println(">>> Parsing query atoms in command line"); |
107 | fq.parseQueryCommaList(options.queryAtoms); |
108 | } |
109 | |
110 | if(options.cwaPreds != null){ |
111 | String[] preds = options.cwaPreds.split(","); |
112 | for(String ps : preds){ |
113 | Predicate p = fq.getPredByName(ps); |
114 | if(p == null){ |
115 | fq.closeFiles(); |
116 | ExceptionMan.die("COMMAND LINE: Unknown predicate name -- " + ps); |
117 | }else{ |
118 | p.setClosedWorld(true); |
119 | } |
120 | } |
121 | } |
122 | |
123 | } |
124 | |
125 | /** |
126 | * Run Felix! |
127 | * @param args Command line options. |
128 | */ |
129 | public String run(String[] args){ |
130 | |
131 | FelixConfig.overrideID(); |
132 | String ret = ""; |
133 | |
134 | Timer.start("Felix-Timer"); |
135 | |
136 | init(); |
137 | |
138 | options = FelixUIMan.parseCommand(args); |
139 | |
140 | this.parseFelixQuery(); |
141 | |
142 | sa = new StaticAnalyzer(this.fq, options); |
143 | sa.parse(); |
144 | |
145 | //for(int j=0;j<2;j++){ |
146 | // |
147 | Scheduler sc = new Scheduler(null, this.fq, options); |
148 | |
149 | // decompose the whole MLN into different operators |
150 | HashSet<StatOperator> ops = sc.ruleDecomposition(null); |
151 | |
152 | // decompose each operators into smaller operators dealing |
153 | // with different portion of data. |
154 | OperatorBucketGraph obg = sc.dataDecomposition(ops, null); |
155 | |
156 | ExecutionPlan ep = sc.orderOperators(obg); |
157 | |
158 | ret = ep.toHTMLString(); |
159 | |
160 | return ret; |
161 | |
162 | } |
163 | |
164 | } |
165 | |
166 | |
167 | |
168 | |