Exemple #1
0
    def gen_full_db_op_set(self, test_label):
        n_0, n_0_id = generate_random_node_dict(test_label)
        n_1, n_1_id = generate_random_node_dict(test_label)
        l_0, l_0_id = generate_random_link_dict(test_label, n_0_id, n_1_id)

        n_set = [n_0, n_1]
        l_set = [l_0]
        topo_diff = Topo_Diff(node_set_add=n_set, link_set_add=l_set)

        attr_diff = Attr_Diff()
        attr_diff.add_node_attr_write(n_0_id, 'attr_0', 0)

        test_rzdoc = generate_random_RZDoc(test_label)

        op_set = [
                  DBO_rzdoc__clone(),
                  DBO_add_node_set(meta_attr_list_to_meta_attr_map(n_set)),
                  DBO_add_link_set(meta_attr_list_to_meta_attr_map(l_set, meta_attr='__type')),
                  DBO_diff_commit__attr(attr_diff),
                  DBO_diff_commit__topo(topo_diff),
                  DBO_rm_node_set(id_set=[n_0_id]),

                  # block chain
                  DBO_block_chain__init(test_rzdoc),
                  DBO_block_chain__commit(commit_obj=topo_diff.to_json_dict()),

                  # rzdoc
                  DBO_rzdoc__create(test_rzdoc),
                  DBO_rzdoc__delete(test_rzdoc),
                  DBO_rzdoc__list(),
                  DBO_rzdoc__lookup_by_name(test_rzdoc.name),
                  ]
        return op_set
Exemple #2
0
    def gen_full_db_op_set(self, test_label):
        n_0, n_0_id = generate_random_node_dict(test_label)
        n_1, n_1_id = generate_random_node_dict(test_label)
        l_0, l_0_id = generate_random_link_dict(test_label, n_0_id, n_1_id)

        n_set = [n_0, n_1]
        l_set = [l_0]
        topo_diff = Topo_Diff(node_set_add=n_set, link_set_add=l_set)

        attr_diff = Attr_Diff()
        attr_diff.add_node_attr_write(n_0_id, 'attr_0', 0)

        test_rzdoc = generate_random_RZDoc(test_label)

        op_set = [
            DBO_rzdoc__clone(),
            DBO_add_node_set(meta_attr_list_to_meta_attr_map(n_set)),
            DBO_add_link_set(
                meta_attr_list_to_meta_attr_map(l_set, meta_attr='__type')),
            DBO_diff_commit__attr(attr_diff),
            DBO_diff_commit__topo(topo_diff),
            DBO_rm_node_set(id_set=[n_0_id]),

            # block chain
            DBO_block_chain__init(test_rzdoc),
            DBO_block_chain__commit(commit_obj=topo_diff.to_json_dict()),

            # rzdoc
            DBO_rzdoc__create(test_rzdoc),
            DBO_rzdoc__delete(test_rzdoc),
            DBO_rzdoc__list(),
            DBO_rzdoc__lookup_by_name(test_rzdoc.name),
        ]
        return op_set
Exemple #3
0
    def test_rzdoc_search(self):
        rzdoc_common_name = test_util.gen_random_name()
        rzdoc_post_a = test_util.generate_random_RZDoc(rzdoc_common_name + "_a")
        rzdoc_post_b = test_util.generate_random_RZDoc(rzdoc_common_name + "_b")
        rzdoc_pre_c = test_util.generate_random_RZDoc("c_" + rzdoc_common_name)
        rzdoc_plain = test_util.generate_random_RZDoc(rzdoc_common_name)

        for rzdoc in [rzdoc_post_a, rzdoc_post_b, rzdoc_pre_c, rzdoc_plain]:
            self.kernel.rzdoc__create(rzdoc_name=rzdoc.name)

        ret = self.kernel.rzdoc__search(rzdoc_common_name)
        self.assertEquals(4, len(ret))

        ret = self.kernel.rzdoc__search(rzdoc_common_name + "_")
        self.assertEquals(2, len(ret))

        ret = self.kernel.rzdoc__search("c_" + rzdoc_common_name)
        self.assertEquals(1, len(ret))
