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

add searching for head of an mwe

parent c2317fdd
Branches
No related merge requests found
......@@ -24,7 +24,7 @@ LexicalUnit::LexicalUnit(const std::string &base,
}
bool LexicalUnit::IsHere(const Wccl::SentenceContext &sc,
std::set<size_t> &out_position) const
std::set<size_t> &out_position, int &head_pos) const
{
// set variables
for(variables_map::const_iterator ivars = variables_.begin();
......@@ -37,6 +37,10 @@ bool LexicalUnit::IsHere(const Wccl::SentenceContext &sc,
if(pResult->get_value() == false)
return false;
bool found_head = false;
Wccl::SentenceContext sc2(sc.get_sentence_ptr());
// fill up positions
foreach(const std::string&varname, condition_->valid_variable_names()){
if(boost::algorithm::starts_with(varname, "Pos")){
......@@ -46,11 +50,24 @@ bool LexicalUnit::IsHere(const Wccl::SentenceContext &sc,
errmsg += " Offending unit: " + base_;
throw Wccl::WcclError(errmsg);
}
out_position.insert( sc.get_abs_position(pos) );
int abs_pos = sc.get_abs_position(pos);
out_position.insert( abs_pos );
if(!found_head){
sc2.set_position(abs_pos);
if(head_cond_->apply(sc2)->get_value()){
head_pos = abs_pos;
found_head = true;
}
}
}
}
// TODO head position
if(!found_head){
std::string errmsg("MWE found, but no head for it.");
errmsg += " Offending unit: " + base_;
throw Wccl::WcclError(errmsg);
}
return true;
}
......
......@@ -35,7 +35,7 @@ public:
* \returns true if this lexical unit was found here
*/
virtual bool IsHere(const Wccl::SentenceContext& sc,
std::set<size_t> &out_positions) const;
std::set<size_t> &out_positions, int &head_pos) const;
const std::string & get_base() const{ return base_;}
const variables_map & get_variables() const{ return variables_;}
......
......@@ -46,7 +46,8 @@ bool MWEReader::registered = TokenReader::register_path_reader<MWEReader>(
std::cout << "# ";
foreach(LexicalUnit::Ptr pLU, potential){
std::set<size_t> positions;
bool is_here = pLU->IsHere(sc, positions);
int head;
bool is_here = pLU->IsHere(sc, positions, head);
if(is_here)
std::cout << "** " << pLU->get_base() << "** ";
}
......
......@@ -17,7 +17,7 @@
<MWE base="Jan Paweł">
<var name="Subst1">jan</var>
<var name="Subst2">paweł</var>
<head>inter(cas[0], {nom})</head>
<head>inter(base[0], "jan")</head>
</MWE>
<MWE base="waga netto">
<var name="Subst1">waga</var>
......
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