def readBible(oldFile, newFile): contentOld = fileReader.getFileContentRemEmptys(oldFile) contentNew = fileReader.getFileContentRemEmptys(newFile) bible = database.Bible() ommitedLinesOld = 0 ommitedLinesNew = 0 for line in contentOld: try: parsed = parser.parse(line) bible.addVerset("Stary Testament", parsed[0], parsed[1], [parsed[2], parsed[3]]) except ValueError: ommitedLinesOld = ommitedLinesOld + 1 for line in contentNew: try: parsed = parser.parse(line) bible.addVerset("Stary Testament", parsed[0], parsed[1], [parsed[2], parsed[3]]) except ValueError: ommitedLinesNew = ommitedLinesNew + 1 log.inf("Ommited: old " + str(ommitedLinesOld)) log.inf("Ommited: new " + str(ommitedLinesNew)) return bible
def getJournal(self): journal = {} journal['title'] = utils.get_text(self.tree, './/journal-title') journal['nlmTa'] = utils.get_text( self.tree, './/journal-meta/journal-id/[@journal-id-type="nlm-ta"]') journal['isoAbbrev'] = utils.get_text( self.tree, './/journal-meta/journal-id/[@journal-id-type="iso-abbrev"]') journal['issn'] = utils.get_atrib_dic(self.tree, './/journal-meta/issn', 'pub-type') journal['publisher'] = utils.get_iter_tex_dic( self.tree, './/journal-meta/publisher/publisher-name') self.dict['journal'] = journal
def CreateThing(url, ninterface): met = {} met['uid'] = url met['netif'] = ninterface met['LastUpdate'] = int(round(time.time() * 1000)) #in ms url = Config.OCFModelRoot + url ThingFactory.parser = Parser(url, 'JSON') thng = ThingFactory.parser.Parse() logging.debug('Parsed OCF thing from ' + url) #Now create the thing met['schema'] = thng['$schema'] #Metadata for key in thng: if not (type(thng[key]) == dict or type(thng[key]) == list): met[key] = thng[key] #properties pro = {} try: prop = thng['definitions'] for p in prop: ppts = prop[p]['properties'] for pp in ppts: pro[pp] = None except KeyError: pro = {} meta = ThingAttribute(**met) props = ThingAttribute(**pro) actns = ThingAttribute(**pro) thing = Thing(meta, props, actns) return thing
def CreateThing(url, ninterface): met = {} met['uid'] = url met['netif'] = ninterface met['LastUpdate'] = int(round(time.time() * 1000)) #in ms url = Config.W3CModelRoot + url ThingFactory.parser = Parser(url, 'JSON') thng = ThingFactory.parser.Parse() logging.debug('Parsed W3C thing from ' + url) #Now create the thing met['context'] = thng['@context'] #Metadata for key in thng: if not (type(thng[key]) == dict or type(thng[key]) == list): met[key] = thng[key] #properties pro = {} try: prop = thng['interactions'] for p in prop: if p['@type'][0] == 'Property': pro[p['name']] = None except KeyError: pro = {} meta = ThingAttribute(**met) props = ThingAttribute(**pro) actns = ThingAttribute(**pro) thing = Thing(meta, props, actns) return thing
def CreateThing(url, ninterface): met = {} met['uid'] = url met['netif'] = ninterface met['LastUpdate'] = int(round(time.time() * 1000)) #in ms url = Config.IPSOModelRoot + url ThingFactory.parser = Parser(url, 'XML') thng = ThingFactory.parser.Parse() logging.debug('Parsed IPSO thing from ' + url) #Now create the thing root = thng.getroot() #Metadata res = root.find('Object') name = res.find('Name') met['Name'] = name.text met['schema'] = str(root.attrib) #properties pro = {} try: res = root.find('Object').find('Resources') for child in res.findall('Item'): pp = child.find('Name') pro[pp.text] = None except KeyError: pro = {} meta = ThingAttribute(**met) props = ThingAttribute(**pro) actns = ThingAttribute(**pro) thing = Thing(meta, props, actns) return thing
def getContributors(self): tree = self.tree.findall('.//contrib-group/contrib/[@contrib-type]') contributors = [] if tree is not None: for e in tree: if (e.text is not None): contrib = {} contrib['type'] = e.attrib['contrib-type'] contrib['name'] = utils.get_text(e, './/name/*', ', ') contributors.append(contrib) self.dict['contributors'] = contributors
def getAffiliations(self): tree = self.tree.findall('.//aff') affiliations = [] if tree is not None: for e in tree: aff = {'id': 'aff', 'name': '', 'country': ''} try: aff['id'] = e.attrib['id'] except: pass aff['name'] = utils.get_text(e, './/institution') aff['address'] = utils.get_text(e, './/addr-line') aff['country'] = utils.get_text(e, './/country') try: if not aff['name']: aff['name'] = aff['address'] if not aff['name']: aff['name'] = [t for t in e.itertext()][-1] except: pass try: if not aff['country']: if aff['address']: aff['country'] = aff['address'].split( ',')[-1].lstrip() elif aff['name']: aff['country'] = aff['name'].split( ',')[-1].lstrip() except: pass affiliations.append(aff) self.dict['affiliations'] = affiliations
def parse(self): self.openFile() # Title tree_title = self.tree.find('.//title-group/article-title') title = utils.get_iter_tex(tree_title) self.dict['title'] = title # Article meta self.dict['pmid'] = utils.get_text( self.tree, './/article-meta/article-id/[@pub-id-type="pmid"]') self.dict['pmc'] = utils.get_text( self.tree, './/article-meta/article-id/[@pub-id-type="pmc"]') self.dict['doi'] = utils.get_text( self.tree, './/article-meta/article-id/[@pub-id-type="doi"]') self.dict['publisherId'] = utils.get_text( self.tree, './/article-meta/article-id/[@pub-id-type="publisher-id"]') # Keywords self.dict['keywords'] = [] for i in self.tree.findall('.//article-meta/*/kwd'): for t in i.findall('.//*'): self.dict['keywords'].append(t.text) if len(self.dict['keywords']) == 0: self.dict['keywords'] = utils.get_text_array( self.tree, './/article-meta/*/kwd') # ElocationId self.dict['elocationId'] = utils.get_text( self.tree, './/journal-meta/elocationId') # Categories self.dict['categories'] = utils.get_text_array( self.tree, './/article-meta/article-categories/*/subj-group/subject') self.getAbstract() self.getJournal() self.getDate() self.getContributors() self.getAffiliations() self.getCountry() self.getKwd() return self
def openFile(self): handle = open(self.path, 'r') self.content = handle.read() self.tree = utils.read_xml(self.path, False) handle.close()