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
Select Git revision
  • hierarchy
  • lu_without_semantic_frames
  • master
  • vertical_relations
  • additional-unification-filters
  • v0.0.1
  • v0.0.2
  • v0.0.3
  • v0.0.4
  • v0.0.5
  • v0.0.6
  • v0.0.7
  • v0.0.8
  • v0.0.9
  • v0.1.0
  • v0.1.1
16 results

Target

Select target project
  • ipipan/valunifer
1 result
Select Git revision
  • hierarchy
  • lu_without_semantic_frames
  • master
  • vertical_relations
  • additional-unification-filters
  • v0.0.1
  • v0.0.2
  • v0.0.3
  • v0.0.4
  • v0.0.5
  • v0.0.6
  • v0.0.7
  • v0.0.8
  • v0.0.9
  • v0.1.0
  • v0.1.1
16 results
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)
#-*- coding:utf-8 -*-
import datetime
from django.db.models import Count, Min, Max
from lxml import etree
from xml.sax.saxutils import escape
from unifier.models import UnifiedFrame2SlowalFrameMapping, \
UnifiedFrameArgumentSlowalFrameMapping
from connections.models import ArgumentConnection
from collections import defaultdict
XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace'
def createteixml(outpath, unified_frames):
root = write_root()
write_header(root)
write_content(root, unified_frames)
with open(outpath, 'wb') as output_file:
root.getroottree().write(output_file,
encoding='UTF-8',
pretty_print=True,
xml_declaration=True,
doctype=u'<!DOCTYPE TEI SYSTEM "tei_all.dtd">')
def write_root():
root = etree.Element('TEI')
root.attrib[etree.QName(XML_NAMESPACE, 'lang')] = u'pl'
root.attrib['xmlns'] = u'http://www.tei-c.org/ns/1.0'
return root
def write_header(root, extensions_file=False):
tei_header = etree.SubElement(root, 'teiHeader')
file_desc = etree.SubElement(tei_header, 'fileDesc')
title_stmt = etree.SubElement(file_desc, 'titleStmt')
title = etree.SubElement(title_stmt, 'title')
title.text = u'ValUnifier (?)'
publication_stmt = etree.SubElement(file_desc, 'publicationStmt')
publisher = etree.SubElement(publication_stmt, 'publisher')
publisher.text = u'Institute of Computer Science, Polish Academy of Sciences (IPI PAN)'
date = etree.SubElement(publication_stmt, 'date')
date.attrib['when'] = datetime.datetime.now().strftime('%Y-%m-%d')
write_license_elem(publication_stmt)
source_desc = etree.SubElement(file_desc, 'sourceDesc')
p = etree.SubElement(source_desc, 'p')
p.text = u'?'
def write_license_elem(parent):
availability = etree.SubElement(parent, 'availability')
licence = etree.SubElement(availability, 'licence')
licence.attrib['target'] = u'http://creativecommons.org/licenses/by-sa/4.0/'
p = etree.SubElement(licence, 'p')
p.text = u'(C) Copyright 2012–2018 by the Institute of Computer Science, Polish Academy of Sciences (IPI PAN)'
p = etree.SubElement(licence, 'p')
p.text = u'This work is distributed under a CC BY-SA license: http://creativecommons.org/licenses/by-sa/4.0/'
p = etree.SubElement(licence, 'p')
p.text = '?'
def write_content(root, unified_frames):
text = etree.SubElement(root, 'text')
body = etree.SubElement(text, 'body')
schemata = etree.SubElement(body, 'div')
frames = etree.SubElement(body, 'div')
used_schemata = set()
write_unified_frames(frames, unified_frames, used_schemata)
write_used_schemata(schemata, used_schemata)
#=================== DIV -- SEMANTIC FRAMES ===================#
def write_unified_frames(parent, unified_frames, used_schemata):
frames_head = etree.SubElement(parent, 'head')
frames_head.text = 'Semantic Frames'
for unified_frame in unified_frames:
write_unified_frame_entry(parent, unified_frame, used_schemata)
def write_unified_frame_entry(parent, unified_frame, used_schemata):
entry_xml_id = u'unif_%d-ent' % unified_frame.id
entry = etree.SubElement(parent, 'entry')
entry.attrib[etree.QName(XML_NAMESPACE, 'id')] = entry_xml_id
write_unified_frame_definition(entry, unified_frame)
write_status_info(entry, unified_frame)
write_unified_frame(entry, unified_frame)
write_unified_frames_realizations(entry, unified_frame, used_schemata)
def write_unified_frame_definition(entry, unified_frame):
definition = etree.SubElement(entry, 'def')
definition.text = unified_frame.title
def write_status_info(parent, unified_frame):
general_fs = etree.SubElement(parent, 'fs')
general_fs.attrib['type'] = 'general_info'
status_f = etree.SubElement(general_fs, 'f')
status_f.attrib['name'] = 'status'
status_string = etree.SubElement(status_f, 'string')
status_string.text = unified_frame.status
#=================== FS TYPE = "FRAME" ===================#
def write_unified_frame(parent, unified_frame):
frame_xml_id = u'unif_%d-frm' % unified_frame.id
frame_fs = etree.SubElement(parent, 'fs')
frame_fs.attrib[etree.QName(XML_NAMESPACE, 'id')] = frame_xml_id
frame_fs.attrib['type'] = 'frame'
write_frame_arguments(frame_fs, unified_frame)
def write_frame_arguments(parent, unified_frame):
arguments_f = etree.SubElement(parent, 'f')
arguments_f.attrib['name'] = 'arguments'
vColl = etree.SubElement(arguments_f, 'vColl')
vColl.attrib['org'] = 'set'
for arg in unified_frame.sorted_arguments():
write_frame_argument(vColl, unified_frame, arg)
def write_frame_argument(parent, frame, arg):
arg_base_id = u'unif_%d' % frame.id
arg_xml_id = arg_base_id + u'.%d-arg' % arg.id
argument_fs = etree.SubElement(parent, 'fs')
argument_fs.attrib[etree.QName(XML_NAMESPACE, 'id')] = arg_xml_id
argument_fs.attrib['type'] = 'argument'
write_roles(argument_fs, arg)
write_selectional_preferences(argument_fs, arg, arg_base_id)
def write_roles(parent, arg):
if arg.role_type is not None:
role_type_f = etree.SubElement(parent, 'f')
role_type_f.attrib['name'] = 'role_type'
role_type_symbol = etree.SubElement(role_type_f, 'symbol')
role_type_symbol.attrib['value'] = arg.role_type.type
role_f = etree.SubElement(parent, 'f')
role_f.attrib['name'] = 'role'
role_symbol = etree.SubElement(role_f, 'symbol')
if arg.role is None:
role_symbol.attrib['value'] = '/'.join([r.role.role for r in arg.proposed_roles.all()])
else:
role_symbol.attrib['value'] = arg.role.role.role
if arg.role.attribute is not None and arg.role.sub_attribute is not None:
attributes_f = etree.SubElement(parent, 'f')
attributes_f.attrib['name'] = 'arributes'
vColl = etree.SubElement(attributes_f, 'vColl')
vColl.attrib['org'] = 'set'
if arg.role.attribute is not None:
write_role_attribute(vColl, arg.role.attribute.attribute)
if arg.role.sub_attribute is not None:
write_role_attribute(vColl, arg.role.sub_attribute.sub_attribute)
def write_role_attribute(parent, symbol):
attribute_symbol = etree.SubElement(parent, 'symbol')
attribute_symbol.attrib['value'] = symbol
def write_selectional_preferences(parent, arg, arg_base_id):
if len(arg.predefined.all()) > 0 or\
len(arg.synsets.all()) > 0 or\
len(arg.relations.all()) > 0:
sel_prefs_f = etree.SubElement(parent, 'f')
sel_prefs_f.attrib['name'] = 'sel_prefs'
sel_prefs_groups_fs = etree.SubElement(sel_prefs_f, 'fs')
sel_prefs_groups_fs.attrib['type'] = 'sel_prefs_groups'
write_synsets_selprefs(sel_prefs_groups_fs, arg)
write_predefined_selprefs(sel_prefs_groups_fs, arg)
write_relation_selprefs(sel_prefs_groups_fs, arg, arg_base_id)
def write_synsets_selprefs(parent, arg):
synsets = arg.synsets.all()
if len(synsets) > 0:
synsets_f = etree.SubElement(parent, 'f')
synsets_f.attrib['name'] = 'synsets'
vColl = etree.SubElement(synsets_f, 'vColl')
vColl.attrib['org'] = 'set'
for synset in synsets:
write_synset(vColl, synset)
def write_synset(parent, synset):
id_numeric = etree.SubElement(parent, 'numeric')
id_numeric.attrib['value'] = str(synset.id)
def write_predefined_selprefs(parent, arg):
predefs = arg.predefined.all()
if len(predefs) > 0:
predefs_f = etree.SubElement(parent, 'f')
predefs_f.attrib['name'] = 'predefs'
vColl = etree.SubElement(predefs_f, 'vColl')
vColl.attrib['org'] = 'set'
for predef in predefs:
write_predef(vColl, predef)
def write_predef(parent, predef):
name_symbol = etree.SubElement(parent, 'symbol')
name_symbol.attrib['value'] = predef.name
def write_relation_selprefs(parent, arg, arg_base_id):
relations = arg.relations.all()
if len(relations) > 0:
relations_f = etree.SubElement(parent, 'f')
relations_f.attrib['name'] = 'relations'
vColl = etree.SubElement(relations_f, 'vColl')
vColl.attrib['org'] = 'set'
for relation in relations:
write_relation(vColl, relation, arg_base_id)
def write_relation(parent, relation, arg_base_id):
relation_fs = etree.SubElement(parent, 'fs')
relation_fs.attrib['type'] = 'relation'
relation_f = etree.SubElement(relation_fs, 'f')
relation_f.attrib['name'] = 'type'
type_symbol = etree.SubElement(relation_f, 'symbol')
type_symbol.attrib['value'] = relation.relation.key
to_f = etree.SubElement(relation_fs, 'f')
to_f.attrib['name'] = 'to'
to_xml_link = '#%s.%d-arg' % (arg_base_id, relation.to.id)
arg_link = etree.SubElement(to_f, 'fs')
arg_link.attrib['sameAs'] = to_xml_link
arg_link.attrib['type'] = 'argument'
#=================== FS TYPE = "FRAME_REALIZATIONS" ===================#
def write_unified_frames_realizations(entry, unified_frame, used_schemata):
realizations_fs = etree.SubElement(entry, 'fs')
realizations_fs.attrib['type'] = 'frame_realizations'
realizations_f = etree.SubElement(realizations_fs, 'f')
realizations_f.attrib['name'] = 'realizations'
vColl = etree.SubElement(realizations_f, 'vColl')
vColl.attrib['org'] = 'set'
write_lexical_units_realizations(vColl, unified_frame, used_schemata)
def write_lexical_units_realizations(parent, unified_frame, used_schemata):
frames_mappings = UnifiedFrame2SlowalFrameMapping.objects.filter(unified_frame=unified_frame,\
removed=False)
lexical_units_sortable = {}
lexical_unit_mapping = {}
for mapping in frames_mappings:
frame = mapping.slowal_frame
for lexical_unit in frame.lexical_units.all():
lexical_unit_mapping[lexical_unit] = mapping
lexical_units_sortable[(lexical_unit.base, lexical_unit.sense)] = lexical_unit
for signature in sorted(lexical_units_sortable.keys()):
lexical_unit = lexical_units_sortable[signature]
mapping = lexical_unit_mapping[lexical_unit]
write_lexical_unit_realization(parent, unified_frame, lexical_unit, mapping, used_schemata)
def write_lexical_unit_realization(parent, unified_frame, lexical_unit, mapping, used_schemata):
lexical_unit_realizations_fs = etree.SubElement(parent, "fs")
lexical_unit_realizations_fs.attrib['type'] = "lexical_unit_realizations"
lexical_unit_f = etree.SubElement(lexical_unit_realizations_fs, "f")
lexical_unit_f.attrib['name'] = 'lexical_unit'
write_lexical_unit(lexical_unit_f, lexical_unit, mapping)
syntactic_realizations_f = etree.SubElement(lexical_unit_realizations_fs, 'f')
syntactic_realizations_f.attrib['name'] = 'syntactic_realizations'
vColl = etree.SubElement(syntactic_realizations_f, 'vColl')
vColl.attrib['org'] = 'set'
write_alternations(vColl, unified_frame, lexical_unit, mapping, used_schemata)
def write_lexical_unit(parent, lexical_unit, mapping):
meaning_fs = etree.SubElement(parent, 'fs')
meaning_fs.attrib['type'] = 'lexical_unit'
name_f = etree.SubElement(meaning_fs, 'f')
name_f.attrib['name'] = 'name'
name_content = etree.SubElement(name_f, 'string')
name_content.text = lexical_unit.base
variant_f = etree.SubElement(meaning_fs, 'f')
variant_f.attrib['name'] = 'variant'
variant_string = etree.SubElement(variant_f, 'string')
variant_string.text = lexical_unit.sense
if lexical_unit.luid is not None:
plwnluid_f = etree.SubElement(meaning_fs, 'f')
plwnluid_f.attrib['name'] = 'plwnluid'
plwnluid_numeric = etree.SubElement(plwnluid_f, 'numeric')
plwnluid_numeric.attrib['value'] = str(lexical_unit.luid)
if lexical_unit.synset is not None and lexical_unit.synset.id > 0:
plwnsid_f = etree.SubElement(meaning_fs, 'f')
plwnsid_f.attrib['name'] = 'plwnsid'
plwnsid_numeric = etree.SubElement(plwnsid_f, 'numeric')
plwnsid_numeric.attrib['value'] = str(lexical_unit.synset.id)
slowal_frame = mapping.slowal_frame
if slowal_frame.opinion is not None:
opinion_f = etree.SubElement(meaning_fs, 'f')
opinion_f.attrib['name'] = 'opinion'
opinion_symbol = etree.SubElement(opinion_f, 'symbol')
opinion_symbol.attrib['value'] = slowal_frame.opinion.key
def write_alternations(parent, unified_frame, lexical_unit, mapping, used_schemata):
alternations = prepare_alternations(mapping, used_schemata)
for key in sorted(alternations.keys()):
alternation_fs = etree.SubElement(parent, 'fs')
alternation_fs.attrib['type'] = 'aternation'
connections_f = etree.SubElement(alternation_fs, 'f')
connections_f.attrib['name'] = 'connections'
vColl = etree.SubElement(connections_f, 'vColl')
vColl.attrib['org'] = 'set'
for argument, schema_hooks in alternations[key].items():
connection_fs = etree.SubElement(vColl, 'fs')
connection_fs.attrib['type'] = 'connection'
argument_f = etree.SubElement(connection_fs, 'f')
argument_f.attrib['name'] = 'argument'
argument_fs = etree.SubElement(argument_f, 'fs')
argument_fs.attrib['type'] = 'argument'
argument_fs.attrib['sameAs'] = u'#unif_%d.%d-arg' % (unified_frame.id, argument.id)
phrases_f = etree.SubElement(connection_fs, 'f')
write_phrases_coll(phrases_f, schema_hooks)
def prepare_alternations(mapping, used_schemata):
argument_mappings = UnifiedFrameArgumentSlowalFrameMapping.objects.filter(unified_frame_mapping = mapping)
alternations = defaultdict(lambda: defaultdict(lambda: []))
for argument_mapping in argument_mappings:
uargument = argument_mapping.unified_agrument
sargument = argument_mapping.slowal_agrument
argument_realization = ArgumentConnection.objects.get(argument = sargument)
by_schema_realizations = argument_realization.schema_connections.all()
for schema_hook in by_schema_realizations:
subentry = schema_hook.subentry
schema = schema_hook.schema
used_schemata.add((subentry, schema))
alternation = schema_hook.alternation
alternations[(subentry.id, schema.id, alternation)][uargument].append(schema_hook)
return alternations
def write_phrases_coll(parent, phrases_list):
vColl = etree.SubElement(parent, 'vColl')
vColl.attrib['org'] = 'set'
for phrase in phrases_list:
phrase_fs = etree.SubElement(vColl, 'fs')
phrase_fs.attrib['type'] = 'phrase'
phrase_fs.attrib['sameAs'] = u'#unif_%d.%d.%d.%d-phr' %(phrase.subentry.id, phrase.schema.id, phrase.position.id, phrase.phrase_type.id)
#=================== DIV -- SYNTACTIC SCHEMATA ===================#
def write_used_schemata(parent, used_schemata):
schemata_head = etree.SubElement(parent, 'head')
schemata_head.text = 'Syntactic Schemata'
for subentry, schema in used_schemata:
write_schema_entry(parent, subentry, schema)
def write_schema_entry(parent, subentry, schema):
entry_xml_id = u'unif_%d.%d-schent' %(subentry.id, schema.id)
entry = etree.SubElement(parent, 'entry')
entry.attrib[etree.QName(XML_NAMESPACE, 'id')] = entry_xml_id
write_schema_definition(entry, subentry, schema)
write_schema(entry, subentry, schema)
def write_schema_definition(parent, subentry, schema):
pass
def write_schema(parent, subentry, schema):
schema_xml_id = u'unif_%d.%d-sch' %(subentry.id, schema.id)
schema_fs = etree.SubElement(parent, 'fs')
schema_fs.attrib[etree.QName(XML_NAMESPACE, 'id')] = schema_xml_id
schema_fs.attrib['type'] = 'schema'
# textual representation @TODO -- not present in the database
# text_rep_f_elem = etree.SubElement(schema_fs_elem, 'f')
# text_rep_f_elem.attrib['name'] = 'text_rep'
# text_rep_string = etree.SubElement(text_rep_f_elem, 'string')
# text_rep = schema.get_position_spaced_text_rep()
# if schema.characteristics.filter(type=u'ZWROTNOŚĆ', value__value=u'się').exists():
# text_rep = ' ' + text_rep
# text_rep_string.text = lemma.entry_obj.name + text_rep.replace(':',': ')
# schema opinion
schema_opinion = schema.opinion.key
if schema.opinion.key is None:
schema_opinion = 'unk'
opinion_f = etree.SubElement(schema_fs, 'f')
opinion_f.attrib['name'] = 'opinion'
opinion_symbol = etree.SubElement(opinion_f, 'symbol')
opinion_symbol.attrib['value'] = schema_opinion
# inherent "się"
reflex = subentry.inherent_sie.name
selfmark_f = etree.SubElement(schema_fs, 'f')
selfmark_f.attrib['name'] = 'inherent_sie'
selfmark_binary = etree.SubElement(selfmark_f, 'binary')
selfmark_binary.attrib['value'] = reflex
# aspect
aspect_f = etree.SubElement(schema_fs, 'f')
aspect_f.attrib['name'] = 'aspect'
if subentry.aspect is not None and subentry.aspect.name != '':
aspect_symbol = etree.SubElement(aspect_f, 'symbol')
aspect_symbol.attrib['value'] = subentry.aspect.name
# negativity
negativity_f = etree.SubElement(schema_fs, 'f')
negativity_f.attrib['name'] = 'negativity'
if subentry.negativity is not None and subentry.negativity.name != '':
negativity_symbol = etree.SubElement(negativity_f, 'symbol')
negativity_symbol.attrib['value'] = subentry.negativity.name
# predicativity
predicativity = subentry.predicativity.name
predicativity_f = etree.SubElement(schema_fs, 'f')
predicativity_f.attrib['name'] = 'predicativity'
predicativity_binary = etree.SubElement(predicativity_f, 'binary')
predicativity_binary.attrib['value'] = predicativity
# positions
write_positions(schema_fs, subentry, schema)
def write_positions(parent, subentry, schema):
positions = schema.positions.all()
positions_f = etree.SubElement(parent, 'f')
positions_f.attrib['name'] = 'positions'
vColl = etree.SubElement(positions_f, 'vColl')
vColl.attrib['org'] = 'set'
for position in positions:
write_position(vColl, subentry, schema, position)
def write_position(parent, subentry, schema, position):
position_xml_id = u'unif_%d.%d.%d-psn' %(subentry.id, schema.id, position.id)
position_fs = etree.SubElement(parent, 'fs')
position_fs.attrib['type'] = 'position'
position_fs.attrib[etree.QName(XML_NAMESPACE, 'id')] = position_xml_id
write_function(position_fs, position)
write_control(position_fs, position)
write_phrases(position_fs, subentry, schema, position)
def write_function(parent, position):
function = position.function
if function is not None:
function_f = etree.SubElement(parent, 'f')
function_f.attrib['name'] = 'function'
function_symbol = etree.SubElement(function_f, 'symbol')
function_symbol.attrib['value'] = function.name
def write_control(parent, position):
control = position.control
pred_control = position.pred_control
if control is not None or pred_control is not None:
control_f = etree.SubElement(parent, 'f')
control_f.attrib['name'] = 'control'
vColl = etree.SubElement(control_f, 'vColl')
vColl.attrib['org'] = 'set'
if control is not None:
control = control.name
control_symbol = etree.SubElement(vColl, 'symbol')
control_symbol.attrib['value'] = control
if pred_control is not None:
control = pred_control.name
pred_control_symbol = etree.SubElement(vColl, 'symbol')
pred_control_symbol.attrib['value'] = control
def write_phrases(parent, subentry, schema, position):
phrases = position.phrase_types.all()
phrases_f = etree.SubElement(parent, 'f')
phrases_f.attrib['name'] = 'phrases'
vColl = etree.SubElement(phrases_f, 'vColl')
vColl.attrib['org'] = 'set'
for phrase in phrases:
write_phrase(vColl, subentry, schema, position, phrase)
def write_phrase(parent, subentry, schema, position, phrase):
phrase_xml_id = u'unif_%d.%d.%d.%d-phr' %(subentry.id, schema.id, position.id, phrase.id)
phrase_fs = etree.SubElement(parent, 'fs')
phrase_fs.attrib[etree.QName(XML_NAMESPACE, 'id')] = phrase_xml_id
phrase_fs.attrib['type'] = phrase.main_type.name
# @TODO -- currently no expansions file
# if phrase.realizations.exists() and write_expansions_id:
# write_expansions_link(phrase_fs_elem, phrase)
write_phrase_textrep(phrase_fs, phrase)
def write_phrase_textrep(parent, phrase):
text_rep = phrase.text_rep
textrep_f = etree.SubElement(parent, 'f')
textrep_f.attrib['name'] = 'textual_representation'
textrep_string = etree.SubElement(textrep_f, 'string')
textrep_string.text = text_rep
......@@ -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>
{% 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,
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': 1,
defaults={'alternation': schema_alternation_id,
'description': ''})
return JsonResponse({})
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({})
......
......@@ -38,6 +38,8 @@
lexicalUnitsVisible: true,
selected_frame_argument_id: null,
selected_schemata_position_id: null,
selected_schemata_position_alternation_id: null,
selected_schemata_subentry_id: null,
}
},
components: {
......@@ -127,8 +129,10 @@
schemataSelected(schemas) {
this.selectedSchemas = schemas;
},
selectSchemaPositionSelected(selected_schemata_position_id) {
selectSchemaPositionSelected(selected_schemata_position_id, subentry, alternation_id) {
this.selected_schemata_position_id = selected_schemata_position_id;
this.selected_schemata_position_alternation_id = alternation_id;
this.selected_schemata_subentry_id = subentry ? subentry.id : null;
},
exampleSelected(selectedExamples) {
this.selectedExamples = selectedExamples;
......@@ -147,10 +151,21 @@
this.active_slowal_frame = frame;
}
},
create_new_slowal_frame() {
connect_lus_to_slowal_frame(frame_in_progress) {
const frame_in_progress_lus = frame_in_progress ? frames2lexical_units([frame_in_progress]).map(l => {
l.id = l.id;
l.str = l.str;
return l;
}) : [];
const free_lus = this.free_lexical_units.map(l => {
l.id = l.pk;
l.str = l.display;
return l;
});
const frame_in_progress_lus_ids = new Set(frame_in_progress_lus.map(l => l.id));
const lusSelect = function () {
return this.free_lexical_units.map(lu => {
return `<label><input type="checkbox" name="lus" value="${lu.pk}" /> ${lu.display}</label><br />`;
return free_lus.concat(frame_in_progress_lus).map(lu => {
return `<label><input type="checkbox" ${frame_in_progress_lus_ids.has(lu.id) ? 'checked' : ''} name="lus" value="${lu.id}" /> ${lu.str}</label><br />`;
}).join("");
}.bind(this);
......@@ -170,16 +185,17 @@
let lu_ids = normalizeFormData(f.lus);
const data = {
'lu_ids': JSON.stringify(lu_ids),
'entry_id': this.entryId
'entry_id': this.entryId,
'frame_id': frame_in_progress ? frame_in_progress.id : null
};
$.ajax({
type: 'post',
url: '/' + lang + '/freelus/create_new_slowal_frame/',
url: '/' + lang + '/freelus/' + (frame_in_progress ? 'change_lus_in_slowal_frame' : 'create_new_slowal_frame') + '/',
dataType: 'json',
data: data,
timeout: 60000,
success: function (response) {
show_info('Nowa rama została stworzona.');
// show_info(frame_in_progress ? 'Nowa rama została stworzona.' : 'Lista podpiętych jednostek leksyklanych zostala zmieniona.');
this.loadEntry();
$.prompt.close();
}.bind(this),
......@@ -196,16 +212,16 @@
},
attach_examples() {
if (this.frame_in_progress) {
if (this.selected_frame_argument_id) {
if (this.selectedLus && this.selectedLus.length > 0) {
const examplesSelect = function () {
return '<div class="attach-examples-table-wrapper-scroll-y attach-examples-custom-scrollbar"><table id="attach-examples" class="table table-bordered table-striped mb-0"><thead><tr class="font-weight-bold"><th></th><th>Zdanie</th><th>Źródło</th><th>Opinia</th></tr></thead>' + this.examples.map(example => {
return `<tr><td><input type="checkbox" name="lus" value="${example.id}" /></td><td>${example.sentence}</td><td>${example.source}</td><td>${example.opinion}</td></tr>`;
return `<tr><td><input type="checkbox" ${this.selectedLus && example.lu_ids.includes(this.selectedLus[0].id) ? 'checked' : ''} name="lus" value="${example.id}" /></td><td>${example.sentence}</td><td>${example.source}</td><td>${example.opinion}</td></tr>`;
}).join("") + '</table></div>';
}.bind(this);
const attach_examples_popup = {
state0: {
title: 'Wybierz przykłady',
title: 'Wybierz przykłady dla: ' + this.selectedLus.map(e => e.str).join(', '),
html: examplesSelect,
buttons: {Anuluj: 0, Wybierz: 1},
focus: -1,
......@@ -219,8 +235,7 @@
let example_ids = normalizeFormData(f.lus);
const data = {
'example_ids': JSON.stringify(example_ids),
'frame_id': this.frame_in_progress.id,
'argument_id': this.selected_frame_argument_id.split('-')[1]
'selected_lus': JSON.stringify(this.selectedLus.map(e => e.id)),
};
$.ajax({
type: 'post',
......@@ -244,7 +259,7 @@
}
$.prompt(attach_examples_popup);
} else {
alert(gettext("Wybierz argument, do którego chcesz podłączyć przykłady."));
alert(gettext("Zaznacz jednostkę leksykalną, do którego chcesz podłączyć przykłady."));
}
} else {
alert(gettext("Stwórz nową ramę."));
......@@ -252,20 +267,47 @@
},
change_frame_opinion() {
if (this.frame_in_progress) {
const frame_opinion_select = function () {
return frame_opinions.map(frame_opinion => {
return `<label><input type="radio" name="opinion" value="${frame_opinion.id}" /> ${frame_opinion.key}</label><br />`;
}).join("");
}.bind(this);
const change_frame_opinion_popup = {
state0: {
title: 'Wybierz opinię',
html: frame_opinion_select,
buttons: {Anuluj: 0, Wybierz: 1},
focus: -1,
submit: function (e, v, m, f) {
if (v == 0) {
e.preventDefault();
$.prompt.close();
}
if (v === 1) {
e.preventDefault();
let opinion_id = normalizeFormData(f.opinion)[0];
send_post_request('/freelus/change_frame_opinion/',
{
'frame_id': this.frame_in_progress.id,
'opinion': frame.id,
'opinion_id': opinion_id,
},
(reponse) => {
show_info('Opinia została zmieniona.');
// show_info('Opinia została zmieniona.');
alert(gettext("Opinia została zmieniona."));
this.loadEntry();
$.prompt.close();
},
(request, errorType, errorMessage) => {
show_error(errorType + ' (' + errorMessage + ')');
alert(gettext("Zmiana opinii nie powiodła się. Błąd: " + errorType + ' (' + errorMessage + ')'));
$.prompt.close();
})
}
}.bind(this)
}
}
$.prompt(change_frame_opinion_popup);
} else {
alert(gettext("Stwórz nową ramę."));
}
......@@ -279,6 +321,32 @@
return roleName;
}
},
remove_argument() {
if (this.selected_frame_argument_id === null) {
alert(gettext("Zaznacz argument, który chcesz usunąć."));
} else {
const data = {
'argument_id': parseInt(this.selected_frame_argument_id.split('-')[1]),
};
$.ajax({
type: 'post',
url: '/' + lang + '/freelus/remove_argument_from_frame/',
dataType: 'json',
data: data,
timeout: 60000,
success: function (response) {
// alert(gettext("Argument został usunięty."));
show_info('Argument został usunięty.');
this.loadEntry();
$.prompt.close();
}.bind(this),
error: function (request, errorType, errorMessage) {
show_error(errorType + ' (' + errorMessage + ')');
$.prompt.close();
}
});
}
},
change_role(selected_frame_argument_id, api_path) {
if (selected_frame_argument_id === null) {
alert(gettext("Zaznacz argument, dla którego chcesz wybrać rolę."));
......@@ -334,12 +402,13 @@
data: data,
timeout: 60000,
success: function (response) {
alert(gettext("Nowa rola zosała zapisana."));
// alert(gettext("Nowa rola zosała zapisana."));
show_info('Nowa rola zosała zapisana.');
this.loadEntry();
$.prompt.close();
}.bind(this),
error: function (request, errorType, errorMessage) {
alert(errorType + ' (' + errorMessage + ')');
show_error(errorType + ' (' + errorMessage + ')');
$.prompt.close();
}
......@@ -373,10 +442,12 @@
assign_schema() {
if (this.frame_in_progress && this.selected_schemata_position_id && this.selected_frame_argument_id) {
const data = {
'frame_id': this.frame_in_progress.id,
'argument_id': this.selected_frame_argument_id.split('-')[1],
'schema_id': this.selectedSchemas[0].id,
'schema_position_id': this.selected_schemata_position_id.split('-')[1]
'frame_id': parseInt(this.frame_in_progress.id),
'subentry_id': parseInt(this.selected_schemata_subentry_id),
'argument_id': parseInt(this.selected_frame_argument_id.split('-')[1]),
'schema_id': parseInt(this.selectedSchemas[0].id),
'schema_position_id': parseInt(this.selected_schemata_position_id.split('-')[1]),
'schema_alternation_id': (parseInt(this.selected_schemata_position_alternation_id)+1)
};
$.ajax({
type: 'post',
......@@ -385,12 +456,18 @@
data: data,
timeout: 60000,
success: function (response) {
alert(gettext("Argument ramy został powiązany z tybranym argumentem schematu."));
if(response['succ'] == true) {
// alert(gettext("Argument ramy został powiązany z tybranym argumentem schematu."));
show_info('Argument ramy został powiązany z tybranym argumentem schematu.');
this.loadEntry();
} else {
alert(gettext(response['error']));
show_info(response['error']);
}
$.prompt.close();
}.bind(this),
error: function (request, errorType, errorMessage) {
alert(errorType + ' (' + errorMessage + ')');
show_error(errorType + ' (' + errorMessage + ')');
$.prompt.close();
}
......@@ -403,9 +480,11 @@
if (this.frame_in_progress && this.selected_schemata_position_id && this.selected_frame_argument_id) {
const data = {
'frame_id': this.frame_in_progress.id,
'subentry_id': parseInt(this.selected_schemata_subentry_id),
'argument_id': this.selected_frame_argument_id.split('-')[1],
'schema_id': this.selectedSchemas[0].id,
'schema_position_id': this.selected_schemata_position_id.split('-')[1]
'schema_position_id': this.selected_schemata_position_id.split('-')[1],
'schema_alternation_id': (parseInt(this.selected_schemata_position_alternation_id)+1)
};
$.ajax({
type: 'post',
......@@ -414,12 +493,13 @@
data: data,
timeout: 60000,
success: function (response) {
alert(gettext("Powiązanie pomiędzy argumentem ramy a argumentem schematu zostało usunięte."));
// alert(gettext("Powiązanie pomiędzy argumentem ramy a argumentem schematu zostało usunięte."));
show_info('Powiązanie pomiędzy argumentem ramy a argumentem schematu zostało usunięte.');
this.loadEntry();
$.prompt.close();
}.bind(this),
error: function (request, errorType, errorMessage) {
alert(errorType + ' (' + errorMessage + ')');
show_error(errorType + ' (' + errorMessage + ')');
$.prompt.close();
}
......@@ -446,6 +526,7 @@
$.prompt.close();
}.bind(this),
error: function (request, errorType, errorMessage) {
alert(errorType + ' (' + errorMessage + ')');
show_error(errorType + ' (' + errorMessage + ')');
$.prompt.close();
}
......@@ -484,29 +565,36 @@
<div id="free-lus-pane" class="col w-100 p-0 overflow-auto">
<table class="table-button-menu sticky-top" cellspacing="1">
<tr style="background-color: white;">
<td id="create-new-frame" class="table-button-menu-td" @click="create_new_slowal_frame()"
style="padding: 10px 15px 10px 15px; color: #000000;">Nowa rama
<td id="create-new-frame" class="table-button-menu-td" @click="connect_lus_to_slowal_frame(this.frame_in_progress)"
style="padding: 10px 15px 10px 15px; color: #000000;">{{this.frame_in_progress ? 'Dodaj/Usuń jednostki' : 'Nowa rama'}}
</td>
<td id="add-argument" class="table-button-menu-td" @click="change_role(-1, 'add_argument_to_frame')"
style="padding: 10px 15px 10px 15px; color: #000000;">Dodaj argument
</td>
<td id="change-role" class="table-button-menu-td"
@click="change_role(selected_frame_argument_id ? selected_frame_argument_id.split('-')[1] : null, 'change_role')"
style="padding: 10px 15px 10px 15px; color: #000000;">Zmień rolę
<td id="assign-schema" class="table-button-menu-td" @click="assign_schema()"
style="padding: 10px 15px 10px 15px; color: #000000;">Podłącz argument
</td>
<td id="assign-examples" class="table-button-menu-td" @click="attach_examples()"
style="padding: 10px 15px 10px 15px; color: #000000;">Podłącz przykłady
</td>
<td id="finish-frame-building" class="table-button-menu-td" @click="finish_frame_building()"
style="padding: 10px 15px 10px 15px; color: #000000;">Gotowe
</td>
</tr>
<tr style="background-color: white;">
<td id="assign-schema" class="table-button-menu-td" @click="assign_schema()"
style="padding: 10px 15px 10px 15px; color: #000000;">Podłącz schemat
<td id="change-role" class="table-button-menu-td"
@click="change_role(selected_frame_argument_id ? selected_frame_argument_id.split('-')[1] : null, 'change_role')"
style="padding: 10px 15px 10px 15px; color: #000000;">Zmień rolę
</td>
<td id="remove-argument" class="table-button-menu-td" @click="remove_argument()"
style="padding: 10px 15px 10px 15px; color: #000000;">Usuń argument
</td>
<td id="delete-schema" class="table-button-menu-td" @click="delete_schema_connections()"
style="padding: 10px 15px 10px 15px; color: #000000;">Rozłącz schemat
style="padding: 10px 15px 10px 15px; color: #000000;">Odłącz argument
</td>
<td id="finish-frame-building" class="table-button-menu-td" @click="finish_frame_building()"
style="padding: 10px 15px 10px 15px; color: #000000;">Zakończ tworzenie nowej ramy
<td id="change-frame-opinion" class="table-button-menu-td" @click="change_frame_opinion()"
style="padding: 10px 15px 10px 15px; color: #000000;">Zmień opinię
</td>
</tr>
</table>
......
......@@ -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))
......