Skip to content

Commit

Permalink
Updated sys.path
Browse files Browse the repository at this point in the history
  • Loading branch information
ciioprof0 committed Aug 17, 2024
1 parent d2e44f7 commit 0ef0668
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 19 deletions.
12 changes: 11 additions & 1 deletion ling508/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,18 @@
from pymysql import MySQLError # Catch specific MySQL errors
from werkzeug.exceptions import BadRequest # Catch Flask request errors

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')))
# Set the path only if not already set
if 'stixd' not in sys.path:
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.append(project_root)
sys.path.append(os.path.join(project_root, 'ling508'))
sys.path.append(os.path.join(project_root, 'ling508', 'app'))
sys.path.append(os.path.join(project_root, 'ling508', 'db'))
sys.path.append(os.path.join(project_root, 'ling508', 'demos'))
sys.path.append(os.path.join(project_root, 'ling508', 'models'))
sys.path.append(os.path.join(project_root, 'ling508', 'tests'))

# Import Local Modules
from ling508.app.clex_importer import ClexImporter # Import Clex entries
from ling508.db.mysql_repository import MySQLRepository # Access the MySQL db

Expand Down
6 changes: 3 additions & 3 deletions ling508/app/clex_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ def import_clex_entries(self, uri: str) -> str:

# Generate a unique hash for the word_tag and word_form
tag_form_hash = self._generate_hash(word_tag, word_form)
# print(f"Generated hash: {tag_form_hash} for {word_tag} - {word_form}")
print(f"Generated hash: {tag_form_hash} for {word_tag} - {word_form}")

# Check if the entry already exists in the lexicon
existing_entry = self.db_repo.find_entry_by_id(tag_form_hash)
if existing_entry:
# print(f"Entry already exists for hash: {tag_form_hash}")
print(f"Entry already exists for hash: {tag_form_hash}")
updated_links += 1
continue

Expand All @@ -132,7 +132,7 @@ def import_clex_entries(self, uri: str) -> str:
# Save the entry to the lexicon table and retrieve its lex_id
lex_id = self.db_repo.save_entry(entry, 'lexicon')
if lex_id:
# print(f"Linking lex_id {lex_id} with stix_object_id {stix_object['obj_id']}")
print(f"Linking lex_id {lex_id} with stix_object_id {stix_object['obj_id']}")
# Link the entry to the STIX object in the junction table
self.db_repo.link_entry_with_stix(lex_id, stix_object['obj_id'])
new_entries += 1
Expand Down
4 changes: 2 additions & 2 deletions ling508/db/mysql_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def save_entry(self, entry: Dict[str, Any], table_name: str) -> int:

cursor.execute(sql_query, tuple(entry.values()))
lex_id = cursor.lastrowid # Directly capture the lex_id here
# print(f"Inserted entry with lex_id: {lex_id} into {table_name}")
print(f"Inserted entry with lex_id: {lex_id} into {table_name}")

if lex_id:
conn.commit()
Expand Down Expand Up @@ -101,7 +101,7 @@ def link_entry_with_stix(self, lex_id: int, stix_uuid: str) -> None:
(lex_id, stix_uuid)
)
conn.commit()
# print(f"Successfully linked lex_id {lex_id} with stix_uuid {stix_uuid}")
print(f"Successfully linked lex_id {lex_id} with stix_uuid {stix_uuid}")
except mysql.connector.Error as err:
print(f"Error linking lex_id {lex_id} with stix_uuid {stix_uuid}: {err}")
conn.rollback()
Expand Down
4 changes: 2 additions & 2 deletions ling508/demos/demo_clex_importer.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1365,14 +1365,14 @@
"\n",
"While the Flask API cannot be run directly within this notebook, you can run it locally by following these steps:\n",
"\n",
"1. Navigate to the directory containing the `api.py` file.\n",
"1. Navigate to the project root directory.\n",
"1. Activate the virtual environment:\n",
" - On Windows: `.venv\\Scripts\\activate`\n",
" - On macOS/Linux: `source .venv/bin/activate`\n",
"1. Install dependencies, if necessary:\n",
" - `pip install -r requirements.txt`\n",
"1. Run the Flask API:\n",
" - `python api.py`\n",
" - `python ling508/api.py`\n",
"1. Access the web form at `http://localhost:5000/`\n",
"1. When finished, stop the Flask API by pressing `Ctrl+C` in the terminal."
]
Expand Down
5 changes: 4 additions & 1 deletion ling508/demos/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
-r ../requirements.txt # Include all root dependencies
# -*- coding: utf-8 -*-
# stixd/ling508/demos/requirements.txt

-r ../../requirements.txt # Include all root dependencies

# Additional requirements for demos
ipykernel>=6.0.0 # For running Jupyter kernels
Expand Down
14 changes: 4 additions & 10 deletions ling508/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
beautifulsoup4>=4.12.0
flask>=3.0.0
html2text>=2024.0.0
mysql-connector-python>=9.0.0
pytest>=8.3.0
pytest-mock>=3.14.0
PyMySQL>=1.1.0
requests>=2.32.0
selenium>=4.23.0
spacy>=3.7.5
# -*- coding: utf-8 -*-
# stixd/ling508/requirements.txt

r ../requirements.txt # Include all root dependencies
10 changes: 10 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
beautifulsoup4>=4.12.0
flask>=3.0.0
html2text>=2024.0.0
mysql-connector-python>=9.0.0
pytest>=8.3.0
pytest-mock>=3.14.0
PyMySQL>=1.1.0
requests>=2.32.0
selenium>=4.23.0
spacy>=3.7.5

0 comments on commit 0ef0668

Please sign in to comment.