Skip to content
This repository has been archived by the owner on Jun 15, 2024. It is now read-only.

Commit

Permalink
chore: name adjust & small change
Browse files Browse the repository at this point in the history
  • Loading branch information
doomspec committed Sep 1, 2023
1 parent 0ef2f71 commit 623f2ee
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
33 changes: 15 additions & 18 deletions evonote/indexing/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ def make_data(cls, new_notes: List[Note], indexing: Indexing,
indexing.data = {
"vecs": None,
"srcs_list": [],
"index_to_note": [],
"note_of_vecs": [],
"weights_list": [],
}

new_srcs, new_weights, new_index_to_note = cls.prepare_src_weight_list(new_notes,
new_srcs, new_weights, new_note_of_vecs = cls.prepare_src_weight_list(new_notes,
indexing,
use_cache)
indexing.data["srcs_list"].extend(new_srcs)
indexing.data["index_to_note"].extend(new_index_to_note)
indexing.data["note_of_vecs"].extend(new_note_of_vecs)
indexing.data["weights_list"].extend(new_weights)

new_vecs = []
Expand Down Expand Up @@ -176,7 +176,7 @@ def get_similarities(cls, query: List[str], indexing: Indexing,
show_src_similarity_gui(similarity, indexing.data, query, weights)
pass

return similarity, indexing.data["index_to_note"]
return similarity, indexing.data["note_of_vecs"]

@classmethod
def process_note_with_content(cls, notes: List[Note], indexing: Indexing,
Expand All @@ -192,7 +192,7 @@ def process_note_without_content(cls, notes: List[Note], indexing: Indexing,
def show_src_similarity_gui(similarity, data, query, weights, top_k=10):
from evonote.gui.similarity_search import draw_similarity_gui
top_note_index = np.argsort(similarity)[::-1][:top_k]
notes = data["index_to_note"]
notes = data["note_of_vecs"]
top_notes = [notes[i] for i in top_note_index]
contents = [note.content for note in top_notes]
src_list = data["srcs_list"]
Expand All @@ -209,8 +209,8 @@ def process_note_with_content(cls, notes: List[Note], indexing: Indexing,
notes_content = [note.content for note in notes]
notebook = indexing.notebook

new_src_list_2 = []
new_weights_2 = []
new_src_list = []
new_weights = []
n_finished = 0
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
for note, frags in zip(notes,
Expand All @@ -222,46 +222,43 @@ def process_note_with_content(cls, notes: List[Note], indexing: Indexing,
new_src.append(note.get_note_path(notebook)[-1])
new_src.append(note.content)

new_src_list_2.append(new_src)
new_src_list.append(new_src)
# TODO Handle when there are too many fragments. Maybe we should group
# them by clustering
weight = np.ones(len(new_src)) / (len(new_src) ** 0.95)
new_weights_2.append(weight)
new_weights.append(weight)

n_finished += 1
if n_finished % 20 == 19:
save_cache()

save_cache()
return new_src_list_2, new_weights_2
return new_src_list, new_weights

@classmethod
def process_note_without_content(cls, notes: List[Note], indexing: Indexing,
use_cache: bool):
new_src_list_1 = []
new_weights_1 = []
new_src_list = []
new_weights = []

for note in notes:
keywords_on_path = note.get_note_path(indexing.notebook)
# keep last 1/3 of the keywords
n_keywords = min(max(math.ceil(len(keywords_on_path) / 3), 3),
len(keywords_on_path))
new_src = keywords_on_path[-n_keywords:]
new_src_list_1.append(new_src)
new_src_list.append(new_src)
weight = np.array([i + 1 for i in range(len(new_src))])
weight = weight / np.sum(weight)
new_weights_1.append(weight)
new_weights.append(weight)

return new_src_list_1, new_weights_1
return new_src_list, new_weights

@classmethod
def prepare_src_weight_list(cls, new_notes: List[Note], indexing: Indexing,
use_cache: bool):

notebook = indexing.notebook

index_to_note = []

notes_with_content = []
notes_content = []
notes_without_content = []
Expand Down
2 changes: 1 addition & 1 deletion evonote/search/code_searcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def possible_function_names(description: str):
res = chat.complete_chat()
res = res.split("\n")
res = [r.strip() for r in res]
res = [r for r in res if len(r) > 0]
res = [" ".join(r.split("_")) for r in res if len(r) > 0]
return res


Expand Down

0 comments on commit 623f2ee

Please sign in to comment.