From fbc84ed5a8b9aefae17521ccb336a5aa37eba281 Mon Sep 17 00:00:00 2001
From: ilor <kailoran@gmail.com>
Date: Thu, 21 Apr 2011 14:40:08 +0200
Subject: [PATCH] make the parser parse match operator rules as MatchRules, fix
 wccl-match to work with that

---
 libwccl/parser/Parser.cpp |  6 +++---
 libwccl/parser/Parser.h   |  6 +++---
 libwccl/parser/grammar.g  | 15 +++++++++------
 wccl-apps/wccl-match.cpp  | 13 ++++++-------
 4 files changed, 21 insertions(+), 19 deletions(-)

diff --git a/libwccl/parser/Parser.cpp b/libwccl/parser/Parser.cpp
index 161959d..f78dec7 100644
--- a/libwccl/parser/Parser.cpp
+++ b/libwccl/parser/Parser.cpp
@@ -508,7 +508,7 @@ boost::shared_ptr<TagRule> Parser::parseSingleRule(
  * @arg istr input stream with writed rule
  * @return the parsed rule via a shared pointer
  */
-boost::shared_ptr<ApplyOperator> Parser::parseMatchRule(
+boost::shared_ptr<MatchRule> Parser::parseMatchRule(
 		const std::string& str) const
 {
 	std::stringstream ss (std::stringstream::in | std::stringstream::out);
@@ -527,11 +527,11 @@ boost::shared_ptr<ApplyOperator> Parser::parseMatchRule(
  * @arg istr input stream with writed rule
  * @return the parsed rule via a shared pointer
  */
-boost::shared_ptr<ApplyOperator> Parser::parseMatchRule(std::istream& istr) const
+boost::shared_ptr<MatchRule> Parser::parseMatchRule(std::istream& istr) const
 {
 	ANTLRLexer lexer(istr);
 	ANTLRParser parser(lexer);
-	boost::shared_ptr<ApplyOperator> res;
+	boost::shared_ptr<MatchRule> res;
 
 	try {
 		res = parser.parse_match_rule(tagset_);
diff --git a/libwccl/parser/Parser.h b/libwccl/parser/Parser.h
index d323f07..0d7e49c 100644
--- a/libwccl/parser/Parser.h
+++ b/libwccl/parser/Parser.h
@@ -18,7 +18,7 @@
 #include <libwccl/ops/rulesequence.h>
 
 // match actions
-#include <libwccl/ops/match/applyoperator.h>
+#include <libwccl/ops/matchrule.h>
 
 // exceptions
 #include <libwccl/parser/ParserException.h>
@@ -83,9 +83,9 @@ public:
 
 	// ---------------------------------------------------------------------------
 	// Parsing match rule from input string
-	boost::shared_ptr<ApplyOperator>
+	boost::shared_ptr<MatchRule>
 			parseMatchRule(const std::string& rule_string) const;
-	boost::shared_ptr<ApplyOperator>
+	boost::shared_ptr<MatchRule>
 			parseMatchRule(std::istream& is) const;
 
 	// ---------------------------------------------------------------------------
diff --git a/libwccl/parser/grammar.g b/libwccl/parser/grammar.g
index 3e553af..03542d3 100644
--- a/libwccl/parser/grammar.g
+++ b/libwccl/parser/grammar.g
@@ -61,6 +61,7 @@ header {
 	
 	// Rules, actions
 	#include <libwccl/ops/tagrule.h>
+	#include <libwccl/ops/matchrule.h>
 	#include <libwccl/ops/rulesequence.h>
 	//
 	#include <libwccl/ops/tagactions/unify.h>
@@ -247,10 +248,10 @@ parse_rule_sequence
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // Rule for parsing the match rules
-// Returns boost::shared_ptr<ApplyOperator>
+// Returns boost::shared_ptr<MatchRule>
 parse_match_rule
 	[const Corpus2::Tagset& tagset]
-	returns [boost::shared_ptr<ApplyOperator> ret_match]
+	returns [boost::shared_ptr<MatchRule> ret_match]
 {
 	Variables vars;
 	vars.get_put<Match>("_M");
@@ -1808,14 +1809,16 @@ action_unmark
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // Match rules
-// Returns boost::shared_ptr<ApplyOperator>
+// Returns boost::shared_ptr<MatchRule>
 match_rule_operator
 	[const Corpus2::Tagset& tagset, Variables& vars]
-	returns [boost::shared_ptr<ApplyOperator> ret_op]
+	returns [boost::shared_ptr<MatchRule> ret_op]
 {
-	//
+	boost::shared_ptr<ApplyOperator> apply;
 }
-	: ret_op = match_apply_operator [tagset, vars]
+	: apply = match_apply_operator [tagset, vars] {
+		ret_op = boost::make_shared<MatchRule>(vars, apply);
+	}
 ;
 
 // Match apply operator:
diff --git a/wccl-apps/wccl-match.cpp b/wccl-apps/wccl-match.cpp
index 6924dcd..a2da6ed 100644
--- a/wccl-apps/wccl-match.cpp
+++ b/wccl-apps/wccl-match.cpp
@@ -4,7 +4,6 @@
 
 #include <libwccl/values/strset.h>
 #include <libwccl/parser/Parser.h>
-#include <libwccl/ops/rulesequence.h>
 #include <libcorpus2/tagsetmanager.h>
 #include <libcorpus2/util/tokentimer.h>
 
@@ -50,12 +49,12 @@ private:
 	const Corpus2::Tagset& tagset_;
 	Wccl::Parser parser_;
 	std::vector<std::string> rule_names_;
-	std::vector<boost::shared_ptr<Wccl::ApplyOperator> > rules_;
+	std::vector<boost::shared_ptr<Wccl::MatchRule> > rules_;
 };
 
 bool MatchRunner::load_more_rules(const std::string& filename)
 {
-	boost::shared_ptr<Wccl::ApplyOperator> retOp;
+	boost::shared_ptr<Wccl::MatchRule> retOp;
 	try {
 		std::ifstream is(filename.c_str());
 		if (!is.good()) {
@@ -86,8 +85,8 @@ void MatchRunner::apply_rules(boost::shared_ptr<Corpus2::TokenReader> reader,
 			boost::shared_ptr<Corpus2::AnnotatedSentence> as;
 			as = Corpus2::AnnotatedSentence::wrap_sentence(s);
 
-			foreach (const boost::shared_ptr<Wccl::ApplyOperator>& r, rules_) {
-				//r->execute();
+			foreach (const boost::shared_ptr<Wccl::MatchRule>& r, rules_) {
+				r->apply(as);
 			}
 
 			timer.count_sentence(*as);
@@ -133,7 +132,7 @@ int main(int argc, char** argv)
 			 "Files to load, looking at the extension to determine type\n")
 			("input-format,i", value(&input_format)->default_value("xces"),
 			 readers_help.c_str())
-			("output-format,o", value(&output_format)->default_value("xces"),
+			("output-format,o", value(&output_format)->default_value("ccl"),
 			 writers_help.c_str())
 			("progress,p", value(&progress)->zero_tokens(),
 			 "Show progress info")
@@ -189,7 +188,7 @@ int main(int argc, char** argv)
 			boost::shared_ptr<Corpus2::TokenWriter> writer;
 			writer.reset(Corpus2::TokenWriter::create(output_format, std::cout, tagset));
 			boost::shared_ptr<Corpus2::TokenReader> reader;
-			reader = Corpus2::TokenReader::create_path_reader(input_format, tagset, ccl_files[0]);
+			reader = Corpus2::TokenReader::create_path_reader(input_format, tagset, corpora_files[0]);
 			runner.apply_rules(reader, writer);
 		}
 	} catch (PwrNlp::PwrNlpError& e) {
-- 
GitLab