@@ -718,6 +718,56 @@ public void testNamedRelation() {
718718 assertFalse (matcher .find ());
719719 }
720720
721+ /**
722+ * The named relation feature should incorporate backreferences
723+ */
724+ public void testNamedRelationBackreference () {
725+ SemanticGraph graph = SemanticGraph .valueOf ("[ate subj>Bill obj>[muffins compound>blueberry]]" );
726+
727+ SemgrexPattern pattern = SemgrexPattern .compile ("{}=A >=foo ({}=B >=foo {}=C)" );
728+ SemgrexMatcher matcher = pattern .matcher (graph );
729+ assertFalse (matcher .find ());
730+
731+ graph = SemanticGraph .valueOf ("[ate dep> [Bill dep> cat]]" );
732+ matcher = pattern .matcher (graph );
733+ assertTrue (matcher .find ());
734+ assertEquals ("ate" , matcher .getNode ("A" ).toString ());
735+ assertEquals ("Bill" , matcher .getNode ("B" ).toString ());
736+ assertEquals ("cat" , matcher .getNode ("C" ).toString ());
737+ assertEquals ("dep" , matcher .getRelnString ("foo" ));
738+ assertFalse (matcher .find ());
739+
740+ graph = SemanticGraph .valueOf ("[ate cop> [Bill dep> cat]]" );
741+ matcher = pattern .matcher (graph );
742+ assertFalse (matcher .find ());
743+
744+ graph = SemanticGraph .valueOf ("[ate dep> [Bill cop> cat]]" );
745+ matcher = pattern .matcher (graph );
746+ assertFalse (matcher .find ());
747+
748+ graph = SemanticGraph .valueOf ("[antennae amod> big amod> blue]" );
749+ pattern = SemgrexPattern .compile ("{}=A >=foo {}=B >=foo ({}=C !== {}=B)" );
750+ matcher = pattern .matcher (graph );
751+ assertTrue (matcher .find ());
752+ assertEquals ("antennae" , matcher .getNode ("A" ).toString ());
753+ assertEquals ("big" , matcher .getNode ("B" ).toString ());
754+ assertEquals ("blue" , matcher .getNode ("C" ).toString ());
755+ assertEquals ("amod" , matcher .getRelnString ("foo" ));
756+
757+ assertTrue (matcher .find ());
758+ assertEquals ("antennae" , matcher .getNode ("A" ).toString ());
759+ assertEquals ("blue" , matcher .getNode ("B" ).toString ());
760+ assertEquals ("big" , matcher .getNode ("C" ).toString ());
761+ assertEquals ("amod" , matcher .getRelnString ("foo" ));
762+
763+ assertFalse (matcher .find ());
764+
765+ graph = SemanticGraph .valueOf ("[antennae amod> big dep> blue]" );
766+ pattern = SemgrexPattern .compile ("{}=A >=foo {}=B >=foo ({}=C !== {}=B)" );
767+ matcher = pattern .matcher (graph );
768+ assertFalse (matcher .find ());
769+ }
770+
721771 public void testAttributeConjunction () {
722772 // A possible user submitted error: https://github.com/stanfordnlp/CoreNLP/issues/552
723773 // A match with both POS and word labeled should have both attributes on the same node
0 commit comments