Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
daf2d54
Add data visualization for Anthropic
Vasilije1990 Jan 10, 2025
b132ff4
Update cognee-mcp/cognee_mcp/server.py
Vasilije1990 Jan 11, 2025
7b0bfe9
Update cognee-mcp/cognee_mcp/server.py
Vasilije1990 Jan 11, 2025
cf4737b
Update cognee-mcp/cognee_mcp/server.py
Vasilije1990 Jan 12, 2025
55e9d64
Add data visualization for Anthropic
Vasilije1990 Jan 13, 2025
047948a
Add data visualization for Anthropic
Vasilije1990 Jan 14, 2025
3ba98b2
Merge branch 'dev' into COG-975
Vasilije1990 Jan 14, 2025
ad07bae
Add data visualization for Anthropic
Vasilije1990 Jan 14, 2025
a0e3686
Update README.md
Vasilije1990 Jan 14, 2025
61118dd
Update README.md
Vasilije1990 Jan 14, 2025
e71f852
Update README.md
Vasilije1990 Jan 14, 2025
933d21a
Update dockerhub pushes
Vasilije1990 Jan 14, 2025
aef7822
Merge branch 'dev' into COG-975
Vasilije1990 Jan 15, 2025
be0b486
Update lock files
Vasilije1990 Jan 16, 2025
662faeb
Update format
Vasilije1990 Jan 16, 2025
4a87df9
Update format
Vasilije1990 Jan 16, 2025
4ae8eb9
Update format
Vasilije1990 Jan 16, 2025
1af24dc
Update format
Vasilije1990 Jan 16, 2025
b2355de
Update format
Vasilije1990 Jan 16, 2025
5b31638
Update format
Vasilije1990 Jan 16, 2025
f19b58a
Update format
Vasilije1990 Jan 16, 2025
5aaf420
Fix for now
Vasilije1990 Jan 16, 2025
72b503f
Fix for now
Vasilije1990 Jan 16, 2025
7a4a0f4
Fix for now
Vasilije1990 Jan 16, 2025
0783625
Fix for now
Vasilije1990 Jan 16, 2025
bbd51e8
Fix for now
Vasilije1990 Jan 16, 2025
cb7b2d3
Fix for now
Vasilije1990 Jan 16, 2025
fe47253
Fix for now
Vasilije1990 Jan 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add data visualization for Anthropic
  • Loading branch information
Vasilije1990 committed Jan 14, 2025
commit ad07bae9a781c909c67658261d579de5834ea3b1
30 changes: 29 additions & 1 deletion cognee/shared/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import pandas as pd
import matplotlib.pyplot as plt
import tiktoken

import nltk
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Remove duplicate nltk import

The nltk module is imported twice. Remove the duplicate import on line 26 to fix the F811 error.

import nltk
import base64
import time
...
- import nltk
from cognee.shared.exceptions import IngestionError

Also applies to: 26-26

🧰 Tools
🪛 GitHub Actions: ruff format

[warning] File needs formatting according to Ruff standards

import base64
import time

Expand All @@ -30,6 +30,34 @@
proxy_url = "https://test.prometh.ai"



def get_entities(tagged_tokens):
nltk.download("maxent_ne_chunker", quiet=True)
from nltk.chunk import ne_chunk

return ne_chunk(tagged_tokens)
Comment on lines +31 to +35
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add docstring and error handling for get_entities()

The function lacks a docstring explaining its purpose and parameters. Also, NLTK resource downloads should be handled with error checking.

 def get_entities(tagged_tokens):
+    """Extract named entities from POS-tagged tokens using NLTK's ne_chunk.
+    
+    Args:
+        tagged_tokens: A list of POS-tagged tokens from nltk.pos_tag()
+    
+    Returns:
+        A tree containing chunks of named entities
+    """
+    try:
         nltk.download("maxent_ne_chunker", quiet=True)
         from nltk.chunk import ne_chunk
+    except Exception as e:
+        logging.error(f"Failed to download NLTK resources: {str(e)}")
+        raise

         return ne_chunk(tagged_tokens)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def get_entities(tagged_tokens):
