def create_property_grid(self): if not properties.is_initialized(): properties.read_config() config = properties.get_config() allowed_sections = config.get('UI-AllowedSections', 'allowed').split(',') property_name_to_edit = {} grid_layout = QtGui.QGridLayout() i = 0 for section in allowed_sections: section_label = QtGui.QLabel(section, self) grid_layout.addWidget(section_label, i, 0) i += 1 for option, value in config.items(section): option_label = QtGui.QLabel(config.get('UI-PropertyNames', option) + ':', self) grid_layout.addWidget(option_label, i, 0) option_value_edit = QtGui.QLineEdit(value, self) grid_layout.addWidget(option_value_edit, i, 1) property_name_to_edit[(section, option)] = option_value_edit i += 1 i += 1 self.property_name_to_edit = property_name_to_edit return grid_layout
def apply_changes(self): config = properties.get_config() for (section, option), edit in self.property_name_to_edit.items(): config.set(section, option, str(edit.text())) properties.save_config() self.parent().centralWidget().load_stitching_settings() self.accept()
def main(weak="lexical"): random.seed(42) config_path = os.path.join("data/npi", f"{weak}.csv") section_to_configs = properties.get_config(config_path) section_to_examples = {"both": [], "neither": [], "weak": []} for section in section_to_examples: # NOTE: there's only one config per section, so we'll just take that one config = section_to_configs[section][0] for _ in range(5_000): sentence = generate_wrapper(config) section_to_examples[section].append(sentence)
def make_dataset(section_to_count, template, easy_feature): dataset = [] config_path = os.path.join("data/sva", f"{template}_{easy_feature}.csv") section_to_configs = properties.get_config(config_path) for section in section_to_count: templates = [] for config in section_to_configs[section]: templates.append(get_template(config)) for _ in range(section_to_count[section]): sentence = generate(random.choice(templates)) label = 1 if section == "both" or section == "strong" else 0 dataset.append({"sentence": sentence, "label": label, "section": section}) return dataset
def make_dataset(section_to_count, template, easy_feature): dataset = [] config_path = os.path.join("data/nli", f"{template}_{easy_feature}.csv") section_to_configs = properties.get_config(config_path) for section in section_to_count: templates = [] section_data = [] for config in section_to_configs[section]: for template in get_template(config): section_data.extend( zip(template.data[:section_to_count[section]], template.labels[:section_to_count[section]])) random.shuffle(section_data) for pair, label in section_data: dataset.append(dict(**pair, label=label, section=section)) return dataset
import logging.config import os from PyQt4 import QtGui, QtCore from PyQt4.Qt import QTranslator, QLibraryInfo from stitching.ui.mainwindow import MainWindow import properties if __name__ == '__main__': config = properties.get_config() logging.config.fileConfig(config.get('Global', 'logConfig')) logger = logging.getLogger('globalLogger') try: import sys app = QtGui.QApplication(sys.argv) # Load localization settings language = config.get('Localization', 'language') localize_path = config.get('Localization', 'translationspath') filename = config.get('Localization', 'translationnameformat').format(language) # Qt localization settings qt_translator = QTranslator() qt_translator.load('qt_' + language, QLibraryInfo.location(QLibraryInfo.TranslationsPath)) app.installTranslator(qt_translator) # Application localization settings app_translator = QTranslator()