Exemplo n.º 1
0
 def parse(self, input, question_node):
     #производим поиск всех связок отношения координаты* в ответе
     coord_sheafs = []
     res_list = session.search3_f_a_a(input, sc.SC_A_CONST|sc.SC_POS, sc.SC_CONST|sc.SC_NODE)
     if res_list is not None:
         for res in res_list:
             sheaf_node = res[2]
             is_coord_rel_sheaf = sc_utils.checkIncToSets(session, sheaf_node, [sc_coord_rel_node], sc.SC_A_CONST|sc.SC_POS)
             if is_coord_rel_sheaf:
                 coord_sheafs.append(sheaf_node)
     
     #элементы связки отношения и запоминаем название географического
     for sheaf in coord_sheafs:
         obj_node = sc_utils.searchOneShot(session.search5_f_a_a_a_f(sheaf, sc.SC_A_CONST|sc.SC_POS, sc.SC_CONST|sc.SC_NODE, sc.SC_A_CONST|sc.SC_POS, sc_keys.n_1))[2]
         obj_name = sc_utils.getLocalizedIdentifier(session, obj_node)[0]
         
         """obj_class_node = session.search3_a_a_f(sc.SC_CONST|sc.SC_ELMNCLASS, sc.SC_A_CONST|sc.SC_POS, obj_node)
         if obj_class_node is not None:
             for el_set in obj_class_node:
                 print sc_utils.getLocalizedIdentifier(session, el_set[0])[0]                    
         obj_class_name = sc_utils.getLocalizedIdentifier(session, obj_class_node)[0]"""
         
         obj_class_name = "geo_obj"
         
         coord_node = sc_utils.searchOneShot(session.search5_f_a_a_a_f(sheaf, sc.SC_A_CONST|sc.SC_POS, sc.SC_CONST|sc.SC_NODE, sc.SC_A_CONST|sc.SC_POS, sc_keys.n_2))[2]
         #получаем координаты из содержимого узла
         _cont = session.get_content_const(coord_node)
         _cont_data = _cont.convertToCont()
         coords_str = str(_cont_data.d.ptr)
         
         #сохраняем сведения об географическом объекте в карту
         self.parsed_data[obj_class_name + " " + obj_name] = coords_str     
Exemplo n.º 2
0
 def translate_impl(self, _input, _output):
     """Translator implementation
     @param _input:    input data set
     @type _input:    sc_global_addr
     @param _output:    output window (must be created)
     @type _output:    sc_global_addr
     
     @return: list of errors each element of list is a tuple(object, error)
     @rtype: list
     """
     #look for question node
     els = session.search11_f_a_a_a_a_a_f_a_f_a_f(_input, 
                                         sc.SC_A_CONST|sc.SC_POS, sc.SC_N_CONST,
                                         sc.SC_A_CONST|sc.SC_POS, sc.SC_N_CONST,
                                         sc.SC_A_CONST|sc.SC_POS, sc_keys.n_2,
                                         sc.SC_A_CONST|sc.SC_POS, sc_keys.n_1,
                                         sc.SC_A_CONST|sc.SC_POS, sc_keys.info.stype_sheaf)
     el = sc_utils.searchOneShot(els)
     assert el is not None
     
     #get question node
     question_node = el[4]
     
     #check if answer on question can be translated
     if sc_utils.checkIncToSets(session, question_node, [sc_show_map_question_set], sc.SC_POS | sc.SC_CONST):
         print "Show map question, translating answer"
         #parse sc-construction
         
         parser = SCParser()
         parser.parse(_input, question_node)            
         data = parser.toYmapsML()
         
         file_name = self._generate_filename()
         self._send_data_to_server(file_name, data)
         #set returned script to _output node content
         session.set_content_str(_output, env.server_address + "/file/"+file_name)            
             
     errors = []
     print "sc2yandexmaps finish translation"
     
     return errors
