class GraphNode: def __init__(self, node=None): if node is None: self.node = Node() else: self.node = node def id(self): """ :return: node's unique Id """ return self.node._id def labels(self): """ :return: labels set """ return self.node.labels def degree(self): """ :return: number of relations """ return self.node.degree def property(self, key): """ :param key: property name :return: property value """ return self.node.properties[key] def properties(self): """ :return: node's properties dict """ return self.node.properties def relationships(self): """ :return: node's relationships iterator """ for rel in self.node.match(): i_rel = GraphRelation(rel) yield i_rel def outgoing_relationships(self): """ :return: node's outgoing relationships iterator """ for rel in self.node.match_outgoing(): i_rel = GraphRelation(rel) yield i_rel
def loadAuthorFilter(): """ @return A list of author names """ profList = list() seqAuthor = 1 filterFiles = ['docentes-unb.json', 'docentes-ufmg.json', 'docentes-ufrn.json', 'docentes-usp.json', 'docentes-ufam.json'] lastAuthorid = graph.run('''MATCH (a:Author) WHERE a.authorid is not null RETURN a.authorid as authorid ORDER BY authorid DESC limit 1''' ) if lastAuthorid.current() is not None: seqAuthor = lastAuthorid.current() + 1 for j in filterFiles: print("Loading filter %s" % j) instName = j.split('.')[0].split('-')[1] institution = graph.find_one("Institution", property_key='name', property_value=instName) if institution is None: institution = Node("Institution", name=instName) for p in json.load(open(j, 'r', encoding='latin-1')): if p is not None: author = Node("Author", name=p['name'], lattesurl=p['lattesurl']) author['authorid'] = seqAuthor graph.create(author) graph.create(Relationship(author, "ASSOCIATED TO", institution)) #del author profList.append(author) seqAuthor += 1 else: print("\tFilter load SKIPPED") for rel in institution.match(rel_type='ASSOCIATED TO'): profList.append(rel.start_node()) del institution return profList