pyknp_eventgraph.eventgraph

class pyknp_eventgraph.eventgraph.EventGraph[source]

Bases: pyknp_eventgraph.component.Component

EventGraph provides a high-level interface that facilitates NLP application development. The core concept of EventGraph is event, a language information unit that is closely related to predicate-argument structure but more application-oriented. Events are linked to each other based on their syntactic and semantic relations.

document: Document

A document on which this EventGraph is built.

classmethod build(blist)[source]

Build an EventGraph from language analysis by KNP.

Parameters

blist (List[BList]) – A list of bunsetsu lists, each of which is a result of analysis performed by KNP on a sentence.

Example:

from pyknp import KNP
from pyknp_eventgraph import EventGraph

# Parse a document.
document = ['彼女は海外勤務が長いので、英語がうまいに違いない。', '私はそう確信していた。']
knp = KNP()
blists = [knp.parse(sentence) for sentence in document]

# Build an EventGraph.
evg = EventGraph.build(blists)
Return type

EventGraph

classmethod load(f, binary=False)[source]

Deserialize an EventGraph.

Parameters
  • f (Union[TextIO, BinaryIO]) – A file descriptor.

  • binary (bool) – If true, deserialize an EventGraph using Python’s pickle utility. Otherwise, deserialize an EventGraph using Python’s json utility.

Example:

from pyknp_eventgraph import EventGraph

# Load an EventGraph serialized in a JSON format.
with open('evg.json', 'r') as f:
    evg = EventGraph.load(f, binary=False)

# Load an EventGraph serialized by Python's pickle utility.
with open('evg.pkl', 'rb') as f:
    evg = EventGraph.load(f, binary=True)

Caution

EventGraph deserialized from a JSON file loses several functionality. To keep full functionality, use Python’s pickle utility for serialization.

Return type

EventGraph

save(path, binary=False)[source]

Save this EventGraph.

Parameters
  • path (str) – An output file path.

  • binary (bool) – If true, serialize this EventGraph using Python’s pickle utility. Otherwise, serialize this EventGraph using Python’s json utility.

Caution

EventGraph deserialized from a JSON file loses several functionality. To keep full functionality, use Python’s pickle utility for serialization.

Return type

None

to_dict()[source]

Convert this object into a dictionary.

Return type

dict

to_string()[source]

Convert this object into a string.

Return type

str

property events

A list of events.

Return type

List[Event]

property relations

A list of relations.

Return type

List[Relation]

property sentences

A list of sentences.

Return type

List[Sentence]