summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authoraarne <aarne@chalmers.se>2010-06-19 16:24:48 +0000
committeraarne <aarne@chalmers.se>2010-06-19 16:24:48 +0000
commit041e5e2a337f7f90e1832f98a1c85b11e1810142 (patch)
tree33035f794398c493494b7ce52751afd3bb1d73ed /examples
parenta0f2ff0772a112b323c95f6b236e3cd3d349e579 (diff)
query language generalized and extended ; added README
Diffstat (limited to 'examples')
-rw-r--r--examples/query/Query.gf66
-rw-r--r--examples/query/QueryEng.gf166
-rw-r--r--examples/query/README57
3 files changed, 201 insertions, 88 deletions
diff --git a/examples/query/Query.gf b/examples/query/Query.gf
index 34f714b88..4687f6c06 100644
--- a/examples/query/Query.gf
+++ b/examples/query/Query.gf
@@ -10,8 +10,10 @@ cat
Query ;
Answer ;
Set ; -- the set requested, e.g. "all persons"
- Relation ; -- something of something, e.g. "subregion of Bulgaria"
+ Interrogative ; -- interrog. pron. e.g. "who"
+ Function ; -- something of something, e.g. "subregion of Bulgaria"
Kind ; -- type of things, e.g. "person"
+ Relation ; -- relation between things,e.g. "employed at"
Property ; -- property of things, e.g. "employed at Google"
Individual ; -- one entity, e.g. "Google"
Name ; -- person, company... e.g. "Eric Schmidt"
@@ -22,13 +24,16 @@ fun
MAnswer : Answer -> Move ;
QSet : Set -> Query ; -- (give me | what are | which are | ) (S | the names of S | S's names)
- QWhere : Set -> Query ; -- where are S
- QWhat : Kind -> Property -> Query ; -- what K P
- QWho : Property -> Query ; -- who P
- QRel : Relation -> Set -> Query ; -- what R does S have
- QInfo : Set -> Query ; -- (give me | ) (information about | all about) S
- QCalled : Individual -> Query ; -- how is X (also | otherwise) (called | named | known) ;
- QWhether : Answer -> Query ; -- is S P --- not in the corpus, but should be ??
+ QWhere : Set -> Query ; -- where are S
+ QWhat : Interrogative -> Property -> Query ; -- who P
+ QWhatWhat : Interrogative -> Interrogative -> Relation -> Query ; -- who R what
+ QWhatWhere : Interrogative -> Relation -> Query ; -- who R where --- overgenerating
+ QRelWhere : Set -> Relation -> Query ; -- where does S R --- overgenerating
+ QFun : Function -> Set -> Query ; -- what R does S have
+ QFunPair : Set -> Function -> Query ; -- S and their R's
+ QInfo : Set -> Query ; -- (give me | ) (information about | all about) S
+ QCalled : Individual -> Query ; -- how is X (also | otherwise) (called | named | known) ;
+ QWhether : Answer -> Query ; -- is S P --- not in the corpus, but should be ??
AKind : Set -> Kind -> Answer ; -- S is a K
AInd : Set -> Individual -> Answer ; -- S is I
@@ -36,7 +41,7 @@ fun
AProp : Set -> Property -> Answer ; -- S is P
SAll : Kind -> Set ; -- all Ks | the Ks
- SRel : Set -> Relation -> Set ; -- S's Rs
+ SFun : Set -> Function -> Set ; -- S's Rs
SOne : Kind -> Set ; -- one K
SIndef : Kind -> Set ; -- a K
SDef : Kind -> Set ; -- the K
@@ -45,12 +50,16 @@ fun
SInd : Individual -> Set ; -- X
SInds : [Individual] -> Set ; -- X and Y
- KRelSet : Relation -> Set -> Kind ; -- R of S | S's R
- KRelsSet : Relation -> Relation -> Set -> Kind ; -- R and Q of S
- KRelKind : Kind -> Relation -> Set -> Kind ; -- K that is R of S
- KRelPair : Kind -> Relation -> Kind ; -- S's with their R's
+ IWho : Interrogative ; -- who
+ IWhat : Interrogative ; -- what
+ IWhich : Kind -> Interrogative ; -- which K | what K | which Ks | what Ks
+
+ KFunSet : Function -> Set -> Kind ; -- R of S | S's R
+ KFunsSet : Function -> Function -> Set -> Kind ; -- R and Q of S
+ KFunKind : Kind -> Function -> Set -> Kind ; -- K that is R of S
+ KFunPair : Kind -> Function -> Kind ; -- S's with their R's
KProp : Property -> Kind -> Kind ; -- P K | K that is P
- KRel : Relation -> Kind ; -- R ---??
+ KFun : Function -> Kind ; -- R ---??
IName : Name -> Individual ;
@@ -59,6 +68,8 @@ fun
PIs : Individual -> Property ;
+ PRelation : Relation -> Set -> Property ;
+
-- the test lexicon
cat
@@ -68,32 +79,37 @@ fun
NCountry : Country -> Name ;
PCountry : Country -> Property ;
- Located : Set -> Property ;
+ Located : Relation ;
- In : Set -> Property ;
- HaveTitleAt : JobTitle -> Set -> Property ;
- HaveTitle : JobTitle -> Property ;
- Employed : Set -> Property ;
+ In : Relation ;
+ HaveTitleAt : JobTitle -> Relation ;
+ EmployedAt : Set -> Relation ;
+ HaveTitle : Relation ;
+ Employed : Relation ;
Named : Name -> Property ;
+
Start : Name -> Property ;
Organization : Kind ;
+ Company : Kind ;
Place : Kind ;
Person : Kind ;
- Location : Relation ;
- Region : Relation ;
- Subregion : Relation ;
+ Location : Function ;
+ Region : Function ;
+ Subregion : Function ;
USA : Country ;
California : Country ;
Bulgaria : Country ;
OblastSofiya : Name ;
- RName : Relation ;
- RNickname : Relation ;
- RJobTitle : Relation ;
+ FName : Function ;
+ FNickname : Function ;
+ FJobTitle : Function ;
+
+ SJobTitle : JobTitle -> Set ; -- a programmer
CEO : JobTitle ;
ChiefInformationOfficer : JobTitle ;
diff --git a/examples/query/QueryEng.gf b/examples/query/QueryEng.gf
index 8f0756e77..7ab5c2ef5 100644
--- a/examples/query/QueryEng.gf
+++ b/examples/query/QueryEng.gf
@@ -15,9 +15,11 @@ lincat
Query = Utt ;
Answer = Cl ; -- Utt ;
Set = NP ;
- Relation = {cn : CN ; prep : Prep} ;
+ Interrogative = IP ;
+ Function = {cn : CN ; prep : Prep} ;
Kind = CN ;
Property = {ap : AP ; vp : VP} ;
+ Relation = {ap : AP ; vp : VP ; prep : Prep} ;
Individual = NP ;
Name = NP ;
[Individual] = [NP] ;
@@ -39,19 +41,34 @@ lin
| mkUtt (mkQS (mkQCl (L.CompIP (L.IdetIP (mkIDet which_IQuant))) ss))
| mkUtt ss ;
- QWhat k p =
- mkUtt (mkQS (mkQCl (mkIP (what_IQuant | which_IQuant) (sgNum | plNum) k) p.vp)) ;
- QWho p = mkUtt (mkQS (mkQCl whoSg_IP p.vp)) ;
-
QWhere s =
mkUtt (mkQS (mkQCl where_IAdv s))
| mkUtt (mkQS (mkQCl where_IAdv (mkCl s (mkA "located" | mkA "situated")))) ;
- QRel r s =
+ QWhat i p = mkUtt (mkQS (mkQCl i p.vp)) ;
+ QWhatWhat i j p = mkUtt (mkQS (QuestQVP i (AdvQVP p.vp (mkIAdv p.prep j)))) ;
+ QWhatWhere i p = mkUtt (mkQS (QuestQVP i (AdvQVP p.vp where_IAdv))) ;
+ QRelWhere s p = mkUtt (mkQS (mkQCl where_IAdv (mkCl s p.vp))) ;
+
+ QFun r s =
mkUtt
- (mkImp (mkVP give_V3 (mkNP and_Conj s (mkNP (mkQuant they_Pron) plNum r.cn)) (mkNP i_Pron)))
+ (mkImp (mkVP give_V3
+ (mkNP and_Conj s (mkNP (mkQuant they_Pron) plNum r.cn)) (mkNP i_Pron)))
| mkUtt (mkQS (mkQCl (mkIP what_IQuant plNum r.cn) s have_V2))
| mkUtt (mkQS (mkQCl whatSg_IP
(mkClSlash (mkClSlash s have_V2) (mkAdv as_Prep (mkNP aPl_Det r.cn))))) ;
+
+ QFunPair s f =
+ let
+ ss0 : NP = s
+ | mkNP (mkNP thePl_Det L.name_N) (mkAdv possess_Prep s) ;
+ ss : NP = mkNP and_Conj ss0 (mkNP (mkQuant they_Pron) plNum f.cn)
+ | mkNP ss0 (mkAdv with_Prep (mkNP (mkQuant they_Pron) plNum f.cn))
+ in
+ mkUtt (mkImp (mkVP give_V3 ss (mkNP i_Pron)))
+ | mkUtt (mkQS (mkQCl (L.CompIP whatPl_IP) ss))
+ | mkUtt (mkQS (mkQCl (L.CompIP (L.IdetIP (mkIDet which_IQuant))) ss))
+ | mkUtt ss ;
+
QInfo s =
let
info : NP = mkNP (all_NP | (mkNP information_N)) (mkAdv about_Prep s) ;
@@ -72,7 +89,7 @@ lin
AProp s p = (mkCl s p.vp) ;
SAll k = mkNP all_Predet (mkNP aPl_Det k) | mkNP thePl_Det k ;
- SRel s r = mkNP (GenNP s) plNum r.cn | mkNP (GenNP s) sgNum r.cn ;
+ SFun s r = mkNP (GenNP s) plNum r.cn | mkNP (GenNP s) sgNum r.cn ;
SOne k = mkNP n1_Numeral k ;
SIndef k = mkNP a_Det k ;
SDef k = mkNP the_Det k ;
@@ -81,20 +98,27 @@ lin
SInd i = i ;
SInds is = mkNP and_Conj is ;
- KRelSet r s =
+ IWhich k =
+ mkIP what_IQuant (sgNum | plNum) k
+ | mkIP which_IQuant (sgNum | plNum) k ;
+
+ IWho = whoSg_IP | whoPl_IP ;
+ IWhat = whatSg_IP | whatPl_IP ;
+
+ KFunSet r s =
mkCN r.cn (mkAdv r.prep s) ;
- KRelsSet r q s =
+ KFunsSet r q s =
mkCN (ConjCN and_Conj (BaseCN r.cn q.cn)) (mkAdv r.prep s) ;
- KRelKind k r s =
+ KFunKind k r s =
mkCN k (mkRS (mkRCl that_RP (mkVP (mkNP aPl_Det (mkCN r.cn (mkAdv r.prep s)))))) ;
- KRelPair k r = mkCN k (mkAdv with_Prep (mkNP (mkQuant they_Pron) plNum r.cn)) ;
+ KFunPair k r = mkCN k (mkAdv with_Prep (mkNP (mkQuant they_Pron) plNum r.cn)) ;
KProp p k =
mkCN p.ap k
| mkCN k (mkRS (mkRCl that_RP p.vp)) ;
- KRel r = r.cn ;
+ KFun r = r.cn ;
IName n = n ;
@@ -103,6 +127,11 @@ lin
PIs i = propVP (mkVP i) ;
+ PRelation r s = {
+ ap = AdvAP r.ap (mkAdv r.prep s) ;
+ vp = mkVP r.vp (mkAdv r.prep s)
+ } ;
+
BaseIndividual = mkListNP ;
ConsIndividual = mkListNP ;
@@ -125,7 +154,7 @@ oper
-- lexical constructors
mkName : Str -> NP =
\s -> mkNP (mkPN s) ;
- mkRelation : Str -> {cn : CN ; prep : Prep} =
+ mkFunction : Str -> {cn : CN ; prep : Prep} =
\s -> {cn = mkCN (mkN s) ; prep = possess_Prep} ;
propAP : AP -> {ap : AP ; vp : VP} = \ap -> {
@@ -138,9 +167,22 @@ oper
vp = vp
} ;
+ relAP : AP -> Prep -> {ap : AP ; vp : VP ; prep : Prep} = \ap,p -> {
+ ap = ap ;
+ vp = mkVP ap ;
+ prep = p
+ } ;
+
+ relVP : VP -> Prep -> {ap : AP ; vp : VP ; prep : Prep} = \vp,p -> {
+ ap = PartVP vp ;
+ vp = vp ;
+ prep = p
+ } ;
+
propCalled : NP -> {ap : AP ; vp : VP} = \i ->
propAP (mkAP (also_AdA | otherwise_AdA) (mkAP (mkA2 called_A []) i)) ;
+ noPrep : Prep = mkPrep [] ;
-- lexicon
@@ -151,65 +193,63 @@ lin
NCountry c = c.np ;
PCountry c = propAP (mkAP c.a) ;
- Located i = propAP (
- mkAP (mkA2 (mkA "located") in_Prep) i
- | mkAP (mkA2 (mkA "situated") in_Prep) i
- ) ;
-
- In i = propVP (mkVP (mkAdv in_Prep i)) ;
-
- Employed i = propAP (
- mkAP (mkA2 (mkA "employed") by8agent_Prep) i
- | mkAP (mkA2 (mkA "paid") by8agent_Prep) i
- | mkAP (mkA2 (mkA "active") at_Prep) i
- | mkAP (mkA2 (mkA "professionally active") at_Prep) i
- )
- |
- propVP (
- mkVP (mkV2 (mkV "work") at_Prep) i
- | mkVP (mkV2 (mkV "collaborate") in_Prep) i
- ) ;
-
- HaveTitle t =
- propAP (
- mkAP (mkA2 (mkA "employed") as_Prep) (mkNP t)
- )
- |
- propVP (
- mkVP (mkNP a_Det t)
- | mkVP (mkV2 (mkV "work") as_Prep) (mkNP t)
--- | mkVP have_V2 (mkNP the_Det (mkCN (mkN2 (mkN "title")) (mkNP t)))
- ) ;
-
- HaveTitleAt t i =
- propAP (
- mkAP (mkA2 (mkA "employed") as_Prep) (mkNP (mkNP t) (mkAdv at_Prep i))
- )
- |
- propVP (
- mkVP (mkVP (mkNP a_Det t)) (mkAdv at_Prep i)
- | mkVP (mkVP (mkV2 (mkV "work") as_Prep) (mkNP t)) (mkAdv at_Prep i)
--- | mkVP (mkVP have_V2 (mkNP the_Det (mkCN (mkN2 (mkN "title")) (mkNP t))))
--- (mkAdv at_Prep i)
- ) ;
+ Located =
+ relAP (mkAP (mkA "located")) in_Prep
+ | relAP (mkAP (mkA "situated")) in_Prep
+ ;
+
+ In = relVP UseCopula in_Prep ;
+
+ Employed =
+ relAP (mkAP (mkA "employed")) by8agent_Prep
+ | relAP (mkAP (mkA "paid")) by8agent_Prep
+ | relAP (mkAP (mkA "active")) at_Prep
+ | relAP (mkAP (mkA "professionally active")) at_Prep
+ | relVP (mkVP (mkV "work")) at_Prep
+ | relVP (mkVP (mkV "collaborate")) in_Prep
+ ;
+
+ HaveTitle =
+ relAP (mkAP (mkA "employed")) as_Prep
+ --- | relVP UseCopula noPrep
+ | relVP (mkVP (mkV "work")) as_Prep
+ | relVP (mkVP have_V2 (mkNP the_Det (mkCN (mkN2 (mkN "title"))))) possess_Prep
+ ;
+
+ EmployedAt s =
+ relAP (mkAP (mkA2 (mkA "employed") at_Prep) s) as_Prep
+ | relAP (mkAP (mkA2 (mkA "employed") by8agent_Prep) s) as_Prep
+ | relVP (mkVP (mkV2 (mkV "work") at_Prep) s) as_Prep
+ ;
+
+ HaveTitleAt t =
+ relAP (mkAP (mkA2 (mkA "employed") as_Prep) (mkNP t)) at_Prep
+ | relAP (mkAP (mkA2 (mkA "employed") as_Prep) (mkNP t)) by8agent_Prep
+ | relVP (mkVP (mkNP a_Det t)) at_Prep
+ | relVP (mkVP (mkV2 (mkV "work") as_Prep) (mkNP t)) at_Prep
+ | relVP (mkVP have_V2 (mkNP the_Det (mkCN (mkN2 (mkN "title")) (mkNP t)))) at_Prep
+ ;
Named n = propAP (mkAP (mkA2 (mkA "named") []) n) ;
Start n = propVP (mkVP (mkV2 "start" with_Prep) n) ;
Organization = mkCN (mkN "organization") ;
+ Company = mkCN (mkN "company") ;
Place = mkCN (mkN "place") ;
Person =
mkCN (mkN "person" "people")
| mkCN (mkN "person") ;
- Location = mkRelation "location" ;
- Region = mkRelation "region" ;
- Subregion = mkRelation "subregion" | mkRelation "sub-region" ;
- RName = mkRelation "name" ;
- RNickname = mkRelation "nickname" ;
- RJobTitle = mkRelation "job title" | mkRelation "job" | mkRelation "position" |
- mkRelation "appointment" | mkRelation "job position" | mkRelation "mandate" |
- mkRelation "title" ;
+ Location = mkFunction "location" ;
+ Region = mkFunction "region" ;
+ Subregion = mkFunction "subregion" | mkFunction "sub-region" ;
+ FName = mkFunction "name" ;
+ FNickname = mkFunction "nickname" ;
+ FJobTitle = mkFunction "job title" | mkFunction "job" | mkFunction "position" |
+ mkFunction "appointment" | mkFunction "job position" | mkFunction "mandate" |
+ mkFunction "title" | mkFunction "capacity" ;
+
+ SJobTitle t = mkNP a_Det t ;
USA = mkCountry "USA" "American" ;
Bulgaria = mkCountry "Bulgaria" "Bulgarian" ;
diff --git a/examples/query/README b/examples/query/README
new file mode 100644
index 000000000..81442cd01
--- /dev/null
+++ b/examples/query/README
@@ -0,0 +1,57 @@
+Copyright (c) 2010 Aarne Ranta, under LGPL(3).
+Part of MOLTO Project, WP 4.
+
+Query language, based on the corpus from Ontotext.
+
+Purpose: natural language queries to an ontology database.
+
+Work in progress:
+- 19 June parsing 28% 160/562
+- 17 June 2010 first version, parsing under 10%
+
+
+The corpus contains misspellings and ungrammatical sentences; these will (mostly) not
+be covered by the grammar.
+
+Test:
+
+ -- start GF with the grammar; notice that lib/present/ must have latest Eng libraries,
+ -- which can be provided by 'runghc Make present lang api langs=Eng' in lib/src/
+ % gf QueryEng.gf
+ -- parse a sentence and see all variants
+ > "p "Bulgarian people working at Google" | l -all
+
+Regression test:
+
+ -- run the parser on the corpus
+ % gf QueryEng.gf <test.gfs > test.results8
+ -- compute the number of sentences not covered
+ % grep "no tree" test.results8 | wc
+
+
+Semantics: generic logical semantics, that could be mapped to many query languages.
+The denotations of the main categories are, assuming a domain of individuals:
+
+ Set ; P(P(D)) (generalized quantifier) -- the set requested, e.g. "all persons"
+ Function ; D -> P(D) -- something of something, e.g. "subregion of Bulgaria"
+ Kind ; P(D) -- type of things, e.g. "person"
+ Relation ; D -> D -> T -- relation between things,e.g. "employed at"
+ Property ; D -> T -- property of things, e.g. "employed at Google"
+ Individual ; D -- one entity, e.g. "Google"
+ Name ; D -- person, company... e.g. "Eric Schmidt"
+
+
+Characteristics:
+- simple AST's, lots of variants (easily hundreds per query)
+- semantic overgeneration, e.g. "Google works at Larry Page"
+- some ambiguities, e.g.
+
+ > give me the organizations and their locations
+ MQuery (QFun Location (SAll Organization))
+ MQuery (QFunPair (SAll Organization) Location)
+
+ Maybe harmless?
+
+Resource grammar was not quite enough; added for instance multiple interrogatives
+("who is employed as what where") in Extra and ExtraEng
+