diff --git a/libwccl/CMakeLists.txt b/libwccl/CMakeLists.txt index f5f5796b8605ba6e09407e90a26b0895bc046258..7f92751ece0a7ecfdf7da84a5a1a2f3ef5e5991e 100644 --- a/libwccl/CMakeLists.txt +++ b/libwccl/CMakeLists.txt @@ -27,11 +27,6 @@ endif(WIN32) SET(libwccl_STAT_SRC exception.cpp - ops/action.cpp - ops/actions/delete.cpp - ops/actions/relabel.cpp - ops/actions/select.cpp - ops/actions/unify.cpp ops/formatters.cpp ops/functions/bool/iteration.cpp ops/functions/bool/iterations/atleast.cpp @@ -59,8 +54,13 @@ SET(libwccl_STAT_SRC ops/functions/tset/catfilter.cpp ops/functions/tset/getsymbols.cpp ops/functions/tset/getsymbolsinrange.cpp - ops/rule.cpp ops/rulesequence.cpp + ops/tagaction.cpp + ops/tagactions/delete.cpp + ops/tagactions/relabel.cpp + ops/tagactions/select.cpp + ops/tagactions/unify.cpp + ops/tagrule.cpp parser/grammar.g parser/Parser.cpp parser/ParserException.cpp diff --git a/libwccl/ops/rulesequence.cpp b/libwccl/ops/rulesequence.cpp index 4e754db67eda9b6a9b23c3c0094e9c5098d59ea7..b5c1f8ac681b7f4f6889019bece07e4df167bad2 100644 --- a/libwccl/ops/rulesequence.cpp +++ b/libwccl/ops/rulesequence.cpp @@ -14,7 +14,7 @@ Bool RuleSequence::execute_once(const boost::shared_ptr<Corpus2::Sentence>& sent Bool changed(false); SentenceContext sc(sentence); while(sc.is_current_inside()) { - foreach (Rule& rule, *this) { + foreach (TagRule& rule, *this) { if (rule.execute(sc).get_value()) { changed.set_value(true); } diff --git a/libwccl/ops/rulesequence.h b/libwccl/ops/rulesequence.h index d15b2720451d344422d8c6a38d3029ecd79633a3..1015a9bf25e6b776a2eaf2988de36485f7471b4b 100644 --- a/libwccl/ops/rulesequence.h +++ b/libwccl/ops/rulesequence.h @@ -1,7 +1,7 @@ #ifndef LIBWCCL_OPS_RULESEQUENCE_H #define LIBWCCL_OPS_RULESEQUENCE_H -#include <libwccl/ops/rule.h> +#include <libwccl/ops/tagrule.h> namespace Wccl { @@ -11,10 +11,10 @@ namespace Wccl { * for all positions of a Sentence. * @note The class methods are not thread-safe */ -class RuleSequence : public std::vector<Rule> +class RuleSequence : public std::vector<TagRule> { public: - RuleSequence(std::vector<Rule> rules); + RuleSequence(std::vector<TagRule> rules); RuleSequence(); @@ -73,13 +73,13 @@ public: //--- implementation details --- // inline -RuleSequence::RuleSequence(std::vector<Rule> rules) - : std::vector<Rule>(rules) { +RuleSequence::RuleSequence(std::vector<TagRule> rules) + : std::vector<TagRule>(rules) { } inline RuleSequence::RuleSequence() - : std::vector<Rule>() { + : std::vector<TagRule>() { } inline diff --git a/libwccl/ops/action.cpp b/libwccl/ops/tagaction.cpp similarity index 89% rename from libwccl/ops/action.cpp rename to libwccl/ops/tagaction.cpp index 4bcf570ac86635584325057200a9e3e948224a23..99a7eed05d11f4cbbad5def0f296a0722859a933 100644 --- a/libwccl/ops/action.cpp +++ b/libwccl/ops/tagaction.cpp @@ -1,4 +1,4 @@ -#include <libwccl/ops/action.h> +#include <libwccl/ops/tagaction.h> #include <libwccl/ops/functions/constant.h> namespace Wccl { diff --git a/libwccl/ops/action.h b/libwccl/ops/tagaction.h similarity index 78% rename from libwccl/ops/action.h rename to libwccl/ops/tagaction.h index 4af09847b76d00410d4075fafbaf6b982616fcd7..c41ef95f7308790d146971fb7a52ed268b70f98a 100644 --- a/libwccl/ops/action.h +++ b/libwccl/ops/tagaction.h @@ -1,5 +1,5 @@ -#ifndef LIBWCCL_OPS_ACTION_H -#define LIBWCCL_OPS_ACTION_H +#ifndef LIBWCCL_OPS_TAGACTION_H +#define LIBWCCL_OPS_TAGACTION_H #include <libwccl/ops/actionexeccontext.h> #include <libwccl/ops/function.h> @@ -10,7 +10,7 @@ namespace Wccl { /** * Abstract base class for actions in WCCL rules */ -class Action : public Expression +class TagAction : public Expression { public: /** @@ -29,4 +29,4 @@ namespace detail { } /* end ns Wccl */ -#endif // LIBWCCL_OPS_ACTION_H +#endif // LIBWCCL_OPS_TAGACTION_H diff --git a/libwccl/ops/actions/delete.cpp b/libwccl/ops/tagactions/delete.cpp similarity index 96% rename from libwccl/ops/actions/delete.cpp rename to libwccl/ops/tagactions/delete.cpp index df2cd223b04110141e1f0d0c5f0fbefd065bb845..05cb5b6be1a47807a739a3abcfc3a0fcf30bcfa8 100644 --- a/libwccl/ops/actions/delete.cpp +++ b/libwccl/ops/tagactions/delete.cpp @@ -1,4 +1,4 @@ -#include <libwccl/ops/actions/delete.h> +#include <libwccl/ops/tagactions/delete.h> #include <libpwrutils/foreach.h> #include <sstream> diff --git a/libwccl/ops/actions/delete.h b/libwccl/ops/tagactions/delete.h similarity index 89% rename from libwccl/ops/actions/delete.h rename to libwccl/ops/tagactions/delete.h index 376877b7b86c9107c0a74ca6f104e56eeca05ab4..53c8e857ab86348e0b63c1ab8a8dd694a608c575 100644 --- a/libwccl/ops/actions/delete.h +++ b/libwccl/ops/tagactions/delete.h @@ -1,7 +1,7 @@ -#ifndef LIBWCCL_OPS_ACTIONS_DELETE_H -#define LIBWCCL_OPS_ACTIONS_DELETE_H +#ifndef LIBWCCL_OPS_TAGACTIONS_DELETE_H +#define LIBWCCL_OPS_TAGACTIONS_DELETE_H -#include <libwccl/ops/action.h> +#include <libwccl/ops/tagaction.h> #include <libwccl/values/position.h> #include <libwccl/values/bool.h> #include <libwccl/ops/function.h> @@ -13,7 +13,7 @@ namespace Wccl { * (unless no lexemes would be left, in which case * token is left alone with no changes) */ -class Delete : public Action +class Delete : public TagAction { public: typedef boost::shared_ptr<Function<Position> > PosFunctionPtr; @@ -66,4 +66,4 @@ private: } /* end ns Wccl */ -#endif // LIBWCCL_OPS_ACTIONS_DELETE_H +#endif // LIBWCCL_OPS_TAGACTIONS_DELETE_H diff --git a/libwccl/ops/actions/relabel.cpp b/libwccl/ops/tagactions/relabel.cpp similarity index 96% rename from libwccl/ops/actions/relabel.cpp rename to libwccl/ops/tagactions/relabel.cpp index e741515f41224a6f7be13f4a235e89aed3d5a8c7..aa2643973ae20fe9e7735a65d74ead8e50f48053 100644 --- a/libwccl/ops/actions/relabel.cpp +++ b/libwccl/ops/tagactions/relabel.cpp @@ -1,4 +1,4 @@ -#include <libwccl/ops/actions/relabel.h> +#include <libwccl/ops/tagactions/relabel.h> #include <libpwrutils/foreach.h> #include <sstream> diff --git a/libwccl/ops/actions/relabel.h b/libwccl/ops/tagactions/relabel.h similarity index 89% rename from libwccl/ops/actions/relabel.h rename to libwccl/ops/tagactions/relabel.h index 5bfd73b0e3f1cf88e42c2d34d4cd14896c13bb58..18d78f6b728229d118fe9ae43539bddf99e45c10 100644 --- a/libwccl/ops/actions/relabel.h +++ b/libwccl/ops/tagactions/relabel.h @@ -1,7 +1,7 @@ -#ifndef LIBWCCL_OPS_ACTIONS_RELABEL_H -#define LIBWCCL_OPS_ACTIONS_RELABEL_H +#ifndef LIBWCCL_OPS_TAGACTIONS_RELABEL_H +#define LIBWCCL_OPS_TAGACTIONS_RELABEL_H -#include <libwccl/ops/action.h> +#include <libwccl/ops/tagaction.h> #include <libwccl/values/position.h> #include <libwccl/values/bool.h> #include <libwccl/ops/function.h> @@ -11,7 +11,7 @@ namespace Wccl { /** * Action to change part of speech for lexemes that meet a condition. */ -class Relabel : public Action +class Relabel : public TagAction { public: typedef boost::shared_ptr<Function<Position> > PosFunctionPtr; @@ -69,4 +69,4 @@ private: } /* end ns Wccl */ -#endif // LIBWCCL_OPS_ACTIONS_RELABEL_H +#endif // LIBWCCL_OPS_TAGACTIONS_RELABEL_H diff --git a/libwccl/ops/actions/select.cpp b/libwccl/ops/tagactions/select.cpp similarity index 96% rename from libwccl/ops/actions/select.cpp rename to libwccl/ops/tagactions/select.cpp index cd746b21362737bd3ff8162e2b5cfaea1f899e40..3205800c2e006a4103bf2edecec99187757d2d66 100644 --- a/libwccl/ops/actions/select.cpp +++ b/libwccl/ops/tagactions/select.cpp @@ -1,4 +1,4 @@ -#include <libwccl/ops/actions/select.h> +#include <libwccl/ops/tagactions/select.h> #include <libpwrutils/foreach.h> #include <sstream> diff --git a/libwccl/ops/actions/select.h b/libwccl/ops/tagactions/select.h similarity index 89% rename from libwccl/ops/actions/select.h rename to libwccl/ops/tagactions/select.h index df08cfee7f4179388d7d913db6df258d71ab4147..b3fd95a10af58f20b42ef4f48aa377df76eabd66 100644 --- a/libwccl/ops/actions/select.h +++ b/libwccl/ops/tagactions/select.h @@ -1,7 +1,7 @@ -#ifndef LIBWCCL_OPS_ACTIONS_SELECT_H -#define LIBWCCL_OPS_ACTIONS_SELECT_H +#ifndef LIBWCCL_OPS_TAGACTIONS_SELECT_H +#define LIBWCCL_OPS_TAGACTIONS_SELECT_H -#include <libwccl/ops/action.h> +#include <libwccl/ops/tagaction.h> #include <libwccl/values/position.h> #include <libwccl/values/bool.h> #include <libwccl/ops/function.h> @@ -13,7 +13,7 @@ namespace Wccl { * (unless no lexemes would be left, in which case * token is left alone with no changes) */ -class Select : public Action +class Select : public TagAction { public: typedef boost::shared_ptr<Function<Position> > PosFunctionPtr; @@ -66,4 +66,4 @@ private: } /* end ns Wccl */ -#endif // LIBWCCL_OPS_ACTIONS_SELECT_H +#endif // LIBWCCL_OPS_TAGACTIONS_SELECT_H diff --git a/libwccl/ops/actions/unify.cpp b/libwccl/ops/tagactions/unify.cpp similarity index 98% rename from libwccl/ops/actions/unify.cpp rename to libwccl/ops/tagactions/unify.cpp index 0cf51523b57798165bbf0fca69303c3b103ab651..2c1e548a035dc4c5cd060e18abd64e9b2edae492 100644 --- a/libwccl/ops/actions/unify.cpp +++ b/libwccl/ops/tagactions/unify.cpp @@ -1,4 +1,4 @@ -#include <libwccl/ops/actions/unify.h> +#include <libwccl/ops/tagactions/unify.h> #include <libpwrutils/foreach.h> #include <sstream> diff --git a/libwccl/ops/actions/unify.h b/libwccl/ops/tagactions/unify.h similarity index 89% rename from libwccl/ops/actions/unify.h rename to libwccl/ops/tagactions/unify.h index 0acd8900528ba8d779ede5cde8fd3cf10a259440..e0e1527f7f42dd1118e657734d32bf2fe6378816 100644 --- a/libwccl/ops/actions/unify.h +++ b/libwccl/ops/tagactions/unify.h @@ -1,7 +1,7 @@ -#ifndef LIBWCCL_OPS_ACTIONS_UNIFY_H -#define LIBWCCL_OPS_ACTIONS_UNIFY_H +#ifndef LIBWCCL_OPS_TAGACTIONS_UNIFY_H +#define LIBWCCL_OPS_TAGACTIONS_UNIFY_H -#include <libwccl/ops/action.h> +#include <libwccl/ops/tagaction.h> #include <libwccl/values/position.h> #include <libwccl/values/bool.h> #include <libwccl/ops/function.h> @@ -12,7 +12,7 @@ namespace Wccl { * Action to unify tokens on an agreement, removing lexemes * that violate the agreement. */ -class Unify : public Action +class Unify : public TagAction { public: typedef boost::shared_ptr<Function<Position> > PosFunctionPtr; @@ -69,4 +69,4 @@ private: } /* end ns Wccl */ -#endif // LIBWCCL_OPS_ACTIONS_UNIFY_H +#endif // LIBWCCL_OPS_TAGACTIONS_UNIFY_H diff --git a/libwccl/ops/rule.cpp b/libwccl/ops/tagrule.cpp similarity index 66% rename from libwccl/ops/rule.cpp rename to libwccl/ops/tagrule.cpp index ba843bd232e191f2c41c6405ebe95d116b62e5e4..2fc123f268cde8735c03c0c11aaa4fa5593a079a 100644 --- a/libwccl/ops/rule.cpp +++ b/libwccl/ops/tagrule.cpp @@ -1,9 +1,9 @@ -#include <libwccl/ops/rule.h> +#include <libwccl/ops/tagrule.h> #include <sstream> namespace Wccl { -Bool Rule::execute(SentenceContext &sentence_context) +Bool TagRule::execute(SentenceContext &sentence_context) { if(sentence_context.size() == 0) { throw InvalidArgument( @@ -18,7 +18,7 @@ Bool Rule::execute(SentenceContext &sentence_context) Bool changed(false); ActionExecContext aec(sentence_context, variables_); if(condition_->apply(aec)->get_value()) { - foreach(const boost::shared_ptr<Action>& action, *actions_) { + foreach(const boost::shared_ptr<TagAction>& action, *actions_) { if(action->execute(aec).get_value()) { changed.set_value(true); } @@ -27,7 +27,7 @@ Bool Rule::execute(SentenceContext &sentence_context) return changed; } -const boost::shared_ptr<const Function<Bool> > Rule::TrueCondition() +const boost::shared_ptr<const Function<Bool> > TagRule::TrueCondition() { static boost::shared_ptr<const Function<Bool> > true_constant( new Constant<Bool>(Bool(true))); @@ -35,20 +35,20 @@ const boost::shared_ptr<const Function<Bool> > Rule::TrueCondition() } -std::string Rule::to_string(const Corpus2::Tagset &tagset) const +std::string TagRule::to_string(const Corpus2::Tagset &tagset) const { std::ostringstream os; os << "rule(\"" << name_ << "\", " << condition_->to_string(tagset); - foreach(const boost::shared_ptr<Action>& action, *actions_) { + foreach(const boost::shared_ptr<TagAction>& action, *actions_) { os << ", " << action->to_string(tagset); } os << ")"; return os.str(); } -std::ostream& Rule::write_to(std::ostream& os) const { +std::ostream& TagRule::write_to(std::ostream& os) const { os << "rule(\"" << name_ << "\", " << *condition_; - foreach(const boost::shared_ptr<Action>& action, *actions_) { + foreach(const boost::shared_ptr<TagAction>& action, *actions_) { os << ", " << *action; } os << ")"; diff --git a/libwccl/ops/rule.h b/libwccl/ops/tagrule.h similarity index 81% rename from libwccl/ops/rule.h rename to libwccl/ops/tagrule.h index f66f90307b6c0cd13c1029933367e62ad4564e95..daee75052d59612360060552ef352acbbb6d84d3 100644 --- a/libwccl/ops/rule.h +++ b/libwccl/ops/tagrule.h @@ -1,11 +1,11 @@ -#ifndef LIBWCCL_OPS_RULE_H -#define LIBWCCL_OPS_RULE_H +#ifndef LIBWCCL_OPS_TAGRULE_H +#define LIBWCCL_OPS_TAGRULE_H #include <boost/scoped_ptr.hpp> #include <libwccl/ops/parsedexpression.h> #include <libwccl/ops/functions/constant.h> -#include <libwccl/ops/action.h> +#include <libwccl/ops/tagaction.h> namespace Wccl { @@ -14,13 +14,13 @@ namespace Wccl { * @note The class methods are not thread-safe, but you can use clone method * to acquire a separate copy of the Rule, and the copy can be used concurrently. */ -class Rule : public ParsedExpression +class TagRule : public ParsedExpression { public: - Rule( + TagRule( const std::string& name, const Variables& variables, - const boost::shared_ptr<const std::vector<boost::shared_ptr<Action> > >& actions, + const boost::shared_ptr<const std::vector<boost::shared_ptr<TagAction> > >& actions, const boost::shared_ptr<const Function<Bool> >& condition = TrueCondition()); /** @@ -79,7 +79,7 @@ public: * @see \link operator=(const Rule&) operator= \endlink - assignment * Rule, yet another way to create a copy. */ - Rule clone() const; + TagRule clone() const; /** * Makes a copy of the Rule, having its own space for Variables. @@ -95,21 +95,21 @@ public: * @see clone_clean_ptr - a version that returns a copy wrapped * in a shared pointer, and also having its Variables cleaned. */ - Rule clone_clean() const; + TagRule clone_clean() const; /** * @returns A copy of the expression, with values of the variables * copied as well. * @see clone_clean_ptr - convenience version that returns clean copy. */ - boost::shared_ptr<Rule> clone_ptr() const; + boost::shared_ptr<TagRule> clone_ptr() const; /** * @returns A copy of the expression, with values of the variables * set to their defaults. * @see clone_ptr - a version that keeps values of the variables. */ - boost::shared_ptr<Rule> clone_clean_ptr() const; + boost::shared_ptr<TagRule> clone_clean_ptr() const; /** * Copy constructor, creates a copy with new set of values for @@ -119,12 +119,12 @@ public: * @param clean - true if copy needs to have its variables * set to default values, false to keep the values; false is default */ - Rule(const Rule& other, bool clean = false); + TagRule(const TagRule& other, bool clean = false); /** * Default constructor. Produces Rule that returns False. */ - Rule(); + TagRule(); /** * Assignment operator to create a workable copy of other Rule * (workable means it has a new set of values for variables, allowing @@ -134,17 +134,17 @@ public: * @param other - Rule to copy * @returns A reference to the current object, after assignment. */ - Rule& operator=(const Rule& other); + TagRule& operator=(const TagRule& other); std::string to_string(const Corpus2::Tagset& tagset) const; protected: - Rule* clone_internal() const; + TagRule* clone_internal() const; std::ostream& write_to(std::ostream& ostream) const; private: static const boost::shared_ptr<const Function<Bool> > TrueCondition(); - boost::shared_ptr<const std::vector<boost::shared_ptr<Action> > > actions_; + boost::shared_ptr<const std::vector<boost::shared_ptr<TagAction> > > actions_; boost::shared_ptr<const Function<Bool> > condition_; std::string name_; }; @@ -155,10 +155,10 @@ private: //--- implementation details --- // inline -Rule::Rule( +TagRule::TagRule( const std::string& name, const Variables& variables, - const boost::shared_ptr<const std::vector<boost::shared_ptr<Action> > >& actions, + const boost::shared_ptr<const std::vector<boost::shared_ptr<TagAction> > >& actions, const boost::shared_ptr<const Function<Bool> >& condition) : ParsedExpression(variables), actions_(actions), @@ -169,22 +169,22 @@ Rule::Rule( } inline -Bool Rule::operator()(SentenceContext& sc) { +Bool TagRule::operator()(SentenceContext& sc) { return execute(sc); } inline -std::string Rule::name() const { +std::string TagRule::name() const { return name_; } inline -Rule* Rule::clone_internal() const { - return new Rule(name_, *variables_, actions_, condition_); +TagRule* TagRule::clone_internal() const { + return new TagRule(name_, *variables_, actions_, condition_); } inline -Rule::Rule(const Rule &other, bool clean) +TagRule::TagRule(const TagRule &other, bool clean) : ParsedExpression(*other.variables_), actions_(other.actions_), condition_(other.condition_), @@ -198,17 +198,17 @@ Rule::Rule(const Rule &other, bool clean) } inline -Rule Rule::clone() const { +TagRule TagRule::clone() const { return *this; } inline -Rule Rule::clone_clean() const { - return Rule(*this, true); +TagRule TagRule::clone_clean() const { + return TagRule(*this, true); } inline -Rule& Rule::operator=(const Rule& other) { +TagRule& TagRule::operator=(const TagRule& other) { BOOST_ASSERT(other.actions_); BOOST_ASSERT(other.condition_); actions_ = other.actions_; @@ -219,9 +219,9 @@ Rule& Rule::operator=(const Rule& other) { } inline -Rule::Rule() +TagRule::TagRule() : ParsedExpression((Variables())), - actions_(boost::make_shared<std::vector<boost::shared_ptr<Action> > >()), + actions_(boost::make_shared<std::vector<boost::shared_ptr<TagAction> > >()), condition_(detail::DefaultFunction<Bool>()), name_() @@ -231,13 +231,13 @@ Rule::Rule() } inline -boost::shared_ptr<Rule> Rule::clone_ptr() const { - return boost::shared_ptr<Rule>(clone_internal()); +boost::shared_ptr<TagRule> TagRule::clone_ptr() const { + return boost::shared_ptr<TagRule>(clone_internal()); } inline -boost::shared_ptr<Rule> Rule::clone_clean_ptr() const { - boost::shared_ptr<Rule> copy(clone_internal()); +boost::shared_ptr<TagRule> TagRule::clone_clean_ptr() const { + boost::shared_ptr<TagRule> copy(clone_internal()); BOOST_ASSERT(copy); copy->clean(); return copy; @@ -245,4 +245,4 @@ boost::shared_ptr<Rule> Rule::clone_clean_ptr() const { } /* end ns Wccl */ -#endif // LIBWCCL_OPS_RULE_H +#endif // LIBWCCL_OPS_TAGRULE_H diff --git a/libwccl/parser/Parser.cpp b/libwccl/parser/Parser.cpp index b7dca250796cbd6bbb657325e75b30bf43a12493..a8bdddf4054cd6308a82d17c7525616e681afe1a 100644 --- a/libwccl/parser/Parser.cpp +++ b/libwccl/parser/Parser.cpp @@ -452,7 +452,7 @@ boost::shared_ptr<RuleSequence> Parser::parseRuleSequence( * @arg str rule * @return the parsed rule via a shared pointer */ -boost::shared_ptr<Rule> Parser::parseSingleRule( +boost::shared_ptr<TagRule> Parser::parseSingleRule( const std::string& str) const { std::stringstream ss (std::stringstream::in | std::stringstream::out); @@ -472,12 +472,12 @@ boost::shared_ptr<Rule> Parser::parseSingleRule( * @arg istr input stream with writed rule * @return the parsed rule via a shared pointer */ -boost::shared_ptr<Rule> Parser::parseSingleRule( +boost::shared_ptr<TagRule> Parser::parseSingleRule( std::istream& istr) const { ANTLRLexer lexer(istr); ANTLRParser parser(lexer); - boost::shared_ptr<Rule> res; + boost::shared_ptr<TagRule> res; try { res = parser.parse_single_rule(tagset_); diff --git a/libwccl/parser/Parser.h b/libwccl/parser/Parser.h index 9f6e3f6bfb6d3d12929a8d60cec8dcde5eedc4d9..645caba176f5d5ec2f9522a1c8f08b4365115d31 100644 --- a/libwccl/parser/Parser.h +++ b/libwccl/parser/Parser.h @@ -73,9 +73,9 @@ public: // --------------------------------------------------------------------------- // Parsing single rule from input string - boost::shared_ptr<Rule> + boost::shared_ptr<TagRule> parseSingleRule(const std::string&) const; - boost::shared_ptr<Rule> + boost::shared_ptr<TagRule> parseSingleRule(std::istream&) const; // --------------------------------------------------------------------------- diff --git a/libwccl/parser/grammar.g b/libwccl/parser/grammar.g index d0969330dcbd9616d80f1d52afed89500710608d..b8d0aa44005a0673aa0be093c00a862aa00227df 100644 --- a/libwccl/parser/grammar.g +++ b/libwccl/parser/grammar.g @@ -59,13 +59,13 @@ header { #include <libwccl/ops/functions/bool/iterations/rightlook.h> // Rules, actions - #include <libwccl/ops/rule.h> + #include <libwccl/ops/tagrule.h> #include <libwccl/ops/rulesequence.h> // - #include <libwccl/ops/actions/unify.h> - #include <libwccl/ops/actions/delete.h> - #include <libwccl/ops/actions/select.h> - #include <libwccl/ops/actions/relabel.h> + #include <libwccl/ops/tagactions/unify.h> + #include <libwccl/ops/tagactions/delete.h> + #include <libwccl/ops/tagactions/select.h> + #include <libwccl/ops/tagactions/relabel.h> // Unicode String @@ -210,10 +210,10 @@ parse_position_operator // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- // Rule for parsing single WCCL Rule -// Returns boost::shared_ptr<Rule> +// Returns boost::shared_ptr<TagRule> parse_single_rule [const Corpus2::Tagset &tagset] - returns [boost::shared_ptr<Rule> rle] + returns [boost::shared_ptr<TagRule> rle] { Variables vars; } @@ -1365,7 +1365,7 @@ symset_setvar // Single action such as select, delete, relabel or unify action [const Corpus2::Tagset& tagset, Variables& vars] - returns [boost::shared_ptr<Action> act] + returns [boost::shared_ptr<TagAction> act] : act = action_select [tagset, vars] | act = action_delete [tagset, vars] | act = action_relabel [tagset, vars] @@ -1378,10 +1378,10 @@ action // select(...), select(...), delete(...) action_sequence [const Corpus2::Tagset& tagset, Variables& vars] - returns [boost::shared_ptr<std::vector<boost::shared_ptr<Action> > > v_act] + returns [boost::shared_ptr<std::vector<boost::shared_ptr<TagAction> > > v_act] { - boost::shared_ptr<Action> act; - v_act.reset(new std::vector<boost::shared_ptr<Action> >); + boost::shared_ptr<TagAction> act; + v_act.reset(new std::vector<boost::shared_ptr<TagAction> >); } : act = action[tagset, vars] { v_act->push_back(act); @@ -1398,10 +1398,10 @@ action_sequence // rule(NAME, ACTIONS) or rule(NAME, COND, ACTIONS) rule [const Corpus2::Tagset& tagset, Variables& vars] - returns [boost::shared_ptr<Rule> rle] + returns [boost::shared_ptr<TagRule> rle] { boost::shared_ptr<Function<Bool> > condition; - boost::shared_ptr<std::vector<boost::shared_ptr<Action> > > actions; + boost::shared_ptr<std::vector<boost::shared_ptr<TagAction> > > actions; } : "rule" LPAREN name: STRING COMMA (condition = bool_operator [tagset, vars] COMMA)? @@ -1409,11 +1409,11 @@ rule RPAREN { if (condition) { rle.reset( - new Rule(token_ref_to_std_string(name), vars, actions, condition)); + new TagRule(token_ref_to_std_string(name), vars, actions, condition)); } else { rle.reset( - new Rule(token_ref_to_std_string(name), vars, actions)); + new TagRule(token_ref_to_std_string(name), vars, actions)); } } /* @@ -1425,14 +1425,14 @@ rule actions = action_sequence [tagset, vars] { // rule(NAME, COND, ACTIONS) rle.reset( - new Rule(token_ref_to_std_string(name), vars, actions, condition)); + new TagRule(token_ref_to_std_string(name), vars, actions, condition)); } ) | ( actions = action_sequence [tagset, vars] { // rule(NAME, ACTIONS) - rle.reset(new Rule(token_ref_to_std_string(name), vars, actions)); + rle.reset(new TagRule(token_ref_to_std_string(name), vars, actions)); } ) ) @@ -1446,7 +1446,7 @@ rule_sequence returns [boost::shared_ptr<RuleSequence> rule_seq] { // FIXME czy tutaj przypadkiem nie powinno byc shared_ptr? - boost::shared_ptr<Rule> rle; + boost::shared_ptr<TagRule> rle; rule_seq.reset(new RuleSequence()); } diff --git a/swig/Makefile b/swig/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..f5fef21701afeb8a27a43a2dd184a873c7f6a0e5 --- /dev/null +++ b/swig/Makefile @@ -0,0 +1,142 @@ +CPP=g++ +SWIG=swig +SWIGOPTS_LANG=-c++ -python + +PYTHONDIR=/usr/include/python2.6 +WCCLDIR=/usr/local/include/libwccl/ +CORPUS2DIR=/usr/local/include/libcorpus2/ +PWRUTILDIR= + +CORPUS2BIN=/usr/local/lib/libcorpus2.so +PWRUTILBIN=/usr/local/lib/libpwrutils.so +CCLBIN=/usr/local/lib/libwccl.so +ANTLRLIB=/usr/lib/libantlr-pic.a + +# CPPFLAGS=-fPIC -Wall -O2 +CPPFLAGS=-fPIC -O2 + +# CBIN=libcorpustag.o libcorpustagset.o libcorpustagsetmanager.o libcclparser.o +# CBIN=libcclvalue.o libcclbool.o libcclposition.o libccltset.o libcclstrset.o +# CBIN=libcclexpression.o libcclparsedexpression.o +CBIN=libcclfunctionaloperator.o + +CBINOUT=_libcorpustag.so _libcorpustagset.so _libcorpustagsetmanager.so \ + _libcclvalue.so _libcclstrset.so _libcclbool.so _libcclposition.so \ + _libccltset.so _libcclexpression.so _libcclparsedexpression.so \ + _libcclfunctionaloperator.so + +CWRAP=libcorpustag_wrap.cxx libcorpustagset_wrap.cxx libcorpustagsetmanager_wrap.cxx \ + libcclvalue_wrap.cxx libcclstrset_wrap.cxx libcclbool_wrap.cxx \ + libcclparser_wrap.cxx libcclposition_wrap.cxx libccltset_wrap.cxx \ + libcclexpression_wrap.cxx libcclparsedexpression_wrap.cxx \ + libcclfunctionaloperator_wrap.cxx + +CWRAPBIN=libcorpustag_wrap.o libcorpustagset_wrap.o libcorpustagsetmanager_wrap.o \ + libcclvalue_wrap.o libcclstrset_wrap.o libcclbool_wrap.o \ + libcclposition_wrap.o libccltset_wrap.o \ + libcclexpression_wrap.o libcclparsedexpression_wrap.o \ + libcclfunctionaloperator_wrap.o + +PYMODULES=libcorpustag.py libcorpustagset.py libcorpustagsetmanager.py \ + libcclvalue.py libcclstrset.py libcclbool.py \ + libcclparser.py libcclposition.py libccltset.py \ + libcclexpression.py libcclparsedexpression.py + +PYCBIN=libcorpustag.pyc libcorpustagset.pyc libcorpustagsetmanager.pyc \ + libcclvalue.pyc libcclstrset.pyc libcclbool.pyc \ + libcclposition.pyc libccltset.pyc libcclexpression.pyc libcclparsedexpression.pyc + +all:$(CBIN) + # Nothing to do + + +# ----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- +# Corpus2 Wrappers +# ----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- +# Tag +libcorpustag.o: + $(SWIG) $(SWIGOPTS_LANG) libcorpustag.i + $(CPP) -c libcorpustag_wrap.cxx -I$(PYTHONDIR) $(CPPFLAGS) + $(CPP) -shared libcorpustag_wrap.o \ + $(PWRUTILBIN) $(CORPUS2BIN) -o _libcorpustag.so + +# Tagset +libcorpustagset.o: + $(SWIG) $(SWIGOPTS_LANG) libcorpustagset.i + $(CPP) -c libcorpustagset_wrap.cxx -I$(PYTHONDIR) $(CPPFLAGS) + $(CPP) -fPIC -shared libcorpustagset_wrap.o \ + $(PWRUTILBIN) $(CORPUS2BIN) -o _libcorpustagset.so + +# Tagsetmanager +libcorpustagsetmanager.o: + $(SWIG) $(SWIGOPTS_LANG) libcorpustagsetmanager.i + $(CPP) -c libcorpustagsetmanager_wrap.cxx -I$(PYTHONDIR) $(CPPFLAGS) + $(CPP) -shared libcorpustagsetmanager_wrap.o \ + $(CCLBIN) $(PWRUTILBIN) $(CORPUS2BIN) -o _libcorpustagsetmanager.so + +# ----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- +# CCL Wrappers +# ----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- +# Value +libcclvalue.o: + $(SWIG) $(SWIGOPTS_LANG) libcclvalue.i + $(CPP) -c libcclvalue_wrap.cxx -I$(PYTHONDIR) -I$(WCCLDIR) $(CPPFLAGS) + $(CPP) -shared libcclvalue_wrap.o \ + $(CCLBIN) $(ANTLRLIB) -o _libcclvalue.so + +# Bool +libcclbool.o: + $(SWIG) $(SWIGOPTS_LANG) libcclbool.i + $(CPP) -c libcclbool_wrap.cxx -I$(PYTHONDIR) -I$(WCCLDIR) $(CPPFLAGS) + $(CPP) -shared libcclbool_wrap.o \ + $(CCLBIN) $(ANTLRLIB) -o _libcclbool.so + +# Position +libcclposition.o: + $(SWIG) $(SWIGOPTS_LANG) libcclposition.i + $(CPP) -c libcclposition_wrap.cxx -I$(PYTHONDIR) -I$(WCCLDIR) $(CPPFLAGS) + $(CPP) -shared libcclposition_wrap.o \ + $(CCLBIN) $(ANTLRLIB) -o _libcclposition.so + +# TSet +libccltset.o: + $(SWIG) $(SWIGOPTS_LANG) libccltset.i + $(CPP) -c libccltset_wrap.cxx -I$(PYTHONDIR) -I$(WCCLDIR) $(CPPFLAGS) + $(CPP) -shared libccltset_wrap.o \ + $(CCLBIN) $(ANTLRLIB) -o _libccltset.so + +# StrSet +libcclstrset.o: + $(SWIG) $(SWIGOPTS_LANG) libcclstrset.i + $(CPP) -c libcclstrset_wrap.cxx -I$(PYTHONDIR) -I$(WCCLDIR) $(CPPFLAGS) + $(CPP) -shared libcclstrset_wrap.o \ + $(CCLBIN) $(ANTLRLIB) -o _libcclstrset.so + +# Expression +libcclexpression.o: + $(SWIG) $(SWIGOPTS_LANG) libcclexpression.i + $(CPP) -c libcclexpression_wrap.cxx -I$(PYTHONDIR) -I$(WCCLDIR) $(CPPFLAGS) + $(CPP) -shared libcclexpression_wrap.o \ + $(CCLBIN) $(ANTLRLIB) -o _libcclexpression.so + +# ParsedExpression +libcclparsedexpression.o: + $(SWIG) $(SWIGOPTS_LANG) libcclparsedexpression.i + $(CPP) -c libcclparsedexpression_wrap.cxx -I$(PYTHONDIR) -I$(WCCLDIR) $(CPPFLAGS) + $(CPP) -shared libcclparsedexpression_wrap.o \ + $(CCLBIN) $(ANTLRLIB) -o _libcclparsedexpression.so + +# FunctionalOperator +libcclfunctionaloperator.o: + $(SWIG) $(SWIGOPTS_LANG) libcclfunctionaloperator.i + $(CPP) -c libcclfunctionaloperator_wrap.cxx -I$(PYTHONDIR) -I$(WCCLDIR) $(CPPFLAGS) + $(CPP) -shared libcclfunctionaloperator_wrap.o \ + $(CCLBIN) $(ANTLRLIB) -o _libcclfunctionaloperator.so + +# ----------------------------------------------------------------------------- +clean: + rm -f $(CBIN) $(CBINOUT) $(CWRAP) $(CWRAPBIN) $(PYMODULES) $(PYCBIN) diff --git a/swig/libcclexpression.i b/swig/libcclexpression.i new file mode 100644 index 0000000000000000000000000000000000000000..b401e859ee380a0b911092228eb12d6babccc89a --- /dev/null +++ b/swig/libcclexpression.i @@ -0,0 +1,23 @@ +#ifndef SWIG_LIBWCCL_EXPRESSION_I +#define SWIG_LIBWCCL_EXPRESSION_I + +%module libcclexpression +%{ + #include <libwccl/ops/expression.h> + #include <boost/noncopyable.hpp> +%} + +%include "libcorpustagset.i" +%include "std_string.i" + +namespace Wccl { + class Expression : boost::noncopyable { + public: + virtual std::string to_string(const Corpus2::Tagset& tagset) const = 0; + }; +} + +using namespace std; +using namespace Wccl; + +#endif /* SWIG_LIBWCCL_EXPRESSION_I */ diff --git a/swig/libcclfunctionaloperator.i b/swig/libcclfunctionaloperator.i new file mode 100644 index 0000000000000000000000000000000000000000..6694916efdd8c08c2ed3c045c5c559510ed35a63 --- /dev/null +++ b/swig/libcclfunctionaloperator.i @@ -0,0 +1,28 @@ +#ifndef SWIG_LIBWCCL_FUNCTIONALOPERATOR_I +#define SWIG_LIBWCCL_FUNCTIONALOPERATOR_I + +%module libcclparsedexpression +%{ + #include <libwccl/ops/operator.h> +%} + +%include "libcclparsedexpression.i" +%include "std_string.i" + +namespace Wccl { + class FunctionalOperator : public ParsedExpression { + public: + // virtual boost::shared_ptr<const Value> base_apply(const SentenceContext& sc) = 0; + // boost::shared_ptr<FunctionalOperator> clone_ptr() const; + // boost::shared_ptr<FunctionalOperator> clone_clean_ptr() const; + + protected: + // explicit FunctionalOperator(const Variables& variables); + // FunctionalOperator* clone_internal() const = 0; + }; +} + +using namespace std; +using namespace Wccl; + +#endif /* SWIG_LIBWCCL_FUNCTIONALOPERATOR_I */ diff --git a/swig/libcclparsedexpression.i b/swig/libcclparsedexpression.i new file mode 100644 index 0000000000000000000000000000000000000000..6b224f7eb257ec1cffd37ce34180edb57deab9ff --- /dev/null +++ b/swig/libcclparsedexpression.i @@ -0,0 +1,43 @@ +#ifndef SWIG_LIBWCCL_PARSEDEXPRESSION_I +#define SWIG_LIBWCCL_PARSEDEXPRESSION_I + +%module libcclparsedexpression +%{ + #include <libwccl/ops/parsedexpression.h> +%} + +%include "libcclexpression.i" +%include "std_string.i" + +namespace Wccl { + class ParsedExpression : public Expression { + public: + // TODO + // const Value& operator[](const std::string& var_name) const; + + // template<class T> + // const T& get(const std::string& var_name) const; + + // template<class T> + // T& get(const std::string& var_name) + + // template<class T> + // void set(const std::string& var_name, const T& value); + + void clean(); + // boost::shared_ptr<ParsedExpression> clone_ptr() const; + // boost::shared_ptr<ParsedExpression> clone_clean_ptr() const; + std::string variables_string(const Corpus2::Tagset& tagset) const; + // std::ostream& dump_variables(std::ostream& ostream, const Corpus2::Tagset& tagset) const; + + protected: + // explicit ParsedExpression(const Variables& variables); + // boost::shared_ptr<Variables> variables_; + virtual ParsedExpression* clone_internal() const = 0; + }; +} + +using namespace std; +using namespace Wccl; + +#endif /* SWIG_LIBWCCL_PARSEDEXPRESSION_I */ diff --git a/swig/libcclparser.i b/swig/libcclparser.i index 2b830cc92caa26ffa761542e2a7b094e17f08a35..fc2284bbf6efe82dcca453060980e12062fce2c2 100644 --- a/swig/libcclparser.i +++ b/swig/libcclparser.i @@ -19,8 +19,6 @@ namespace Wccl { /* --------------------------------------------------------------------- */ }; - - inline const Tagset& get_named_tagset(const std::string& name); } using namespace std;