Dr. Philip Cannata 1 with ReL
Dr. Philip Cannata 2 10 Java (Object Oriented) ASP RDF (Horn Clause Deduction, Semantic Web) Relation Jython in Java This Course High Level Languages
Dr. Philip Cannata 3 svn co jythonhttps://jython.svn.sourceforge.net/svnroot/jython/trunk/jython ant. BUILD SUCCESSFUL Total time: 46 seconds dist/bin/jython Jython 2.6a0+ (trunk:7292M, Sep , 21:48:21) [Java HotSpot(TM) 64-Bit Server VM (Apple Inc.)] on java1.6.0_33 Type "help", "copyright", "credits" or "license" for more information. >>> >>> quit() Download and build Jython
Dr. Philip Cannata 4 A grammar file for the python language –./grammar/python.g Java classes that get instantiated as nodes on the Abstract Syntax Tree –./src/org/python/antlr/ast A way of printing the Abstract Syntax Tree –./dist/bin/jython ast/astview.py file.py Visitor classes for the interpreter –./org/python/antlr/ast/VisitorBase.java./org/python/antlr/ast/VisitorIF.java./org/python/antlr/Visitor.java A way to hook into the visitor’s process of setting up the runtime stack –./org/python/compiler/Code.java./org/python/compiler/CodeCompiler.java A way to work with the results from the jython interpreter – an example that we’ll use a lot is./org/python/core/PyTuple.java What would you expect to find in Jython
Dr. Philip Cannata 5 # Download ReL.zip from the class website to../../Download/ReL.zip cp -R../ReL/*. ant. BUILD SUCCESSFUL Total time: 46 seconds dist/bin/jython Jython 2.6a0+ (trunk:7292M, Sep , 21:48:21) [Java HotSpot(TM) 64-Bit Server VM (Apple Inc.)] on java1.6.0_33 Type "help", "copyright", "credits" or "license" for more information. >>> >>> quit() Overlay ReL code on top of Jython
Dr. Philip Cannata 6 ('body', ('BinOp (6,59)', ('left', ('Name (6,59)', ('id', 'x'), ('ctx', ('Load',)))), ('op', ('Add',)), ('right', ('Num (6,61)', ('n', 1))))))), ('args', ('Num (6,65)', ('n', 4))), ('keywords',), ('starargs', None), ('kwargs', None)), ('Name (6,69)', ('id', 'i'), ('ctx', ('Load',))), ('Name (6,72)', ('id', 'x'), ('ctx', ('Load',)))), ('ctx', ('Load',)))))), ('orelse',)), ('Print (7,0)', ('dest', None), ('values', ('Tuple (7,7)', ('elts',), ('ctx', ('Load',)))), ('nl', True)), ('Print (8,0)', ('dest', None), ('values', ('Tuple (8,7)', ('elts',), ('ctx', ('Load',)))), ('nl', True)), ('Print (9,0)', ('dest', None), ('values', ('Tuple (9,7)', ('elts', ('Name (9,52)', ('id', 'x'), ('ctx', ('Load',)))), ('ctx', ('Load',)))), ('nl', True)))) $ cat tests/demo.py ; dist/bin/jython ast/astview.py tests/demo.py MAKECONNECT URL UNAME cs345_50 PWORD cs345_50p; DROP TABLE NEWTEST1; # CREATE TABLE NEWTEST1 (VAL1 NUMBER, VAL2 NUMBER, VAL3 NUMBER); x=3 for i in [2, 4, 7]: INSERT INTO NEWTEST1 (VAL1, VAL2, VAL3) VALUES ((lambda x:x+1) (4), i, x); print (SELECT * FROM NEWTEST1;) print (SELECT VAL2 FROM NEWTEST1;) print (SELECT VAL1, VAL2 FROM NEWTEST1 WHERE VAL3 = x;) ('Module', ('body', ('Expr (1,0)', ('value', ('Connection (1,0)', ('elts',), ('ctx', ('Load',))))), ('Expr (2,0)', ('value', ('Tuple (2,0)', ('elts',), ('ctx', ('Load',))))), ('Assign (4,0)', ('targets', ('Name (4,0)', ('id', 'x'), ('ctx', ('Store',)))), ('value', ('Num (4,2)', ('n', 3)))), ('For (5,0)', ('target', ('Name (5,4)', ('id', 'i'), ('ctx', ('Store',)))), ('iter', ('List (5,9)', ('elts', ('Num (5,10)', ('n', 2)), ('Num (5,13)', ('n', 4)), ('Num (5,16)', ('n', 7))), ('ctx', ('Load',)))), ('body', ('Expr (6,1)', ('value', ('Tuple (6,1)', ('elts', ('Call (6,49)', ('func', ('Lambda (6,50)', ('args', ('arguments', ('args', ('Name (6,57)', ('id', 'x'), ('ctx', ('Param',)))), ('vararg', AST
Dr. Philip Cannata 7 MAKECONNECT – Python.g
Dr. Philip Cannata 8 MAKECONNECT– Python.g
Dr. Philip Cannata 9 MAKECONNECT– Python.g
Dr. Philip Cannata 10 MAKECONNECT– Python.g
Dr. Philip Cannata 11 MAKECONNECT– Python.g
Dr. Philip Cannata 12 MAKECONNECT– Python.g
Dr. Philip Cannata 13 Connection.java
Dr. Philip Cannata 14 Connection.java
Dr. Philip Cannata 15 VisitorBase.java
Dr. Philip Cannata 16 VisitorIF.java
Dr. Philip Cannata 17 Code.java
Dr. Philip Cannata 18 CodeCompiler.java
Dr. Philip Cannata 19 CodeCompiler.java
Dr. Philip Cannata 20 CodeCompiler.java
Dr. Philip Cannata 21 SELECT– Python.g
Dr. Philip Cannata 22 SELECT– Python.g
Dr. Philip Cannata 23 Tuple.java and PyTuple.java fjyswan files $ find. -type f -print./build.xml./extlibs/jsqlparser./extlibs/jsqlparser.jar./extlibs/META-INF./extlibs/ojdbc6.jar./fjyswanreadme.txt./grammar/Python.g./src/org/python/antlr/ast/Connection.java./src/org/python/antlr/ast/Tuple.java./src/org/python/antlr/ast/VisitorBase.java./src/org/python/antlr/ast/VisitorIF.java./src/org/python/compiler/Code.java./src/org/python/compiler/CodeCompiler.java./src/org/python/core/PyTuple.java./tests/astdemo.py./tests/demo.py
Dr. Philip Cannata 24 Tuple.java
Dr. Philip Cannata 25 Tuple.java
Dr. Philip Cannata 26 CodeCompiler.java
Dr. Philip Cannata 27 PyTuple.java
Dr. Philip Cannata 28 PyTuple.java
Dr. Philip Cannata 29 PyTuple.java
Dr. Philip Cannata 30 PyTuple.java
Dr. Philip Cannata 31 PyTuple.java Continues until line 319
Dr. Philip Cannata 32 $ dist/bin/jython tests/demo.py DROP TABLE NEWTEST1 INSERT INTO NEWTEST1 (VAL1, VAL2, VAL3) VALUES (5, 2, 3) INSERT INTO NEWTEST1_RDF_DATA VALUES (1, SDO_RDF_TRIPLE_S('NEWTEST1_CS345_RICK', ' ' ' INSERT INTO NEWTEST1_RDF_DATA VALUES (2, SDO_RDF_TRIPLE_S('NEWTEST1_CS345_RICK', ' ' ' INSERT INTO NEWTEST1_RDF_DATA VALUES (3, SDO_RDF_TRIPLE_S('NEWTEST1_CS345_RICK', ' ' ' INSERT INTO NEWTEST1 (VAL1, VAL2, VAL3) VALUES (5, 4, 3) INSERT INTO NEWTEST1_RDF_DATA VALUES (4, SDO_RDF_TRIPLE_S('NEWTEST1_CS345_RICK', ' ' ' INSERT INTO NEWTEST1_RDF_DATA VALUES (5, SDO_RDF_TRIPLE_S('NEWTEST1_CS345_RICK', ' ' ' INSERT INTO NEWTEST1_RDF_DATA VALUES (6, SDO_RDF_TRIPLE_S('NEWTEST1_CS345_RICK', ' ' ' INSERT INTO NEWTEST1 (VAL1, VAL2, VAL3) VALUES (5, 7, 3) INSERT INTO NEWTEST1_RDF_DATA VALUES (7, SDO_RDF_TRIPLE_S('NEWTEST1_CS345_RICK', ' ' ' INSERT INTO NEWTEST1_RDF_DATA VALUES (8, SDO_RDF_TRIPLE_S('NEWTEST1_CS345_RICK', ' ' ' INSERT INTO NEWTEST1_RDF_DATA VALUES (9, SDO_RDF_TRIPLE_S('NEWTEST1_CS345_RICK', ' ' ' Interpretation output
Dr. Philip Cannata 33 SELECT * FROM NEWTEST1 SELECT sub, pred, obj FROM TABLE(SEM_MATCH('(?sub ?pred ?obj)', SEM_Models('NEWTEST1_CS345_RICK'), null, SEM_ALIASES(SEM_ALIAS('',' null)) (('SUB', 'PRED', 'OBJ'), (' ' ' (' WTEST1/1', ' ' (' ' ' (' ' ' (' rg/NEWTEST1/2', ' ' (' ' 3', ' (' ' ' (' ple.org/NEWTEST1/3', ' ' (' ' 1/VAL3', ' SELECT VAL2 FROM NEWTEST1 SELECT b FROM TABLE(SEM_MATCH('(?sub :VAL2 ?b)', SEM_Models('NEWTEST1_CS345_RICK'), null, SEM_ALIASES(SEM_ALIAS('',' null)) (('B',), (' (' (' SELECT VAL1, VAL2 FROM NEWTEST1 WHERE VAL3 = 3 SELECT b, c FROM TABLE(SEM_MATCH('(?sub :VAL1 ?b) (?sub :VAL2 ?c) (?sub :VAL3 :3)', SEM_Models('NEWTEST1_CS345_RICK'), null, SEM_ALIASES(SEM_ALIAS('',' null)) (('B', 'C'), (' ' (' ' ('w ww.example.org/NEWTEST1/5', ' SQLSPARQL