Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • ipipan/valunifer
1 result
Show changes
Commits on Source (13)
#-*- coding:utf-8 -*-
import datetime
import os
from django.core.management.base import BaseCommand
from optparse import make_option
from unifier.models import UnifiedFrame
from django.contrib.auth.models import User
from users.models import Assignment
from common.valunifier_tei import createteixml
BASEPATH = '.'
class Command(BaseCommand):
args = ''
help = 'Export ValUnifier in TEI format'
def add_arguments(self, parser):
parser.add_argument('-i', '--individual', action='store_true', help='Gen individual files.')
def handle(self, **options):
now = datetime.datetime.now().strftime('%Y%m%d')
if not options['individual']:
print("Full dictionary")
outfile = 'valunifier_' + now + '.xml'
outpath = os.path.join(BASEPATH, outfile)
frames = UnifiedFrame.objects.all()
createteixml(outpath, frames)
else:
for user in User.objects.all():
print("Part for " + user.username)
frames = []
for assignment in Assignment.objects.filter(user=user):
if assignment.subject_ct.model_class() == UnifiedFrame:
frames.append(assignment.subject_ct.get_object_for_this_type(id=assignment.subject_id))
outfile = user.username + '_' + now + '.xml'
outpath = os.path.join(BASEPATH, outfile)
if len(frames) > 0:
createteixml(outpath, frames)
This diff is collapsed.
......@@ -32,5 +32,5 @@ table.table-button-menu {
}
#free-lus-frame .argument.active {
background-color: #dee1e4;
background-color: black;
}
......@@ -12,6 +12,7 @@ var curr_examples_by_id = null;
var roles = []
var role_attributes = []
var role_sub_attributes = []
var frame_opinions = []
function make_opinion_row(item, span, width) {
const opinion_row = document.createElement('tr');
......@@ -1133,6 +1134,18 @@ function getRoleSubAttributes() {
});
}
function getFrameOpinions() {
$.ajax({
dataType: "json",
url: '/' + lang + '/entries/frame_opinions',
success: function(data){
frame_opinions = data.result;
},
async: false
});
}
$(document).ready(function() {
bind_last_visited();
......@@ -1166,6 +1179,8 @@ $(document).ready(function() {
getRoleSubAttributes();
getFrameOpinions();
// $.getJSON('relations', function(data){
// memorizeRelations(data.relations);
// });
......
......@@ -33,8 +33,9 @@
<li class="nav-item mr-1"><a
onclick='window.location.replace(window.currUnifiedFrameId ? "/pl/entries/hierarchy/?unified_frame_id="+window.currUnifiedFrameId : "/pl/entries/hierarchy")'
class="nav-link cursor-pointer">{% trans "Hierarchia" %}</a></li>
<li class="nav-item mr-1"><a href="{% url 'entries:lu_free' %}" class="nav-link">{% trans "Wolne jednostki" %}</a></li>
{% if is_superlexicograf %}
<li class="nav-item mr-1"><a href="{% url 'entries:lu_free' %}" class="nav-link">{% trans "Wolne jednostki" %}</a></li>
{% endif %}
{% endif %}
<li class="nav-item dropdown mr-1">
<a class="nav-link dropdown-toggle mr-1" href="#" id="nav-filters" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
......
......@@ -2,7 +2,7 @@ from django.urls import path
from . import autocompletes, views
from .views import ajax_plWN_context_lookup, ajax_predefined_preferences, ajax_relations, ajax_synsets, ajax_roles, \
ajax_role_attributes, ajax_role_sub_attributes, ajax_free_slowal_frame_lookup
ajax_role_attributes, ajax_role_sub_attributes, ajax_free_slowal_frame_lookup, ajax_frame_opinions
app_name = 'entries'
......@@ -25,6 +25,7 @@ urlpatterns = [
path('plWN_context_lookup/', ajax_plWN_context_lookup, name='plWN_context_lookup'),
path('predefined_preferences/', ajax_predefined_preferences, name='predefined_preferences'),
path('roles/', ajax_roles, name='roles'),
path('frame_opinions/', ajax_frame_opinions, name='frame_opinions'),
path('role_attributes/', ajax_role_attributes, name='role_attributes'),
path('role_sub_attributes/', ajax_role_sub_attributes, name='role_sub_attributes'),
path('relations/', ajax_relations, name='relations'),
......
......@@ -21,7 +21,7 @@ from connections.models import Entry, Subentry, ArgumentConnection, RealisationD
from meanings.models import LexicalUnit
from syntax.models import NaturalLanguageDescription, Schema
from semantics.models import Frame, PredefinedSelectionalPreference, SelectivePreferenceRelations, SemanticRole, \
RoleAttribute, RoleSubAttribute, SelectionalPreferenceRelation
RoleAttribute, RoleSubAttribute, SelectionalPreferenceRelation, FrameOpinion
from common.decorators import ajax_required, ajax
from unifier.models import UnifiedFrame
......@@ -99,6 +99,7 @@ def hierarchy(request):
if "unified_frame_id" in request.GET:
unified_frame_id = request.GET.get("unified_frame_id")
user = request.user
return render(
request,
'hierarchy.html',
......@@ -109,6 +110,7 @@ def hierarchy(request):
'frames_form': FrameFormFactory.get_form(as_subform=False),
'schemata_form': SchemaFormFactory.get_form(as_subform=False),
'unified_frames_form': UnifiedFrameFormFactory.get_form(as_subform=False),
'is_superlexicograf': user.groups.filter(name=settings.SUPER_LEXICOGRAPHS_GROUP_NAME).exists()
},
)
......@@ -120,6 +122,7 @@ def lu_free(request):
if "unified_frame_id" in request.GET:
unified_frame_id = request.GET.get("unified_frame_id")
user = request.user
return render(
request,
'lu_free.html',
......@@ -130,6 +133,7 @@ def lu_free(request):
'frames_form': FrameFormFactory.get_form(as_subform=False),
'schemata_form': SchemaFormFactory.get_form(as_subform=False),
'unified_frames_form': UnifiedFrameFormFactory.get_form(as_subform=False),
'is_superlexicograf': user.groups.filter(name=settings.SUPER_LEXICOGRAPHS_GROUP_NAME).exists()
},
)
......@@ -414,10 +418,12 @@ def get_scroller_params(POST_data):
#from django.db.models import Count
def iter_lexical_units(lexical_units, has_unified_frame='false'):
def iter_lexical_units(lexical_units, has_unified_frame='false', exclude_status=None):
for lu in lexical_units:
lu._frame = lu._frames[0] if lu._frames and len(lu._frames) > 0 else None
if lu._frame is None or (not hasattr(lu._frame, 'slowal_frame_2_unified_frame') and has_unified_frame == 'true'):
if lu._frame is None or \
(not hasattr(lu._frame, 'slowal_frame_2_unified_frame') and has_unified_frame == 'true') or \
(exclude_status is not None and lu._frame.status == exclude_status):
continue
else:
yield lu
......@@ -446,8 +452,7 @@ def get_entries(request):
#entries = entries.filter(subentries__schema_hooks__alternation=2)
if without_frames:
entries = entries.filter(name__in=(LexicalUnit.objects.filter(frames__isnull=True).values("base")))
print('entries.query: ', entries.query)
entries = entries.filter(name__in=(LexicalUnit.objects.filter(Q(frames__isnull=True) | Q(frames__in_building=True)).values("base")))
total = entries.count()
if scroller_params['filter']:
......@@ -505,7 +510,7 @@ def get_entries(request):
)
)
if exclude_status is not None:
entries = entries.filter(lexical_units__frames__status__iexact=exclude_status)
entries = entries.exclude(lexical_units__frames__status=exclude_status)
entries = entries.filter(lexical_units__frames__isnull=False)
if has_unified_frame == 'true':
entries = entries.filter(lexical_units__frames__slowal_frame_2_unified_frame__isnull=False)
......@@ -530,7 +535,7 @@ def get_entries(request):
**(
{
'lexical_units': [
lu2dict(lu) for lu in iter_lexical_units(e.lexical_units.all(), has_unified_frame)
lu2dict(lu) for lu in iter_lexical_units(e.lexical_units.all(), has_unified_frame, exclude_status=exclude_status)
]
}
if with_lexical_units else {}
......@@ -757,10 +762,13 @@ def get_examples(entry):
if connection.lexical_unit:
lu_ids.add(connection.lexical_unit.id)
for hook in connection.schema_connections.all():
schema_ids.add(hook.schema.id);
schema_ids.add(hook.schema.id)
phrases.add('{}-{}-{}-{}'.format(hook.schema.id, hook.position.id, hook.phrase_type.id, hook.alternation - 1))
phrases_syntax.add('{}-{}-{}'.format(hook.schema.id, hook.position.id, hook.phrase_type.id))
positions.add('{}-{}'.format(hook.schema.id, hook.position.id))
for argument_connection in hook.argument_connections.all():
frame_ids.add(argument_connection.argument.frame.id)
argument_ids.add('{}-{}'.format(argument_connection.argument.frame.id, argument_connection.argument.id))
examples.append({
'id' : str(example.id),
'sentence' : example.sentence,
......@@ -923,7 +931,7 @@ def get_entry(request):
schemata.append(schema2dict(schema, subentry.negativity, request.LANGUAGE_CODE))
if schemata:
all_schema_objects += list(schema_objects)
subentries.append({ 'str' : subentry2str(subentry), 'schemata' : schemata })
subentries.append({'str': subentry2str(subentry), 'id': subentry.id, 'schemata': schemata})
# frame_objects = Frame.objects.filter(arguments__argument_connections__schema_connections__subentry__entry=entry).distinct()
frame_objects = Frame.objects.filter(lexical_units__entry=entry).distinct()
# filter out frames by frame properties
......@@ -1071,6 +1079,15 @@ def ajax_roles(request):
return context
@ajax(method='get', encode_result=True)
def ajax_frame_opinions(request):
opinions = []
for opinion in FrameOpinion.objects.exclude(key='unk').filter(frame__isnull=False).distinct().order_by('priority'):
opinions.append({"id": opinion.id, "key": str(FRAME_OPINION()[opinion.key])})
return {'result': opinions}
@ajax(method='get', encode_result=True)
def ajax_role_attributes(request):
roleAttributes = []
......@@ -1155,3 +1172,5 @@ def ajax_free_slowal_frame_lookup(request, term):
lexical_unit_str.append(str(lexical_unit))
return {'result': lexical_unit_str}
......@@ -84,9 +84,9 @@ class ApiTest(TestCase):
request = self.factory.post("/pl/freelus/attach_examples_to_frame/",
HTTP_X_REQUESTED_WITH='XMLHttpRequest',
data={'frame_id': frame.pk,
'argument_id': argument.pk,
'selected_lus': json.dumps([self.lu.pk], separators=(',', ':')),
'example_ids': json.dumps([self.example.pk], separators=(',', ':'))})
response = attach_examples_to_frame(request)
examples = ExampleConnection.objects.filter(arguments=argument)
examples = ExampleConnection.objects.filter(lexical_unit=self.lu)
self.assertEqual(1, examples.count())
......@@ -13,5 +13,9 @@ urlpatterns = [
path('delete_schema_to_argument_connection/', views.delete_schema_to_argument_connection,
name='delete_schema_to_argument_connection'),
path('finish_frame_processing/', views.finish_frame_processing, name='finish_frame_processing'),
path('remove_argument_from_frame/', views.remove_argument_from_frame, name='remove_argument_from_frame'),
path('change_lus_in_slowal_frame/', views.change_lus_in_slowal_frame, name='change_lus_in_slowal_frame'),
path('change_frame_opinion/', views.change_frame_opinion, name='change_frame_opinion'),
]
......@@ -4,26 +4,60 @@ from django.http import JsonResponse
from common.decorators import ajax_required
from connections.models import Entry, Status, ExampleConnection, SchemaHook, ArgumentConnection, RealisationDescription
from examples.models import Example
from meanings.models import LexicalUnit
from semantics.models import Frame, FrameOpinion, Argument, ArgumentRole, SemanticRole, \
RoleAttribute, RoleSubAttribute, RoleType
from syntax.models import Position
@ajax_required
@transaction.atomic
def change_status(request):
def change_frame_opinion(request):
"""
Changing status of slowal frame in building process.
The request has to contain 'entry_id' and 'status'.
Changing opinion of slowal frame in building process.
The request has to contain 'frame_id' and 'opinion_id'.
:param request: http request
:return: Empty json response
"""
if request.method == 'POST':
frame_id = request.POST['frame_id']
opinion_id = request.POST['opinion_id']
frame = Frame.objects.get(pk=frame_id)
frame.opinion_id = opinion_id
frame.save()
return JsonResponse({})
return JsonResponse({})
@ajax_required
@transaction.atomic
def change_lus_in_slowal_frame(request):
"""
Change lus assigned to slowal frame.
The request has to contain 'entry_id' and 'lu_ids' list for witch slowal frame has to be created.
:param request: http request
:return: Empty json response
"""
if request.method == 'POST':
entry_id = request.POST['entry_id']
status = request.POST['status']
frame_id = request.POST['frame_id']
lu_ids = json.loads(request.POST['lu_ids'])
frame = Frame.objects.get(id=frame_id)
frame.lexical_units.clear()
entry = Entry.objects.get(pk=entry_id)
entry.status = Status.objects.get(key=status)
entry.lexical_units.clear()
for lu_id in lu_ids:
lu = LexicalUnit.objects.get(pk=lu_id)
lu.entry = entry
lu.save()
frame.lexical_units.add(lu)
entry.lexical_units_count = entry.lexical_units_count + 1
frame.save()
entry.save()
return JsonResponse({})
......@@ -82,6 +116,28 @@ def add_argument_to_frame(request):
return JsonResponse({})
@ajax_required
@transaction.atomic
def remove_argument_from_frame(request):
"""
Removing argument from the specified slowal frame in building process.
The request has to contain 'argument_id'.
:param request: http request
:return: Empty json response
"""
if request.method == 'POST':
# frame_id = request.POST['frame_id']
argument_id = request.POST['argument_id']
# frame = Frame.objects.get(id=frame_id)
ArgumentConnection.objects.filter(argument_id=argument_id).delete()
Argument.objects.get(id=argument_id).delete()
return JsonResponse({})
return JsonResponse({})
@ajax_required
@transaction.atomic
def change_role(request):
......@@ -123,28 +179,24 @@ def change_role_base(frame_argument, request):
@transaction.atomic
def attach_examples_to_frame(request):
"""
Attaching selected examples to the slowal frame in building process.
The request has to contain 'frame_id' and 'argument_id' that represents slowal frame in building process.
Attaching selected examples to the lus.
The request has to contain 'selected_lus' that represents lu ids.
List of example ids ('example_ids') is also required.
:param request: http request
:return: Empty json response
"""
if request.method == 'POST':
frame_id = request.POST['frame_id']
argument_id = request.POST['argument_id']
example_ids = json.loads(request.POST['example_ids'])
selected_lus = json.loads(request.POST['selected_lus'])
argument = Argument.objects.get(id=argument_id)
frame = Frame.objects.get(id=frame_id)
lexical_units = frame.lexical_units.all()
lexical_units = LexicalUnit.objects.filter(id__in=selected_lus).all()
for lexical_unit in lexical_units:
ExampleConnection.objects.filter(lexical_unit=lexical_unit).delete()
for example_id in example_ids:
for lexical_unit in lexical_units:
example_conn = ExampleConnection(example_id=example_id, lexical_unit=lexical_unit)
example_conn.save()
example_conn.arguments.add(argument)
example_conn.save()
return JsonResponse({})
......@@ -159,28 +211,46 @@ def attach_schema_to_argument(request):
:return: Empty json response
"""
if request.method == 'POST':
frame_id = request.POST['frame_id']
argument_id = request.POST['argument_id']
schema_id = request.POST['schema_id']
schema_position_id = request.POST['schema_position_id']
frame_id = int(request.POST['frame_id'])
subentry_id = int(request.POST['subentry_id'])
argument_id = int(request.POST['argument_id'])
schema_id = int(request.POST['schema_id'])
schema_position_id = int(request.POST['schema_position_id'])
schema_alternation_id = int(request.POST['schema_alternation_id'])
argument = Argument.objects.get(id=argument_id)
schema_hooks = SchemaHook.objects.filter(schema_id=schema_id, position_id=schema_position_id)
if len(schema_hooks) > 0:
schema_hook = schema_hooks[0]
argument_connection, xxx = ArgumentConnection.objects.get_or_create(argument=argument,
defaults={'argument': argument})
argument_connection.save()
argument_connection.schema_connections.add(schema_hook)
argument_connection.save()
RealisationDescription.objects.get_or_create(frame_id=frame_id,
schema_id=schema_id,
defaults={'alternation': 1,
'description': ''})
return JsonResponse({})
if not ArgumentConnection.objects.filter(argument=argument, schema_connections__schema_id=schema_id).exists():
position = Position.objects.get(id=schema_position_id)
for phrase_type in position.phrase_types.all():
schema_hooks = SchemaHook.objects.filter(subentry_id=subentry_id, schema_id=schema_id,
position_id=schema_position_id, phrase_type=phrase_type,
alternation=schema_alternation_id)
if not schema_hooks.exists():
schema_hooks = [SchemaHook.objects.create(subentry_id=subentry_id, schema_id=schema_id,
position_id=schema_position_id, phrase_type=phrase_type,
alternation=schema_alternation_id)]
# examples = Example.objects.filter(example_connections__schema_connections__in=schema_hooks)
# for example in examples:
# ExampleConnection.objects.get_or_create(example=example, argument=argument, schema_hook)
argument_connection, _ = ArgumentConnection.objects.get_or_create(argument=argument,
defaults={'argument': argument})
argument_connection.save()
for schema_hook in schema_hooks:
argument_connection.schema_connections.add(schema_hook)
argument_connection.save()
RealisationDescription.objects.get_or_create(frame_id=frame_id,
schema_id=schema_id,
defaults={'alternation': schema_alternation_id,
'description': ''})
return JsonResponse({'succ': True})
else:
return JsonResponse({'succ': False, 'error': 'Odrzucono próbę połączenia. Argument jest już podłączony do innej pozycji w wybranym schemacie.'})
else:
return JsonResponse({'succ': False, 'error': 'Not a Post request.'})
@ajax_required
......@@ -195,14 +265,18 @@ def delete_schema_to_argument_connection(request):
if request.method == 'POST':
argument_id = request.POST['argument_id']
schema_id = request.POST['schema_id']
subentry_id = request.POST['subentry_id']
schema_position_id = request.POST['schema_position_id']
schema_alternation_id = request.POST['schema_alternation_id']
argument = Argument.objects.get(id=argument_id)
schema_hooks = SchemaHook.objects.filter(schema_id=schema_id, position=schema_position_id)
argument_connection = ArgumentConnection.objects.get(argument=argument)
argument_connection.schema_connections.remove(schema_hooks[0])
schema_hooks = SchemaHook.objects.filter(subentry_id=subentry_id, schema_id=schema_id,
position_id=schema_position_id,
alternation=schema_alternation_id)
for schema_hook in schema_hooks.all():
argument_connection.schema_connections.remove(schema_hook)
argument_connection.save()
return JsonResponse({})
......
......@@ -103,7 +103,7 @@
});
this.$emit('schemataSelected', selected);
},
selectSchemaPosition(schema, position) {
selectSchemaPosition(schema, position, subentry, alternation_id) {
this.subentries.forEach(subentry => {
subentry.schemata.forEach(s => {
s.selected = false;
......@@ -111,12 +111,12 @@
});
if(this.selected_schemata_position_id != position.id) {
this.selected_schemata_position_id = position.id;
this.$emit('schemaPositionSelected', this.selected_schemata_position_id);
this.$emit('schemaPositionSelected', this.selected_schemata_position_id, subentry, alternation_id);
this.$emit('schemataSelected', [schema]);
} else {
this.selected_schemata_position_id = null;
this.$emit('schemaPositionSelected', null);
this.$emit('schemataSelected', []);
this.$emit('schemaPositionSelected', null, null, null);
this.$emit('schemataSelected', null);
}
},
computePositionCSS(position) {
......@@ -172,7 +172,7 @@
<tr class="phrase-types alt-0">
<th scope="row" class="py-0 px-1 text-secondary">Typy fraz</th>
<td v-for="position in schema.positions" class="px-0 py-0 border-top border-left border-secondary"
@click.stop="selectSchemaPosition(schema, position)"
@click.stop="selectSchemaPosition(schema, position, subentry, index)"
@mouseenter="position.hover=true"
@mouseleave="position.hover=false"
:class="computePositionCSS(position)">
......@@ -194,7 +194,7 @@
<tr class="phrase-types alt-0">
<th scope="row" class="py-0 px-1 text-secondary">Typy fraz</th>
<td v-for="position in schema.positions" class="px-0 py-0 border-top border-left border-secondary"
@click.stop="selectSchemaPosition(schema, position)"
@click.stop="selectSchemaPosition(schema, position, subentry, 0)"
@mouseenter="position.hover=true"
@mouseleave="position.hover=false"
:class="computePositionCSS(position)">
......
......@@ -79,7 +79,8 @@ class WalentyTeiHandler(handler.ContentHandler):
entry = Entry(self._subtree, self._entry_meanings, self._meanings, self._frames, self._examples_in, self._examples_out, self._misconnected_out)
if not connections.models.Entry.objects.filter(id=int(entry._id)).exists():
print("Entry not exists in database: {}, status: {}".format(entry._base, entry._status))
if entry._status == '(S) sprawdzone' or entry._status == 'sprawdzone' or entry._status == '(S) gotowe':
if entry._status == '(F) sprawdzone' or entry._status == '(S) w obróbce' or \
entry._status == '(S) sprawdzone' or entry._status == 'sprawdzone' or entry._status == '(S) gotowe':
entry.store(self._meanings, self._stored_positions)
else:
print("Odrzucono niegotowe: {}, status: {}".format(entry._base, entry._status))
......