예제 #1
0
def main():

    # create users, resources and tag objects
    users = User()
    resources = Resource()
    tags = Tag()

    # fetch users, resources and tags from repository
    users.fetchFromDB()
    resources.fetchFromDB()
    tags.fetchFromDB()

    # create user-tag-resource relations object
    urt = db.UserResourceTag(users, resources, tags)
    # fetch relations from db
    urt.fetchFromDB()

    # print data
    f = open('res_repr.txt', 'w')
    f.write('\n\n\nUSERS\n\n\n')
    f.write(repr(users))
    f.write('\n\n\nRESOURCES\n\n\n')
    f.write(repr(resources))
    f.write('\n\n\nTAAAAGS\n\n\n')
    f.write(repr(tags))
    f.write('\n\n\nRELATIONS\n\n\n')
    for (u, r, t) in urt.urt:
        f.write('(%d, %d, %d)\n' % (u, r, t))

    # init folk rank algorithm
    fr = FolkRank(
        urt=urt.urt,
        nu=urt.getUsersNumber(),
        nr=urt.getResourcesNumber(),
        nt=urt.getTagsNumber()
    )
    fr.A.export_mtx('rez.txt', 2)

    # search tags list
    stags = []
    print 'Starting search for tags : %d - %s' % (139, urt.tags.tags[139])
    res = fr.searchResourcesByTags(139)
    writeResultsToFile('ratings139.txt', res, users=users, resources=resources, tags=tags)

    print 'Starting search for tags : %d - %s' % (25, urt.tags.tags[25])
    res = fr.searchResourcesByTags(25)
    writeResultsToFile('ratings25.txt', res, users=users, resources=resources, tags=tags)

    print 'All done !'
예제 #2
0
def update_network(accounts, depth):
    for account_id in accounts.keys():
        print '\tupdating user:'******'\t\tupdating', acc_type, 'account:', acc_username

            if acc_username == '': continue

            if acc_type == DELICIOUS:
                crawl = DeliciousCrawler.factory(acc_username, depth=depth) 
            elif acc_type == FLICKR:
                crawl = FlickrCrawler.factory(acc_username, depth=depth)
            elif acc_type == SLIDESHARE:
                crawl = SlideShareCrawler.factory(acc_username, depth=depth)
            elif acc_type == TWITTER:
                crawl = TwitterCrawler.factory(acc_username, depth=depth)
            elif acc_type == YOUTUBE:
                crawl = YouTubeCrawler.factory(acc_username, depth=depth)

            personUris.append(crawl.getUserUri(acc_username))
            crawlers.append(crawl)

        # create crawlers using user network accounts data
        t1 = time.clock()
        CrawlNetworks(crawlers).crawl(start_time=sdate)
        t2 = time.clock()

        # link resources to each other
        Resource.unify_all(personUris)

        print 'Finished in %d seconds' % (t2 - t1)