Exemple #4
0
    def test_rzdoc_search(self):
        rzdoc_common_name = test_util.gen_random_name()
        rzdoc_post_a = test_util.generate_random_RZDoc(rzdoc_common_name + '_a')
        rzdoc_post_b = test_util.generate_random_RZDoc(rzdoc_common_name + '_b')
        rzdoc_pre_c = test_util.generate_random_RZDoc('c_' + rzdoc_common_name)
        rzdoc_plain = test_util.generate_random_RZDoc(rzdoc_common_name)

        for rzdoc in [rzdoc_post_a, rzdoc_post_b, rzdoc_pre_c, rzdoc_plain]:
            self.kernel.rzdoc__create(rzdoc_name=rzdoc.name)

        ret = self.kernel.rzdoc__search(rzdoc_common_name)
        self.assertEquals(4, len(ret))

        ret = self.kernel.rzdoc__search(rzdoc_common_name + '_')
        self.assertEquals(2, len(ret))

        ret = self.kernel.rzdoc__search('c_' + rzdoc_common_name)
        self.assertEquals(1, len(ret))
Exemple #5
0
    def test_T__add_node_filter__rzdoc_id_label(self):
        test_label = neo4j_test_util.rand_label()
        test_rzdoc = generate_random_RZDoc(test_label)

        dbq_set = []
        op_set = self.gen_full_db_op_set(test_label)

        for op in op_set:
            if isinstance(op, DB_composed_op): continue  # sub-queries tested instead
            for dbq in op:
                dbq_set.append(dbq)

        q_arr = ['match (n)-[l_old {id: {id}}]->(m)',
                 'where type(l_old)<>\'is not\'',
                 'delete l_old, params: {\'id\': u\'9fbhxwcn\'}']
        dbq = DB_Query(q_arr)
        dbq_set = [dbq]

        # dbq_set = dbq_set[:1]
        self.test_T__common(dbq_set, QT_RZDOC_NS_Filter, test_rzdoc)
Exemple #6
0
    def test_T__add_node_filter__rzdoc_id_label(self):
        test_label = neo4j_test_util.rand_label()
        test_rzdoc = generate_random_RZDoc(test_label)

        dbq_set = []
        op_set = self.gen_full_db_op_set(test_label)

        for op in op_set:
            if isinstance(op, DB_composed_op): continue  # sub-queries tested instead
            for dbq in op:
                dbq_set.append(dbq)

        q_arr = ['match (n)-[l_old {id: {id}}]->(m)',
                 'where type(l_old)<>\'is not\'',
                 'delete l_old, params: {\'id\': u\'9fbhxwcn\'}']
        dbq = DB_Query(q_arr)
        dbq_set = [dbq]

        # dbq_set = dbq_set[:1]
        self.test_T__common(dbq_set, QT_RZDOC_NS_Filter, test_rzdoc)
Exemple #7
0
    def test_random_data_generation__domain__CRI(self, export_as_csv=True):
        """
        test:
           - random CRI domain data generation
           - DB dump in cvs format: person x skill x skill-level
        """

        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:
            return

        q_arr = ['match (n: Person)',
                 'with n',
                 'match (n)-[r:Novice|Intermediate|Expert]->(m:Skill)',  # [!] expect link type to be proficiency level
                 'return n.name, collect({skill_name: m.name, skill_level: r.proficiency})'
                 ]
        op = DBO_raw_query_set(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.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]
                        for skill_dict in skill_dict_set:
                            skill_name = skill_dict['skill_name']
                            skill_level = skill_dict['skill_level']
                            cvs_line_arr += [skill_name, skill_level]
                        f_out.write(','.join(cvs_line_arr) + '\n')
                f_out.write('\n')

        op.process_result_set = q_process_result_set
        self.db_ctl.exec_op(op)