diff --git a/examples/simple-match.ccl b/examples/simple-match.ccl new file mode 100644 index 0000000000000000000000000000000000000000..fbac352a51e91292acbc185965d5e70ae25dcb5b --- /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 45f310150515f6068df5818d5ce53eece7ae196e..826221c0030943b7faf69a418870f1e4318f2bfc 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 1b94aa0cd8c66cc9f3727019a0e13371f50f8171..af1ce94f371eb0fc531000fd23c6149a3e462659 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 cc5105c10047799639eb21209e41ba15c4581e75..d45853b668d8c72bf28ca7d1bf5ca287c20f6c3b 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); /* --------------------------------------------------------------------- */