예제 #1
0
def init_database():
    ents = ms.convert_entities()
    stemTS = ms.yaml2json('travelgene/pymonk-master/examples/turtle_scripts/turtle_stem.yml')
    stemT = ms.create_turtle(stemTS)
    # print stemT.generic()
    ents = ms.load_entities()
    for ent in ents:
        add_label(ent._id,'likeTravel','N')
    # print len(ents)
    # print ents[0].generic()
    fields=['title', 'comment', 'desc']
    print [stemT.predict(ent, fields) for ent in ents]
예제 #2
0
def get_recommended_place(collection_name,skip_num=0,request_num=5):  
    #print collection_name
    ents = ms.load_entities(collectionName = collection_name)
    user_turtle = 'likeTravel'
    trainer = train(user_turtle,'monk')
    rank=[]
    for ent in ents:
	rank.append((ent._id,predict(trainer,ent._id)))
    sorted_by_score = sorted(rank, key=lambda tup: tup[1])
    rst = []
    for r in sorted_by_score:
	ent = ms.load_entity(r[0])
        e = {}
        # e['place_id'] = ent.place_id
        e['_id'] = ent._id
        e['img_url'] = ent.img_url
        e['desc'] = ent.desc
        rst.append(e)
   # print len(ents)
    return rst[skip_num:skip_num+request_num]
예제 #3
0
import json
client = MongoClient()

def printJson(my_json):
	parsed = json.loads(my_json)
	print json.dumps(parsed,indent=4,sort_keys=True)

if __name__=='__main__':

	config=default_config()
	ms.initialize(default_config())

	stemTS = ms.yaml2json('turtle_scripts/turtle_stem.yml')
	stemT = ms.create_turtle(stemTS)
	# print stemT.generic()
	ents = ms.load_entities()
	# print len(ents)
	# print ents[0].generic()
	fields=['title', 'comment', 'desc']
	print [stemT.predict(ent, fields) for ent in ents]
	stemT.save()
	[ent.save() for ent in ents]
	likeTS = ms.yaml2json('turtle_scripts/turtle_like.yml')
	# print likeTS
	likeT = ms.create_turtle(likeTS)
	likeT.save()
	ent = ents[0]
	# print ents[0].generic()
	ent._setattr('likeTravel', 'Y')
	ms.crane.entityStore.save_one(ent)
	ms.add_data('likeTravel', 'monk', str(ents[0]._id))