Object

eventuality

class aser.eventuality.Eventuality(pattern='unknown', dependencies=None, skeleton_dependencies=None, parsed_result=None, use_lemma=True)[source]

Bases: JsonSerializedObject

ASER Eventuality

Parameters:
  • pattern (str) – the corresponding pattern

  • dependencies (List[Tuple[int, str, int]]) – the corresponding dependencies (e.g., [(1, “nsubj”, 0)])

  • skeleton_dependencies (List[Tuple[int, str, int]]) – the corresponding dependencies without optional edges (e.g., [(1, “nsubj”, 0)])

  • parsed_result (Dict[str, object]) – the parsed result of a sentence

decode(msg, encoding='utf-8', **kw)[source]

Decode the eventuality

Parameters:
  • msg (bytes) – the encoded bytes

  • encoding (str (default = "utf-8")) – the encoding format

  • kw (Dict[str, object]) – other parameters

Returns:

the decoded bytes

Return type:

bytes

property dependencies
static extract_indices_from_dependencies(dependencies)[source]

Extract indices from dependencies

Parameters:

dependencies (List[Tuple[int, str, int]]) – the input dependencies

Returns:

the involved indices

Return type:

List[int]

Input:

    [(8, "cop", 7), (8, "nsubj", 6)]

Output:

    [6, 7, 8]
static generate_eid(eventuality)[source]

Generate the eid to an eventuality

Parameters:

eventuality (aser.eventuality.Eventuality) – the given eventuality

Returns:

the unique eid to the eventuality

Return type:

str

property mentions
property ners
property phrases
property phrases_ners
property phrases_postags
property position
Returns:

this property returns average position of eventuality in a sentence. this property only make sense when this eventuality are constructed while extraction, instead of recovered from database.

property raw_dependencies
property skeleton_dependencies
property skeleton_ners
property skeleton_phrases
property skeleton_phrases_ners
property skeleton_phrases_postags
property skeleton_pos_tags
property skeleton_words
static sort_dependencies_position(dependencies, reset_position=True)[source]

Fix absolute positions into relevant positions and sort them

Parameters:
  • dependencies (List[Tuple[int, str, int]]) – the input dependencies

  • reset_position (bool (default = True)) – whether to reset positions

Returns:

the new dependencies, the position mapping, and the inversed mapping

Return type:

Tuple[List[Tuple[int, str, int], Union[Dict[int, int], None], Union[Dict[int, int], None]]

Input:

    [(8, "cop", 7), (8, "nsubj", 6)]

Output:

    [(2, 'nsubj', 0), (2, 'cop', 1)], {6: 0, 7: 1, 8: 2}, {0: 6, 1: 7, 2: 8}
to_dict(**kw)[source]

Convert an eventuality to a dictionary

Parameters:

kw (Dict[str, object]) – other parameters

Returns:

the converted dictionary that contains necessary information

Return type:

Dict[str, object]

update(x)[source]

Update the eventuality (‘s frequency)

Parameters:

x (Union[float, aser.eventuality.Eventuality]) – the given frequency or eventuality

Returns:

the updated eventuality

Return type:

aser.eventuality.Eventuality

property verbs

relation

class aser.relation.Relation(hid='', tid='', relations=None)[source]

Bases: JsonSerializedObject

ASER Relation

Parameters:
  • hid (str) – the unique eid to the head eventuality or conceptualied eventuality

  • tid (str) – the unique eid to the tail eventuality or conceptualied eventuality

  • relations (Union[None, Dict[str, float], aser.relation.Relation]) – the corresponding relations

static generate_rid(hid, tid)[source]
Parameters:
  • hid (str) – the unique eid to the head eventuality or conceptualied eventuality

  • tid (str) – the unique eid to the tail eventuality or conceptualied eventuality

Returns:

the unique rid to the pair

Return type:

str

to_triplets()[source]

Convert a relation to triplets

Returns:

a list of triplets

Return type:

List[Tuple[str, str]]

update(x)[source]

Update the relation (‘s frequency)

Parameters:

x (Union[Dict[str, float], Tuple[str], aser.relation.Relation]) – the given relation

Returns:

the updated relation

Return type:

aser.relation.Relation

concept

class aser.concept.ASERConcept(words=None, instances=None)[source]

Bases: JsonSerializedObject

ASER Conceptualied Eventuality

Parameters:
  • words (List[str]) – the word list of a concept

  • instances (List[Tuple[str, str, float]]) – a list of (eid, pattern, score)

static generate_cid(concept_str)[source]

Generate the cid to a concept

Parameters:

concept_str (List[str]) – concept representation (words connected by “ “)

Returns:

the corresponding unique cid

Return type:

str

instantiate(kg_conn=None)[source]

Retrieve the instances that are associated with this concept

Parameters:

kg_conn (aser.database.kg_connection.ASERKGConnection) – an KG connection to ASER

Returns:

a list of (eid, pattern, score)

Return type:

List[Tuple[str, str, float]]

property pattern
class aser.concept.ASERConceptInstancePair(cid='', eid='', pattern='unknown', score=0.0)[source]

Bases: JsonSerializedObject

Parameters:
  • cid (str) – the unique cid to the conceptualized eventuality

  • eid (str) – the unique eid to the eventuality

  • pattern (str) – the corresponding pattern

  • score (float) – the conceptualization probability

static generate_pid(cid, eid)[source]

Generate the pid to a pair

Parameters:
  • cid (str) – the unique cid to the conceptualized eventuality

  • eid (str) – the unique eid to the eventuality

Returns:

the unique pid to the pair

Return type:

str

class aser.concept.ProbaseConcept(data_concept_path='')[source]

Bases: object

Copied from https://github.com/ScarletPan/probase-concept

Parameters:

data_concept_path (str) – Probase .txt file path

property concept_size
conceptualize(instance, score_method='likelihood')[source]

Conceptualize the given instance

Parameters:
  • instance (str) – the given instance

  • score_method (str) – the method to compute sscores (“likelihood” or “pmi”)

Returns:

a list of (concept, score)

Return type:

List[Tuple[aser.concept.ProbaseConcept, float]]

get_concept_chain(instance, max_chain_length=5)[source]

Conceptualize the given instance in a chain

Parameters:
  • instance (str) – the given instance

  • max_chain_length (int (default = 5)) – the maximum length of the chain

Returns:

a chain that contains concepts

Return type:

List[str]

get_concept_freq(concept)[source]

Get the frequency of a concept

Parameters:

concept (str) – the given concept

Returns:

the corresponding frequency

Return type:

float

get_instance_freq(instance)[source]

Get the frequency of an instance

Parameters:

instance (str) – the given instance

Returns:

the corresponding frequency

Return type:

float

property instance_size
instantiate(concept)[source]

Retrieve all instances of a concept

Parameters:

concept (str) – the given concept

Returns:

a list of instances

Return type:

List[Tuple[str, float]]

load(file_name)[source]
Parameters:

file_name (str) – the file name to load the probase concepts

save(file_name)[source]
Parameters:

file_name (str) – the file name to save the probase concepts