Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1447: Search for glosses with annotated sentences in general search #1455

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions signbank/dictionary/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ class GlossSearchForm(forms.ModelForm):
widget=forms.Select(attrs=ATTRS_FOR_BOOLEAN_FORMS))
hasmultiplesenses = forms.ChoiceField(label=_("Has Multiple Senses"), choices=[(0, '-')],
widget=forms.Select(attrs=ATTRS_FOR_BOOLEAN_FORMS))

hasannotatedsentences = forms.ChoiceField(label=_("Has Annotated Sentences"), choices=[(0, '-')],
widget=forms.Select(attrs=ATTRS_FOR_BOOLEAN_FORMS))
relation = forms.CharField(label=_('Gloss of Related Sign'),
widget=forms.TextInput(attrs=ATTRS_FOR_FORMS))
relationToForeignSign = forms.CharField(label=_('Gloss of Foreign Sign'),
Expand Down Expand Up @@ -347,7 +348,7 @@ def __init__(self, *args, **kwargs):
widget=forms.Select(attrs=ATTRS_FOR_FORMS))
for boolean_field in ['hasvideo', 'repeat', 'altern', 'isNew', 'inWeb', 'defspublished',
'excludeFromEcv', 'hasRelationToForeignSign', 'hasmultiplesenses',
'hasothermedia', 'isablend', 'ispartofablend']:
'hasothermedia', 'isablend', 'ispartofablend', 'hasannotatedsentences']:
self.fields[boolean_field].choices = [('0', '-'), ('2', _('Yes')), ('3', _('No'))]
for boolean_field in ['weakdrop', 'weakprop']:
self.fields[boolean_field].choices = [(0, '-'), (1, _('Neutral')), (2, _('True')), (3, _('False'))]
Expand Down
20 changes: 18 additions & 2 deletions signbank/query_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def query_parameters_this_gloss(phonology_focus, phonology_matrix):
# these mappings match the choices in the Gloss Search Form
NEUTRALBOOLEANCHOICES = {'None': '1', 'True': '2', 'False': '3'}
query_parameters[field_key] = NEUTRALBOOLEANCHOICES[field_value]
elif field_key in ['defspublished', 'hasmultiplesenses']:
elif field_key in ['defspublished', 'hasmultiplesenses', 'hasannotatedsentences']:
# these mappings match the choices in the Gloss Search Form and get_queryset
# some of these are legacy mappings
YESNOCHOICES = {'None': '-', 'True': _('Yes'), 'False': _('No')}
Expand Down Expand Up @@ -283,6 +283,14 @@ def convert_query_parameters_to_filter(query_parameters):
'gloss').annotate(Count('id')).filter(id__count=1)]
query_list.append(Q(id__in=multiple_senses))

elif get_key == 'hasannotatedsentences' and get_value:
glosses_with_annotated_sentences = [gsv['gloss'] for gsv in AnnotatedGloss.objects.values('gloss')]
val = get_value == 'yes'
if val:
query_list.append(Q(pk__in=glosses_with_annotated_sentences))
else:
query_list.append(~Q(pk__in=glosses_with_annotated_sentences))

elif get_key == 'negative' and get_value:
sentences_with_negative_type = ExampleSentence.objects.filter(negative__exact=True)
sentences_with_other_type = ExampleSentence.objects.filter(negative__exact=False)
Expand Down Expand Up @@ -615,7 +623,7 @@ def pretty_print_query_values(dataset_languages,query_parameters):
query_dict[key] = _('No')
elif key in ['inWeb', 'isNew', 'excludeFromEcv', 'hasvideo', 'hasothermedia']:
query_dict[key] = NULLBOOLEANCHOICES[query_parameters[key]]
elif key in ['defspublished', 'hasmultiplesenses', 'negative']:
elif key in ['defspublished', 'hasmultiplesenses', 'negative', 'hasannotatedsentences']:
query_dict[key] = YESNOCHOICES[query_parameters[key]]
elif key in ['hasRelation']:
choices_for_category = [RELATION_ROLE_CHOICES[val] for val in query_parameters[key]]
Expand Down Expand Up @@ -1127,6 +1135,14 @@ def queryset_glosssense_from_get(model, formclass, searchform, GET, qs):
query_filter = gloss_prefix + 'id__in'
qs = qs.filter(**{query_filter: multiple_senses})
continue
elif get_key in ['hasannotatedsentences']:
glosses_with_annotated_sentences = [gsv['gloss'] for gsv in AnnotatedGloss.objects.values('gloss')]
query_filter = gloss_prefix + 'id__in'
if get_value == '2':
qs = qs.filter(**{query_filter: glosses_with_annotated_sentences})
else:
qs = qs.exclude(**{query_filter: glosses_with_annotated_sentences})
continue
elif get_key in ['hasothermedia']:
pks_for_glosses_with_othermedia = [om.parent_gloss.pk for om in OtherMedia.objects.all()]
query_filter = gloss_prefix + 'pk__in'
Expand Down
2 changes: 1 addition & 1 deletion signbank/settings/server_specific/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@

FIELDS['publication'] = ['inWeb', 'isNew']

FIELDS['properties'] = ['hasvideo', 'hasothermedia', 'hasmultiplesenses',
FIELDS['properties'] = ['hasvideo', 'hasothermedia', 'hasmultiplesenses', 'hasannotatedsentences',
'definitionRole', 'definitionContains', 'defspublished',
'createdBy', 'createdAfter', 'createdBefore',
'tags', 'excludeFromEcv']
Expand Down