event_extractor#

class predict_backend.ml.nlp.components.event_extractor.EventExtractor(nlp)#

Bases: SqlCompliant, PandasCompliant

Spacy custom component responsible for extracting events from spacy docs. It will set events_summary as a custom extension to the doc object. It also implements PandasCompliant and SqlCompliant so that it is compatible with the various persistence handlers.

assigns = ['doc._.events_summary']#
beautiful_name = 'Event Extraction'#
static create_component(nlp, name, depends_on)#

Factory function. Create a new instance of this component.

Parameters:
  • nlp (Any) – The spacy nlp object

  • name (str) – Useless. Just to give an example of registered params

  • depends_on (List[str]) – Useless. Just to give an example of registered params

Returns:

A new instance of the EventExtractor component

depends_on = ['ner', 'tagger', 'attribute_ruler']#
feature_columns = ['predicate', 'subject', 'object', 'oblique']#
classmethod get_default()#
Returns:

The default configuration for the component

classmethod get_df_table_name()#
Return type:

str

Returns:

The table name of the component.

classmethod get_feature_columns()#
Return type:

List

Returns:

Return the pandas columns names of the feature it extracts

classmethod get_sql_table_name()#
Return type:

str

Returns:

The table neme of the table that should contain the information extracted by this component.

classmethod init_dataframe()#
Return type:

DataFrame

Returns:

An empty dataframe with the necessary columns to store the information extracted by this component.

classmethod init_extension()#

Register the doc extension used by this component.

classmethod init_sql_db()#
Return type:

List[str]

Returns:

A list with the necessary columns to store the information extracted by this component.

name = 'virtualitics_event_extractor'#
pandas_cols = ['doc_number', 'predicate', 'subject', 'object', 'oblique', 'count']#
requires = []#
sql_cols = ['doc_number text', 'predicate text', 'subject text', 'object text', 'oblique text', 'count integer']#
table_name = 'events'#
classmethod to_df(doc, idx_col)#
Parameters:
  • doc (Doc) – Spacy doc object.

  • idx_col (str) – The column to use as idx.

Return type:

DataFrame

Returns:

Extract a dict with the events_summary information attached to a document.

classmethod to_dict(doc, idx_col)#
Parameters:
  • doc (Doc) – Spacy doc object.

  • idx_col (str) – The column to use as idx.

Return type:

List[Dict]

Returns:

Extract a dict with the events_summary information attached to a document.

classmethod transform_sql(doc, idx_col, value_placeholder='%s')#
Parameters:
  • doc – The spacy doc object

  • idx_col (str) – The column to use as id

  • value_placeholder – The type of placeholder to use (it can vary based on the client you’re using)

Return type:

Tuple[str, List]

Returns:

A list elements ready to be inserted into a db