Skip to content

Commit

Permalink
Merge pull request #98 from Knox-AAU/97-database-crud
Browse files Browse the repository at this point in the history
add database docs
  • Loading branch information
BlakRoenne authored Dec 8, 2023
2 parents d04204c + 92a9f1f commit 5fcd59b
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions docs/database.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# [Database](https://github.com/Knox-AAU/PreProcessingLayer_EntityRecognitionAndLinking/blob/main/components/Db.py)
The database is responsible for keeping track of sentences, entity mentions, and entity indices.

## Features
- CRUD (Create, Read, Update, Delete) Operations supported.
- Uses [SQLite](https://www.sqlite.org/index.html).
- Seeds the database with required tables if they do not exist.

## <a name="overview"></a>Overview
The database contains the following tables:

![](img/database-visualized.png)

### sentence
Contains each sentence from all input text. Has a unique `sid`.

### entitymention
Represents each entity mention from all input text. Has `sid` as foreign key (a sentence must exist for the entitymention to exist).

### EntityIndex
Used by the [Entity Linker](https://github.com/Knox-AAU/PreProcessingLayer_EntityRecognitionAndLinking/blob/main/components/EntityLinker.py) to find potential matches for a given entity mention. See [Entity Linker Docs](https://github.com/Knox-AAU/PreProcessingLayer_EntityRecognitionAndLinking/blob/main/docs/entitylinker.md) for more information.

## Methods
```python
async def InitializeIndexDB(dbPath):
```
### Parameters:
- **dbPath** (str): A path where the database will be stored / is stored, ie. `some/path/to/a/Database/directory`.

```python
async def Insert(dbPath, tableName, queryInformation):
```
### Parameters:
- **dbPath** (str): A path where the database will be stored / is stored, ie. `some/path/to/a/Database/directory`.
- **tableName** (str): The name of the table you want to insert into, available ones can be found in [Overview](##Overview).
- **queryInformation** (JSON): A JSON object containing the key-value pairs you want to insert, for example:
```JSON
{
"fileName": "article.txt",
"string": "A duck walked across the road",
"startindex": 20,
"endIndex": 29
}
```
Would be a valid insert in the `sentence` table.

> **_NOTE:_** The `sid` is autogenerated using `AUTOINCREMENT`.
```python
async def Read(dbPath, tableName, searchPred=""):
```
### Parameters:
- **dbPath** (str): A path where the database will be stored / is stored, ie. `some/path/to/a/Database/directory`.
- **tableName** (str): The name of the table you want to insert into, available ones can be found in [Overview](##Overview).
- The search predicate to query the table with, for example if `searchPred` = `Jones` and the `tableName` = `entitymention`, the entitymention table will be searched for `Jones`.

```python
async def Update(dbPath, tableName, indexID, updatedName):
```
### Parameters:
- **dbPath** (str): A path where the database will be stored / is stored, ie. `some/path/to/a/Database/directory`.
- **tableName** (str): The name of the table you want to insert into, available ones can be found in [Overview](##Overview).
- **indexID** (str): The `sid`, `eid` or `id` (EntityIndex) to update.
- **updatedName** (str): What the `string`, `mention` or `name` should be updated to.


```python
async def Delete(dbPath, tableName, indexID):
```
### Parameters:
- **dbPath** (str): A path where the database will be stored / is stored, ie. `some/path/to/a/Database/directory`.
- **tableName** (str): The name of the table you want to insert into, available ones can be found in [Overview](##Overview).
- **indexID** (str): The `sid`, `eid` or `id` (EntityIndex) to delete.
Binary file added docs/img/database-visualized.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5fcd59b

Please sign in to comment.