-
Notifications
You must be signed in to change notification settings - Fork 0
/
artifact.py
56 lines (42 loc) · 1.16 KB
/
artifact.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
'''
Created on Jul 5, 2016
@author: ubuntu
'''
import re
import requests
class Artifact(object):
'''
classdocs
'''
refs = []
def __init__(self, uri, internal=False):
'''
Constructor
'''
self.uri = uri
self.internal = internal
self.relationships = [] # list of artifact instances
Artifact.refs.append(self)
def relate(self, other):
self.relationships.append(other)
other.relationships.append(self)
def score(self, scorer):
top = scorer(self.uri, self.internal)
self.relationships = top
def get_features(self):
# needs lots of expansion, assuming text for now
response = requests.get(self.uri)
feats = re.findall(r'\w+|[^\s\w]', response.content.decode())
return feats
@classmethod
def train(cls):
for ref in cls.refs[:1000]:
print('training', ref)
if __name__ == '__main__':
import string
from random import choice
letters = list(string.ascii_letters)
for i in range(1000000):
url = ''.join(choice(letters) for i in range(50))
a = Artifact(url)
Artifact.train()