Example #1
0
def findPlanetTitle(session, planet, language):
    """
    @param session:  current workable session
    @type session:   sc_session
    @param planet:   planet which title we are finding
    @type planet:    sc_global_addr
    @param language:   language of title
    @type language:    sc_global_addr
    
    @return: title of the planet
    @rtype: string 
    """
    identficationKey = keynodes.common.nrel_identification

    addr1 = sc_utils.searchOneShotBinPairAttrToNode(session, planet,
                                                    identficationKey,
                                                    sc.SC_N_CONST)
    if addr1 is not None:
        addr2 = searchPosArcFrom(session, addr1)
        for addr in addr2:
            is_spec_lang = sc_utils.checkIncToSets(session, addr, [language],
                                                   sc.SC_A_CONST)
            if is_spec_lang is True:
                content = session.get_content_str(addr)
                if content is not None:
                    return sc_utils.cp1251ToUtf8(content)
    return None
Example #2
0
def findPlanetProperty(session, planet, property, unit_attr):
    """
    @param session:  current workable session
    @type session:   sc_session
    @param planet:   planet which property we are finding
    @type planet:    sc_global_addr
    @param property:   property keynode
    @type property:    sc_global_addr
    @param unit_attr:   property unit attribute keynode
    @type unit_attr:    sc_global_addr
    
    @return: property value of the planet
    @rtype: str 
    """

    identficationKey = keynodes.common.nrel_identification
    dec_system = space_keynodes.DefaultAttr.dec_system

    addr1 = sc_utils.searchOneShotBinPairAttrFromNode(session, planet,
                                                      property, sc.SC_N_CONST)
    if addr1 is not None:
        addr2 = searchOneShotPosArcAttrFrom(session, addr1, unit_attr)
        addr3 = sc_utils.searchOneShotBinPairAttrToNode(
            session, addr2, identficationKey, sc.SC_N_CONST)
        addr4 = searchPosArcAttrFrom(session, addr3, dec_system)
        for addr in addr4:
            content = session.get_content_str(addr)
            if content is not None:
                return sc_utils.cp1251ToUtf8(str(content))

    return None
Example #3
0
def findPlanetAtmosphChemistry(session, planet):
    """
    @param session:  current workable session
    @type session:   sc_session
    @param planet:   planet which radius we are finding
    @type planet:    sc_global_addr
    
    @return: chemistry of the planet
    @rtype: tuple(property_name, [tuple(substance_name, percent),...],unit_name) 
    """
    atmosphereKey = space_keynodes.SpaceRelation.atmosphere
    chemistryKey = space_keynodes.SpaceRelation.chemistry

    prop_name = str(sc_utils.cp1251ToUtf8(session.get_idtf(atmosphereKey)))
    prop_name = prop_name.replace('*', '')

    result = None

    addr1 = sc_utils.searchOneShotBinPairAttrFromNode(session, planet,
                                                      atmosphereKey,
                                                      sc.SC_N_CONST)
    if addr1 is not None:
        addr2 = sc_utils.searchOneShotBinPairAttrFromNode(
            session, addr1, chemistryKey, sc.SC_N_CONST)
        chemistry = findAllPlanetProperties(session, addr2)
        items = []
        unit_name = ""
        for chem in chemistry:
            if chem is not None:
                name, value, unit_name = chem
                item = (name, value)
                items.append(item)
                result = (prop_name, items, unit_name)
    return result
Example #4
0
def findPlanetAtmosphChemistry(session, planet):
    """
    @param session:  current workable session
    @type session:   sc_session
    @param planet:   planet which radius we are finding
    @type planet:    sc_global_addr
    
    @return: chemistry of the planet
    @rtype: tuple(property_name, [tuple(substance_name, percent),...],unit_name) 
    """
    atmosphereKey = space_keynodes.SpaceRelation.atmosphere
    chemistryKey = space_keynodes.SpaceRelation.chemistry
    
    prop_name = str(sc_utils.cp1251ToUtf8(session.get_idtf(atmosphereKey)))
    prop_name = prop_name.replace('*', '')
        
    result=None
    
    addr1 = sc_utils.searchOneShotBinPairAttrFromNode(session, planet, atmosphereKey, sc.SC_N_CONST)    
    if addr1 is not None:
        addr2 = sc_utils.searchOneShotBinPairAttrFromNode(session, addr1, chemistryKey, sc.SC_N_CONST)
        chemistry = findAllPlanetProperties(session, addr2)
        items = []
        unit_name = ""
        for chem in chemistry:
            if chem is not None:
                name, value, unit_name = chem
                item = (name, value)
                items.append(item)
                result = (prop_name, items, unit_name)
    return result
