#
# Rules for the first pass recognition of english relations inside chunks
# This file uses the Modex rules syntax
#
# Created on Thu nov 21 2003
# by Gael de Chalendar <Gael.de-Chalendar@cea.fr>
# initial rules by Hubert Naets
#

# NOTE: for these rules, the recognizer is called with the parameters:
# test all vertices: true
# stop at first success: false
# only one success per type: false
# return at first success: false


set encoding=utf8
using modex lima-analysis.xml
using groups LinguisticProcessing


#----------------------------------------------------------------------
# microcategories classes
#----------------------------------------------------------------------
use categoriesClassesDeclaration-eng.txt

#----------------------------------------------------------------------
# sub-automatons
#----------------------------------------------------------------------

# noun group size=3
# head is at position 3
define subautomaton NounGroup {
 pattern=$DET? (@Adverb{0-2} @Adj|@Substantif|@ConjCoord|@Ing|@DetNum|@PrepComp){0-n} @Substantif (@DetNum (@ConjCoord @DetNum)?)?
}

# prep group size=2
# head is at position 2.3
define subautomaton PrepGroup {
 pattern=@PrepComp %NounGroup
}

#----------------------------------------------------------------------
# 
#----------------------------------------------------------------------

@Substantif:@PronPoss (@Adj|@Substantif){0-n}:@AfterNominalChunk:SYNTACTIC_RELATION:
+SecondUngovernedBy(left.1,trigger.1,"det")
+CreateRelationBetween(left.1,trigger.1,"det")
=>AddRelationInGraph()
=<ClearStoredRelations()

#----------------------------------------------------------------------
# 1. Relation entre adjectif prenominal et substantif : AdjPrenSub
#   @Adj*  (@Adj|@Substantif) @Substantif
# "a green car"
# ADJPRENSUB :    green[12|12]{27/70}     -> car[11|11]{23/37}
#   @Substantif*  (@Adj|@Substantif) @Substantif
# "a police car"
# ADJPRENSUB :    police[12|12]{27/70}     -> car[11|11]{23/37}
#----------------------------------------------------------------------

$NC::$NP $NP:SYNTACTIC_RELATION:
+!GovernorOf(trigger.1,"ADJPRENSUB")
+!GovernorOf(right.1,"SUBSUBJUX")
+SecondUngovernedBy(trigger.1,right.2,"ANY")
+SecondUngovernedBy(right.1,right.2,"ANY")
+CreateRelationBetween(trigger.1,right.2,"ADJPRENSUB")
+CreateRelationBetween(right.1,right.2,"SUBSUBJUX")
=>AddRelationInGraph()
=<ClearStoredRelations()

@Substantif::(@Substantif|@Ing):SYNTACTIC_RELATION:
+!GovernorOf(trigger.1,"ADJPRENSUB")
+!GovernorOf(right.1,"SUBSUBJUX")
+SecondUngovernedBy(trigger.1,right.1,"ANY")
+CreateRelationBetween(trigger.1,right.1,"ADJPRENSUB")
=>AddRelationInGraph()
=<ClearStoredRelations()


@Substantif::(@Substantif|@Adj){1-n} (@Substantif|@Ing):SYNTACTIC_RELATION:
+!GovernorOf(trigger.1,"ADJPRENSUB")
+SecondUngovernedBy(trigger.1,right.2,"ANY")
+CreateRelationBetween(trigger.1,right.2,"ADJPRENSUB")
=>AddRelationInGraph()
=<ClearStoredRelations()

@Substantif::(@Substantif|@Adj){0-n} (@Substantif|@Ing):SYNTACTIC_RELATION:
+!GovernorOf(trigger.1,"ADJPRENSUB")
+SecondUngovernedBy(trigger.1,right.2,"ANY")
+CreateRelationBetween(trigger.1,right.2,"ADJPRENSUB")
=>AddRelationInGraph()
=<ClearStoredRelations()

