<jupyter_start><jupyter_text>Create Neptune client<jupyter_code>GremlinUtils.init_statics(globals())

gremlin = GremlinUtils()

neptune_connection = gremlin.remote_connection()
g = gremlin.traversal_source(connection=neptune_connection)<jupyter_output><empty_output><jupyter_text>Create ElastiCache client<jupyter_code>ec = redis.StrictRedis(host=os.environ['ELASTICACHE_ENDPOINT'], port=6379)<jupyter_output><empty_output><jupyter_text>Query ElastiCache and Neptune<jupyter_code>class HtmlTable:
    def __init__(self):
        self.html = '<table style="border: 1px solid black">'
        self.empty_row = '<tr style="border: 1px solid black;"><td style="border: 1px solid black; vertical-align: top; text-align: center;" colspan="4">No results</td></tr>'
    
    def add_header_row(self, cols):
        self.html += '<tr style="border: 1px solid black; background-color: gainsboro; font-weight: bold;">'
        for col in cols:
            self.html += '<td style="border: 1px solid black; vertical-align: top; text-align: left;">{}</td>'.format(col)
        self.html += '</tr>'
        
    def add_row(self, cols):
        self.empty_row = ''
        self.html += '<tr style="border: 1px solid black;">'
        for col in cols:
            self.html += '<td style="border: 1px solid black; vertical-align: top; text-align: left;">{}</td>'.format(col)
        self.html += '</tr>'
        
    def get_html(self):
        result = self.html + self.empty_row + '</table>'
        return result
        
most_popular = ec.zrevrange('degree_centrality', 0, 2, withscores=True)

vertex_ids = []
centralities = []

for (vertex_id, centrality) in most_popular:
    vertex_ids.append(vertex_id.decode("utf-8") )
    centralities.append(int(centrality))
    
users = g.V(vertex_ids).valueMap(True).toList()

tbl = HtmlTable()
tbl.add_header_row(['First Name', 'Last Name', 'Age', 'Centrality'])

for (user, centrality) in zip(users, centralities):
    tbl.add_row([user['firstname'][0], user['lastname'][0], user['age'][0], centrality])
    
display(HTML(tbl.get_html()))<jupyter_output><empty_output><jupyter_text>Close Neptune client<jupyter_code>neptune_connection.close()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1546485260770975, 'fraction_numerical': 0.00816326530612245, 'mean_word_length': 4.528822055137844, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '479456', 'license': 'MIT-0', 'n_tokens_mistral': 779, 'n_tokens_neox': 749, 'n_words': 141, 'path': 'gremlin/neptune-streams/notebooks/centrality-counts.ipynb', 'repo_name': 'JanuaryThomas/amazon-neptune-samples', 'size': '2205'}