Skip to content

Instantly share code, notes, and snippets.

@dennisdv1
Created December 2, 2020 08:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dennisdv1/1c9e7754ae76e97fecbe5fa85b464dde to your computer and use it in GitHub Desktop.
Save dennisdv1/1c9e7754ae76e97fecbe5fa85b464dde to your computer and use it in GitHub Desktop.
from spacy.pipeline import EntityRuler
from spacy import displacy
import jsonlines
# Create list with entity labels from jsonl file
with jsonlines.open(PROJECT_DIR + "data/skill_patterns.jsonl") as f:
created_entities = [line['label'].upper() for line in f.iter()]
def add_newruler_to_pipeline(skill_pattern_path):
'''Reads in all created patterns from a JSONL file and adds it to the pipeline after PARSER and before NER'''
new_ruler = EntityRuler(nlp).from_disk(skill_pattern_path)
nlp.add_pipe(new_ruler, after='parser')
def visualize_entity_ruler(entity_list, doc):
'''Visualize the Skill entities of a doc'''
options = {"ents": entity_list}
displacy.render(doc, style='ent', options=options)
visualize_entity_ruler(created_entities, doc)
@Blurdroid
Copy link

in this code
project_dir not defined i want know which file is that can someone explain that ??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment