0% found this document useful (0 votes)
54 views

Query Languages: SQL - CQL: HS Practical Corpus Linguistics Tim Ladiges WS 2005/ 06

This document provides an overview of query languages SQL and CQL. It defines SQL as a relational data definition and manipulation language used with databases. CQL is used to query text corpora and can include searches for words, tags, and syntactic patterns. The document explains how to construct queries in both languages, including using SELECT statements and operators in SQL and defining atomic queries joined with operators in CQL.

Uploaded by

rajarajkumar543
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

Query Languages: SQL - CQL: HS Practical Corpus Linguistics Tim Ladiges WS 2005/ 06

This document provides an overview of query languages SQL and CQL. It defines SQL as a relational data definition and manipulation language used with databases. CQL is used to query text corpora and can include searches for words, tags, and syntactic patterns. The document explains how to construct queries in both languages, including using SELECT statements and operators in SQL and defining atomic queries joined with operators in CQL.

Uploaded by

rajarajkumar543
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 18

Query Languages: SQL - CQL

HS Practical Corpus Linguistics Tim Ladiges WS 2005/ 06

Keywords
Database Query Structured Query Language Corpus Query Language

What is a Database?
Structure to hold data Self-describing collection of integrated records Administered by Database Management System (DBMS) Relational databases are based on tables DB stores metadata in data dictionary (description of tables, columns, indexes,)

What are Queries?


A formulated request for the search tool
e.g. to find items from a corpus

If data in DB satisfies conditions of query, SQL retrieves queried data Important how to formulate the query that will produce the words

Database Access
User

------------------------------Application Programs/Queries

-----------------------------Software to Process Queries/Programs

DBMS
Software to Access Stored Data

-------------------------------Database Definition Stored Database

Simplified Database Environment (Elmashi, Navathe 2000: 6)

Structured Query Language (SQL)


The most common data sublanguage in use today Used especially in client/server system A relational data definition and manipulation language Difference to other computer languages: tell SQL what you want, not: how to get it DBMS provides what has been queried SQL query: SELECT <attribute list>
FROM <table list> WHERE <condition>

Components of SQL
Data Definition Language (DDL) creation of relational databases containment hierarchy (tables, schemas, catalogs, database) Data Manipulation Language (DML)
Database maintenance

Data Control Language (DCL)


security for database

Query example in SQL


Goal: we want the address of each employee Method: SELECT ColumnName, ColumnName, ... FROM TableName;
EmployeeAddressTable

SSN
512687458 758420012 102254896 876512563

FirstName
Joe Mary Sam Sarah

LastName
Smith Scott Jones Ackerman

Address
83 First Street 842 Vine Ave. 33 Elm St. 440 U.S. 110

City
Howard Losantiville Paris Upton

State
Ohio Ohio New York Michigan

Query example in SQL


SELECT FirstName, LastName, Address, City, State FROM EmployeeAddressTable; Result of our query:

First Name Joe Mary

Last Name Smith Scott

Address 83 First Street 842 Vine Ave.

City Howard Losantiville

State Ohio Ohio

Sam Sarah

Jones Ackerman

33 Elm St. 440 U.S. 110

Paris Upton

New York Michigan

Query Example in SQL: Conditional Selection


Goal: display only certain rows, which meet query criteria Method: use of WHERE clause and relational operators Relational operators: = < or != < > <= >= Equal Not Equal Less Than Greater Than Less Than or Equal To Greater Than or Equal To

Query Example in SQL


Goal: Last Name of employees who are from Ohio SELECT LastName FROM EmployeeAddressTable WHERE State = Ohio; any text in statement always in single quote Result of our query: Scott, Smith 1 further example: Goal: in a given table look for employees who earn $50,000 or more SELECT EMPLOYEEIDNO FROM EMPLOYEESTATISTICSTABLE WHERE SALARY >= 50000; Result of our query: any employee ID numbers which share a table row with a salary entry of 50,000 or more

SQL on the Internet


Advantages:
Low cost for the client standardized user interface standardized client/server relationship

Disadvantages:
security questions arise

Corpus Query Languages (CQL)


Used to retrieve data from corpora Corpus query tool SARA uses CQL Tasks:
encoding of syntactic annotations of corpus definition of queries

Depending on tasks and corpora CQL may vary

The Corpus Query


What are we looking for?
Query for word, syntactic constituents, etc.

Corpus annotation?
Plain text, PoS-tagged, syntactically annotated, semantic tags

Output of Corpus Query?


KWIC, PoS-tags, syntactic structures, lemmas, etc.

How do I define a CQL query?


CQL: command language which a SARA client program uses to communicate with the SARA server CQL syntax CQL query consists of one or more atomic queries like the following: a word, punctuation mark, or delimited string e.g. jam, ?, "Mrs."; a word-and-POS pair, e.g. "CAN"=NN1; a phrase, e.g. "not on your life"; a pattern; an SGML query, that is, a search for a start- or end-tag. Attribute values may also be searched for; the wildcard character _, which will match any single word.

How do I define a CQL query?


Four unary operators are allowed in CQL: case The $ operator makes the query which is its operand case-sensitive. header The @ operator makes the query which is its operand search within headers as well as in the bodies of texts. not The ! operator matches anything which is not a solution to the query which is its operand; it makes no sense unless the query is combined with another.

A CQL expression containing more than one atomic query may use the following binary operators: sequence one or more blanks between two queries matches cases where solutions to the first immediately precede solutions to the second. disjunction The | operator between two queries matches cases where either query is satisfied. join The * operator between two queries matches cases where both queries are satisfied in the order specified; the # operator between two queries matches cases where both queries are satisfied in either order.

How do I define a CQL query?


When queries are joined, the scope of the expression may be defined in one of the following ways:

SGML element A join query followed by a / operator and an SGML query matches cases where the joined query is satisfied within the scope of the SGML element. number A join query followed by a / operator and a number matches cases where the joined query is satisfied within the number of L-words specified.

Examples: cat _ dog finds three word phrases of which the first word is `cat' and the last is `dog !cat dog finds occurrences of `dog' not preceded by `cat' within the same document cat*dog finds occurrences of `cat' followed anywhere within the same document by `dog' cat#dog finds occurrences of `cat' followed or preceded by `dog' anywhere within the same document cat*dog/10 finds occurrences of `cat' followed by `dog' within ten words cat*dog/ finds occurrences of `cat' followed by `dog' within a single <head> element

Resources
Merz, Charlotte: Gastreferat zur Vorlesung Korpuslinguistik mit und fr Computerlinguistik, 3.12.2002. http://www.ifi.unizh.ch/cl/volk/corpling/Vorl_07_Korpus-Abfrage.pdf Taylor, Allen G. (1998) SQL for Dummies, 3rd Edition, Foster City, CA, IDG Books Worldwide, Inc. Reference Guide to the SARA Windows Client http://www.natcorp.ox.ac.uk/getting/chap4.htm#FIMNU Tutorial on SQL http://riki-lb1.vet.ohiostate.edu/mqlin/computec/tutorials/SQLTutorial.htm

You might also like