Skip to content
Snippets Groups Projects
Select Git revision
  • 5e5e461b6cc35dba693cd458bc72f265da603b0e
  • main default protected
  • ud_training_script
  • fix_seed
  • merged-with-ner
  • multiword_fix_transformer
  • transformer_encoder
  • combo3
  • save_deprel_matrix_to_npz
  • master protected
  • combo-lambo
  • lambo-sent-attributes
  • adding_lambo
  • develop
  • update_allenlp2
  • develop_tmp
  • tokens_truncation
  • LR_test
  • eud_iwpt
  • iob
  • eud_iwpt_shared_task_bert_finetuning
  • 3.3.1
  • list
  • 3.2.1
  • 3.0.3
  • 3.0.1
  • 3.0.0
  • v1.0.6
  • v1.0.5
  • v1.0.4
  • v1.0.3
  • v1.0.2
  • v1.0.1
  • v1.0.0
34 results

setup.py

Blame
  • regex.cpp 1.75 KiB
    #include <boost/test/unit_test.hpp>
    #include <boost/bind.hpp>
    #include <boost/shared_ptr.hpp>
    #include <libcorpus2/sentence.h>
    
    #include <libwccl/ops/functions/constant.h>
    #include <libwccl/ops/functions/bool/predicates/regex.h>
    #include <libwccl/values/bool.h>
    #include <libwccl/values/strset.h>
    #include <libwccl/sentencecontext.h>
    #include <unicode/unistr.h>
    
    using namespace Wccl;
    
    BOOST_AUTO_TEST_SUITE(regexing)
    
    struct RegexFix
    {
    	RegexFix()
    		: sc(boost::make_shared<Corpus2::Sentence>()),
    		  tagset(),
    		  cx(sc, boost::make_shared<Variables>())
    	{
    	}
    	SentenceContext sc;
    	Corpus2::Tagset tagset;
    	FunExecContext cx;
    };
    
    BOOST_FIXTURE_TEST_CASE(positive_sanity_check, RegexFix)
    {
    	StrSet sanity;
    	sanity.insert("word");
    	boost::shared_ptr<Function<StrSet> > sanity_expr(new Constant<StrSet>(sanity));
    	Regex r(sanity_expr, "word");
    	BOOST_CHECK(r.apply(cx)->get_value());
    }
    
    BOOST_FIXTURE_TEST_CASE(negative_sanity_check, RegexFix)
    {
    	StrSet sanity;
    	sanity.insert("word");
    	boost::shared_ptr<Function<StrSet> > sanity_expr(new Constant<StrSet>(sanity));
    	Regex r(sanity_expr, "Word");
    	BOOST_CHECK(!r.apply(cx)->get_value());
    }
    
    //TODO: need more regex tests...
    
    //------------ To string ----------
    
    BOOST_FIXTURE_TEST_CASE(regex_tostring, RegexFix)
    {
    	StrSet sanity;
    	sanity.insert("word");
    	boost::shared_ptr<Function<StrSet> > sanity_expr(new Constant<StrSet>(sanity));
    	Regex r(sanity_expr, "Word");
    	BOOST_CHECK_EQUAL("regex([\"word\"], \"Word\")", r.to_string(tagset));
    }
    
    BOOST_AUTO_TEST_CASE(regex_to_raw_string)
    {
    	StrSet sanity;
    	sanity.insert("word");
    	boost::shared_ptr<Function<StrSet> > sanity_expr(new Constant<StrSet>(sanity));
    	Regex r(sanity_expr, "Word");
    	BOOST_CHECK_EQUAL("regex([\"word\"], \"Word\")", r.to_raw_string());
    }
    
    BOOST_AUTO_TEST_SUITE_END()