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
0453dd96
Commit
0453dd96
authored
Mar 30, 2021
by
Florent Jacquemard
Browse files
class Run is no more a template
parent
c448d43e
Changes
27
Hide whitespace changes
Inline
Side-by-side
qparse.xcodeproj/project.pbxproj
View file @
0453dd96
...
...
@@ -214,6 +214,8 @@
430972A2206020AF001F7688
/* MeterSig.cpp in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
430972A1206020AE001F7688
/* MeterSig.cpp */
;
};
4309FF4D24388C3F00A5E402
/* MeasureStacked.cpp in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
4309FF4B24388C3F00A5E402
/* MeasureStacked.cpp */
;
};
4309FF502438BC4D00A5E402
/* Sequence.cpp in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
4309FF4E2438BC4D00A5E402
/* Sequence.cpp */
;
};
4313D8D12613102500702519
/* Runey.cpp in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
43C573C8224D2FD3003FA990
/* Runey.cpp */
;
};
4313D8DE2613231800702519
/* RunCompare.cpp in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
4313D8DD2613231800702519
/* RunCompare.cpp */
;
};
4315C86C22F9D091003F66AF
/* TestRuney.cpp in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
4315C86B22F9D091003F66AF
/* TestRuney.cpp */
;
};
4315C86D22F9D70C003F66AF
/* ParsingEnv.cpp in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
437FA6F722F97709003974DC
/* ParsingEnv.cpp */
;
};
4315C86E22F9D70C003F66AF
/* Ranked.cpp in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
43552ED322A6ADA800C557BA
/* Ranked.cpp */
;
};
...
...
@@ -1112,6 +1114,7 @@
430B4FA91FE089A600496F73
/* Record.hpp */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.cpp.h
;
path
=
Record.hpp
;
sourceTree
=
"<group>"
;
};
43101555229C22AB00DFEFFB
/* Symbol.cpp */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.cpp.cpp
;
name
=
Symbol.cpp
;
path
=
../V1/schemata/Symbol.cpp
;
sourceTree
=
"<group>"
;
};
43101556229C22AB00DFEFFB
/* Symbol.hpp */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.cpp.h
;
name
=
Symbol.hpp
;
path
=
src/V1/schemata/Symbol.hpp
;
sourceTree
=
SOURCE_ROOT
;
};
4313D8DD2613231800702519
/* RunCompare.cpp */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.cpp.cpp
;
path
=
RunCompare.cpp
;
sourceTree
=
"<group>"
;
};
4315C86B22F9D091003F66AF
/* TestRuney.cpp */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.cpp.cpp
;
path
=
TestRuney.cpp
;
sourceTree
=
"<group>"
;
};
4315C87122FAD583003F66AF
/* RecordOne.tpp */
=
{
isa
=
PBXFileReference
;
explicitFileType
=
sourcecode.cpp.cpp
;
path
=
RecordOne.tpp
;
sourceTree
=
"<group>"
;
xcLanguageSpecificationIdentifier
=
xcode.lang.cpp
;
};
4315C87222FAD583003F66AF
/* RecordOne.hpp */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.cpp.h
;
path
=
RecordOne.hpp
;
sourceTree
=
"<group>"
;
};
...
...
@@ -1457,7 +1460,7 @@
43C0E60E1F696B020011E1BA
/* main.cpp */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.cpp.cpp
;
path
=
main.cpp
;
sourceTree
=
"<group>"
;
};
43C453D423D758DB00E49691
/* GaussianDistance.cpp */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.cpp.cpp
;
path
=
GaussianDistance.cpp
;
sourceTree
=
"<group>"
;
};
43C453D523D758DB00E49691
/* GaussianDistance.hpp */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.cpp.h
;
path
=
GaussianDistance.hpp
;
sourceTree
=
"<group>"
;
};
43C573C8224D2FD3003FA990
/* Runey.
t
pp */
=
{
isa
=
PBXFileReference
;
explicitFileType
=
sourcecode.cpp.cpp
;
path
=
Runey.
t
pp
;
sourceTree
=
"<group>"
;
xcLanguageSpecificationIdentifier
=
xcode.lang.cpp
;
};
43C573C8224D2FD3003FA990
/* Runey.
c
pp */
=
{
isa
=
PBXFileReference
;
explicitFileType
=
sourcecode.cpp.cpp
;
path
=
Runey.
c
pp
;
sourceTree
=
"<group>"
;
xcLanguageSpecificationIdentifier
=
xcode.lang.cpp
;
};
43C67A3125879A2B00FE7724
/* Ambitus.cpp */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.cpp.cpp
;
path
=
Ambitus.cpp
;
sourceTree
=
"<group>"
;
};
43C67A3225879A2C00FE7724
/* Ambitus.hpp */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.cpp.h
;
path
=
Ambitus.hpp
;
sourceTree
=
"<group>"
;
};
43C692A22368A4CE0063ABAE
/* KeySIP.cpp */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.cpp.cpp
;
path
=
KeySIP.cpp
;
sourceTree
=
"<group>"
;
};
...
...
@@ -2226,7 +2229,7 @@
439EA0BB224CCF91006E742E
/* RunFilter.hpp */
,
439EA0BA224CCF91006E742E
/* RunFilter.cpp */
,
43EEB0A5224ACC56002A91E7
/* Runey.hpp */
,
43C573C8224D2FD3003FA990
/* Runey.
t
pp */
,
43C573C8224D2FD3003FA990
/* Runey.
c
pp */
,
430046E52604CF3F000E9898
/* RunTerm.hpp */
,
430046E42604CF3F000E9898
/* RunTerm.tpp */
,
430046F22604CF97000E9898
/* RunInner.hpp */
,
...
...
@@ -2234,6 +2237,7 @@
434F406422FB198300C3940E
/* RunRanked.hpp */
,
434F406322FB198300C3940E
/* RunRanked.tpp */
,
431864B123099B5900940ECB
/* RunCompare.hpp */
,
4313D8DD2613231800702519
/* RunCompare.cpp */
,
4315C87522FAD873003F66AF
/* Recordey.hpp */
,
4315C87422FAD873003F66AF
/* Recordey.tpp */
,
4315C87222FAD583003F66AF
/* RecordOne.hpp */
,
...
...
@@ -3248,6 +3252,7 @@
buildActionMask
=
2147483647
;
files
=
(
438686BB2339FAAC005A7C64
/* Binasc.cpp in Sources */
,
4313D8D12613102500702519
/* Runey.cpp in Sources */
,
438686C02339FAAC005A7C64
/* Options.cpp in Sources */
,
438686BC2339FAAC005A7C64
/* MidiEvent.cpp in Sources */
,
438686BD2339FAAC005A7C64
/* MidiEventList.cpp in Sources */
,
...
...
@@ -3401,6 +3406,7 @@
435B1D68256DA6B600927C77
/* SMPrinter.cpp in Sources */
,
432D3F7C257CF35A009B2363
/* SMMEI.cpp in Sources */
,
43AE7B1325C8101A00BE80C3
/* RewriteStaccato.cpp in Sources */
,
4313D8DE2613231800702519
/* RunCompare.cpp in Sources */
,
43552EBE22A69BAF00C557BA
/* Spiral.cpp in Sources */
,
4396086E25DC4CE40058E46A
/* PSshortest.cpp in Sources */
,
4348EA4025DA77C60037B9BC
/* PSConfig.cpp in Sources */
,
...
...
src/parsing/Key.hpp
View file @
0453dd96
...
...
@@ -258,7 +258,7 @@ public:
/// @param env parsing environment.
/// @return a pointer to a newly allocated fail run, with fail symbol.
/// This returned run will answer succesfully to Run.fail().
Run
<
K
>
*
failRun
(
const
ParsingEnv
&
env
)
const
;
Run
*
failRun
(
const
ParsingEnv
&
env
)
const
;
/// @brief time interval represented by this key,
/// or NULL if there is none.
...
...
src/parsing/Key.tpp
View file @
0453dd96
...
...
@@ -77,13 +77,13 @@ void Key<K>::leaves(const Transition& tr,
template
<
class
K
>
Run
<
K
>
*
Key
<
K
>::
failRun
(
const
ParsingEnv
&
env
)
const
Run
*
Key
<
K
>::
failRun
(
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
());
return
new
Run
Term
(
t1
,
a
,
t1
.
weight
());
}
...
...
src/parsing/RecordOne.hpp
View file @
0453dd96
...
...
@@ -32,7 +32,7 @@ public:
/// @param failrun fixed run returned by best when there is no best run.
/// @warning the key associated to the record must
/// be set later to a non-NULL ptr with setKey.
RecordOne
(
RunCompare
<
K
>
comp
,
const
Run
<
K
>*
failrun
);
RecordOne
(
RunCompare
comp
,
const
Run
Term
<
K
>*
failrun
);
/// deleting a RecordOne frees the best run contained.
virtual
~
RecordOne
();
...
...
@@ -41,13 +41,13 @@ public:
/// @param r candidate run to add.
/// @warning the key of this record must be set.
/// @warning if r is not added, it is deleted.
virtual
size_t
add
(
const
Run
<
K
>
*
r
);
virtual
size_t
add
(
const
Run
*
r
);
/// @brief returns the 1-th best run of the record.
/// @param n rank, must be 1 for RecordOne.
/// @return the n-th best run of the record or, if there is none,
/// the failRun set or NULL when the failRun was not set with setFailRun.
virtual
const
Run
<
K
>
*
best
(
size_t
n
=
1
);
virtual
const
Run
*
best
(
size_t
n
=
1
);
//virtual Run<K>* best(TableParse<K,Record<K,H>,H>* table, size_t n=1);
virtual
bool
empty
()
const
;
...
...
@@ -55,7 +55,7 @@ public:
protected:
/// best run for the associated state.
const
Run
<
K
>
*
_best
;
const
Run
*
_best
;
};
...
...
src/parsing/RecordOne.tpp
View file @
0453dd96
...
...
@@ -10,7 +10,7 @@
namespace
Parsing
{
template
<
class
K
>
RecordOne
<
K
>::
RecordOne
(
RunCompare
<
K
>
comp
,
const
Run
<
K
>*
failrun
)
:
RecordOne
<
K
>::
RecordOne
(
RunCompare
comp
,
const
Run
Term
<
K
>*
failrun
)
:
Record
<
K
>
(
comp
,
failrun
),
// base class constructor with parameter
_best
(
nullptr
)
// initialize with worst run
{
}
...
...
@@ -35,9 +35,9 @@ RecordOne<K>::~RecordOne()
}
//Run
<K>
* RecordOne<K>::best(TableParse<K,Record<K,H>,H>* table, size_t n)
//Run* RecordOne<K>::best(TableParse<K,Record<K,H>,H>* table, size_t n)
template
<
class
K
>
const
Run
<
K
>
*
RecordOne
<
K
>::
best
(
size_t
n
)
const
Run
*
RecordOne
<
K
>::
best
(
size_t
n
)
{
assert
(
n
==
1
);
assert
((
_best
==
nullptr
)
||
_best
->
complete
());
...
...
@@ -50,7 +50,7 @@ const Run<K>* RecordOne<K>::best(size_t n)
if
(
_best
==
nullptr
)
{
TRACE
(
"RecordOne[{}].best : no best run"
,
*
key
);
const
Run
<
K
>
*
fail
=
this
->
_fail
;
const
Run
*
fail
=
this
->
_fail
;
assert
((
fail
==
nullptr
)
||
fail
->
fail
());
if
(
fail
==
nullptr
)
...
...
@@ -74,7 +74,7 @@ const Run<K>* RecordOne<K>::best(size_t n)
template
<
class
K
>
size_t
RecordOne
<
K
>::
add
(
const
Run
<
K
>
*
r
)
size_t
RecordOne
<
K
>::
add
(
const
Run
*
r
)
{
assert
(
this
->
_key
);
const
K
&
thiskey
=
*
(
this
->
_key
);
...
...
src/parsing/RecordQueue.hpp
View file @
0453dd96
...
...
@@ -30,7 +30,7 @@ public:
/// @param failrun fixed run returned by best when there is no best run.
/// @warning the key associated to the record must
/// be set later to a non NULL ptr with initKey.
RecordQueue
(
RunCompare
<
K
>
comp
,
const
Run
<
K
>*
failrun
);
RecordQueue
(
RunCompare
comp
,
const
Run
Term
<
K
>*
failrun
);
/// deleting a RecordQueue frees all runs contained
/// in the candidate queue and the best list.
...
...
@@ -41,7 +41,7 @@ public:
/// r is ignored (not added) if it is NULL,
/// its weight is unknown, or zero. @see Record::valid
/// @warning ignored runs are deleted.
virtual
size_t
add
(
const
Run
<
K
>
*
r
);
virtual
size_t
add
(
const
Run
*
r
);
/// @brief n-th best run of the record.
/// @param n (as in n-best) is the rank of the run
...
...
@@ -52,7 +52,7 @@ public:
/// If less than k best can be constructed (table is complete),
/// return a fail run or NULL run (weight unknown),
/// otherwise, the weight of the returned run is known.
virtual
const
Run
<
K
>
*
best
(
size_t
n
=
1
);
virtual
const
Run
*
best
(
size_t
n
=
1
);
virtual
bool
empty
()
const
;
...
...
@@ -63,7 +63,7 @@ protected:
/// it is empty iff no more k-best can be added
std
::
priority_queue
<
RunRanked
<
K
>*
,
std
::
vector
<
RunRanked
<
K
>*>
,
RunCompare
<
K
>
>
_cand
;
RunCompare
>
_cand
;
/// ordered list of best runs for the associated state.
std
::
vector
<
RunRanked
<
K
>*>
_best
;
...
...
@@ -96,12 +96,12 @@ protected:
/// @return the n-th best run.
/// @param n index of wanted best run. must be between 1 and
/// the number of best runs computed (@see bestSize()).
Run
<
K
>
*
getBest
(
size_t
n
);
Run
*
getBest
(
size_t
n
);
/// @brief number of best runs computed.
size_t
sizeBest
()
const
;
// bool bestFilter(const Run
<K>
* r);
// bool bestFilter(const Run* r);
/// add the candidates following Run r (lexico order for ranks)
/// to the heap of candidates.
...
...
src/parsing/RecordQueue.tpp
View file @
0453dd96
...
...
@@ -11,7 +11,7 @@ namespace Parsing{
template
<
class
K
>
RecordQueue
<
K
>::
RecordQueue
(
RunCompare
<
K
>
comp
,
const
Run
<
K
>*
failrun
)
:
RecordQueue
<
K
>::
RecordQueue
(
RunCompare
comp
,
const
Run
Term
<
K
>*
failrun
)
:
Record
<
K
>
(
comp
,
failrun
),
// base class constructor with parameter
_cand
(
comp
),
// empty candidate list
_best
()
// empty best list
...
...
@@ -31,17 +31,17 @@ RecordQueue<K>::~RecordQueue()
while
(
!
_cand
.
empty
())
{
Run
<
K
>
*
r
=
_cand
.
top
();
Run
*
r
=
_cand
.
top
();
_cand
.
pop
();
assert
(
r
);
delete
r
;
}
// no clear() for priority_queues
_cand
=
std
::
priority_queue
<
RunRanked
<
K
>*
,
std
::
vector
<
RunRanked
<
K
>*>
,
RunCompare
<
K
>
>
();
_cand
=
std
::
priority_queue
<
RunRanked
<
K
>*
,
std
::
vector
<
RunRanked
<
K
>*>
,
RunCompare
>
();
// std::priority_queue<RunRanked<K>*,
// vector<RunRanked<K>*>,
// std::function<bool(const Run
<K>
*, const Run
<K>
*)>>().swap(_cand);
// std::function<bool(const Run*, const Run*)>>().swap(_cand);
// deallocate all runs in the _best list
if
(
this
->
_key
)
...
...
@@ -69,7 +69,7 @@ bool RecordQueue<K>::empty() const
template
<
class
K
>
const
Run
<
K
>
*
RecordQueue
<
K
>::
best
(
size_t
n
)
const
Run
*
RecordQueue
<
K
>::
best
(
size_t
n
)
{
assert
(
n
>
0
);
const
K
*
key
=
this
->
_key
;
...
...
@@ -87,7 +87,7 @@ const Run<K>* RecordQueue<K>::best(size_t n)
if
(
emptyCand
())
{
TRACE
(
"RecordQueue[{}]: no best {}"
,
*
key
,
n
);
const
Run
<
K
>
*
fail
=
this
->
_fail
;
const
Run
*
fail
=
this
->
_fail
;
assert
((
fail
==
nullptr
)
||
fail
->
fail
());
// return a fail Run
...
...
@@ -165,7 +165,7 @@ const Run<K>* RecordQueue<K>::best(size_t n)
// external add
template
<
class
K
>
size_t
RecordQueue
<
K
>::
add
(
const
Run
<
K
>
*
r
)
size_t
RecordQueue
<
K
>::
add
(
const
Run
*
r
)
{
assert
(
this
->
_key
);
const
K
&
thiskey
=
*
(
this
->
_key
);
...
...
@@ -280,11 +280,11 @@ void RecordQueue<K>::addBest(RunRanked<K>* r)
template
<
class
K
>
Run
<
K
>
*
RecordQueue
<
K
>::
getBest
(
size_t
n
)
Run
*
RecordQueue
<
K
>::
getBest
(
size_t
n
)
{
assert
(
n
>
0
);
assert
(
_best
.
size
()
>=
n
);
Run
<
K
>
*
best
=
_best
[
n
-
1
];
Run
*
best
=
_best
[
n
-
1
];
assert
(
best
);
assert
(
best
->
complete
());
assert
(
!
best
->
weight
().
unknown
());
...
...
@@ -301,7 +301,7 @@ size_t RecordQueue<K>::sizeBest() const
// template<class K>
// bool RecordQueue<K>::bestFilter(const Run
<K>
* r)
// bool RecordQueue<K>::bestFilter(const Run* r)
// {
// assert (r);
// assert(r->inner() || r->terminal());
...
...
src/parsing/Recordey.hpp
View file @
0453dd96
...
...
@@ -16,6 +16,7 @@
#include "trace.hpp"
#include "Runey.hpp"
#include "RunTerm.hpp"
#include "RunCompare.hpp"
...
...
@@ -53,12 +54,12 @@ public:
/// @todo delete failrun if not necessary (replaced by method)
/// @warning the key associated to the record must
/// be set later to a non-NULL ptr with setKey.
Record
(
RunCompare
<
K
>
comp
,
const
Run
<
K
>*
failrun
);
Record
(
RunCompare
comp
,
const
Run
Term
<
K
>*
failrun
);
virtual
~
Record
();
/// @brief add a run to the record.
virtual
size_t
add
(
const
Run
<
K
>
*
r
)
=
0
;
virtual
size_t
add
(
const
Run
*
r
)
=
0
;
/// @brief n-th best run of the record.
// @param table may be completed with new runs (lazy evaluation of candidates).
...
...
@@ -66,8 +67,8 @@ public:
/// @return the n-th best run of the record or, if there is none,
/// the failRun set or NULL when the failRun was not set with setFailRun.
/// @warning the record can be modified.
virtual
const
Run
<
K
>
*
best
(
size_t
n
=
1
)
=
0
;
// virtual Run
<K>
* best(TableI<K>* table, size_t n=1) = 0;
virtual
const
Run
*
best
(
size_t
n
=
1
)
=
0
;
// virtual Run* best(TableI<K>* table, size_t n=1) = 0;
/// @brief key associated to the record.
inline
const
K
*
key
()
const
{
return
_key
;
}
...
...
@@ -81,7 +82,7 @@ public:
/// @brief set the fail Run associated to the record.
/// @param r the fail run to be set.
/// @warning the current fail Run of this record must be NULL.
void
setFailRun
(
const
Run
<
K
>*
r
);
void
setFailRun
(
const
Run
Term
<
K
>*
r
);
/// at least one run has been added succesfully.
virtual
bool
empty
()
const
=
0
;
...
...
@@ -105,14 +106,14 @@ protected:
const
K
*
_key
;
/// comparison function.
RunCompare
<
K
>
_comp
;
RunCompare
_comp
;
/// generic fail run associated to the key.
/// will be returned in case of parse failure.
/// @todo delete if not necessary
const
Run
<
K
>*
_fail
;
const
Run
Term
<
K
>*
_fail
;
/// @todo shared_ptr
// std::shared_ptr<Run
<K>
> _fail;
// std::shared_ptr<Run> _fail;
/// stats: number of candidate bests constructed.
size_t
_nb_cand
;
...
...
@@ -127,11 +128,11 @@ protected:
/// - ptr to Run with unknown weight (i.e. weight with NULL letter).
/// - ptr to Run with weight == zero (acc. to test zero()).
/// a Run not in these 3 cases is called valid.
bool
valid
(
const
Run
<
K
>
*
);
bool
valid
(
const
Run
*
);
// Fail run associated with the key.
// will be returned in case of parse failure.
// const Run
<K>
* fail() const;
// const Run* fail() const;
};
...
...
src/parsing/Recordey.tpp
View file @
0453dd96
...
...
@@ -14,7 +14,7 @@ namespace Parsing{
template
<
class
K
>
Record
<
K
>::
Record
(
RunCompare
<
K
>
comp
,
const
Run
<
K
>*
failrun
)
:
Record
<
K
>::
Record
(
RunCompare
comp
,
const
Run
Term
<
K
>*
failrun
)
:
_key
(
nullptr
),
_comp
(
comp
),
_fail
(
failrun
),
...
...
@@ -49,17 +49,17 @@ void Record<K>::setKey(const K* k)
template
<
class
K
>
void
Record
<
K
>::
setFailRun
(
const
Run
<
K
>*
r
)
void
Record
<
K
>::
setFailRun
(
const
Run
Term
<
K
>*
r
)
{
assert
(
r
);
assert
(
_fail
==
nullptr
);
// set only once
_fail
=
r
;
//_fail = std::shared_ptr<Run
<K>
>(r);
//_fail = std::shared_ptr<Run>(r);
}
template
<
class
K
>
bool
Record
<
K
>::
valid
(
const
Run
<
K
>
*
r
)
bool
Record
<
K
>::
valid
(
const
Run
*
r
)
{
const
K
&
thiskey
=
*
(
this
->
_key
);
...
...
src/parsing/RunCompare.hpp
View file @
0453dd96
...
...
@@ -17,63 +17,29 @@
#include "trace.hpp"
#include "Weight.hpp"
//
#include "Runey.hpp"
#include "Runey.hpp"
namespace
Parsing
{
/// orderings for ordered containers
/// used in k-best procedures.
template
<
class
K
>
using
RunCompare
=
std
::
function
<
bool
(
const
Run
<
K
>
*
,
const
Run
<
K
>
*
)
>
;
using
RunCompare
=
std
::
function
<
bool
(
const
Run
*
,
const
Run
*
)
>
;
/// one ordering for k-best to rank Runs
/// weightMax is one ordering for k-best to rank Runs
/// from best weight to worse weight,
/// where partial run or run with unknown weight
/// is considered to be the best
/// (highest priority for unevaluated candidates)
template
<
class
K
>
RunCompare
<
K
>
weightMax
=
[](
const
Run
<
K
>*
lhs
,
const
Run
<
K
>*
rhs
)
{
assert
(
lhs
);
assert
(
rhs
);
assert
(
lhs
->
complete
());
assert
(
rhs
->
complete
());
return
(
lhs
->
weight
()
<
rhs
->
weight
());
// if (rhs->partial() || rhs->weight().unknown())
// return false;
// else if (lhs->partial() || lhs->weight().unknown())
// return true;
// else
// return (lhs->weight() > rhs->weight());
};
//RunCompare weightMax;
/// one ordering for k-best to rank Runs
/// weightMin is one ordering for k-best to rank Runs
/// from worse weight to best weight,
/// where partial runs and runs with unknown weight
/// is considered to be the worst.
/// (highest priority for unevaluated candidates)
template
<
class
K
>
RunCompare
<
K
>
weightMin
=
[](
const
Run
<
K
>*
lhs
,
const
Run
<
K
>*
rhs
)
{
assert
(
lhs
);
assert
(
rhs
);
assert
(
lhs
->
complete
());
assert
(
rhs
->
complete
());
return
(
lhs
->
weight
()
>
rhs
->
weight
());
// if (lhs->partial() || lhs->weight().unknown())
// return false;
// // if rhs == 0 then lhs == rhs
// // if rhs > 0 then lhs > rhs;
// else if (rhs->partial() || rhs->weight().unknown())
// return true;
// else
// return (lhs->weight() < rhs->weight());
};
//RunCompare weightMin;
}
// end namespace
...
...
src/parsing/RunInner.hpp
View file @
0453dd96
...
...
@@ -21,7 +21,7 @@
#include "Weight.hpp"
#include "Transition.hpp"
#include "Runey.hpp"
#include "Recordey.hpp"
namespace
Parsing
{
...
...
@@ -29,16 +29,15 @@ namespace Parsing{
template
<
class
K
>
class
RunInner
;
template
<
class
K
>
std
::
ostream
&
operator
<<
(
std
::
ostream
&
o
,
const
RunInner
<
K
>&
r
);
//template<class K>
//std::ostream& operator<<(std::ostream& o, const RunInner<K>& r);
/// An inner run is a particular case of run with at least one subrun.
/// An inner run is complete when the length of the list of children is the arity.
/// It is partial otherwise.
/// param K = class of Key in parse table
template
<
class
K
>
class
RunInner
:
public
Run
<
K
>
class
RunInner
:
public
Run
{
public:
...
...
@@ -79,7 +78,7 @@ public:
/// - add rec at the end of children list.
/// - multiply current weight by the weight of best.
/// - update current filter with the filter of best.
RunInner
(
const
RunInner
<
K
>&
r
,
Record
<
K
>*
rec
,
const
Run
<
K
>
*
best
);
RunInner
(
const
RunInner
<
K
>&
r
,
Record
<
K
>*
rec
,
const
Run
*
best
);
/// destructor
virtual
~
RunInner
();
...
...
@@ -106,7 +105,7 @@ public:
/// @param i the index of the subrun, between 0 and size()-1.
/// @return the ith subrun or NULL if there is none.
/// @warning this run must be complete.
const
Run
<
K
>
*
subrun
(
size_t
i
)
const
;
const
Run
*
subrun
(
size_t
i
)
const
;
/// return the ith key of this run.
/// @param i index of subrun, must be between 0 and run size - 1.
...
...
@@ -122,7 +121,7 @@ protected:
/// [opt] data for optimization.
/// backup of the best runs used for construction.
/// @todo TBR. not used.
typename
std
::
vector
<
const
Run
<
K
>
*>
_subruns
;
typename
std
::
vector
<
const
Run
*>
_subruns
;
/// @param i the index of the subrun, between 0 and arity-1.
/// @param n the rank for n-best.
...
...
@@ -130,7 +129,7 @@ protected:
/// must be larger or equal to 1 for ranked runs.
/// @return the ith subrun or NULL if there is none.
/// @warning this run must be complete.
const
Run
<
K
>
*
subrun
(
size_t
i
,
size_t
n
)
const
;
const
Run
*
subrun
(
size_t
i
,
size_t
n
)
const
;
// return the ith record of this run.
// @param i index of subrun, between 0 and arity-1.
...
...
@@ -142,7 +141,7 @@ private:
/// with the weight of the given best subrun.
/// @param rec record added as new subrun. must not be NULL and have a key.
/// @param best subrun to add. must not be NULL.
void
init_best
(
Record
<
K
>*
rec
,
const
Run
<
K
>
*
best
);
void
init_best
(
Record
<
K
>*
rec
,
const
Run
*
best
);
};
...
...
src/parsing/RunInner.tpp
View file @
0453dd96
...
...
@@ -11,7 +11,7 @@ namespace Parsing{
template
<
class
K
>
RunInner
<
K
>::
RunInner
(
const
Transition
&
tr
)
:
Run
<
K
>
(
tr
),
Run
(
tr
),
_children
(),
// no children yet
_subruns
()
// [opt]
{
...
...
@@ -22,7 +22,7 @@ _subruns() // [opt]
template
<
class
K
>
RunInner
<
K
>::
RunInner
(
const
Transition
&
tr
,
label_t
a
,
const
Weight
&
w
)
:
Run
<
K
>
::
Run
(
tr
,
a
,
w
),
Run
::
Run
(
tr
,
a
,
w
),
_children
(),
// no children yet
_subruns
()
// [opt]
{
...
...
@@ -36,7 +36,7 @@ _subruns() // [opt]
// copy
template
<
class
K
>
RunInner
<
K
>::
RunInner
(
const
RunInner
<
K
>&
r
)
:
Run
<
K
>
(
r
),
Run
(
r
),
_children
(
r
.
_children
),
// copy
_subruns
(
r
.
_subruns
)
// [opt]
{
...
...
@@ -50,14 +50,14 @@ RunInner<K>::RunInner(const RunInner<K>& r, Record<K>* rec):
RunInner
<
K
>
(
r
)
// copy
{
assert
(
rec
);
const
Run
<
K
>
*
best
=
rec
->
best
(
1
);
const
Run
*
best
=
rec
->
best
(
1
);
init_best
(
r
,
rec
,
best
);
}
// copy/update
template
<
class
K
>
RunInner
<
K
>::
RunInner
(
const
RunInner
<
K
>&
r
,
Record
<
K
>*
rec
,
const
Run
<
K
>
*
best
)
:
RunInner
<
K
>::
RunInner
(
const
RunInner
<
K
>&
r
,
Record
<
K
>*
rec
,
const
Run
*
best
)
:
RunInner
<
K
>
(
r
)
// copy
{
assert
(
rec
);
...
...
@@ -66,7 +66,7 @@ RunInner<K>(r) // copy
template
<
class
K
>
void
RunInner
<
K
>::
init_best
(
Record
<
K
>*
rec
,
const
Run
<
K
>
*
best
)
void
RunInner
<
K
>::
init_best
(
Record
<
K
>*
rec
,
const
Run
*
best
)
{
assert
(
this
->
partial
());
assert
(
this
->
inner
());
...
...
@@ -81,7 +81,7 @@ void RunInner<K>::init_best(Record<K>* rec, const Run<K>* best)
// const Transition& tr = this->_origin;
assert
(
best
!=
nullptr
);
assert
(
best
->
complete
());
this
->
_
filter
.
u
pdate
(
best
->
_
filter
);
// handles the case of FAIL subrun
filter
U
pdate
(
best
->
filter
()
);
// handles the case of FAIL subrun
if
(
best
->
fail
())
{
// ignore weight of FAIL run
...
...
@@ -114,7 +114,7 @@ RunInner<K>& RunInner<K>::operator= (const RunInner<K>& rhs)
{
if
(
this
!=
&
rhs
)
{
Run
<
K
>
::
operator
=
(
rhs
);
Run
::
operator
=
(
rhs
);
_children
.
resize
(
rhs
.
_children
.
size
());
_children
=
rhs
.
_children
;
// copy
_subruns
.
resize
(
rhs
.
_subruns
.
size
());
...
...
@@ -128,7 +128,7 @@ RunInner<K>& RunInner<K>::operator= (const RunInner<K>& rhs)
template
<
class
K
>
bool
RunInner
<
K
>::
operator
==
(
const
RunInner
<
K
>&
rhs
)
const
{
if
(
!
Run
<
K
>
::
operator
==
(
rhs
))
if
(
!
Run
::
operator
==
(
rhs
))
return
false
;
if
(
_children
.
size
()
!=
rhs
.
_children
.
size
())
...
...
@@ -193,14 +193,14 @@ bool RunInner<K>::complete() const
template
<
class
K
>
const
Run
<
K
>
*
RunInner
<
K
>::
subrun
(
size_t
i
)
const