def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.api = WikipediaAPI(on_error=self.Error.api_error) self.result = None query_box = gui.hBox(self.controlArea, 'Query') # Queries configuration layout = QGridLayout() layout.setSpacing(7) row = 0 self.query_edit = ListEdit(self, 'query_list', "Each line represents a " "separate query.", 100, self) layout.addWidget(QLabel('Query word list:'), row, 0, 1, self.label_width) layout.addWidget(self.query_edit, row, self.label_width, 1, self.widgets_width) # Language row += 1 language_edit = ComboBox(self, 'language', tuple(sorted(lang2code.items()))) layout.addWidget(QLabel('Language:'), row, 0, 1, self.label_width) layout.addWidget(language_edit, row, self.label_width, 1, self.widgets_width) # Articles per query row += 1 layout.addWidget(QLabel('Articles per query:'), row, 0, 1, self.label_width) slider = gui.valueSlider(query_box, self, 'articles_per_query', box='', values=[1, 3, 5, 10, 25]) layout.addWidget(slider.box, row, 1, 1, self.widgets_width) query_box.layout().addLayout(layout) self.controlArea.layout().addWidget(query_box) self.controlArea.layout().addWidget( CheckListLayout('Text includes', self, 'text_includes', self.attributes, cols=2, callback=self.set_text_features)) self.info_box = gui.hBox(self.controlArea, 'Info') self.result_label = gui.label(self.info_box, self, self.info_label.format(0)) self.button_box = gui.hBox(self.controlArea) self.search_button = gui.button(self.button_box, self, 'Search', self.start_stop) self.search_button.setFocusPolicy(Qt.NoFocus)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.api = WikipediaAPI(on_error=self.Error.api_error) self.result = None query_box = gui.hBox(self.controlArea, '查询') # Queries configuration layout = QGridLayout() layout.setSpacing(7) row = 0 self.query_edit = ListEdit(self, 'query_list', "每一行表示一个不同的查询", 100, self) layout.addWidget(QLabel('查询词:'), row, 0, 1, self.label_width) layout.addWidget(self.query_edit, row, self.label_width, 1, self.widgets_width) # Articles per query row += 1 layout.addWidget(QLabel('每次查询文章数量:'), row, 0, 1, self.label_width) slider = gui.valueSlider(query_box, self, 'articles_per_query', box='', values=[10, 30, 50, 80, 100]) layout.addWidget(slider.box, row, 1, 1, self.widgets_width) query_box.layout().addLayout(layout) self.controlArea.layout().addWidget(query_box) self.controlArea.layout().addWidget( CheckListLayout('包含的内容', self, 'text_includes', self.attributes, cols=2, callback=self.set_text_features)) self.info_box = gui.hBox(self.controlArea, '基本信息') self.result_label = gui.label(self.info_box, self, self.info_label.format(0)) self.button_box = gui.hBox(self.controlArea) self.search_button = gui.button(self.button_box, self, '查询', self.start_stop) self.search_button.setFocusPolicy(Qt.NoFocus)
def __init__(self): super().__init__() self.corpus = None self.api = None self.output_info = '' # API token self.api_dlg = self.CredentialsDialog(self) self.api_dlg.accept(silent=True) gui.button(self.controlArea, self, 'Facebook login', callback=self.api_dlg.exec_, focusPolicy=Qt.NoFocus) # Query self.query_box = gui.widgetBox(self.controlArea, 'Posts', addSpace=True) gui.label(self.query_box, self, 'Page IDs (or page URLs)') self.query_box.layout().addWidget(ListEdit(self, 'page_ids', 'One page ID per line', 80, self)) def date_changed(): d.picker_to.setVisible(self.date_option in [DATE_BETWEEN]) d.picker_from.setVisible(self.date_option in [DATE_FROM, DATE_BETWEEN]) gui.comboBox(self.query_box, self, 'date_option', items=DATE_OPTIONS, label="Date filter", callback = date_changed) date_box = gui.hBox(self.query_box) d = DatePickerInterval(date_box, self, 'date_from', 'date_to', min_date=None, max_date=date.today(), margin=(0, 3, 0, 0)) date_changed() self.mode_box = gui.widgetBox(self.query_box, box=True) mode_box_h = gui.hBox(self.mode_box) gui.radioButtonsInBox(mode_box_h, self, 'mode', btnLabels=['only posts from page itself', 'all public posts on page'], orientation=2) # gui.radioButtonsInBox(mode_box_h, self, 'accumulate', btnLabels=['new results', 'add to previous results'], orientation=2, label='On search:') gui.lineEdit(mode_box_h, self, 'max_documents', label='Max docs per page:', valueType=str, controlWidth=50) comments_box = gui.widgetBox(self.controlArea, box='Comments') gui.radioButtonsInBox(comments_box, self, 'comments', btnLabels=['ignore', 'direct comments', 'all comments'], orientation=2) # Text includes features self.query_box.layout().addWidget( CheckListLayout('Text includes', self, 'text_includes', self.attributes, cols=2, callback=self.set_text_features)) # Output info_box = gui.hBox(self.controlArea, 'Output') gui.label(info_box, self, 'Articles: %(output_info)s') # Buttons self.button_box = gui.hBox(self.controlArea) self.button_box.layout().addWidget(self.report_button) self.search_button = gui.button(self.button_box, self, 'Search', self.start_stop, focusPolicy=Qt.NoFocus)
class OWWikipedia(OWWidget): """ Get articles from wikipedia. """ name = '维基百科' priority = 160 icon = 'icons/Wikipedia.svg' class Outputs: corpus = Output("Corpus", Corpus) want_main_area = False resizing_enabled = False label_width = 1 widgets_width = 2 attributes = [feat.name for feat in WikipediaAPI.string_attributes] text_includes = settings.Setting( [feat.name for feat in WikipediaAPI.string_attributes]) query_list = settings.Setting([]) language = settings.Setting('en') articles_per_query = settings.Setting(10) info_label = '文章数量 {:d}' class Error(OWWidget.Error): api_error = Msg('API error: {}') class Warning(OWWidget.Warning): no_text_fields = Msg('未选择文字功能时,将推断文字功能') def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.api = WikipediaAPI(on_error=self.Error.api_error) self.result = None query_box = gui.hBox(self.controlArea, '查询') # Queries configuration layout = QGridLayout() layout.setSpacing(7) row = 0 self.query_edit = ListEdit(self, 'query_list', "每一行表示一个不同的查询", 100, self) layout.addWidget(QLabel('查询词:'), row, 0, 1, self.label_width) layout.addWidget(self.query_edit, row, self.label_width, 1, self.widgets_width) # Language row += 1 language_edit = ComboBox(self, 'language', tuple(sorted(lang2code.items()))) layout.addWidget(QLabel('语言:'), row, 0, 1, self.label_width) layout.addWidget(language_edit, row, self.label_width, 1, self.widgets_width) # Articles per query row += 1 layout.addWidget(QLabel('每次查询文章数量:'), row, 0, 1, self.label_width) slider = gui.valueSlider(query_box, self, 'articles_per_query', box='', values=[1, 3, 5, 10, 25]) layout.addWidget(slider.box, row, 1, 1, self.widgets_width) query_box.layout().addLayout(layout) self.controlArea.layout().addWidget(query_box) self.controlArea.layout().addWidget( CheckListLayout('包含的内容', self, 'text_includes', self.attributes, cols=2, callback=self.set_text_features)) self.info_box = gui.hBox(self.controlArea, '基本信息') self.result_label = gui.label(self.info_box, self, self.info_label.format(0)) self.button_box = gui.hBox(self.controlArea) self.search_button = gui.button(self.button_box, self, '查询', self.start_stop) self.search_button.setFocusPolicy(Qt.NoFocus) def start_stop(self): if self.search.running: self.search.stop() else: self.search() @asynchronous def search(self): return self.api.search(lang=self.language, queries=self.query_list, articles_per_query=self.articles_per_query, on_progress=self.progress_with_info, should_break=self.search.should_break) @search.callback(should_raise=False) def progress_with_info(self, progress, n_retrieved): self.progressBarSet(100 * progress, None) self.result_label.setText(self.info_label.format(n_retrieved)) @search.on_start def on_start(self): self.Error.api_error.clear() self.progressBarInit(None) self.search_button.setText('停止') self.result_label.setText(self.info_label.format(0)) self.Outputs.corpus.send(None) @search.on_result def on_result(self, result): self.result = result self.result_label.setText( self.info_label.format(len(result) if result else 0)) self.search_button.setText('查询') self.set_text_features() self.progressBarFinished(None) def set_text_features(self): self.Warning.no_text_fields.clear() if not self.text_includes: self.Warning.no_text_fields() if self.result is not None: vars_ = [ var for var in self.result.domain.metas if var.name in self.text_includes ] self.result.set_text_features(vars_ or None) self.Outputs.corpus.send(self.result) def send_report(self): if self.result: items = (('语言', code2lang[self.language]), ('查询', self.query_edit.toPlainText()), ('文档数量', len(self.result))) self.report_items('Query', items)
def __init__(self): OWWidget.__init__(self) ConcurrentWidgetMixin.__init__(self) self.api = None self.api_dlg = self.APICredentialsDialog(self) self.api_dlg.accept() # Set API key button gui.button( self.controlArea, self, "Twitter API Key", callback=self.open_key_dialog, tooltip="Set the API key for this widget.", focusPolicy=Qt.NoFocus, ) # Query query_box = gui.hBox(self.controlArea, "Query") layout = QGridLayout() layout.setVerticalSpacing(5) layout.setColumnStretch(2, 1) # stretch last columns layout.setColumnMinimumWidth(1, 15) # add some space for checkbox ROW = 0 COLUMNS = 3 def add_row(label, items): nonlocal ROW, COLUMNS layout.addWidget(QLabel(label), ROW, 0) if isinstance(items, tuple): for i, item in enumerate(items): layout.addWidget(item, ROW, 1 + i) else: layout.addWidget(items, ROW, 1, 1, COLUMNS - 1) ROW += 1 # Query input add_row( "Query word list:", ListEdit( self, "word_list", "Multiple lines are joined with OR.", 80, self, ), ) # Search mode add_row( "Search by:", gui.comboBox(self, self, "mode", items=self.MODES, callback=self.mode_toggle), ) # Language langs = (("Any", None), ) + tuple( (code2lang[l], l) for l in SUPPORTED_LANGUAGES) self.language_combo = ComboBox(self, "language", items=langs) add_row("Language:", self.language_combo) # Max tweets add_row( "Max tweets:", gui.spin( self, self, "max_tweets", minv=1, maxv=10000, checked="limited_search", ), ) # Retweets self.retweets_checkbox = gui.checkBox(self, self, "allow_retweets", "", minimumHeight=30) add_row("Allow retweets:", self.retweets_checkbox) # Collect Results add_row("Collect results:", gui.checkBox(self, self, "collecting", "")) query_box.layout().addLayout(layout) # Buttons self.search_button = gui.button( self.buttonsArea, self, "Search", self.start_stop, focusPolicy=Qt.NoFocus, ) self.mode_toggle() self.setFocus() # to widget itself to show placeholder for query_edit
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.api = None self.corpus = None self.api_dlg = self.APICredentialsDialog(self) self.api_dlg.accept(silent=True) # Set API key button gui.button(self.controlArea, self, 'Twitter API Key', callback=self.open_key_dialog, tooltip='Set the API key for this widget.', focusPolicy=Qt.NoFocus) # Query query_box = gui.hBox(self.controlArea, 'Query') layout = QGridLayout() layout.setVerticalSpacing(5) layout.setColumnStretch(2, 1) # stretch last columns layout.setColumnMinimumWidth(1, 15) # add some space for checkbox ROW = 0 COLUMNS = 3 def add_row(label, items): nonlocal ROW, COLUMNS layout.addWidget(QLabel(label), ROW, 0) if isinstance(items, tuple): for i, item in enumerate(items): layout.addWidget(item, ROW, 1 + i) else: layout.addWidget(items, ROW, 1, 1, COLUMNS - 1) ROW += 1 # Query input add_row( 'Query word list:', ListEdit(self, 'word_list', 'Multiple lines are joined with OR.', 80, self)) # Search mode add_row( 'Search by:', gui.comboBox(self, self, 'mode', items=self.MODES, callback=self.mode_toggle)) # Language self.language_combo = ComboBox(self, 'language', items=(('Any', None), ) + tuple(sorted(lang2code.items()))) add_row('Language:', self.language_combo) # Max tweets add_row( 'Max tweets:', gui.spin(self, self, 'max_tweets', minv=1, maxv=10000, checked='limited_search')) # Retweets self.retweets_checkbox = gui.checkBox(self, self, 'allow_retweets', '', minimumHeight=30) add_row('Allow retweets:', self.retweets_checkbox) # Collect Results add_row('Collect results:', gui.checkBox(self, self, 'collecting', '')) query_box.layout().addLayout(layout) self.controlArea.layout().addWidget( CheckListLayout('Text includes', self, 'text_includes', self.attributes, cols=2, callback=self.set_text_features)) self.tweets_info_label = gui.label(self.controlArea, self, self.tweets_info.format(0), box='Info') # Buttons self.button_box = gui.hBox(self.controlArea) self.button_box.layout().addWidget(self.report_button) self.search_button = gui.button(self.button_box, self, 'Search', self.start_stop, focusPolicy=Qt.NoFocus) self.mode_toggle() self.setFocus() # to widget itself to show placeholder for query_edit
def __init__(self, *args, **kwargs): """ Attributes: api (twitter.TwitterAPI): Twitter API object. """ super().__init__(*args, **kwargs) self.api = None self.corpus = None self.api_dlg = self.APICredentialsDialog(self) self.api_dlg.accept(silent=True) self.controlArea.layout().setContentsMargins(0, 15, 0, 0) # Set API key button. key_dialog_button = gui.button(self.controlArea, self, 'Twitter API Key', callback=self.open_key_dialog, tooltip="Set the API key for this widget.") key_dialog_button.setFocusPolicy(QtCore.Qt.NoFocus) # Query self.query_box = gui.hBox(self.controlArea, 'Query') # Queries configuration layout = QtGui.QGridLayout() layout.setSpacing(7) # Query row = 0 query_edit = ListEdit(self, 'word_list', "Multiple lines are automatically joined with OR.", self) query_edit.setFixedHeight(self.text_area_height) layout.addWidget(QtGui.QLabel('Query word list:'), row, 0, 1, self.label_width) layout.addWidget(query_edit, row, self.label_width, 1, self.widgets_width) # Search mode row += 1 mode = gui.comboBox(self, self, 'mode') mode.addItem('Content') mode.addItem('Author') mode.addItem('Content & Author') layout.addWidget(QtGui.QLabel('Search by:'), row, 0, 1, self.label_width) layout.addWidget(mode, row, self.label_width, 1, self.widgets_width) # Retweets row += 1 check = gui.checkBox(self, self, 'allow_retweets', '') layout.addWidget(QtGui.QLabel('Allow\nretweets:'), row, 0, 1, self.label_width) layout.addWidget(check, row, self.label_width, 1, 1) # Time interval row += 1 interval = DateInterval(self, 'date_interval', min_date=datetime.now().date() - timedelta(10), max_date=datetime.now().date(), from_label='since', to_label='until') layout.addWidget(QtGui.QLabel('Date:'), row, 0, 1, self.label_width) layout.addWidget(interval, row, self.label_width, 1, self.widgets_width) # Language row += 1 language_edit = ComboBox(self, 'language', (('Any', None),) + tuple(sorted(lang2code.items()))) layout.addWidget(QtGui.QLabel('Language:'), row, 0, 1, self.label_width) layout.addWidget(language_edit, row, self.label_width, 1, self.widgets_width) # Max tweets row += 1 check, spin = gui.spin(self, self, 'max_tweets', minv=1, maxv=10000, checked='limited_search') layout.addWidget(QtGui.QLabel('Max tweets:'), row, 0, 1, self.label_width) layout.addWidget(check, row, self.label_width, 1, 1) layout.addWidget(spin, row, self.label_width + 1, 1, self.widgets_width - 1) # Checkbox row += 1 check = gui.checkBox(self, self, 'advance', '') layout.addWidget(QtGui.QLabel('Accumulate\nresults:'), row, 0, 1, self.label_width) layout.addWidget(check, row, self.label_width, 1, 1) self.query_box.layout().addLayout(layout) self.controlArea.layout().addWidget( CheckListLayout('Text includes', self, 'text_includes', self.attributes, cols=2, callback=self.set_text_features)) self.info_box = gui.hBox(self.controlArea, 'Info') self.tweets_count_label = gui.label(self.info_box, self, self.tweets_info.format(0)) # Buttons self.button_box = gui.hBox(self.controlArea) self.button_box.layout().addWidget(self.report_button) self.search_button = gui.button(self.button_box, self, "Search", self.search) self.search_button.setFocusPolicy(QtCore.Qt.NoFocus) self.start_signal.connect(self.on_start) self.error_signal.connect(self.on_error) self.progress_signal.connect(self.on_progress) self.finish_signal.connect(self.on_finish) self._tweet_count = False self.send_corpus() self.setFocus() # set focus to widget itself so placeholder is shown for query_edit
class OWWikipedia(OWWidget): """ Get articles from wikipedia. """ name = 'Wikipedia' priority = 160 icon = 'icons/Wikipedia.svg' class Outputs: corpus = Output("Corpus", Corpus) want_main_area = False resizing_enabled = False label_width = 1 widgets_width = 2 attributes = [feat.name for feat in WikipediaAPI.string_attributes] text_includes = settings.Setting([feat.name for feat in WikipediaAPI.string_attributes]) query_list = settings.Setting([]) language = settings.Setting('en') articles_per_query = settings.Setting(10) info_label = 'Articles count {:d}' class Error(OWWidget.Error): api_error = Msg('API error: {}') class Warning(OWWidget.Warning): no_text_fields = Msg('Text features are inferred when none are selected.') def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.api = WikipediaAPI(on_error=self.Error.api_error) self.result = None query_box = gui.hBox(self.controlArea, 'Query') # Queries configuration layout = QGridLayout() layout.setSpacing(7) row = 0 self.query_edit = ListEdit(self, 'query_list', "Each line represents a " "separate query.", 100, self) layout.addWidget(QLabel('Query word list:'), row, 0, 1, self.label_width) layout.addWidget(self.query_edit, row, self.label_width, 1, self.widgets_width) # Language row += 1 language_edit = ComboBox(self, 'language', tuple(sorted(lang2code.items()))) layout.addWidget(QLabel('Language:'), row, 0, 1, self.label_width) layout.addWidget(language_edit, row, self.label_width, 1, self.widgets_width) # Articles per query row += 1 layout.addWidget(QLabel('Articles per query:'), row, 0, 1, self.label_width) slider = gui.valueSlider(query_box, self, 'articles_per_query', box='', values=[1, 3, 5, 10, 25]) layout.addWidget(slider.box, row, 1, 1, self.widgets_width) query_box.layout().addLayout(layout) self.controlArea.layout().addWidget(query_box) self.controlArea.layout().addWidget( CheckListLayout('Text includes', self, 'text_includes', self.attributes, cols=2, callback=self.set_text_features)) self.info_box = gui.hBox(self.controlArea, 'Info') self.result_label = gui.label(self.info_box, self, self.info_label.format(0)) self.button_box = gui.hBox(self.controlArea) self.search_button = gui.button(self.button_box, self, 'Search', self.start_stop) self.search_button.setFocusPolicy(Qt.NoFocus) def start_stop(self): if self.search.running: self.search.stop() else: self.search() @asynchronous def search(self): return self.api.search(lang=self.language, queries=self.query_list, articles_per_query=self.articles_per_query, on_progress=self.progress_with_info, should_break=self.search.should_break) @search.callback(should_raise=False) def progress_with_info(self, progress, n_retrieved): self.progressBarSet(100 * progress, None) self.result_label.setText(self.info_label.format(n_retrieved)) @search.on_start def on_start(self): self.Error.api_error.clear() self.progressBarInit(None) self.search_button.setText('Stop') self.result_label.setText(self.info_label.format(0)) self.Outputs.corpus.send(None) @search.on_result def on_result(self, result): self.result = result self.result_label.setText(self.info_label.format(len(result) if result else 0)) self.search_button.setText('Search') self.set_text_features() self.progressBarFinished(None) def set_text_features(self): self.Warning.no_text_fields.clear() if not self.text_includes: self.Warning.no_text_fields() if self.result is not None: vars_ = [var for var in self.result.domain.metas if var.name in self.text_includes] self.result.set_text_features(vars_ or None) self.Outputs.corpus.send(self.result) def send_report(self): if self.result: items = (('Language', code2lang[self.language]), ('Query', self.query_edit.toPlainText()), ('Articles count', len(self.result))) self.report_items('Query', items)
def __init__(self): super().__init__() self.corpus = None self.api = None self.output_info = '' # API token self.api_dlg = self.CredentialsDialog(self) self.api_dlg.accept(silent=True) gui.button(self.controlArea, self, 'AmCAT login', callback=self.api_dlg.exec_, focusPolicy=Qt.NoFocus) # Query query_box = gui.widgetBox(self.controlArea, 'Query', addSpace=True) aset_box = gui.hBox(query_box) project_edit = gui.lineEdit(aset_box, self, 'project', label='Project: ', orientation=1, valueType=str) set_edit = gui.lineEdit(aset_box, self, 'articleset', label='Articleset: ', orientation=1, valueType=str) queryset_box = gui.hBox(query_box) query_box.layout().addWidget( ListEdit(self, 'query', 'One query per line', 80, self)) # Year box def date_changed(): d.picker_to.setVisible( self.date_option in [DATE_BEFORE, DATE_BETWEEN]) d.picker_from.setVisible( self.date_option in [DATE_AFTER, DATE_BETWEEN]) gui.comboBox(query_box, self, 'date_option', items=DATE_OPTIONS, label="Date filter", callback=date_changed) date_box = gui.hBox(query_box) d = DatePickerInterval(date_box, self, 'date_from', 'date_to', min_date=None, max_date=date.today(), margin=(0, 3, 0, 0)) date_changed() # Text includes features self.controlArea.layout().addWidget( CheckListLayout('Text includes', self, 'text_includes', ['Headline', 'Byline', 'Content', 'Section'], cols=2, callback=self.set_text_features)) # Output info_box = gui.hBox(self.controlArea, 'Output') gui.label(info_box, self, 'Articles: %(output_info)s') # Buttons self.button_box = gui.hBox(self.controlArea) self.button_box.layout().addWidget(self.report_button) self.search_button = gui.button(self.button_box, self, 'Search', self.start_stop, focusPolicy=Qt.NoFocus)