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 (21)
Showing
with 277 additions and 752 deletions
......@@ -5,3 +5,4 @@
/.idea/
/import.log
.DS_Store
/collected_static/
FROM node:16.16
MAINTAINER Dariusz Czerski <dcz@ipipan.waw.pl>
ADD frontend/yarn.lock /yarn.lock
ADD frontend/package.json /package.json
RUN yarn install --frozen-lockfile
ENV PATH /node_modules/.bin:$PATH
ADD frontend /src
ADD docker /docker
VOLUME /src
WORKDIR /src
ENTRYPOINT ["/docker/scripts/docker-entrypoint-frontend"]
......@@ -17,3 +17,11 @@ In order to run the development environment locally:
Whenever you need to establish an interactive bash session in the running applicaiton container, execute:
./docker/scripts/docker-bash
## Deploying to production
In order to build the frontend Vue.js application for production execute the following command:
docker-compose run frontend yarn build
Compiled application files will be located in `frontend/dist/`.
......@@ -2,6 +2,7 @@
{% load i18n %}
{% load static %}
{% load django_vite %}
{% get_current_language as LANGUAGE_CODE %}
......@@ -33,10 +34,11 @@
<!-- translations: https://docs.djangoproject.com/en/2.2/topics/i18n/translation/#using-the-javascript-translation-catalog -->
<script type="text/javascript" src="{% url 'javascript-catalog' %}"></script>
{% block scripts %}{% endblock %}
{% vite_hmr_client %}
{% vite_asset 'src/main.js' %}
</head>
<body>
{% block modals %}{% endblock %}
<div class="container-fluid h-100 d-flex flex-column p-0">
......@@ -102,10 +104,14 @@
</a>
</nav>
<main class="container-fluid flex-grow-1 overflow-auto m-0 p-0 bg-dark" role="main">
{% block content %}{% endblock %}
</main>
{% if is_vue_app %}
<main id="vue-app"></main>
{% else %}
<main class="container-fluid flex-grow-1 overflow-auto m-0 p-0 bg-dark" role="main">
{% block content %}{% endblock %}
</main>
{% endif %}
<footer class="footer bg-dark text-muted">
<div class='px-1'>
Copyright © {% trans "Instytut Podstaw Informatyki PAN" %}, 2021.
......
......@@ -19,8 +19,12 @@ services:
- ./.datastore/postgresql:/var/lib/postgresql/data
backend:
#platform: linux/amd64
container_name: shellvalier-backend
image: shellvalier-developer:latest
build:
context: .
dockerfile: Dockerfile
depends_on:
- postgresql
networks:
......@@ -30,3 +34,16 @@ services:
- .:/app
ports:
- "8000:8000"
frontend:
container_name: shellvalier-frontend
image: shellvalier-frontend-developer:latest
build:
context: .
dockerfile: Dockerfile-frontend
networks:
- app-tier
volumes:
- ./frontend:/src
ports:
- "8010:8010"
#!/bin/bash
echo 'Starting docker container'
set -e
exec "$@"
exec yarn dev
#!/usr/bin/env bash
set -e
docker build -t shellvalier-developer -f Dockerfile .
docker-compose up
docker-compose up --build
......@@ -26,7 +26,9 @@ from semantics.models import (
PredefinedSelectionalPreference, RelationalSelectionalPreference, SelectionalPreferenceRelation,
)
from meanings.models import Synset
from meanings.models import Synset, LexicalUnit
from unifier.choices import UnifiedFrameStatus
from unifier.models import UnifiedFrame, UnifiedFrameArgument
from .form_fields.generic_fields import (
RangeFilter,
......@@ -138,6 +140,8 @@ class EntryForm(QueryForm):
self.make_field('pos'),
self.make_field('phraseology'),
self.make_field('status'),
self.make_field('frequency_1M'),
self.make_field('frequency_300M'),
]
schema_components = [
......@@ -206,6 +210,14 @@ class EntryForm(QueryForm):
label=_('Liczba ram'),
lookup='frames_count',
)
frequency_1M = RangeFilter(
label=_('Frekwencja w korpusie 1M'),
lookup='frequency_1M',
)
frequency_300M = RangeFilter(
label=_('Frekwencja w korpusie 300M'),
lookup='frequency_300M',
)
phrase_type = PhraseTypeFilter(
queryset=PhraseTypeModel.objects.filter(main_phrase_types__positions__schemata__isnull=False).distinct(),
#help_text=_('Typ frazy występujący w haśle.'),
......@@ -601,6 +613,94 @@ class FrameFormFactory(FormFactory):
raise KeyError(type(child_form))
class UnifiedFrameFormFactory(FormFactory):
form_class_name = 'UnifiedFrameForm'
form_model = UnifiedFrame
form_formtype = 'unifiedframe'
form_header = _('Zunifikowana rama semantyczna')
field_makers = (
(
'status',
lambda: ModelMultipleChoiceFilter(
label=_('Status'),
queryset=UnifiedFrame.objects.distinct(),
key='status',
lookup='status',
), None,
),
(
None, None,
lambda n, cls: and_or_form_creator(_('Opnia podpiętych ram slowala'), 'add-slowal-frame-opinion-{}'.format(n), data_add='FrameOpinion'),
),
(
'num_arguments',
lambda: RangeFilter(
label=_('Liczba argumentów'),
lookup='arguments_count',
), None
),
(
'num_frames',
lambda: RangeFilter(
label=_('Liczba ram semantycznych'),
lookup='slowal_frames_count',
), None
),
(
'name',
lambda: RegexFilter(
label=_('Nazwa'),
max_length=200,
lookup='title',
), None,
),
(
'lemmas',
lambda: RegexFilter(
label=_('Lematy jednostek leksykalnych'),
max_length=200,
lookup='unified_frame_2_slowal_frame__slowal_frame__lexical_units__base',
), None,
),
(
None, None,
lambda n, cls: and_or_form_creator(_('UnifiedFrameArgument'), 'add-unified-frame-argument-{}'.format(n), data_add='UnifiedArgument'),
),
)
@staticmethod
def get_child_form_prefix(child_form):
if child_form.model_class == UnifiedFrameArgument:
return 'unified_arguments__in'
if child_form.model_class == Frame:
return 'unified_frame_2_slowal_frame__slowal_frame__in'
raise KeyError(type(child_form))
class FrameOpinionFormFactory(FormFactory):
form_class_name = 'FrameOpinionForm'
form_model = Frame
form_formtype = 'FrameOpinion'
form_header = _('Opinia ramy slowala')
field_makers = (
(
'opinion',
lambda: ModelMultipleChoiceFilter(
label=_('Opinia'),
queryset=FrameOpinion.objects.exclude(key='unk').filter(frame__isnull=False).distinct(),
key='key',
human_values=polish_strings.FRAME_OPINION(),
lookup='opinion',
), None,
),
)
class ArgumentFormFactory(FormFactory):
form_class_name = 'ArgumentForm'
......@@ -663,6 +763,70 @@ class ArgumentFormFactory(FormFactory):
raise KeyError(type(child_form))
class UnifiedArgumentFormFactory(FormFactory):
form_class_name = 'UnifiedArgumentForm'
form_model = UnifiedFrameArgument
form_formtype = 'UnifiedArgument'
form_header = _('Argument semantyczny ramy zunifkikoanej')
field_makers = (
(
'role',
lambda: RoleNameFilter(
label=_('Rola'),
lookup='role__role',
), None,
),
(
'role_attribute',
lambda: RoleAttributeFilter(
label=_('Atrybut roli'),
lookup='role__attribute',
), None,
),
(
'num_preferences',
lambda: RangeFilter(
label=_('Liczba preferencyj selekcyjnych argumentu'),
lookup='preferences_count',
), None
),
(
'preference_type',
lambda: ChoiceFilter(
label=_('Preferencja selekcyjna'),
choices=(('', _('wybierz')), ('predefined', _('Predefiniowana grupa znaczeń')), ('relational', _('Wyrażona przez relację')), ('synset', _('Wyrażona przez jednostkę leksykalną Słowosieci'))),
),
lambda n, cls: and_or_form_creator(_('Preferencja selekcyjna'), 'add-preference-{}'.format(n), field=cls.make_field(FormFactory.unique_name('preference_type', n)))
),
# removing until we discuss whether this field is needed & how it should work
#(
# None, None,
# lambda n, cls: and_or_form_creator(_('Pozycja'), 'add-position-{}'.format(n), data_add='position'),
#),
(
'phrase_type',
lambda: PhraseTypeFilter(help_text=_('Typ frazy, przez którą może być realizowany argument.')),
lambda n, cls: and_or_form_creator(_('Fraza'), 'add-phrase-{}'.format(n), field=cls.make_field(FormFactory.unique_name('phrase_type', n)), data_prefix='phrase_'),
),
)
@staticmethod
def get_child_form_prefix(child_form):
if child_form.model_class == PredefinedSelectionalPreference:
return 'predefined__in'
if child_form.model_class == RelationalSelectionalPreference:
return 'relations__in'
if child_form.model_class == Synset:
return 'synsets__in'
if child_form.model_class == PhraseType:
return 'unified_agrument_mapping__slowal_agrument__argument_connections__schema_connections__phrase_type__in'
# return 'argument_connections__schema_connections__phrase_type__in'
raise KeyError(type(child_form))
class PredefinedPreferenceFormFactory(FormFactory):
form_class_name = 'PredefinedPreferenceForm'
......@@ -676,8 +840,9 @@ class PredefinedPreferenceFormFactory(FormFactory):
lambda: ModelMultipleChoiceFilter(
label=_('Predefiniowane'),
queryset=PredefinedSelectionalPreference.objects.all(),
key='key',
lookup='key',
key='name',
human_values=polish_strings.PREDEFINED_SELECTIONAL_PREFERENCE(),
lookup='name',
), None,
),
)
......
......@@ -228,3 +228,26 @@ def EXAMPLE_OPINION():
'wątpliwy' : _('wątpliwy'),
'dobry' : _('dobry'),
}
def PREDEFINED_SELECTIONAL_PREFERENCE():
return {
'ALL' : _('ALL'),
'LUDZIE' : _('LUDZIE'),
'ISTOTY' : _('ISTOTY'),
'PODMIOTY' : _('PODMIOTY'),
'DOBRA' : _('DOBRA'),
'KOMUNIKAT' : _('KOMUNIKAT'),
'KONCEPCJA' : _('KONCEPCJA'),
'WYTWÓR' : _('WYTWÓR'),
'JADŁO' : _('JADŁO'),
'MIEJSCE' : _('MIEJSCE'),
'CZAS' : _('CZAS'),
'OBIEKTY' : _('OBIEKTY'),
'CECHA' : _('CECHA'),
'CZYNNOŚĆ' : _('CZYNNOŚĆ'),
'SYTUACJA' : _('SYTUACJA'),
'KIEDY' : _('KIEDY'),
'CZEMU' : _('CZEMU'),
'ILOŚĆ' : _('ILOŚĆ')
}
......@@ -182,7 +182,6 @@ legend {
border-style: dashed;
border-width: 2px;
border-color: #564c4c;
padding: 3px;
}
.sticky-bottom {
......
export default {
props: {
text: String,
visibleText: String
},
data () {
return {
iconUrl: window.STATIC_URL + 'common/img/info.svg'
}
},
computed: {
quotedText () {
return this.text.replace(/"/g, '&quot;');
}
},
mounted () {
$(this.$refs.tooltip).tooltip();
},
template: `
<span
data-toggle="tooltip"
data-placement="bottom"
data-html="true"
:title="quotedText"
ref="tooltip"
>
<img v-if="!visibleText" :src="iconUrl" alt="info" width="14" height="14" />
<span v-else>{{visibleText}}</span>
</span>
`
}
export default {
data() {
return { gettext: window.gettext }
},
template: `
<div class="d-flex justify-content-center wait-spinner">
<div class="spinner-border text-primary m-5" style="width: 3rem; height: 3rem;" role="status">
<span class="sr-only">{{ gettext('Proszę czekać...') }}</span>
</div>
</div>
`
}
export default {
props: {
initialLexicalUnitId: Number,
initialEntryId: Number,
unificationEntriesListRefreshKey: Number,
},
watch: {
unificationEntriesListRefreshKey() {
// TODO: reload data and click in selected row
// this.datatableObject.ajax.reload();
setup_entries_list({
table: this.$refs.table,
lexicalUnitSelected: (entryId, lexicalUnitId) => { this.$emit('lexicalUnitSelected', entryId, lexicalUnitId); },
selectEntryId: this.initialEntryId,
secondarySelectEntryId: this.initialLexicalUnitId,
});
}
},
data () {
return {
gettext: window.gettext,
canViewAssignment: has_permission("users.view_assignment"),
}
},
emits: ['lexicalUnitSelected'],
mounted () {
setup_entries_list({
table: this.$refs.table,
lexicalUnitSelected: (entryId, lexicalUnitId) => { this.$emit('lexicalUnitSelected', entryId, lexicalUnitId); },
selectEntryId: this.initialEntryId
});
},
template: `
<table ref="table" class="table table-sm text-dark">
<thead>
<tr>
<th class="p-1">{{ gettext('Lemat') }}</th>
<th class="p-1">{{ gettext('Część mowy') }}</th>
<th class="p-1">{{ gettext('Do pobrania') }}</th>
<th v-if="canViewAssignment" class="p-1">{{ gettext('Semantyk') }}</th>
<th v-else class="p-1">{{ gettext('Moje (w opracowaniu)') }}</th>
</tr>
</thead>
<tbody id="entries">
</tbody>
</table>
`
};
import InfoTooltip from "../InfoTooltip.js";
export default {
props: {
examples: Object,
frame: Object,
frame_arguments: Object,
frame_arguments_or_type: null,
schemas: Object,
lus: Object,
},
components: {InfoTooltip},
data() {
return {
img_prefix: String
}
},
methods: {
getExamples () {
let ret = this.examples;
if(this.schemas && this.schemas.length > 0) {
// ograniczone do schematu
ret = ret.filter(e => this.schemas.every(a => e.schema_ids.includes(parseInt(a.id))));
}
if(this.frame_arguments && this.frame_arguments.length > 0) {
// ograniczone do argumentu ramy
if(this.frame_arguments_or_type) {
ret = ret.filter(e => this.frame_arguments.some(a => e.argument_ids.includes(a.id)));
} else {
ret = ret.filter(e => this.frame_arguments.every(a => e.argument_ids.includes(a.id)));
}
}
if(this.frame) {
ret = ret.filter(e => e.frame_ids.includes(this.frame.id));
}
if(this.lus && this.lus.length > 0) {
ret = ret.filter(e => this.lus.every(lu => e.lu_ids.includes(lu.id)));
}
return ret;
},
getSchemaStr(schema) {
return schema.positions.map(e => e.phrases.map(p => p.str).join(",")).join('|');
}
},
mounted () {
this.img_prefix = window.STATIC_URL;
},
template: `
<table id="semantics-examples" v-if="getExamples().length > 0" class="table table-sm table-hover" style="">
<thead>
<tr>
<th scope="col">Przykład
<i v-if="frame_arguments" v-for="frame_argument in frame_arguments">
<span class="example-role"> {{' '}}
<span :class="frame_argument.role">{{frame_argument.role}}</span>
</span>
</i>
<i v-if="lus" v-for="lu in lus">{{' ' + lu.str}}</i>
<i v-if="schemas" v-for="schema in schemas">{{' '+getSchemaStr(schema)}}</i>
</th>
<th scope="col">Źródło</th>
<th scope="col">Opinia</th>
</tr>
</thead>
<tbody id="semantics-examples-list">
<tr v-for="example in getExamples()" class="example">
<td class="py-1">
{{example.sentence}}
<info-tooltip v-if="example.note" :text="example.note" />
</td>
<td class="py-1">{{example.source}}</td>
<td class="py-1">{{example.opinion}}</td>
</tr>
</tbody>
</table>
<p v-else class="mx-1 my-1" id="semantics-no-examples" style="display: none;">Brak przykładów</p>
`
}
import InfoTooltip from "../InfoTooltip.js";
import MeaningComponent from "./MeaningComponent.js";
export default {
props: {
frame: Object,
},
components: {InfoTooltip, MeaningComponent},
emits: ['frameSelectionChanged'],
data() {
return {
img_prefix: String,
selectedLus: null
}
},
methods: {
getTitleHTML() {
const ret = window.lexical_units2dom(this.frame.lexical_units);
return ret;
},
getOpinionHTML() {
return window.make_opinion_row(this.frame, this.frame.arguments.length, 3).outerHTML;
},
getArguments() {
return this.frame.arguments;
},
triggerSelectedEvent() {
const selectedLus = this.frame.lexical_units.filter(lu => lu.selected);
const selectedArguments = this.frame.arguments.filter(argument => argument.selected)
this.$emit('frameSelectionChanged', selectedArguments, selectedLus);
},
meaningLuSelected(selectedLus) {
this.triggerSelectedEvent();
},
selectArgument(argument) {
argument.selected = !argument.selected;
this.triggerSelectedEvent();
}
},
mounted () {
this.img_prefix = window.STATIC_URL;
},
template: `
<div class="frame mb-3 active">
<div class="frame mt-0" id="lexical-unit">
<meaning-component
:lexicalUnits="frame.lexical_units"
@meaning-lu-selected="meaningLuSelected"
></meaning-component>
</div>
<table class="table m-0 table-borderless border border-secondary text-dark">
<tbody>
<tr class="opinion-row" v-html="getOpinionHTML()">
</tr>
<tr>
<th scope="row" class="py-2 px-1 text-secondary">Rola</th>
<template v-for="argument in frame.arguments">
<td class="argument py-2 px-1 border-top border-left border-secondary"
@mouseenter="argument.hover=true"
@mouseleave="argument.hover=false"
@click.stop="selectArgument(argument)"
:class="argument.role + ' ' + (argument.selected ? 'active' : argument.hover ? 'bg-highlight' : '')"
>
{{argument.str}}
</td>
</template>
</tr>
<tr>
<th scope="row" class="py-0 px-1 text-secondary">Preferencje selekcyjne</th>
<template v-for="argument in getArguments()">
<td class="preferences py-0 px-0 border-top border-left border-secondary"
:class="argument.selected ? 'active' : argument.hover ? 'bg-highlight' : ''"
>
<template v-if="argument.preferences.length > 0" v-for='preference in argument.preferences'>
<div
v-if="preference.url != null"
class="preference py-2 px-1"
>
<a class="synset-plwn" v-bind:href="preference.url" target="_blank">{{ preference.str }}</a>
<info-tooltip v-if="preference.info" :text="'definicja: <i>'+ preference.info +'</i>'" />
</div>
<div v-else class="preference py-2 px-1">{{ preference.str }}</div>
</template>
</td>
</template>
</tr>
</tbody>
</table>
</div>
`
}
......@@ -1113,7 +1113,7 @@ $(document).ready(function() {
bind_settings();
initialize_entries_list();
// initialize_entries_list();
// $('#id_filter_schema_').change(function() {
// get_entry(curr_entry, curr_no_filters);
......@@ -1124,22 +1124,24 @@ $(document).ready(function() {
// });
initialize_main_form();
initialize_frames_form();
initialize_schemata_form();
initialize_unified_frames_form();
//$('.local-filter').hide();
getPredefinedSelections();
// getPredefinedSelections();
getRoles();
getRoleAttributes();
// getRoles();
//
// getRoleAttributes();
$.getJSON('relations', function(data){
memorizeRelations(data.relations);
});
// $.getJSON('relations', function(data){
// memorizeRelations(data.relations);
// });
$('#main-form').submit();
});
import Entries from './components/Entries.js';
const { createApp } = Vue;
window.update_entries = function () {
if(window.unificationLeftPaneApp) {
window.unificationLeftPaneApp.unificationEntriesListRefreshKey++;
window.unificationLeftPaneApp.lexicalUnitId = null;
} else {
window.unificationLeftPaneApp = createApp(Entries).mount('#vue-app');
}
}
......@@ -412,9 +412,9 @@ function initialize_main_form() {
var submit = main_form.find('input[type="submit"]');
submit.prop('disabled', true);
event.preventDefault();
clear_results();
// clear_results();
clear_info();
show_entry_list_spinner();
// show_entry_list_spinner();
clear_form_errors(main_form);
var data = { 'forms' : serialize_forms(main_form) };
$.ajax({
......@@ -427,9 +427,7 @@ function initialize_main_form() {
if (response.errors) {
show_form_errors(main_form, response.errors);
} else if (response.success) {
if(window.unificationLeftPaneApp) {
// window.unificationLeftPaneApp.refresh();
}
//ponizsza funkcja prowadzi do metody osadzonej w main.js, gdzie nastepuje odpowiednie odswiezenie komponentu z lista elementow Vue
update_entries();
$('#entry-filters').modal('hide');
}
......@@ -479,7 +477,8 @@ function initialize_local_form(selector, url) {
if (response.errors) {
show_form_errors(form, response.errors);
} else if (response.success) {
get_entry(curr_entry, curr_no_filters);
//ponizsza funkcja prowadzi do metody osadzonej w main.js, gdzie nastepuje odpowiednie odswiezenie komponentu z lista elementow Vue
update_entries();
selector.modal('hide');
}
submit.prop('disabled', false);
......@@ -494,12 +493,17 @@ function initialize_local_form(selector, url) {
}
function initialize_frames_form() {
initialize_local_form($('#frame-filters'), '/' + lang + '/entries/send_frames_form/');
initialize_local_form($('#frame-filters-local'), '/' + lang + '/entries/send_frames_form/');
}
function initialize_unified_frames_form() {
initialize_local_form($('#unified-frame-filters'), '/' + lang + '/entries/send_unified_frames_form/');
}
function initialize_schemata_form() {
initialize_local_form($('#schema-filters'), '/' + lang + '/entries/send_schemata_form/');
initialize_local_form($('#schema-filters-local'), '/' + lang + '/entries/send_schemata_form/');
/*var schemata_form = $('#schema-filters').find('form');
......
var predefined = [];
var relations = [];
var synsets = [];
var change = false;
function predefinedSelect() {
let display = "";
let i;
for (i = 0; i < predefined.length; i++) {
display += "<input type = \"checkbox\" name = \"predef\" value = \"" + predefined[i].id + "\">" + predefined[i].content + "<br>";
}
return display;
}
function getPredefinedSelections() {
$.ajax({
dataType: "json",
url: 'predefined_preferences',
success: function(data){
predefined = data.predefined;
},
async: false
});
}
function memorizeRelations(new_relations) {
relations = new_relations;
}
function relationsSelect() {
let display = "<select name = \"rel\">";
let i;
for (i = 0; i < relations.length; i++) {
display += "<option value = \"" + relations[i].id + "\">" + relations[i].content + "</option>";
}
display += "</select>"
return display;
}
function argumentSelect(frame, complement_id) {
let display = "<select name = \"arg\">";
let i;
for (i = 0; i < frame.arguments.length; i++) {
var local_complement_id = frame.arguments[i].argument_id;
if (local_complement_id && local_complement_id !== String(complement_id)) {
display += "<option value = \"" + local_complement_id + "\">" + frame.arguments[i].role + "</option>";
}
}
display += "</select>"
return display;
}
function getSynsets(context, pos) {
if ((typeof pos) == 'undefined') {
pos = '_';
}
$.ajax({
dataType: "json",
url: 'synsets',
data: {base: context, pos: pos},
success: function(data){ synsets = data.synsets },
async: false
});
let display = "";
let i;
for (i = 0; i < synsets.length; i++) {
display += "<input type = \"radio\" name = \"synset\" value = \"" + synsets[i].id + "\"><div>";
let j;
for (j = 0; j < synsets[i].content.length; j++) {
const lexical_unit = synsets[i].content[j];
display += lexical_unit.base + "-" + lexical_unit.sense + ": <i>" + lexical_unit.glossa + "</i><br>";
}
display += "</div>";
}
return display;
}
function relationArgument(frame, complement_id) {
return relationsSelect() + "<br><br>" + argumentSelect(frame, complement_id);
}
function attachPlWNContextAutocomplete() {
$('#plWN_context_selection').autocomplete({
select: function(event, ui){
},
source: function(req, add){
$.getJSON('plWN_context_lookup', req, function(data) {
const suggestions = [];
$.each(data['result'], function(i, val){
suggestions.push(val);
});
add(suggestions);
});
},
});
}
function addSelectivePreference(unified_frame, unified_frame_active_argument_id, frames, callbackFunction) {
if (!unified_frame_active_argument_id) return;
addSelectivePreferenceBase(unified_frame, frames, unified_frame_active_argument_id, callbackFunction);
}
function addSelectivePreferenceBase(unified_frame, frames, complement_id, callbackFunction) {
let unified_frame_id = unified_frame.id;
const submitSynsetSelection = function(e,v,m,f){
if (v == -1) {
e.preventDefault();
$.prompt.goToState('state2');
}
if (v == 1) {
e.preventDefault();
const synset = normalizeFormData(f.synset);
let i;
for (i = 0; i < synset.length; i++) {
saveSynsetPreference(unified_frame_id, complement_id, synset[i])
}
$.prompt.goToState('state0');
}
}
const existingSelect = function () {
let availablePreferencies = slowal_frames2selecional_preferencies(unified_frame, frames)[complement_id];
if (!availablePreferencies) {
return gettext('Brak preferencji selekcyjnych do wyboru.')
}
return availablePreferencies.map(preference => {
return `<label><input type="checkbox" name="existing" value="${preference.type}:${preference.id}" /> ${preference.str}</label><br />`;
}).join("");
};
const select_preference = {
state0: {
title: 'Typ preferencji selekcyjnej',
html: 'Wybierz typ preferencji selekcyjnej',
buttons: { Istniejąca: 0, Predefiniowana: 1, Słowosieć: 2, Relacja: 3, Koniec: -1 },
focus: -1,
submit: function(e,v,m,f){
if (v == -1) {
e.preventDefault();
$.prompt.close();
callbackFunction();
}
if (v === 0) {
e.preventDefault();
$.prompt.goToState('state4');
}
if (v == 1) {
e.preventDefault();
$.prompt.goToState('state1');
}
if (v == 2) {
e.preventDefault();
$.prompt.goToState('state2');
}
if (v == 3) {
e.preventDefault();
$.prompt.goToState('state3');
}
}
},
state1: {
title: 'Wybierz preferencję selekcyjną',
html: predefinedSelect(),
buttons: { Anuluj: -1, Zatwierdź: 1 },
focus: 1,
submit: function(e,v,m,f){
if (v == -1) {
e.preventDefault();
$.prompt.goToState('state0');
}
if (v == 1) {
e.preventDefault();
const predef = normalizeFormData(f.predef);
let i;
for (i = 0; i < predef.length; i++) {
savePredefinedPreference(unified_frame_id, complement_id, predef[i])
// addPreference(unified_frame_id, complement_id, { type: 'g', content: predef[i], text: predefined[indexOfId(predefined, predef[i])].content });
}
$.prompt.goToState('state0');
}
}
},
state2: {
title: 'Wybierz preferencję selekcyjną',
html: "<input id=\"plWN_context_selection\" type=\"text\" name=\"context\">",
buttons: { Anuluj: -1, Wyszukaj: 1 },
focus: 1,
submit: function(e,v,m,f){
if (v == -1) {
e.preventDefault();
$.prompt.goToState('state0');
}
if (v == 1) {
e.preventDefault();
$.prompt.removeState('state21');
$.prompt.addState('state21', {title: 'Znaczenia', html: getSynsets(f.context), buttons: {Anuluj: -1, Zatwierdź: 1}, focus: 1, submit: submitSynsetSelection}, 'state2');
$.prompt.goToState('state21');
}
}
},
state3: {
title: 'Wybierz relację i argument',
html: relationArgument(unified_frame, complement_id),
buttons: { Anuluj: -1, Zatwierdź: 1 },
focus: 1,
submit: function(e,v,m,f){
if (v == -1) {
e.preventDefault();
$.prompt.goToState('state0');
}
if (v == 1) {
e.preventDefault();
const rel = normalizeFormData(f.rel);
const args = normalizeFormData(f.arg);
let i, j;
for (i = 0; i < rel.length; i++) {
for (j = 0; j < args.length; j++) {
saveRelationalSelectionalPreference(unified_frame_id, complement_id, args[j], rel[i])
// addPreference(unified_frame_id, complement_id, {type: 'r', content: { relation: rel[i], to: args[j] }, text: relations[indexOfId(relations, rel[i])].content + "<br>-> [" + text + "]" });
}
}
$.prompt.goToState('state0');
}
}
},
state4: {
title: 'Wybierz z istniejących',
html: existingSelect(),
buttons: { Anuluj: -1, Zatwierdź: 1 },
focus: 1,
submit: function(e,v,m,f){
if (v == -1) {
e.preventDefault();
$.prompt.goToState('state0');
}
if (v == 1) {
e.preventDefault();
normalizeFormData(f.existing).map(choice => {
let [type, id] = choice.split(':');
switch (type) {
case 'meanings.Synset':
saveSynsetPreference(unified_frame_id, complement_id, id);
case 'semantics.PredefinedSelectionalPreference':
savePredefinedPreference(unified_frame_id, complement_id, id);
case 'semantics.RelationalSelectionalPreference':
saveRelationalSelectionalPreference(unified_frame_id, complement_id, null, null); // TODO
}
});
$.prompt.goToState('state0');
}
}
},
};
if (change == true) {
alertSemantics();
} else {
$.prompt(select_preference);
attachPlWNContextAutocomplete();
}
}
function saveSynsetPreference(frame_id, complement_id, synset_preference_id) {
const data = { 'frame_id' : frame_id, 'complement_id' : complement_id, 'synset_preference_id' : synset_preference_id };
$.ajax({
type : 'post',
url : '/' + lang + '/unifier/save_synset_preference/',
dataType : 'json',
data : data,
timeout : 60000,
success : function(response) {
show_info('Preferencja zosała zapisana');
},
error: function(request, errorType, errorMessage) {
show_error(errorType + ' (' + errorMessage + ')');
}
});
}
function savePredefinedPreference(frame_id, complement_id, predefined_preference_id) {
const data = { 'frame_id' : frame_id, 'complement_id' : complement_id, 'predefined_preference_id' : predefined_preference_id };
$.ajax({
type : 'post',
url : '/' + lang + '/unifier/save_predefined_preference/',
dataType : 'json',
data : data,
timeout : 60000,
success : function(response) {
show_info('Preferencja zosała zapisana');
},
error: function(request, errorType, errorMessage) {
show_error(errorType + ' (' + errorMessage + ')');
}
});
}
function saveRelationalSelectionalPreference(frame_id, complement_id_from, complement_id_to, relation_id) {
const data = { 'frame_id' : frame_id, 'complement_id_from' : complement_id_from, 'complement_id_to' : complement_id_to, 'relation_id': relation_id };
$.ajax({
type : 'post',
url : '/' + lang + '/unifier/save_relational_selectional_preference/',
dataType : 'json',
data : data,
timeout : 60000,
success : function(response) {
show_info('Preferencja zosała zapisana');
},
error: function(request, errorType, errorMessage) {
show_error(errorType + ' (' + errorMessage + ')');
}
});
}
"use strict";
function get_unified_frame(unified_frame_id, related) {
check_import_status();
clear_entry();
show_entry_spinners();
//const data = { 'forms' : serialize_forms($('#main-form')), 'entry' : entry_id };
const data = { 'unified_frame_id' : unified_frame_id, 'no_filters' : related };
$.ajax({
type : 'post',
url : '/' + lang + '/unifier/get_unified_frame/',
dataType : 'json',
data : data,
timeout : 60000,
success : function(response) {
curr_entry = unified_frame_id;
curr_no_filters = related;
clear_info();
curr_alternations = response.alternations;
curr_realisation_phrases = response.realisation_phrases;
curr_realisation_descriptions = response.realisation_descriptions;
curr_examples = response.examples;
curr_examples_by_id = Object();
for (let i in curr_examples) {
curr_examples_by_id[curr_examples[i].id] = curr_examples[i];
}
// show_syntax(response.subentries);
show_unified_frame(response.unified_frame, response.frames)
show_unified_frame_lexical_units(response.frames)
fulfill_slowal_frames_arguments_with_empty_elems(response.unified_frame, response.frames)
show_semantics_unified_view(response.frames, response.subentries);
// show_unmatched_examples();
// tooltips with meaning gloss
activate_tooltips($('#semantics-frames-pane'));
update_last_visited(response.last_visited);
},
error: function(request, errorType, errorMessage) {
show_error(errorType + ' (' + errorMessage + ')');
}
});
}
function slowal_frames2selecional_preferencies(unified_frame, slowal_frames) {
const unified_argument_2_selecional_preferencies = {}
for (let i in unified_frame.slowal_frame_mapping) {
const slowal_frame_mapping = unified_frame.slowal_frame_mapping[i];
let slowal_frame = slowal_frames.find(o => o.id === slowal_frame_mapping.slowal_frame_id);
for (let j in slowal_frame_mapping.slowal_frame_argument_mapping) {
const slowal_frame_argument_mapping = slowal_frame_mapping.slowal_frame_argument_mapping[j];
let slowal_frame_argument = slowal_frame.arguments.find(o => o.argument_id === slowal_frame_argument_mapping.slowal_frame_agrument_id);
let unified_frame_argument = unified_frame.arguments.find(o => o.id === slowal_frame_argument_mapping.unified_frame_agrument_id);
const unified_frame_argument_preferences = new Set(unified_frame_argument.preferences.map(preference => preference.str));
let preferenceEntry = unified_argument_2_selecional_preferencies[slowal_frame_argument_mapping.unified_frame_agrument_id];
if(preferenceEntry == null) {
preferenceEntry = [];
unified_argument_2_selecional_preferencies[slowal_frame_argument_mapping.unified_frame_agrument_id] = preferenceEntry
}
preferenceEntry.push.apply(preferenceEntry, slowal_frame_argument.preferences.filter(preference => !unified_frame_argument_preferences.has(preference.str)))
}
}
return unified_argument_2_selecional_preferencies;
}
function fulfill_slowal_frames_arguments_with_empty_elems(unified_frame, slowal_frames) {
for (let i in unified_frame.slowal_frame_mapping) {
const slowal_frame_mapping = unified_frame.slowal_frame_mapping[i];
let slowal_frame = slowal_frames.find(o => o.id === slowal_frame_mapping.slowal_frame_id);
let new_slowal_frame_arguments = [];
for (let j in unified_frame.arguments) {
const unified_frame_argument = unified_frame.arguments[j];
let unified_frame_argument_mapping = slowal_frame_mapping.slowal_frame_argument_mapping.find(o => o.unified_frame_agrument_id === unified_frame_argument.id);
let slowal_frame_argument = null;
if(unified_frame_argument_mapping == null) {
slowal_frame_argument = {
'str' : 'Empty',
'id' : slowal_frame.id+'-_'+(unified_frame_argument.id),
'role' : 'Empty',
'role_type' : 'Empty',
'preferences' : [],
'proposed_roles': [],
}
} else {
slowal_frame_argument = slowal_frame.arguments.find(o => o.argument_id === unified_frame_argument_mapping.slowal_frame_agrument_id);
}
new_slowal_frame_arguments.push(slowal_frame_argument)
}
slowal_frame.arguments = new_slowal_frame_arguments;
}
}
function frames2lexical_units(frames) {
const lexical_units = []
for (let i in frames) {
const frame = frames[i];
for (let j in frame.lexical_units) {
const lexical_unit = frame.lexical_units[j];
lexical_unit.opinion = frame.opinion;
lexical_unit.opinion_key = frame.opinion_key;
lexical_unit.frame_status = frame.status;
lexical_units.push(lexical_unit);
}
}
return lexical_units;
}