mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-25 04:43:03 +03:00
beautify
This commit is contained in:
parent
91e699f90d
commit
4f02f19ab4
@ -20,20 +20,20 @@ namespace Moses
|
||||
{
|
||||
class ContextScope
|
||||
{
|
||||
protected:
|
||||
typedef std::map<void const*, boost::shared_ptr<void> > scratchpad_t;
|
||||
typedef scratchpad_t::iterator iter_t;
|
||||
typedef scratchpad_t::value_type entry_t;
|
||||
typedef scratchpad_t::const_iterator const_iter_t;
|
||||
scratchpad_t m_scratchpad;
|
||||
protected:
|
||||
typedef std::map<void const*, boost::shared_ptr<void> > scratchpad_t;
|
||||
typedef scratchpad_t::iterator iter_t;
|
||||
typedef scratchpad_t::value_type entry_t;
|
||||
typedef scratchpad_t::const_iterator const_iter_t;
|
||||
scratchpad_t m_scratchpad;
|
||||
#ifdef WITH_THREADS
|
||||
mutable boost::shared_mutex m_lock;
|
||||
mutable boost::shared_mutex m_lock;
|
||||
#endif
|
||||
public:
|
||||
// class write_access
|
||||
// {
|
||||
// boost::unique_lock<boost::shared_mutex> m_lock;
|
||||
// public:
|
||||
public:
|
||||
// class write_access
|
||||
// {
|
||||
// boost::unique_lock<boost::shared_mutex> m_lock;
|
||||
// public:
|
||||
|
||||
// write_access(boost::shared_mutex& lock)
|
||||
// : m_lock(lock)
|
||||
@ -50,53 +50,48 @@ class ContextScope
|
||||
// return write_access(m_lock);
|
||||
// }
|
||||
|
||||
template<typename T>
|
||||
boost::shared_ptr<void> const&
|
||||
set(void const* const key, boost::shared_ptr<T> const& val)
|
||||
{
|
||||
template<typename T>
|
||||
boost::shared_ptr<void> const&
|
||||
set(void const* const key, boost::shared_ptr<T> const& val) {
|
||||
#ifdef WITH_THREADS
|
||||
boost::unique_lock<boost::shared_mutex> lock(m_lock);
|
||||
boost::unique_lock<boost::shared_mutex> lock(m_lock);
|
||||
#endif
|
||||
return (m_scratchpad[key] = val);
|
||||
}
|
||||
return (m_scratchpad[key] = val);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
boost::shared_ptr<T> const
|
||||
get(void const* key, bool CreateNewIfNecessary=false)
|
||||
{
|
||||
template<typename T>
|
||||
boost::shared_ptr<T> const
|
||||
get(void const* key, bool CreateNewIfNecessary=false) {
|
||||
#ifdef WITH_THREADS
|
||||
using boost::shared_mutex;
|
||||
using boost::upgrade_lock;
|
||||
// T const* key = reinterpret_cast<T const*>(xkey);
|
||||
upgrade_lock<shared_mutex> lock(m_lock);
|
||||
#endif
|
||||
iter_t m = m_scratchpad.find(key);
|
||||
boost::shared_ptr< T > ret;
|
||||
if (m != m_scratchpad.end())
|
||||
{
|
||||
if (m->second == NULL && CreateNewIfNecessary)
|
||||
{
|
||||
#ifdef WITH_THREADS
|
||||
boost::upgrade_to_unique_lock<shared_mutex> xlock(lock);
|
||||
using boost::shared_mutex;
|
||||
using boost::upgrade_lock;
|
||||
// T const* key = reinterpret_cast<T const*>(xkey);
|
||||
upgrade_lock<shared_mutex> lock(m_lock);
|
||||
#endif
|
||||
m->second.reset(new T);
|
||||
}
|
||||
ret = boost::static_pointer_cast< T >(m->second);
|
||||
return ret;
|
||||
}
|
||||
if (!CreateNewIfNecessary) return ret;
|
||||
iter_t m = m_scratchpad.find(key);
|
||||
boost::shared_ptr< T > ret;
|
||||
if (m != m_scratchpad.end()) {
|
||||
if (m->second == NULL && CreateNewIfNecessary) {
|
||||
#ifdef WITH_THREADS
|
||||
boost::upgrade_to_unique_lock<shared_mutex> xlock(lock);
|
||||
boost::upgrade_to_unique_lock<shared_mutex> xlock(lock);
|
||||
#endif
|
||||
ret.reset(new T);
|
||||
m_scratchpad[key] = ret;
|
||||
m->second.reset(new T);
|
||||
}
|
||||
ret = boost::static_pointer_cast< T >(m->second);
|
||||
return ret;
|
||||
}
|
||||
if (!CreateNewIfNecessary) return ret;
|
||||
#ifdef WITH_THREADS
|
||||
boost::upgrade_to_unique_lock<shared_mutex> xlock(lock);
|
||||
#endif
|
||||
ret.reset(new T);
|
||||
m_scratchpad[key] = ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
ContextScope() { }
|
||||
|
||||
ContextScope(ContextScope const& other)
|
||||
{
|
||||
ContextScope(ContextScope const& other) {
|
||||
#ifdef WITH_THREADS
|
||||
boost::unique_lock<boost::shared_mutex> lock1(this->m_lock);
|
||||
boost::unique_lock<boost::shared_mutex> lock2(other.m_lock);
|
||||
|
@ -140,17 +140,14 @@ SetCache(TranslationOption& to) const
|
||||
if (to.GetLexReorderingScores(this)) return;
|
||||
// Scores were were set already (e.g., by sampling phrase table)
|
||||
|
||||
if (m_table)
|
||||
{
|
||||
Phrase const& sphrase = to.GetInputPath().GetPhrase();
|
||||
Phrase const& tphrase = to.GetTargetPhrase();
|
||||
to.CacheLexReorderingScores(*this, this->GetProb(sphrase,tphrase));
|
||||
}
|
||||
else // e.g. OOV with Mmsapt
|
||||
{
|
||||
Scores vals(GetNumScoreComponents(), 0);
|
||||
to.CacheLexReorderingScores(*this, vals);
|
||||
}
|
||||
if (m_table) {
|
||||
Phrase const& sphrase = to.GetInputPath().GetPhrase();
|
||||
Phrase const& tphrase = to.GetTargetPhrase();
|
||||
to.CacheLexReorderingScores(*this, this->GetProb(sphrase,tphrase));
|
||||
} else { // e.g. OOV with Mmsapt
|
||||
Scores vals(GetNumScoreComponents(), 0);
|
||||
to.CacheLexReorderingScores(*this, vals);
|
||||
}
|
||||
}
|
||||
|
||||
LRModel const&
|
||||
|
@ -5,8 +5,7 @@
|
||||
|
||||
#define CMD_H
|
||||
|
||||
enum CommandType
|
||||
{
|
||||
enum CommandType {
|
||||
CMDDOUBLETYPE = 1,
|
||||
CMDENUMTYPE,
|
||||
CMDINTTYPE,
|
||||
|
@ -20,8 +20,7 @@ const int MAX_WORD = 10000; // maximum lengthsource/target strings
|
||||
const int MAX_M = 400; // maximum length of source strings
|
||||
const int MAX_N = 400; // maximum length of target strings
|
||||
|
||||
enum Alignment
|
||||
{
|
||||
enum Alignment {
|
||||
UNION = 1,
|
||||
INTERSECT,
|
||||
GROW,
|
||||
@ -429,25 +428,24 @@ int main(int argc, char** argv)
|
||||
istream *inp = &std::cin;
|
||||
ostream *out = &std::cout;
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
if (input) {
|
||||
fstream *fin = new fstream(input,ios::in);
|
||||
if (!fin->is_open()) throw runtime_error("cannot open " + string(input));
|
||||
inp = fin;
|
||||
}
|
||||
|
||||
|
||||
if (output) {
|
||||
fstream *fout = new fstream(output,ios::out);
|
||||
if (!fout->is_open()) throw runtime_error("cannot open " + string(output));
|
||||
out = fout;
|
||||
}
|
||||
|
||||
|
||||
int a[MAX_M],b[MAX_N],m,n;
|
||||
fa=new int[MAX_M+1];
|
||||
ea=new int[MAX_N+1];
|
||||
|
||||
|
||||
|
||||
|
||||
int sents = 0;
|
||||
A=new int *[MAX_N+1];
|
||||
for (int i=1; i<=MAX_N; i++) A[i]=new int[MAX_M+1];
|
||||
@ -473,14 +471,14 @@ int main(int argc, char** argv)
|
||||
cerr << "symal: computing grow alignment: diagonal ("
|
||||
<< diagonal << ") final ("<< isfinal << ")"
|
||||
<< "both-uncovered (" << bothuncovered <<")\n";
|
||||
|
||||
|
||||
while(getals(*inp,m,a,n,b))
|
||||
printgrow(*out,m,a,n,b,diagonal,isfinal,bothuncovered);
|
||||
|
||||
|
||||
break;
|
||||
case TGTTOSRC:
|
||||
cerr << "symal: computing target-to-source alignment\n";
|
||||
|
||||
|
||||
while(getals(*inp,m,a,n,b)) {
|
||||
printtgttosrc(*out,m,a,n,b);
|
||||
sents++;
|
||||
@ -489,7 +487,7 @@ int main(int argc, char** argv)
|
||||
break;
|
||||
case SRCTOTGT:
|
||||
cerr << "symal: computing source-to-target alignment\n";
|
||||
|
||||
|
||||
while(getals(*inp,m,a,n,b)) {
|
||||
printsrctotgt(*out,m,a,n,b);
|
||||
sents++;
|
||||
@ -511,9 +509,7 @@ int main(int argc, char** argv)
|
||||
if (out != &std::cout) {
|
||||
delete inp;
|
||||
}
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
} catch (const std::exception &e) {
|
||||
cerr << e.what() << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user