Discussion Forum

Trouble using phone_calls example

I followed exact same step as shown in your documentation but I am not able to migrate data using python client. It is showing error as followed…

TypeError Traceback (most recent call last)
in
----> 1 build_phone_call_graph(inputs=inputs)

in build_phone_call_graph(inputs)
1 def build_phone_call_graph(inputs):
----> 2 with GraknClient(uri=“localhost:48555”) as client:
3 with client.session(keyspace = “phone_calls”) as session:
4 for input in inputs:
5 print(“Loading from [” + input[“data_path”] + “] into Grakn …”)

~\Anaconda3\lib\site-packages\grakn\client.py in init(self, uri, credentials)
17 self.credentials = credentials
18 self._channel = grpc.insecure_channel(uri)
—> 19 self._keyspace_service = KeyspaceService(self.uri, self._channel, credentials)
20
21 def session(self, keyspace):

TypeError: init() takes 3 positional arguments but 4 were given

Kindly suggest me some solution

Can you post your full migration script that you’re using please, along with Grakn version and client-python version :slight_smile:

from grakn.client import GraknClient

import csv

def build_phone_call_graph(inputs):
with GraknClient(uri=“localhost:48555”) as client:
with client.session(keyspace = “phone_calls”) as session:
for input in inputs:
print(“Loading from [” + input[“data_path”] + “] into Grakn …”)
load_data_into_grakn(input, session)

In[18]:

def load_data_into_grakn(input, session):
items = parse_data_to_dictionaries(input)

for item in items:
    with session.transaction().write() as transaction:
        graql_insert_query = input["template"](item)
        print("Executing Graql Query: " + graql_insert_query)
        transaction.query(graql_insert_query)
        transaction.commit()
        print("\nInserted " + str(len(items)) + " items from [ " + input["data_path"] + "] into Grakn.\n")

In[19]:

def company_template(company):
return ‘insert $company isa company, has name "’ + company[“name”] + ‘";’

In[20]:

def person_template(person):
# insert person
graql_insert_query = ‘insert $person isa person, has phone-number "’ + person[“phone_number”] + ‘"’
if person[“first_name”] == “”:
# person is not a customer
graql_insert_query += “, has is-customer false”
else:
# person is a customer
graql_insert_query += “, has is-customer true”
graql_insert_query += ‘, has first-name "’ + person[“first_name”] + ‘"’
graql_insert_query += ‘, has last-name "’ + person[“last_name”] + ‘"’
graql_insert_query += ‘, has city "’ + person[“city”] + ‘"’
graql_insert_query += ", has age " + str(person[“age”])
graql_insert_query += “;”
return graql_insert_query

In[21]:

def contract_template(contract):
# match company
graql_insert_query = ‘match $company isa company, has name "’ + contract[“company_name”] + ‘";’
# match person
graql_insert_query += ’ $customer isa person, has phone-number “’ + contract[“person_id”] + '”;’
# insert contract
graql_insert_query += " insert (provider: $company, customer: $customer) isa contract;"
return graql_insert_query

In[22]:

def call_template(call):
# match caller
graql_insert_query = ‘match $caller isa person, has phone-number "’ + call[“caller_id”] + ‘";’
# match callee
graql_insert_query += ’ $callee isa person, has phone-number “’ + call[“callee_id”] + '”;’
# insert call
graql_insert_query += (" insert $call(caller: $caller, callee: $callee) isa call; " +
"$call has started-at " + call[“started_at”] + "; " +
"$call has duration " + str(call[“duration”]) + “;”)
return graql_insert_query

In[23]:

def parse_data_to_dictionaries(input):
items = []
with open(input[“data_path”] + “.csv”) as data: # 1
for row in csv.DictReader(data, skipinitialspace = True):
item = { key: value for key, value in row.items() }
items.append(item) # 2
return items

In[24]:

inputs = [
{
“data_path”: “phone-calls/data/companies”,
“template”: company_template
},
{
“data_path”: “phone-calls/data/people”,
“template”: person_template
},
{
“data_path”: “phone-calls/data/contracts”,
“template”: contract_template
},
{
“data_path”: “phone-calls/data/calls”,
“template”: call_template
}
]

build_phone_call_graph(inputs)

grakn core version is 1.6.2

i dont how how to check python client??

i am using jupyter notebook