Transcript PPT
Logics for Data and Knowledge
Representation
Exercises: Languages
Fausto Giunchiglia, Rui Zhang and Vincenzo Maltese
Outline
BNF grammars
Basic exercises
BNF for ER diagrams
BNF for natural languages (POS tagging)
2
BNF GRAMMARS :: BASIC EXERCISES :: BNF AND ER DIAGRAMS :: POS TAGGING
Backus–Naur Form (BNF)
BNF is a syntax used to express context-free grammars:
that is, a formal way to describe formal languages.
Optional items are enclosed in square brackets: [ ]
Items repeating 0 or more times are enclosed in curly brackets
and/or suffixed with an asterisk: { }*
Items repeating 1 or more times are followed by a +
Terminals may appear in bold and Non-Terminals in plain text
rather than using italics and angle brackets <>
Alternative choices in a production are separated by the | symbol
Where items need to be grouped they are enclosed in simple
parentheses ().
3
BNF GRAMMARS :: BASIC EXERCISES :: BNF AND ER DIAGRAMS :: POS TAGGING
Example of BNF: A mathematical expression
1.
<expression> ::= <value> [<operator> <expression>]
2.
<value > ::= [<sign>] <unsigned> [ . <unsigned>]
3.
<unsigned> ::= <digit> {<digit>}*
4.
<digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
5.
<sign> ::= + | -
6.
<operator> ::= + | - | * | /
4
BNF GRAMMARS :: BASIC EXERCISES :: BNF AND ER DIAGRAMS :: POS TAGGING
Exercises of BNF: mathematical expressions
Are
1.
2.
3.
4.
5.
the following well-formed formulas of expression?
123
00123
199 + 299
+ 20 * 200
+ - 345 / (123 + 456)
1. YES
5
2. YES
3. YES
4. YES
5. NO
BNF GRAMMARS :: BASIC EXERCISES :: BNF AND ER DIAGRAMS :: POS TAGGING
Exercises of BNF: PL language
Consider
the BNF for the PL language above:
<Atomic Formula> ::= A | B | ... | P | Q | ... | ⊥ | ⊤
<wff> ::= <Atomic Formula> | ¬<wff> | <wff>∧ <wff> | <wff>∨ <wff>
Differentiate wff from others below:
4.
A⊔
A⊓
A∧
A∧
5.
¬A ∨ B ∧
1.
2.
3.
1. NO
6
B⊒A
B⊑B
¬B
B⊨ A∨ B
⊤
2. NO
3. YES
4. NO
5.YES
BNF GRAMMARS :: BASIC EXERCISES :: BNF AND ER DIAGRAMS :: POS TAGGING
Recall: ER Diagram
In software engineering, an Entity-Relationship (ER) Model
is an abstract and conceptual representation of data.
The basic components of ER:
Entity
Relation
Cardinality of Relation
Cardinality of Attribute
Attribute
Primary Key
Monkey
0..1
Climb
Banana
ID
7
0..n
Box
Height
BNF GRAMMARS :: BASIC EXERCISES :: BNF AND ER DIAGRAMS :: POS TAGGING
The BNF for ER Diagrams
<entity> ::=
<relation> ::=
<attribute> ::=
<conn> ::=
Entity
Relation
Attribute
[ <digit> “..” <digit> ]
<digit> ::= 0 | 1 | n | m
<sentence> ::= <entity> {<conn> <relation> <conn> <entity>}* |
<entity> {<conn> < attribute>}*
<Diagram> :: = {<sentence>}*
8
BNF GRAMMARS :: BASIC EXERCISES :: BNF AND ER DIAGRAMS :: POS TAGGING
BNF of Yahoo! Directory
The Yahoo! Directory is an online guide to the World Wide Web.
It is a catalog of sites created by a staff of editors who visit and
evaluate web sites, and then organize them into subject-based
categories and sub-categories.
Yahoo! editors distinguish between a number of factors when
organizing web sites, including commercial vs. non-commercial,
regional vs. global, and so forth. All of the site listings in the
Directory are contained in an appropriate place within the 14
main categories seen on the front page of the Yahoo! Directory.
9
BNF GRAMMARS :: BASIC EXERCISES :: BNF AND ER DIAGRAMS :: POS TAGGING
So take a look!
10
BNF GRAMMARS :: BASIC EXERCISES :: BNF AND ER DIAGRAMS :: POS TAGGING
Preliminaries: Open/Close Word Class
In linguistics, an open class (or open word class) is a word
class that accepts the addition of new items, through such
processes as compounding, derivation, coining, borrowing, etc.
Typical open word classes are nouns, verbs and adjectives.
A closed class (or closed word class) is a word class to which
no new items can normally be added, and that usually contains
a relatively small number of items.
Typical closed classes found in many languages are
adpositions (prepositions and postpositions), determiners,
conjunctions, and pronouns.
11
BNF GRAMMARS :: BASIC EXERCISES :: BNF AND ER DIAGRAMS :: POS TAGGING
Parts of Speech: open word class
OPEN WORD CLASS
JJ//Adjective
NN//Noun, singular or mass
NNS//Noun, plural
NNP//Proper noun, singular
RB//Adverb
VB//Verb, base form
VBD//Verb, past tense
VBZ//Verb, 3rd person singular present
12
EXAMPLE
blue / green / soft
apple / sugar
apples
Fausto
slowly
go
went
goes
BNF GRAMMARS :: BASIC EXERCISES :: BNF AND ER DIAGRAMS :: POS TAGGING
Parts of Speech: closed word class
CLOSED WORD CLASS
CC//Coordinating conjunction
CD//Cardinal number
DT//Determiner
IN//Preposition or subordinating conjunction
POS//Possessive ending
TO//to
13
EXAMPLE
and / or
the / an / a
in / for / but
to
BNF GRAMMARS :: BASIC EXERCISES :: BNF AND ER DIAGRAMS :: POS TAGGING
BNF for Yahoo Directory
(1)
ForwardPhrase::= [VB] [IN] DisPhrase {Conn } DisPhrase
(2)
DisPhrase::= Phrase [“(”ProperDis | NounDis“)”] [“(”Period“)”][“:” Phrase]
(3)
Phrase::=[DT] Adjectives [Nouns] | [Proper] Nouns
(4)
Adjectives::= Adjective|CD {[CC] Adjective}
(5)
Nouns::= Noun {Noun}
(6)
Conn::= ConjunctionConn | PrepositionConn
(7)
Noun::= NN [POS] | NNS [POS]
(8)
Adjective::= JJ
(9)
ConjunctionConn::= CC | “,”
(10) PrepositionConn::= IN | TO
(11) Proper::= NNP {NNP|POS}
(12) NounDis::= Period|Nouns|Adjectives [Nouns]
(13) ProperDis::= ProperSeq [CC ProperSeq]
(14) Period::= [NN] CD [“-”] [CD] [NN]
(15) ProperSeq::= Proper [“,” Proper]
14
BNF GRAMMARS :: BASIC EXERCISES :: BNF AND ER DIAGRAMS :: POS TAGGING
Example: Provinces and Districts
Provinces and Districts
ForwardPhrase
Conn
ForwardPhrase
DisPhrase
ConjunctionConn
DisPhrase
Phrase
Phrase
Nouns
Nouns
Noun
Noun
NNS
15
CC
NNS
BNF GRAMMARS :: BASIC EXERCISES :: BNF AND ER DIAGRAMS :: POS TAGGING
Examples
Science > Computer Science > Artificial Intelligence > Natural
Language Processing > Web Directories
Computer Science
NN
NN
Artificial Intelligence
JJ
NN
Natural Language Processing
JJ
NN
VBG
Web Directories
NN NNS
16