-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathexample.py
More file actions
executable file
·28 lines (23 loc) · 789 Bytes
/
Copy pathexample.py
File metadata and controls
executable file
·28 lines (23 loc) · 789 Bytes
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
#!/usr/bin/env python
from __future__ import print_function
import random
import urlclustering
def pprint(clusters):
for key, urls in clusters.items():
print('REGEX:', key[0])
print('HUMAN:', key[1])
print('URLS:')
print('\t' + '\n\t'.join(urls) + '\n')
urls = [
u'http://example.com',
u'http://example.com/about',
]
cats = [u'http://example.com/cat/%s' % x
for x in ('sports', 'tech', 'life', 'politics', 'world')]
tags = [u'http://example.com/tag/%s/tag%s' % (random.randint(100, 999), x)
for x in range(10)]
arts = [u'http://example.com/article/?id=%s' % x for x in range(10)]
c = urlclustering.cluster(urls + cats + tags + arts, 5)
pprint(c['clusters'])
print('UNCLUSTERED:')
print('\t' + '\n\t'.join(c['unclustered']))