130 likes | 219 Views
ASPJylog +SQL. Integration of SQL functionality into ASPJylog ++ Russell Beavers Srijith Prabhu Venkat Yerramsetti. Two types of facts:. Regular fact: Ex1: married(mrAstor , mrsAstor ). Ex2: data(0, 30, 60). Group fact: Ex: male(mrAstor;mrBlake;mrCrane;mrDavis ).
E N D
ASPJylog+SQL Integration of SQL functionality into ASPJylog++ Russell Beavers SrijithPrabhu VenkatYerramsetti
Two types of facts: • Regular fact: • Ex1: married(mrAstor, mrsAstor). • Ex2: data(0, 30, 60). • Group fact: • Ex: male(mrAstor;mrBlake;mrCrane;mrDavis).
Grammar for setting options for SELECT FORMAT: ASP_SELECT [fact_type] [fact_name] From Python.g: (ASP_SELECT (REG_FACT{$asp_stmt::strings.add("reg_fact");} | GROUP_FACT{$asp_stmt::strings.add("group_fact");}) NAME{$asp_stmt::strings.add($NAME.text);} -> ^(ASP_SELECT<Tuple>[$asp_stmt.start, actions.castExprs($asp_stmt::exprs), $expr::ctype, $asp_stmt::strings, $asp_stmt::append, true]))
Tokens added to support the grammar for options //*******lexer rules for asp*************** ASP : 'ASP' ; ASPBLANKQ : '?-.' ; ASPPRINTDB : 'PRINT' ; ASPLC : '!{' ; ASPDOTDOT : '..' ; REG_FACT : '?<<' ; GROUP_FACT : '?@@' ; ASP_SELECT : 'ASP_SELECT' ; //*******end of lexer rules for asp********
Code added to process the options for ASP SELECT This code determines if the fact is a regular fact or a group fact, and gets the name to be given to the fact From PyTuple.java: else if (as_attr[0].equals("reg_fact")){ asp_select= true; fact_type= as_attr[0]; fact_name= as_attr[1]; } else if (as_attr[0].equals("group_fact")){ asp_select= true; fact_type= as_attr[0]; fact_name= as_attr[1]; }
Code from Homework 5 • Here, we modify the tuples returned by SELECT from a remote database • public PyTuple(PyType subtype, PyObject[] elements, String sqlstrings, String server, String uname, String pword, String ctype) { • ArrayList<PyObject> rows = new ArrayList<PyObject>(); • if(ctype.equals("remote")) { • System.out.println(sqlstmt); • Statement stmt = conn.createStatement(); • if (statement instanceofSelect) { • try{ • OracleResultSetrs = (OracleResultSet) • stmt.executeQuery(sqlstmt); • ResultSetMetaDatard=rs.getMetaData();
Code to modify the tuples obtained from a Remote database if ( fact_type.equals("reg_fact")){ asp_fact+= ((PyString)temp[0]).toString(); for (inti=1 ; i < temp.length ; i++){ asp_fact+= "," + ((PyString)temp[i]).toString(); } } else { if (first_item){ asp_fact+= ((PyString)temp[0]).toString(); first_item= false; } else { asp_fact+= ";" + ((PyString)temp[0]).toString(); } }
Code to modify the tuples obtained from a Remote database (continued) if ( fact_type.equals("reg_fact")){ asp_fact+= ")."; f.write(asp_fact); f.write("\n"); asp_fact= fact_name + "("; } if ( fact_type.equals("group_fact")){ asp_fact+= ")."; f.write(asp_fact); f.write("\n"); } if(asp_select) { asp_select= false; fact_type = ""; fact_name = ""; }
The tuples obtained from a local database are modified in the convertToRDF method public ArrayList<PyObject> convertToRDF(net.sf.jsqlparser.statement.Statement statement, OracleConnectionconn) {
Code to modify the tuples obtained from a local database if ( fact_type.equals("reg_fact")){ fact_element= ((PyString)temp[0]).toString(); slash_index= fact_element.lastIndexOf("/"); asp_fact+= fact_element.substring(slash_index + 1); for (inti=1 ; i < temp.length ; i++){ fact_element= ((PyString)temp[i]).toString(); slash_index= fact_element.lastIndexOf("/"); asp_fact+= "," + fact_element.substring(slash_index + 1); } } else { fact_element= ((PyString)temp[0]).toString(); slash_index= fact_element.lastIndexOf("/"); if (first_item){ asp_fact+= fact_element.substring(slash_index + 1); first_item= false; } else { asp_fact+= ";" + fact_element.substring(slash_index + 1); }
Code to modify the tuples obtained from a local database (continued) if ( fact_type.equals("reg_fact")){ asp_fact+= ")."; f.write(asp_fact); f.write("\n"); asp_fact= fact_name + "("; } if ( fact_type.equals("group_fact")){ asp_fact+= ")."; f.write(asp_fact); f.write("\n"); } if(asp_select) { asp_select= false; fact_type = ""; fact_name= ""; }
Example Queries For Facts ASP_SELECT ?<< male SELECT NAME FROM DINERS WHERE GENDER = ‘Male’; - gives male(mrA;mrB;mrC). ASP_SELECT ?@@ married SELECT NAME, SPOUSE FROM DINERS; - gives married(mrA,mrsA).
Concepts Covered • Tokens • ASP • Prolog • SQL • RDF