-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add keyword extraction logic and rename source text collector directory #58
Draft
maxachis
wants to merge
6
commits into
Police-Data-Accessibility-Project:main
Choose a base branch
from
maxachis:mc_keyword_extraction
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ebf75c4
Rename html_tag_collector to source_tag_collector
maxachis 0c33781
Rename html_tag_collector to source_tag_collector
maxachis 63220e3
Rename text_html_tag_collector_integration to html_source_tag_collect…
maxachis 1c38fda
Create KeywordExtractor class
maxachis 17ee74b
Create source_text_collector_unit tests, add test_extract_keywords
maxachis c5e6b84
Add keyword extractor to collector logic
maxachis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
Tests/test_html_tag_collector_integration.py → ...test_source_text_collector_integration.py
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
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,16 @@ | ||
import pytest | ||
from unittest.mock import MagicMock, patch | ||
from source_text_collector.keyword_extractor import KeywordExtractor | ||
|
||
@patch('keybert.KeyBERT.extract_keywords') | ||
def test_extract_keywords(mock_extract_keywords): | ||
# Arrange | ||
mock_extract_keywords.return_value = [('keyword1', 0.8), ('keyword2', 0.7), ('keyword3', 0.6)] # return some mock keywords | ||
keyword_extractor = KeywordExtractor() | ||
|
||
# Act | ||
keywords = keyword_extractor.extract_keywords("some text", n=3) | ||
|
||
# Assert | ||
mock_extract_keywords.assert_called_once_with("some text", keyphrase_ngram_range=(1, 3), stop_words='english', top_n=3) | ||
assert keywords == ['keyword1', 'keyword2', 'keyword3'] |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
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,29 @@ | ||
import asyncio | ||
|
||
import requests | ||
import yake | ||
from bs4 import BeautifulSoup | ||
from keybert import KeyBERT | ||
|
||
|
||
# from multi_rake import Rake | ||
|
||
class KeywordExtractor: | ||
""" | ||
This class is used to extract keywords from text using the KeyBERT algorithm. | ||
""" | ||
|
||
def __init__(self): | ||
self.model = KeyBERT(model='all-mpnet-base-v2') | ||
|
||
def extract_keywords(self, text: str, n=10) -> list[str]: | ||
""" | ||
Extract keywords from text using KeyBERT algorithm. | ||
Args: | ||
text: The text to extract keywords from. | ||
n: The number of keywords to extract. | ||
|
||
Returns: The top n keywords extracted from the text. | ||
""" | ||
keywords = self.model.extract_keywords(text, keyphrase_ngram_range=(1, 3), stop_words='english', top_n=n) | ||
return [keyword for keyword, _ in keywords] |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need this in the requirements.txt?