-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copied bm25_retriever script from local directory to general directory
- Loading branch information
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)]) |