diff --git a/libwccl/parser/Parser.cpp b/libwccl/parser/Parser.cpp index 161959d12a9d5e1d18b05f84d547ed267933a92c..f78dec74c16f61a6715715de4d968d9eb4522fd1 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 d323f077dca216aeb19f5e1a6b2f91f40dba76fc..0d7e49cf4b4520d1a41f0a6111813ffa78629e88 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 3e553affe1fa62daaa202e3996b7c17469c53724..03542d3f35a051173bca2b898a721e20afd06b34 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 6924dcd5d620910d7e96f1f8572d1a33f090102b..a2da6ede3e90b62ea67688751823b81c5ecc913c 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) {