@Ing::(@Substantif|@Adj){0-n} (@Substantif|@Ing):SYNTACTIC_RELATION:
+!GovernorOf(trigger.1,"ADJPRENSUB")
+SecondUngovernedBy(trigger.1,right.2,"ANY")
+CreateRelationBetween(trigger.1,right.2,"ADJPRENSUB")
=>AddRelationInGraph()
=<ClearStoredRelations()


#--------------
# Relation entre les elements d'un nom propre
# John F. Kennedy
#

@NomPropre::(((@NomPropre){1-n})?) @NomPropre:SYNTACTIC_RELATION:
+!GovernorOf(trigger.1,"SUBSUBJUX")
+SecondUngovernedBy(trigger.1,right.2,"ANY")
+CreateRelationBetween(trigger.1,right.2,"SUBSUBJUX")
=>AddRelationInGraph()
=<ClearStoredRelations()

#----------------------------------------------------------------------
# 4. Relation de complement du nom : CompDuNom
# Deux noms juxtaposes. En dernier pour essayer de creer les autre relations
# avant et donc generer moins de bruit
#----------------------------------------------------------------------
#-@Substantif::(@Adj){0-n} @Substantif:SYNTACTIC_RELATION:
#-+SecondUngovernedBy(trigger.1,right.2,"ANY")
#-+CreateRelationBetween(trigger.1,right.2,"COMPDUNOM")


#----------------------------------------------------------------------
# Relation entre deux substantifs juxtaposés : SubSubJux
# A revoir et completer  (voir l2r 24/1/05 GG)
#----------------------------------------------------------------------
#-@NomPropre::@Substantif:SYNTACTIC_RELATION:
#-+SecondUngovernedBy(trigger.1,right.1,"ANY")
#-+CreateRelationBetween(trigger.1,right.1)

#-@NomPropre:@Substantif::SYNTACTIC_RELATION:
#-+SecondUngovernedBy(trigger.1,left.1,"ANY")
#-+CreateRelationBetween(trigger.1,left.1)

@Prep:@Sent:@Substantif $V-VERB @Comma:SYNTACTIC_RELATION:
+SecondUngovernedBy(right.2,right.1,"ANY")
+CreateRelationBetween(right.2,right.1,"SUBADJPOST")
=>AddRelationInGraph()
=<ClearStoredRelations()

#----------------------------------------------------------------------
# Relation between a determiner and its noun with a numeric modifier that would be nummod in UD
#----------------------------------------------------------------------
@DetDef::@DetNum @Substantif:SYNTACTIC_RELATION:
+SecondUngovernedBy(trigger.1,right.2,"ANY")
+SecondUngovernedBy(right.1,right.2,"ANY")
+CreateRelationBetween(trigger.1,right.2,"det")
+CreateRelationBetween(right.1,right.2,"MOD_N")
=>AddRelationInGraph()
=<ClearStoredRelations()

@DetNum::@Substantif:SYNTACTIC_RELATION:
+!GovernorOf(trigger.1,"ANY")
+SecondUngovernedBy(trigger.1,right.1,"ANY")
+CreateRelationBetween(trigger.1,right.1,"det")
=>AddRelationInGraph()
=<ClearStoredRelations()


@DetNum::%NounGroup:SYNTACTIC_RELATION:
+!GovernorOf(trigger.1,"ANY")
+SecondUngovernedBy(trigger.1,right.1.3,"ANY")
+CreateRelationBetween(trigger.1,right.1.3,"det")
=>AddRelationInGraph()
=<ClearStoredRelations()

@Substantif::@DetNum:SYNTACTIC_RELATION:
+!GovernorOf(right.1,"ANY")
+SecondUngovernedBy(right.1,trigger.1,"ANY")
+CreateRelationBetween(right.1,trigger.1,"MOD_N")
=>AddRelationInGraph()
=<ClearStoredRelations()
