Skip to content

Commit

Permalink
[PS] summary results re: #801
Browse files Browse the repository at this point in the history
Passed Tests 1, 2, 3.1, 3.2, and 3.3
Need more work to pass test 3.3, i.e., syllable search with the listing by seg set as False and [sa] and [ʃa] in a single env.
  • Loading branch information
stannam committed May 9, 2022
1 parent 8bc1345 commit b05c9de
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
10 changes: 6 additions & 4 deletions corpustools/gui/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,10 +590,12 @@ def _summarize(self, segsum):
except NameError:
pass
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 or segsum: # then check if the word is in results for satisfying env[i]
typefreq[segenvfilters] += 1 # if so, +1 in the type freq
tokenfreq[segenvfilters] += line['Word'].frequency # and add token freq accordingly
if res_type == 'positive':# if positive search
for ie in line['raw_env']: # ie being Index and Env
if ie[0] == i and ie[1] is not None or segsum: # ie[0] is the env # in the query. ie[1] is not None then that env # gave a search result.
typefreq[segenvfilters] += 1 # Therefore, +1 in the type freq
tokenfreq[segenvfilters] += line['Word'].frequency # and add token freq accordingly
break
else:
typefreq[segenvfilters] += 0
tokenfreq[segenvfilters] += 0
Expand Down
6 changes: 4 additions & 2 deletions corpustools/gui/psgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -878,12 +878,13 @@ def setResults(self, results):
if self.mode == 'segMode':
userinput_target = tuple(', '.join(list(y.original_middle)) for y in self.envWidget.value())
userinput_env = tuple(str(y) for y in self.envWidget.value())
fo = [f[1] for f in found] # fo drops all env# info. i.e., contains environment objects only.

if str(word) == 'N/A' and word.transcription is None: # if there was no hit from the search, side way
res_transcription = target = envs = word.frequency = 'N/A'

else: # regular cases with one or more words searched
f = list(filter(None, found))
f = list(filter(None, fo))
target = tuple(x.middle for x in f)
res_transcription = str(getattr(word, self.tierWidget.value()))
if len(target) == 0 and self.resultType == 'negative':
Expand All @@ -897,12 +898,13 @@ def setResults(self, results):

else: # syllable search mode
userinput_target, userinput_env = self.cleanse_syl_userinput()
fo = [f[1] for f in found] # fo drops all env# info. i.e., contains environment objects only.

if str(word) == 'N/A' and word.transcription is None: # if there was no hit from the search, side way
res_transcription = target = envs = word.frequency = 'N/A'

else: # regular cases with one or more words searched
list_of_sylEnvs = list(filter(None, found))
list_of_sylEnvs = list(filter(None, fo))
target = tuple(
syl.print_syl_structure(env=False) for syl in list_of_sylEnvs) # 'target' column in res. window

Expand Down
13 changes: 7 additions & 6 deletions corpustools/phonosearch/phonosearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,19 @@ def phonological_search(corpus, envs, sequence_type='transcription', call_back=N
tier = getattr(word, sequence_type)
found = []

for env in envs:
for i, env in enumerate(envs):
es = tier.find(env, mode)
try:
found.extend(es)
except TypeError: # when es == None
found.append(es)
found.extend([[i, e] for e in es])
except TypeError: # when es == None
found.append([i, es])

fo = [f[1] for f in found]
if result_type == 'positive':
if not all(e is None for e in found): # if the word satisfies at least one environment,
if not all(e is None for e in fo): # if the word satisfies at least one environment,
results.append((word, found)) # add it to 'results'
else:
if all(e is None for e in found):
if all(e is None for e in fo):
results.append((word, found))

# additional filters
Expand Down

1 comment on commit b05c9de

@stannam
Copy link
Member Author

@stannam stannam commented on b05c9de May 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

edit: It turned out that this commit passes all tests in the comment #801 (comment) .
The hand calculation was wrong in the desired output of 3.3. (The machine was right 🙄.)

Please sign in to comment.