def create_graph(request): print request.form name = request.form['skill_name'] utterances = { key: request.form[key] for key in request.form.keys() if (key.startswith("utterance")) } utterances = build_set_utterances(utterances) steps = [ request.form[key] for key in request.form.keys() if (key.startswith("step")) ] tasks = {} for s in steps: tasks[s] = {} for key1 in request.form.keys(): print "key1:{}".format(key1) for key2 in steps: print "key2:{}".format(key2) if key1.startswith(key2): index = key1[-1:] print "Index : {}".format(index) tasks[key2].update({index: request.form[key1]}) print "Name : {}".format(name) print "Utterances : {}".format(utterances) print "Steps : {}".format(steps) skill = model.Skill(name, utterances, steps, tasks, kb) return skill.to_rdf()
def get_skills(self) -> Iterable[model.Skill]: return [ # Construct a new Skill model.Skill(sid, sname) # For each row returned for sid, sname in self.db.execute( SqliteRepository.__SELECT_ALL_SKILLS).fetchall() ]
def find_skills_by_name(self, skill_name: str) -> Iterable[model.Skill]: wildcard_name = f'%{skill_name}%' return [ # Construct a new Skill model.Skill(sid, sname) # For each row returned for sid, sname in self.db.execute( 'SELECT skill_id, skill_name FROM skills WHERE skill_name LIKE ?', [wildcard_name]).fetchall() ]
def find_skills_by_id(self, skills_ids: Iterable[int]) -> Iterable[model.Skill]: ids = ','.join([str(id) for id in skills_ids]) query = f"SELECT skill_id, skill_name FROM skills WHERE skill_id IN ({ids});" return [ # Construct a new Skill model.Skill(sid, sname) # For each row returned for sid, sname in self.db.execute(query).fetchall() ]
print(f"People skills: {len(g.people_skills)}") for person, skill in g.people_skills: print(f"{person.name} <-> {skill.name}") ############################# # Model tests ############################# import model p1 = model.Person(1, "Alice") p2 = model.Person(2, "Bob") p3 = model.Person(3, "Charles") s1 = model.Skill(11, "Dancing") s2 = model.Skill(22, "Fishing") g = model.Graph() g.add_person(p1) g.add_person(p2) g.add_person(p3) g.add_skill(s1) g.add_skill(s2) g.link_person_to_skill(1, 11) g.link_person_to_skill(1, 22) g.link_person_to_skill(2, 11) g.link_person_to_skill(3, 22)