1 #ifndef HEAD_ENGLISH_H_
2 #define HEAD_ENGLISH_H_
18 #warning "[Code police] Do not put 'using namespace' in global scope of header."
21 #define TCI typename std::list< spear::RCIPtr<T> >::const_iterator
22 #define TCRI typename std::list< spear::RCIPtr<T> >::const_reverse_iterator
29 const Char * labels [],
30 bool traverseLabelsFirst =
true)
32 if(traverseLabelsFirst ==
true){
36 for(
int i = 0; labels[
i] != NULL;
i ++){
37 for(
TCRI it = (
TCRI) children.rbegin();
38 it != (
TCRI) children.rend(); it ++){
39 if((* it)->getLabel() == labels[
i]){
48 for(
TCRI it = (
TCRI) children.rbegin();
49 it != (
TCRI) children.rend(); it ++){
50 for(
int i = 0; labels[
i] != NULL;
i ++){
51 if((* it)->getLabel() == labels[
i]){
64 const Char * labels [],
65 bool traverseLabelsFirst =
true)
67 if(traverseLabelsFirst ==
true){
71 for(
int i = 0; labels[
i] != NULL;
i ++){
72 for(
TCI it = (
TCI) children.begin();
73 it != (
TCI) children.end(); it ++){
74 if((* it)->getLabel() == labels[
i]){
83 for(
TCI it = (
TCI) children.begin();
84 it != (
TCI) children.end(); it ++){
85 for(
int i = 0; labels[
i] != NULL;
i ++){
86 if((* it)->getLabel() == labels[
i]){
101 static const Char * row1 [] =
102 {
W(
"NN"),
W(
"NNP"),
W(
"NNPS"),
W(
"NNS"),
W(
"NX"),
W(
"POS"),
W(
"JJR"), NULL };
103 static const Char * row2 [] =
104 {
W(
"NP"),
W(
"NPB"), NULL };
105 static const Char * row3 [] =
106 {
W(
"$"),
W(
"ADJP"),
W(
"PRN"), NULL };
107 static const Char * row4 [] =
109 static const Char * row5 [] =
110 {
W(
"JJ"),
W(
"JJS"),
W(
"RB"),
W(
"QP"), NULL };
114 if((head = traverseRightToLeft<T>(children, row1,
false)) !=
118 if((head = traverseLeftToRight<T>(children, row2,
false)) !=
122 if((head = traverseRightToLeft<T>(children, row3,
false)) !=
126 if((head = traverseRightToLeft<T>(children, row4,
false)) !=
130 if((head = traverseRightToLeft<T>(children, row5,
false)) !=
134 return children.back();
137 template <
typename T>
142 static const Char * row1 [] = {
143 W(
"NNS"),
W(
"QP"),
W(
"NN"),
W(
"$"),
W(
"ADVP"),
W(
"VBN"),
W(
"JJ"),
W(
"PRT"),
144 W(
"ADVP|PRT"),
W(
"VBG"),
W(
"ADJP"),
W(
"JJR"),
W(
"NP"),
W(
"NPB"),
W(
"JJS"),
W(
"DT"),
145 W(
"FW"),
W(
"RBR"),
W(
"RBS"),
W(
"SBAR"),
W(
"RB"),
W(
"IN"),
W(
"VBD"), NULL
150 if((head = traverseLeftToRight<T>(children, row1)) !=
154 return children.front();
157 template <
typename T>
162 static const Char * row1 [] = {
163 W(
"RB"),
W(
"RBR"),
W(
"RBS"),
W(
"FW"),
W(
"ADVP"),
W(
"PRT"),
W(
"ADVP|PRT"),
W(
"TO"),
164 W(
"CD"),
W(
"JJR"),
W(
"JJ"),
W(
"IN"),
W(
"NP"),
W(
"NPB"),
W(
"JJS"),
W(
"NN"),
W(
"PP"), NULL
169 if((head = traverseRightToLeft<T>(children, row1)) !=
173 return children.front();
176 template <
typename T>
181 static const Char * row1 [] = {
W(
"CC"),
W(
"RB"),
W(
"IN"), NULL };
185 if((head = traverseRightToLeft<T>(children, row1)) !=
189 return children.front();
192 template <
typename T>
197 return children.back();
200 template <
typename T>
205 return children.front();
208 template <
typename T>
213 static const Char * row1 [] = {
W(
"LS"),
W(
":"),
W(
","), NULL };
217 if((head = traverseRightToLeft<T>(children, row1)) !=
221 return children.front();
224 template <
typename T>
229 static const Char * row1 [] = {
230 W(
"NN"),
W(
"NNS"),
W(
"NNP"),
W(
"NNPS"),
W(
"NP"),
W(
"NPB"),
W(
"NAC"),
W(
"EX"),
W(
"$"),
231 W(
"CD"),
W(
"QP"),
W(
"PRP"),
W(
"VBG"),
W(
"JJ"),
W(
"JJS"),
W(
"JJR"),
W(
"ADJP"),
W(
"FW"),
237 if((head = traverseLeftToRight<T>(children, row1)) !=
241 return children.front();
244 template <
typename T>
249 static const Char * row1 [] =
250 {
W(
"IN"),
W(
"TO"),
W(
"VBG"),
W(
"VBN"),
W(
"RP"),
W(
"FW"),
W(
"PP"),
W(
"ADJP"), NULL };
254 if((head = traverseRightToLeft<T>(children, row1)) !=
258 return children.back();
261 template <
typename T>
266 return children.front();
269 template <
typename T>
274 static const Char * row1 [] = {
275 W(
"$"),
W(
"IN"),
W(
"NNS"),
W(
"NN"),
W(
"JJ"),
W(
"RB"),
W(
"DT"),
W(
"CD"),
W(
"QP"),
W(
"JJR"),
281 if((head = traverseLeftToRight<T>(children, row1)) !=
285 return children.front();
288 template <
typename T>
293 static const Char * row1 [] = {
294 W(
"VP"),
W(
"NP"),
W(
"NPB"),
W(
"ADVP"),
W(
"PRT"),
W(
"ADVP|PRT"),
W(
"ADJP"),
W(
"PP"),
300 if((head = traverseRightToLeft<T>(children, row1)) !=
304 return children.front();
307 template <
typename T>
312 static const Char * row1 [] = {
313 W(
"TO"),
W(
"IN"),
W(
"VP"),
W(
"S"),
W(
"SBAR"),
W(
"ADJP"),
W(
"UCP"),
W(
"NP"),
W(
"NPB"),
319 if((head = traverseLeftToRight<T>(children, row1)) !=
323 return children.front();
326 template <
typename T>
331 static const Char * row1 [] = {
332 W(
"WHNP"),
W(
"WHPP"),
W(
"WHADVP"),
W(
"WHADJP"),
W(
"IN"),
W(
"DT"),
W(
"S"),
W(
"SQ"),
333 W(
"SINV"),
W(
"SBAR"),
W(
"FRAG"), NULL
338 if((head = traverseLeftToRight<T>(children, row1)) !=
342 return children.front();
345 template <
typename T>
350 static const Char * row1 [] = {
351 W(
"SQ"),
W(
"S"),
W(
"SINV"),
W(
"SBARQ"),
W(
"FRAG"),
W(
"SBAR"), NULL
356 if((head = traverseRightToLeft<T>(children, row1)) !=
360 return children.front();
363 template <
typename T>
368 static const Char * row1 [] = {
369 W(
"VBZ"),
W(
"VBD"),
W(
"VBP"),
W(
"VB"),
W(
"MD"),
W(
"VP"),
W(
"S"),
W(
"SINV"),
W(
"ADJP"),
370 W(
"NP"),
W(
"NPB"), NULL
375 if((head = traverseLeftToRight<T>(children, row1)) !=
379 return children.front();
382 template <
typename T>
387 static const Char * row1 [] = {
388 W(
"VBZ"),
W(
"VBD"),
W(
"VBP"),
W(
"VB"),
W(
"MD"),
W(
"VP"),
W(
"SQ"), NULL
393 if((head = traverseLeftToRight<T>(children, row1)) !=
397 return children.front();
400 template <
typename T>
405 return children.back();
408 template <
typename T>
413 static const Char * row1 [] = {
414 W(
"TO"),
W(
"VBD"),
W(
"VBN"),
W(
"MD"),
W(
"VBZ"),
W(
"VB"),
W(
"VBG"),
W(
"VBP"),
W(
"VP"),
W(
"VPB"),
415 W(
"ADJP"),
W(
"NN"),
W(
"NNS"),
W(
"NP"),
W(
"NPB"), NULL
420 if((head = traverseLeftToRight<T>(children, row1)) !=
424 return children.front();
427 template <
typename T>
432 static const Char * row1 [] = {
W(
"CC"),
W(
"WRB"),
W(
"JJ"),
W(
"ADJP"), NULL };
436 if((head = traverseLeftToRight<T>(children, row1)) !=
440 return children.front();
443 template <
typename T>
448 static const Char * row1 [] = {
W(
"CC"),
W(
"WRB"), NULL };
452 if((head = traverseRightToLeft<T>(children, row1)) !=
456 return children.front();
459 template <
typename T>
464 static const Char * row1 [] =
465 {
W(
"WDT"),
W(
"WP"),
W(
"WP$"),
W(
"WHADJP"),
W(
"WHPP"),
W(
"WHNP"), NULL };
469 if((head = traverseLeftToRight<T>(children, row1)) !=
473 return children.front();
476 template <
typename T>
481 static const Char * row1 [] = {
W(
"IN"),
W(
"TO"),
W(
"FW"), NULL };
485 if((head = traverseRightToLeft<T>(children, row1)) !=
489 return children.front();
492 template <
typename T>
497 return children.front();
500 template <
typename T>
505 return children.front();
508 template <
typename T>
513 if(parent ==
W(
"NP") ||
515 return findHeadEnglishNP<T>(parent, children);
516 }
else if(parent ==
W(
"ADJP")){
517 return findHeadEnglishADJP<T>(parent, children);
518 }
else if(parent ==
W(
"ADVP") ||
519 parent ==
W(
"PRT") ||
520 parent ==
W(
"ADVP|PRT") ||
521 parent ==
W(
"PRT|ADVP")){
522 return findHeadEnglishADVP<T>(parent, children);
523 }
else if(parent ==
W(
"CONJP")){
524 return findHeadEnglishCONJP<T>(parent, children);
525 }
else if(parent ==
W(
"FRAG")){
526 return findHeadEnglishFRAG<T>(parent, children);
527 }
else if(parent ==
W(
"INTJ")){
528 return findHeadEnglishINTJ<T>(parent, children);
529 }
else if(parent ==
W(
"LST")){
530 return findHeadEnglishLST<T>(parent, children);
531 }
else if(parent ==
W(
"NAC")){
532 return findHeadEnglishNAC<T>(parent, children);
533 }
else if(parent ==
W(
"PP")){
534 return findHeadEnglishPP<T>(parent, children);
535 }
else if(parent ==
W(
"PRN")){
536 return findHeadEnglishPRN<T>(parent, children);
537 }
else if(parent ==
W(
"QP")){
538 return findHeadEnglishQP<T>(parent, children);
539 }
else if(parent ==
W(
"RRC")){
540 return findHeadEnglishRRC<T>(parent, children);
541 }
else if(parent ==
W(
"S") ||
543 return findHeadEnglishS<T>(parent, children);
544 }
else if(parent ==
W(
"SBAR")){
545 return findHeadEnglishSBAR<T>(parent, children);
546 }
else if(parent ==
W(
"SBARQ")){
547 return findHeadEnglishSBARQ<T>(parent, children);
548 }
else if(parent ==
W(
"SINV")){
549 return findHeadEnglishSINV<T>(parent, children);
550 }
else if(parent ==
W(
"SQ")){
551 return findHeadEnglishSQ<T>(parent, children);
552 }
else if(parent ==
W(
"UCP")){
553 return findHeadEnglishUCP<T>(parent, children);
554 }
else if(parent ==
W(
"VP")){
555 return findHeadEnglishVP<T>(parent, children);
556 }
else if(parent ==
W(
"WHADJP")){
557 return findHeadEnglishWHADJP<T>(parent, children);
558 }
else if(parent ==
W(
"WHADVP")){
559 return findHeadEnglishWHADVP<T>(parent, children);
560 }
else if(parent ==
W(
"WHNP")){
561 return findHeadEnglishWHNP<T>(parent, children);
562 }
else if(parent ==
W(
"WHPP")){
563 return findHeadEnglishWHPP<T>(parent, children);
564 }
else if(parent ==
W(
"TOP")){
565 return findHeadEnglishTOP<T>(parent, children);
566 }
else if(parent ==
W(
"X") ||
568 return findHeadEnglishX<T>(parent, children);
570 CERR <<
"Can not find head edge for label " << parent << endl;
571 CERR <<
"The children are:\n";
572 for(
TCI it = (
TCI) children.begin();
573 it != (
TCI) children.end(); it ++){
574 (* it)->display(
CERR);
577 LASSERT(
false,
"unknown edge label");
580 return children.front();
583 template <
typename T>
590 if(current == children.rend())
return children.rend();
593 if((* current)->getLabel() ==
W(
"CC")){
595 if(current == children.rend())
return children.rend();
597 return children.rend();
601 for(; current != (
TCRI) children.rend() &&
602 (* current)->getLabel() ==
W(
",");
604 if(current == children.rend())
return children.rend();
609 template <
typename T>
614 LASSERT(children.empty() ==
false,
"empty children set");
618 findHeadEnglishNoCoord<T>(parent, children);
621 for(
TCRI it = (
TCRI) children.rbegin();
622 it != (
TCRI) children.rend(); it ++){
629 if((parent !=
W(
"NPB")) &&
630 (newHead = isCoordinatedHead<T>(children, it)) != children.rend()){
spear::RCIPtr< T > findHeadEnglishADVP(const String &parent, const std::list< spear::RCIPtr< T > > &children)
Definition: HeadEnglish.h:159
Reference counting pointer class This file contains the code for the classes and class templates maki...
spear::RCIPtr< T > findHeadEnglishWHNP(const String &parent, const std::list< spear::RCIPtr< T > > &children)
Definition: HeadEnglish.h:461
TCRI isCoordinatedHead(const std::list< spear::RCIPtr< T > > &children, TCRI current)
Definition: HeadEnglish.h:585
spear::RCIPtr< T > findHeadEnglishTOP(const String &parent, const std::list< spear::RCIPtr< T > > &children)
Definition: HeadEnglish.h:494
spear::RCIPtr< T > findHeadEnglishSBARQ(const String &parent, const std::list< spear::RCIPtr< T > > &children)
Definition: HeadEnglish.h:347
spear::RCIPtr< T > findHeadEnglishWHADJP(const String &parent, const std::list< spear::RCIPtr< T > > &children)
Definition: HeadEnglish.h:429
spear::RCIPtr< T > findHeadEnglishUCP(const String &parent, const std::list< spear::RCIPtr< T > > &children)
Definition: HeadEnglish.h:402
spear::RCIPtr< T > findHeadEnglishPP(const String &parent, const std::list< spear::RCIPtr< T > > &children)
Definition: HeadEnglish.h:246
spear::RCIPtr< T > findHeadEnglishNoCoord(const String &parent, const std::list< spear::RCIPtr< T > > &children)
Definition: HeadEnglish.h:510
char Char
Definition: Wide.h:34
spear::RCIPtr< T > findHeadEnglishSQ(const String &parent, const std::list< spear::RCIPtr< T > > &children)
Definition: HeadEnglish.h:384
spear::RCIPtr< T > findHeadEnglish(const String &parent, const std::list< spear::RCIPtr< T > > &children)
Definition: HeadEnglish.h:611
spear::RCIPtr< T > findHeadEnglishPRN(const String &parent, const std::list< spear::RCIPtr< T > > &children)
Definition: HeadEnglish.h:263
spear::RCIPtr< T > findHeadEnglishWHPP(const String &parent, const std::list< spear::RCIPtr< T > > &children)
Definition: HeadEnglish.h:478
spear::RCIPtr< T > findHeadEnglishS(const String &parent, const std::list< spear::RCIPtr< T > > &children)
Definition: HeadEnglish.h:309
#define TCRI
Definition: HeadEnglish.h:22
spear::RCIPtr< T > traverseLeftToRight(const std::list< spear::RCIPtr< T > > &children, const Char *labels[], bool traverseLabelsFirst=true)
Definition: HeadEnglish.h:63
spear::RCIPtr< T > findHeadEnglishQP(const String &parent, const std::list< spear::RCIPtr< T > > &children)
Definition: HeadEnglish.h:271
spear::RCIPtr< T > findHeadEnglishFRAG(const String &parent, const std::list< spear::RCIPtr< T > > &children)
Definition: HeadEnglish.h:194
#define String
Definition: Wide.h:36
spear::RCIPtr< T > findHeadEnglishNP(const String &parent, const std::list< spear::RCIPtr< T > > &children)
Definition: HeadEnglish.h:98
spear::RCIPtr< T > findHeadEnglishSINV(const String &parent, const std::list< spear::RCIPtr< T > > &children)
Definition: HeadEnglish.h:365
spear::RCIPtr< T > findHeadEnglishVP(const String &parent, const std::list< spear::RCIPtr< T > > &children)
Definition: HeadEnglish.h:410
#define W(X)
Definition: Wide.h:45
spear::RCIPtr< T > findHeadEnglishADJP(const String &parent, const std::list< spear::RCIPtr< T > > &children)
Definition: HeadEnglish.h:139
spear::RCIPtr< T > findHeadEnglishX(const String &parent, const std::list< spear::RCIPtr< T > > &children)
Definition: HeadEnglish.h:502
get the indices of edges in each direction for i
Definition: APPgetLargeConnectedEdges.m:48
spear::RCIPtr< T > findHeadEnglishLST(const String &parent, const std::list< spear::RCIPtr< T > > &children)
Definition: HeadEnglish.h:210
spear::RCIPtr< T > findHeadEnglishNAC(const String &parent, const std::list< spear::RCIPtr< T > > &children)
Definition: HeadEnglish.h:226
#define TCI
Definition: HeadEnglish.h:21
spear::RCIPtr< T > findHeadEnglishINTJ(const String &parent, const std::list< spear::RCIPtr< T > > &children)
Definition: HeadEnglish.h:202
spear::RCIPtr< T > findHeadEnglishRRC(const String &parent, const std::list< spear::RCIPtr< T > > &children)
Definition: HeadEnglish.h:290
spear::RCIPtr< T > findHeadEnglishWHADVP(const String &parent, const std::list< spear::RCIPtr< T > > &children)
Definition: HeadEnglish.h:445
spear::RCIPtr< T > traverseRightToLeft(const std::list< spear::RCIPtr< T > > &children, const Char *labels[], bool traverseLabelsFirst=true)
Definition: HeadEnglish.h:28
#define LASSERT(condition, message)
Definition: Assert.h:14
spear::RCIPtr< T > findHeadEnglishSBAR(const String &parent, const std::list< spear::RCIPtr< T > > &children)
Definition: HeadEnglish.h:328
#define CERR
Definition: Wide.h:30
spear::RCIPtr< T > findHeadEnglishCONJP(const String &parent, const std::list< spear::RCIPtr< T > > &children)
Definition: HeadEnglish.h:178