Example #5
0
def findPlanetProperty(session, planet, property, unit_attr):
    """
    @param session:  current workable session
    @type session:   sc_session
    @param planet:   planet which property we are finding
    @type planet:    sc_global_addr
    @param property:   property keynode
    @type property:    sc_global_addr
    @param unit_attr:   property unit attribute keynode
    @type unit_attr:    sc_global_addr
    
    @return: property value of the planet
    @rtype: str 
    """
    
    identficationKey = keynodes.common.nrel_identification
    dec_system = space_keynodes.DefaultAttr.dec_system
 
    addr1 = sc_utils.searchOneShotBinPairAttrFromNode(session, planet, property, sc.SC_N_CONST)
    if addr1 is not None:
        addr2 = searchOneShotPosArcAttrFrom(session, addr1, unit_attr)
        addr3 = sc_utils.searchOneShotBinPairAttrToNode(session, addr2, identficationKey, sc.SC_N_CONST)
        addr4 = searchPosArcAttrFrom(session, addr3, dec_system)
        for addr in addr4:
            content = session.get_content_str(addr)
            if content is not None:
                return sc_utils.cp1251ToUtf8(str(content))
        
    return None
Example #6
0
def findAllPlanetProperties(session, planet):
    """
    @param session:  current workable session
    @type session:   sc_session
    @param planet:   planet which properties we are finding
    @type planet:    sc_global_addr
        
    @return: list of the planet properties
    @rtype: list[tuple(key,value,unit),...]
    """

    identficationKey = keynodes.common.nrel_identification
    dec_system = space_keynodes.DefaultAttr.dec_system
    properties = []

    list1 = searchBinPairsFromNode(session, planet, sc.SC_CONST)

    for el in list1:
        list2 = searchPosArcFrom(session, el[1])
        if len(list2) > 0:
            addr1 = list2[0]
            list3 = searchFullPosArcFrom(session, el[1], addr1)
            attr = list3[0][1]
            rel = el[0]
            prop_name = str(sc_utils.cp1251ToUtf8(session.get_idtf(rel)))
            prop_name = prop_name.rstrip('*')
            unit_name = str(sc_utils.cp1251ToUtf8(session.get_idtf(attr)))
            unit_name = unit_name.rstrip('_')
            unit_name = unit_name.replace("значение", "")
            prop_value = str(findPlanetProperty(session, planet, rel, attr))

            properties.append((prop_name, prop_value, unit_name))

    chemistry = findPlanetAtmosphChemistry(session, planet)
    properties.append(chemistry)

    return properties
Example #7
0
def findAllPlanetProperties(session, planet):
    """
    @param session:  current workable session
    @type session:   sc_session
    @param planet:   planet which properties we are finding
    @type planet:    sc_global_addr
        
    @return: list of the planet properties
    @rtype: list[tuple(key,value,unit),...]
    """
    
    identficationKey = keynodes.common.nrel_identification
    dec_system = space_keynodes.DefaultAttr.dec_system
    properties=[]
 
    list1 = searchBinPairsFromNode(session, planet, sc.SC_CONST)
    
    for el in list1:
         list2 = searchPosArcFrom(session, el[1])
         if len(list2)>0:
             addr1 = list2[0]
             list3 = searchFullPosArcFrom(session, el[1], addr1)
             attr = list3[0][1]
             rel = el[0]
             prop_name = str(sc_utils.cp1251ToUtf8(session.get_idtf(rel)))
             prop_name = prop_name.rstrip('*')
             unit_name = str(sc_utils.cp1251ToUtf8(session.get_idtf(attr)))
             unit_name = unit_name.rstrip('_')
             unit_name = unit_name.replace("значение", "")
             prop_value = str(findPlanetProperty(session, planet, rel, attr))
           
             properties.append((prop_name, prop_value, unit_name))   
    
    chemistry = findPlanetAtmosphChemistry(session, planet);
    properties.append(chemistry)
     
    return properties
Example #8
0
def findPlanetTitle(session, planet, language):
    """
    @param session:  current workable session
    @type session:   sc_session
    @param planet:   planet which title we are finding
    @type planet:    sc_global_addr
    @param language:   language of title
    @type language:    sc_global_addr
    
    @return: title of the planet
    @rtype: string 
    """
    identficationKey = keynodes.common.nrel_identification
    
    addr1 = sc_utils.searchOneShotBinPairAttrToNode(session, planet, identficationKey, sc.SC_N_CONST)
    if addr1 is not None:
        addr2 = searchPosArcFrom(session, addr1) 
        for addr in addr2:
            is_spec_lang = sc_utils.checkIncToSets(session, addr, [language], sc.SC_A_CONST)
            if is_spec_lang is True:
                content = session.get_content_str(addr)
                if content is not None:
                    return sc_utils.cp1251ToUtf8(content)
    return None
