def generate_map(storage_path, storage_name, output_path): # Read patent data from storage result = p2n.storage.read(storage_path, storage_name) if not result: logger.error('Could not read storage "{}"'.format(storage_name)) sys.exit(1) # List value in countries, avoiding for bre in result['brevets']: if isinstance(bre['country'], list) and len(bre['country']) == 1: # Well, taking the first one, this is an approximation bre['country'] = bre['country'][0] # Status message logger.info("Mapping {count} patents. Excepting EP and WO.".format( count=len(result['brevets']))) # Compute map data mapdata = p2n.formatter.maps.d3plus_data_brevets(result['brevets'], 'country') # Render map jsonfile = '{storage_name}CountryMap.json'.format(**locals()) htmlfile = '{storage_name}Carto.html'.format(**locals()) with open(os.path.join(output_path, jsonfile), "w") as mapdatafile: json.dump(mapdata, mapdatafile) RenderTemplate( "ModeleCarto.html", os.path.join(output_path, htmlfile), request=result["requete"], jsonFile=jsonfile, )
def generate_map(storage_path, storage_name, output_path): # Read patent data from storage result = p2n.storage.read(storage_path, storage_name) if not result: logger.error( 'Could not read "{storage_name}" from storage path "{storage_path}".' .format(**locals())) sys.exit(1) # Status message logger.info("Mapping {count} patents. Excepting EP and WO.".format( count=len(result['brevets']))) # Compute map data mapdata_all = { 'Applicant-Country': p2n.formatter.maps.d3plus_data_brevets(result['brevets'], 'Applicant-Country'), 'Inventor-Country': p2n.formatter.maps.d3plus_data_brevets(result['brevets'], 'Inventor-Country'), } # Create output path if not os.path.isdir(output_path): os.makedirs(output_path) # Render maps for field, mapdata in list(mapdata_all.items()): field_name = field.split('-')[0] jsonfile = '{storage_name}Map{field_name}.json'.format(**locals()) htmlfile = '{storage_name}Carto{field_name}.html'.format(**locals()) with open(os.path.join(output_path, jsonfile), "w") as mapdatafile: json.dump(mapdata, mapdatafile) RenderTemplate( "ModeleCartoDeposant.html", os.path.join(output_path, htmlfile), field=field_name, request=result["requete"], jsonFile=jsonfile, )
Double = dict( ) #dictionnary to manage multiple bib entries (same authors and date) with open(ResultPathContent + '//' + ndf + '.json', 'w') as resFic: resFic.write(contenu) #outfile = ndf + '.xlsx' outfile = ResultPathContent + '//' + ndf + '.html' RenderTemplate( "Modele.html", outfile, GlobalPath=GlobalPath, fichier=ndf + '.json', fichierPivot=ndf + 'Pivot.html', fichieXls=ndf + ".xlsx", requete=requete.replace('"', ''), CollectName=ndf, Request=requete, #TotalPatents=totalPatents, # TotalFamily=nbFam, # HasFamily=GatherFamilly, # TotalsPerType=totalsPerType, # TotalsPerFamilyType=totalsPerFamilyType ) with open("scriptSearch.js", 'r') as Source: js = Source.read() js = js.replace('***fichierJson***', ndf + '.json') js = js.replace('{ "data": "application-ref"},', '') with open(ResultPathContent + '//' + 'scriptSearch.js', 'w') as resFic: resFic.write(js)
"utf8") as resFic: # encode and append line by line to avoid memory error try: resFic.write(contenu2) for contenu2 in json.JSONEncoder(indent=3).iterencode(LstExp2): #with codecs.open(ResultPathContent + '//' + ndf+'Pivot.json', 'a', "utf8") as resFic: resFic.write(contenu2) except: resFic.write(contenu2) contenu2 = json.dumps(LstExp2, indent=3, ensure_ascii=False, encoding='utf8') #, #with codecs.open(ResultPathContent + '//' + ndf+'Pivot.json', 'w', "utf8") as resFic: resFic.write(contenu2) FichierHtml = ndf + '.html' if ndf.startswith('Families'): ModelePivot = "ModeleFamillePivot.html" else: ModelePivot = "Pivot.html" RenderTemplate(ModelePivot, ResultPathContent + '//' + ndf + 'Pivot.html', fichier=ndf + 'Pivot.json', requete=DataBrevet['requete'].replace('"', ''), FichierHtml=FichierHtml, FichierHtmlFamille='Families' + FichierHtml) #os.system('start firefox -url '+ URLs.replace('//','/') )
Dones = [] Double = dict( ) #dictionnary to manage multiple bib entries (same authors and date) with open(ResultPathContent + '//' + ndf + '.json', 'w') as resFic: resFic.write(contenu) #outfile = ndf + '.xlsx' outfile = ResultPathContent + '//' + ndf + '.html' RenderTemplate( "ModeleDataTable.html", outfile, GlobalPath=GlobalPath, fichier=ndf + '.json', requete=configFile.requete, CollectName=ndf, Request=configFile.requete, #TotalPatents=totalPatents, # TotalFamily=nbFam, # HasFamily=GatherFamilly, # TotalsPerType=totalsPerType, # TotalsPerFamilyType=totalsPerFamilyType ) with open("templates/scriptSearch2.js", 'r') as Source: js = Source.read() js = js.replace('***fichierJson***', ndf + '.json') js = js.replace('{ "data": "application-ref"},', '') with open(ResultPathContent + '//' + 'scriptSearch.js', 'w') as resFic: resFic.write(js) #os.system('start firefox -url '+ URLs.replace('//','/') )
str( etree.tostring(rac, pretty_print=True, encoding='unicode', method='xml'))) ficRes.write(don[len(don) - 3]) ficRes.write(don[len(don) - 2].strip()) ficRes.write(don[len(don) - 1]) #making the html from model RenderTemplate( "Graphe.html", ResultGephiPath + '/' + outputFile.replace('.gexf', 'JS.html'), TitleNet=network[1:] + ' Network for ' + requete, fichierConfigJS=outputFile.replace('.gexf', '') + 'Conf.js', mediaStyle='../../../Patent2Net/media/styles', mediaJs='../../../Patent2Net/media/js', ) # making the js from model # maybe we could adjust node size and other parameters here RenderTemplate( "gephiConfig.js", ResultGephiPath + '/' + outputFile.replace('.gexf', '') + 'Conf.js', FicRezo=outputFile, ) if outputFileJS in os.listdir(ResultGephiPath + '/'): os.remove(ResultGephiPath + '/' + outputFileJS)
def run(): # Bootstrap logging boot_logging() # Load configuration config = LoadConfig() # Run this only if enabled if not config.GatherImages: return # Get some information from configuration expression = config.requete storage_basedir = config.ResultBiblioPath storage_dirname = config.ndf output_path = config.ResultPathImages # Compute prefixes prefixes = [""] if config.GatherFamilly: prefixes.append("Families") # Build maps for all prefixes for prefix in prefixes: # Status message label = label_from_prefix(prefix) logger.info("Generating gallery of drawings for {}. ".format(label)) # Compute storage slot using prefix and DataDirectory # e.g. "Lentille" vs. "FamiliesLentille" storage_name = prefix + storage_dirname # Load bibliographic data biblio_file = LoadBiblioFile(storage_basedir, storage_name) # Generate thumbnails gallery = [] patents = biblio_file['brevets'] cpt = 0 for patent in patents: cpt + 1 AnnonceProgres(Appli='p2n_image', valMax=100, valActu=90 + cpt * 10 / len(patents)) patent_label = get_patent_label(patent) i = 1 logger.info('Processing patent {}'.format(patent_label)) path_img_base = '{}//{}-{}.tiff'.format(output_path, patent_label, '{}') path = path_img_base.format(i) while os.path.exists(path): thumb, orig, tiff = generate_thumbnails(path) gallery.append({ "_id": '{}-{}'.format(patent_label, i), 'thumb': thumb, 'orig': orig, 'label': patent['title'], 'ipcr7': patent['IPCR7'], 'code': patent_label, 'tiff': tiff, }) i += 1 path = path_img_base.format(i) # Render gallery AnnonceProgres(Appli='p2n_image', valMax=100, valActu=100) RenderTemplate( 'ModeleImages.html', output_path + '/index' + prefix + '.html', request=expression.replace('"', ''), gallery=gallery, json=json.dumps(gallery), )
dicoRes['data'] = LstExp contenu = json.dumps(dicoRes, indent=3) #ensure_ascii=True, import pandas as pd df = pd.DataFrame(dicoRes["data"]) df.to_excel(ResultPathContent + '//' + ndf + '.xlsx', sheet_name=ndf) compt = 0 Dones = [] Double = dict( ) #dictionnary to manage multiple bib entries (same authors and date) with open(ResultPathContent + '//' + ndf + '.json', 'w') as resFic: resFic.write(contenu) RenderTemplate("ModeleFamille.html", ResultPathContent + '//' + ndf + '.html', CollectName=ndf, GlobalPath=GlobalPath, fichier=ndf + '.json', fichierPivot=ndf + 'Pivot.html', requete=requete.replace('"', '')) with open("searchScript.js", 'r') as Source: js = Source.read() js = js.replace('***fichierJson***', ndf + '.json') js = js.replace('{ "data": "application-ref"},', '') with open(ResultPathContent + '//' + 'searchScript.js', 'w') as resFic: resFic.write(js) #os.system('start firefox -url '+ URLs.replace('//','/') )
RenderTemplate( "ModeleContenuIndex.html", outfile, GlobalPath=GlobalPath, CollectName=ndf, Request=requete, TotalPatents=totalPatents, TotalFamily=nbFam, HasFamily=GatherFamilly, Date=date, TotalsPerType=totalsPerType, TotalsPerFamilyType=totalsPerFamilyType, InventorNetwork=configFile.InventorNetwork, ApplicantNetwork=configFile.ApplicantNetwork, ApplicantInventorNetwork=configFile.ApplicantInventorNetwork, InventorCrossTechNetwork=configFile.InventorCrossTechNetwork, ApplicantCrossTechNetwork=configFile.ApplicantCrossTechNetwork, CountryCrossTechNetwork=configFile.CountryCrossTechNetwork, CrossTechNetwork=configFile.CrossTechNetwork, CompleteNetwork=configFile.CompleteNetwork, References=configFile.References, Citations=configFile.Citations, Equivalents=configFile.Equivalents, FormateExportCountryCartography=configFile.FormateExportCountryCartography, FormateExportBiblio=configFile.FormateExportBiblio, FormateExportDataTable=configFile.FormateExportDataTable, FormateExportPivotTable=configFile.FormateExportPivotTable, FreePlane=configFile.FreePlane, FusionCarrot2=configFile.FusionCarrot2, Images=configFile.GatherImages, Cluster=configFile.Cluster, )