Commit fb6e09a6c059270dd0b8fdc8dae8a506dc98a6ef
1 parent
b82f1028
Connected entry and frame, improved 'się' handling for phraseology
Showing
4 changed files
with
46 additions
and
24 deletions
semantics/management/commands/connect_frames_to_entries.py
0 → 100644
1 | +#! /usr/bin/python | ||
2 | +# -*- coding: utf-8 -*- | ||
3 | + | ||
4 | +import sys, os, codecs | ||
5 | + | ||
6 | +from django.core.management.base import BaseCommand | ||
7 | + | ||
8 | +from dictionary.models import Entry | ||
9 | +from semantics.models import SemanticFrame | ||
10 | +from settings import PROJECT_PATH | ||
11 | + | ||
12 | +class Command(BaseCommand): | ||
13 | + args = 'none' | ||
14 | + help = '' | ||
15 | + | ||
16 | + def handle(self, **options): | ||
17 | + connect_frames() | ||
18 | + | ||
19 | +def connect_frames(): | ||
20 | + entries = Entry.objects.all() | ||
21 | + for entry in entries: | ||
22 | + frames = entry.actual_frames() | ||
23 | + for frame in frames: | ||
24 | + frame.entry = entry | ||
25 | + frame.save() | ||
26 | + |
semantics/models.py
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | 2 | ||
3 | from django.db import models | 3 | from django.db import models |
4 | 4 | ||
5 | -from dictionary.models import Argument, Frame, Position, NKJP_Example | 5 | +from dictionary.models import Argument, Frame, Position, NKJP_Example, Entry |
6 | from wordnet.models import LexicalUnit, Synset | 6 | from wordnet.models import LexicalUnit, Synset |
7 | from django.contrib.auth.models import User | 7 | from django.contrib.auth.models import User |
8 | from datetime import datetime | 8 | from datetime import datetime |
@@ -43,6 +43,8 @@ class SemanticFrame(models.Model): | @@ -43,6 +43,8 @@ class SemanticFrame(models.Model): | ||
43 | removed = models.BooleanField(default=False) | 43 | removed = models.BooleanField(default=False) |
44 | author = models.ForeignKey(User, null=True) | 44 | author = models.ForeignKey(User, null=True) |
45 | opinion = models.ForeignKey(FrameOpinion, null=True) | 45 | opinion = models.ForeignKey(FrameOpinion, null=True) |
46 | + # hasło w Walentym | ||
47 | + entry = models.ForeignKey(Entry, null=True, related_name='semantic_frames') | ||
46 | 48 | ||
47 | def role_exists(self, role_name): | 49 | def role_exists(self, role_name): |
48 | if self.complements.filter(roles__role=role_name).exists(): | 50 | if self.complements.filter(roles__role=role_name).exists(): |
semantics/saving.py
@@ -20,7 +20,7 @@ def make_operations(lemma_id, operations): | @@ -20,7 +20,7 @@ def make_operations(lemma_id, operations): | ||
20 | for operation in operations: | 20 | for operation in operations: |
21 | if operation['operation'] == "create_frame": | 21 | if operation['operation'] == "create_frame": |
22 | luids = [int(m['id']) for m in operation['meanings']] | 22 | luids = [int(m['id']) for m in operation['meanings']] |
23 | - translation['frame_id'][int(operation['id'])] = create_frame(luids) | 23 | + translation['frame_id'][int(operation['id'])] = create_frame(entry, luids) |
24 | elif operation['operation'] == "add_unit": | 24 | elif operation['operation'] == "add_unit": |
25 | translation['unit_id'][int(operation['unit']['id'])] = add_unit(entry, operation['unit']) | 25 | translation['unit_id'][int(operation['unit']['id'])] = add_unit(entry, operation['unit']) |
26 | elif operation['operation'] == "remove_frame": | 26 | elif operation['operation'] == "remove_frame": |
@@ -134,8 +134,8 @@ def make_operations(lemma_id, operations): | @@ -134,8 +134,8 @@ def make_operations(lemma_id, operations): | ||
134 | else: | 134 | else: |
135 | pass | 135 | pass |
136 | 136 | ||
137 | -def create_frame(luids): | ||
138 | - frame = SemanticFrame() | 137 | +def create_frame(entry, luids): |
138 | + frame = SemanticFrame(entry=entry) | ||
139 | frame.save() | 139 | frame.save() |
140 | for id in luids: | 140 | for id in luids: |
141 | lu = LexicalUnit.objects.get(id=id) | 141 | lu = LexicalUnit.objects.get(id=id) |
semantics/static/js/semantics_lexical_units.js
@@ -213,10 +213,11 @@ function getMeaningsSelectionForFrame(frame_id) { | @@ -213,10 +213,11 @@ function getMeaningsSelectionForFrame(frame_id) { | ||
213 | options.push(schemas_content[sch].display.arguments[0][k].lex); | 213 | options.push(schemas_content[sch].display.arguments[0][k].lex); |
214 | } | 214 | } |
215 | } | 215 | } |
216 | + var lex = {lemma: base, args: options}; | ||
216 | if (hasRefl(sch)) { | 217 | if (hasRefl(sch)) { |
217 | - options.push(['się']); | 218 | + lex.lemma = base + " się"; |
218 | } | 219 | } |
219 | - lexicalisation.push(options); | 220 | + lexicalisation.push(lex); |
220 | } | 221 | } |
221 | } | 222 | } |
222 | 223 | ||
@@ -229,25 +230,18 @@ function getMeaningsSelectionForFrame(frame_id) { | @@ -229,25 +230,18 @@ function getMeaningsSelectionForFrame(frame_id) { | ||
229 | 230 | ||
230 | function getFormForLexicalisation(lexicalisation) { | 231 | function getFormForLexicalisation(lexicalisation) { |
231 | var result = ""; | 232 | var result = ""; |
232 | - var perms = permutations(lexicalisation); | ||
233 | var i; | 233 | var i; |
234 | - for (i = 0; i < perms.length; i++) { | ||
235 | - result += lexicalisationForm(cartesian(perms[i])); | 234 | + for (i = 0; i < lexicalisation.length; i++) { |
235 | + var perms = permute(lexicalisation[i].args); | ||
236 | + var j; | ||
237 | + for (j = 0; j < perms.length; j++) { | ||
238 | + result += lexicalisationForm(lexicalisation[i].lemma, cartesian(perms[j])) | ||
239 | + } | ||
240 | + result += '<br\>'; | ||
236 | } | 241 | } |
237 | return result; | 242 | return result; |
238 | } | 243 | } |
239 | 244 | ||
240 | -function permutations(lllist) { | ||
241 | - //return lllist; | ||
242 | - if (lllist.length == 0) { | ||
243 | - return []; | ||
244 | - } else { | ||
245 | - var shortlllist = lllist.slice(); | ||
246 | - shortlllist.splice(0, 1); | ||
247 | - return permute(lllist[0]).concat([[]].concat(permutations(shortlllist))) | ||
248 | - } | ||
249 | -} | ||
250 | - | ||
251 | function permute(list) { | 245 | function permute(list) { |
252 | var i; | 246 | var i; |
253 | if (list.length == 0) { | 247 | if (list.length == 0) { |
@@ -292,7 +286,7 @@ function cartesian(llist) { | @@ -292,7 +286,7 @@ function cartesian(llist) { | ||
292 | return result; | 286 | return result; |
293 | } | 287 | } |
294 | 288 | ||
295 | -function lexicalisationForm(tokenised) { | 289 | +function lexicalisationForm(lemma, tokenised) { |
296 | var display = ""; | 290 | var display = ""; |
297 | var i; | 291 | var i; |
298 | for (i = 0; i < tokenised.length; i++) { | 292 | for (i = 0; i < tokenised.length; i++) { |
@@ -301,12 +295,12 @@ function lexicalisationForm(tokenised) { | @@ -301,12 +295,12 @@ function lexicalisationForm(tokenised) { | ||
301 | } else { | 295 | } else { |
302 | var j; | 296 | var j; |
303 | for (j = 0; j < lexical_units.length; j++) { | 297 | for (j = 0; j < lexical_units.length; j++) { |
304 | - if (base + " " + tokenised[i].join(" ") == lexical_units[j].base) { | 298 | + if (lemma + " " + tokenised[i].join(" ") == lexical_units[j].base) { |
305 | return ""; | 299 | return ""; |
306 | } | 300 | } |
307 | } | 301 | } |
308 | - display += "<input type = \"checkbox\" name = \"mwe\" value = \"" + base + " " + tokenised[i].join(" ") + "\">"; // TODO: unikalne wartości, wartość => dodanie odpowiedniej jednostki (nazwa jednostki w wartości?) | ||
309 | - display += base + " " + tokenised[i].join(" ") + "<br\>"; | 302 | + display += "<input type = \"checkbox\" name = \"mwe\" value = \"" + lemma + " " + tokenised[i].join(" ") + "\">"; // TODO: unikalne wartości, wartość => dodanie odpowiedniej jednostki (nazwa jednostki w wartości?) |
303 | + display += lemma + " " + tokenised[i].join(" ") + "<br\>"; | ||
310 | } | 304 | } |
311 | } | 305 | } |
312 | return display; | 306 | return display; |