File size: 3,619 Bytes
723e191
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
def add_job_nodes(response, job_name):
    job = response.job

    # Create job nodes
    cypher = f'''
    CREATE (job:Job {{name: "{job_name}"}})
    '''

    # Job description
    if job.description:
        cypher += f'SET job.description = "{job.description}"'

    # Work mode
    if job.work_mode:
        cypher += f'''
        SET job.work_mode = "{job.work_mode}"
        '''

    # Benefits & Compensations
    if job.benefit_compensation:
        cypher += f'''
        SET job.benefit_compensation = "{job.benefit_compensation}"
        '''

    # Locations
    if job.work_at:
        cypher += f'''
    MERGE (loc: Location {{name: "{job.work_at.name}", location_type: "{job.work_at.location_type}"}})
    MERGE (job)-[:WORK_AT]->(loc)
    '''

    # Work Levels
    if job.work_level:
        cypher += f'''
    MERGE (level: Work_LV {{name: "{job.work_level.name}"}})
    MERGE (job)-[:AT_LEVEL]->(level)
    '''

    # Required educations
    if job.education_requirements:
        for i, edu in enumerate(job.education_requirements):
            cypher += f'''
        CREATE (edu_{i}:Education {{name: "{edu.name}"}})
        MERGE (job)-[:REQUIRES]->(edu_{i})
            '''

            if edu.fields:
                cypher += f'SET edu_{i}.fields = "{edu.fields}"'

            if edu.status:
                cypher += f'SET edu_{i}.status = "{edu.status}"'

    # Required skills
    if job.skill_requirements:
        for i, skill in enumerate(job.skill_requirements):
            cypher += f'''
        MERGE (skill_{i}:Skill {{name: "{skill.name}"}})
        MERGE (job)-[:REQUIRES]->(skill_{i})
            '''

            if skill.hypernym:
                cypher += f'''
        MERGE (hypernym_{i}:Skill {{name: "{skill.hypernym}"}})
        MERGE (skill_{i})-[:HYPERNYM]->(hypernym_{i})  
        '''

    # Required work experiences
    if job.work_exper_requirements:
        for i, exper in enumerate(job.work_exper_requirements):
            cypher += f'''
        MERGE (exper_{i}:Work_Exper {{name: "{exper.name}"}})
        MERGE (job)-[:REQUIRES]->(exper_{i})
        '''

            if exper.duration:
                cypher += f'SET exper_{i}.duration = "{exper.duration}"'

    return cypher

def add_company_nodes(response, company_name):
    company = response.job.from_company

    cypher = f'''
    MERGE (company:Company {{name: "{company_name}"}})
    MERGE (job)-[:FROM]->(company)
    MERGE (company)-[:RECRUITES]->(job)
        '''

    if company:
        if company.subdiaries:
            for i, sub in enumerate(company.subdiaries):
                cypher += f'''
            MERGE (sub_{i}:Company {{name: "{sub}"}})
            MERGE (company)-[:SUBDIARY]->(sub_{i})
                '''

        if company.locations:
            for i, loc in enumerate(company.locations):
                cypher += f'''
            MERGE (loc_{i}:Location {{name: "{loc.name}"}})
            MERGE (company)-[:LOCATES_IN]->(loc_{i})
                '''

                if loc.location_type:
                    cypher += f'SET loc_{i}.location_type = "{loc.location_type}"'

        if company.industry:
            for i, industry in enumerate(company.industry):
                cypher += f'''
            MERGE (industry_{i}:Industry {{name: "{industry}"}})
            MERGE (company)-[:OPERATES_IN]->(industry_{i})
                '''

    return cypher


def make_cypher_query(response, job_title, company_name):
    job_cypher = add_job_nodes(response, job_title)
    company_cypher = add_company_nodes(response, company_name)
    return job_cypher + company_cypher