1 / 13

ASPJylog +SQL

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 ).

anais
Download Presentation

ASPJylog +SQL

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ASPJylog+SQL Integration of SQL functionality into ASPJylog++ Russell Beavers SrijithPrabhu VenkatYerramsetti

  2. Two types of facts: • Regular fact: • Ex1: married(mrAstor, mrsAstor). • Ex2: data(0, 30, 60). • Group fact: • Ex: male(mrAstor;mrBlake;mrCrane;mrDavis).

  3. 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]))

  4. 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********

  5. 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]; }

  6. 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();

  7. 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(); } }

  8. 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 = ""; }

  9. The tuples obtained from a local database are modified in the convertToRDF method public ArrayList<PyObject> convertToRDF(net.sf.jsqlparser.statement.Statement statement, OracleConnectionconn) {

  10. 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); }

  11. 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= ""; }

  12. 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).

  13. Concepts Covered • Tokens • ASP • Prolog • SQL • RDF

More Related