cryogenic22 commited on
Commit
4ff66ad
·
verified ·
1 Parent(s): 9f4320e

Create modules/extractor_module.py

Browse files
Files changed (1) hide show
  1. modules/extractor_module.py +31 -0
modules/extractor_module.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+
3
+ #modules/extractor_module.py
4
+ from typing import Dict, List
5
+ from core.base_module import AIModule
6
+ import spacy
7
+
8
+ class ExtractorModule(AIModule):
9
+ def __init__(self):
10
+ self.nlp = spacy.load("en_core_web_sm")
11
+
12
+ async def process(self, input_data: Dict) -> Dict:
13
+ text = input_data.get("text", "")
14
+ doc = self.nlp(text)
15
+
16
+ entities = [
17
+ {"text": ent.text, "label": ent.label_}
18
+ for ent in doc.ents
19
+ ]
20
+
21
+ return {
22
+ "entities": entities,
23
+ "num_entities": len(entities)
24
+ }
25
+
26
+ async def get_status(self) -> Dict:
27
+ return {"status": "operational", "model": "en_core_web_sm"}
28
+
29
+ @property
30
+ def capabilities(self) -> List[str]:
31
+ return ["named-entity-recognition", "information-extraction"]