Server/Client

ASER server

class aser.server.ASERDataBase(opt, db_sender_addr_list, sink_addr)[source]

Bases: Process

Process to provide DB retrieval functions

close()[source]

Close the process safely

handle_exact_match_concept(cid)[source]

Retrieve the extract match concept from DB

Parameters:

cid (str) – cid

Returns:

the exact matched concept or None

Return type:

Union[aser.concept.ASERConcept, None]

handle_exact_match_concept_relation(rid)[source]

Retrieve the extract match relation between concepts from DB

Parameters:

rid (str) – rid

Returns:

the exact matched relation or None

Return type:

Union[aser.relation.Relation, None]

handle_exact_match_eventuality(eid)[source]

Retrieve the extract match eventuality from DB

Parameters:

eid (str) – eid

Returns:

the exact matched eventuality or None

Return type:

Union[aser.eventuality.Eventuality, None]

handle_exact_match_eventuality_relation(rid)[source]

Retrieve the extract match relation between eventualities from DB

Parameters:

rid (str) – rid

Returns:

the exact matched relation or None

Return type:

Union[aser.relation.Relation, None]

Fetch all related concepts of the given concept

Parameters:

cid (str) – cid

Returns:

all related concepts associated with corresponding relations

Return type:

List[Tuple[aser.concept.ASERConcept, aser.relation.Relation]]

Fetch all related eventualities of the given eventuality

Parameters:

eid (str) – eid

Returns:

all related eventualities associated with corresponding relations

Return type:

List[Tuple[aser.eventuality.Eventuality, aser.relation.Relation]]

run()[source]

Method to be run in sub-process; can be overridden in sub-class

class aser.server.ASERServer(opt)[source]

Bases: object

ASER server to provide extraction, conceptualization, and retrieval functions

Parameters:

opt (argparse.Namespace) – the namespace that includes parameters

close()[source]

Clase the server safely

run()[source]

Start the server

class aser.server.ASERSink(args, sink_addr_receiver_addr)[source]

Bases: Process

Process to forward messages

run()[source]

Method to be run in sub-process; can be overridden in sub-class

class aser.server.ASERWorker(opt, id, worker_addr_list, sink_addr)[source]

Bases: Process

Process to serve extraction and conceptualization functions

close()[source]

Close the process safely

handle_conceptualize_eventuality(eventuality)[source]
handle_extract_eventualities(data)[source]
handle_extract_eventualities_and_relations(data)[source]
handle_extract_relations(data)[source]
handle_parse_text(text)[source]
run()[source]

Method to be run in sub-process; can be overridden in sub-class

aser.server.is_port_occupied(ip='127.0.0.1', port=80)[source]

Check whether the ip:port is occupied

Parameters:
  • ip (str (default = "127.0.0.1")) – the ip address

  • port (int (default = 80)) – the port

Returns:

whether is occupied

Return type:

bool

aser.server.sockets_ipc_bind(socket)[source]
Parameters:

socket (zmq.sugar.socket.Socket) – a socket

Returns:

the bound address

Return type:

str

You can get the aser-server usage via:

aser-server --help
usage: aser-server [-h] [-n_workers N_WORKERS] [-n_concurrent_back_socks N_CONCURRENT_BACK_SOCKS] [-port PORT]
                   [-port_out PORT_OUT] [-corenlp_path CORENLP_PATH] [-base_corenlp_port BASE_CORENLP_PORT]
                   [-aser_kg_dir ASER_KG_DIR] [-concept_kg_dir CONCEPT_KG_DIR] [-concept_method {probase,seed}]
                   [-probase_path PROBASE_PATH] [-concept_topk CONCEPT_TOPK] [-log_path LOG_PATH]

Named Arguments

-n_workers

Number of ASER workers, same as num of corenlp workers

Default: 5

-n_concurrent_back_socks

Number of concurrent workers sockets

Default: 10

-port

server port for receiving msg from client

Default: 8000

-port_out

client port for receving return data from server

Default: 8001

-corenlp_path

StanfordCoreNLP path

Default: “”

-base_corenlp_port

Base port of corenlp[base_corenlp_port, base_corenlp_port + n_workers - 1]should be reserved

Default: 9000

-aser_kg_dir

ASER KG directory

Default: “”

-concept_kg_dir

concept KG directory

Default: “”

-concept_method

Possible choices: probase, seed

the method to do conceptualization, using probase or seeds

Default: “probase”

-probase_path

the file_path to probase .txt file,which is available at https://concept.research.microsoft.com/Home/Download

Default: “”

-concept_topk

how many top conceptualized eventualities are kept

Default: 5

-log_path

Logging path of server output

Default: “./.server.log”

ASER client

class aser.client.ASERClient(ip='localhost', port=8000, port_out=8001, timeout=-1)[source]

Bases: object

A client object of ASER

Parameters:
  • ip (str) – ip address of the server

  • port (int) – port for push request from a client to the server

  • port_out (int) – port for Subscribe return data from the server to a server

  • timeout (float) – client receiver timeout (milliseconds), -1 means no timeout

close()[source]

Close the client safely

conceptualize_eventuality(eventuality)[source]

Conceptualize an eventuality by sending a request to ASERServer

Parameters:

eventuality (aser.eventuality.Eventuality) – an eventuality

Returns:

a list of (conceptualized eventuality, score) pair

Return type:

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

exact_match_concept(data)[source]

Retrieve the extract match concept by sending a DB retrieval request

Parameters:

data (Union[aser.concept.ASERConcept, str]) – a concept or cid

Returns:

the exact matched concept or None

Return type:

Union[aser.concept.ASERConcept, None]

exact_match_eventuality(data)[source]

Retrieve the extract match eventuality by sending a DB retrieval request

Parameters:

data (Union[aser.eventuality.Eventuality, str]) – an eventuality or eid

Returns:

the exact matched eventuality or None

Return type:

Union[aser.eventuality.Eventuality, None]

extract_eventualities(data)[source]

Extract eventualities by sending a request to ASERServer

Parameters:

data (Union[str, List[Dict[str, object]]]) – a raw text or a parsed result of a paragraph

Returns:

the extracted eventualities

Return type:

List[List[aser.eventuality.Eventuality]]

extract_eventualities_and_relations(data)[source]

Extract both eventualities and relations by sending a request to ASERServer

Parameters:

data (List[Dict[str, object]]) – a raw text or the parsed result returned by corenlp

Returns:

the extracted eventualities and relations

Return type:

Tuple[Union[List[List[aser.eventuality.Eventuality]], List[List[Dict[str, object]]], List[aser.eventuality.Eventuality], List[Dict[str, object]]], Union[List[List[aser.relation.Relation]], List[List[Dict[str, object]]], List[aser.relation.Relation], List[Dict[str, object]]]]

extract_relations(data)[source]

Extract relations by sending a request to ASERServer

Parameters:

data (Union[str, Tuple[List[Dict[str, object]], List[List[aser.eventuality.Eventuality]]]]) – a raw text or a parsed result of a paragraph associated with extracted eventualities

Returns:

the extracted relations

Return type:

List[List[aser.relation.Relation]]

Fetch all related concepts of the given concept

Parameters:

data (Union[str, aser.concept.ASERConcept]) – the given concept or cid

Returns:

all related concepts associated with corresponding relations

Return type:

List[Tuple[aser.concept.ASERConcept, aser.relation.Relation]]

Fetch all related eventualities of the given eventuality

Parameters:

data (Union[str, aser.eventuality.Eventuality]) – the given eventuality or eid

Returns:

all related eventualities associated with corresponding relations

Return type:

List[Tuple[aser.eventuality.Eventuality, aser.relation.Relation]]

parse_text(text)[source]

Parse a raw text by sending a request to ASERServer

Parameters:

text (str) – a raw text

Returns:

the parsed result

Return type:

List[Dict[str, object]]

predict_concept_relation(concept1, concept2)[source]

Predict the relation between two conceptualized eventualities by sending a DB retrieval request

Parameters:
Returns:

the relation stored in concept KG

Return type:

aser.relation.Relation

predict_eventuality_relation(eventuality1, eventuality2)[source]

Predict the relation between two eventualities by sending a DB retrieval request

Parameters:
Returns:

the relation stored in KG

Return type:

aser.relation.Relation