Skip to content

Commit

Permalink
Copied bm25_retriever script from local directory to general directory
Browse files Browse the repository at this point in the history
  • Loading branch information
alkidbaci committed Jan 5, 2025
1 parent 474d80c commit 7aa44e3
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions general_working_directory/bm25_retriever.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import numpy as np
import rdflib
from declarations import BM25

g = rdflib.Graph()
g.parse("fashionpedia-third-generation.owl", format="xml")

# Extract triplets
triplets = []
cn = 0
for subj, pred, obj in g:
triplets.append((str(subj), str(pred), str(obj)))

print(len(triplets))
# Index the data (convert triplets to text format)
documents = ["\n".join(triplet) for triplet in triplets]

bm25 = BM25()
bm25.fit(documents)
# Find the similar documents given query
query = "What are some clothes containing blue tshirt with long sleeves?"
scores = bm25.transform(query, documents)
print(documents[np.argmax(scores)])

0 comments on commit 7aa44e3

Please sign in to comment.