Welcome    Usage    Browse    Find CID    Search     Log in

cM API Documentation

module.py

Go to the documentation of this file.
00001 #
00002 # Collective Mind
00003 #
00004 # See cM LICENSE.txt for licensing details.
00005 # See cM Copyright.txt for copyright details.
00006 #
00007 # Developer(s): (C) Grigori Fursin, started on 2011.09
00008 #
00009 
00010 # Should always be here
00011 ini={}
00012 cm_kernel=None
00013 
00014 # Local settings
00015 import shutil
00016 import os
00017 import json
00018 
00019 # ============================================================================
00020 def init(i):
00021     return {'cm_return':0}
00022 
00023 # ============================================================================
00024 def generate(i):
00025 
00026     """
00027     Generating research topics and papers for "low-hanging fruits" ;) 
00028 
00029     Input:  {
00030               cm_data_uoa   - data with topic template
00031               (cm_repo_uoa) - repository
00032             }
00033 
00034     Output: {
00035               cm_return  - return code >0 if error
00036             }
00037     """
00038 
00039     cm_kernel.print_for_con('This is beta version of research topic generator!')
00040 
00041     cm_kernel.print_for_con('')
00042     cm_kernel.print_for_con('It allows to automatically generate research and grant topics, and possibly')
00043     cm_kernel.print_for_con('papers in our field. We hope it will be very appreciated by some of my')
00044     cm_kernel.print_for_con('academic colleagues since it can now help to automatically generate')
00045     cm_kernel.print_for_con('numerous research topics for grants, PhD/MS theses and "low hanging fruit"')
00046     cm_kernel.print_for_con('articles each year needed for academic promotion and awards while making')
00047     cm_kernel.print_for_con('all readers very happy with those numerous exciting articles.')
00048 
00049     cm_kernel.print_for_con('')
00050 
00051     du=i.get('cm_data_uoa','')
00052     if du=='': return {'cm_return':1,'cm_error':'cm_data_uoa is not defined'}
00053 
00054     dr=i.get('cm_repo_uoa','')
00055 
00056     ii={'cm_run_module_uoa':ini['cm_module_uid'],
00057         'cm_action':'load',
00058         'cm_data_uoa':du}
00059     if dr!='': ii['cm_repo_uoa']=dr
00060     r=cm_kernel.access(ii)
00061     if r['cm_return']>0: return r
00062 
00063     d=r['cm_data_obj']['cfg'].get('template_for_generator',[])
00064 
00065     # Generating topic
00066     s=''
00067 
00068     for q in d:
00069         t=q.get('text','')
00070         c=q.get('choice',[])
00071 
00072         if t!='':
00073            s+=t
00074         else:
00075            ii={'cm_run_module_uoa':ini['cfg']['cm_modules']['choice'],
00076                'cm_action':'explore',
00077                'cm_choices':{'cm_choice':'true',
00078                              'cm_list':c,
00079                              'cm_type':'one_of'},
00080                'cm_exploration_strategy':'random'}
00081            r=cm_kernel.access(ii)
00082            if r['cm_return']>0: return r
00083 
00084            s+=r['cm_choice'][0]
00085 
00086     cm_kernel.print_for_con('')
00087     cm_kernel.print_for_con('Generated topic:')
00088 
00089     cm_kernel.print_for_con('')
00090     cm_kernel.print_for_con(s)
00091 
00092     return {'cm_return':0}

Generated on Wed May 28 02:49:02 2014 for Collective Mind Framework by DoxyGen 1.6.1
Concept, design and coordination: Grigori Fursin (C) 1993-2013