Session - 6 - Complex Data Types
Session - 6 - Complex Data Types
Session 6
Academic year 2023-2024
SELECT ?name
WHERE {
?cid title "Intro. to Computer Science" . "Intro. to Computer Science," is represented by the variable
?cid
?sid course ?cid .
?id takes ?sid . student takes the specified computer science course
?id name ?name . entity with an identifier (?id) takes the course
} represented by ?sid
• User-defined types
create type Person
(ID varchar(20) primary key,
name varchar(20),
address varchar(20)) ref from(ID); instances of this type can be
create table people of Person; referenced by their ID
• Table types
create type interest as table ( Create interest which
is a table
topic varchar(20),
degree_of_interest int);
create table users (
ID varchar(20), interests is interest
type, so a table
name varchar(20),
interests interest);
Object-relational Database
• Type inheritance
create type Student under Person
(degree varchar(20)) ;
create type Teacher under Person
(salary integer);
• Table inheritance and hierarchy
create table students
(degree varchar(20))
inherits people;
create table teachers
(salary integer)
inherits people;
create table people of Person; Creates a table people as base table
create table students of Student
under people;
create table teachers of Teacher
under people;
Object-relational Database
• Creating reference types
create type Department ( Head reference to Person and
dept_name varchar(20), must be under the scope of table
head ref(Person) scope people); people
create table departments of Department
12345 is the ID in the table Person
insert into departments values ('CS', '12345’)
• System generated references can be retrieved using subqueries
select ref(p)
from people as p
where ID = '12345'
• Using references in path expressions
select head->name, head->address
from departments;
Object-relational mapping
• Object-relational mapping (ORM) systems allow
• Specification of mapping between programming language objects and database
tuples
• Automatic creation of database tuples upon creation of objects
• Automatic update/delete of database tuples when objects are update/deleted
• Interface to retrieve objects satisfying specified conditions
• Tuples in database are queried, and object created from the tuples
• Django ORM for Python
Textual Data
Textual data
• Information retrieval when querying of unstructured data
• Simple model of keyword queries: given query keywords, retrieve documents
containing all the keywords
• More advanced models rank the relevance of documents
• Today, keyword queries return many types of information as answers
• E.g., a query “cricket” typically returns information about ongoing cricket
matches
• Relevance ranking
• Essential since there are usually many documents matching keywords
Ranking using TF-ITF
• Term: keyword occurring in a document/query
• Term Frequency: TF(d, t), the relevance of a term t to a document d
• One definition: TF(d, t) = log(1 + n(d,t)/n(d))
where
• n(d,t) = number of occurrences of term t in document d
• n(d) = number of terms in document d
• Inverse Document Frequency: IDF(t)
• One definition: IDF(t) = log(N/n(t))
Where
• N is the total number of documents in the collection.
• n(t) is the number of documents containing the term t
• F1 Score is the harmonic mean of precision and recall, providing a balanced measure
of both