Skip to content

Commit

Permalink
Lint-fixing binge.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeroen Vermeulen committed Jun 2, 2015
1 parent 35cf55d commit 0981d23
Show file tree
Hide file tree
Showing 23 changed files with 311 additions and 114 deletions.
2 changes: 2 additions & 0 deletions .beautify-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ irstlm
jam-files
lm
mingw/MosesGUI/icons_rc.py
mingw/MosesGUI/Ui_credits.py
mingw/MosesGUI/Ui_mainWindow.py
moses/TranslationModel/UG
phrase-extract/pcfg-common
phrase-extract/syntax-common
Expand Down
11 changes: 7 additions & 4 deletions mingw/MosesGUI/addMTModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
Module implementing Dialog.
"""

from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PyQt4.QtGui import (
QDialog,
QFileDialog,
)
from PyQt4.QtCore import pyqtSignature

import datetime
import os

from Ui_addMTModel import Ui_Dialog
from util import *
from util import doAlert


class AddMTModelDialog(QDialog, Ui_Dialog):
Expand Down Expand Up @@ -88,7 +91,7 @@ def on_buttonBox_accepted(self):
def checkEmpty(mystr):
return len(str(mystr).strip()) <= 0

#check everything
# Check everything.
self.modelName = self.editName.text()
if checkEmpty(self.modelName):
doAlert("Please provide non-empty Model Name")
Expand Down
31 changes: 22 additions & 9 deletions mingw/MosesGUI/chooseMTModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@
Module implementing ChooseMTModelDialog.
"""

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtSql import *
import sys

from PyQt4.QtCore import (
pyqtSignature,
QObject,
SIGNAL,
)
from PyQt4.QtGui import QDialog
from PyQt4.QtSql import QSqlQueryModel

from Ui_chooseMTModel import Ui_Dialog
from util import doAlert


class ChooseMTModelDialog(QDialog, Ui_Dialog):
Expand All @@ -28,14 +35,20 @@ def __init__(self, parent=None, datamodel=None):
self.selTableView.hideColumn(0)
self.selTableView.hideColumn(5)
self.selTableView.hideColumn(6)
#change status and keep the column
QObject.connect(datamodel, SIGNAL("modelInstalled()"), self.on_datamodel_modelInstalled)
# Change status and keep the column.
QObject.connect(
datamodel, SIGNAL("modelInstalled()"),
self.on_datamodel_modelInstalled)

def updateModel(self):
self.model.setQuery('SELECT ID, name, srclang, trglang, status, path, mosesini FROM models WHERE status = "READY" AND deleted != "True"', self.database)
self.model.setQuery(
'SELECT ID, name, srclang, trglang, status, path, mosesini '
'FROM models '
'WHERE status = "READY" AND deleted != "True"',
self.database)

def on_datamodel_recordUpdated(self, bRecord):
#deal with the selection changed problem
"""Deal with the selection changed problem."""
try:
if bRecord:
current = self.selTableView.currentIndex()
Expand All @@ -44,9 +57,9 @@ def on_datamodel_recordUpdated(self, bRecord):
else:
self.curSelection = None
else:
if not self.curSelection is None:
if self.curSelection is not None:
self.selTableView.selectRow(self.curSelection)
except Exception, e:
except Exception as e:
print >> sys.stderr, str(e)

def on_datamodel_modelInstalled(self):
Expand Down
4 changes: 1 addition & 3 deletions mingw/MosesGUI/main.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# -*- coding: utf-8 -*-

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtGui import QApplication

import os
import sys

from mainWindow import MainWindow
from datamodel import DataModel
from moses import Moses
from util import *

if __name__ == "__main__":
app = QApplication(sys.argv)
Expand Down
71 changes: 49 additions & 22 deletions mingw/MosesGUI/mainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,27 @@
Module implementing MainWindow.
"""

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtSql import *
from PyQt4.QtCore import (
pyqtSignature,
QObject,
Qt,
SIGNAL,
)
from PyQt4.QtGui import (
QMainWindow,
QMessageBox,
QProgressDialog,
)

import sys
import threading

from Ui_mainWindow import Ui_MainWindow
from addMTModel import AddMTModelDialog
from chooseMTModel import ChooseMTModelDialog
from engine import Engine
from credits import DlgCredits
from util import *
from util import doAlert


class MainWindow(QMainWindow, Ui_MainWindow):
Expand Down Expand Up @@ -54,18 +63,27 @@ def on_delModelBtn_clicked(self):
Slot documentation goes here.
"""
current = self.tableView.currentIndex()
if current and current.row() >= 0:
if self.engine and self.datamodel.getRowID(current.row()) == self.engine.model['ID']:
text = '''The model is still in use, do you want to stop and delete it?
It might take a while...'''
reply = QMessageBox.question(None, 'Message', text, QMessageBox.Yes, QMessageBox.No)
if reply == QMessageBox.No:
return
t = self.stopEngine(self.engine)
t.join()
self.engine = None
self.clearPanel()
self.datamodel.delModel(current.row())
if not current or current.row() < 0:
return
model_in_use = (
self.engine and
self.datamodel.getRowID(current.row()) == self.engine.model['ID']
)
if model_in_use:
text = (
"The model is still in use, do you want to "
"stop and delete it?\n"
"It might take a while..."
)
reply = QMessageBox.question(
None, 'Message', text, QMessageBox.Yes, QMessageBox.No)
if reply == QMessageBox.No:
return
t = self.stopEngine(self.engine)
t.join()
self.engine = None
self.clearPanel()
self.datamodel.delModel(current.row())

