Commit 0175e48aebf296cd0b7e51ba40a78746cd2a6161

Authored by Bartłomiej Nitoń
1 parent 8918efb6

Added negation to regular expression based frame filters.

dictionary/models.py
... ... @@ -1434,8 +1434,6 @@ def sortFrameChars(frameChars):
1434 1434 def sortatributes(argument):
1435 1435 sortedatributes = []
1436 1436 atribute_models = get_attribute_models(argument)
1437   - #arg_model_obj = Argument_Model.objects.get(arg_model_name=argument.type)
1438   - #atribute_models = arg_model_obj.atribute_models.order_by('priority')
1439 1437 for atribute_model in atribute_models:
1440 1438 # warunek, zeby fixed stare dalo sie edytowac
1441 1439 if argument.atributes.filter(type=atribute_model.atr_model_name).exists():
... ...
dictionary/static/js/lemma-view.js
... ... @@ -3220,12 +3220,18 @@ function has_positions(frame, pos_term)
3220 3220 for(var i=0; i<conjs.length; i++) {
3221 3221 try {
3222 3222 var matched_poss = [];
3223   - var posRe = new RegExp('^'+escape_regex(conjs[i].trim())+'$');
  3223 + var conj = conjs[i].trim();
  3224 + var regEx = conj;
  3225 + if (regEx.substring(0, 1) == '!') {
  3226 + regEx = regEx.substring(1);
  3227 + }
  3228 + var posRe = new RegExp('^'+escape_regex(regEx)+'$');
3224 3229 matched_poss = $.grep(frame.positions,
3225 3230 function(pos){
3226 3231 return pos.text_rep.match(posRe);
3227 3232 });
3228   - if(matched_poss.length == 0) {
  3233 + if((matched_poss.length > 0 && conj.startsWith('!')) ||
  3234 + (matched_poss.length == 0 && !conj.startsWith('!'))) {
3229 3235 allConjsMatch = false;
3230 3236 break;
3231 3237 }
... ... @@ -3251,7 +3257,12 @@ function has_arguments(frame, arg_term) {
3251 3257 for(var i=0; i<conjs.length; i++) {
3252 3258 try {
3253 3259 var matched_args = [];
3254   - var argRe = new RegExp('^'+escape_regex(conjs[i].trim())+'$');
  3260 + var conj = conjs[i].trim();
  3261 + var regEx = conj;
  3262 + if (regEx.substring(0, 1) == '!') {
  3263 + regEx = regEx.substring(1);
  3264 + }
  3265 + var argRe = new RegExp('^'+escape_regex(regEx)+'$');
3255 3266  
3256 3267 for(var j=0; j<frame.positions.length; j++) {
3257 3268 matched_args = $.grep(frame.positions[j].arguments, function(arg) {
... ... @@ -3261,10 +3272,11 @@ function has_arguments(frame, arg_term) {
3261 3272 break;
3262 3273 }
3263 3274 }
3264   - if(matched_args.length == 0) {
3265   - allConjsMatch = false;
3266   - break;
3267   - }
  3275 + if((matched_args.length > 0 && conj.startsWith('!')) ||
  3276 + (matched_args.length == 0 && !conj.startsWith('!'))) {
  3277 + allConjsMatch = false;
  3278 + break;
  3279 + }
3268 3280 }
3269 3281 catch(e) {
3270 3282 allConjsMatch = false;
... ...
dictionary/teixml.py
... ... @@ -35,7 +35,7 @@ from xml.sax.saxutils import escape
35 35 from dictionary.models import Atribute_Model, Frame_Opinion_Value, \
36 36 Frame_Char_Model, PositionCategory, \
37 37 Argument_Model, \
38   - sortArguments, sortPositions
  38 + sortArguments, sortatributes, sortPositions
39 39 from dictionary.common_func import getArgsList
40 40  
41 41 XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace'
... ... @@ -247,21 +247,31 @@ def write_phrase(parent_elem, phrase, position_xml_id):
247 247 phrase_fs_elem.attrib[etree.QName(XML_NAMESPACE, 'id')] = phrase_xml_id
248 248 phrase_fs_elem.attrib['type'] = phrase.type
249 249  
250   - text_rep_elem = etree.SubElement(phrase_fs_elem, 'f')
251   - text_rep_elem.attrib['name'] = 'text_rep'
  250 +# text_rep_elem = etree.SubElement(phrase_fs_elem, 'f')
  251 +# text_rep_elem.attrib['name'] = 'text_rep'
  252 +# string_elem = etree.SubElement(text_rep_elem, 'string')
  253 +# string_elem.text = phrase.text_rep
252 254  
253   - string_elem = etree.SubElement(text_rep_elem, 'string')
254   - string_elem.text = phrase.text_rep
  255 + write_attributes(phrase_fs_elem, phrase)
  256 +
  257 +def write_attributes(parent_elem, phrase):
  258 + attributes = sortatributes(phrase)
  259 + for attribute in attributes:
  260 + writeattribute(parent_elem, attribute)
  261 +
  262 +def writeattribute(parent_elem, attribute):
  263 + attribute_model = Atribute_Model.objects.get(atr_model_name=attribute.type)
  264 + attr_f_elem = etree.SubElement(parent_elem, 'f')
  265 + attr_f_elem.attrib['name'] = attribute_model.sym_name
  266 + attr_f_elem.text = unicode(attribute)
  267 +
  268 +# if attribute_model.type.sym_name == 'parameter': # mamy problem, nie moze byc symbol, bo takie comprepnp np. ma spacje
  269 +# symbol_elem = etree.SubElement(attr_f_elem, 'symbol')
  270 +# symbol_elem.attrib['value'] = unicode(attribute)
  271 +# elif attribute_model.type.sym_name == 'text':
  272 +# string_elem = etree.SubElement(attr_f_elem, 'string')
  273 +# else:
255 274  
256   -# if argument.atributes.all():
257   -# outfile.write(u' <f name="attributes">\n')
258   -# outfile.write(u' <vColl org="list">\n')
259   -# # sort atributes
260   -# attributes = sortatributes(argument)
261   -# for attribute in attributes:
262   -# writeattribute(outfile, attribute)
263   -# outfile.write(u' </vColl>\n')
264   -# outfile.write(u' </f>\n')
265 275  
266 276 def write_examples_layer(parent_elem, lemma):
267 277 examples_layer_elem = etree.SubElement(parent_elem, 'fs')
... ... @@ -815,17 +825,5 @@ def writefsdecl(outfile):
815 825 outfile.write(u' </fsDecl>\n')
816 826  
817 827 outfile.write(u' </fsdDecl>\n')
818   - outfile.write(u' </encodingDesc>\n')
819   -
820   -def writeattribute(outfile, attribute):
821   - '''
822   - Write attribute feature structure to TEI xml file.
823   - '''
824   - # znajdz model atrybutu, zeby dodac jego miedzynarodowa nazwe
825   - attribute_model = Atribute_Model.objects.get(atr_model_name=attribute.type)
826   - outfile.write(u' <fs type="%s">\n' % unicode(attribute_model.sym_name))
827   - outfile.write(u' <f name="text_rep">\n')
828   - outfile.write(u' <symbol value="%s"/>\n' % unicode(attribute))
829   - outfile.write(u' </f>\n')
830   - outfile.write(u' </fs>\n')
  828 + outfile.write(u' </encodingDesc>\n')
831 829  
832 830 \ No newline at end of file
... ...