forked from manasRK/word2vec-recommender
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathqueryFormation.py
More file actions
34 lines (28 loc) · 733 Bytes
/
queryFormation.py
File metadata and controls
34 lines (28 loc) · 733 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
29
30
31
32
33
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author: Akhil Gupta
# @Email: akhilgupta.official@gmail.com
# @Github username: @codeorbit
# @Last Modified by: Akhil Gupta
# @Last Modified time: 2016-07-1
import re
'''
Types of query
q1 = "michael jackson, jazz, price 50"
q2 = "michael jackson"
q3 = "pid B123"
'''
def queryTokenize(query):
tokens = {}
tokens["items"] = [] #for one or more item in query e.g. q1
for ele in query.split(","):
ele = ele.strip()
if re.search('\d+',ele):
temp = ele.split()
if temp[0] == "pid":
tokens.update({"orig_pid":temp[1]})
if temp[0] == "price":
tokens.update({"price":temp[1]})
else:
tokens["items"].append(ele.replace(" ","_"))
return tokens