@pyqtSignature("")
def on_newModelBtn_clicked(self):
Expand Down Expand Up @@ -153,17 +171,24 @@ def startEngine(self, model):
if self.progress:
self.progress.close()
self.progress = None
self.progress = QProgressDialog("Model: %s" % model['name'], "Cancel", 0, self.engine.countSteps(), self)
self.progress = QProgressDialog(
"Model: %s" % model['name'], "Cancel", 0,
self.engine.countSteps(), self)
self.progress.setAutoReset(True)
self.progress.setAutoClose(True)
self.progress.setWindowModality(Qt.WindowModal)
self.progress.setWindowTitle('Loading Model...')
QObject.connect(self.progress, SIGNAL("canceled()"), self.progressCancelled)
QObject.connect(
self.progress, SIGNAL("canceled()"), self.progressCancelled)
self.progress.show()

#connect engine signal
QObject.connect(self.engine, SIGNAL("stepFinished(int)"), self.engineStepFinished)
QObject.connect(self.engine, SIGNAL("loaded(bool, QString)"), self.engineLoaded)
# Connect engine signal.
QObject.connect(
self.engine, SIGNAL("stepFinished(int)"),
self.engineStepFinished)
QObject.connect(
self.engine, SIGNAL("loaded(bool, QString)"),
self.engineLoaded)

def startEngineThread():
self.engine.start()
Expand Down Expand Up @@ -225,7 +250,9 @@ def on_btnTranslate_clicked(self):
if text.strip() == "":
trans.append(text)
else:
trans.append(self.engine.translate(text.replace('\r', ' ').strip()).decode('utf8'))
trans.append(
self.engine.translate(
text.replace('\r', ' ').strip()).decode('utf8'))
self.editTrg.setText('\n'.join(trans))
except Exception, e:
print >> sys.stderr, str(e)
Expand Down
2 changes: 1 addition & 1 deletion misc/processLexicalTableMin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ int main(int argc, char** argv)
bool multipleScoreTrees = true;
size_t quantize = 0;

size_t threads =
size_t threads =
#ifdef WITH_THREADS
boost::thread::hardware_concurrency() ? boost::thread::hardware_concurrency() :
#endif
Expand Down
2 changes: 1 addition & 1 deletion misc/processPhraseTableMin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ int main(int argc, char **argv)
bool sortScoreIndexSet = false;
size_t sortScoreIndex = 2;
bool warnMe = true;
size_t threads =
size_t threads =
#ifdef WITH_THREADS
boost::thread::hardware_concurrency() ? boost::thread::hardware_concurrency() :
#endif
Expand Down
2 changes: 1 addition & 1 deletion moses/FF/GlobalLexicalModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void GlobalLexicalModel::Load()

