SlideShare a Scribd company logo
Alexandru Ioan Cuza University
Faculty of Computer Science




                      SQL2SPARQL

                              Students:
                       Dron Alexandru ISS21
                       Ifrim Alexandru ISS21
1.Install Guide – Preparing the environment


Summary

       1.1 MySql install
             1.1.1 Create database
             1.1.2 Import a sql file to database
       1.2 JRE install
             1.2.1 Set Path
       1.3 Jena install
       1.4 .NET framework


       1.1 MySql install

        You can get MySQL from the following address:
http://dev.mysql.com/downloads/mysql, select the right version for you, download
and install it. Go to MySQL folder and run mysql_installservice.bat to set mysql
server to be a service on the windows platform, if the installer didn`t already do
that for you. Then you can check if MySql service is running in Administrative
Tools/Services tab.

              1.1.1 Create database


               Go to your MySql installation folder using Command Prompt and
into the bin folder. Type in the following command :
               mysql.exe -u root -p
(the default password is blank and the user is "root").
            If everything was installed correct, now you are on the mysql
command line tool. To create our database, simply type:
            create database facultate

              1.1.2 Import a sql file to database

             First, we have to tell to mysql what database we want to use, to do
that we have to type:
             use facultate
             (the message from the MySql server should be "Database
changed").
To import our table structure and data, open the file called bd.sql,
       copy & paste the sql code to console. Alternatively you can type : quit, move the
       bd.sql file to the bin folder and type in the windows command prompt :
                       mysql -u root -p facultate < bd.sql
                       Another method to import is to use the phpmyadmin script, but you
       will need to have Apache and PHP installed.
                       If you want to see if the import worked, in mysql command line,
       after you select what database to use, you can type:
                       show tables;




                                   Fig.1.1.1


              1.2 JRE install

               The installation of the Java Runtime Environment (JRE) is straight
forward, just go to the following url http://www.java.com/en/download/index.jsp,
download and install it.

                     1.2.1 Set Path

            To verify that the java command is environmental, open the Command
Prompt from windows and type:

              java

             If you get the “'java' is not recognized as an internal or external command,
operable program or batch file”, you will have to set the Path to the java.exe file.

               Open the System tab from Control Panel, click on the Advanced System
Properties, select the Environment Variables. Edit the Path with the path to the folder
bin in your java installation. (The default is : C:Program Files (x86)Javajre6bin on
windows 7 64biti). Don`t forget to add ; after the other paths that are written in there(Fig.
1.2.1).

              1.3 Jena install

              To install Jena Framework go to the jena official page and download the
latest version: http://sourceforge.net/projects/jena/files/Jena/.
1.4 .NET framework



            And of course, to run our app you will also need to have the .NET
framework. Download the latest version from the microsoft.com website.




                                 Fig.1.2.1

2. Application



 Summary

  2.1 SQL2SPARQL – application short description

  2.2 Transforming sql database tables into rdf format

  2.3 How does the application work?
             2.3.1<prefixes>, <type declarations>
             2.3.2 <sparql select clause>, <select fields declarations>
             2.3.3<auxiliary fields declarations>
             2.3.4<filters>
2.1 SQL2SPARQL – application short description


       The „sql2sparql‟ application transforms sql queries that are entered by the user,
into sparql queries that will give the same result over the rdf transformation of the
database (by following some rules listed under).
       The application is a console application that takes an input from the user
representing a sql query, runs the query over „facultate‟ mysql database and shows the
results, and then converts the query to sparql, that is ran over the rdf file using jena.


       2.2 Transforming sql database tables into rdf format.

        There are some rules that we used when transforming the sql database tables
