-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindexer.py
More file actions
30 lines (24 loc) · 1008 Bytes
/
indexer.py
File metadata and controls
30 lines (24 loc) · 1008 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
import db
stop_words = ["", " ", "the", "and", "or", "but", "not", "for", "at", "nor", "to", "from", "a", "of"]
delimiters = [":", "-", ","]
def add_index(context, url):
if(db.indexes.count_documents({"context": context},limit=1)==0):
print("adding indexes for -> " + context + ", " + url)
words: str = context
words = words.lower()
for d in delimiters:
words = words.replace(d, " ")
words: [str] = words.split(" ")
words = [word for word in words if word not in stop_words]
i = 0
for i in range(0, len(words)):
obj = {"index": words[0], "context": context, "url": url, "point": i}
print("inserting -> " + obj.__str__())
db.indexes.insert_one(obj)
rotate_right(words)
return
def rotate_right(words):
tmpcnt = words[len(words) - 1]
for j in range(len(words) - 2, 0, -1):
words[j + 1] = words[j]
words[0] = tmpcnt