Skip to content
Snippets Groups Projects
Commit e70ded36 authored by Bartosz Broda's avatar Bartosz Broda
Browse files

small cleanup, small extensions

parent cc8c48ad
No related merge requests found
......@@ -19,7 +19,7 @@ LexicalUnit::LexicalUnit(const std::string &base,
}
bool LexicalUnit::IsHere(const Wccl::SentenceContext &sc,
std::set<size_t> &out_position)
std::set<size_t> &out_position) const
{
boost::shared_ptr<const Wccl::Bool> pResult = condition_->apply(sc);
if(pResult->get_value() == false)
......@@ -39,6 +39,8 @@ bool LexicalUnit::IsHere(const Wccl::SentenceContext &sc,
return true;
}
////////////////////////////////////////////////////////////////////
// TODO realy needed?
FixedLU::FixedLU(const std::string &base,
boost::shared_ptr<Wccl::Operator<Wccl::Bool> > condition,
......@@ -56,12 +58,14 @@ FlexLU::FlexLU(const std::string &base,
{
}
MWEIndex::MWEIndex()
{
////////////////////////////////////////////////////////////////////
MWEIndex::MWEIndex() : index_(), empty_()
{
// noop
}
void MWEIndex::add_lexicalunit(LexicalUnitPtr lu)
void MWEIndex::add_lexicalunit(LexicalUnit::Ptr lu)
{
foreach(const std::string& base, lu->get_potential_bases()){
value_type::iterator find = index_.find(base);
......@@ -75,4 +79,13 @@ void MWEIndex::add_lexicalunit(LexicalUnitPtr lu)
}
}
const MWEIndex::luvec& MWEIndex::get_potential_lu(const std::string &base){
value_type::iterator find = index_.find(base);
if(find == index_.end()){ // not found -> return empty
return empty_;
}
return (find->second);
}
}//ns Corpus2
......@@ -31,14 +31,14 @@ public:
* \returns true if this lexical unit was found here
*/
virtual bool IsHere(const Wccl::SentenceContext& sc,
std::set<size_t> &out_positions) ;
std::set<size_t> &out_positions) const;
const std::string & get_base() const{ return base_;}
const strmap & get_variables() const{ return variables_;}
const strset& get_potential_bases() const{ return potential_bases_;}
typedef boost::shared_ptr<LexicalUnit> Ptr;
protected:
boost::shared_ptr<Wccl::Operator<Wccl::Bool> > condition_;
......@@ -51,7 +51,7 @@ protected:
const Wccl::Position nowhere_;
};
typedef boost::shared_ptr<LexicalUnit> LexicalUnitPtr;
// TODO: czy bedzie potrzebny podzial na fix/flex w kodzie?
......@@ -59,9 +59,9 @@ class FixedLU : public LexicalUnit
{
public:
FixedLU(const std::string &base,
boost::shared_ptr<Wccl::Operator<Wccl::Bool> > condition,
boost::shared_ptr<Wccl::Operator<Wccl::Bool> > head_cond,
std::map<std::string, std::string> variables
LexicalUnit::BoolOpPtr condition,
LexicalUnit::BoolOpPtr head_cond,
LexicalUnit::strmap variables
);
};
......@@ -69,9 +69,9 @@ class FlexLU : public LexicalUnit
{
public:
FlexLU(const std::string &base,
boost::shared_ptr<Wccl::Operator<Wccl::Bool> > condition,
boost::shared_ptr<Wccl::Operator<Wccl::Bool> > head_cond,
std::map<std::string, std::string> variables
LexicalUnit::BoolOpPtr condition,
LexicalUnit::BoolOpPtr head_cond,
LexicalUnit::strmap variables
);
};
......@@ -79,16 +79,22 @@ public:
class MWEIndex // lub base -> vector<LexicalUnit>
{
public:
typedef std::vector<LexicalUnit::Ptr> luvec;
MWEIndex();
void add_lexicalunit(LexicalUnitPtr lu);
void add_lexicalunit(LexicalUnit::Ptr lu);
const luvec& get_potential_lu(const std::string& base);
protected:
typedef std::vector<LexicalUnitPtr> luvec;
typedef boost::unordered_map<std::string,luvec> value_type;
value_type index_;
const luvec empty_;
};
}// ns Corpus2
......
......@@ -60,17 +60,18 @@ namespace Corpus2 {
MWEBuilder::BoolOpPtr head = mwe_builder_->get_head_condition(
head_cond_);
LexicalUnitPtr lu;
if(group_type_ == "fix"){ // group_name_ -> lower case
lu = LexicalUnitPtr(new FixedLU(mwe_base_, main, head,
variables_));
mwe_index_.add_lexicalunit( LexicalUnit::Ptr(new FixedLU(mwe_base_, main, head,
variables_)));
} else if(group_type_ == "flex"){
lu = LexicalUnitPtr(new FlexLU(mwe_base_, main, head,
variables_));
mwe_index_.add_lexicalunit(LexicalUnit::Ptr(new FlexLU(mwe_base_, main, head,
variables_)));
} else {
throw Wccl::WcclError("Unknown type of lexical unit:"
+ group_type_);
}
}
std::string MWEParser::get_attribute(const AttributeList& attributes,
......
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