Application Design Documentseproj/2006-2007/shaevich/ADD.doc · Web viewSet_Field_Name(string...
Transcript of Application Design Documentseproj/2006-2007/shaevich/ADD.doc · Web viewSet_Field_Name(string...
SmartSQL
Application Design Document
Application Design Document
Faculty of Engineering ScienceSoftware Engineering Program
Fourth Year Engineering Project
SmartSQL
SmartSQL1
SmartSQL
Application Design Document
Table of Contents:
1. Use Cases..........................................................................................32. Data Model......................................................................................20
2.1. Description of Data Objects............................................202.2. Data Objects Relationships.............................................272.3. Databases.........................................................................29
3. Behavioral Analysis........................................................................323.1. Sequence Diagrams.........................................................323.2. Events................................................................................393.3. States.................................................................................39
4. Object Oriented Analysis................................................................404.1. Class Diagrams..................................................................404.2. Class Description...............................................................444.3. Packages............................................................................584.4. Unit Testing.......................................................................59
5. System Architecture........................................................................716. User Interface Draft.......................................................................727. Testing.............................................................................................868. Task List..........................................................................................879. Appendix – Example of processing NLP sentence......................89
SmartSQL2
SmartSQL
Application Design Document
1. Use Cases1.1.Use Case no. 1: Creating SQL select queries by SQL builder
The story: The user selects the relevant parameters for his query and the system response with the correct SQL query and his execution.Primary Actors: System Administrator, UserStakeholders and Interests:
System Administrator: wants to create SQL query User: wants to create SQL query
Pre-conditions: Relevant tables and fields exist in database.Post-conditions: SQL query was generated correctly and executed.
Main Success Scenario: Select query.Actor Action (or Intention) System Responsibility
1. The user chooses Select query option.
3. The user selects table.
5. The user selects fields to use in the query.
6. For each field user sets: a. If the field is viewable.b. User enters field presentation name.
7. The User sets if “Distinct” used.
8. The User sets if “Extra Condition” used (adding where condition in free text).
9. User asks to see the query.
11. User asks to execute the query.
2. The system displays special panel with table’s names.
4. The list of table's fields are populated
10. The system shows generated SQL query.
12. The system executes SQL query
SmartSQL3
SmartSQL
Application Design Document
and shows result.Alternative Flow 1 – JOIN query:
Note: steps 4-7 can be executed several times.
Alternative Flow 2- Selecting additional query parameters:
Actor Action (or Intention) System Responsibility
1. User defines if the field is used in “where”, “Order by”, “Group by” ,”avg”, “min”, “max”, ”count”.
2. If “where” selected, user enters condition.
SmartSQL4
Actor Action (or Intention) System Responsibility
4. User adds another table.
5. User chooses joined type.
6. User chooses target table for join.
7. User chooses field name for join on both tables.
SmartSQL
Application Design Document
1.2.Use Case 2: Creating new table in database or changing/deleting existing one by SQL Builder.
The story: The user selects or inputs all the relevant data to create a new table.Primary Actors: System Administrator, User.Stakeholders and Interests:
System Administrator: wants to create/alter/drop table in database. User: wants to create/alter/drop table in database.
Pre-conditions: Relevant table and fields exist in case of alter/drop.Post-conditions: SQL query was generated correctly and executed.Main Success Scenario: Table Creation:
Actor Action (or Intention) System Responsibility
1. The user chooses creation of new table option.
3. The user enters new table name.4. The user enters new field parameters(this done as number of fields we want to add):
a. Field name.b. Field type.c. Allow null.d. Is primary key.e. Is foreign key and to which table
and field.
5. User asks to see the query.
7. User asks to execute the query.
2. The system displays the special (creation table) panel.
6. The system shows generated SQL query.
8. The system executes SQL
SmartSQL5
SmartSQL
Application Design Document
query.
Alternative Flow 1 – Alter table (rename, retype of fields):
SmartSQL6
Actor Action (or Intention) System Responsibility
1. The user chooses the alter table option.
3. The User chooses alter operation to perform from the list.
4. The user chooses the table to alter.
6. The user chooses field to update.7. The user enters new type or/and new name.
8. User asks to see the query.
10. The user requests the ”alter” to be executed.
The system displays the special panel.
5. The system displays table’s fields.
9. The system shows generated SQL query.
11. The system executes SQL query.
SmartSQL
Application Design Document
Alternative Flow 2 – Alter table (add field):
Alternative Flow 3 – Alter table (delete field):
SmartSQL7
Actor Action (or Intention) System Responsibility
6. The user enters new field parameters(this done as number of fields we want to add):
a. Field name.b. Field type.c. Allow null.d. Is primary key.e. Is foreign key and to which
table and field.
Actor Action (or Intention) System Responsibility
6. The user chooses field to delete.
7. User asks to see the query.
9. The user requests the ”alter” to be executed.
11. The user responds for the system request.
8. The system shows generated SQL query.
10. The system asks user if he sure that he wants this field to be deleted.
12 The system executes SQL query.
SmartSQL
Application Design Document
SmartSQL8
SmartSQL
Application Design Document
Alternative Flow 4 – Delete table:
Alternative Flow 5 – Delete table (can not be performed):
SmartSQL9
Actor Action (or Intention) System Responsibility
1. The user chooses delete table option.
The user chooses the table to delete.
4. The user requests the update to be executed.
6. The user responds for the system request.
2. Special panel displayed.
5. The system displays warning if the user is sure he wants to delete the table.
7. The system shows generated SQL query and updates the table.
Actor Action (or Intention) System Responsibility
5. The system displays message the table can not be deleted in case his primary key is foreign key in another table.
SmartSQL
Application Design Document
1.3.Use Case 3: Change data records by SQL Builder.
The story: The user selects or inputs all the relevant data to perform Insert/Update/Delete query. Primary Actors: System Administrator, User.Stakeholders and Interests:
System Administrator: wants to Insert/Update/Delete records in table. User: wants to Insert/Update/Delete records in table.
Pre-conditions: Relevant table and fields exist.Post-conditions: SQL query was generated correctly and executed.Main Success Scenario: Insert record:
Actor Action (or Intention) System Responsibility
1. The user chooses Insertion operation.
3. The user selects the table.4. The user selects the field.5. The user enters field value.*(steps 4-5 executed as number of fields we want to insert)
6. User asks to see the query.
8. User asks to execute the query.
2. The system displays the special panel.
7. The system shows generated SQL query.
9. The system executes SQL query.
SmartSQL10
SmartSQL
Application Design Document
Alternative Flow 1 – Update records (not using where):
Actor Action (or Intention) System Responsibility
1. The user chooses Update operation.
3. The user selects the table.4. The user selects the field.5. The user enters field value.*(steps 4-5 executed as number of fields we want to update)
6. User asks to see the query.
8. User asks to execute the query.
2. The system displays the special panel.
7. The system shows generated SQL query.
9. The system executes SQL query.
SmartSQL11
SmartSQL
Application Design Document
Alternative Flow 2 – Update records (using where):Actor Action (or Intention) System Responsibility
6. The user selects the field to use in where.7. The user enters the condition*(steps 6-7 executed as number of fields we want to use in where)8. The user enters extra condition (optionally). 9. User asks to see the query.
11. User asks to execute the query.
10. The system shows generated SQL query.
1. The system executes SQL query.Alternative Flow 3 – Delete records:Actor Action (or Intention) System Responsibility
1. The user chooses Delete operation.
3. The user selects the table.4. The user selects the field to use in where.5. The user enters the condition*(steps 4-5 executed as number of fields we want to use in where)6. The user enters extra condition (optionally).
7. User asks to see the query.
9. User asks to execute the query.
2. The system displays the special panel.
8. The system shows generated SQL query.
SmartSQL12
SmartSQL
Application Design Document
10. The system executes SQL query.1.4.Use Case 4: Generating SQL from NL.
The story: The user inputs request in free language and the system generates the SQL query and executes it.Primary Actors: User Stakeholders and Interests:
User: wants to create and execute SQL queryPre-conditions: Relevant tables, fields and schema exist in database. The database was analyzed and keywords were extracted.Post-conditions: SQL query was generated and executed correctly.Main Success Scenario:
Actor Action (or Intention) System Responsibility
1. The user inputs question in natural language in the input field.
2. The system checks whether the given NL query has already been saved. If it has been, the system returns the corresponding saved SQL query.
3. Else, the system tags the sentence.4. In order to determine the query type, the
system will find it in query_type_db1 xml.5. For each found noun, the system searches it
in key_words _db2 xml. If there are key words in the sentence, the system will not refer to them as fields or tables.
6. The system will check whether there are value patterns in the given sentence by looking at db_values3 xml.
7. For each noun that was retrieved from the sentence and filtered by key_words_db xml, the system will check whether there are fields or tables that the current noun may
1 query_type_db.xml – XML which holds all the words that can refer to a query type. For example: for query type select, there can be words such as “give”, “list”, “show”, etc.2 key_words_db.xml - XML which holds all the words that can refer to all key words of SQL, such as: AND, OR, MAX, MIN, ORDER BY, GROUP BY, etc. For example: for MAX the words would be: “the most”, “biggest”, “maximal”, etc.3 db_values.xml – XML which holds for each table and each field its unique values in the database.
SmartSQL13
SmartSQL
Application Design Document
11. User chooses to save the query.
refer to by looking at field_conversion4 and table_conversion5 xmls correspondingly.
8. The system generates corresponding SQL query.
9. The system shows generated SQL query.
10. SQL query executes and the system shows results.
12. The system saves the query.
Alternative Flow 1: Misunderstanding.Actor Action (or Intention) System Responsibility
4. The user changes his question according to the presented message by rewriting the question or by choosing one of the presented choices.
3. If the system, after searching the query_type_db , key_words_ db, db_values, field_conversion and table_conversion, doesn’t understand the desired query: The system notifies the user about the problem and asks him to reformulate the question (possibly presenting options)
5. The system analyzes the question again.6. The system generates corresponding SQL query.7. The system shows generated SQL
4 field_conversion.xml – XML which holds all the possible words that refer to the specific field in the database.5 table_conversion.xml – XML which holds all the possible words that refer to the specific table in the database.
SmartSQL14
SmartSQL
Application Design Document
9. User chooses to save the query.
query.8. SQL query executes and the system shows results.
10. The system saves the query.Note: steps 3-5 can be executed several times
SmartSQL15
SmartSQL
Application Design Document
1.5.Use Case 5: Opening saved NL queries.
The story: The user loads saved natural language query from the list.Primary Actors: User Stakeholders and Interests:
User: wants to open and execute NL query.Pre-conditions: Query was previously saved in the system. Post-conditions: SQL query was generated and executed correctly.Main Success Scenario:
Actor Action (or Intention) System Responsibility
1. The user wants to open saved NL query.
3. The user chooses query from the list.
7. User asks to see the result.
2. The system displays a window with a list of saved queries referring to the current active database.
4. The system turns to the saved queries DB and search for the desired query.
5. If the query exists in the DB, the system generates corresponding SQL query.
6. The system shows generated SQL query.
8. SQL query executes and the system shows results.
SmartSQL16
SmartSQL
Application Design Document
Use Case no. 6: System Administration.
The story: System administrator adds new database to systems domain or adds new user to system.Stakeholders and Interests:
System administrator: Wants to login to the system.Pre-conditions: System administrator logged in to the system.Post-conditions: Desired operations executed successfully.
Main Success Scenario: Adding database.
Actor Action (or Intention) System Responsibility
1. Administrator wishes to add new database to the systems domain.
3. Administrator chooses database to add.
2. Appropriate window is shown.
4. The system performs database adding and displays appropriate message.
SmartSQL17
SmartSQL
Application Design Document
Alternative Flow 2: Remove database.
Actor Action (or Intention) System Responsibility
1. Administrator wishes to remove exist database from the systems domain.
3. Administrator chooses database to remove.
2. Appropriate window is shown.
4. The system performs database removing and displays appropriate message.
Alternative Flow 3: Adding new user-succeeded.
Actor Action (or Intention) System Responsibility
1. Administrator wishes to add new user to the systems.
3. Administrator enters new user parameters: name, password and status (user or administrator).
2. Appropriate window is shown.
4. The system performs adding new user and displays appropriate message.
SmartSQL18
SmartSQL
Application Design Document
Alternative Flow 4: Adding new user - failed (user exists).
Actor Action (or Intention) System Responsibility
1. Administrator wishes to add new user to the systems.
3. Administrator enters new user parameters: name, password and status (user or administrator).
2. Appropriate window is shown.
4. The system notifies the user already subscripted to the system.
Note: steps 3-4 can be performed several times
Alternative Flow 5: Adding new user-failed (wrong parameters).
Actor Action (or Intention) System Responsibility
1. Administrator wishes to add new user to the systems.
3. Administrator enters new user parameters: name, password and status (user or administrator).
2. Appropriate window is shown.
4. The system notifies that one of inputs is bad (for example: password to short).
Note: steps 3-4 can be performed several times
SmartSQL19
SmartSQL
Application Design Document
Alternative Flow 6: Update XML Database of database scheme structure.
Actor Action (or Intention) System Responsibility
1. Administrator wishes to update the database (XML) of database scheme structure.
3. Administrator chooses database to update.
2. Appropriate window is shown.
4. The system performs updating of database XML and displays appropriate message.
Alternative Flow 7: Update XML Database of database glossaries (keywords).
Actor Action (or Intention) System Responsibility
1. Administrator wishes to update the database (XML) of database keywords.
3 Administrator adds or removes keyword
2. Appropriate window is shown.
4. The system performs updating of database XML.
SmartSQL20
SmartSQL
Application Design Document
Alternative Flow 8: Update XML Database of database glossaries (query types).
Actor Action (or Intention) System Responsibility
1. Administrator wishes to update the database (XML) of database query types.
3 Administrator adds or removes query types or their values
2. Appropriate window is shown.
4. The system performs updating of database XML.
Alternative Flow 9: Update XML Database of database glossaries (conversion tables – alternative names for database tables and fields).
Actor Action (or Intention) System Responsibility
1. Administrator wishes to update the database (XML) of database conversion tables.
4 Administrator adds or removes alternatives for tables and fields
2. Appropriate window is shown.
4. The system performs updating of database XML.
SmartSQL21
SmartSQL
Application Design Document
Alternative Flow 10: Update XML Database of database glossaries (fields values – values of fields in database).
Actor Action (or Intention) System Responsibility
1. Administrator wishes to update the database (XML) of database fields values.
3. Administrator adds or removes values for database fields
2. Appropriate window is shown.
4. The system performs updating of database XML.
SmartSQL22
SmartSQL
Application Design Document
Use Case no. 7: Login.
The story: The user enters his user name and password and the system lets the user in and allows him to perform different operations according to his status (user or administrator).Stakeholders and Interests:
User: Wants to login to the system. System administrator: Wants to login to the system.
Pre-conditions: User parameters (name, password) are saved in the system.Post-conditions: The user entered to the systemMain Success Scenario: Success login.
Actor Action (or Intention) System Responsibility
1. User enters his name and password.
2. User got access to system according to his status (user or administrator).
Alternative Flow 2: Login failed.
Actor Action (or Intention) System Responsibility
1. User enters his name and password.
2. User enters his name and password again.
2. The user was not identified by the system and he asked to try again.
4. User got access to system according to his status (user or administrator).
Note: steps 2-3 can be performed several times
SmartSQL23
SmartSQL
Application Design Document
2. Data Model2.1. Description of Data Objects
Query_Manager (SQL Builder)
Responsible for managing all the operations in SQL Builder, manages Data Objects: Query, Field and Table and responsible for constructing SQL query.
Attributes: m_tables: ArrayList- Holds all Table objects that was created in the
builder. m_fields: ArrayList- Holds all Field objects that was created in the
builder. m_query_string: string- Holds SQL query string that was generated by
“Build_Query()” method. m_db_handler: Database_Handler_Interface-Instance of
Database_Handler which supplies interface to all operations with DBMS. m_query: Query –Instance of Query object.
Query
Responsible for holding query parameters which will be used in query creation by Query_Manager, also holds parameters which
describes query’s correctness status. This object is created by Query_Manager in its constructor. SQL_Builder has only one instance of this object.
Attributes: m_type: string - Holds query type, for example: Select, Create ,etc. m_alter_type: string- Holds “Alter” query type,possible
types:Add,Drop,Change,Modify. m_status: string – Describes query’s correctness current status, in
case of incorrectness describes the source of the problem. m_query_valid: boolean – Holds boolean representation of
previous attribute. m_where_extra_condition: string – Holds “where” free text condition
(not assigned to some field).
SmartSQL24
SmartSQL
Application Design Document
m_distinct_used: boolean – Holds true if “Distinct” parameter used in select query.
Table (SQL Builder)
Its attributes describes “join” parameters which will be used in query creation by Query_Manager. This object is created by Query_Manager each time we add table to SQL query.
Attributes: m_name: string - Holds table’s name. m_join_type: string - Holds join type of this table to some other
one, possible types: inner join, left outer join, right outer join. m_my_join_field: string - Holds column name to use in join from
my table. m_target_join_field: string - Holds column name to use in join
from other table. m_target_join_tabel: string - Holds other table name to use in
join.
Field (SQL Builder)
Holds field parameters which describe field usage and responsibilities in the query. They will be used in query creation by Query_Manager. This object is created by Query_Manager each time we add field to SQL query.
Attributes: m_name: string - Holds field’s name. m_viewable: boolean – Holds true if we want to see this column in
“Select” query. m_new_name: string - Holds field’s new name in case of “Alter”
query. m_used_in_where: boolean – Holds true if this field is used in
“Where” condition. m_where_condition: string - Holds where condition for this field. m_used_in_order_by: boolean – Holds true if this field is used in
“Order by”
SmartSQL25
SmartSQL
Application Design Document
m_used_in_OrderBy: boolean – Holds true if this field is used in “Order by”
m_used_in_DescOrder: boolean – Holds true if this field is used in “Order by” in descending order.
m_used_in_GroupBy: boolean – Holds true if this field is used in “Group by”
m_used_in_sum: boolean – Holds true if this field is used in “sum” function.
m_used_in_min: boolean – Holds true if this field is used in “ min ” function.
m_used_in_max: boolean – Holds true if this field is used in “ max ” function.
m_used_in_count: boolean – Holds true if this field is used in “count” function.
m_used_in_avg: boolean – Holds true if this field is used in “ avg ” function.
m_type: string - Holds field’s type. m_allow_null: boolean – True if nullable ,used in “Create/Alter”
queries. m_primary_key: boolean – True if primary key, used in
“Create/Alter” queries. m_foreign_key: boolean – True if foreign key, used in “Create/Alter”
queries. m_foreign_key_Table: string – Holds foreign key reference table
name. m_foreign_key_Field: string – Holds foreign key reference field name. m_onDelete_foreignKey_restriction: string – Holds foreign key
restriction if delete operation performed on its reference. m_onUpdate_foreignKey_restriction: string – Holds foreign key
restriction if update operation performed on its reference. m_field_value: string – Holds field’s value, used “Insert/Update”
queries. m_presentation_name: string – Holds field presentation name for the
user, used in “Select” query (the value of “as” operator in SQL).
SmartSQL26
SmartSQL
Application Design Document
NLP_Data_Levels (NLP) Holds tables which represent the databases of the system. They will be used while building the SQL query from NL sentence.
Attributes: m_tables: HashTable - Holds per each table in the DB its fields. The
key of this HashTable is table name, and its value is a list of this table’s fields.
m_connections: HashTable – Holds per each table_name_field_name, list of pairs: <table_name, field_name>. The pairs in this list are the tables and the fields in which the key of the HashTable is a foreign key.
m_query_types: HashTable - Holds for each quey type (such as: Select, Insert, Drop, Alter, etc.) a list of key words that can describe the query type in the natural language. For example, for the query type “Select” there will be words such as: “get”, “give”, “present”, “show”, etc.
m_key_words: HashTable – Holds for each common SQL function, such as: “AND”, “OR”, “SUM”, etc, a list of key words that can describe each of those functions. For example, for the function “AND” there will be words such as: also, as well, in addition, etc.
m_where_part: ArrayList – Holds a list of words which in the sentence indicate that in SQL query should be a “WHERE” part.
m_saved_queries: ArrayList – A list of saved queries. Consists of an original NLP query that was given by the user and its corresponding SQL query that was generating by the system.
m_words_of_tables: HashTable – Holds for each table a list of words that can be written by the user and refer to that specific table.
m_words_of_fields: HashTable - Holds for each table and its every field a list of words that can be written by the user and refer to that specific field.
m_associated_values: HashTable – Holds for each table and its each field a list of its unique values.
m_xml_handler: XML_Handler – An instance of XML_Handler for updating and retrieving information from the XMLs.
m_query_generator : Sql_Builder_Interface – An instance of Sql_Builder_Interface for retrieving fields and tables from SQL Builer.
SmartSQL27
SmartSQL
Application Design Document
Login Manager (Login)
Responsible for managing all users information in the Smart SQL system keep collection of all user.
Attributes: m_users_collection: ArrayList- Holds all Users objects that was
registered in the system. m_xml_login_handler: XML_Login_Handler-Instance of
XML_Login_Handler which supplies interface to all operations with Logins collection (in XML).
User (Login)
Responsible for holding user attributes.
Attributes: m_id: int - Holds user id number, for example: 12345. m_password: string- Holds password of user. m_status: boolean – Holds administration status of user (true if user
with admininistration privilegies, false if user is standart simple user).
Administration_Controller (System Administration)
Responsible for control and managing all database information in the Smart SQL system keep collection of all databases that exist in the system.
Attributes: m_db_collection: ArrayList- Holds all Databases objects that was
exists in the system. m_xml_admin_handler: XML_Administration_Handler-Instance of
XML_Administration_Handler which supplies interface to all operations with Databases collection (in XML).
SmartSQL28
SmartSQL
Application Design Document
Database (System Administration)Responsible for holding database attributes such as DBMS, DB name and other.
Attributes: m_db_type: string - Holds database’s type (Access or SQL Server). m_db_name: string – Holds database’s name string. m_db_path: string - Holds database’s path if m_db_type is Access
and null otherwise.
Login_Manager(Login)
Responsible for managing all users information in the Smart SQL system keep collection of all user.
Attributes: m_users_collection: ArrayList- Holds all Users objects that was
registered in the system. m_xml_login_handler: XML_Login_Handler-Instance of
XML_Login_Handler which supplies interface to all operations with Logins collection (in XML).
User ( Login )
Responsible for holding user attributes.
Attributes: m_name: string - Holds user name String (all user name should be
different), for example: nick_name. m_password: string- Holds password of user. m_status: boolean – Holds administration status of user (true if user
with admininistration privilegies, false if user is standart simple user).
SmartSQL29
SmartSQL
Application Design Document
Administration_Controller (System Administration)
Responsible for control and managing all database information in the Smart SQL system keep collection of all databases that exist in the system.Attributes:
m_db_collection: ArrayList- Holds all Databases objects that was exists in the system.
m_users_collection: ArrayList- Holds all Users objects that was registered in the system.
m_xml_admin_handler: XML_Administration_Handler-Instance of XML_Administration_Handler which supplies interface to all operations with Databases collection (in XML).
m_xml_login_handler: XML_Login_Handler-Instance of XML_Login_Handler which supplies interface to all operations with Logins collection (in XML).
Database (System Administration)
Responsible for holding database attributes such as DBMS, DB name and other.
Attributes: m_db_type: string - Holds database’s type (Access or SQL Server). m_db_name: string – Holds database’s name string. m_db_path: string - Holds database’s path if m_db_type is Access and
null otherwise.
SmartSQL30
SmartSQL
Application Design Document
2.2. Data Objects Relationships
SQL Builder
NLP Analyzer
SmartSQL31
SmartSQL
Application Design Document
Login
System Administration
SmartSQL32
SmartSQL
Application Design Document
2.3. DatabasesAll persistence data will be saved in XML documents.
Class XML_Login_Handler operates with user’s login collection and all user data is held in XML document.Users XML Document will be created in the beginning and updated (by XML_Login_Handler) upon every change in user collection such as add new user or delete user.
Example of Users XML:<users>
<user name="Radi" password="11111" admin_status=true><user name="Vova" password="22222" admin_status=true><user name="Marina" password="33333" admin_status=true><user name="Sasha" password="44444" admin_status=true>
</users>
Class XML_Administration_Handler operates with database collection and all database attributes are held in XML document.Database XML Document will be created in the beginning and updated (by XML_Administration_Handler) upon every change in database collection such as add new DB or Update and Delete DB user.
Example of Database XML:
<DATABASES><Database name="Erez.mdb" type="access" path="Erez.mdb"
active="False" /><Database name="Northwind" type="sql" path="Data Source=MAIN-HOME\SQLEXPRESS;Integrated Security=SSPI;" active="True" />
</DATABASES>
SmartSQL33
SmartSQL
Application Design Document
Example of Key Words DB XML:
This XML is created upon the start of the system, meaning – the administrator adds the new words to this database. Other words can also be added later, during the operation of the system (also by the admin).
The NLP Analyzer uses this database in order to find matching words from the received nlp query.
<KEY_WORDS_DB><OR sign="OR">
<KEY_WORD>or</KEY_WORD> <KEY_WORD>choose</KEY_WORD> <KEY_WORD>between</KEY_WORD> </OR> <AND sign="AND"> <KEY_WORD>and</KEY_WORD> <KEY_WORD>also</KEY_WORD> <KEY_WORD>as well as</KEY_WORD> <KEY_WORD>and also</KEY_WORD> <KEY_WORD>followed by</KEY_WORD> <KEY_WORD>next to</KEY_WORD> <KEY_WORD>along with</KEY_WORD> <KEY_WORD>in addition</KEY_WORD> </AND>
</KEY_WORDS_DB>
Example of Query Type DB XML:This XML is created upon the start of the system, meaning – the administrator adds the new words to this database. Other words can also be added later, during the operation of the system (also by the admin).
The NLP Analyzer uses this database in order to find the type of the given nlp query.
<QUERY_TYPE_DB> <Select> <KEY_WORD>select</KEY_WORD> <KEY_WORD>get</KEY_WORD> <KEY_WORD>give</KEY_WORD>
SmartSQL34
SmartSQL
Application Design Document
</Select> <Insert>
<KEY_WORD>insert</KEY_WORD> <KEY_WORD>put</KEY_WORD> <KEY_WORD>write</KEY_WORD> </Insert>
<QUERY_TYPE_DB>
Example of Where Part XML:This XML is created upon the start of the system, meaning – the administrator adds the new words to this database. Other words can also be added later, during the operation of the system (also by the admin).
The NLP Analyzer uses this database in order to find in the given sentence the where part of the query.
<WHERE_PART> <KEY_WORD>more</KEY_WORD> <KEY_WORD>less</KEY_WORD> <KEY_WORD>smaller</KEY_WORD> <KEY_WORD>over</KEY_WORD> <KEY_WORD>under</KEY_WORD> <KEY_WORD>more</KEY_WORD> <KEY_WORD>equal</KEY_WORD> <KEY_WORD>that</KEY_WORD> <KEY_WORD>such</KEY_WORD> <KEY_WORD>equal</KEY_WORD> <KEY_WORD>after</KEY_WORD> <KEY_WORD>before</KEY_WORD> <KEY_WORD>with</KEY_WORD> <KEY_WORD>where</KEY_WORD> <KEY_WORD>if</KEY_WORD> <KEY_WORD>which</KEY_WORD></WHERE_PART>
SmartSQL35
SmartSQL
Application Design Document
The following XMLs are created for each database:Example of DB Connection XML:This XML is created upon the start of the system, meaning – the administrator adds the new words to this database. Other words can also be added later, during the operation of the system (also by the admin).
The NLP Analyzer uses this database in order to find the connections between tables of the current database.<DB_CONNECTIONS>
<TABLE_CONNECTIONS table_name="Categories" field_name="CategoryID">
<CONNECTION table="Products" /> </TABLE_CONNECTIONS> <TABLE_CONNECTIONS table_name="CustomerCustomerDemo" field_name="CustomerID"> <CONNECTION table="Customers" /> <CONNECTION table="Orders" /> </TABLE_CONNECTIONS>
</DB_CONNECTIONS>
Example of DB Schema XML:This XML is created upon the start of the system, meaning – the administrator adds the new words to this database. Other words can also be added later, during the operation of the system (also by the admin).
This XML represents the schema of the current database.<DB_SCHEMA> <TABLE name="Categories"> <FIELD>CategoryID</FIELD> <FIELD>CategoryName</FIELD> <FIELD>Description</FIELD> <FIELD>Picture</FIELD> </TABLE> <TABLE name="CustomerCustomerDemo"> <FIELD>CustomerID</FIELD> <FIELD>CustomerTypeID</FIELD> </TABLE>
SmartSQL36
SmartSQL
Application Design Document
</DB_SCHEMA>
SmartSQL37
SmartSQL
Application Design Document
Example of DB Values XML:This XML is created upon the start of the system, meaning – the administrator adds the new words to this database. Other words can also be added later, during the operation of the system (also by the admin).
This XML includes values for each table and its every field.
<TABLES> <TABLE name="Employees"> <FIELD name="City"> <KEY_WORD>London</KEY_WORD> <KEY_WORD>Kirkland</KEY_WORD> <KEY_WORD>Redmond</KEY_WORD> <KEY_WORD>Seattle</KEY_WORD> <KEY_WORD>Tacoma</KEY_WORD> </FIELD> <FIELD name="LastName"> <KEY_WORD>Buchanan</KEY_WORD> <KEY_WORD>Dodsworth</KEY_WORD> </FIELD> </TABLE></TABLES>
Example of Table Conversion XML:This XML is created upon the start of the system, meaning – the administrator adds the new words to this database. Other words can also be added later, during the operation of the system (also by the admin).
This XML includes for each table a list of words which can be referred to.<TABLES> <TABLE name="Employees"> <KEY_WORD>employees</KEY_WORD> <KEY_WORD>worker</KEY_WORD> </TABLE> <TABLE name="Customers"> <KEY_WORD>customers</KEY_WORD> <KEY_WORD>clients</KEY_WORD> <KEY_WORD>consumers</KEY_WORD> </TABLE>
SmartSQL38
SmartSQL
Application Design Document
</TABLES>
SmartSQL39
SmartSQL
Application Design Document
Example of Field Conversion XML:This XML is created upon the start of the system, meaning – the administrator adds the new words to this database. Other words can also be added later, during the operation of the system (also by the admin).
This XML includes for each table and it’s every field, a list of words which can be referred to.
<TABLES> <TABLE name="Employees"> <FIELD name="FirstName"> <KEY_WORD>name</KEY_WORD> <KEY_WORD>firstname</KEY_WORD> </FIELD> <FIELD name="City"> <KEY_WORD>city</KEY_WORD> <KEY_WORD>metropolis</KEY_WORD> </FIELD> </TABLE></TABLES>
Example of Saved Queries XML:This XML is created upon the start of the system, meaning – the administrator adds the new words to this database. Other words can also be added later, during the operation of the system (also by the admin).
This XML includes every saved query – its nlp and sql version – for the current database.
<SAVED_QUERIES> <QUERY> <NLP_QUERY>What products are less than 20 in stock</NLP_QUERY> <SQL_QUERY>Select * FROM Products WHERE Products.UnitsInStock < 20</SQL_QUERY> </QUERY> </SAVED_QUERIES>
SmartSQL40
SmartSQL
Application Design Document
3. Behavioral Analysis3.1. Sequence Diagrams
Creating SQL select queries by SQL builder:
SmartSQL41
SmartSQL
Application Design Document
Creating new table in database or changing/deleting existing one by SQL Builder:
SmartSQL42
SmartSQL
Application Design Document
Change data records by SQL Builder:
SmartSQL43
SmartSQL
Application Design Document
Open Saved Query
SmartSQL44
SmartSQL
Application Design Document
Execute New Query
SmartSQL45
SmartSQL
Application Design Document
SmartSQL46
SmartSQL
Application Design Document
SmartSQL47
SmartSQL
Application Design Document
Administration
SmartSQL48
SmartSQL
Application Design Document
Login
SmartSQL49
SmartSQL
Application Design Document
3.2. Events
Not applicable.
3.3. States
State diagram of Building and executing a new query by NLP Analyzer:
SmartSQL50
SmartSQL
Application Design Document
4. Object Oriented Analysis4.1. Class Diagrams
4.1.1.Class Diagram of the package: SQL Builder
SmartSQL51
SmartSQL
Application Design Document
4.1.2.Class Diagram of the package: Database Handler
SmartSQL52
SmartSQL
Application Design Document
4.1.3.Class Diagram of the package: NLP
SmartSQL53
SmartSQL
Application Design Document
SmartSQL54
SmartSQL
Application Design Document
4.1.4.Login Package
SmartSQL55
SmartSQL
Application Design Document
4.1.5.Administration Package
SmartSQL56
SmartSQL
Application Design Document
4.2. Class Description
4.2.1.Classes of package: SQL_Builder
4.2.1.1. Query_Manager
Responsible for managing all the operations in SQL Builder, manages Data Objects: Query, Field and Table and responsible for constructing SQL query.
Operations: Add_Table(string name) : void – creates new Table
object and adds it to table’s collection- m_tables. Pre-condition: Table with the same name is not
exists in table collection. Post-condition: Table was created and added to
table’s collection.
Add_Field(string name) : Field - creates new Field object and adds it to field’s collection- m_fields.
Pre-condition: Field with the same name is not exists in field’s collection.
Post-condition: Field was created and added to field’s collection.
Remove_Table(string name) : void – Removes table with specified name from table’s collection - m_tables.
Pre-condition: Table with specified name exists in the system.
Post-condition: Table with specified name was removed from the system.
Remove_Field(string name) : void – Removes field with specified name from field’s collection - m_fields.
SmartSQL57
SmartSQL
Application Design Document
Pre-condition: Field with specified name exists in the system.
Post-condition: Field with specified name was removed from the system.
Build_Query() : void – Generates SQL query string according to internal states of objects: Query, Tables, Fields.
Pre-condition: internal states of following objects: Query, Tables, Fields is set according to User’s choice.
Post-condition: SQL query was generated correctly.
4.2.1.2. Query (SQL Builder) Responsible for holding query parameters which will be used in query creation by Query_Manager, also holds parameters which describes query’s correctness status. This object is created by Query_Manager in his constructor. SQL_Builder has only one instance of this object.
4.2.1.3.Table (SQL Builder) Its attributes describes “join” parameters which will be used in query creation by Query_Manager. This object is created by Query_Manager each time we add table to SQL query.
4.2.1.4. Field (SQL Builder) Holds field parameters which describe field usage and responsibilities in the query which will be used in query creation by Query_Manager. This object is created by Query_Manager each time we add field to SQL query.
4.2.1.5. Login_Manager Responsible for managing all the operations in Login, manages all User’s Authentication holds collection of user profiles.
Operations: Login(name : string, password : string) : boolean –
check if user with this name and password could enter to the system.
SmartSQL58
SmartSQL
Application Design Document
Pre-condition: User exist and he has permission enter to the system .
Post-condition: User was login and enter to the system. System state will be changed.
Logout():void – user logout from the system. Pre-condition: user was login. Post-condition: User logout from the system all
appropriate data will be saved. Login window will be shown. System state will be changed.
4.2.1.6. User (Login)
Responsible for holding user parameters which will be used in user registration by Administration_Controller and in user authentication by Logi_Manager
4.2.1.7. XML Login Handler (Login) Responsible for giving interaction interface with database of user’s properties in xml document.This Class will be singleton in our system
Operations: Read_All_Users() : User []– return collection of all
users that registries in the system. Pre-condition: XML document with appropriate
information exists. Post-condition: Collection of all users that exist in
the system was returned.
Write_All_Users(users_collection : User []) : void – writes collection of all users that registries in the system into the XML document .
Pre-condition: none. Post-condition: XML document with appropriate
information created.
SmartSQL59
SmartSQL
Application Design Document
4.2.2. Classes of package: Database_Handler4.2.2.1.Database_Handler_Interface
Responsible for giving database interaction interface through DLL (Database_Package) which was supplied by “AlfaTech”.
Operations: Get_Database_Tables_Names() : ArrayList – Returns
list of all table’s names which exists in current DBMS.
Pre-condition: Instance of this connection with specified DBMS are exists.
Post-condition: Correct list was returned.
Get_Columns_Names(string : table_name) : ArrayList – Returns list of all field’s names of specified table.
Pre-condition: Connection established with DBMS and given table is present at database.
Post-condition: Correct list was returned.
Get_Result_Table_From_DB(string : query) : Data_Object – Executes “Select” query and returns result.
Pre-condition: Query is correct. Post-condition: Correct data was returned.
Update_Command(string : query) : bool – Executes all types of queries except “|Select”.
Pre-condition: Query is correct. Post-condition: Query executed correctly.
Get_Instance() : DB_Connection – Returns instance of current connection.
Pre-condition: Connection instance is exists. Post-condition: Returned current connection
instance.
SmartSQL60
SmartSQL
Application Design Document
Get_Instance(string : conn_string) : DB_Connection – Establishing new connection instance.
Pre-condition: Connection string parameters are exists in the computer (DBMS, database name).
Post-condition: Connection instance was created successfully.
clear_Instance() : void – Clears current connection instance.
Pre-condition: none. Post-condition: Cleared successfully.
change_Connection_String(string : conn_string) : void – Changes connection instance.
Pre-condition: Connection string parameters are exists in the computer (DBMS, database name).
Post-condition: New connection instance was created successfully.
SmartSQL61
SmartSQL
Application Design Document
4.2.3.Classes of package: NLP4.2.3.1. NLP_Data_Levels
Responsible identifying different parts of query and extracting query and DB keywords.
Operations: Add_To_Tables(string table_name, string field) : bool
– updates m_tables Hashtable by adding “field” associated with “table”.
Pre-condition: Hashtable object m_tables exists. Post-condition: Field is added and associated with
table in the Hashtable m_tables. Remove_From_Tables(string table_name, string field)
: bool – updates m_tables Hashtable by removing “field” associated with “table”.
Pre-condition: Hashtable object m_tables exists and there is a key “table” in it.
Post-condition: Field is removed from table in the Hashtable m_tables.
Remove_From_Tables(string table_name) : bool – updates m_tables Hashtable by removing the entire “table”.
Pre-condition: Hashtable object m_tables exists and there is a key “table” in it.
Post-condition: Table is removed from Hashtable
m_tables.
SmartSQL62
SmartSQL
Application Design Document
Add_To_Connections_Table(string key, Pair value ) : bool - creates new connection between foreign key “key” and table, where it is primary key, by adding these values to Hashtable m_connections.
Pre-condition: Hashtable m_connections exists. Post-condition: Values were successfully added to
m_connections. Remove_From_Connections_Table(string key, Pair
value ) : bool – remove connection between foreign key “key” and table, where it is primary key, by removing these values from Hashtable m_connections.
Pre-condition: Hashtable m_connections exists and these values are in it.
Post-condition: Values were successfully removed from m_connections.
Remove_From_Connections_Table(string key) : bool – remove connection of the foreign key “key”, by removing this value from Hashtable m_connections.
Pre-condition: Hashtable m_connections exists and these values are in it.
Post-condition: Value was successfully removed from m_connections.
Add_To _Key_Words_DB(string subject, string word) : bool – adds an association between “word” and “subject”, by adding these values to Hashtable m_key_words_db.
Pre-condition: Hashtable m _key_words_db exists Post-condition: Values were successfully added to
m _key_words_db.
Remove_From _Key_Words_DB(string subject, string word) : bool – removes an association between
SmartSQL63
SmartSQL
Application Design Document
“word” and “subject”, by removing these values from Hashtable m _key_words_db.
Pre-condition: Hashtable m _key_words_db exists and “word” and “subject” are in it.
Post-condition: Values were successfully removed from m _key_words_db.
Remove_From _Key_Words_DB(string subject) : bool – removes the entire “subject”, from Hashtable m _key_words_db.
Pre-condition: Hashtable m _key_words_db exists and “subject” is in it.
Post-condition: Subject was successfully removed from m _key_words_db.
SmartSQL64
SmartSQL
Application Design Document
Add_To _Query_Type(string query_type, string word) : bool – adds an association between “word” and “query_type”, by adding these values to Hashtable m_query_types.
Pre-condition: Hashtable m_query_types exists. Post-condition: “word” was successfully added to
m_query_types. Remove_From _Query_Type(string query_type, string
word) : bool – removes an association between “query_type” and “word”, by removing these values from Hashtable m_query_types.
Pre-condition: Hashtable m_query_types exists and “word” and “query_type” are in it.
Post-condition: Values were successfully removed from m_query_types.
Remove_From _Query_Type (string query_type) : bool – removes the entire “query_type” section, from Hashtable m_query_types.
Pre-condition: Hashtable m_query_types exists and “query_type” is in it.
Post-condition: Subject was successfully removed from m_query_types.
Add_To _Saved_Queries(string nlp_query, string sql_query) : bool – adds an association between “nlp_query” and “sql_query”, by adding these values to Hashtable m_saved_queries.
Pre-condition: Hashtable m_saved_queries exists. Post-condition: “nlp_query” and “sql_query” were
successfully added to m_saved_queries.
Remove_From _ Saved_Queries (string query) : bool – removes the “query” from Hashtable m_saved_queries.
Pre-condition: Hashtable m_saved_queries exists and “query” is in it.
SmartSQL65
SmartSQL
Application Design Document
Post-condition: Value was successfully removed from m_saved_queries.
SmartSQL66
SmartSQL
Application Design Document
Add_To _Where_Part(string key_word) : bool – adds a “key_word” to Hashtable m_key_words.
Pre-condition: Hashtable m_key_words exists. Post-condition: “key_word” was successfully
added to m_key_words.
Remove_From _ Where_Part (string key_word) : bool – removes the “key_word” from Hashtable m_key_words.
Pre-condition: Hashtable m_key_words exists and “key_word” is in it.
Post-condition: Value was successfully removed from m_key_words.
Check_Sub_String (string st, string sub_st) : bool – Checks whether sub_st is substring of st.
Pre-condition: - . Post-condition: -.
Check_If_Order_Begin (string word) : bool – Checks whether the word belongs to order-by list.
Pre-condition: - . Post-condition: -.
Check_If_Where_Begin (string word) : bool – Checks whether the word belongs to where list.
Pre-condition: - . Post-condition: -.
Get_Associated_Fields (string word) : ArrayList – Returns the list of associated fields with user’s request.
Pre-condition: Hashtable m_words_of_fields exists. Post-condition: Associated fields were successfully
returned or empty set if there aren’t
any.
SmartSQL67
SmartSQL
Application Design Document
Get_Associated_Table (string word) : ArrayList – Returns the list of associated tables with user’s request.
Pre-condition: Hashtable m_words_of_tables exists.
Post-condition: Associated tables were successfully returned or empty set if there aren’t
any.
Get_Associated_Values (string word) : ArrayList – Returns the list of associated values with user’s request.
Pre-condition: Hashtable m_associated_values exists.
Post-condition: Associated values were successfully returned or empty set if there aren’t any.
Get_Correct_Table_Name_By_Table (string table_name) : ArrayList – Returns correct table name if found.
Pre-condition: Hashtable m_tables exists. Post-condition: Tables with similar table_name
were successfully returned.
Get_Fields_By_Table_Name (string table_name) : ArrayList – Returns correct table name if found.
Pre-condition: Hashtable m_tables exists. Post-condition: Tables with similar table_name
were successfully returned.
Get_Query_Type(string key_word) : string – returns query type associated with given “key_word” by
SmartSQL68
SmartSQL
Application Design Document
retrieving information from Hashtable m_query_key_words.
Pre-condition: Hashtable m_query_key_words exists.
Post-condition: Query type was successfully returned or null if no association with “key_word” was found in m_query_key_words.
Get_Table_Name_By_Field(string field) : string – returns table name associated with “field”, by retrieving it from m_tables Hashtable or null if no such association exists.
Pre-condition: Hashtable m_tables exists. Post-condition: Values were successfully returned
if field was associated with table or null if not.
Get_Fields_By_Table_Name(string table) : string[] – return array of all fields in “table” , by retrieving these values from Hashtable m_tables.
Pre-condition: Hashtable m_tables exists. Post-condition: Values were successfully
extracted from m_tables ot null if no such table.
Check_Foregn_Key(Pair key) : boolean – Checks whether “key” is foreign key or not, by looking in m_connections Hashtable .
Pre-condition: Hashtable m_connections exists. Post-condition: -.
Get_Synonyms_From_Word_Net(string word) : ArrayList – returns all synonyms of given word from WordNet system .
Pre-condition: WordNet is installed and set up properly.
Post-condition: -.
SmartSQL69
SmartSQL
Application Design Document
Get_Generalization_Words(string word) : ArrayList – Check whether a certain key_word is of a specified field and returns the list of all appropriate fields.
Pre-condition: Hashtable m_words_of_fields exists. Post-condition: -.
Get_Pair_By_Field(string field) : ArrayList – returns pair – Table_name.field_name of field. Pre-condition : - . Post-condition: -.
Get_Key_Words_Of_Field(string field) : ArrayList – returns generalizations of given word from WordNet system .
Pre-condition: WordNet is installed and set up properly.
Post-condition: -.
4.2.3.2. NLP_Analyzer
Responsible for analyzing question in natural language and constructing a SQL-like query from that question.
Operations:
Analyze _Query(string sentence) : string – returns SQL-like string representation of given question. Analyzes the question and assigns parts of question to SQL query parts.
Pre-condition: All the needed XML databases exist and up to date.
Post-condition: The query type and needed SQL parts are identified and saved.
SmartSQL70
SmartSQL
Application Design Document
Get_Saved_Queries_List() : ArrayList – returns string ArrayLsit of previously saved queries that were successfully analyzed and identified.
Pre-condition: All the needed XML databases exist and up to date.
Post-condition: -.
Remove_From_Saved_Queries (string query) : bool – Removes a specified query from the saved queries list.
Pre-condition: The saved_queries exists and query is in it.
Post-condition: - The query is successfully removed from the system.
Add_Field_By_Value(Tagged_Word word, Pair pair) : void – Adds a field to SQL Builder if there is a value in the nlp query associated to it.
Pre-condition: -. Post-condition: -.
Add_Field_To_Builder(Tagged_Word word, Pair field) : void – Adds a field to SQL Builder and the table corresponding to it.
Pre-condition: -. Post-condition: The field is successfully added to
SQL builder.
Add_Table_To_Builder(string table_name) : void – Adds a table to SQL Builder
Pre-condition: -. Post-condition: The table is successfully added to
SQL builder.
SmartSQL71
SmartSQL
Application Design Document
Add_To_Saved_Queries(string nlp_query, string sql_query) : bool – Adds a new entry of the nlp user’s query and its generated sql query. Pre-condition: -. Post-condition: The entry is successfully added to
the system.
Check_For_Value_Patterns(ref ArrayList word) : ArrayList – Checks whether there are values in the given sentence that can be interpreted as fields. Returns exceptions that may appear. Pre-condition: All values are loaded into the
system. Post-condition: - .
Check_Sub_String (string st, string sub_st) : bool – Checks whether sub_st is substring of st.
Pre-condition: - . Post-condition: -.
Check_Table_Field_Consistency (ref string sentence) : void – Checks whether there are fields that can be omitted from exception that will be presented to user. If there are only one field relevant assigns it without asking the user. This function reduces the number of possibilities presented to user.
Pre-condition: - . Post-condition: -.
Check_For_SQL_Patterns (ArrayList words, string sentence) : void – Checks whether there are patterns in the given sentence by the user. If there are, replace them by SQL key_words such as “SUM”, “OR”, “MAX”, “AVG”, etc.
Pre-condition: - . Post-condition: -.
SmartSQL72
SmartSQL
Application Design Document
Establish_Tables_Connections () : void – Sets the flags of Joins between tables in the SQL Builder instance.
Pre-condition: - . Post-condition: -.
Extract_Tagged_Words_From_Sentence (string tegged_sentence) : ArrayList – Returns all the nouns of the sentence as Tagged_Word objects.
Pre-condition: - . Post-condition: -.
Find_And_Assign_Field_To_Where_Operand (string[] tokens, int index, string condition) : bool – Searches for field that should be assigned to where operand found in the sentence given by the user.
Pre-condition: - All the values from xmls are loaded into the system.
Post-condition: -.
Handle_Average (string[] tokens, int index): bool – Searches for field that should be assigned to average operand found in the sentence given by the user.
Pre-condition: - All the values from xmls are loaded into the system.
Post-condition: -.
Handle_Count(string[] tokens, int index, string condition) : bool – Searches for field that should be assigned to count operand found in the sentence given by the user.
Pre-condition: - All the values from xmls are loaded into the system.
Post-condition: -.
SmartSQL73
SmartSQL
Application Design Document
Handle_GroupBy (string[] tokens, int index): bool – Searches for field that should be assigned to group-by operand found in the sentence given by the user.
Pre-condition: - All the values from xmls are loaded into the system.
Post-condition: -.
Handle_Insert (string[] tokens, int index): bool – Handles "Insert" query assigns value for each field in builder.
Pre-condition: - All the values from xmls are loaded into the system.
Post-condition: -. Handle_Max_Min (string[] tokens, int index, string
operand): bool – Searches for field that should be assigned to max or min operand found in the sentence given by the user.
Pre-condition: - All the values from xmls are loaded into the system.
Post-condition: -.
Handle_Orde_By (string[] tokens, int index, string operand): bool – Searches for field that should be assigned to order-by operand found in the sentence given by the user.
Pre-condition: - All the values from xmls are loaded into the system.
Post-condition: -.
Handle_Set (string[] tokens, int index): bool – Handles "Update" query assigns value for each field in builder.
Pre-condition: - All the values from xmls are loaded into the system.
Post-condition: -.
SmartSQL74
SmartSQL
Application Design Document
Handle_Sum (string[] tokens, int index): bool – Handles the sentences which include sum operations. Recieves tokens and an index of the "sum" word in the sentence. This function searches for the field that sum should be applied on.
Pre-condition: - All the values from xmls are loaded into the system.
Post-condition: -.
SmartSQL75
SmartSQL
Application Design Document
Remove_From_Words(Tagged_Word word) : void – Removes word from m_words ArrayList.
Pre-condition: - m_words ArrayList exists in the system and word is in it.
Post-condition: word is successfully removed from the system.
Remove_From_Words_For_Wordnet(Tagged_Word word)
: void – Removes word from m_words ArrayList. Pre-condition: - m_words_for_wordnet ArrayList
exists in the system and word is in it. Post-condition: word is successfully removed from
the system.
Replace (int selection_pos, string sentence, string old_word, string new_word) : string – Replace old_word with new_word in the sentence in the selection_pos place.
Pre-condition: - old_word is placed in the selection_pos in the senetence
Post-condition: old_word is successfully replaced with new_word.
Establish_Tables_Connections () : void – Sets the flags of Joins between tables in the SQL Builder instance.
Pre-condition: - . Post-condition: -.
Analyze _Query(string sentence) : string – returns SQL-like string representation of given question. Analyzes the question and assigns parts of question to SQL query parts.
Pre-condition: All the needed XML databases exist and up to date.
Post-condition: The query type and needed SQL parts are identified and saved.
SmartSQL76
SmartSQL
Application Design Document
4.2.3.3. NLP_Controller
Responsible for building SQL query from natural language question and loading list of previously built queries.
Operations:
Remove_From_Words(Tagged_Word word) : void – Removes word from m_words ArrayList.
Pre-condition: - m_words ArrayList exists in the system and word is in it.
Post-condition: word is successfully removed from the system.
Remove_From_Words_For_Wordnet(Tagged_Word word)
: void – Removes word from m_words ArrayList. Pre-condition: - m_words_for_wordnet ArrayList
exists in the system and word is in it. Post-condition: word is successfully removed from
the system.
Remove_From_Saved_Queries (string query) : bool – Removes a specified query from the saved queries list.
Pre-condition: The saved_queries exists and query is in it.
Post-condition: - The query is successfully removed from the system.
Get_Saved_Queries_List() : ArrayList – returns string ArrayLsit of previously saved queries that were successfully analyzed and identified.
Pre-condition: All the needed XML databases exist and up to date.
SmartSQL77
SmartSQL
Application Design Document
Post-condition: -. Add_To_Saved_Queries(string nlp_query, string
sql_query) : bool – Adds a new entry of the nlp user’s query and its generated sql query. Pre-condition: -. Post-condition: The entry is successfully added to
the system. Add_Field_By_Value(Tagged_Word word, Pair pair) :
void – Adds a field to SQL Builder if there is a value in the nlp query associated to it.
Pre-condition: -. Post-condition: -.
Add_Field_To_Builder(Tagged_Word word, Pair field) : void – Adds a field to SQL Builder and the table corresponding to it.
Pre-condition: -. Post-condition: The field is successfully added to
SQL builder.
Add_Table_To_Builder(string table_name) : void – Adds a table to SQL Builder
Pre-condition: -. Post-condition: The table is successfully added to
SQL builder.
SmartSQL78
SmartSQL
Application Design Document
4.2.4.Classes of package: Administration4.2.4.1.Administration_Controller
(Administration)Responsible for managing all the operations in Administration, manages all Database operation, updates XML database scheme to all Database.
Operations: Add_Database(db_name : string)– Adds new
database to the system. Pre-condition: Database with this db_name are
exists. Post-condition: XML database scheme to this Database
created and database object created and added into system database collection.
Remove_Database(db_name : string) – Removes database from the system.
Pre-condition: Database object with this db_name are exists in the system database collection.
Post-condition: Database object deleted from the system database collection.
Add_User(user : User) – Adds new user to the system.
Pre-condition: User object are exists with correct profile data.
Post-condition: User object added into the system user collection.
Remove_User(login : string) – Removes user from the system..
Pre-condition: User object with this login are exists in the system user collection.
Post-condition: User object deleted from the system user collection.
SmartSQL79
SmartSQL
Application Design Document
Update_Database_XML(db_name : string) – Update database XML document i.e. update table and field names relationship between tables, check if column is primary key or foreign key.
Pre-condition: Appropriate Database is exists, connection instance is exists.
Post-condition: Database_XML document with correct information created.
SmartSQL80
SmartSQL
Application Design Document
Set_Current_DB(string current_db) - Set DB with name current_db to be current working database.
Pre-condition: Appropriate Database is exists, connection instance is exists.
Post-condition: Database_XML document “db_xml_doc.xml” with correct information updated.
4.2.4.2.Database (Administration)Responsible for holding database parameters which will be used in database managing by Administration_Controller.
4.2.4.3. PairResponsible for holding association between field and its table.Operations:
Get_Table_Name() : string – returns table name. Pre-condition: - Post-condition: -.
Get_Field_Name() : string – returns field name. Pre-condition: - Post-condition: -.
Set_Table_Name(string table_name) : void – sets table name.
Pre-condition: - Post-condition: - value table_name assigned to
m_table_name.
Set_Field_Name(string field_name) : void – sets field name.
Pre-condition: - Post-condition: - value field_name assigned to
m_field_name.
SmartSQL81
SmartSQL
Application Design Document
5.2.4.4. XML_Handler
Responsible for reading and writing data to and from XML program database.
Operations: Read_From_Query_Key_Words_XML(string filepath) :
vector – returns vector of query keywords from keywords XML database in file “filepath”.
Pre-condition: XML database file exists and accessible.
Post-condition: The returned vector contains all the keywords in database.
Write_To_Query_Key_Words_XML(string key_word, string query_type, string filepath) :void – adds “key_word” and associated “query_type” to XML database file.
Pre-condition: XML database file exists and accessible.
Post-condition: Values “key_word” and “query_type” were added to XML database “filepath” in the right of ZZplace.
Read_From_DB_XML(string filepath) : vector – returns vector of all user database schema from XML database in file “filepath”.
Pre-condition: XML database file exists and accessible.
Post-condition: The returned vector contains all the schema in right order.
Write_To_DB_XML(string table name, string field_name, string filepath) :void – adds “table_name” and associated “field_name” to XML database.
SmartSQL82
SmartSQL
Application Design Document
Pre-condition: XML database file exists and accessible.
Post-condition: Values “table_name” and “field_name” were added to XML database “filepath” in the right place.
Read_From_Saved_queries_DB(string filepath) : vector – read and returns vector of all saved queries from XML database.
Pre-condition: XML database file exists and accessible.
Post-condition: All previously saved queries were read from “filepath” XML database.
Write_To_Saved_Queries_DB(string query, string filepath) :void – adds “query” to saved queries XML database.
Pre-condition: XML database file exists and accessible.
Post-condition: Values “query” was added to XML database “filepath” in the right place.
Is_Table_Exist (string table_name, string xml) : bool – checks whether the given table is already exists in the xml specified in the filepath.
Pre-condition: XML database file exists and accessible.
Post-condition: The true returned if table exists.
Is_Query_Type_Exist(string query_type) : bool – checks function checks whether the specified query_type exists in the xml.
Pre-condition : QUERY_TYPE_DB_XML file exists and accessible.
Post-condition: The true returned if query_type exists.
Read_From_ DB_Schema_XML () : Hashtable – read from the DB_Schema_XML and returns the hash table of all the tables as keys and for each table, a list of all its fields.
SmartSQL83
SmartSQL
Application Design Document
Pre-condition: DB_SCHEMA XML file exists and accessible.
Post-condition: All tables as keys and for each table, a list of all its fields were read from DB_SCHEMA XML document.
Write_To_DB_Schema_XML(string table_name, ArrayList field_names) : bool– adds table with list of fields to DB_SCHEMA XML.
Pre-condition: DB_SCHEMA XML file exists and accessible.
Post-condition: Appropriate Table with list of fields were added to DB_SCHEMA XML in the right place and value true returned .
SmartSQL84
SmartSQL
Application Design Document
Delete_From_DB_Schema_XML(string table_name, string field_Name): bool– removes table field from the DB_SCHEMA XML if it exists otherwise return false.
Pre-condition: DB_SCHEMA XML file exists and accessible.
Post-condition: Appropriate Table with field were removed from the DB_SCHEMA XML and value true returned .
5.2.4.5. GlossaryManagerController
Responsible for providing information about database glossaries and updating it.
Operations: Add_Field_Alternative(table : string, field : string, value
: string) : void – adds new alternative to specified field name.
Pre-condition: specified table and field exist. Post-condition: new alternative added to specified
field name.
Add_Keyword(subject : string, sign :string) void– adds new keyword to XML database.
Pre-condition: none. Post-condition: given keyword added to XML
database.
Add_Keyword_Value(keyword : string, value : string) : void– adds new keyword value to XML database.
Pre-condition: none. Post-condition: given keyword value added to XML
database.
Add_Table_Alternative(table : string, alternative : string) : void– adds new alternative word to given table name.
Pre-condition: table exists.
SmartSQL85
SmartSQL
Application Design Document
Post-condition: given alternative was added to tables alternatives.
Add_TP_Keyword(query_type : string, keyword : string) : void– adds new keyword value for given query type to query types XML database.
Pre-condition: none. Post-condition: given keyword added to XML
database.
Add_Value_To_Field(table : string, field : string, value : string): void– adds new value for given field.
Pre-condition: table and field exist. Post-condition: given value added to field’.
Get_Field_Alternatives(table : string, field: string) : ArrayList– returns list of alternative names for given field.
Pre-condition: table and field exist. Post-condition: returned list of alternative values .
Get_Keyword_Values(keyword : string) : ArrayList – returns list of values for the given keyword.
Pre-condition: keyword exists. Post-condition: returned list of keyword’s values.
Get_Keywords() : ArrayList – returns list of keywords stored in the system.
Pre-condition: none. You have its Post-condition: returned list of keywords.
Get_Table_Alternatives(table : string) : ArrayList – returns list of alternative names for given table name.
Pre-condition: table exists. Post-condition: returned list of table alternatives .
Get_Table_Fields(field : string)– ArrayList – returns list of fields in the given table
Pre-condition: table exists.
SmartSQL86
SmartSQL
Application Design Document
Post-condition: returned list of fields of the given table.
Get_Tables_Names() : ArrayList –returns list of all tables in database.
Pre-condition: database was previously chosen. Post-condition: returned list of all tables.
Get_Type_Values(query_type : string) : ArrayList – returns list of values associated with given query type.
Pre-condition: none. Post-condition: returned list of values.
Get_Types_Parts() : ArrayList – returns list of all query types.
Pre-condition: none. Post-condition: returned list of query types.
Get_Unique_Field_Values_From_DB(table : string, field : string) : ArrayList – returns list of all unique values in field’s column.
Pre-condition: table and field exist. Post-condition: returned list of field’s unique
values.
Get_Values_For_Field(table : string, field : string) : ArrayList – returns list of values associated with given field name.
Pre-condition: table and field exist. Post-condition: returned list of field’s values.
Get_Where_Values() : ArrayList – returns list of values associated with “where” part of query.
Pre-condition: none. Post-condition: returned list of values.
Remove_Field_Alternative(table : string, field : string, alternative : string): void– removes specified alternative name from list of given field’s alternatives.
Pre-condition: table and field exist.SmartSQL
87
SmartSQL
Application Design Document
Post-condition: given value removed from field’s alternatives.
Remove_Keyword(keyword : string): void– removes keyword and all associated values from the system.
Pre-condition: keyword exists. Post-condition: keyword was removed and
corresponding XML database was updated.
Remove_Keyword_Value(keyword : string, value : string) : void– removes value from given keyword’s list.
Pre-condition: keyword exists. Post-condition: given value removed from the list
and corresponding XML database updated.
Remove_Table_Alternative(table : string, alternative : string): void– removes alternative value from given table’s alternatives.
Pre-condition: table exists. Post-condition: given alternative removed from
the list.
Remove_TP_Keyword(query_type : string, keyword : string): void– removes specified keyword from the given query type’s list of keywords.
Pre-condition: none. Post-condition: given keyword removed from the
list.
Remove_Value_From_Field(table : string, field : string, value : string): void– removes value from list of values of the given field.
Pre-condition: table and field exist.
SmartSQL88
SmartSQL
Application Design Document
Post-condition: given value was removed from the list.
Update_And_Save_Conversion_Tables(): void– saves all the changes made with conversion tables .
Pre-condition: none . Post-condition: all the information related to
conversion tables was saved to appropriate XML database files.
Update_And_Save_Fields_Values(): void– saves all the changes made to fields values.
Pre-condition: none. Post-condition: all the information related to fields
values was saved to appropriate XML database files.
Update_Fields_Values(): void– rereads information about fields values from XML database.
Pre-condition: none. Post-condition: all related data structures were
updated.
Update_Tables_And_Conversion(): void– rereads information about tables names, fields names and conversion values from XML database.
Pre-condition: none. Post-condition: all related data structures were
updated.
Preconditions, postconditions and behaviour of all other functions (Reading, Writing and Removing) in XML_Handler very similar (if not identical) to above described functions. Thus their full description is not expedient.
SmartSQL89
SmartSQL
Application Design Document
4.3. Packages
Remarks:
1. NLP Utilities- Responsible to provide interface to Brill tagger.2. NLP- Analyzes NL query and produces SQL query.3. SQL Builder- Offers SQL query construction using GUI and is used by NLP package
to generate SQL query.4. Login- Offers login functionality of the system and access control, since we have two
types of users –user, administrator.5. Administration- Responsible for adding/removing users , adding/removing databases
and managing database glossaries. 6. Database_Handler- Offers interface of DLL provided by “AlfaTech” to access
DBMS- access, SQL server.
SmartSQL90
SmartSQL
Application Design Document
4.4. Unit Testing
4.4.1. Unit testing for Query_Manager class
Add_Table(string name) : voidNo Test Description Expected Result1 Call the function with
some name that was not used before in that method.
Object “Table” with given name was added to collection.
2 Call the function with some name that was used before in that method.
There is only one instance of Table with that name in collection.
Add_Field(string name) : voidNo Test Description Expected Result1 Call the function with
some name that was not used before in that method.
Object “Field” with given name was added to collection.
2 Call the function with some name that was used before in that method.
There is only one instance of Field with that name in collection.
Remove_Table(string name) : voidNo Test Description Expected Result1 Call the function with
name that Table with corresponding name exists in the table’s collection.
Object “Table” with given name was removed from collection.
2 Call the function with Table’s collection SmartSQL
91
SmartSQL
Application Design Document
name that Table with corresponding name not exists in the table’s collection.
was not changed.
Remove_Field (string name) : voidNo Test Description Expected Result1 Call the function with
name that Field with corresponding name exists in the field’s collection.
Object “Field” with given name was removed from collection.
2 Call the function with name that Field with corresponding name not exists in the field’s collection.
Field’s collection was not changed.
Build_Query() : voidNo Test Description Expected Result1 Set some parameters
in objects: Fields, Tables, Query with query type=”Select” and call the function.
Corresponding correct query was generated.
2 Set some parameters in objects: Fields, Tables, Query with query type=”Create” and call the function.
Corresponding correct query was generated.
SmartSQL92
SmartSQL
Application Design Document
3 Set some parameters in objects: Fields, Tables, Query with query type=”Alter” and call the function.
Corresponding correct query was generated.
4 Set some parameters in objects: Fields, Tables, Query with query type=”Drop” and call the function.
Corresponding correct query was generated.
5 Set some parameters in objects: Fields, Tables, Query with query type=”Update” and call the function.
Corresponding correct query was generated.
6 Set some parameters in objects: Fields, Tables, Query with query type=”Delete” and call the function.
Corresponding correct query was generated.
7 Set some parameters in objects: Fields, Tables, Query with query type=”Insert” and call the function.
Corresponding correct query was generated.
4.4.2. Unit testing for Database_Handler_Interface class
Get_Database_Tables_Names() : ArrayListNo Test Description Expected Result1 Call the function. Returned list of all
SmartSQL93
SmartSQL
Application Design Document
table’s names.
Get_Columns_Names(string : table_name): ArrayListNo Test Description Expected Result1 Call the function with
table name which exists.
Returned list of all field’s names for corresponding table.
Get_Result_Table_From_DB(string : query) : Data_ObjectNo Test Description Expected Result1 Call the function with
correct “Select” query.
Returned correct data which corresponds to query.
Update_Command(string : query) : boolNo Test Description Expected Result1 Call the function with
correct non “Select” query.
Query executed correctly and true returned.
4.4.3. Unit testing for Login_Manager class (Login)
Login(name : string, password : string) : booleanNo Test Description Expected Result1 Call the function with
some correct name and password.
Boolean true was returned.System state will be changed
2 Call the function with some incorrect name or password.
Boolean false was returned.
Logout():voidSmartSQL
94
SmartSQL
Application Design Document
No Test Description Expected Result1 Call the function with
some user that is login in the system.
User logout from the system all appropriate data will be saved. System state will be changed.
4.4.4. Unit testing for Administration_Controller class (Administration)
Add_Database(db_name : string): voidNo Test Description Expected Result1 Call the function with
name corresponding to exists database.
XML database scheme to this Database created and database object created and added into system database collection.
2 Call the function with name corresponding to database that not exists.
System database collection was not changed.
Remove_Database(db_name : string) : voidNo Test Description Expected Result1 Call the function with
name that database with corresponding name exists in the system database collection.
Appropriate Database object with given name was removed from system database collection.
2 Call the function with name that database with corresponding name not exists in the system database collection.
System database collection was not changed.
SmartSQL95
SmartSQL
Application Design Document
Add_User(user : User): voidNo Test Description Expected Result1 Call the function with
exist correct User object.
User object added into the system user collection.
2 Call the function with not exist or not correct User object.
System user collection was not changed.
Remove_User(login : string) : voidNo Test Description Expected Result1 Call the function with
login that user with corresponding name exists in the system user collection.
Appropriate User object with given login was removed from system user collection.
2 Call the function with login that user with corresponding name not exists in the system user collection.
System user collection was not changed.
Update_Database_XML(db_name : string) : voidNo Test Description Expected Result1 Call the function with
name that database with corresponding name exists in the system database collection.
Appropriate database information was added to Database_XML document.
2 Call the function with name that database with corresponding name not exists in the system database
Database_XML document was not changed.
SmartSQL96
SmartSQL
Application Design Document
collection.
SmartSQL97
SmartSQL
Application Design Document
4.4.5. Unit testing for XML_Handler class
Read_From_Query_Key_Words_XML(filepath : string) : VectorNo Test Description Expected Result1 Call the function with
correct filepath of the XML file.
The correct attributes of the XML file were retrieved.
2 Call the function with incorrect filepath.
The function notifies that no file with the given filepath exists and no information is retrieved.
3 Call the function with test XML database file
The vector of results includes all the key words
Write_To_Query_Key_Words_XML(filepath : string, key_word : string, query_type : string) : void
No Test Description Expected Result1 Call the function with
correct filepath of the XML file, key word and query type.
The key word is written into the file which location is filepath, under the tag query type.
2 Call the function with incorrect filepath.
The function notifies that no file with the given filepath exists and no information is written.
3 Call the function with incorrect query type.
The function notifies that the given query type does not exist in the XML file and thus no information is written.
4 Call the function with test XML database file and predefined key_word and query_type
The key_word is written to test XML database file in the right place and in the right syntax
SmartSQL98
SmartSQL
Application Design Document
Read_From_DB_XML(filepath : string) : VectorNo Test Description Expected Result1 Call the function with
correct filepath of the XML file.
The correct attributes of the XML file were retrieved.
2 Call the function with incorrect filepath.
The function notifies that no file with the given filepath exists and no information is retrieved.
3 Call the function with test XML database file
The vector of results includes all test DB schema
Write_To_DB_XML(filepath : string, table_name : string, field_name : string) : voidNo Test Description Expected Result1 Call the function with
correct filepath of the XML file, table name and field name.
Table name and field name are written into the file which location is filepath.
2 Call the function with incorrect filepath.
The function notifies that no file with the given filepath exists and no information is written.
3 Call the function with test XML database file and predefine table_name and field_name
The values are written to test XML database file in the right place and in the right syntax
Read_From_Saved_Queries_DB(filepath : string) : stringNo Test Description Expected Result1 Call the function with
correct filepath of the XML file.
The correct query from the XML file was retrieved.
2 Call the function with incorrect filepath.
The function notifies that no file with the given filepath exists and no information is retrieved.
SmartSQL99
SmartSQL
Application Design Document
3 Call the function with test XML database
The vector of results includes all the saved queries
Write_To_Saved_Queries_DB(filepath : string, query : string) : voidNo Test Description Expected Result1 Call the function with
correct filepath of the XML file and query.
The query is written into the file which location is filepath.
2 Call the function with incorrect filepath.
The function notifies that no file with the given filepath exists and no information is written.
3 Call the function with test XML database file and predefined query string
The values are written to test XML database file in the right place and in the right syntax
4.4.6. Unit testing for NLP_Data_Levels class
Get _Type_Of_Query(key_word : string) : stringNo Test Description Expected Result1 Call the function with
existing key word used in question.
The correct query type is returned.
2 Call the function with not existing key word.
The function returns that there is no corresponding query type to the given key word.
Get_Pair _By_Field(field : string) : ArrayListNo Test Description Expected Result1 Call the function with
existing field name.The list of Table.field matching to field are returned.
2 Call the function with not existing field name.
The function returns an empty list.
SmartSQL100
SmartSQL
Application Design Document
Get_Correct_Table_Name_By_Table(table_name : string) : ArrayListNo Test Description Expected Result1 Call the function with
existing table name.The list of all correct tables derived from table_name is returned.
2 Call the function with not existing table name.
The function returns an empty list.
Check_Foreign_Key(key : string, value : Pair): PairNo Test Description Expected Result1 Call the function with
key that is a foreign key in value.
Table and field are returned.
2 Call the function with key that has no foreign keys to it.
The function returns null.
Get_Synonyms_From_Word_Net(word : string) : ArrayListNo Test Description Expected Result1 Call the function with
the given word.The list of synonyms is returned from the Word Net.
Get_Generalization_Words (word : string) : ArrayListNo Test Description Expected Result1 Call the function with
the given word.The list of generalization words is returned from the Word Net.
Add_To_Tables(table_name : string, field_name : string): boolNo Test Description Expected Result1 Call the function with
existing table name.The field_name is inserted into the m_tables HashTable
SmartSQL101
SmartSQL
Application Design Document
in table_name.2 Call the function with
not existing table name.
A new entry is created in m_tables HashTable and field_name is inserted as its value.
3 Call the function with existing table name, but with a field_name that is already exists in the HashTable,
The field_name is not inserted again into the m_tables HashTable.
Remove_From_Tables(table_name : string, field_name : string): boolNo Test Description Expected Result1 Call the function with
existing table name and existing field_name.
The field_name is removed from the m_tables HashTable, from table_name key.
2 Call the function with not existing table name.
An error is returned.
3 Call the function with existing table name but not existing field_name.
Nothing is removed from the m_tables HashTable.
Remove_From_Tables(table_name : string): boolNo Test Description Expected Result1 Call the function with
existing table name.The table_name is removed from the m_tables HashTable.
2 Call the function with not existing table name.
An error is returned.
Add_To_Connections_Table(key : Pair, value : Pair): boolNo Test Description Expected Result1 Call the function with The value is inserted
SmartSQL102
SmartSQL
Application Design Document
existing key. into the m_connections HashTable in key place.
2 Call the function with not existing key.
A new entry is created and the value is inserted into the m_connections HashTable.
3 Call the function with existing key, but with value that is already in the HashTable.
The value is not inserted again into the m_connections HashTable.
SmartSQL103
SmartSQL
Application Design Document
Remove_From_Connections_Table(key : Pair, value : Pair): boolNo Test Description Expected Result1 Call the function with
existing key.The value is removed from the m_connections HashTable, from key place.
2 Call the function with not existing key.
An error is returned.
3 Call the function with existing key but not existing value.
Nothing is removed from the m_connections HashTable.
Remove_From_Connections_Table(key : Pair): boolNo Test Description Expected Result1 Call the function with
existing key.The value is removed from the m_connections HashTable, from key place.
2 Call the function with not existing key.
An error is returned.
Add_To_Query_Type(query_type : string, word : string): boolNo Test Description Expected Result1 Call the function with
existing query_type.The value is inserted into the m_query_types HashTable in query_type place.
2 Call the function with not existing query_type.
A new entry is created and the word is inserted into the m_query_types HashTable.
3 Call the function with existing query_type,
The word is not inserted again into the
SmartSQL104
SmartSQL
Application Design Document
but with word that is already in the HashTable.
m_query_types HashTable.
SmartSQL105
SmartSQL
Application Design Document
Remove_From_Query_Type(query_type : string, word : string): boolNo Test Description Expected Result1 Call the function with
existing query_type and existing word.
The value is removed from the m_query_types HashTable, from query_type place.
2 Call the function with not existing query_type.
An error is returned.
3 Call the function with existing query_type but not existing word.
Nothing is removed from the m_query_types HashTable.
Remove_From_Query_Type(query_type : string): boolNo Test Description Expected Result1 Call the function with
existing query_type.The query_type is removed from the m_query_types HashTable.
2 Call the function with not existing query_type.
An error is returned.
Add_To_Key_Words_DB(subject : string, key_word : string): boolNo Test Description Expected Result1 Call the function with
existing subject.The key_word is inserted into the m_key_words HashTable in subject place.
2 Call the function with not existing subject.
A new entry is created and the key_word is inserted into the m_key_words HashTable.
SmartSQL106
SmartSQL
Application Design Document
3 Call the function with existing subject, but with key_word that is already in the HashTable.
The key_word is not inserted again into the m_key_words HashTable.
SmartSQL107
SmartSQL
Application Design Document
Remove_From_Key_Words_DB(subject : string, key_word : string): boolNo Test Description Expected Result1 Call the function with
existing subject and existing key_word.
The key_word is removed from the m_key_words HashTable, from subject place.
2 Call the function with not existing subject.
An error is returned.
3 Call the function with existing subject but not existing key_word.
Nothing is removed from the m_key_words HashTable.
Remove_From_Key_Words_DB(subject : string, key_word : string): boolNo Test Description Expected Result1 Call the function with
existing subject.The subject is removed from the m_key_words HashTable.
2 Call the function with not existing subject.
An error is returned.
Add _To_Saved_Queries(nlp_query : string, sql_query : string): boolNo Test Description Expected Result1 Call the function with
existing nlp_query.False is returned.
2 Call the function with not existing nlp_query.
A new entry is created and the nlp_query and its corresponding sql_query are is inserted into the m_saved_queries ArrayList.
Remove _From_Saved_Queries(query : string): boolNo Test Description Expected Result
SmartSQL108
SmartSQL
Application Design Document
1 Call the function with existing query.
The query is removed and true is returned.
2 Call the function with not existing nlp_query.
Nothing is removed and false is returned.
Add _To_Where_Part(key_word : string): boolNo Test Description Expected Result1 Call the function with
existing key_word.False is returned.
2 Call the function with not existing key_word.
A new entry is created and the key_word is inserted into the m_where_part ArrayList.
Remove _From_Where_Part(key_word : string): boolNo Test Description Expected Result1 Call the function with
existing key_word.The key_word is removed and true is returned.
2 Call the function with not existing key_word.
Nothing is removed and false is returned.
Check _Sub_String(st : string, sub_st: string): boolNo Test Description Expected Result1 Call the function with
st that contains sub_st in it.
True is returned
2 Call the function with st that doesn’t contain sub_st in it.
False is returned.
Check _If_Order_Begin(word : string): boolNo Test Description Expected Result1 Call the function with True is returned
SmartSQL109
SmartSQL
Application Design Document
word that belongs to order by list.
2 Call the function with word that doesn’t belong to order by list.
False is returned.
Check _If_Where_Begin(word : string): boolNo Test Description Expected Result1 Call the function with
word that belongs to order by list.
True is returned
2 Call the function with word that doesn’t belong to order by list.
False is returned.
Get _Associated_Fields(word : string): ArrayListNo Test Description Expected Result1 Call the function with
word that belongs to some associated field’s list.
A list of Table.fields which word is associated with is returned.
2 Call the function with word that doesn’t belong to associated field’s list.
An empty list is returned.
Get _Associated_Tables(word : string): ArrayListNo Test Description Expected Result1 Call the function with
word that belongs to some associated table’s list.
A list of tables which word is associated with is returned.
2 Call the function with word that doesn’t belong to associated
An empty list is returned.
SmartSQL110
SmartSQL
Application Design Document
table’s list.
Get _Associated_Tables(word : string): ArrayListNo Test Description Expected Result1 Call the function with
word that belongs to some associated value’s list.
A list of Table.fields which word is associated with its value is returned.
2 Call the function with word that doesn’t belong to associated value’s list.
An empty list is returned.
Get _Key_Words_Of_Fields(field : string): ArrayListNo Test Description Expected Result1 Call the function with
field that belongs to the m_words_of_fields Hashtable.
A list of all key words that associated with field is returned.
2 Call the function with field that doesn’t belong to the m_words_of_fields Hashtable.
An empty list is returned.
4.4.7. Unit testing for NLP_Analyzer class
Add_Field_By_Value(word: Tagged_Word, pair: Pair): voidNo Test Description Expected Result1 Call the function with
sentence that contains only one key_word associated with pair
The key_word is removed from the m_words and its corresponding tagged_word is inserted into the m_words ArrayList.
2 Call the function with The key_word is SmartSQL
111
SmartSQL
Application Design Document
sentence that contains more than one key_word associated with pair
inserted into the m_words ArrayList.
Add_Field_To_Builder(field: Pair, word: Tagged_Word): voidNo Test Description Expected Result1 Call the function with
word whose “after_where” attribute is true.
A field is inserted into builder and its Field_Where attribute is set to true.
2 Call the function with word whose “after_order_by” attribute is true.
A field is inserted into builder and its after_order_by attribute is set to true.
3 Call the function with word whose “after_order_by” and “after_where” attributes are false.
A field is inserted into builder and its “viewable” attribute is set to true.
Check_For_Value_Patterns(words: ref ArrayList): ArrayListNo Test Description Expected Result1 Call the function with
value patterns in the given nl sentence.
All value patterns are found and replaced by Table.field.
SmartSQL112
SmartSQL
Application Design Document
Check_Table_Field_Consistency(sentence: ref string): voidNo Test Description Expected Result1 Call the function while
the choices for the user can be reduced.
All the irrelevant choices are removed from m_exceptions list.
2 Call the function while the choices for the user can’t be reduced.
No choice is removed from the m_exceptions list.
Check_For_SQL_Patterns(words: ArrayList, sentence: string): voidNo Test Description Expected Result1 Call the function with
sentence that includes SQL patterns written in nl and listed in the xml.
All the SQL patterns in nl are replaced with SQL key_words such as SUM, MAX, etc.
Establish_Tables_Connections(): voidNo Test Description Expected Result1 Call the function with nl
sentence which doesn’t involve any join operations
No join between tables found in the builder.
2 Call the function with nl sentence which involve a simple join operation between 2 tables.
A join between tables found in the builder.
3 Call the function with nl sentence which involve a transition table that should be joined between 2 tables (two join operations).
A join between tables found in the builder.
SmartSQL113
SmartSQL
Application Design Document
Extract_Tagged_Words_From_Sentence(tagged_sentence: string): ArrayListNo Test Description Expected Result1 Call the function with
tagged_sentence that contains several nouns.
All the nouns are returned.
2 Call the function with tagged_sentence that doesn’t contain nouns.
An empty list is returned.
Find_And_Assign_Field_To_Where_Operand(tokens: string[], index: int, condition: string): bool
No Test Description Expected Result1 Call the function with
sentence which contains a field to assign to where operand previously found.
The field is found and true is returned.
2 Call the function with sentence which doesn’t contain a field to assign to where operand previously found.
No field is found and false is returned.
Handle_Average(tokens: string[], index: int): boolNo Test Description Expected Result1 Call the function with
sentence that contains field to be assigned to average operation previously found.
Field to assign to average operation is found and true is returned.
2 Call the function with sentence that doesn’t contain field to be assigned to average operation previously found.
No field found to assign to average operation and false is returned.
SmartSQL114
SmartSQL
Application Design Document
SmartSQL115
SmartSQL
Application Design Document
Handle_Count(tokens: string[], index: int, operand: string): boolNo Test Description Expected Result1 Call the function with
sentence that contains field to be assigned to count operation previously found.
Field to assign to count operation is found and true is returned.
2 Call the function with sentence that doesn’t contain field to be assigned to count operation previously found.
No field found to assign to count operation and false is returned.
Handle_GroupBy(tokens: string[], index: int): boolNo Test Description Expected Result1 Call the function with
sentence that contains field to be assigned to group by operation previously found.
Field to assign to group by operation is found and true is returned.
2 Call the function with sentence that doesn’t contain field to be assigned to group by operation previously found.
No field found to assign to group by operation and false is returned.
Handle_Insert(tokens: string[], index: int): voidNo Test Description Expected Result1 Call the function with
sentence that contains field to be assigned to insert operation previously found.
Field to assign to insert operation is found.
2 Call the function with No field found to
SmartSQL116
SmartSQL
Application Design Document
sentence that doesn’t contain field to be assigned to insert operation previously found.
assign to insert operation.
SmartSQL117
SmartSQL
Application Design Document
Handle_Max_Min(tokens: string[], index: int, operand: string): boolNo Test Description Expected Result1 Call the function with
sentence that contains field to be assigned to max or min operation previously found.
Field to assign to max or min operation is found and true is returned.
2 Call the function with sentence that doesn’t contain field to be assigned to max or min operation previously found.
No field found to assign to max or min operation and false is returned.
Handle_Order_By(tokens: string[], index: int, operand: string): boolNo Test Description Expected Result1 Call the function with
sentence that contains field to be assigned to order by operation previously found.
Field to assign to order by operation is found and true is returned.
2 Call the function with sentence that doesn’t contain field to be assigned to order by operation previously found.
No field found to assign to order by operation and false is returned.
Handle_Set(tokens: string[], index: int): voidNo Test Description Expected Result1 Call the function with
sentence that contains field to be assigned to set operation previously found.
Field to assign to set operation is found.
2 Call the function with No field found to
SmartSQL118
SmartSQL
Application Design Document
sentence that doesn’t contain field to be assigned to set operation previously found.
assign to set operation.
SmartSQL119
SmartSQL
Application Design Document
Handle_Sum(tokens: string[], index: int): boolNo Test Description Expected Result1 Call the function with
sentence that contains field to be assigned to sum operation previously found.
Field to assign to sum operation is found and true is returned.
2 Call the function with sentence that doesn’t contain field to be assigned to sum operation previously found.
No field found to assign to sum operation and false is returned.
Remove_From_Words(word: Tagged_Words): voidNo Test Description Expected Result1 Call the function with
tagged_word that doesn’t appear in m_words
No word is removed from m_words.
2 Call the function with tagged_word that appears in m_words but not in the same position as the word in m_words.
No word is removed from m_words.
3 Call the function with tagged_word that appears in m_words in the same position as the word in m_words.
The word is removed from m_words.
Remove_From_Words_For_Wordnet(word: Tagged_Words): voidNo Test Description Expected Result1 Call the function with
tagged_word that doesn’t appear in m_words_for_wordnet.
No word is removed from m_words_for_wordnet.
SmartSQL120
SmartSQL
Application Design Document
2 Call the function with tagged_word that appears in m_words_for_wordnet in the same position as the word in m_words_for_wordnet.
The word is removed from m_words_for_wordnet.
Replace(selection_pos: int, sentence: string, old_word: string, new_word: string): string
No Test Description Expected Result1 Call the function with
sentence that contains in the selection_pos the old_word.
Old_word is replaced with new_word in the sentence in the selection_pos.
2 Call the function with sentence that doesn’t contain in the selection_pos the old_word.
Old_word is not replaced with new_word in the sentence in the selection_pos.
Check_Sub_String(st: string, sub_st: string): stringChecked in the NLP_Data_Levels class.
Add_To_Saved_Queries(nlp_query: string, sql_query: string): stringChecked in the NLP_Data_Levels class.
Remove_From_Saved_Queries(query: string): boolChecked in the NLP_Data_Levels class.
Add_Table_To_Builder(field: Pair, word: Tagged_Word): voidChecked in the Sql_Builder_Interface class.
Get_Saved_Query(): stringChecked in the XML_Handler class.
SmartSQL121
SmartSQL
Application Design Document
Get_Saved_Queries_List(): ArrayListChecked in the XML_Handler class.
SmartSQL122
SmartSQL
Application Design Document
Analyze _Query(string sentence ) : stringNo Test Description Expected Result1 Call the function with
predefined NL query, with known SQL equivalent.
The returned SQL query is equivalent to given NL query
Select _Analyzer(tagged_text: string, sentence: string, wn: bool ) : string
No Test Description Expected Result1 Call the function with
tagged_text and the sentence, with known SQL equivalent.
The returned SQL query is equivalent to given NL query
4.4.8. Unit testing for Pair class
Getters and setters are checking each otherSet_Table_Name(string table_name) : void
No Test Description Expected Result1 Call the function with
known table_name.Using Get_Table_Name(), we check that table_name is correct.
Set_Field_Name(string field_name) : voidNo Test Description Expected Result1 Call the function with
known field_name.Using Get_Field_Name(), we check that field_name is correct.
4.4.9. Unit testing for NLP_Controller class
Reset_Builder() : voidSmartSQL
123
SmartSQL
Application Design Document
Checked by parts in other classes of Sql_Builder_Interface.
Remove_From_Words_For_Wordnet(word: Tagged_Word) : void Checked in NLP_Analyzer class.
Remove_From_Words (word: Tagged_Word) : void Checked in NLP_Analyzer class.
Remove_From_Saved_Queries (query: tring) : boolChecked in NLP_Analyzer class.
Get _Saved_Queries_List () : ArrayListChecked in NLP_Analyzer class.
Get _Current_Query() : stringChecked in NLP_Analyzer class.
Establish_Tables_Connections() : voidChecked in NLP_Analyzer class.
Analyze_Query(nlp_query: string) : stringChecked in NLP_Analyzer class.
Add_To_Saved_Queries(nlp_query: string, sql_query: string) : voidChecked in NLP_Analyzer class.
Add_Table_To_Builder(pair: Pair, word: Tagged_Word) : voidChecked in NLP_Analyzer class.
Add_Field_To_Builder(pair: Pair, word: Tagged_Word) : voidChecked in NLP_Analyzer class.
Add_Field_By_Value(pair: Pair, word: Tagged_Word) : boolChecked in NLP_Analyzer class.
SmartSQL124
SmartSQL
Application Design Document
SmartSQL125
SmartSQL
Application Design Document
5. System Architecture
“Alfa Magic” is an application which offers environment to create GUI- based applications. Adding functionality to controls is done by selecting implemented activities from the list. Our application will provide another activity that the user of “AlfaMagic” can select.Our application runs on one computer.All DBMS which application uses, are located on the same computer.The system uses two types of DBMS: access, SQL server.
SmartSQL126
Company Manager
User
DBMS (SQL server, access)
System Administrator
SmartSQL(our package)
AlfaMagic
QueryData Set
SmartSQL
Application Design Document
6. User Interface Draft
6.1. SQL_Builder
Main:
SmartSQL127
SmartSQL
Application Design Document
Select choosing table:
SmartSQL128
SmartSQL
Application Design Document
Select choosing fields:
SmartSQL129
SmartSQL
Application Design Document
Select - setting field usages and other query parameters:
SmartSQL130
SmartSQL
Application Design Document
Create/Alter/Drop :
SmartSQL131
SmartSQL
Application Design Document
Insert/Update/Delete:
SmartSQL132
SmartSQL
Application Design Document
6.2. NLP Analyzer
Main
SmartSQL133
SmartSQL
Application Design Document
Open Saved Query
SmartSQL134
SmartSQL
Application Design Document
Execute Query
SmartSQL135
SmartSQL
Application Design Document
New Query
SmartSQL136
SmartSQL
Application Design Document
6.3. LoginLogin Window
SmartSQL137
SmartSQL
Application Design Document
SmartSQL Main Form
SmartSQL138
SmartSQL
Application Design Document
Administration
SmartSQL139
SmartSQL
Application Design Document
Database Manager
SmartSQL140
SmartSQL
Application Design Document
7. Testing
7.1. Speed
We will measure that after 2 seconds the system has responded.
7.2. Usability
We will take a naïve user which is not familiar with our system and we will measure the time it takes him to deal with our system.
SmartSQL141
SmartSQL
Application Design Document
8. Task List
SmartSQL142
SmartSQL
Application Design Document
SmartSQL143
SmartSQL
Application Design Document
SmartSQL144
SmartSQL
Application Design Document
9. AppendixExample of processing NLP sentence by NLP package:
Sentence : Give me all the nurses that work at Saturday night as manager.
The database includes the following tables :
NursesID Name Department
The algorithm to translate the NLP query to SQL query:
1. Tagging the sentence:
Give(VB) me(PRP) all(PDT) the(DT) nurses(NNS) that(WDT) work(VBP) at(IN) Saturday(NNP) night(JJ) as(IN) manager(NN).
(VB-verb, JJ-adjective, NN*-noun)
2. Determining query type : taking first verb and searching his presence in Keywords_DB => Give => Query type= “Select”.
SmartSQL145
Timetable
ID SID Role
ShiftsSID Day Time
SmartSQL
Application Design Document
3. Determining role of each noun and adjective in the query by looking for their presence in : Keywords_DB , DB_Schema, Table_Conversion, Field_Conversion and DB_Values. If the word was found in one of these xmls, its object and role in query are updated in Sql_Builder package. If there are a few words matching, the system turns to the user for clarifications.
SQL mapping rules:a. First verb determines SQL type.b. Each found tables are mapped to join table section (”From”) in the query.c. Each found field after the word “that” are mapped to “Where” section of the
query.d. Each found field before the word “that” are mapped to the “Select” section of the
query.e. If found table in the “Select” part of NL query, than all the fields of this table will
be chosen for the SQL query.
Mapping:
Word Data level Role SQL_Builder actions Turn to Userfor clarifications
nurses DB_Schema Table 1. Creating object Table (Nurses).
saturday Word NetShould be in one of the xmls.
Condition of field Day in Shifts table
1. Creating object Table (Shifts).2. Creating object Field (Day).3. Updating where condition in the Day object.
night Word NetShould be on one of the xmls.
Condition of field Time in Shifts table
2. Creating object Field (Time).3. Updating where condition in the Time object.
There is no matching in field format, thus program presents the User format of the field that he should fill in.
manager Word NetShould be in one of the xmls.
Condition of field Role on Timetable table.
1. Creating object Table (Timetable).2. Creating object Field (Role).3. Updating where condition in the Role
SmartSQL146
SmartSQL
Application Design Document
object.
SmartSQL147
SmartSQL
Application Design Document
4. Building SQL Query by SQL_Builder:
Result:
SELECT * FROM Nurses INNER JOIN Timetable ON (Nurses .ID= Timetable .ID) INNER JOIN Shifts ON (Timetable .SID= Shifts .SID)WHERE Shifts.Day=”saturday” and Shifts.Time 23:00 and Shifts.Time 7:00 and Timetable.Role=”manager”.
SmartSQL148