Skip to content

Commit

Permalink
[PS] separate summary result rows by target segments
Browse files Browse the repository at this point in the history
re: issue #801
  • Loading branch information
stannam committed Apr 5, 2022
1 parent 672dc98 commit 48db2e0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
18 changes: 13 additions & 5 deletions corpustools/gui/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,14 +562,17 @@ def __init__(self, header, summary_header, results, settings, parent=None):
self.rows = [[data[h] for h in self.header] for data in self.allData]
self.summarized = False

def _summarize(self,segsum):
def _summarize(self, segsum):
typefreq = defaultdict(float)
tokenfreq = defaultdict(float)

for line in self.allData:
if segsum:
segs = line['Target']
envs = line['Environment']

if segs == 'N/A': # search has no hits then continue
continue
else:
segs = line['userinput_target']
envs = line['userinput_env']
Expand All @@ -579,7 +582,7 @@ def _summarize(self,segsum):
pc = line['Min Phoneme Number'], line['Max Phoneme Number'] # phoneme count min/max
sc = line['Min Syllable Number'], line['Max Syllable Number'] # syllable count min/max
filters = wf, pc, sc
for i,seg in enumerate(segs):
for i, seg in enumerate(segs):
segenvfilters = seg, envs[i], filters, tier, res_type # segs + envs + (freq and phoneme/syllable count filters) + result_type
if res_type == 'positive': # if positive search
if line['raw_env'][i] is not None: # then check if the word is in results for satisfying env[i]
Expand Down Expand Up @@ -632,7 +635,7 @@ def setSummarizedData(self):
mini_dict['Token frequency'] = sum([line['Word'].frequency for s in line['Segment']])
self.summarizedAllData.append(mini_dict)

def setSummarized(self, b, segsum=False):
def setSummarized(self, b, segsum):
if self.summarized == b:
return
self.summarized = b
Expand All @@ -653,11 +656,16 @@ def setSummarized(self, b, segsum=False):

self.layoutChanged.emit()

def addRows(self,rows):
def addRows(self, rows, segsum):
'''
Adding phonological search result rows on top of existing results
:param rows: list. rows to add
:param segsum: bool. whether the rows in the summary result should be separated by segments.
'''
self.layoutAboutToBeChanged.emit()
self.allData.extend(rows)
if self.summarized:
self._summarize()
self._summarize(segsum)
self.layoutChanged.emit()

class TreeItem(object):
Expand Down
2 changes: 1 addition & 1 deletion corpustools/gui/psgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ def __init__(self, parent, settings, recents, saved, corpus, inventory, showTool
searchLayout.addWidget(saveSearch)

optionLayout.addWidget(searchFrame)
self.segsum = QCheckBox('summarize target by segments')
self.segsum = QCheckBox('Separate summary rows by segments')
optionLayout.addWidget(self.segsum)
# for additional filters (word/phoneme/syllable frequency filters)
validator = QDoubleValidator(float('inf'), 0, 8) # values should be 0-inf with max 8 sub-decimal digits
Expand Down
15 changes: 8 additions & 7 deletions corpustools/gui/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -860,8 +860,8 @@ def __init__(self, title, dialog, parent):
dataModel = PhonoSearchResultsModel(self.dialog.header,
self.dialog.summary_header,
self.dialog.results, self._parent.settings)
summary_by_seg = dialog.segsum.isChecked()
dataModel.setSummarized(True, summary_by_seg)
self.summary_by_seg = dialog.segsum.isChecked()
dataModel.setSummarized(True, self.summary_by_seg)
self.table.setModel(dataModel)

self.summarized = True
Expand All @@ -878,13 +878,13 @@ def summaryDetail(self):
# label switch.
if self.summarized:
# summarized result -> total result
self.table.model().setSummarized(False) # update table contents
self.table.model().setSummarized(False, self.summary_by_seg) # update table contents
self.individualButton.hide()
self.aclayout.insertWidget(0, self.summaryButton)
self.summaryButton.show()
else:
# total result -> summarized result
self.table.model().setSummarized(True) # update table contents
self.table.model().setSummarized(True, self.summary_by_seg) # update table contents
self.summaryButton.hide()
self.aclayout.insertWidget(0, self.individualButton)
self.individualButton.show()
Expand All @@ -896,17 +896,18 @@ def redo(self):
if self.dialog.update: # when 'Calculate [...] (add to current results table)' selected
if len(self.dialog.results) > 0:
if not self.duplicate_check()[0]:
self.table.model().addRows(self.dialog.results)
self.table.model().addRows(rows=self.dialog.results, segsum=self.dialog.segsum.isChecked())
self.summarized = False
self.table.model().setSummarized(True)
self.table.model().setSummarized(True, self.summary_by_seg)
else: # when 'Calculate [...] (start new results table)' selected
dataModel = PhonoSearchResultsModel(self.dialog.header,
self.dialog.summary_header,
self.dialog.results,
self._parent.settings)
self.table.setModel(dataModel)
self.summarized = False
self.table.model().setSummarized(True)
segsum = self.dialog.segsum.isChecked()
self.table.model().setSummarized(True, segsum)
self.raise_()
self.activateWindow()

Expand Down

0 comments on commit 48db2e0

Please sign in to comment.