diff --git a/components/EntityLinker.py b/components/EntityLinker.py index 7634bfc..a82ad85 100644 --- a/components/EntityLinker.py +++ b/components/EntityLinker.py @@ -19,6 +19,8 @@ def GetAllEntities(entityMentions): sentence=sentence["sentence"], sentenceStartIndex=sentence["sentenceStartIndex"], sentenceEndIndex=sentence["sentenceEndIndex"], + label=entity["label"], + type=entity["type"], ) allEntities.append(newEntity) return allEntities @@ -29,6 +31,9 @@ async def entitylinkerFunc(entities, threshold=80): linked_entities = [] db_path = "./Database/DB.db" for entity in entities: + if entity.type is "Literal": + linked_entities.append(EntityLinked(entity, "")) + continue # Use the Read function to get all entities starting with the same name potential_matches = await Db.Read( db_path, "EntityIndex", searchPred=entity.name diff --git a/components/GetSpacyData.py b/components/GetSpacyData.py index 98dc971..0d1c09c 100644 --- a/components/GetSpacyData.py +++ b/components/GetSpacyData.py @@ -106,8 +106,15 @@ def GetEntities(doc) -> List[Entity]: sentence=entity.sent.text, sentenceStartIndex=entity.sent.start_char, sentenceEndIndex=entity.sent.end_char, + label=entity.label_, + type=isLiteral(entity), ) ) return entities - \ No newline at end of file + +def isLiteral(entity): + if entity.label_ == "DATE" or entity.label_ == "TIME" or entity.label_ == "PERCENT" or entity.label_ == "MONEY" or entity.label_ == "QUANTITY" or entity.label_ == "ORDINAL" or entity.label_ == "CARDINAL": + return "Literal" + else: + return "Entity" \ No newline at end of file diff --git a/lib/Entity.py b/lib/Entity.py index 839409c..72a28e5 100644 --- a/lib/Entity.py +++ b/lib/Entity.py @@ -1,8 +1,10 @@ class Entity: - def __init__(self, name: str, startIndex: int, endIndex: int, sentence: str, sentenceStartIndex: int, sentenceEndIndex: int): + def __init__(self, name: str, startIndex: int, endIndex: int, sentence: str, sentenceStartIndex: int, sentenceEndIndex: int, label: str, type: str): self.name = name self.startIndex = startIndex self.endIndex = endIndex self.sentence = sentence self.sentenceStartIndex = sentenceStartIndex - self.sentenceEndIndex = sentenceEndIndex \ No newline at end of file + self.sentenceEndIndex = sentenceEndIndex + self.label = label + self.type = type \ No newline at end of file diff --git a/lib/EntityLinked.py b/lib/EntityLinked.py index 1b2e472..4dc852e 100644 --- a/lib/EntityLinked.py +++ b/lib/EntityLinked.py @@ -4,15 +4,18 @@ class EntityLinked(Entity): def __init__(self, entity: Entity, iri: str): super().__init__( - entity.name, entity.startIndex, entity.endIndex, entity.sentence, entity.sentenceStartIndex, entity.sentenceEndIndex + entity.name, entity.startIndex, entity.endIndex, entity.sentence, entity.sentenceStartIndex, entity.sentenceEndIndex, entity.label, entity.type ) self.iri = iri.replace(" ", "_") def getEntityJSON(self): return { "name": self.name, + "type": self.type, + "label": self.label, + "type": self.type, "startIndex": self.startIndex, "endIndex": self.endIndex, - "iri": "knox-kb01.srv.aau.dk/" + self.iri, + "iri": ("knox-kb01.srv.aau.dk/" + self.iri) if self.type is "Entity" else None } diff --git a/main.py b/main.py index 63d9f8e..c6e7529 100644 --- a/main.py +++ b/main.py @@ -12,13 +12,28 @@ from lib.FileWatcher import FileWatcher from langdetect import detect from fastapi import FastAPI, HTTPException, Request +from fastapi.responses import HTMLResponse +from fastapi.staticfiles import StaticFiles app = FastAPI() +app.mount("/public", StaticFiles(directory="public"), name="public") + + # @app.on_event("startup") # async def startEvent(): # await main() +@app.get("/", response_class=HTMLResponse) +async def mainpage(): + + return """ + + + + +""" + @app.get("/entitymentions") async def getJson(): diff --git a/public/boombastic.mp3 b/public/boombastic.mp3 new file mode 100644 index 0000000..644dc85 Binary files /dev/null and b/public/boombastic.mp3 differ diff --git a/public/important_images/kurt.webp b/public/important_images/kurt.webp new file mode 100644 index 0000000..f3215df Binary files /dev/null and b/public/important_images/kurt.webp differ diff --git a/public/style.css b/public/style.css new file mode 100644 index 0000000..f734081 --- /dev/null +++ b/public/style.css @@ -0,0 +1,9 @@ +* { + background-image: url("/public/important_images/kurt.webp"); + width: 100%; + height: 100%; + overflow: hidden; + background-position: center; + background-repeat: no-repeat; + background-size: cover; +} \ No newline at end of file diff --git a/tests/unit/test_EntityLinker.py b/tests/unit/test_EntityLinker.py index 0ce2bd4..3fa5772 100644 --- a/tests/unit/test_EntityLinker.py +++ b/tests/unit/test_EntityLinker.py @@ -27,8 +27,8 @@ async def mock_insert(db_path, table, entity_name): ): # Create some Entity instances entMentions = [ - Entity("Entity1", 0, 6, "Sentence1", 0, 9), - Entity("newEntity3", 0, 6, "Sentence2", 0, 9), + Entity("Entity1", 0, 6, "Sentence1", 0, 9, "PERSON", "Entity"), + Entity("newEntity3", 0, 6, "Sentence2", 0, 9, "PERSON", "Entity"), ] # Call the entitylinkerFunc @@ -62,7 +62,7 @@ async def mock_insert(db_path, table, entity_name): ): # Create some Entity instances entMentions = [ - Entity("Entity1", 0, 6, "Sentence1", 0, 9), + Entity("Entity1", 0, 6, "Sentence1", 0, 9, "PERSON", "Entity"), ] # Call the entitylinkerFunc @@ -95,7 +95,7 @@ async def mock_insert(db_path, table, entity_name): ): # Create some Entity instances entMentions = [ - Entity("Entity1", 0, 6, "Sentence1", 0, 9), + Entity("Entity1", 0, 6, "Sentence1", 0, 9, "PERSON", "Entity"), ] # Call the entitylinkerFunc @@ -149,7 +149,7 @@ async def mock_insert(db_path, table, queryInformation): # Create some Entity instances TestingDataset = { "test": [ - Entity(name, 0, 6, "Sentence1", 0, 9) + Entity(name, 0, 6, "Sentence1", 0, 9, "PERSON", "Entity") for name in names_with_duplicates ], "GoldStandardNames": [ diff --git a/tests/unit/test_GetSpacyData.py b/tests/unit/test_GetSpacyData.py index 5ad996a..45e4224 100644 --- a/tests/unit/test_GetSpacyData.py +++ b/tests/unit/test_GetSpacyData.py @@ -48,6 +48,7 @@ def test_GetEntities(): "start_char": 0, "end_char": 40 }), + "label_": "PERSON", "text": "Drake", "start_char": 0, "end_char": 5 @@ -58,6 +59,7 @@ def test_GetEntities(): "start_char": 0, "end_char": 14 }), + "label_": "PERSON", "text": "Buddyguy", "start_char": 6, "end_char": 14