nltk.download("maxent_ne_chunker", quiet=True)
from nltk.chunk import ne_chunk
return ne_chunk(tagged_tokens)
def get_entities(tagged_tokens):
"""Extract named entities from POS-tagged tokens using NLTK's ne_chunk.
Args:
tagged_tokens: A list of POS-tagged tokens from nltk.pos_tag()
Returns:
A tree containing chunks of named entities
"""
try:
nltk.download("maxent_ne_chunker", quiet=True)
from nltk.chunk import ne_chunk
except Exception as e:
logging.error(f"Failed to download NLTK resources: {str(e)}")
raise
return ne_chunk(tagged_tokens)
🧰 Tools
🪛 GitHub Actions: ruff format

[warning] File requires formatting using Ruff formatter



def extract_pos_tags(sentence):
"""Extract Part-of-Speech (POS) tags for words in a sentence."""

# Ensure that the necessary NLTK resources are downloaded
nltk.download("words", quiet=True)
nltk.download("punkt", quiet=True)
nltk.download("averaged_perceptron_tagger", quiet=True)

from nltk.tag import pos_tag
from nltk.tokenize import word_tokenize

# Tokenize the sentence into words
tokens = word_tokenize(sentence)

# Tag each word with its corresponding POS tag
pos_tags = pos_tag(tokens)

return pos_tags

Comment on lines +38 to +56
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add input validation and improve error handling for extract_pos_tags()

The function should validate input and handle NLTK resource downloads more robustly.

 def extract_pos_tags(sentence):
     """Extract Part-of-Speech (POS) tags for words in a sentence.
+    
+    Args:
+        sentence (str): Input sentence to be POS tagged
+    
+    Returns:
+        list: A list of tuples containing (word, POS_tag)
+    
+    Raises:
+        ValueError: If sentence is not a string or is empty
+        Exception: If NLTK resource download fails
+    """
+    if not isinstance(sentence, str) or not sentence.strip():
+        raise ValueError("Input must be a non-empty string")

+    try:
         # Ensure that the necessary NLTK resources are downloaded
         nltk.download("words", quiet=True)
         nltk.download("punkt", quiet=True)
         nltk.download("averaged_perceptron_tagger", quiet=True)
+    except Exception as e:
+        logging.error(f"Failed to download NLTK resources: {str(e)}")
+        raise

     from nltk.tag import pos_tag
     from nltk.tokenize import word_tokenize

     # Tokenize the sentence into words
     tokens = word_tokenize(sentence)

     # Tag each word with its corresponding POS tag
     pos_tags = pos_tag(tokens)

     return pos_tags
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def extract_pos_tags(sentence):
"""Extract Part-of-Speech (POS) tags for words in a sentence."""
# Ensure that the necessary NLTK resources are downloaded
nltk.download("words", quiet=True)
nltk.download("punkt", quiet=True)
nltk.download("averaged_perceptron_tagger", quiet=True)
from nltk.tag import pos_tag
from nltk.tokenize import word_tokenize
# Tokenize the sentence into words
tokens = word_tokenize(sentence)
# Tag each word with its corresponding POS tag
pos_tags = pos_tag(tokens)
return pos_tags
def extract_pos_tags(sentence):
"""Extract Part-of-Speech (POS) tags for words in a sentence.
Args:
sentence (str): Input sentence to be POS tagged
Returns:
list: A list of tuples containing (word, POS_tag)
Raises:
ValueError: If sentence is not a string or is empty
Exception: If NLTK resource download fails
"""
if not isinstance(sentence, str) or not sentence.strip():
raise ValueError("Input must be a non-empty string")
try:
# Ensure that the necessary NLTK resources are downloaded
nltk.download("words", quiet=True)
nltk.download("punkt", quiet=True)
nltk.download("averaged_perceptron_tagger", quiet=True)
except Exception as e:
logging.error(f"Failed to download NLTK resources: {str(e)}")
raise
from nltk.tag import pos_tag
from nltk.tokenize import word_tokenize
# Tokenize the sentence into words
tokens = word_tokenize(sentence)
# Tag each word with its corresponding POS tag
pos_tags = pos_tag(tokens)
return pos_tags
🧰 Tools
🪛 GitHub Actions: ruff format

[warning] File needs formatting according to Ruff standards


def get_anonymous_id():
"""Creates or reads a anonymous user id"""
home_dir = str(pathlib.Path(pathlib.Path(__file__).parent.parent.parent.resolve()))
Expand Down
Loading