160 likes | 276 Views
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). Backus–Naur Form (BNF).
E N D
Logics for Data and KnowledgeRepresentation Exercises: Languages Fausto Giunchiglia, Rui Zhang and Vincenzo Maltese
Outline • BNF grammars • Basic exercises • BNF for ER diagrams • BNF for natural languages (POS tagging)
Backus–Naur Form (BNF) BNF GRAMMARS :: BASIC EXERCISES :: BNF AND ER DIAGRAMS :: POS TAGGING • 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
Example of BNF: A mathematical expression BNF GRAMMARS :: BASIC EXERCISES :: BNF AND ER DIAGRAMS :: POS TAGGING • <expression> ::= <value> [<operator> <expression>] • <value > ::=[<sign>] <unsigned> [ . <unsigned>] • <unsigned> ::= <digit> {<digit>}* • <digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 • <sign> ::= + | - • <operator> ::= + | - | * | / 4
Exercises of BNF: mathematical expressions BNF GRAMMARS :: BASIC EXERCISES :: BNF AND ER DIAGRAMS :: POS TAGGING • Are the following well-formed formulas of expression? • 123 • 00123 • 199 + 299 • + 20 * 200 • + - 345 / (123 + 456) 1. YES 2. YES 3. YES 4. YES 5. NO 5
Exercises of BNF: PL language BNF GRAMMARS :: BASIC EXERCISES :: BNF AND ER DIAGRAMS :: POS TAGGING • 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: • A ⊔ B ⊒ A • A ⊓ B ⊑ B • A ∧ ¬B • A ∧ B ⊨ A ∨ B • ¬A ∨ B ∧ ⊤ 1. NO 2. NO 3. YES 4. NO 5.YES 6
Recall: ER Diagram BNF GRAMMARS :: BASIC EXERCISES :: BNF AND ER DIAGRAMS :: POS TAGGING • In software engineering, an Entity-Relationship (ER) Model is an abstract and conceptual representationof data. • The basic components of ER: • Entity • Relation • Cardinality of Relation • Cardinality of Attribute • Attribute • Primary Key 0..1 Climb 0..n Monkey Box Height Banana ID 7
The BNF for ER Diagrams BNF GRAMMARS :: BASIC EXERCISES :: BNF AND ER DIAGRAMS :: POS TAGGING <entity> ::= <relation> ::= <attribute> ::= <conn> ::=[ <digit> “..” <digit> ] <digit> ::= 0 | 1 | n | m <sentence> ::= <entity> {<conn> <relation> <conn> <entity>}* | <entity>{<conn> < attribute>}* <Diagram> :: ={<sentence>}* Entity Relation Attribute 8
BNF of Yahoo! Directory BNF GRAMMARS :: BASIC EXERCISES :: BNF AND ER DIAGRAMS :: POS TAGGING • 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
So take a look! BNF GRAMMARS :: BASIC EXERCISES :: BNF AND ER DIAGRAMS :: POS TAGGING 10
Preliminaries: Open/Close Word Class BNF GRAMMARS :: BASIC EXERCISES :: BNF AND ER DIAGRAMS :: POS TAGGING • 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
Parts of Speech: open word class BNF GRAMMARS :: BASIC EXERCISES :: BNF AND ER DIAGRAMS :: POS TAGGING OPEN WORD CLASSEXAMPLE JJ//Adjective blue / green / soft NN//Noun, singular or mass apple / sugar NNS//Noun, plural apples NNP//Proper noun, singular Fausto RB//Adverb slowly VB//Verb, base form go VBD//Verb, past tense went VBZ//Verb, 3rd person singular present goes 12
Parts of Speech: closed word class BNF GRAMMARS :: BASIC EXERCISES :: BNF AND ER DIAGRAMS :: POS TAGGING CLOSED WORD CLASS EXAMPLE CC//Coordinating conjunction and / or CD//Cardinal number DT//Determiner the / an / a IN//Preposition or subordinating conjunction in / for / but POS//Possessive ending TO//to to 13
BNF for Yahoo Directory BNF GRAMMARS :: BASIC EXERCISES :: BNF AND ER DIAGRAMS :: POS TAGGING (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
Example: Provinces and Districts BNF GRAMMARS :: BASIC EXERCISES :: BNF AND ER DIAGRAMS :: POS TAGGING Provinces and Districts ForwardPhrase Conn ForwardPhrase DisPhrase ConjunctionConn DisPhrase Phrase Phrase Nouns Nouns Noun Noun NNS NNS CC 15
Examples BNF GRAMMARS :: BASIC EXERCISES :: BNF AND ER DIAGRAMS :: POS TAGGING • 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