Commit 814dc84a authored by Florent Jacquemard's avatar Florent Jacquemard
Browse files

unfail runs for target squant2

parent 50a1da87
......@@ -229,44 +229,59 @@ public:
/// Key assignement.
virtual K& operator= (const K& p) = 0;
/// for use as key in a unordered_multimap.
virtual bool operator==(const K& p) const = 0;
inline bool operator!=(const K& p) const
{ return (! (*this == p)); }
/// return wether this Key is an instance of p.
/// if p is complete, then it is equality.
virtual bool instance(const K& p) const = 0;
/// inverse of instance
/// return wether p is an instance of this Key.
/// if this Key is complete, then it is equality.
bool subsume(const K& p) const
{ return p.instance(*this); }
/// all attributes of the key are valued
virtual bool complete() const = 0;
/// one atribute at least of the key is not valued
inline bool partial() const
{ return(! this->complete()); }
/// allocate and return a special Run representing a parse failure for this key.
/// @param env parsing environment.
/// @return a pointer to a newly allocated fail run, with
/// - transition with dummy symbol, empty body, weight one in the
/// domain of the base wta in the passed environment.
/// - fail symbol
/// - weight zero (in the domain of the base wta).
/// This returned run will answer succesfully to Run.fail().
Run<K>* failRun_zero(const ParsingEnv& env) const;
/// @brief number of input events represented by this key.
virtual size_t size() const { return 0; }
/// allocate and return a special Run representing a parse failure for this key.
/// @param env parsing environment.
/// @return a pointer to a newly allocated fail run, with
/// - transition with dummy symbol, empty body, weight one in the
/// domain of the base wta in the passed environment.
/// - fail symbol
/// - weight one (in the domain of the base wta).
/// This returned run will answer succesfully to Run.fail().
Run<K>* failRun_one(const ParsingEnv& env) const;
/// @brief time interval represented by this key,
/// or NULL if there is none.
virtual IntervalTree* interval() const { return NULL; }
protected:
/// @brief number of input events represented by this key.
virtual size_t size() const { return 0; }
private:
/// trick of Curiously Recurring Template Pattern
......@@ -278,11 +293,12 @@ private:
};
} // end namespace Parsing
// separated definition of template class
#include "Key.tpp"
} // end namespace Parsing
#endif /* Key_hpp */
......
......@@ -6,6 +6,8 @@
// Copyright © 2019 Florent Jacquemard. All rights reserved.
//
namespace Parsing{
template<class K>
Key<K>::Key()
......@@ -74,6 +76,27 @@ void Key<K>::leaves(const Transition& tr,
}
template<class K>
Run<K>* Key<K>::failRun_zero(const ParsingEnv& env) const
{
assert(env.wta);
const Transition& t0 = env.dummyTransition_zero();
assert(t0.weight().zero());
label_t a = SymbLabel::make_fail(this->size());
return new Run<K>(t0, a, t0.weight());
}
template<class K>
Run<K>* Key<K>::failRun_one(const ParsingEnv& env) const
{
assert(env.wta);
const Transition& t1 = env.dummyTransition_one();
assert(t1.weight().one());
label_t a = SymbLabel::make_fail(this->size());
return new Run<K>(t1, a, t1.weight());
}
// template<class K>
// K* Key<K>::leaf(label_t a,
// const Transition& tr,
......@@ -110,3 +133,7 @@ void Key<K>::leaves(const Transition& tr,
// return (new K(k));
// }
//}
} // end namespace Parsing
......@@ -116,6 +116,26 @@ protected:
public:
/// allocate and return a special Run representing a parse failure for this key.
/// @param env parsing environment.
/// @return a pointer to a newly allocated fail run, with
/// - transition with dummy symbol, empty body, weight one in the
/// domain of the base wta in the passed environment.
/// - fail symbol
/// - weight zero (in the domain of the base wta).
/// This returned run will answer succesfully to Run.fail().
Run<KeyS>* failRun_zero(const ParsingEnv& env) const;
/// allocate and return a special Run representing a parse failure for this key.
/// @param env parsing environment.
/// @return a pointer to a newly allocated fail run, with
/// - transition with dummy symbol, empty body, weight one in the
/// domain of the base wta in the passed environment.
/// - fail symbol
/// - weight one (in the domain of the base wta).
/// This returned run will answer succesfully to Run.fail().
Run<KeyS>* failRun_one(const ParsingEnv& env) const;
/// @brief this key can be an inner node, target of tr, in a run.
/// @param tr a SWTA transition, augmented by the transition partially
......
......@@ -159,6 +159,23 @@ _interval(head._interval) // no clone (share intervals)
// case of terminal bar symbol (double bar)
}
Run<KeySI>* KeySI::failRun_zero(const ParsingEnv& env) const
{
assert(env.wta);
const Transition& t0 = env.dummyTransition_zero();
assert(t0.weight().zero());
label_t a = SymbLabel::make_fail(this->size());
return new Run<KeySI>(t0, a, t0.weight());
}
Run<KeySI>* KeySI::failRun_one(const ParsingEnv& env) const
{
assert(env.wta);
const Transition& t1 = env.dummyTransition_one();
assert(t1.weight().one());
label_t a = SymbLabel::make_fail(this->size());
return new Run<KeySI>(t1, a, t1.weight());
}
size_t KeySI::leaf(const Transition& tr,
const ParsingEnv& env) const
......
......@@ -115,6 +115,25 @@ protected:
public:
/// allocate and return a special Run representing a parse failure for this key.
/// @param env parsing environment.
/// @return a pointer to a newly allocated fail run, with
/// - transition with dummy symbol, empty body, weight one in the
/// domain of the base wta in the passed environment.
/// - fail symbol
/// - weight zero (in the domain of the base wta).
/// This returned run will answer succesfully to Run.fail().
Run<KeySI>* failRun_zero(const ParsingEnv& env) const;
/// allocate and return a special Run representing a parse failure for this key.
/// @param env parsing environment.
/// @return a pointer to a newly allocated fail run, with
/// - transition with dummy symbol, empty body, weight one in the
/// domain of the base wta in the passed environment.
/// - fail symbol
/// - weight one (in the domain of the base wta).
/// This returned run will answer succesfully to Run.fail().
Run<KeySI>* failRun_one(const ParsingEnv& env) const;
/// @brief number of leaf instances that can be obtained
/// from this key and the given args.
......@@ -137,7 +156,6 @@ public:
virtual size_t leaf(const Transition& tr,
const ParsingEnv& env) const;
// /// @brief completion of this partial leaf key to be the head
// /// of a nullary (leaf) transition augmenting tr.
// /// Build and store in the given queue q
......@@ -152,7 +170,6 @@ public:
const ParsingEnv& env,
std::queue<KeySI>& q) const;
/// Best label of terminal transition augmenting tr targeted to this key.
/// @param tr a SWTA transition, possibly unlabelled or partialy labelled
/// @param env parsing environment.
......@@ -184,7 +201,6 @@ public:
const Transition& tr,
const ParsingEnv& env) const;
/// @brief return WTA transitions to be generalized
/// to augmented transitions targeted by this key or an instance.
/// @param s a stack to be filled with WTA transitions to be augmented.
......@@ -193,42 +209,34 @@ public:
virtual void transitions(std::stack<const Transition*>& s,
ParsingEnv& env) const;
/// @brief Key assignement.
virtual KeySI& operator= (const KeySI& p);
/// @brief for use as key in a unordered_multimap.
virtual bool operator==(const KeySI& p) const;
virtual bool operator!=(const KeySI& p) const;
/// @brief return wether this Key is an instance of p.
/// = equality in this case because KeyS are always complete.
virtual bool instance(const KeySI& p) const;
/// @brief all attributes of the key are valued
virtual bool complete() const;
/// @brief accessor
virtual size_t size() const;
/// @brief accessor
virtual IntervalTree* interval() const { return _interval; }
/// @brief printer
friend std::ostream& operator<<(std::ostream& o, const KeySI& p);
protected:
rtu_t _barlen; // current bar length. useful only for meta keys.
IntervalTree* _interval; // should not be modified
/// @brief accessor
virtual size_t size() const;
bool equal_interval(const KeySI&) const;
/// @brief weight for the case of a and tr inner.
......@@ -312,7 +320,6 @@ protected:
};
/// hash function for using as key in a table.
/// rank is ignoreds : same as SpointerHasher
struct KeySIHasher
......
......@@ -155,6 +155,26 @@ _pre_laston(head._pre_laston)
}
Run<KeySIO>* KeySIO::failRun_zero(const ParsingEnv& env) const
{
assert(env.wta);
const Transition& t0 = env.dummyTransition_zero();
assert(t0.weight().zero());
label_t a = SymbLabel::make_fail(this->size());
return new Run<KeySIO>(t0, a, t0.weight());
}
Run<KeySIO>* KeySIO::failRun_one(const ParsingEnv& env) const
{
assert(env.wta);
const Transition& t1 = env.dummyTransition_one();
assert(t1.weight().one());
label_t a = SymbLabel::make_fail(this->size());
return new Run<KeySIO>(t1, a, t1.weight());
}
size_t KeySIO::size() const
{
assert(_interval);
......
......@@ -138,6 +138,26 @@ public:
label_t a,
const ParsingEnv& env);
/// allocate and return a special Run representing a parse failure for this key.
/// @param env parsing environment.
/// @return a pointer to a newly allocated fail run, with
/// - transition with dummy symbol, empty body, weight one in the
/// domain of the base wta in the passed environment.
/// - fail symbol
/// - weight zero (in the domain of the base wta).
/// This returned run will answer succesfully to Run.fail().
Run<KeySIO>* failRun_zero(const ParsingEnv& env) const;
/// allocate and return a special Run representing a parse failure for this key.
/// @param env parsing environment.
/// @return a pointer to a newly allocated fail run, with
/// - transition with dummy symbol, empty body, weight one in the
/// domain of the base wta in the passed environment.
/// - fail symbol
/// - weight one (in the domain of the base wta).
/// This returned run will answer succesfully to Run.fail().
Run<KeySIO>* failRun_one(const ParsingEnv& env) const;
/// @brief completion of this partial leaf key to be the head
/// of a nullary (leaf) transition augmenting tr.
/// Build and store in the given queue q
......@@ -166,9 +186,6 @@ public:
/// @brief all attributes of the key are valued
virtual bool complete() const;
/// @brief accessor
virtual size_t size() const;
/// @brief accessor
inline pre_t pre() const { return _pre; }
......@@ -232,6 +249,9 @@ protected:
/// if the second half contains no point.
bool _post_laston;
/// @brief accessor
virtual size_t size() const;
/// @brief weight for the case of a and tr terminal.
virtual Weight terminalWeight(label_t a,
const Transition& tr,
......
......@@ -133,6 +133,26 @@ _pre(head._pre)
}
Run<KeySIP>* KeySIP::failRun_zero(const ParsingEnv& env) const
{
assert(env.wta);
const Transition& t0 = env.dummyTransition_zero();
assert(t0.weight().zero());
label_t a = SymbLabel::make_fail(this->size());
return new Run<KeySIP>(t0, a, t0.weight());
}
Run<KeySIP>* KeySIP::failRun_one(const ParsingEnv& env) const
{
assert(env.wta);
const Transition& t1 = env.dummyTransition_one();
assert(t1.weight().one());
label_t a = SymbLabel::make_fail(this->size());
return new Run<KeySIP>(t1, a, t1.weight());
}
size_t KeySIP::size() const
{
assert(_interval);
......
......@@ -129,6 +129,26 @@ protected:
public:
/// allocate and return a special Run representing a parse failure for this key.
/// @param env parsing environment.
/// @return a pointer to a newly allocated fail run, with
/// - transition with dummy symbol, empty body, weight one in the
/// domain of the base wta in the passed environment.
/// - fail symbol
/// - weight zero (in the domain of the base wta).
/// This returned run will answer succesfully to Run.fail().
Run<KeySIP>* failRun_zero(const ParsingEnv& env) const;
/// allocate and return a special Run representing a parse failure for this key.
/// @param env parsing environment.
/// @return a pointer to a newly allocated fail run, with
/// - transition with dummy symbol, empty body, weight one in the
/// domain of the base wta in the passed environment.
/// - fail symbol
/// - weight one (in the domain of the base wta).
/// This returned run will answer succesfully to Run.fail().
Run<KeySIP>* failRun_one(const ParsingEnv& env) const;
/// @brief completion of this partial leaf key to be the head
/// of a nullary (leaf) transition augmenting tr.
/// Build and store in the given queue q
......@@ -142,16 +162,13 @@ public:
virtual void leaves(const Transition& tr,
const ParsingEnv& env,
std::queue<KeySIP>& q) const;
/// @brief Key assignement.
virtual KeySIP& operator= (const KeySIP& p);
/// @brief for use as key in a unordered_multimap.
virtual bool operator==(const KeySIP& p) const;
virtual bool operator!=(const KeySIP& p) const;
/// @brief return wether this Key is an instance of p.
/// = equality in this case because KeyS are always complete.
......@@ -161,9 +178,6 @@ public:
/// @brief all attributes of the key are valued
virtual bool complete() const;
/// @brief accessor
virtual size_t size() const;
/// @brief accessor
inline pre_t pre() const { return _pre; }
......@@ -179,6 +193,8 @@ protected:
pre_t _pre;
pre_t _post;
/// @brief accessor
virtual size_t size() const;
/// @brief weight for the case of a and tr terminal.
virtual Weight terminalWeight(label_t a,
......
......@@ -134,6 +134,26 @@ _pre(head._pre)
}
Run<KeySIR>* KeySIR::failRun_zero(const ParsingEnv& env) const
{
assert(env.wta);
const Transition& t0 = env.dummyTransition_zero();
assert(t0.weight().zero());
label_t a = SymbLabel::make_fail(this->size());
return new Run<KeySIR>(t0, a, t0.weight());
}
Run<KeySIR>* KeySIR::failRun_one(const ParsingEnv& env) const
{
assert(env.wta);
const Transition& t1 = env.dummyTransition_one();
assert(t1.weight().one());
label_t a = SymbLabel::make_fail(this->size());
return new Run<KeySIR>(t1, a, t1.weight());
}
size_t KeySIR::size() const
{
assert(_interval);
......
......@@ -132,6 +132,26 @@ protected:
public:
/// allocate and return a special Run representing a parse failure for this key.
/// @param env parsing environment.
/// @return a pointer to a newly allocated fail run, with
/// - transition with dummy symbol, empty body, weight one in the
/// domain of the base wta in the passed environment.
/// - fail symbol
/// - weight zero (in the domain of the base wta).
/// This returned run will answer succesfully to Run.fail().
Run<KeySIR>* failRun_zero(const ParsingEnv& env) const;
/// allocate and return a special Run representing a parse failure for this key.
/// @param env parsing environment.
/// @return a pointer to a newly allocated fail run, with
/// - transition with dummy symbol, empty body, weight one in the
/// domain of the base wta in the passed environment.
/// - fail symbol
/// - weight one (in the domain of the base wta).
/// This returned run will answer succesfully to Run.fail().
Run<KeySIR>* failRun_one(const ParsingEnv& env) const;
/// @brief completion of this partial leaf key to be the head
/// of a nullary (leaf) transition augmenting tr.
/// Build and store in the given queue q
......@@ -160,9 +180,6 @@ public:
/// @brief all attributes of the key are valued
virtual bool complete() const;
/// @brief accessor
virtual size_t size() const;
/// @brief accessor
inline pre_t pre() const { return _pre.first; }
......@@ -209,6 +226,9 @@ protected:
/// number of offset points in _post
// pre_t _post_off;
/// @brief accessor
virtual size_t size() const;
/// @brief weight for the case of a and tr terminal.
virtual Weight terminalWeight(label_t a,
const Transition& tr,
......
......@@ -136,9 +136,6 @@ public:
Run<KeySV>* failRun_one(const ParsingEnv& env) const;
// std::shared_ptr<Run<KeySV>> failRun_one(const ParsingEnv& env) const;
/// @brief accessor
virtual size_t size() const;
/// @brief number of leaf instances that can be obtained
/// from this key and the given args.
/// @param tr a SWTA transition, augmented by the transition partially
......@@ -246,6 +243,14 @@ protected:
// @brief constructor for internal use
// KeySV(state_t s, const ValueList& seg);
/// @brief accessor
virtual size_t size() const;
/// @brief number of points to read in the input segment
/// in order to make a transition to this Key state.
/// @todo RM : replaced by size()
virtual size_t points() const;
/// @brief weight for the case of a and tr inner.
/// @todo case zero redundant with filterInnerLabel ?
virtual Weight innerWeight(label_t a,
......@@ -297,11 +302,6 @@ protected:
virtual bool filterInnerTransition(const Transition& tr,
const ParsingEnv& env) const;
/// @brief number of points to read in the input segment
/// in order to make a transition to this Key state.
/// @todo RM : replaced by size()
virtual size_t points() const;
// @brief number of input point to read for transition from the given
// label symbol to this key.
// @param a a label. must be terminal.
......
......@@ -291,7 +291,7 @@ size_t TableMonoImporter::readTree(ScoringEnv& env,
// Preorder Traversal
// push top symbol to the tree stack of builder
size_t n = k.size();
size_t n = SymbLabel::nbEvents(a); // k.size();
// if (SymbLabel::terminal(a))
// n = k.pointsTerminalLabel(a, env);
......@@ -345,12 +345,14 @@ size_t TableMonoImporter::readTree(ScoringEnv& env,
// parse fail
else if (_unfailing) // skip this subrun and continue
{
label_t ai = ri->label();
/// @todo j should advance! wee need a run with a special symbol FAIL
/// containing number of events to skip
WARN("TableImporter[{}]: NULL subrun - unfailing mode", j);
/// @todo TBC only 1 staff for mono case?
int staff = 0;
j = readFail(multi, j, ki->size(), staff);
j = readFail(multi, j, SymbLabel::nbEvents(ai), staff);
}
else // fail when NULL subrun
{
......
Supports Markdown
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