Exemplo n.º 3
0
def searchOneShotPosArcAttrFrom(_session, _el, _attr):
    """Searches positive arc with attribute
    @see: searchPosArcAttrFrom
    """
    return sc_utils.searchOneShot(searchPosArcAttrFrom(_session, _el, _attr))
Exemplo n.º 4
0
def searchOneShotPosArcAttrFrom(_session, _el, _attr):
    """Searches positive arc with attribute
    @see: searchPosArcAttrFrom
    """
    return sc_utils.searchOneShot(searchPosArcAttrFrom(_session, _el, _attr))
Exemplo n.º 5
0
 def running(self, question):
     print "runing: Show map operation"
     
     res = []
     """targets = session.search3_f_a_a(question, sc.SC_A_CONST|sc.SC_POS, sc.SC_CONST|sc.SC_NODE)        
     # перебираем найденые элементы
     for target in targets:
         els = session.search3_f_a_a(target[2], sc.SC_A_CONST|sc.SC_POS, sc.SC_EMPTY)
         if els is not None:
             for el in els:
                 res.append(el[2])"""
                 
     #return test cont
     cont = sc_utils.searchOneShot(session.search3_f_a_a(sc_test_res_1, sc.SC_A_CONST|sc.SC_POS, sc.SC_CONST|sc.SC_NODE))[2]
     
     search_res_list = session.search3_f_a_a(cont, sc.SC_A_CONST|sc.SC_POS, sc.SC_CONST)
     if search_res_list is not None:
         for search_res in search_res_list:
             res.append(search_res[2])
     
                 
     #add sheet with type YMAPSML to display answer to
     
     """output_window = session.create_el(ui_segment, sc.SC_N_CONST)
     session.gen3_f_a_f(ui_segment, ymapsml_fmt_node, output_window, sc.SC_A_CONST)
     
     core.addOutputWindow(output_window)"""
     
     
     """input_param_set = None
     
     #get set of input parameters
     els = session.search3_f_a_f(question, sc.SC_A_CONST|sc.SC_POS, arg_set_node)
     result = sc_utils.searchOneShot(els)[2]
     
     assert result is not None
     input_param_set = result[2]
     
     res = []
     #search for output element from input_param and add all object in such set to result
     els = session.search3_f_a_a(input_param_set, sc.SC_A_CONST|sc.SC_POS, sc.SC_N_CONST)
     if els is not None:
         for el in els:
             elem_id = sc_utils.getLocalizedIdentifier(session, el[2])
             res.append(el[2])
             print "param id = %s" % (elem_id[0])"""
     
     """it = session.create_iterator(session.sc_constraint_new(sc_constants.CONSTR_5_a_a_f_a_a,
                                                        sc.SC_POS,
                                                        sc.SC_A_CONST | sc.SC_POS,
                                                        question,
                                                        sc.SC_A_CONST | sc.SC_POS,
                                                        sc.SC_POS), True)
     print "attributes for input arcs"
     while not it.is_over():
         elem_id = sc_utils.getLocalizedIdentifier(session, it.value(0))
         attr_id = sc_utils.getLocalizedIdentifier(session, it.value(4))
         print "elem id = %s  with attr id = %s" % (elem_id[0], attr_id[0])
         it.next()"""
     
     #show all input elements id's
     #print "input elements id's"
     #re = sc_utils.strInputIdtf(session, question)
     #print re
     
     # создаем множество для ответа
     #res = []
     # получаем элементы текущего вопроса
     """it = session.create_iterator(session.sc_constraint_new(sc_constants.CONSTR_3_f_a_a,
                                                        question,
                                                        sc.SC_A_CONST | sc.SC_POS,
                                                        sc.SC_CONST
                                                        ), True)
     print "ids of all question's elements"
     while not it.is_over():
         id = sc_utils.getLocalizedIdentifier(session, it.value(2))
         print "id = %s" % id[0]
         it.next()
     
     #test only"""
     #res.append(question)
     return res