Пример #1
0
 def initialize() -> None:
     if (OrgGlobal.GLOBAL_ORGS is not None): 
         return
     OrgGlobal.GLOBAL_ORGS = IntOntologyCollection()
     org0_ = None
     oi = None
     with ProcessorService.create_empty_processor() as geo_proc: 
         geo_proc.add_analyzer(GeoAnalyzer())
         geos = dict()
         for k in range(3):
             lang = (MorphLang.RU if k == 0 else (MorphLang.EN if k == 1 else MorphLang.UA))
             name = ("Orgs_ru.dat" if k == 0 else ("Orgs_en.dat" if k == 1 else "Orgs_ua.dat"))
             dat = PullentiNerOrgInternalResourceHelper.get_bytes(name)
             if (dat is None): 
                 raise Utils.newException("Can't file resource file {0} in Organization analyzer".format(name), None)
             with MemoryStream(OrgItemTypeToken._deflate(dat)) as tmp: 
                 tmp.position = 0
                 xml0_ = None # new XmlDocument
                 xml0_ = Utils.parseXmlFromStream(tmp)
                 for x in xml0_.getroot(): 
                     org0_ = OrganizationReferent()
                     abbr = None
                     for xx in x: 
                         if (Utils.getXmlLocalName(xx) == "typ"): 
                             org0_.add_slot(OrganizationReferent.ATTR_TYPE, Utils.getXmlInnerText(xx), False, 0)
                         elif (Utils.getXmlLocalName(xx) == "nam"): 
                             org0_.add_slot(OrganizationReferent.ATTR_NAME, Utils.getXmlInnerText(xx), False, 0)
                         elif (Utils.getXmlLocalName(xx) == "epo"): 
                             org0_.add_slot(OrganizationReferent.ATTR_EPONYM, Utils.getXmlInnerText(xx), False, 0)
                         elif (Utils.getXmlLocalName(xx) == "prof"): 
                             org0_.add_slot(OrganizationReferent.ATTR_PROFILE, Utils.getXmlInnerText(xx), False, 0)
                         elif (Utils.getXmlLocalName(xx) == "abbr"): 
                             abbr = Utils.getXmlInnerText(xx)
                         elif (Utils.getXmlLocalName(xx) == "geo"): 
                             geo_ = None
                             wrapgeo1767 = RefOutArgWrapper(None)
                             inoutres1768 = Utils.tryGetValue(geos, Utils.getXmlInnerText(xx), wrapgeo1767)
                             geo_ = wrapgeo1767.value
                             if (not inoutres1768): 
                                 ar = geo_proc.process(SourceOfAnalysis(Utils.getXmlInnerText(xx)), None, lang)
                                 if (ar is not None and len(ar.entities) == 1 and (isinstance(ar.entities[0], GeoReferent))): 
                                     geo_ = (Utils.asObjectOrNull(ar.entities[0], GeoReferent))
                                     geos[Utils.getXmlInnerText(xx)] = geo_
                                 else: 
                                     pass
                             if (geo_ is not None): 
                                 org0_.add_slot(OrganizationReferent.ATTR_GEO, geo_, False, 0)
                     oi = org0_.create_ontology_item_ex(2, True, True)
                     if (oi is None): 
                         continue
                     if (abbr is not None): 
                         oi.termins.append(Termin(abbr, None, True))
                     if (k == 2): 
                         OrgGlobal.GLOBAL_ORGS_UA.add_item(oi)
                     else: 
                         OrgGlobal.GLOBAL_ORGS.add_item(oi)
     return
Пример #2
0
 def deserialize_referent_from_xml(
         self,
         xml0_: xml.etree.ElementTree.Element,
         identity: str = None,
         create_links1: bool = True) -> 'Referent':
     """ Десериализация сущности из узла XML
     
     Args:
         xml0_(xml.etree.ElementTree.Element): 
         identity(str): для внутреннего использования (д.б. null)
     
     Returns:
         Referent: сущность
     """
     try:
         res = None
         for a in self.analyzers:
             res = a.create_referent(Utils.getXmlName(xml0_))
             if ((res) is not None):
                 break
         if (res is None):
             return None
         for x in xml0_:
             if (Utils.getXmlLocalName(x) == "#text"):
                 continue
             nam = Utils.getXmlName(x)
             if (nam.startswith("ATCOM_")):
                 nam = ("@" + nam[6:])
             att = Utils.getXmlAttrByName(x.attrib, "ref")
             slot = None
             if (att is not None and att[1] == "true"):
                 pr = ProxyReferent._new2850(Utils.getXmlInnerText(x), res)
                 pr.owner_slot = res.add_slot(nam, pr, False, 0)
                 slot = pr.owner_slot
                 att = Utils.getXmlAttrByName(x.attrib, "id")
                 if ((att) is not None):
                     pr.identity = att[1]
                 if (self.__m_refs is None):
                     self.__m_refs = list()
                 self.__m_refs.append(pr)
             else:
                 slot = res.add_slot(nam, Utils.getXmlInnerText(x), False,
                                     0)
             att = Utils.getXmlAttrByName(x.attrib, "count")
             if ((att) is not None):
                 cou = 0
                 wrapcou2851 = RefOutArgWrapper(0)
                 inoutres2852 = Utils.tryParseInt(att[1], wrapcou2851)
                 cou = wrapcou2851.value
                 if (inoutres2852):
                     slot.count = cou
         if (self.__m_links is None):
             self.__m_links = dict()
         if (self.__m_links2 is None):
             self.__m_links2 = dict()
         if (create_links1):
             key = str(res)
             if (not key in self.__m_links):
                 self.__m_links[key] = res
         if (not Utils.isNullOrEmpty(identity)):
             res.tag = identity
             if (not identity in self.__m_links2):
                 self.__m_links2[identity] = res
         return res
     except Exception as ex:
         return None