1 | package felix.io; |
2 | |
3 | import java.sql.ResultSet; |
4 | import java.sql.SQLException; |
5 | import java.util.ArrayList; |
6 | |
7 | import org.antlr.runtime.Token; |
8 | |
9 | import felix.dstruct.FelixPredicate; |
10 | import felix.dstruct.FelixQuery; |
11 | |
12 | import tuffy.db.RDB; |
13 | import tuffy.mln.Atom; |
14 | import tuffy.mln.Type; |
15 | |
16 | /** |
17 | * Class for normalizing ids of a database table. |
18 | * |
19 | * @deprecated |
20 | * |
21 | * @author Ce Zhang |
22 | * |
23 | */ |
24 | public class IDNormalizor { |
25 | |
26 | /** |
27 | * Normalizes ids of given schema.table. |
28 | * @param schema |
29 | * @param table |
30 | * @param p |
31 | * @param fq |
32 | */ |
33 | public static void loadFromDBTable(String schema, String table, FelixPredicate p, FelixQuery fq){ |
34 | |
35 | RDB db = RDB.getRDBbyConfig(schema); |
36 | String sql = "SELECT * FROM " + table; |
37 | db.disableAutoCommitForNow(); |
38 | |
39 | ResultSet rs = db.query(sql); |
40 | try { |
41 | while(rs.next()){ |
42 | // System.out.println(rs.getString(1)); |
43 | ArrayList<String> args = new ArrayList<String>(); |
44 | for(int i=0; i<p.arity(); i++){ |
45 | Type type = p.getTypeAt(i); |
46 | String s; |
47 | s = rs.getString(i+1); |
48 | if(type.isNonSymbolicType()){ |
49 | args.add(s); |
50 | }else{ |
51 | Integer cid = fq.getSymbolID(s,type); |
52 | args.add(Integer.toString(cid)); |
53 | } |
54 | } |
55 | Atom gp = null; |
56 | //TODO: SOFT & TRUTH |
57 | // if(pr == null) { |
58 | gp = new Atom(args, true); |
59 | // }else{ |
60 | // gp = new Atom(args, pr); |
61 | // } |
62 | p.addEvidence(gp); |
63 | |
64 | |
65 | } |
66 | } catch (SQLException e) { |
67 | // TODO Auto-generated catch block |
68 | e.printStackTrace(); |
69 | } |
70 | |
71 | db.close(); |
72 | } |
73 | |
74 | } |