into rdf format. One of them (needed by the application to convert from sql queries to
sparql queries) is to write in a file, for every table, a line with the following format:
tableName[http://rdfTableNamespace]=fieldName1;fieldName2;…
As example for the table „persoana‟ with the fields: id, nume, prenume, data_nasterii,
sex; the file should contain the following line:
persoana[http://facultate.wad/persoana]=id;nume;prenume;data_nasterii;sex;
(The rdf would contain in this case a declaration of the namespace
xmlns:persoana=http://facultate.wad/persoana).

       This could have also been declared in the rdf file in the following record:
       <persoana:prototype>
                    <persoana:id></persoana:id>
                    <persoana:nume></persoana:nume>
                    <persoana:prenume></persoana:prenume>
                    <persoana:data_nasterii></persoana:data_nasterii>
                    <persoana:sex></persoana:sex>
       </persoana:prototype>
but parsing a smaller file would be more efficient and easier.

        Each record from the table will appear in the rdf file as: <tableName:record>, and
its values will contain the fields values as <tableName:tableField>. If the field type is of
int value, then this will also be declared in the rdf record (required for conditioning
where/filter).
For example, the following record from persoana (from the sql database):
+----+---------------+---------------+-------------------+-----+
       | id | nume           | prenume | data_nasterii | sex |
       +----+---------------+---------------+-------------------+-----+
       | 12 | campeanu | loredana | 1985-08-03 | F |
       +----+---------------+---------------+-------------------+-----+
       In the rdf file will look like this:
       <persoana:record>
                        <persoana:id
       rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">12</persoana:id>
                        <persoana:nume>campeanu</persoana:nume>
                        <persoana:prenume>loredana</persoana:prenume>
                        <persoana:data_nasterii>1985-08-03</persoana:data_nasterii>
                        <persoana:sex>F</persoana:sex>
       </persoana:record>




       2.3 How does the application work?


        The application takes an input from the user which represents the sql query over
the „facultate‟ database (which was also manually converted to „facultate.rdf‟ using the
rules listed above). This can be entered on multiple lines (such as in mysql console
application), and will stop reading only if „;‟ is the last non-space character on the line.
       The command is then run over „facultate‟ database, and the results will be
displayed in the console. If any errors appear the application stops, since the query is
most probably invalid, and the resulting sparql query will be the same.
        In order to convert the sql query to a sparql query that will work over
„facultate.rdf‟ and show the same result that the sql query returns over „facultate‟
database, the input goes to several steps.


       Step 1


        In the first step the sql query is parsed into a dictionary with the keys “select”,
“from”, “where” and “alias” (which is set only for nested selects). The values of the keys
are strings that contain the entire „select‟, „from‟ and respectively „where‟ clauses of the
query (except nested select where the value is a dictionary with the same keys). This is
done by splitting the entire entered query at words such as „select‟, „from‟ and „where‟.
The „where‟ key might be missing in case no „where‟ clause was entered.
e.g.: “select * from persoana where persoana.id > 10” =>
[select = “*”; from=”persoana”; where=” persoana.id > 10”];
Step 2


       In the second step some more info is collected from the dictionary prepared in
step 1.
For the from clause, a new dictionary is created that contains the used tables and their
aliases (the dictionary keys will be the table aliases, or their name if no alias is set, and
their values will be the table names). This is done by splitting the „from‟ value into words
(the split is made after spaces as well as after „”,” and operators (such as „<‟, „>=‟, etc.),
and taking the first (table name) and last values (alias) from each group of words
separated by commas (the second word from a group might be „AS‟).
e.g.: “[from] persoana per1, persoana as per2, sex” =>
[per1=”persoana”; per2=”persoana”; sex=”sex”];
        For the select clause there is also a dictionary created which contains the fields
and aliases that will appear in the final result. In this case the dictionary keys will be the
field names (e.g.: persoana.id) while the values will be the aliases (for the ease of use in
further steps). If “*” is encountered in the „select‟ clause then all the fields belonging to
the „from‟ tables will be added into the dictionary. The list of fields that belong to a table
are retrieved from the conversion file described at „Transforming sql database tables
into rdf format‟.
e.g.: “[select] *” (from=[persoana=”persoana”]) =>
[persoana.id=”persoana.id”; persoana.nume=”persoana.nume”,
persoana.prenume=”persoana.prenume”; persoana.sex=”persoana.sex”;
persoana.data_nasterii=”persoana.data_nasterii”];
         For the where clause 1 list (array) and 1 dictionary are created. The list holds the
filter statements (expr1 operator expr2), while the other will hold the fields that are used
in these expressions, but which should not appear in the final result. The filter
statements can be combined by „and‟ and „or‟, which are modified to “&&” and “||” for
sparql. The filters list will have as the first element the left side expression of a filter
statement, the second will be the operator of the statement and the third will be the right
side of the statement. If there are more statements then there will be a 4 th element
which will be either “&&” or “||”, followed by at least 3 more objects composing a new
filter statement. Each „variable‟ found in expr1 or expr 2 will be formatted as
“?tableAlias_tableField”, and if the select dictionary does not include them then they‟re
added to the auxiliary fields dictionary as [tableAlias.tableField =
“?tableAlias_tablefield”];
e.g.: “[where] persoana.id > 10 and persoana.id+3<=15”
(select=[persoana.nume=persoana.nume]) =>
(filters){?persoana_id, >, 10, &&, ?persoana_id+3, <=, 15};
(auxFields)[persoana.id=?persoana_id];
Step 3


       In the 3rd step the sparql query is prepared using the info gathered and prepared
at the previous step. The sparql query will have the form:
<prefixes>
SELECT <sparql select clause>
WHERE {
<type declarations> .
<‟select‟ fields declarations> .
<auxiliary fields declarations>
FILTER ( <filters> )
}

                2.3.1<prefixes>, <type declarations>

                The prefixes are created from the dictionary created at step 2 for the „from‟
clause. This is done by going through the entire dictionary and getting the table names
used in the „from‟ clause. Using the file that describes the conversion rules from the
database to rdf the namespace for that table is retrieved from the file (the file is actually
read at application startup and stored in a dictionary for further use). The prefix for a
table „t‟ with alias „a‟ will look like: “PREFIX a: <namespaceForT>”.
        For every included table, a new value is also created in the type declarations:
“tableAlias a tableAlias:record”;
e.g.: (from)[persoana=persoana; s=student] =>
PREFIX persoana: <http://facultate.wad/persoana>
PREFIX s: <http://facultate.wad/student>

                2.3.2 <sparql select clause>, <select fields declarations>

                The sparql select clause and the type declarations are created by going
through the dictionary created at step 2 for the „select‟ clause. If the fields contained in
the dictionary contain aliases (the value of the alias does not contain “.”) then the select
clause for sparql will append the „field‟ “?alias”, otherwise it will append
“?tableAlias.fieldName”. The “field declarations” will have the form: “?tableAlias
tableAlias:tableField „field‟”.
        e.g.: “SELECT * from ersoana” =>
<sparql select clause> = “?persoana_id ?persoana_nume ?persoana_prenume
?persoana_data_nasterii”
<field declarations> =
        “?persoana persoana:id ?persoana_id .
?persoana persoana:nume ?persoana_nume .
       ?persoana persoana:prenume ?persoana_prenume .
       ?persoana persoana:data_nasterii ?persoana_data_nasterii .
       ?persoana persoana:sex ?persoana_sex”

              2.3.3<auxiliary fields declarations>

              These are constructed the same way as the <field declarations>, but from
the contents of the dictionary created at step 2 for the „where‟ clause.

              2.3.4<filters>

               The filters are created by simply appending the values from the list of
filters created at step 2 for the „where‟ clause, everything being prepared at that step.
e.g.: “[where] persoana.id > 10 and persoana.id+3<=15” =>
“?persoana_id > 10 && ?persoana_id+3 <= 15}”;

              After the sparql query is prepared, it is written out on the console for the
user to see. The query is also written to a file (sparql), and jena is launched taking as
parameters the query file and the rdf file (facultate.rdf), showing the results of the sparql
query. Launching jena with the given parameters is done through a bat file with the
following content:
“set JENAROOT=[PATH TO JENA DIR]
cmd.exe /K "[PATH TO JENA ARQ BAT} --data=facultate.rdf --query=sparql"”.



3. Application overview

   Summary
   3.1 Console application
   3.2 Windows Forms application



       3.1 Console application

       To run our example or another in accordance with our rules, you will have to
modify some files. First open with a text editor the file called “jena_facultate_test.bat”.
Set the path to your jena installation folder, to the “arq.bat” file from the bin folder in your
jena and your rdf file. You will also need to add the “tables” in the file named
“database_fields.txt”, based on our rules, if you use another example.
Another thing to know, is that the application is using to connect to MySql the
user named “root” and no password. The database name that the app is looking for is
“facultate”.
       You can see in Annex 1 some examples run on the console application.


       3.2 Windows Forms application


         The windows forms application is more easy to use, and that was our goal in the
first place, but we like the console application as well.
         The first thing we will have to do when you run the app is to go to the
“Configurare” section. Here you have your options for the MySql connection : user,
pass, database, server. If the server box is left empty, the default is “localhost”.
         Sparql options are bellow and you must set the path to jena (double click on the
textbox field), to the rdf file and to the prefix file (database_name.txt in our example).
See Fig. 3.2.1.




                                   Fig. 3.2.1


         The main application is very straightforward, you will have to type the sql query
like in the Fig. 3.2.2, press „ruleaza” and the app will do the magic.
Fig. 3.2.2




       Some video examples with the structure, console and windows apps are
available at http://www.dron.ro/wad.
       The structure of the database/rdf file is in Annex 2.
Bibliografie




http://profs.info.uaic.ro/~adria/teach/wad/wad.html

http://profs.info.uaic.ro/~busaco/teach/courses/wade/web-film.html

http://www.w3.org/TR/rdf-sparql-query/

http://www.ibm.com/developerworks/xml/library/j-sparql/

http://www.cambridgesemantics.com/2008/09/sparql-by-example/#%281%29

http://www.zvon.org/xxl/RDFTutorial/General/contents.html

http://dev.mysql.com/doc/refman/5.5/en/
Annex 1
SQL2SPARQL
SQL2SPARQL
Annex 2



                                      Database structure




                                           RDF
<rdf:RDF

  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"

  xmlns:sex="http://facultate.wad/sex"

       xmlns:persoana="http://facultate.wad/persoana"

       xmlns:studii="http://facultate.wad/studii"

       xmlns:student="http://facultate.wad/student"

       xmlns:profesor="http://facultate.wad/profesor">

       <!--    xsd="http://www.w3.org/2001/XMLSchema#" -->

       <sex:prototype>

               <sex:cod></sex:cod>

               <sex:nume></sex:nume>

       </sex:prototype>
<persoana:prototype>

                <persoana:id></persoana:id>

                <persoana:nume></persoana:nume>

                <persoana:prenume></persoana:prenume>

                <persoana:data_nasterii></persoana:data_nasterii>

                <persoana:sex></persoana:sex>

        </persoana:prototype>

<studii:prototype>

                <studii:cod></studii:cod>

                <studii:an></studii:an>

                <studii:categorie></studii:categorie>

        </studii:prototype>

<student:prototype>

                <student:id></student:id>

                <student:studii></student:studii>

                <student:grupa></student:grupa>

        </student:prototype>

<profesor:prototype>

                <profesor:id></profesor:id>

        </profesor:prototype>



                      Database_fields.txt – Prefixes/Conventions

sex[http://facultate.wad/sex]=cod;nume;

persoana[http://facultate.wad/persoana]=id;nume;prenume;data_nasterii;sex;

profesor[http://facultate.wad/profesor]=id;

student[http://facultate.wad/student]=id;studii;grupa;

studii[http://facultate.wad/studii]=cod;an;categorie;
Ad

More Related Content

What's hot (20)

Sq lite
Sq liteSq lite
Sq lite
Revuru Bharadwaja
 
MySQL and its basic commands
MySQL and its basic commandsMySQL and its basic commands
MySQL and its basic commands
Bwsrang Basumatary
 
PL/SQL Interview Questions
PL/SQL Interview QuestionsPL/SQL Interview Questions
PL/SQL Interview Questions
Srinimf-Slides
 
Mysql ppt
Mysql pptMysql ppt
Mysql ppt
Sanmuga Nathan
 
Oracle vs. MS SQL Server
Oracle vs. MS SQL ServerOracle vs. MS SQL Server
Oracle vs. MS SQL Server
Teresa Rothaar
 
Adbms
AdbmsAdbms
Adbms
jass12345
 
spring-tutorial
spring-tutorialspring-tutorial
spring-tutorial
Arjun Shanka
 
Concepts of NonStop SQL/MX: Part 2 - Introduction to catalogs and other objects
Concepts of NonStop SQL/MX: Part 2 - Introduction to catalogs and other objectsConcepts of NonStop SQL/MX: Part 2 - Introduction to catalogs and other objects
Concepts of NonStop SQL/MX: Part 2 - Introduction to catalogs and other objects
Frans Jongma
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c  - New Features for Developers and DBAsOracle Database 12c  - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAs
Alex Zaballa
 
MySql slides (ppt)
MySql slides (ppt)MySql slides (ppt)
MySql slides (ppt)
webhostingguy
 
Advanced SQL injection to operating system full control (slides)
Advanced SQL injection to operating system full control (slides)Advanced SQL injection to operating system full control (slides)
Advanced SQL injection to operating system full control (slides)
Bernardo Damele A. G.
 
Concepts of NonStop SQL/MX: Part 3 - Introduction to Metadata
Concepts of NonStop SQL/MX: Part 3 - Introduction to MetadataConcepts of NonStop SQL/MX: Part 3 - Introduction to Metadata
Concepts of NonStop SQL/MX: Part 3 - Introduction to Metadata
Frans Jongma
 
Concepts of NonStop SQL/MX: Part 4 - Storage.
Concepts of NonStop SQL/MX: Part 4 - Storage.Concepts of NonStop SQL/MX: Part 4 - Storage.
Concepts of NonStop SQL/MX: Part 4 - Storage.
Frans Jongma
 
261 Pdfsam
261 Pdfsam261 Pdfsam
261 Pdfsam
Emanuel Mateus
 
MFC Whitepaper
MFC WhitepaperMFC Whitepaper
MFC Whitepaper
Frans Jongma
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
Alex Zaballa
 
Oracle notes
Oracle notesOracle notes
Oracle notes
Prashant Dadmode
 
SQLMAP Tool Usage - A Heads Up
SQLMAP Tool Usage - A  Heads UpSQLMAP Tool Usage - A  Heads Up
SQLMAP Tool Usage - A Heads Up
Mindfire Solutions
 
Oracle developer interview questions(entry level)
Oracle developer interview questions(entry level)Oracle developer interview questions(entry level)
Oracle developer interview questions(entry level)
Naveen P
 
Data Handning with Sqlite for Android
Data Handning with Sqlite for AndroidData Handning with Sqlite for Android
Data Handning with Sqlite for Android
Jakir Hossain
 
PL/SQL Interview Questions
PL/SQL Interview QuestionsPL/SQL Interview Questions
PL/SQL Interview Questions
Srinimf-Slides
 
Oracle vs. MS SQL Server
Oracle vs. MS SQL ServerOracle vs. MS SQL Server
Oracle vs. MS SQL Server
Teresa Rothaar
 
Concepts of NonStop SQL/MX: Part 2 - Introduction to catalogs and other objects
Concepts of NonStop SQL/MX: Part 2 - Introduction to catalogs and other objectsConcepts of NonStop SQL/MX: Part 2 - Introduction to catalogs and other objects
Concepts of NonStop SQL/MX: Part 2 - Introduction to catalogs and other objects
Frans Jongma
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c  - New Features for Developers and DBAsOracle Database 12c  - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAs
Alex Zaballa
 
Advanced SQL injection to operating system full control (slides)
Advanced SQL injection to operating system full control (slides)Advanced SQL injection to operating system full control (slides)
Advanced SQL injection to operating system full control (slides)
Bernardo Damele A. G.
 
Concepts of NonStop SQL/MX: Part 3 - Introduction to Metadata
Concepts of NonStop SQL/MX: Part 3 - Introduction to MetadataConcepts of NonStop SQL/MX: Part 3 - Introduction to Metadata
Concepts of NonStop SQL/MX: Part 3 - Introduction to Metadata
Frans Jongma
 
Concepts of NonStop SQL/MX: Part 4 - Storage.
Concepts of NonStop SQL/MX: Part 4 - Storage.Concepts of NonStop SQL/MX: Part 4 - Storage.
Concepts of NonStop SQL/MX: Part 4 - Storage.
Frans Jongma
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
Alex Zaballa
 
SQLMAP Tool Usage - A Heads Up
SQLMAP Tool Usage - A  Heads UpSQLMAP Tool Usage - A  Heads Up
SQLMAP Tool Usage - A Heads Up
Mindfire Solutions
 
Oracle developer interview questions(entry level)
Oracle developer interview questions(entry level)Oracle developer interview questions(entry level)
Oracle developer interview questions(entry level)
Naveen P
 
Data Handning with Sqlite for Android
Data Handning with Sqlite for AndroidData Handning with Sqlite for Android
Data Handning with Sqlite for Android
Jakir Hossain
 

Similar to SQL2SPARQL (20)

Jdbc example program with access and MySql
Jdbc example program with access and MySqlJdbc example program with access and MySql
Jdbc example program with access and MySql
kamal kotecha
 
Tomcat + other things
Tomcat + other thingsTomcat + other things
Tomcat + other things
Aravindharamanan S
 
How to connect sql server to oracle server
How to connect sql server to oracle serverHow to connect sql server to oracle server
How to connect sql server to oracle server
Gustavo Bernardo
 
Playing With (B)Sqli
Playing With (B)SqliPlaying With (B)Sqli
Playing With (B)Sqli
Chema Alonso
 
Sql injection
Sql injectionSql injection
Sql injection
Nitish Kumar
 
Tuning and optimizing webcenter spaces application white paper
Tuning and optimizing webcenter spaces application white paperTuning and optimizing webcenter spaces application white paper
Tuning and optimizing webcenter spaces application white paper
Vinay Kumar
 
Advanced sql injection 1
Advanced sql injection 1Advanced sql injection 1
Advanced sql injection 1
Karunakar Singh Thakur
 
DBMS LAB FILE1 task 1 , task 2, task3 and many more.pdf
DBMS LAB FILE1 task 1 , task 2, task3 and many more.pdfDBMS LAB FILE1 task 1 , task 2, task3 and many more.pdf
DBMS LAB FILE1 task 1 , task 2, task3 and many more.pdf
AbhishekKumarPandit5
 
Lecture 1. java database connectivity
Lecture 1. java database connectivityLecture 1. java database connectivity
Lecture 1. java database connectivity
Waheedullah Suliman Khail
 
Asegúr@IT IV - Remote File Downloading
Asegúr@IT IV - Remote File DownloadingAsegúr@IT IV - Remote File Downloading
Asegúr@IT IV - Remote File Downloading
Chema Alonso
 
1 CMPS 12M Data Structures Lab Lab Assignment 1 .docx
1 CMPS 12M Data Structures Lab Lab Assignment 1 .docx1 CMPS 12M Data Structures Lab Lab Assignment 1 .docx
1 CMPS 12M Data Structures Lab Lab Assignment 1 .docx
tarifarmarie
 
Get database properties using power shell in sql server 2008 techrepublic
Get database properties using power shell in sql server 2008   techrepublicGet database properties using power shell in sql server 2008   techrepublic
Get database properties using power shell in sql server 2008 techrepublic
Kaing Menglieng
 
Java jdbc
Java jdbcJava jdbc
Java jdbc
Arati Gadgil
 
Mysql
MysqlMysql
Mysql
Rathan Raj
 
Project Presentation
Project PresentationProject Presentation
Project Presentation
ShariffAyesha
 
Jdbc tutorial
Jdbc tutorialJdbc tutorial
Jdbc tutorial
Dharma Kshetri
 
Introduction to JDBC and database access in web applications
Introduction to JDBC and database access in web applicationsIntroduction to JDBC and database access in web applications
Introduction to JDBC and database access in web applications
Fulvio Corno
 
9 Python programming notes for ktu physics and computer application semester 4
9 Python programming notes for ktu  physics and computer application semester 49 Python programming notes for ktu  physics and computer application semester 4
9 Python programming notes for ktu physics and computer application semester 4
ebindboby1
 
Oracle to MySQL DatabaseLink
Oracle to MySQL DatabaseLinkOracle to MySQL DatabaseLink
Oracle to MySQL DatabaseLink
Osama Mustafa
 
Jdbc ja
Jdbc jaJdbc ja
Jdbc ja
DEEPIKA T
 
Jdbc example program with access and MySql
Jdbc example program with access and MySqlJdbc example program with access and MySql
Jdbc example program with access and MySql
kamal kotecha
 
How to connect sql server to oracle server
How to connect sql server to oracle serverHow to connect sql server to oracle server
How to connect sql server to oracle server
Gustavo Bernardo
 
Playing With (B)Sqli
Playing With (B)SqliPlaying With (B)Sqli
Playing With (B)Sqli
Chema Alonso
 
Tuning and optimizing webcenter spaces application white paper
Tuning and optimizing webcenter spaces application white paperTuning and optimizing webcenter spaces application white paper
Tuning and optimizing webcenter spaces application white paper
Vinay Kumar
 
DBMS LAB FILE1 task 1 , task 2, task3 and many more.pdf
DBMS LAB FILE1 task 1 , task 2, task3 and many more.pdfDBMS LAB FILE1 task 1 , task 2, task3 and many more.pdf
DBMS LAB FILE1 task 1 , task 2, task3 and many more.pdf
AbhishekKumarPandit5
 
Asegúr@IT IV - Remote File Downloading
Asegúr@IT IV - Remote File DownloadingAsegúr@IT IV - Remote File Downloading
Asegúr@IT IV - Remote File Downloading
Chema Alonso
 
1 CMPS 12M Data Structures Lab Lab Assignment 1 .docx
1 CMPS 12M Data Structures Lab Lab Assignment 1 .docx1 CMPS 12M Data Structures Lab Lab Assignment 1 .docx
1 CMPS 12M Data Structures Lab Lab Assignment 1 .docx
tarifarmarie
 
Get database properties using power shell in sql server 2008 techrepublic
Get database properties using power shell in sql server 2008   techrepublicGet database properties using power shell in sql server 2008   techrepublic
Get database properties using power shell in sql server 2008 techrepublic
Kaing Menglieng
 
Project Presentation
Project PresentationProject Presentation
Project Presentation
ShariffAyesha
 
Introduction to JDBC and database access in web applications
Introduction to JDBC and database access in web applicationsIntroduction to JDBC and database access in web applications
Introduction to JDBC and database access in web applications
Fulvio Corno
 
9 Python programming notes for ktu physics and computer application semester 4
9 Python programming notes for ktu  physics and computer application semester 49 Python programming notes for ktu  physics and computer application semester 4
9 Python programming notes for ktu physics and computer application semester 4
ebindboby1
 
Oracle to MySQL DatabaseLink
Oracle to MySQL DatabaseLinkOracle to MySQL DatabaseLink
Oracle to MySQL DatabaseLink
Osama Mustafa
 
Ad

Recently uploaded (20)

Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Network Security. Different aspects of Network Security.
Network Security. Different aspects of Network Security.Network Security. Different aspects of Network Security.
Network Security. Different aspects of Network Security.
gregtap1
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Learn the Basics of Agile Development: Your Step-by-Step Guide
Learn the Basics of Agile Development: Your Step-by-Step GuideLearn the Basics of Agile Development: Your Step-by-Step Guide
Learn the Basics of Agile Development: Your Step-by-Step Guide
Marcel David
 
Asthma presentación en inglés abril 2025 pdf
Asthma presentación en inglés abril 2025 pdfAsthma presentación en inglés abril 2025 pdf
Asthma presentación en inglés abril 2025 pdf
VanessaRaudez
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Image processinglab image processing image processing
Image processinglab image processing  image processingImage processinglab image processing  image processing
Image processinglab image processing image processing
RaghadHany
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Network Security. Different aspects of Network Security.
Network Security. Different aspects of Network Security.Network Security. Different aspects of Network Security.
Network Security. Different aspects of Network Security.
gregtap1
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Learn the Basics of Agile Development: Your Step-by-Step Guide
Learn the Basics of Agile Development: Your Step-by-Step GuideLearn the Basics of Agile Development: Your Step-by-Step Guide
Learn the Basics of Agile Development: Your Step-by-Step Guide
Marcel David
 
Asthma presentación en inglés abril 2025 pdf
Asthma presentación en inglés abril 2025 pdfAsthma presentación en inglés abril 2025 pdf
Asthma presentación en inglés abril 2025 pdf
VanessaRaudez
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Image processinglab image processing image processing
Image processinglab image processing  image processingImage processinglab image processing  image processing
Image processinglab image processing image processing
RaghadHany
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Ad

SQL2SPARQL

  • 1. Alexandru Ioan Cuza University Faculty of Computer Science SQL2SPARQL Students: Dron Alexandru ISS21 Ifrim Alexandru ISS21
  • 2. 1.Install Guide – Preparing the environment Summary 1.1 MySql install 1.1.1 Create database 1.1.2 Import a sql file to database 1.2 JRE install 1.2.1 Set Path 1.3 Jena install 1.4 .NET framework 1.1 MySql install You can get MySQL from the following address: http://dev.mysql.com/downloads/mysql, select the right version for you, download and install it. Go to MySQL folder and run mysql_installservice.bat to set mysql server to be a service on the windows platform, if the installer didn`t already do that for you. Then you can check if MySql service is running in Administrative Tools/Services tab. 1.1.1 Create database Go to your MySql installation folder using Command Prompt and into the bin folder. Type in the following command : mysql.exe -u root -p (the default password is blank and the user is "root"). If everything was installed correct, now you are on the mysql command line tool. To create our database, simply type: create database facultate 1.1.2 Import a sql file to database First, we have to tell to mysql what database we want to use, to do that we have to type: use facultate (the message from the MySql server should be "Database changed").
  • 3. To import our table structure and data, open the file called bd.sql, copy & paste the sql code to console. Alternatively you can type : quit, move the bd.sql file to the bin folder and type in the windows command prompt : mysql -u root -p facultate < bd.sql Another method to import is to use the phpmyadmin script, but you will need to have Apache and PHP installed. If you want to see if the import worked, in mysql command line, after you select what database to use, you can type: show tables; Fig.1.1.1 1.2 JRE install The installation of the Java Runtime Environment (JRE) is straight forward, just go to the following url http://www.java.com/en/download/index.jsp, download and install it. 1.2.1 Set Path To verify that the java command is environmental, open the Command Prompt from windows and type: java If you get the “'java' is not recognized as an internal or external command, operable program or batch file”, you will have to set the Path to the java.exe file. Open the System tab from Control Panel, click on the Advanced System Properties, select the Environment Variables. Edit the Path with the path to the folder bin in your java installation. (The default is : C:Program Files (x86)Javajre6bin on windows 7 64biti). Don`t forget to add ; after the other paths that are written in there(Fig. 1.2.1). 1.3 Jena install To install Jena Framework go to the jena official page and download the latest version: http://sourceforge.net/projects/jena/files/Jena/.
  • 4. 1.4 .NET framework And of course, to run our app you will also need to have the .NET framework. Download the latest version from the microsoft.com website. Fig.1.2.1 2. Application Summary 2.1 SQL2SPARQL – application short description 2.2 Transforming sql database tables into rdf format 2.3 How does the application work? 2.3.1<prefixes>, <type declarations> 2.3.2 <sparql select clause>, <select fields declarations> 2.3.3<auxiliary fields declarations> 2.3.4<filters>
  • 5. 2.1 SQL2SPARQL – application short description The „sql2sparql‟ application transforms sql queries that are entered by the user, into sparql queries that will give the same result over the rdf transformation of the database (by following some rules listed under). The application is a console application that takes an input from the user representing a sql query, runs the query over „facultate‟ mysql database and shows the results, and then converts the query to sparql, that is ran over the rdf file using jena. 2.2 Transforming sql database tables into rdf format. There are some rules that we used when transforming the sql database tables into rdf format. One of them (needed by the application to convert from sql queries to sparql queries) is to write in a file, for every table, a line with the following format: tableName[http://rdfTableNamespace]=fieldName1;fieldName2;… As example for the table „persoana‟ with the fields: id, nume, prenume, data_nasterii, sex; the file should contain the following line: persoana[http://facultate.wad/persoana]=id;nume;prenume;data_nasterii;sex; (The rdf would contain in this case a declaration of the namespace xmlns:persoana=http://facultate.wad/persoana). This could have also been declared in the rdf file in the following record: <persoana:prototype> <persoana:id></persoana:id> <persoana:nume></persoana:nume> <persoana:prenume></persoana:prenume> <persoana:data_nasterii></persoana:data_nasterii> <persoana:sex></persoana:sex> </persoana:prototype> but parsing a smaller file would be more efficient and easier. Each record from the table will appear in the rdf file as: <tableName:record>, and its values will contain the fields values as <tableName:tableField>. If the field type is of int value, then this will also be declared in the rdf record (required for conditioning where/filter). For example, the following record from persoana (from the sql database):
  • 6. +----+---------------+---------------+-------------------+-----+ | id | nume | prenume | data_nasterii | sex | +----+---------------+---------------+-------------------+-----+ | 12 | campeanu | loredana | 1985-08-03 | F | +----+---------------+---------------+-------------------+-----+ In the rdf file will look like this: <persoana:record> <persoana:id rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">12</persoana:id> <persoana:nume>campeanu</persoana:nume> <persoana:prenume>loredana</persoana:prenume> <persoana:data_nasterii>1985-08-03</persoana:data_nasterii> <persoana:sex>F</persoana:sex> </persoana:record> 2.3 How does the application work? The application takes an input from the user which represents the sql query over the „facultate‟ database (which was also manually converted to „facultate.rdf‟ using the rules listed above). This can be entered on multiple lines (such as in mysql console application), and will stop reading only if „;‟ is the last non-space character on the line. The command is then run over „facultate‟ database, and the results will be displayed in the console. If any errors appear the application stops, since the query is most probably invalid, and the resulting sparql query will be the same. In order to convert the sql query to a sparql query that will work over „facultate.rdf‟ and show the same result that the sql query returns over „facultate‟ database, the input goes to several steps. Step 1 In the first step the sql query is parsed into a dictionary with the keys “select”, “from”, “where” and “alias” (which is set only for nested selects). The values of the keys are strings that contain the entire „select‟, „from‟ and respectively „where‟ clauses of the query (except nested select where the value is a dictionary with the same keys). This is done by splitting the entire entered query at words such as „select‟, „from‟ and „where‟. The „where‟ key might be missing in case no „where‟ clause was entered. e.g.: “select * from persoana where persoana.id > 10” => [select = “*”; from=”persoana”; where=” persoana.id > 10”];
  • 7. Step 2 In the second step some more info is collected from the dictionary prepared in step 1. For the from clause, a new dictionary is created that contains the used tables and their aliases (the dictionary keys will be the table aliases, or their name if no alias is set, and their values will be the table names). This is done by splitting the „from‟ value into words (the split is made after spaces as well as after „”,” and operators (such as „<‟, „>=‟, etc.), and taking the first (table name) and last values (alias) from each group of words separated by commas (the second word from a group might be „AS‟). e.g.: “[from] persoana per1, persoana as per2, sex” => [per1=”persoana”; per2=”persoana”; sex=”sex”]; For the select clause there is also a dictionary created which contains the fields and aliases that will appear in the final result. In this case the dictionary keys will be the field names (e.g.: persoana.id) while the values will be the aliases (for the ease of use in further steps). If “*” is encountered in the „select‟ clause then all the fields belonging to the „from‟ tables will be added into the dictionary. The list of fields that belong to a table are retrieved from the conversion file described at „Transforming sql database tables into rdf format‟. e.g.: “[select] *” (from=[persoana=”persoana”]) => [persoana.id=”persoana.id”; persoana.nume=”persoana.nume”, persoana.prenume=”persoana.prenume”; persoana.sex=”persoana.sex”; persoana.data_nasterii=”persoana.data_nasterii”]; For the where clause 1 list (array) and 1 dictionary are created. The list holds the filter statements (expr1 operator expr2), while the other will hold the fields that are used in these expressions, but which should not appear in the final result. The filter statements can be combined by „and‟ and „or‟, which are modified to “&&” and “||” for sparql. The filters list will have as the first element the left side expression of a filter statement, the second will be the operator of the statement and the third will be the right side of the statement. If there are more statements then there will be a 4 th element which will be either “&&” or “||”, followed by at least 3 more objects composing a new filter statement. Each „variable‟ found in expr1 or expr 2 will be formatted as “?tableAlias_tableField”, and if the select dictionary does not include them then they‟re added to the auxiliary fields dictionary as [tableAlias.tableField = “?tableAlias_tablefield”]; e.g.: “[where] persoana.id > 10 and persoana.id+3<=15” (select=[persoana.nume=persoana.nume]) => (filters){?persoana_id, >, 10, &&, ?persoana_id+3, <=, 15}; (auxFields)[persoana.id=?persoana_id];
  • 8. Step 3 In the 3rd step the sparql query is prepared using the info gathered and prepared at the previous step. The sparql query will have the form: <prefixes> SELECT <sparql select clause> WHERE { <type declarations> . <‟select‟ fields declarations> . <auxiliary fields declarations> FILTER ( <filters> ) } 2.3.1<prefixes>, <type declarations> The prefixes are created from the dictionary created at step 2 for the „from‟ clause. This is done by going through the entire dictionary and getting the table names used in the „from‟ clause. Using the file that describes the conversion rules from the database to rdf the namespace for that table is retrieved from the file (the file is actually read at application startup and stored in a dictionary for further use). The prefix for a table „t‟ with alias „a‟ will look like: “PREFIX a: <namespaceForT>”. For every included table, a new value is also created in the type declarations: “tableAlias a tableAlias:record”; e.g.: (from)[persoana=persoana; s=student] => PREFIX persoana: <http://facultate.wad/persoana> PREFIX s: <http://facultate.wad/student> 2.3.2 <sparql select clause>, <select fields declarations> The sparql select clause and the type declarations are created by going through the dictionary created at step 2 for the „select‟ clause. If the fields contained in the dictionary contain aliases (the value of the alias does not contain “.”) then the select clause for sparql will append the „field‟ “?alias”, otherwise it will append “?tableAlias.fieldName”. The “field declarations” will have the form: “?tableAlias tableAlias:tableField „field‟”. e.g.: “SELECT * from ersoana” => <sparql select clause> = “?persoana_id ?persoana_nume ?persoana_prenume ?persoana_data_nasterii” <field declarations> = “?persoana persoana:id ?persoana_id .
  • 9. ?persoana persoana:nume ?persoana_nume . ?persoana persoana:prenume ?persoana_prenume . ?persoana persoana:data_nasterii ?persoana_data_nasterii . ?persoana persoana:sex ?persoana_sex” 2.3.3<auxiliary fields declarations> These are constructed the same way as the <field declarations>, but from the contents of the dictionary created at step 2 for the „where‟ clause. 2.3.4<filters> The filters are created by simply appending the values from the list of filters created at step 2 for the „where‟ clause, everything being prepared at that step. e.g.: “[where] persoana.id > 10 and persoana.id+3<=15” => “?persoana_id > 10 && ?persoana_id+3 <= 15}”; After the sparql query is prepared, it is written out on the console for the user to see. The query is also written to a file (sparql), and jena is launched taking as parameters the query file and the rdf file (facultate.rdf), showing the results of the sparql query. Launching jena with the given parameters is done through a bat file with the following content: “set JENAROOT=[PATH TO JENA DIR] cmd.exe /K "[PATH TO JENA ARQ BAT} --data=facultate.rdf --query=sparql"”. 3. Application overview Summary 3.1 Console application 3.2 Windows Forms application 3.1 Console application To run our example or another in accordance with our rules, you will have to modify some files. First open with a text editor the file called “jena_facultate_test.bat”. Set the path to your jena installation folder, to the “arq.bat” file from the bin folder in your jena and your rdf file. You will also need to add the “tables” in the file named “database_fields.txt”, based on our rules, if you use another example.
  • 10. Another thing to know, is that the application is using to connect to MySql the user named “root” and no password. The database name that the app is looking for is “facultate”. You can see in Annex 1 some examples run on the console application. 3.2 Windows Forms application The windows forms application is more easy to use, and that was our goal in the first place, but we like the console application as well. The first thing we will have to do when you run the app is to go to the “Configurare” section. Here you have your options for the MySql connection : user, pass, database, server. If the server box is left empty, the default is “localhost”. Sparql options are bellow and you must set the path to jena (double click on the textbox field), to the rdf file and to the prefix file (database_name.txt in our example). See Fig. 3.2.1. Fig. 3.2.1 The main application is very straightforward, you will have to type the sql query like in the Fig. 3.2.2, press „ruleaza” and the app will do the magic.
  • 11. Fig. 3.2.2 Some video examples with the structure, console and windows apps are available at http://www.dron.ro/wad. The structure of the database/rdf file is in Annex 2.
  • 16. Annex 2 Database structure RDF <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:sex="http://facultate.wad/sex" xmlns:persoana="http://facultate.wad/persoana" xmlns:studii="http://facultate.wad/studii" xmlns:student="http://facultate.wad/student" xmlns:profesor="http://facultate.wad/profesor"> <!-- xsd="http://www.w3.org/2001/XMLSchema#" --> <sex:prototype> <sex:cod></sex:cod> <sex:nume></sex:nume> </sex:prototype>
  • 17. <persoana:prototype> <persoana:id></persoana:id> <persoana:nume></persoana:nume> <persoana:prenume></persoana:prenume> <persoana:data_nasterii></persoana:data_nasterii> <persoana:sex></persoana:sex> </persoana:prototype> <studii:prototype> <studii:cod></studii:cod> <studii:an></studii:an> <studii:categorie></studii:categorie> </studii:prototype> <student:prototype> <student:id></student:id> <student:studii></student:studii> <student:grupa></student:grupa> </student:prototype> <profesor:prototype> <profesor:id></profesor:id> </profesor:prototype> Database_fields.txt – Prefixes/Conventions sex[http://facultate.wad/sex]=cod;nume; persoana[http://facultate.wad/persoana]=id;nume;prenume;data_nasterii;sex; profesor[http://facultate.wad/profesor]=id; student[http://facultate.wad/student]=id;studii;grupa; studii[http://facultate.wad/studii]=cod;an;categorie;