Skip to content
Snippets Groups Projects
Commit 128dcb67 authored by Adam Radziszewski's avatar Adam Radziszewski
Browse files

fix MatchRuleSeq wrapper to allow for basic Sentence objects

parent 39283388
Branches
No related merge requests found
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")
)
)
)
#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;
......
......@@ -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;
......
......@@ -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);
/* --------------------------------------------------------------------- */
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment