diff --git a/semantics/saving.py b/semantics/saving.py
index 9afb9d7..d31e782 100644
--- a/semantics/saving.py
+++ b/semantics/saving.py
@@ -15,11 +15,13 @@ def modify_frames(lemma_id, operations, user):
     make_operations(operations)
 
 def make_operations(operations):
-    translation = {'frame_id': {}, 'complement_id': {}, 'preference_id': {}}
+    translation = {'unit_id': {}, 'frame_id': {}, 'complement_id': {}, 'preference_id': {}}
     for operation in operations:
         if operation['operation'] == "create_frame":
             luids = [int(m['id']) for m in operation['meanings']]
             translation['frame_id'][int(operation['id'])] = create_frame(luids)
+        elif operation['operation'] == "add_unit":
+            translation['unit_id'][int(operation['unit']['id'])] = add_unit(operation['unit'])
         elif operation['operation'] == "remove_frame":
             if int(operation['id']) in translation['frame_id']:
                 frame_id = translation['frame_id'][int(operation['id'])]
@@ -91,7 +93,7 @@ def make_operations(operations):
                 frame_id = translation['frame_id'][int(operation['frame_id'])]
             else:
                 frame_id = int(operation['frame_id'])
-            luids = [int(m) for m in operation['units']]
+            luids = [translation['unit_id'][int(m)] if int(m) in translation['unit_id'] else int(m) for m in operation['units']]
             change_units(frame_id, luids)
         elif operation['operation'] == "set_opinion":
             if int(operation['frame_id']) in translation['frame_id']:
diff --git a/semantics/static/js/semantics_lexical_units.js b/semantics/static/js/semantics_lexical_units.js
index 70fccd3..b15f7d5 100644
--- a/semantics/static/js/semantics_lexical_units.js
+++ b/semantics/static/js/semantics_lexical_units.js
@@ -166,6 +166,9 @@ function getMeaningsSelectionForFrame(frame_id) {
     var display = "";
     var id = "" + frame_id;
     
+
+    // podstawowe znaczenia
+    display += "<div>";
     var i;
     for (i = 0; i < lexical_units.length; i++) {
         display += "<input type = \"checkbox\" name = \"meaning\" value = \"" + lexical_units[i].id + "\""
@@ -182,10 +185,118 @@ function getMeaningsSelectionForFrame(frame_id) {
         }
         display += ">" + lexical_units[i].base + "-" + lexical_units[i].sense + "<br><div id=\"glossa_" + lexical_units[i].id + "\">" + lexical_units[i].glossa + "</div>"
     }
+    display += "</div>";
+
+    // znaczenia wielowyrazowe
+
+    var lexicalisation = [];
+
+    display += "<br/>";
+
+    display += "<div>";
+
+    var i;
+    var roles = frame_content[frame_id].display.roles;
+    for (i = 0; i < roles.length; i++) {
+        if (isPOL(frame_id, i)) {
+            var j;
+            for (j = 0; j < connected[roles[i].csv_class].length; j++) {
+                var options = [];
+		var sch = connected[roles[i].csv_class][j].split("pos")[0];
+	        var pos = connected[roles[i].csv_class][j].split("arg")[0];
+	        var k;
+                for (k = 0; k < schemas_content[sch].display.arguments[0].length; k++) {
+                    if (schemas_content[sch].display.arguments[0][k].csv_class == pos) {
+			var l;
+                        for (l = 0; l < schemas_content[sch].display.arguments[0][k].lex.length; l++) {
+			    options.push(schemas_content[sch].display.arguments[0][k].lex[l]);
+                        }
+                    } 
+                } 
+                var temp; // TODO: temporal solution for multiple schemata
+                if (hasRefl(sch)) {
+                    temp = [['się'], options]
+                } else {
+                    temp = [options]; 
+                }
+	        lexicalisation.push(temp);
+            } 
+	} 
+    }
+
+    display += getFormForLexicalisation(lexicalisation);
+
+    display += "</div>";
+
+    return display;
+}
+
+function getFormForLexicalisation(lexicalisation) {
+    var result = "";
+    var perms = permutations(lexicalisation);
+    var i;
+    for (i = 0; i < perms.length; i++) {
+        result += lexicalisationForm(cartesian(perms[i]));
+    }
+    return result;
+}
+
+function permutations(llist) {
+    return llist;
+/*    if (list.length == 0) {
+        return [[]];
+    }
+    var i;
+    var result = [];
+    for (i = 0; i < list.length; i++) {
+        var shortlist = list.slice();
+        shortlist.splice(i, 1);
+	var perms = permutations(shortlist);
+        var j;
+        for (j = 0; j < perms.length; j++) {
+            var tmp = perms[j];
+            tmp.push(list[i]);
+            result.push(tmp);
+        }
+    }
+    return result;
+*/
+}
+
+function cartesian(llist) {
+    if (llist.length == 0) {
+        return [[]];
+    }
+    var result = [];
+    var shortllist = llist.slice();
+    shortllist.splice(shortllist.length - 1, 1);
+    var carts = cartesian(shortllist);
+    var i;
+    for (i = 0; i < llist[llist.length - 1].length; i++) {
+        var tail = llist[llist.length - 1][i];
+        var heads = carts.slice();
+        var j;
+        for (j = 0; j < heads.length; j++) {
+            var tmp = heads[j].slice();
+            tmp.push(tail);
+            //alert(tmp);
+            result.push(tmp);
+        }
+    }
+    return result;
+}
 
+function lexicalisationForm(tokenised) {
+    var display = "";
+    var i;
+    for (i = 0; i < tokenised.length; i++) {
+        display += "<input type = \"checkbox\" name = \"mwe\" value = \"" + base + " " + tokenised[i].join(" ") + "\">"; // TODO: unikalne wartości, wartość => dodanie odpowiedniej jednostki (nazwa jednostki w wartości?)
+        display += base + " " + tokenised[i].join(" ") + "<br\>";
+    }
     return display;
 }
 
+
 // get readable form of lexical unit
 function getLexicalUnit(luid) {
     var i = indexOfId(lexical_units, luid);
@@ -193,3 +304,24 @@ function getLexicalUnit(luid) {
     var lu = lexical_units[i];
     return lu.base + '-' + lu.sense;
 }
+
+
+function addPhraseologicalUnit(mwe, glossa, relation, to) {
+    var lu = {base: mwe, glossa: "" + glossa, definition: "", id: free_luid, luid: -1, refl: "false", glossa: glossa, pos: "czasownik", sense: "A", relation: relation, to: to, location: ""};
+    var operation = {operation: 'add_unit', unit:lu};
+    lexical_units.push(lu);
+    lexical_unit_examples[free_luid] = [];
+    frames_operations.push(operation); 
+    free_luid -= 1; 
+    return (free_luid + 1);
+}
+
+function addPhraseologicalUnits(frame_id, old_units, mwes, glossa, relation, to) {
+    var i;
+    var units = [];
+    for (i = 0; i < mwes.length; i++) {
+        units.push(addPhraseologicalUnit(mwes[i], glossa, relation, to));
+    }
+    changeUnits(frame_id, old_units.concat(units));
+}
+
diff --git a/semantics/static/js/semantics_roles.js b/semantics/static/js/semantics_roles.js
index 3521c80..5b8dfa5 100644
--- a/semantics/static/js/semantics_roles.js
+++ b/semantics/static/js/semantics_roles.js
@@ -1,50 +1,60 @@
 var roles_display_table = ""; // roles table in html form
+var roles_display_table_full = ""; // with lemma role
 var role_name = [];           // displayed names of roles
 var role_color = [];          // colors assigned to roles
 
-function memorizeRoles(roles_display){
-    var i, j, k;
-    roles_display_table = '<table border="1" style="font-size: 11px">';
+function rolesToHtml(roles_display, full){
+    var i, j, k, table;
+    table = '<table border="1" style="font-size: 11px">';
     for (i = 0; i < roles_display.length; i++) {
-        roles_display_table += '<tr>';
+        table += '<tr>';
         for (j = 0; j < roles_display[i].length; j++) {
-            roles_display_table += '<td rowspan="';
-            roles_display_table += roles_display[i][j].rowspan;
-            roles_display_table += '" colspan="';
-            roles_display_table += roles_display[i][j].colspan;
-            roles_display_table += '">';
+            table += '<td rowspan="';
+            table += roles_display[i][j].rowspan;
+            table += '" colspan="';
+            table += roles_display[i][j].colspan;
+            table += '">';
             if (roles_display[i][j].caption != "None") {
-                roles_display_table += "<b>"
-                roles_display_table += roles_display[i][j].caption;
-                roles_display_table += "</b>"
+                table += "<b>"
+                table += roles_display[i][j].caption;
+                table += "</b>"
             }
             for (k = 0; k < roles_display[i][j].roles.length; k++) {
-                roles_display_table += '<div style=';
+                table += '<div style=';
                 if (roles_display[i][j].roles[k].color != 'None') {
-                    roles_display_table += '"background-color: rgb(' + roles_display[i][j].roles[k].color + ')';
+                    table += '"background-color: rgb(' + roles_display[i][j].roles[k].color + ')';
                 } else {
-                    roles_display_table += '"background: linear-gradient(to ' + roles_display[i][j].roles[k].gradient + ',  rgba(100,100,100,0.1), rgba(100,100,100,1))';
+                    table += '"background: linear-gradient(to ' + roles_display[i][j].roles[k].gradient + ',  rgba(100,100,100,0.1), rgba(100,100,100,1))';
                 }
-                roles_display_table += '"><input type="checkbox" name="roles" value="';
-                roles_display_table += roles_display[i][j].roles[k].id;
-                roles_display_table +=  '"><label>';
-                roles_display_table += roles_display[i][j].roles[k].rolename;
-                roles_display_table +=  '</label></div>';
-                role_name[roles_display[i][j].roles[k].id] = roles_display[i][j].roles[k].rolename;
-                role_color[roles_display[i][j].roles[k].id] = {"color": roles_display[i][j].roles[k].color, "gradient": roles_display[i][j].roles[k].gradient};
+                table += '"><input type="checkbox" name="roles" value="';
+                table += roles_display[i][j].roles[k].id;
+                table +=  '"><label>';
+                table += roles_display[i][j].roles[k].rolename;
+                table +=  '</label></div>';
+		if (full) {
+                    role_name[roles_display[i][j].roles[k].id] = roles_display[i][j].roles[k].rolename;
+                    role_color[roles_display[i][j].roles[k].id] = {"color": roles_display[i][j].roles[k].color, "gradient": roles_display[i][j].roles[k].gradient};
+		}
             }
-            roles_display_table += '</td>';
+            table += '</td>';
         }
-        roles_display_table += '</tr>';
+        table += '</tr>';
     }
-    roles_display_table += '</table>';
+    table += '</table>';
+
+    return table;
+}
+
+function memorizeRoles(roles_display, roles_full){
+    roles_display_table = rolesToHtml(roles_display, false);
+    roles_display_table_full = rolesToHtml(roles_full, true);
 }
 
 function getStyle(frame_id, complement_num) {
     style_type = "";
     style_color = "";
     style_value = ""
-    roles = frame_content[parseInt(frame_id)].display.roles[complement_num].argument;
+    var roles = frame_content[parseInt(frame_id)].display.roles[complement_num].argument;
     var i;
     for (i = 0; i < roles.length; i++) {
         var color = role_color[roles[i]];
@@ -63,3 +73,15 @@ function getStyle(frame_id, complement_num) {
     }
     return {"type": style_type, "value": style_value};
 }
+
+function isPOL(frame_id, complement_num) {
+    var roles = frame_content[parseInt(frame_id)].display.roles[complement_num].argument;
+    if (roles.length != 1) {
+	return false;
+    }
+    if (role_name[roles[0]] == 'Lemma') {
+	return true;
+    } else {
+	return false;
+    }
+}
diff --git a/semantics/static/js/semantics_schemas.js b/semantics/static/js/semantics_schemas.js
index 4329dc8..3bd866e 100644
--- a/semantics/static/js/semantics_schemas.js
+++ b/semantics/static/js/semantics_schemas.js
@@ -1,3 +1,4 @@
+var subentry_display = [];
 var ranks = {};                 // lexical unit based rank of schema
 var schemas_content = [];       // schemas in html form
 var default_order = [];         // default order of schemas
@@ -106,7 +107,7 @@ function schemaHeader(schema, alternates){
     return schema_header;
 }
 
-function schemaBody(schema, alternation){
+function schemaBody(schema, alternation, lex){
     var schema_body = '';
     
     if (alternation != 1) {
@@ -117,7 +118,7 @@ function schemaBody(schema, alternation){
     schema_body += '<td class="ColumnHeader">Funkcja:</td>';
     var display = schema.display;
     for (k = 0; k < display.categories.length; k++) {
-        schema_body += '<td class="' + display.categories[k].csv_class + 'alt_' + alternation + '_" id="' + display.categories[k].csv_class + 'alt_' + alternation + '_" onclick="schemaClick(\'' + display.categories[k].csv_id + 'alt_' + alternation + '_\')">';
+        schema_body += '<td class="' + display.categories[k].csv_class + 'alt_' + alternation + '_" id="' + display.categories[k].csv_class + 'alt_' + alternation + '_" onclick="schemaClick(\'' + display.categories[k].csv_id + 'alt_' + alternation + '_\', [])">';
         schema_body += display.categories[k].argument;
         schema_body += '</td>';
         position_arguments[display.categories[k].csv_class + 'alt_' + alternation + '_'] = [];
@@ -127,7 +128,12 @@ function schemaBody(schema, alternation){
     schema_body += '<td class="ColumnHeader" rowspan="' + schema.rowspan + '">Typy fraz:</td>';
     for (k = 0; k < display.arguments.length; k++) {
         for (l = 0; l < display.arguments[k].length; l++) {
-            schema_body += '<td id="' + display.arguments[k][l].csv_id + 'alt_' + alternation + '_" class="' + display.arguments[k][l].csv_class + 'alt_' + alternation + '_"  onclick="schemaClick(\'' + display.arguments[k][l].csv_id + 'alt_' + alternation +'_\')">';
+            schema_body += '<td id="' + display.arguments[k][l].csv_id + 'alt_' + alternation + '_" class="' + display.arguments[k][l].csv_class + 'alt_' + alternation + '_"  onclick="schemaClick(\'' + display.arguments[k][l].csv_id + 'alt_' + alternation +'_\', ';
+	    if (display.arguments[k][l].lex.length != 0) {
+		schema_body += '[\'' + display.arguments[k][l].lex.join('\', \'') + '\'])">';
+	    } else {
+		schema_body += '[])">';
+	    }
             schema_body += display.arguments[k][l].argument;
             schema_body += '</td>';
             if (parseInt(display.arguments[k][l].csv_id.split('_')[5]) >= 0) {
@@ -147,6 +153,7 @@ function alternationCounts(alternations) {
 
 function displaySchemas(lemma, characteristic_display){
     var i, j, k, l;
+    subentry_display = characteristic_display;
     var schemas_display = "";
     for (i = 0; i < characteristic_display.length; i++) {
         char_id = characteristic_display[i].characteristic_id;
@@ -205,3 +212,23 @@ function redrawSchemas(frame) {
         } 
     }
 }
+
+
+function hasRefl(schema) {
+    // TODO: refl i recip w schemacie
+    var sid = schemaId(schema);
+    var i, j;
+    for (i = 0; i < subentry_display.length; i++) {
+        var char_display = subentry_display[i].characteristic_display;
+        for (j = 0; j < subentry_display[i].schemas.length; j++) {
+            if (subentry_display[i].schemas[j].schema_id == sid) {
+		if (char_display.search('się') >= 0) {
+		    return true;
+		} else {
+		    return false;
+		}
+            }
+        }
+    }
+    return false;
+}
diff --git a/semantics/static/js/semantics_view.js b/semantics/static/js/semantics_view.js
index 96c212a..3f4066b 100644
--- a/semantics/static/js/semantics_view.js
+++ b/semantics/static/js/semantics_view.js
@@ -356,6 +356,9 @@ function createFrame() {
                         } else {
                             units = f.meaning;
                         }
+			if ((typeof units) == 'undefined') {
+			    units = [];
+			}
                     
                         frameClick("");
                         newFrame(units);
@@ -376,6 +379,47 @@ function createFrame() {
 
 function changeLexicalUnits() {
 
+    var getRelation = 
+        function(f) {
+	        return '<label>Relacja <select name="relation" disabled><option value="' + f.relation + '">' + relations_creating[parseInt(f.relation)] + '</option></label></select><br />';
+        };
+
+    var getRelationsForm =
+        function () {
+            var result = '<label>Relacja ';
+            result += '<select id="synset_input_relation" name="relation" onchange="changeSynsetInput()">';
+            result += '<option value="0">' + relations_creating[0] + '</option>';
+            result += '<option value="1">' + relations_creating[1] + '</option>';
+            result += '<option value="2">' + relations_creating[2] + '</option>';
+            result += '</select></label><br />';
+            return result;
+        };
+
+    var units = [];
+    var mwes = [];
+    var a = "";
+    var gloss = "";
+
+    var addPhraseology =
+                function(e,v,m,f){
+                    e.preventDefault();
+                    if (v == -1)
+                        $.prompt.goToState('state0');
+                    if (v == 0) {
+                        $.prompt.close();
+                    }
+                    if (v == 1) {
+                        changeUnits(highlighted_id, units);
+
+                        addPhraseologicalUnits(highlighted_id, units, mwes, f.glossa, f.relation, f.synset);
+
+                        frameClick("");
+		        displayFrames();
+                        frameClick(a);
+                        $.prompt.close();
+                    }
+                };
+
     var change_units = {
             state0: {
 	            title: 'Zmiana jednostek leksykalnych',
@@ -383,30 +427,69 @@ function changeLexicalUnits() {
 	            buttons: { "Anuluj": -1, "Potwierdź": 1 },
 	            focus: 1,
 	            submit:function(e,v,m,f){ 
-                    e.preventDefault();
-                    if (v == -1) {
-                        $.prompt.close();
-                    }
-                    if (v == 1) {
-                    
-                        var units = normalizeFormData(f.meaning);
-                        if (units.length > 0) {
-                    
-                            var a = semantics_selected_id;
-                            changeUnits(highlighted_id, units);
-                            frameClick("");
-                            displayFrames();
-                            frameClick(a);
-                            
+			e.preventDefault();
+			if (v == -1) {
+			    $.prompt.close();
+			}
+			if (v == 1) {
+
+			    units = normalizeFormData(f.meaning);
+			    mwes = normalizeFormData(f.mwe);
+			    a = semantics_selected_id;
+
+                            if (mwes.length == 0) {
+                                changeUnits(highlighted_id, units);
+			    
+                                frameClick("");
+                                displayFrames();
+                                frameClick(a);
+                                $.prompt.close();
+                            } else {
+                                 $.prompt.goToState('state1');
+                                 attachPlWNContextAutocomplete();
+                            }
+
+			}
+	            }
+            },
+            state1: { /* nowa frazeologia */
+	            title: 'Nowe jednostki frazeologiczne',
+	            html: '<label>Glossa <input type="text" name="glossa" value=""></label><br />' + 
+                          getRelationsForm() + "<label id=\"synset_input\">w stosunku do <input id=\"plWN_context_selection\" type=\"text\" name=\"context\"></label>",
+	            buttons: { "Wstecz": -1, "Anuluj": 0, "Potwierdź": 1 },
+	            focus: 1,
+	            submit:function(e,v,m,f){ 
+			e.preventDefault();
+			if (v == -1) {
+			    $.prompt.goToState('state0');
+			}
+                        if (v == 0) {
                             $.prompt.close();
-                            
-                        } else {
-                        
-                            alert("Należy wybrać co najmniej jedną jednostkę leksykalną dla ramy");
-                        
                         }
-                    }
-	            }
+			if (v == 1) {
+                            if (parseInt(f.relation) != 2) { 
+                                /* podana lokalizacja w Słowosieci */
+                                $.prompt.removeState('state2');
+                                $.prompt.addState('state2',
+                                                  {
+                                                      title: 'Znaczenia',
+                                                      html: '<label>Glossa <input type="text" name="glossa" value="' + gloss + '" disabled></label><br />' + 
+                                                            getRelation(f) + "w stosunku do:<br />" + getSynsets(f.context, "czasownik"), 
+                                                      buttons: {Wstecz: -1, Anuluj: 0, Zatwierdź: 1}, 
+                                                      focus: 1, 
+                                                      submit: addPhraseology
+                                                  })
+                                $.prompt.goToState('state2');
+                            } else {
+                                /* zignorowane umiejscowienie w Słowosieci */
+                                addPhraseologicalUnits(highlighted_id, units, mwes, f.glossa, f.relation, -1);
+			        frameClick("");
+			        displayFrames();
+			        frameClick(a)
+                                $.prompt.close();
+                            }
+			}
+	            }       
             },
         };
     if (change == true) {
@@ -1018,8 +1101,13 @@ function color(what, how, disconnected_background, disconnected_text) {
 
 }
 
-function schemaClick(class_id) {
+function schemaClick(class_id, lex) {
     
+    var table = roles_display_table;
+    if (lex.length != 0){
+	table = roles_display_table_full;
+    }
+
     var field_ids;
     if (class_id.split('arg').length == 1) {
         field_ids = position_arguments[class_id].slice();
@@ -1045,7 +1133,7 @@ function schemaClick(class_id) {
                 var choose_role = {
                         state0: {
                             title: 'Wybierz rolę',
-                            html: roles_display_table,
+                            html: table,
                             buttons: { Anuluj: -1, Zatwierdź: 1 },
                             focus: 1,
                             close: function(){return result;},
diff --git a/semantics/templates/roles.json b/semantics/templates/roles.json
index b6c8d31..22389ea 100644
--- a/semantics/templates/roles.json
+++ b/semantics/templates/roles.json
@@ -1,19 +1,6 @@
-{"roles_display": [
+{% load jsonify %}
 
-
-    {% for row, outer_comma in roles_display %}
-        [
-        {% for caption, rowspan, colspan, roles, row_comma in row %}
-            {
-            "caption": "{{ caption }}", "rowspan": {{ rowspan }}, "colspan": {{ colspan }}, "roles": [
-            {% for role, inner_comma in roles %}
-                { "id": {{ role.id }}, "rolename": "{{ role.role }}", "color": "{{ role.color }}", "gradient": "{{ role.gradient }}" }{{ inner_comma }}
-            {% endfor %}
-            ]
-            } {{ row_comma }}
-        {% endfor %}
-        ] {{ outer_comma }}
-    {% endfor %}
-
-
-]}
+{
+    "roles_display": {{ roles_display|jsonify }},
+    "roles_full": {{ roles_full|jsonify }}
+}
diff --git a/semantics/templates/semantics.html b/semantics/templates/semantics.html
index d08fd2b..006d969 100644
--- a/semantics/templates/semantics.html
+++ b/semantics/templates/semantics.html
@@ -35,7 +35,7 @@
         });
         
         $.getJSON(ajax_roles, function(data){
-            memorizeRoles(data.roles_display);
+            memorizeRoles(data.roles_display, data.roles_full);
             $.getJSON(ajax_opinions, {lemma_id: {{ lemma.id }}}, function(data){
 	        memorizeOpinions(data.opinions);
                 $.getJSON(ajax_frames, {lemma_id: {{ lemma.id }}}, function(data){
diff --git a/semantics/views.py b/semantics/views.py
index e3b578e..6396439 100644
--- a/semantics/views.py
+++ b/semantics/views.py
@@ -8,7 +8,7 @@ from semantics.models import SemanticRole, SemanticFrame, Complement, \
 from wordnet.models import Hypernymy, Synonymy
 
 from dictionary.models import Frame_Char_Model, Lemma, Lemma_Status, \
-                              sort_arguments, sort_positions
+                              sort_arguments, sort_positions, sortatributes
 from dictionary.ajax_lemma_view import user_can_modify
 from django.core.exceptions import SuspiciousOperation
 from django.core.urlresolvers import reverse
@@ -18,6 +18,7 @@ from common.decorators import render, ajax
 from semantics.saving import modify_frames, update_meanings
 from semantics.validation import validate_schemas, validate_frames, validate_lexical_units
 
+from settings import MORFEUSZ2
 
 ####################################### render #####################################
 
@@ -74,8 +75,8 @@ def reorder_history(frames_list):
 def ajax_frames(request, lemma_id):
 
     lemma = Lemma.objects.get(id=lemma_id, old=False)
-    lexical_units = LexicalUnit.objects.filter(Q(base=lemma.entry, pos="czasownik")|Q(base=lemma.entry+u' się', pos="czasownik")).order_by('sense')
-#    lexical_units = LexicalUnit.objects.filter(Q(base__startswith=lemma.entry + u' ')|Q(base__contains=u' '+lemma.entry+u' ')|Q(base__endswith=u' '+lemma.entry)|Q(base=lemma.entry)).order_by('sense')
+    # lexical_units = LexicalUnit.objects.filter(Q(base=lemma.entry, pos="czasownik")|Q(base=lemma.entry+u' się', pos="czasownik")).order_by('sense')
+    lexical_units = LexicalUnit.objects.filter(Q(base__startswith=lemma.entry + u' ')|Q(base__contains=u' '+lemma.entry+u' ')|Q(base__endswith=u' '+lemma.entry)|Q(base=lemma.entry)).order_by('sense')
     
     alternations = {}        
     frames_dict = {}
@@ -96,8 +97,6 @@ def ajax_frames(request, lemma_id):
             type_frames[t] = []
         type_frames[tuple(frame_units[frame_id])].append(frames_dict[frame_id])
 
-#    ala[ma]=kot    
-        
     frames_display = []
     complement_arguments = {}
     arguments_frame_connected = {}
@@ -194,7 +193,7 @@ def ajax_frames(request, lemma_id):
         frames_display.append(frame_display)
 
     # ala["ma"] = "kot"
-
+    
     context = {
                'frames_display': frames_display, 
                'connections': {'connected': complement_arguments, 'connected_reverse': arguments_frame_connected},
@@ -208,8 +207,8 @@ def ajax_frames(request, lemma_id):
 @ajax(method='get', encode_result=False)   
 def ajax_units(request, lemma_id):
     lemma = Lemma.objects.get(id=lemma_id, old=False)
-    lexical_units = LexicalUnit.objects.filter(Q(base = lemma.entry, pos="czasownik")|Q(base = lemma.entry + u' się', pos="czasownik")).order_by('base', 'sense')
-#    lexical_units = LexicalUnit.objects.filter(Q(base__startswith=lemma.entry + u' ', pos="czasownik")|Q(base__contains=u' '+lemma.entry+u' ', pos="czasownik")|Q(base__endswith=u' '+lemma.entry, pos="czasownik")|Q(base=lemma.entry, pos="czasownik")).order_by('base', 'sense')
+    # lexical_units = LexicalUnit.objects.filter(Q(base = lemma.entry, pos="czasownik")|Q(base = lemma.entry + u' się', pos="czasownik")).order_by('base', 'sense')
+    lexical_units = LexicalUnit.objects.filter(Q(base__startswith=lemma.entry + u' ', pos="czasownik")|Q(base__contains=u' '+lemma.entry+u' ', pos="czasownik")|Q(base__endswith=u' '+lemma.entry, pos="czasownik")|Q(base=lemma.entry, pos="czasownik")).order_by('base', 'sense')
 
     context = {
                'lexical_units': [{"id": lu.id, "luid": lu.luid, "base": lu.base, "sense": lu.sense, "pos": lu.pos, "glossa": lu.glossa, "definition": lu.definition, "location": location(lu)} for lu in lexical_units],
@@ -293,25 +292,46 @@ def ajax_opinions(request):
 
     return context
 
+def NoneisNone(o):
+    if o is None:
+        return 'None'
+    else:
+        return o
+
 @render('roles.json')  
 @ajax(method='get', encode_result=False)
 def ajax_roles(request):       
     roles_display = []
     maxrow = SemanticRolesDisplay.objects.all().order_by('-row')[0].row
-    for i in range(1, maxrow + 1):
+    for i in range(1, maxrow):
         row = []
         cells = SemanticRolesDisplay.objects.filter(row=i).order_by('column')
         for cell in cells:
-            content = cell.roles.all().order_by('id')
-            commas = [','] * max(len(content) - 1, 0) + ['']
-            row.append((cell.caption, cell.rowspan, cell.colspan, zip(content, commas)))
-        commas = [','] * max(len(row) - 1, 0) + ['']
-        captions, rowspans, colspans, contents = zip(*row)
-        roles_display.append(zip(list(captions), list(rowspans), list(colspans), list(contents), commas))
-    commas = [','] * max(len(roles_display) - 1, 0) + ['']
+            roles = [{"id": r.id, "rolename": r.role, "color": NoneisNone(r.color), "gradient": NoneisNone(r.gradient)} for r in cell.roles.all().order_by('id')]
+            row.append({"caption": NoneisNone(cell.caption), 
+                        "rowspan": cell.rowspan, 
+                        "colspan": cell.colspan, 
+                        "roles": roles})
+        roles_display.append(row)
+
+    roles_short = roles_display[:]
+     
+    row = []
+    cells = SemanticRolesDisplay.objects.filter(row=maxrow).order_by('column')
+    for cell in cells:
+        roles = [{"id": r.id, "rolename": r.role, "color": NoneisNone(r.color), "gradient": NoneisNone(r.gradient)} for r in cell.roles.all().order_by('id')]
+        row.append({"caption": NoneisNone(cell.caption), 
+                    "rowspan": cell.rowspan, 
+                    "colspan": cell.colspan, 
+                    "roles": roles})
+    roles_display.append(row)
+
+    roles_full = roles_display
+
 
     context = {
-               'roles_display': zip(roles_display, commas),
+               'roles_display': roles_short,
+               'roles_full': roles_full
               }
 
     return context
@@ -373,13 +393,22 @@ def ajax_schemas(request, lemma_id):
                 for schema_id, position in zip(schema_ids, ordered_positions):
                     if position.arguments.count() > i:
                         ordered_arguments = sort_arguments(position.arguments.all())
-                        row.append(unicode(ordered_arguments[i]))
+                        row.append((unicode(ordered_arguments[i]), ordered_arguments[i]))
                         idents.append(schema_id + 'arg_' + str(ordered_arguments[i].id) + '_')
                     else: # this category has fewer posible argument realizations
-                        row.append('')
+                        row.append(('', None))
                         idents.append(schema_id + 'arg_-' + str(i + 1) + '_')
                 # identifier, class, argument
-                display["arguments"].append([{"csv_id": i, "csv_class": c, "argument": a} for i, c, a in zip(idents, schema_ids, row)])
+                arg =  []
+                #ma["ala"] = kot
+                for i, c, a in zip(idents, schema_ids, row):
+                    astr, aobj = a
+                    if aobj is not None and aobj.is_phraseologic():
+                        lex = lexicalisation(aobj)
+                    else:
+                        lex = []
+                    arg.append({"csv_id": i, "csv_class": c, "argument": astr, "lex": lex})
+                display["arguments"].append(arg)
             
             schema_display["schemas"].append({"schema_id": str(schema.id), "grade": lemma.get_schema_opinion(schema), "colspan": str(max(len(schema_categories), 1)), "rowspan": str(schema_arguments_rowspan), "display": display, "phraseologic": schema.phraseologic})
             
@@ -400,6 +429,62 @@ def ajax_schemas(request, lemma_id):
 
     return context
   
+def lexicalisation(argument):
+    b = argument.type
+    attributes = sortatributes(argument)
+    lexicalisation_type = attributes[0].values.all()[0].argument.type
+    lexicalisation_parameters = sortatributes(attributes[0].values.all()[0].argument)
+    if lexicalisation_type == 'np': # np(case), number, nouns, atr
+        nps = get_nps(get_case(lexicalisation_parameters[0]), get_number(attributes[1]), get_words(attributes[2]), attributes[3])
+        return nps
+    elif lexicalisation_type == 'prepnp': #prepnp(prep, case), number, nouns, atr
+        prepnps = get_prepnps(get_preposition(lexicalisation_parameters[0]), get_case(lexicalisation_parameters[1]), get_number(attributes[1]), get_words(attributes[2]), attributes[3])
+        return prepnps
+    else:
+        return []
+    return []
+
+def get_preposition(attribute):
+    return attribute.values.all()[0].parameter.type.name
+
+def get_words(attribute):
+    words = [word.text[1:-1] for word in attribute.values.all()]
+    return words
+
+def get_case(attribute):
+    case = attribute.values.all()[0].parameter.type.name
+    if case == u'str':
+        case = u'acc'
+    return case
+
+def get_number(attribute):
+    number = attribute.values.all()[0].parameter.type.name
+    return number
+
+def get_nps(case, number, nouns, _atr):
+    result = []
+    for noun in nouns:
+        options = [(interp.orth, interp.getTag(MORFEUSZ2)) for interp in MORFEUSZ2.generate(noun.encode('utf8'))]
+        if case != u'_':
+            filtered = []
+            for option in options:
+                (orth, tag) = option
+                if case in tag:
+                    filtered.append(option)
+            options = filtered
+        if number != u'_':
+            filtered = []
+            for option in options:
+                (orth, tag) = option
+                if number in tag:
+                    filtered.append(option)
+            options = filtered
+    return [orth for orth, _ in options]
+
+def get_prepnps(prep, case, number, nouns, _atr):
+    nps = get_nps(case, number, nouns, _atr)
+    return [prep + ' ' + np for np in nps]
+
 @render('examples.json')   
 @ajax(method='get', encode_result=False)
 def ajax_examples(request, lemma_id):