Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
qparse
qparselib
Commits
d0fe2a42
Commit
d0fe2a42
authored
Jun 17, 2021
by
Florent Jacquemard
Browse files
bug initialization in KeySIO
parent
858113d1
Changes
12
Hide whitespace changes
Inline
Side-by-side
src/V2.2/targets/quant/squant2.2.cpp
View file @
d0fe2a42
//
// squanty.cpp
// qparse
// test new architecture Runey
//
test new architecture Runey
//
// Created by Florent Jacquemard on 29/03/2019.
// Copyright © 2019 Florent Jacquemard. All rights reserved.
...
...
src/parsing/KeyS.cpp
View file @
d0fe2a42
...
...
@@ -108,6 +108,8 @@ void KeyS::runs(std::stack<RunInner<KeyS>*>& si,
std
::
stack
<
std
::
pair
<
const
KeyS
*
,
RunTerm
*>>&
st
,
ParsingEnv
&
env
)
const
{
assert
(
si
.
empty
());
assert
(
st
.
empty
());
RunFactory
<
KeyS
>::
runs
(
*
this
,
si
,
st
,
env
);
}
...
...
src/parsing/KeyS.hpp
View file @
d0fe2a42
...
...
@@ -129,7 +129,7 @@ public:
virtual
bool
operator
==
(
const
KeyS
&
k
)
const
;
virtual
bool
operator
!=
(
const
KeyS
&
k
)
const
;
/// return wether this Key is an instance of
p
.
/// return wether this Key is an instance of
k
.
/// = equality in this case because KeyS are always complete.
virtual
bool
instance
(
const
KeyS
&
k
)
const
;
...
...
@@ -142,8 +142,8 @@ public:
/// accessor
inline
state_t
state
()
const
{
return
_state
;
}
/// @brief construct (augmented) runs targeting complete instances
of
/// this key.
/// @brief construct (augmented) runs targeting complete instances
///
of
this key.
/// @param si a stack to be filled with inner runs. must be empty.
/// @param st a stack to be filled with pairs containing terminal runs.
/// must be empty.
...
...
src/parsing/KeySI.cpp
View file @
d0fe2a42
...
...
@@ -43,14 +43,6 @@ _barlen(len)
KeySI
::
KeySI
(
const
KeySI
&
k
,
RunInner
<
KeySI
>&
r
,
const
ParsingEnv
&
env
)
:
KeyS
(
k
,
(
RunInner
<
KeyS
>&
)
r
,
env
),
_barlen
(
k
.
_barlen
)
// k is the parent (fs, ns) or matcher (instanciate)
{
init
(
k
,
r
,
env
);
}
void
KeySI
::
init
(
const
KeySI
&
k
,
RunInner
<
KeySI
>&
r
,
const
ParsingEnv
&
env
)
{
assert
(
r
.
inner
());
const
Transition
&
t
=
r
.
origin
();
...
...
@@ -70,10 +62,11 @@ void KeySI::init(const KeySI& k,
// instanciate head (inner case)
else
if
(
r
.
complete
())
{
assert
(
r
.
size
()
>
0
);
assert
(
r
.
size
()
==
t
.
size
());
assert
(
_state
==
k
.
_state
);
// check downcast of KeyS
assert
(
r
.
size
()
>
0
);
assert
(
r
.
key
(
r
.
size
()
-
1
));
// last sibling
// instanciate k with last key in r
init_instanciate
(
k
,
*
(
r
.
key
(
r
.
size
()
-
1
)),
t
,
env
);
}
// next sibling
...
...
@@ -180,8 +173,8 @@ void KeySI::init_instanciate(const KeySI& head,
{
assert
(
last
.
complete
());
_interval
=
head
.
_interval
;
//
nothing to do (h
ead is already complete
)
assert
(
this
->
complete
());
// ead is already complete
in the case of KeySI
//
assert(this->complete());
}
...
...
src/parsing/KeySI.hpp
View file @
d0fe2a42
...
...
@@ -127,14 +127,7 @@ protected:
/// @brief constructor for internal use
KeySI
(
state_t
s
,
IntervalTree
*
node
,
rtu_t
barlen
);
/// @param k target key for the run. can be partial.
/// @param r an inner run to be completed with the key initialized.
/// @param env input environment.
virtual
void
init
(
const
KeySI
&
k
,
RunInner
<
KeySI
>&
r
,
const
ParsingEnv
&
env
);
/// @param k parent of this key
/// @param t base wta transition to be augmented with the constructed key.
/// @param env parsing environment, contain an input segment,
...
...
src/parsing/KeySIO.cpp
View file @
d0fe2a42
...
...
@@ -42,7 +42,7 @@ _post_laston(post_laston)
{
}
// successor key (fs or ns or instance)
// successor key
in run
(fs or ns or instance)
KeySIO
::
KeySIO
(
const
KeySIO
&
k
,
RunInner
<
KeySIO
>&
r
,
const
ParsingEnv
&
env
)
:
...
...
@@ -54,7 +54,44 @@ _post(P_UNKNOWN),
_post_on
(
P_UNKNOWN
),
_post_laston
(
false
)
{
init
(
k
,
(
RunInner
<
KeySI
>&
)
r
,
env
);
// in KeySI
assert
(
r
.
inner
());
const
Transition
&
t
=
r
.
origin
();
assert
(
t
.
inner
());
assert
(
0
<
t
.
size
());
assert
(
t
.
size
()
<=
t
.
arity
());
// dispatch
// the asserts ALREADY in KeySI::KeySI
// first child, k is parent
if
(
r
.
empty
())
{
assert
(
r
.
partial
());
assert
(
_state
==
t
.
state
(
0
));
// check downcast of KeyS
init_firstchild
(
k
,
t
,
env
);
}
// instanciate k (inner case) with last key in r
else
if
(
r
.
complete
())
{
assert
(
r
.
size
()
==
t
.
size
());
assert
(
_state
==
k
.
_state
);
// check downcast of KeyS
const
KeySIO
*
last
=
r
.
key
(
r
.
size
()
-
1
);
// last sibling
assert
(
last
);
init_instanciate
(
k
,
*
last
,
t
,
env
);
}
// next sibling
else
{
assert
(
r
.
partial
());
size_t
i
=
r
.
size
();
// index of next sibling in r
assert
(
0
<
i
);
// there is at least one previous sibling
assert
(
i
<
t
.
size
());
// r partial
assert
(
_state
==
t
.
state
(
i
));
// check downcast of KeyS
const
KeySIO
*
last
=
r
.
key
(
i
-
1
);
// previous sibling
assert
(
last
);
init_nextsibling
(
k
,
*
last
,
t
,
i
,
env
);
}
}
...
...
@@ -121,19 +158,22 @@ void KeySIO::init_instanciate(const KeySIO& head,
assert
(
P_KNOWN
(
head
.
_pre
));
_pre
=
head
.
_pre
;
// copy
assert
(
P_KNOWN
(
head
.
_pre_on
));
_pre_on
=
head
.
_pre_on
;
_pre_laston
=
head
.
_pre_laston
;
assert
(
P_KNOWN
(
last
.
_post
));
_post
=
last
.
_post
;
// up-propagation of post
assert
(
P_KNOWN
(
last
.
_post_on
));
_post_on
=
last
.
_post_on
;
_post_laston
=
last
.
_post_laston
;
// this key is now complete
// assert(this->complete());
// this key is now complete
assert
(
P_KNOWN
(
this
->
_pre
));
assert
(
P_KNOWN
(
this
->
_pre_on
));
assert
(
P_KNOWN
(
this
->
_post
));
assert
(
P_KNOWN
(
this
->
_post_on
));
assert
(
this
->
complete
());
}
...
...
@@ -228,9 +268,12 @@ bool KeySIO::instance(const KeySIO& p) const
bool
KeySIO
::
complete
()
const
{
assert
(
_pre
!=
P_UNKNOWN
);
assert
(
_pre_on
!=
P_UNKNOWN
);
assert
((
_post
!=
P_UNKNOWN
)
||
(
_post_on
==
P_UNKNOWN
));
assert
((
_post_on
!=
P_UNKNOWN
)
||
(
_post
==
P_UNKNOWN
));
return
(
KeySI
::
complete
()
&&
(
_post
!=
P_UNKNOWN
));
return
(
KeySI
::
complete
()
&&
(
_post
!=
P_UNKNOWN
)
&&
(
_post_on
!=
P_UNKNOWN
));
}
...
...
@@ -294,8 +337,9 @@ void KeySIO::RunsTerminal(const Transition& t,
laston
(
env
));
// _post_laston
}
assert
(
knew
);
assert
(
P_KNOWN
(
knew
->
_post
));
assert
(
P_KNOWN
(
knew
->
_post_on
));
assert
(
knew
->
complete
());
//assert(P_KNOWN(knew->_post));
//assert(P_KNOWN(knew->_post_on));
/// no points in pre + left-half of interval
if
(
SymbLabel
::
continuation
(
a
)
||
SymbLabel
::
dot
(
a
))
...
...
@@ -304,7 +348,7 @@ void KeySIO::RunsTerminal(const Transition& t,
assert
(
_pre
!=
P_UNKNOWN
);
if
(
_pre
+
_interval
->
lsize
()
==
0
)
{
addTerminalRun
(
*
knew
,
0
,
t
,
st
,
env
);
// run with 0 points
knew
->
addTerminalRun
(
0
,
t
,
st
,
env
);
// run with 0 points
// 0 points to read in interval or
}
// otherwise : do not update stack
}
...
...
@@ -321,7 +365,7 @@ void KeySIO::RunsTerminal(const Transition& t,
// 1 offset in pre (and nothing in left-half of interval)
if
((
_pre
==
1
)
&&
(
_interval
->
lsize
()
==
0
)
&&
(
!
_pre_laston
))
{
addTerminalRun
(
*
knew
,
1
,
t
,
st
,
env
);
// 1 point to read in interval
knew
->
addTerminalRun
(
1
,
t
,
st
,
env
);
// 1 point to read in interval
}
// 1 offset in left-half of interval (and nothing in pre)
else
if
((
_pre
==
0
)
&&
(
_interval
->
lsize
()
==
1
))
...
...
@@ -330,7 +374,7 @@ void KeySIO::RunsTerminal(const Transition& t,
size_t
last
=
_interval
->
lfirst
();
assert
(
env
.
segment
);
if
(
env
.
segment
->
point
(
last
).
offset
())
addTerminalRun
(
*
knew
,
1
,
t
,
st
,
env
);
// 1 point to read
knew
->
addTerminalRun
(
1
,
t
,
st
,
env
);
// 1 point to read
}
// special case of performance beginning with a gap (not an event).
else
if
((
_pre
==
0
)
&&
...
...
@@ -339,7 +383,7 @@ void KeySIO::RunsTerminal(const Transition& t,
// (_interval->rbegin() == 0)
{
WARN
(
"KeySIR: first event in performance is not at 0, padding with a rest"
);
addTerminalRun
(
*
knew
,
0
,
t
,
st
,
env
);
// 0 point to read
knew
->
addTerminalRun
(
0
,
t
,
st
,
env
);
// 0 point to read
}
// otherwise : do not update stack
}
...
...
@@ -358,7 +402,7 @@ void KeySIO::RunsTerminal(const Transition& t,
// nb of g.n. + 1 note = nb of onsets
(
SymbLabel
::
nbEvents
(
a
)
==
_pre_on
))
{
addTerminalRun
(
*
knew
,
_pre
,
t
,
st
,
env
);
knew
->
addTerminalRun
(
_pre
,
t
,
st
,
env
);
// _pre points to read in interval (onsets and offsets)
}
}
...
...
@@ -376,7 +420,7 @@ void KeySIO::RunsTerminal(const Transition& t,
(
_pre_on
+
_interval
->
lonsets
())))
{
size_t
n
=
_pre
+
_interval
->
lsize
();
addTerminalRun
(
*
knew
,
n
,
t
,
st
,
env
);
knew
->
addTerminalRun
(
n
,
t
,
st
,
env
);
// (_pre + _interval->lsize()) points to read (onsets and offsets)
}
}
...
...
@@ -389,7 +433,7 @@ void KeySIO::RunsTerminal(const Transition& t,
// && (DBL_APPROX_EQUAL(_interval->rend(), _interval->rbegin()))
if
((
_interval
->
rduration
()
<
_barlen
)
&&
(
!
_interval
->
inhabited
()))
{
addTerminalRun
(
*
knew
,
0
,
t
,
st
,
env
);
knew
->
addTerminalRun
(
0
,
t
,
st
,
env
);
// 0 or -1 point to read in interval
}
// otherwise : do not update stack
}
...
...
@@ -404,17 +448,17 @@ void KeySIO::RunsTerminal(const Transition& t,
}
void
KeySIO
::
addTerminalRun
(
const
KeySIO
&
k
,
void
KeySIO
::
addTerminalRun
(
//
const KeySIO& k,
size_t
n
,
// nb points
const
Transition
&
t
,
std
::
stack
<
std
::
pair
<
const
KeySIO
*
,
RunTerm
*>>&
st
,
const
ParsingEnv
&
env
)
const
{
assert
(
k
.
complete
());
assert
(
this
->
complete
());
const
label_t
&
a
=
t
.
label
();
Weight
w
=
terminalWeight
(
a
,
t
,
env
);
assert
(
!
w
.
unknown
());
RunFactory
<
KeySIO
>::
terminalRun
(
k
,
t
,
a
,
w
,
n
,
st
);
RunFactory
<
KeySIO
>::
terminalRun
(
*
this
,
t
,
a
,
w
,
n
,
st
);
}
...
...
@@ -508,7 +552,7 @@ void KeySIO::RunsInner(const Transition& t,
std
::
stack
<
RunInner
<
KeySIO
>*>&
si
,
const
ParsingEnv
&
env
)
const
{
assert
(
State
::
isWTA
(
_state
));
//
assert(State::isWTA(_state));
const
label_t
&
a
=
t
.
label
();
assert
(
SymbLabel
::
inner
(
a
));
...
...
src/parsing/KeySIO.hpp
View file @
d0fe2a42
...
...
@@ -267,13 +267,14 @@ private:
/// add to the given stack one run built from the given transition,
/// the given number of points and an weight computed from the env.
/// @param k key the run is targeting. must be complete.
/// this key is the target of the run built. it must be complete.
// @param k key that the run is targeting. must be complete.
/// @param n number of points in interval for the run added
/// = grace-notes + grace-rests + 1 note or -1.
/// @param t transition to build terminal runs. must be terminal and complete.
/// @param st a stack to be filled with pairs containing terminal runs.
/// @param env parsing environment, contain an input segment,
void
addTerminalRun
(
const
KeySIO
&
k
,
void
addTerminalRun
(
//
const KeySIO& k,
size_t
n
,
// nb points
const
Transition
&
t
,
std
::
stack
<
std
::
pair
<
const
KeySIO
*
,
RunTerm
*>>&
st
,
...
...
src/parsing/KeySIP.cpp
View file @
d0fe2a42
...
...
@@ -59,42 +59,41 @@ KeySI(k, (RunInner<KeySI>&) r, env),
_pre
(
k
.
_pre
),
// k is the parent (fs, ns) or matcher (instanciate)
_post
(
k
.
_post
)
{
init
(
k
,
(
RunInner
<
KeySI
>&
)
r
,
env
);
// in KeySI
// assert(r.inner());
// const Transition& t = r.origin();
// assert(t.inner());
// assert(0 < t.size());
// assert(t.size() <= t.arity());
//
// // first child, k is parent
// if (r.empty())
// {
// assert(r.partial());
// assert(_state == t.state(0)); // check downcast of KeyS
// init_firstchild(k, t, env);
// }
// // instanciate head (inner case)
// else if (r.complete())
// {
// assert(r.size() == t.size());
// assert(_state == k._state); // check downcast of KeyS
// assert(r.size() > 0);
// const KeySIP* last = r.key(r.size()-1);
// assert(last);
// init_instanciate(k, *last, t, env);
// }
// // next sibling
// else
// {
// assert(r.partial());
// size_t i = r.size(); // index of next sibling in r
// assert(0 < i); // there is at least one previous sibling
// assert(i < t.size()); // r partial
// assert(_state == t.state(i)); // check downcast of KeyS
// const KeySIP* last = r.key(i-1);
// assert(last);
// init_nextsibling(k, *last, t, i, env);
// }
assert
(
r
.
inner
());
const
Transition
&
t
=
r
.
origin
();
assert
(
t
.
inner
());
assert
(
0
<
t
.
size
());
assert
(
t
.
size
()
<=
t
.
arity
());
// first child, k is parent
if
(
r
.
empty
())
{
assert
(
r
.
partial
());
assert
(
_state
==
t
.
state
(
0
));
// check downcast of KeyS
init_firstchild
(
k
,
t
,
env
);
}
// instanciate head (inner case)
else
if
(
r
.
complete
())
{
assert
(
r
.
size
()
==
t
.
size
());
assert
(
_state
==
k
.
_state
);
// check downcast of KeyS
assert
(
r
.
size
()
>
0
);
const
KeySIP
*
last
=
r
.
key
(
r
.
size
()
-
1
);
assert
(
last
);
init_instanciate
(
k
,
*
last
,
t
,
env
);
}
// next sibling
else
{
assert
(
r
.
partial
());
size_t
i
=
r
.
size
();
// index of next sibling in r
assert
(
0
<
i
);
// there is at least one previous sibling
assert
(
i
<
t
.
size
());
// r partial
assert
(
_state
==
t
.
state
(
i
));
// check downcast of KeyS
const
KeySIP
*
last
=
r
.
key
(
i
-
1
);
assert
(
last
);
init_nextsibling
(
k
,
*
last
,
t
,
i
,
env
);
}
}
void
KeySIP
::
init_firstchild
(
const
KeySIP
&
parent
,
...
...
src/parsing/RunFactory.hpp
View file @
d0fe2a42
...
...
@@ -26,7 +26,7 @@
namespace
parsing
{
/// methods for the generation of runs common to several key classes K.
/// methods for the generation of runs common to several key classes K
eyX
.
/// Every Run object represents an augmented transition built by extension of
/// - a transitios of a base WTA, for the parsing inside a bar, or
/// - a generic transition for parsing over the bars, built in this factory.
...
...
@@ -43,7 +43,7 @@ namespace parsing{
/// mk B0
/// ```
/// where B0, B2 are nullary (final) and binary bar symbols
/// and m1,...,mk are the parse tree for measures 1 to k.
/// and m1,...,mk are the parse tree
s
for measures 1 to k.
template
<
class
K
>
class
RunFactory
{
...
...
@@ -52,8 +52,8 @@ public:
// RunFactory(const K& k);
/// @brief construct runs targeting complete instances of
///
this key
.
/// @brief construct runs targeting complete instances of
given key.
///
@param k target key of the run
.
/// @param si a stack to be filled with inner runs. must be empty.
/// @param st a stack to be filled with pairs containing terminal runs.
/// must be empty.
...
...
src/parsing/RunFactory.tpp
View file @
d0fe2a42
...
...
@@ -76,7 +76,7 @@ void RunFactory<K>::runsBar(const K& k,
std
::
stack
<
std
::
pair
<
const
K
*
,
RunTerm
*>>&
st
,
ParsingEnv
&
env
)
{
assert
(
k
.
complete
());
//
assert(k.complete());
assert
(
State
::
isMeta
(
k
.
state
()));
// create final bar nullary transition. it is added to the env pool.
const
Transition
&
t0
=
barTransition
(
k
.
state
(),
0
,
env
);
...
...
@@ -112,7 +112,7 @@ void RunFactory<K>::terminalRun(const K& k,
}
RunTerm
*
r
=
new
RunTerm
(
t
,
a
,
w
,
len
);
TRACE
(
"NEW terminal run {} -> {} for {}"
,
*
r
,
k
,
t
);
st
.
push
(
std
::
make_pair
(
&
k
,
r
));
//
this
key is complete
st
.
push
(
std
::
make_pair
(
&
k
,
r
));
// key
k
is complete
}
...
...
src/parsing/TableParse.hpp
View file @
d0fe2a42
...
...
@@ -97,6 +97,7 @@ private: // data
//
// RunCompare _comparer;
/// main table
MapRecord
<
K
,
R
,
H
>
_table
;
/// associate to every registered partial key k
...
...
src/parsing/TableParse.tpp
View file @
d0fe2a42
...
...
@@ -810,8 +810,14 @@ typename MapRecord<K,R,H>::iterator TableParse<K,R,H>::addemplace(const K& k,
// init with components of the entry in table
if
(
newrec
)
{
const
K
&
key
=
pret
.
first
->
first
;
assert
(
key
.
complete
());
initRecord
(
&
(
pret
.
first
->
first
),
&
(
pret
.
first
->
second
));
}
else
{
ERROR
(
"Table.addemplace: key {} already in table"
,
k
);
}
return
pret
.
first
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment