From 128dcb676145ec2adda228feb684bc3a271f2fe3 Mon Sep 17 00:00:00 2001 From: Adam Radziszewski <adam.radziszewski@pwr.wroc.pl> Date: Fri, 16 Sep 2011 13:34:02 +0200 Subject: [PATCH] fix MatchRuleSeq wrapper to allow for basic Sentence objects --- examples/simple-match.ccl | 24 ++++++++++++++++++++++++ libwccl/ops/matchrulesequence.cpp | 18 +++++++++++++++++- libwccl/ops/matchrulesequence.h | 8 ++++++++ swig/matchrulesequence.i | 2 ++ 4 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 examples/simple-match.ccl diff --git a/examples/simple-match.ccl b/examples/simple-match.ccl new file mode 100644 index 0000000..fbac352 --- /dev/null +++ b/examples/simple-match.ccl @@ -0,0 +1,24 @@ +match_rules( + apply( + match( + optional(equal(base[0], "nie")), + repeat( + inter(class[0], {adj, ppas, pact}) + ) + ), + actions( + mark(M, "AdjP") + ) + ); + + apply( + match( + optional(is("AdjP")), + inter(class[0], {subst, ger, depr}) + ), + actions( + mark(M, M, :2, "NP") + ) + ) +) + diff --git a/libwccl/ops/matchrulesequence.cpp b/libwccl/ops/matchrulesequence.cpp index 45f3101..826221c 100644 --- a/libwccl/ops/matchrulesequence.cpp +++ b/libwccl/ops/matchrulesequence.cpp @@ -1,10 +1,13 @@ #include <libwccl/ops/matchrulesequence.h> #include <libpwrutils/foreach.h> +#include <boost/shared_ptr.hpp> + namespace Wccl { namespace Matching { -void MatchRuleSequence::apply_all(const boost::shared_ptr<Corpus2::AnnotatedSentence>& sentence) +void MatchRuleSequence::apply_all( + const boost::shared_ptr<Corpus2::AnnotatedSentence>& sentence) { if(!sentence || sentence->empty()) { throw InvalidArgument( @@ -16,6 +19,19 @@ void MatchRuleSequence::apply_all(const boost::shared_ptr<Corpus2::AnnotatedSent } } +void MatchRuleSequence::apply_all_sentence_wrapper( + const boost::shared_ptr<Corpus2::Sentence>& sentence) +{ + boost::shared_ptr<Corpus2::AnnotatedSentence> as; + as = boost::dynamic_pointer_cast<Corpus2::AnnotatedSentence>(sentence); + if (!as) { + throw InvalidArgument( + "sentence", + "Did not get an AnnotatedSentence from reader, 'ann' option broken?"); + } + apply_all(as); +} + std::string MatchRuleSequence::to_string(const Corpus2::Tagset& tagset) const { std::ostringstream os; diff --git a/libwccl/ops/matchrulesequence.h b/libwccl/ops/matchrulesequence.h index 1b94aa0..af1ce94 100644 --- a/libwccl/ops/matchrulesequence.h +++ b/libwccl/ops/matchrulesequence.h @@ -54,6 +54,14 @@ public: */ void apply_all(const boost::shared_ptr<Corpus2::AnnotatedSentence>& sentence); + /** + * A convenience wrapper that pretends the input is a standard + * Corpus::Sentence object and casts it internally as an AnnotatedSentence. + * @see \link apply_all \endlink - the same routine without wrapping. + */ + void apply_all_sentence_wrapper( + const boost::shared_ptr<Corpus2::Sentence>& sentence); + std::string to_string(const Corpus2::Tagset& tagset) const; protected: std::ostream& write_to(std::ostream& os) const; diff --git a/swig/matchrulesequence.i b/swig/matchrulesequence.i index cc5105c..d45853b 100644 --- a/swig/matchrulesequence.i +++ b/swig/matchrulesequence.i @@ -9,6 +9,7 @@ %include "matchrule.i" %include "expression.i" %include "libcorpus2/annotatedsentence.i" +%include "libcorpus2/sentence.i" %include "std_string.i" %include "std_vector.i" @@ -35,6 +36,7 @@ namespace Matching { /* --------------------------------------------------------------------- */ void apply_all(const shared_ptr<Corpus2::AnnotatedSentence>& sentence); + void apply_all_sentence_wrapper(const shared_ptr<Corpus2::Sentence>& sentence); /* --------------------------------------------------------------------- */ -- GitLab