diff options
| author | LV-426 <lv-426@taproot.org.il> | 2015-05-17 17:57:00 +0300 |
|---|---|---|
| committer | LV-426 <lv-426@taproot.org.il> | 2015-05-17 18:07:51 +0300 |
| commit | 7e13f1fc247e8157abedbdf3f20e95012dee7a05 (patch) | |
| tree | 163d0157c06aa673ade9c7601d2498356f3532d8 /src | |
| parent | be61af9c3f8bca1428dad7eaba1ad6c8da58e666 (diff) | |
refactoring DBO_RDG__skill_graph out of Test_Domain_CRI
Diffstat (limited to 'src')
| -rw-r--r-- | src/local/domain/cri.rhizi.net/domain_cri.py | 140 | ||||
| -rw-r--r-- | src/local/domain/cri.rhizi.net/test_domain__CRI.py | 114 | ||||
| -rw-r--r-- | src/server-tests/test_util__rzdoc.py | 65 |
3 files changed, 171 insertions, 148 deletions
diff --git a/src/local/domain/cri.rhizi.net/domain_cri.py b/src/local/domain/cri.rhizi.net/domain_cri.py deleted file mode 100644 index db6ed925..00000000 --- a/src/local/domain/cri.rhizi.net/domain_cri.py +++ /dev/null @@ -1,140 +0,0 @@ -from db_op import DB_op - -class DBO_random_data_generation__domain__CRI(DB_op): - - def __init__(self, lim_n=50, - lim_r=10000, - prob_link_create=0.03): - """ - generate random data: CRI domain: Person x Skill - """ - super(DBO_random_data_generation__domain__CRI, self).__init__() - - n_attr_set__skill_raw = ['Cryptocurrency', - 'Database architecture', - 'Web-development', - 'Mobile-development', - 'Machine learning', - 'Guitar Playing', - 'Image processing', - 'Algebra', - 'Calculus', - 'Molecular-Biology', - 'Graphic design', - 'Geo-location services', - 'Drone-building', - 'Artificial-intelligence', - 'Distributed information systems', - 'Wordpress', - 'Woodworking', - 'Quality-control', - 'Video-editing', - 'Soldering', - 'Network engineering', - 'GIT', - 'Electronic music', - 'Network administration'] - - n_attr_set__skill = [] - for s in n_attr_set__skill_raw: - n_attr_set__skill.append(s) - - n_attr_set__name = ['John', - 'William', - 'James', - 'Charles', - 'George', - 'Frank', - 'Joseph', - 'Thomas', - 'Henry', - 'Robert', - 'Edward', - 'Harry', - 'Walter', - 'Arthur', - 'Fred', - 'Albert', - 'Samuel', - 'David', - 'Louis', - 'Joe', - 'Charlie', - 'Clarence', - 'Richard', - 'Andrew', - 'Daniel', - 'Ernest', - 'Mary', - 'Anna', - 'Emma', - 'Elizabeth', - 'Minnie', - 'Margaret', - 'Ida', - 'Alice', - 'Bertha', - 'Sarah', - 'Annie', - 'Clara', - 'Ella', - 'Florence', - 'Cora', - 'Martha', - 'Laura', - 'Nellie', - 'Grace', - 'Carrie', - 'Maude', - 'Mabel', - 'Bessie', - 'Jennie', - 'Gertrude', - 'Julia'] - - l_attr_set__level = ['Novice', 'Intermediate', 'Expert'] - - - min_id = 10000 # separate group ids with numerical perfix - - # create persons - q_arr = ['with {n_attr_set__name} as n_attr_set', # TODO clean: foreach triggers SyntaxException: otherwise - 'foreach (idx in range(0,%d)' % (lim_n - 1), - '|', - 'create (n:%s' % ('Person'), - '{id: \'test-id_\' + toString(%d + idx),' % (min_id), - 'name: n_attr_set[idx %% %d]}' % (len(n_attr_set__name)), - '))', - ] - q_param = {'n_attr_set__name': n_attr_set__name} - self.add_statement(q_arr, q_param) - min_id *= 2 - - # create skills - q_arr = ['with {skill_set} as skill_set', # TODO clean: foreach triggers SyntaxException: otherwise - 'foreach (idx in range(0,%d)' % (len(n_attr_set__skill) - 1), - '|', - 'create (n:%s' % ('Skill'), - '{id: \'test-id_\' + toString(idx + %d),' % (min_id), - 'name: skill_set[idx]}', - '))', - ] - q_param = {'skill_set': n_attr_set__skill} - self.add_statement(q_arr, q_param) - min_id *= 2 - - # create links - for skill_level in l_attr_set__level: - q_arr = ['match (n:%s),(m:%s)' % ('Person', 'Skill'), - 'with n, m, rand() as rand', - 'order by rand', - 'limit %d' % (lim_r - 1), - 'where rand() < %.2f' % (prob_link_create), - 'create (n)-[r:%s' % (skill_level), - '{id: \'test-id_\' + toString(%d + toInt(%d * rand())),' % (min_id, lim_r * 100000), # aim for low id collision probability, - 'proficiency: \'%s\'}' % (skill_level), - ']->(m)', - 'return collect(r.id)', - ] - - self.add_statement(q_arr, q_param) diff --git a/src/local/domain/cri.rhizi.net/test_domain__CRI.py b/src/local/domain/cri.rhizi.net/test_domain__CRI.py index 54131bbd..652c04a6 100644 --- a/src/local/domain/cri.rhizi.net/test_domain__CRI.py +++ b/src/local/domain/cri.rhizi.net/test_domain__CRI.py @@ -4,17 +4,20 @@ import tempfile import unittest import db_controller as dbc -from db_op import DBO_cypher_query -from domain_cri import DBO_random_data_generation__domain__CRI -from rz_server import Config +from db_op import DBO_cypher_query, DBO_rzdoc__create +from neo4j_test_util import rand_label +from rz_config import RZ_Config +from test_util import generate_random_RZDoc +from test_util__pydev import debug__pydev_pd_arg +from test_util__rzdoc import DBO_RDG__skill_graph class Test_Domain_CRI(unittest.TestCase): @classmethod def setUpClass(self): - cfg = Config.init_from_file('res/etc/rhizi-server.conf') - self.db_ctl = dbc.DB_Controller(cfg) + cfg = RZ_Config.init_from_file('res/etc/rhizi-server.conf') + self.db_ctl = dbc.DB_Controller(cfg.neo4j_url) self.log = logging.getLogger('rhizi') self.log.addHandler(logging.StreamHandler()) @@ -24,7 +27,95 @@ class Test_Domain_CRI(unittest.TestCase): - random CRI domain data generation - DB dump in cvs format: person x skill x skill-level """ - op = DBO_random_data_generation__domain__CRI() + + skill_set = ['Cryptocurrency', + 'Database architecture', + 'Web-development', + 'Mobile-development', + 'Machine learning', + 'Guitar Playing', + 'Image processing', + 'Algebra', + 'Calculus', + 'Molecular-Biology', + 'Graphic design', + 'Geo-location services', + 'Drone-building', + 'Artificial-intelligence', + 'Distributed information systems', + 'Wordpress', + 'Woodworking', + 'Quality-control', + 'Video-editing', + 'Soldering', + 'Network engineering', + 'GIT', + 'Electronic music', + 'Network administration'] + + name_set = ['John', + 'William', + 'James', + 'Charles', + 'George', + 'Frank', + 'Joseph', + 'Thomas', + 'Henry', + 'Robert', + 'Edward', + 'Harry', + 'Walter', + 'Arthur', + 'Fred', + 'Albert', + 'Samuel', + 'David', + 'Louis', + 'Joe', + 'Charlie', + 'Clarence', + 'Richard', + 'Andrew', + 'Daniel', + 'Ernest', + 'Mary', + 'Anna', + 'Emma', + 'Elizabeth', + 'Minnie', + 'Margaret', + 'Ida', + 'Alice', + 'Bertha', + 'Sarah', + 'Annie', + 'Clara', + 'Ella', + 'Florence', + 'Cora', + 'Martha', + 'Laura', + 'Nellie', + 'Grace', + 'Carrie', + 'Maude', + 'Mabel', + 'Bessie', + 'Jennie', + 'Gertrude', + 'Julia'] + + test_label = rand_label() + rzdoc = generate_random_RZDoc(test_label) + + op = DBO_rzdoc__create(rzdoc) + self.db_ctl.exec_op(op) + + op = DBO_RDG__skill_graph(rzdoc, + lim_n=10, + skill_set=skill_set, + name_set=name_set) self.db_ctl.exec_op(op) if False == export_as_csv: @@ -37,10 +128,13 @@ class Test_Domain_CRI(unittest.TestCase): ] op = DBO_cypher_query(q_arr) + # + # write csv file + # cur_f_name = inspect.stack()[0][3] def q_process_result_set(): with tempfile.NamedTemporaryFile(prefix='rz_%s' % (cur_f_name), dir='/tmp', suffix='.csv', delete=False) as f_out: - for _, _, r_set in op: + for _, _, r_set in op.iter__r_set(): for row in r_set: person_name, skill_dict_set = row # person to {sname: skill, s:pro: skill_level{ dict set cvs_line_arr = [person_name] @@ -54,5 +148,9 @@ class Test_Domain_CRI(unittest.TestCase): op.process_result_set = q_process_result_set self.db_ctl.exec_op(op) -if __name__ == "__main__": +@debug__pydev_pd_arg +def main(): unittest.main() + +if __name__ == "__main__": + main() diff --git a/src/server-tests/test_util__rzdoc.py b/src/server-tests/test_util__rzdoc.py new file mode 100644 index 00000000..ffcc2423 --- /dev/null +++ b/src/server-tests/test_util__rzdoc.py @@ -0,0 +1,65 @@ +from db_op import DBO_cypher_query +import neo4j_util + + +class DBO_RDG__skill_graph(DBO_cypher_query): + + def __init__(self, rzdoc, + lim_n=50, + lim_r=10000, + prob_link_create=0.03, + name_set=['Bruce Lee', 'Kesuke Miyagi'], + skill_set=['Kung Foo', 'Karate'], + skill_level_set=['Novice', 'Intermediate', 'Expert'] + ): + """ + Random data generator: + - Name x Skill[proficiency: {Novice|Intermediate|Expert}] + """ + super(DBO_RDG__skill_graph, self).__init__() + + rzdoc_label = neo4j_util.rzdoc__ns_label(rzdoc) + min_id = 10000 # separate group ids with numerical perfix + + # create persons + q_arr = ['with {name_set} as n_attr_set', # TODO clean: foreach triggers SyntaxException: otherwise + 'foreach (idx in range(0,%d)' % (lim_n - 1), + '|', + 'create (n:%s:%s' % (rzdoc_label, 'Person'), + '{id: \'test-id_\' + toString(%d + idx),' % (min_id), + 'name: n_attr_set[idx %% %d]}' % (len(name_set)), + '))', + ] + q_param = {'name_set': name_set} + self.add_statement(q_arr, q_param) + min_id *= 2 + + # create skills + q_arr = ['with {skill_set} as skill_set', # TODO clean: foreach triggers SyntaxException: otherwise + 'foreach (idx in range(0,%d)' % (len(skill_set) - 1), + '|', + 'create (n:%s:%s' % (rzdoc_label, 'Skill'), + '{id: \'test-id_\' + toString(idx + %d),' % (min_id), + 'name: skill_set[idx]}', + '))', + ] + q_param = {'skill_set': skill_set} + self.add_statement(q_arr, q_param) + min_id *= 2 + + # create links + for skill_level in skill_level_set: + q_arr = ['match (n:%s),(m:%s)' % ('Person', 'Skill'), + 'with n, m, rand() as rand', + 'order by rand', + 'limit %d' % (lim_r - 1), + 'where rand() < %.2f' % (prob_link_create), + 'create (n)-[r:%s' % (skill_level), + '{id: \'test-id_\' + toString(%d + toInt(%d * rand())),' % (min_id, lim_r * 100000), # aim for low id collision probability, + 'proficiency: \'%s\'}' % (skill_level), + ']->(m)', + 'return collect(r.id)', + ] + + self.add_statement(q_arr, q_param) + |