void GlobalLexicalModel::InitializeForInput(ttasksptr const& ttask)
{
UTIL_THROW_IF2(ttask->GetSource()->GetType() != SentenceInput,
UTIL_THROW_IF2(ttask->GetSource()->GetType() != SentenceInput,
"GlobalLexicalModel works only with sentence input.");
Sentence const* s = reinterpret_cast<Sentence const*>(ttask->GetSource().get());
m_local.reset(new ThreadLocalStorage);
Expand Down
2 changes: 1 addition & 1 deletion moses/FF/GlobalLexicalModelUnlimited.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ bool GlobalLexicalModelUnlimited::Load(const std::string &filePathSource,

void GlobalLexicalModelUnlimited::InitializeForInput(ttasksptr const& ttask)
{
UTIL_THROW_IF2(ttask->GetSource()->GetType() != SentenceInput,
UTIL_THROW_IF2(ttask->GetSource()->GetType() != SentenceInput,
"GlobalLexicalModel works only with sentence input.");
Sentence const* s = reinterpret_cast<Sentence const*>(ttask->GetSource().get());
m_local.reset(new ThreadLocalStorage);
Expand Down
4 changes: 2 additions & 2 deletions moses/IOWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,10 @@ ReadInput()
boost::lock_guard<boost::mutex> lock(m_lock);
#endif
boost::shared_ptr<InputType> source = GetBufferedInput();
if (source)
if (source)
{
source->SetTranslationId(m_currentLine++);
if (m_look_ahead || m_look_back)
if (m_look_ahead || m_look_back)
this->set_context_for(*source);
}
m_past_input.push_back(source);
Expand Down
13 changes: 6 additions & 7 deletions moses/StaticData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ bool StaticData::LoadData(Parameter *parameter)
ini_factor_maps();
ini_input_options();
m_bookkeeping_options.init(*parameter);
m_nbest_options.init(*parameter); // if (!ini_nbest_options()) return false;
m_nbest_options.init(*parameter); // if (!ini_nbest_options()) return false;
if (!ini_output_options()) return false;

// threading etc.
Expand All @@ -616,14 +616,14 @@ bool StaticData::LoadData(Parameter *parameter)
ini_mira_options();

// set m_nbest_options.enabled = true if necessary:
if (m_mbr || m_useLatticeMBR || m_outputSearchGraph || m_outputSearchGraphSLF
|| m_mira || m_outputSearchGraphHypergraph || m_useConsensusDecoding
if (m_mbr || m_useLatticeMBR || m_outputSearchGraph || m_outputSearchGraphSLF
|| m_mira || m_outputSearchGraphHypergraph || m_useConsensusDecoding
#ifdef HAVE_PROTOBUF
|| m_outputSearchGraphPB
|| m_outputSearchGraphPB
#endif
|| m_latticeSamplesFilePath.size())
{
m_nbest_options.enabled = true;
{
m_nbest_options.enabled = true;
}

// S2T decoder
Expand Down Expand Up @@ -1371,4 +1371,3 @@ void StaticData::ResetWeights(const std::string &denseWeights, const std::string
}

} // namespace

2 changes: 1 addition & 1 deletion moses/StaticData.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class StaticData
BookkeepingOptions m_bookkeeping_options;
// size_t m_nBestSize;
// size_t m_nBestFactor;

size_t m_latticeSamplesSize;
size_t m_maxNoTransOptPerCoverage;
size_t m_maxNoPartTransOpt;
Expand Down
2 changes: 1 addition & 1 deletion moses/WordsBitmapTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ BOOST_AUTO_TEST_CASE(initialise)
bitvec[2] = true;
bitvec[3] = true;
bitvec[7] = true;

WordsBitmap wbm2(7,bitvec);
BOOST_CHECK_EQUAL(wbm2.GetSize(),7);
for (size_t i = 0; i < 7; ++i) {
Expand Down
2 changes: 1 addition & 1 deletion moses/parameters/BookkeepingOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Moses {
bool& x = need_alignment_info;
P.SetParameter(x, "print-alignment-info", false);
if (!x) P.SetParameter(x, "print-alignment-info-in-n-best", false);
if (!x)
if (!x)
{
PARAM_VEC const* params = P.GetParam("alignment-output-file");
x = params && params->size();
Expand Down
14 changes: 7 additions & 7 deletions moses/parameters/NBestOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,30 @@ init(Parameter const& P)
{
const PARAM_VEC *params;
params = P.GetParam("n-best-list");
if (params)
if (params)
{
if (params->size() >= 2)
if (params->size() >= 2)
{
output_file_path = params->at(0);
nbest_size = Scan<size_t>( params->at(1) );
only_distinct = (params->size()>2 && params->at(2)=="distinct");
}
else
}
else
{
std::cerr << "wrong format for switch -n-best-list file size [disinct]";
return false;
}
}
}
else nbest_size = 0;

P.SetParameter<size_t>(factor, "n-best-factor", 20);
P.SetParameter(include_alignment_info, "print-alignment-info-in-n-best", false );
P.SetParameter(include_feature_labels, "labeled-n-best-list", true );
P.SetParameter(include_segmentation, "include-segmentation-in-n-best", false );
P.SetParameter(include_passthrough, "print-passthrough-in-n-best", false );
P.SetParameter(include_all_factors, "report-all-factors-in-n-best", false );
P.SetParameter(print_trees, "n-best-trees", false );

enabled = output_file_path.size();
return true;
}
Expand Down
4 changes: 1 addition & 3 deletions moses/parameters/NBestOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ namespace Moses {
bool include_all_factors;

std::string output_file_path;

bool init(Parameter const& param);

};



}
Loading

0 comments on commit 0981d23

Please sign in to comment.