Skip to content

convert_openie_to_conll

allennlp_models.structured_prediction.tools.convert_openie_to_conll

[SOURCE]


Extraction#

Extraction = namedtuple(
    "Extraction",  # Open IE extraction
    [
        "sent",  # Sentence in which this  ...

Element#

Element = namedtuple(
    "Element",  # An element (predicate or argument) in an Open IE extraction
    [
     ...

main#

def main(inp_fn: str, domain: str, out_fn: str) -> None

inp_fn: str Path to file from which to read Open IE extractions in Open IE4's format. domain: str Domain to be used when writing CoNLL format. out_fn: str Path to file to which to write the CoNLL format Open IE extractions.

safe_zip#

def safe_zip(*args)

Zip which ensures all lists are of same size.

char_to_word_index#

def char_to_word_index(char_ind: int, sent: str) -> int

Convert a character index to word index in the given sentence.

element_from_span#

def element_from_span(span: List[Token], span_type: str) -> Element

Return an Element from span (list of spaCy tokens).

split_predicate#

def split_predicate(ex: Extraction) -> Extraction

Ensure single word predicate by adding "before-predicate" and "after-predicate" arguments.

extraction_to_conll#

def extraction_to_conll(ex: Extraction) -> List[str]

Return a CoNLL representation of a given input Extraction.

interpret_span#

def interpret_span(text_spans: str) -> Tuple[int, int]

Return an integer tuple from textual representation of closed/open spans.

interpret_element#

def interpret_element(
    element_type: str,
    text: str,
    span: str
) -> Element

Construct an Element instance from regexp groups.

parse_element#

def parse_element(raw_element: str) -> List[Element]

Parse a raw element into text and indices (integers).

read#

def read(fn: str) -> Iterable[List[Extraction]]

convert_sent_to_conll#

def convert_sent_to_conll(
    sent_ls: List[Extraction]
) -> Iterable[Tuple[str, ...]]

Given a list of extractions for a single sentence, converts it to CoNLL representation.

pad_line_to_ontonotes#

def pad_line_to_ontonotes(
    line: Tuple[str, ...],
    domain: str
) -> List[str]

Pad line to conform to OntoNotes representation.

convert_sent_to_conll_str#

def convert_sent_to_conll_str(
    sent_ls: List[Extraction],
    domain: str
) -> str

Given a dictionary from sentence -> extractions, return a corresponding CoNLL representation.