Example #9
0
def searchBinPairsFromNode(_session, _beg, _const):
    """Searches full data for all binary orient pairs with specified begin element
    @param _session:    session to work with
    @type _session: MThreadSession
    @param _beg:    begin element of pair
    @type _beg:    sc_global_addr
    @param _const:    pair constant type
    @type _const:    int
        
    @return:    list of tuple(rel, end)
    @rtype:     list
    
    @raise RuntimeWarning:    if structure of binary orient pair is wrong
    
    template:
                x ? rel
                |
                v
        O =============> ? (node to find)
     _beg                
    """

    res = []
    # finding sheaf node
    it1 = _session.create_iterator(
        _session.sc_constraint_new(sc_constants.CONSTR_5_a_a_f_a_f,
                                   sc.SC_NODE | _const,
                                   sc.SC_ARC | sc.SC_POS | _const, _beg,
                                   sc.SC_ARC | sc.SC_POS | _const,
                                   keynodes.n_1), True)
    while not it1.is_over():
        # check if founded node is sheaf
        sheaf_node = it1.value(0)
        if sc_utils.isNodeSheaf(_session, sheaf_node):
            #finding relation node
            list1 = searchPosArcTo(_session, sheaf_node)
            rel_node = None
            for el in list1:
                idtf = str(sc_utils.cp1251ToUtf8(_session.get_idtf(el)))
                if not idtf.__eq__("stype_sheaf"):
                    rel_node = el

            # finding end node
            it2 = _session.create_iterator(
                _session.sc_constraint_new(sc_constants.CONSTR_5_f_a_a_a_f,
                                           sheaf_node,
                                           sc.SC_ARC | sc.SC_POS | _const,
                                           sc.SC_NODE,
                                           sc.SC_ARC | sc.SC_POS | _const,
                                           keynodes.n_2), True)
            end_el = None
            while not it2.is_over():
                if end_el is None:
                    end_el = it2.value(2)
                else:
                    raise RuntimeWarning("Invalid binary orient pair")
                it2.next()

            if end_el is not None: res.append((rel_node, end_el))

        it1.next()

    return res
Example #10
0
def searchBinPairsFromNode(_session, _beg, _const):
    """Searches full data for all binary orient pairs with specified begin element
    @param _session:    session to work with
    @type _session: MThreadSession
    @param _beg:    begin element of pair
    @type _beg:    sc_global_addr
    @param _const:    pair constant type
    @type _const:    int
        
    @return:    list of tuple(rel, end)
    @rtype:     list
    
    @raise RuntimeWarning:    if structure of binary orient pair is wrong
    
    template:
                x ? rel
                |
                v
        O =============> ? (node to find)
     _beg                
    """
    
    res = []
    # finding sheaf node
    it1 = _session.create_iterator(_session.sc_constraint_new(sc_constants.CONSTR_5_a_a_f_a_f,
                                                           sc.SC_NODE | _const,
                                                           sc.SC_ARC | sc.SC_POS | _const,
                                                           _beg,
                                                           sc.SC_ARC | sc.SC_POS | _const,
                                                           keynodes.n_1), True)
    while not it1.is_over():
        # check if founded node is sheaf
        sheaf_node = it1.value(0)
        if sc_utils.isNodeSheaf(_session, sheaf_node):
            #finding relation node
            list1 = searchPosArcTo(_session, sheaf_node)
            rel_node = None
            for el in list1:
                idtf = str(sc_utils.cp1251ToUtf8(_session.get_idtf(el)))
                if not idtf.__eq__("stype_sheaf"):
                    rel_node=el
                                
            # finding end node
            it2 = _session.create_iterator(_session.sc_constraint_new(sc_constants.CONSTR_5_f_a_a_a_f,
                                                                   sheaf_node,
                                                                   sc.SC_ARC | sc.SC_POS | _const,
                                                                   sc.SC_NODE,
                                                                   sc.SC_ARC | sc.SC_POS | _const,
                                                                   keynodes.n_2), True)
            end_el = None
            while not it2.is_over():
                if end_el is None:
                    end_el = it2.value(2)
                else:
                    raise RuntimeWarning("Invalid binary orient pair")
                it2.next()
                
            if end_el is not None:   res.append((rel_node, end_el))
            
        it1.next()
   
    return res