a sparqly jython++ a sparqly jython++ an asp/sparql enhanced jython cliff cheng carlos urrutia...

Post on 21-Jan-2016

229 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

A SParqly Jython++A SParqly Jython++an ASP/SPARQL enhanced Jython

Cliff Cheng Carlos Urrutia

Francisco Garcia

Summary

Improving ASPJython++ by incorporating homeworks. (SPARQL not fully supported, joins, update, delete, etc,.)

Added syntax to be allow conversion of a RDF database into ASP/Prolog facts by returning a Tuple.

Added syntax to be able to create RDF table from SQL table, using the Tuple as the return type.

Use of Oracle Sequence as a GUID.

Phyton.gThese tokens behave like the regular SELECT.

The grammar will check for syntax correctness.

Since the format of ASPSELECT and RDFSELECT is similar as SELECT, we just treated them as SQL grammar, which implies no need to build a node of type Tuple (Tuple.java) because SQL node were already created by Frank, and so the conversion of the nodes into python objects(CodeCompiler.java).

......

| (ASPSELECT sqlquery SEMI {$sql_stmt::strings.add($sql_stmt::temp); }| (ASPSELECT sqlquery SEMI {$sql_stmt::strings.add($sql_stmt::temp); }

-> ^(ASPSELECT<Tuple>[$sql_stmt.start, actions.castExprs($sql_stmt::exprs), $expr::ctype,-> ^(ASPSELECT<Tuple>[$sql_stmt.start, actions.castExprs($sql_stmt::exprs), $expr::ctype,$sql_stmt::strings, $connection::url, $connection::uname, $connection::pword]))$sql_stmt::strings, $connection::url, $connection::uname, $connection::pword]))

| (RDFSELECT sqlquery SEMI {$sql_stmt::strings.add($sql_stmt::temp); }| (RDFSELECT sqlquery SEMI {$sql_stmt::strings.add($sql_stmt::temp); }

-> ^(RDFSELECT<Tuple>[$sql_stmt.start, actions.castExprs($sql_stmt::exprs), $expr::ctype,-> ^(RDFSELECT<Tuple>[$sql_stmt.start, actions.castExprs($sql_stmt::exprs), $expr::ctype,$sql_stmt::strings, $connection::url, $connection::uname, $connection::pword]))$sql_stmt::strings, $connection::url, $connection::uname, $connection::pword]))

……

//new Tokens to help get ASP/Prolog facts //new Tokens to help get ASP/Prolog facts

ASPSELECT :ASPSELECT : 'ASPSELECT';'ASPSELECT';

RDFSELECT :RDFSELECT : 'RDFSELECT';'RDFSELECT';

PyTuple.java Here is where Tuples get evaluated.

The use of ASPSELECT is to indicate weather we return the RDF “triple” parsed into (SUB, PRED, OBJ) without the RDF format, to be used by end users to create ASP/Prolog facts.

RDFSELECT is used to create an RDF table from a SQL table.

But this new created syntax are best used with *, because ASPSELECT uses an RDF database, so you probably want to get the whole tuple as (SUB, PRED, OBJ)

Note: This does not mean it only works with *.

Sample syntax:

ASPSELECT * FROM SOMETABLE;ASPSELECT * FROM SOMETABLE;

RDFSELECT * FROM SOMETABLE;RDFSELECT * FROM SOMETABLE;

PyTuple.java (some code)

PyTuple.java

Oracle Sequence

In order for ASPSELECTASPSELECT to work properly, the way the guid was implemented for the INSERT statements had to be modified.

Before: every separate session's INSERTINSERT to the same RDF table would reset the guid to 1, since there will not be prior records of the last guid used.

Now: Oracle sequence: What is an Oracle sequence? A sequence is an object in Oracle to generate a number sequence. Useful to act as a primary key, here for our guid.

Oracle Sequnce Syntax

CREATE SEQUENCE sequence_name

MINVALUE value

MAXVALUE value

START WITH value

INCREMENT BY value

CACHE value;

Way implemented: //Create sequence

stmt.executeQuery("CREATE SEQUENCE stmt.executeQuery("CREATE SEQUENCE "+caststmt.getTable()+"_RDF_DATA_sqnc "+caststmt.getTable()+"_RDF_DATA_sqnc MINVALUE 1 START WITH 1 INCREMENT BY MINVALUE 1 START WITH 1 INCREMENT BY 1 NOCACHE");1 NOCACHE");

//Drop sequence

stmt.executeQuery("DROP SEQUENCE stmt.executeQuery("DROP SEQUENCE "+caststmt.getName()+"_RDF_DATA_sqnc");"+caststmt.getName()+"_RDF_DATA_sqnc");

//To get next value in sequence

OracleResultSet rs2 = OracleResultSet rs2 = (OracleResultSet)stmt.executeQuery("SELECT (OracleResultSet)stmt.executeQuery("SELECT " + tableName + "_RDF_DATA_sqnc.nextval " + tableName + "_RDF_DATA_sqnc.nextval FROM dual");FROM dual");

Concepts

Tokens Terminal Non-terminal Context-Free grammar Abstract Syntax Tree

ASP/Prolog facts and rules

SQL SPARQL RDF Concepts

Improvements

Keep working on fully supporting SPARQL (joins,delete,update) Make ASP/Prolog more dynamic Keep integrating more languages(Lisp, Haskell,

etc) :-)

top related