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
e1f4a303
Commit
e1f4a303
authored
Apr 21, 2021
by
Florent Jacquemard
Browse files
update targets for new key classes
parent
109b9044
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/targets/equiv/equiv2.cpp
View file @
e1f4a303
...
...
@@ -44,15 +44,20 @@
#include "SWTAFileIn.hpp"
// parsing
#include "Key.hpp"
//
#include "KeyS.hpp"
//
#include "Key.hpp"
#include "KeyS.hpp"
// #include "KeySI.hpp"
// #include "KeySIP.hpp"
// #include "KeySIR.hpp"
#include "KeySV.hpp"
#include "Runey.hpp"
#include "RunInner.hpp"
#include "RunTerm.hpp"
#include "RunCompare.hpp"
#include "Recordey.hpp"
#include "RecordOne.hpp"
#include "RecordQueue.hpp"
#include "TableA.hpp"
#include "TableParse.hpp"
// output
...
...
@@ -79,7 +84,7 @@ namespace sm = ScoreModel;
static
int
verbosity
=
0
;
/// number of K-best to compute
static
size_t
k
=
1
;
static
size_t
nbest
=
1
;
/// whether the best is the max (true) or the min (false) weight
static
int
f_max
=
true
;
...
...
@@ -307,12 +312,12 @@ static int getOption(int c, int option_index)
break
;
case
'k'
:
k
=
atoi
(
optarg
);
nbest
=
atoi
(
optarg
);
TRACE
(
"Option {} : {}"
,
long_options
[
option_index
].
name
,
k
);
if
(
k
==
0
)
long_options
[
option_index
].
name
,
nbest
);
if
(
nbest
==
0
)
{
ERROR
(
"option error: k={} must be > 0"
,
k
);
ERROR
(
"option error: k={} must be > 0"
,
nbest
);
return
2
;
}
break
;
...
...
@@ -418,7 +423,7 @@ static int getOption(int c, int option_index)
// unknown or ambiguous option Error already signaled by getopt
case
'?'
:
WARN
(
"unkown or ambiguous option argument"
);
WARN
(
"unk
n
own or ambiguous option argument"
);
break
;
// Do nothing for the options that are not flag-managed but without arguments
...
...
@@ -532,6 +537,51 @@ size_t parse_fail(const std::string filename)
}
/// @param tab a parse table.
/// @param init initial key to start parsing.
/// @param n number of best trees to compute.
template
<
class
K
>
void
printTrees
(
parsing
::
TableA
<
K
>&
tab
,
const
K
&
init
,
size_t
n
)
{
for
(
size_t
i
=
1
;
i
<=
nbest
;
i
++
)
{
const
parsing
::
Run
*
best_run
=
tab
.
best
(
init
,
i
);
if
(
best_run
==
NULL
)
// should no more happen (changed to FAIL)
{
//assert(best_tree == NULL);
INFO
(
"{}-best: NULL"
,
i
);
}
else
if
(
nbest
==
1
)
{
//LabeledRhythmTree* best_tree = tab->bestTree(best_run);
LabeledRhythmTree
*
best_tree
=
LRTFactory
<
K
>::
projection
(
tab
,
best_run
,
1
);
assert
(
best_tree
);
INFO
(
"{}-best = {} weight = {}"
,
i
,
best_tree
->
to_string
(),
best_run
->
weight
());
delete
best_tree
;
}
else
{
const
parsing
::
RunRanked
<
parsing
::
KeySV
>*
best_runr
=
dynamic_cast
<
const
parsing
::
RunRanked
<
parsing
::
KeySV
>*>
(
best_run
);
assert
(
best_runr
);
//LabeledRhythmTree* best_tree = tab->bestTree(best_runr);
LabeledRhythmTree
*
best_tree
=
LRTFactory
<
K
>::
projection
(
tab
,
best_runr
);
assert
(
best_tree
);
INFO
(
"{}-best = {} weight = {}"
,
i
,
best_tree
->
to_string
(),
best_run
->
weight
());
delete
best_tree
;
}
}
}
int
main
(
int
argc
,
char
**
argv
)
{
...
...
@@ -720,13 +770,17 @@ int main(int argc, char** argv)
}
INFO
(
"parsing"
);
// prepare a parsing environment
assert
(
_schema
);
parsing
::
ParsingEnv
*
penv
=
new
parsing
::
ParsingEnv
(
_schema
,
NULL
);
parsing
::
RunCompare
<
parsing
::
KeySV
>
comp
=
(
f_max
)
?
parsing
::
weightMax
<
parsing
::
KeySV
>:
parsing
::
weightMin
<
parsing
::
KeySV
>
;
parsing
::
TableA
<
parsing
::
KeySV
>*
tab
;
// empty table
parsing
::
ParsingEnv
penv
=
parsing
::
ParsingEnv
(
_schema
,
NULL
);
parsing
::
RunCompare
comp
=
(
f_max
)
?
parsing
::
weightMax
:
parsing
::
weightMin
;
// parse table
parsing
::
TableA
<
parsing
::
KeySV
>*
tab
=
nullptr
;
// empty table
if
(
k
==
1
)
// 1-best
if
(
nbest
==
1
)
// 1-best
{
INFO
(
"1-best computation"
);
tab
=
new
parsing
::
TableParse
<
parsing
::
KeySV
,
...
...
@@ -735,21 +789,24 @@ int main(int argc, char** argv)
}
else
// k-best
{
INFO
(
"{}-best computation"
,
k
);
assert
(
k
>
1
);
// cannot be 0
INFO
(
"{}-best computation"
,
nbest
);
assert
(
nbest
>
1
);
// cannot be 0
tab
=
new
parsing
::
TableParse
<
parsing
::
KeySV
,
parsing
::
RecordQueue
<
parsing
::
KeySV
>
,
parsing
::
KeySVHasher
>
(
penv
,
comp
);
}
assert
(
penv
);
const
parsing
::
KeySV
k0
=
parsing
::
KeySV
(
seg
,
*
penv
);
// initial augmented state
const
parsing
::
KeySV
k0
=
parsing
::
KeySV
(
seg
,
penv
);
// fill table up to n-best
INFO
(
"parsing IOI segment {} (dur={}bars)"
,
seg
,
seg
.
size
());
clock_t
time_start
=
clock
();
tab
->
best
(
k0
,
k
);
// fill table up to k-best
assert
(
tab
);
tab
->
best
(
k0
,
nbest
);
// fill table up to k-best
INFO
(
"time to parse : {}ms"
,
util
::
duration
(
time_start
));
LabeledRhythmTree
*
t
=
LRTFactory
<
parsing
::
KeySV
>::
best
(
tab
,
k0
);
LabeledRhythmTree
*
t
=
LRTFactory
<
parsing
::
KeySV
>::
best
(
*
tab
,
k0
);
assert
(
t
);
INFO
(
"Ouput tree : {}"
,
*
t
);
...
...
@@ -782,5 +839,8 @@ int main(int argc, char** argv)
}
}
delete
t
;
if
(
tab
)
delete
tab
;
return
0
;
}
src/targets/quant/squant2.cpp
View file @
e1f4a303
...
...
@@ -67,7 +67,6 @@
#include <getopt.h> // handling commandline options
#include <assert.h>
#include "config.hpp" // check compile flags
#include "trace.hpp"
#include "Rational.hpp"
...
...
@@ -83,7 +82,6 @@
#include "Voicing.hpp"
#include "VoicingMono.hpp"
// automata and parsing
// switch options for WCFG weight
#include "Weight.hpp"
#include "WeightDom.hpp"
...
...
@@ -91,8 +89,16 @@
#include "TropicalWeight.hpp"
#include "ViterbiWeight.hpp"
// automata
#include "Label.hpp"
#include "SymbLabel.hpp"
#include "State.hpp"
#include "Transition.hpp"
#include "WFSM.hpp"
#include "SWTA.hpp"
#include "SWTAFileIn.hpp"
// parsing
//#include "Key.hpp"
#include "KeyS.hpp"
#include "KeySI.hpp"
...
...
@@ -1208,7 +1214,7 @@ int main(int argc, char** argv)
assert
(
_schema
);
parsing
::
ParsingEnv
env
=
parsing
::
ParsingEnv
(
_schema
,
NULL
);
state_t
init
=
_schema
->
initial
();
const
KeyS
k0
=
KeyS
(
init
,
env
);
const
parsing
::
KeyS
k0
=
parsing
::
KeyS
(
init
,
env
);
// flag f_max: ordering for enumeration (user option)
parsing
::
TableA
<
parsing
::
KeyS
>*
tab
=
parse
<
parsing
::
KeyS
,
parsing
::
KeySHasher
>
(
k0
,
_nbest
,
f_max
,
env
);
...
...
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