Concept API for Python#

class eot.wowool.annotation.Concept#

Bases: eot.wowool.annotation.annotation.Annotation

Concept is a class that contains all the information of a concept

ConceptType#

alias of eot.wowool.annotation.annotation.Annotation

FilterType#

alias of Callable[[eot.wowool.annotation.concept.ConceptType], bool]

__init__(begin_offset: int, end_offset: int, uri: str)#

Initialize a Concept instance

Parameters
  • begin_offset (int) – Begin offset of the concept

  • end_offset (int) – End offset of the concept

  • uri (str) – URI, or name, of the concept

Returns

An initialized concept

Return type

Concept

property uri: str#
Returns

The URI, or name, of the concept

Type

str

property literal: str#
Returns

The literal representation of the concept

Return type

str

property literals: List[str]#
Returns

The literals of the concept

Return type

A list of str

property stem: str#
Returns

The stem representation of the concept

Type

str

property canonical: str#
Returns

The stem representation of the concept

Type

str

property stems: List[str]#
Returns

The stems of the concept

Return type

A list of str

property text#
Returns

A string representation of the concept

Return type

str

property tokens: List[eot.wowool.annotation.token.Token]#
Returns

The tokens of the concept

Return type

A list of str

property annotations: List[eot.wowool.annotation.annotation.Annotation]#
Returns

The tokens of the concept

Return type

A list of str

__getattr__(name: str) Union[None, str, eot.wowool.annotation.concept.Concept]#

Find an attribute or the first child instance of the concept with the given name. Some often used attributes are:

  • canonical: canonical representation (str) of the concept

  • attributes: attributes (dict) collected on the concept

For example:

# Find a child concept in this concept
person = concept.Person
# or print the attribute 'gender'
print(person.gender)
Parameters

name (str) – Attribute name

Returns

The first instance of the matching concept or the requested attribute value

Type

Concept or str

find_first(uri: str) Union[None, eot.wowool.annotation.concept.Concept]#

Find the first child instance of the concept with the given URI in this concept

For example:

# Find a child concept in the current concept
person = concept.find_first('Person'))
Parameters

uri (str) – URI, or name, of the concept

Returns

The first matching child instance of the given concept

Return type

Concept

find(uri: str) List[eot.wowool.annotation.concept.Concept]#

Find all child concepts with the given URI in this concept

For example:

# Find a child concept in the current concept
for person in concept.find('Person')):
    print(person)
Parameters

uri (str) – URI, or name, of the concept

Returns

The matching child instances of the given concept

Return type

A list of Concept

__getitem__(key)#
Returns

Attribute of the concept

Return type

str

rich() str#
Returns

A rich string representation of the concept

Return type

str

keys()#

This function is used to convert a concept object to a dictionary

{ **concept }
Returns

a list of the keys of the concept.

Return type

list(str)

to_json()#
Returns

A dictionary representing a JSON object of the concept

Return type

dict

static iter(object, filter: FilterType = <function _filter_pass_thru>, align: bool = True) Iterator[Concept]#

Iterate over the concepts in a document, an analysis, a sentence or a concept. For example:

document = analyzer("Hello from Antwerp, said John Smith.")
for concept in Concept.iter(document, lambda concept : concept.uri == "NP"):
    print(concept)
Parameters
  • object (Analysis, Sentence or Concept) – Object to iterate

  • filter (Callable accepting a Concept and returning a bool) – Predicate function to filter the concepts, callable that accepts a concept and returns True if the concept is considered a match

Returns

A generator expression yielding concepts

Return type

Concept

static next(sentence: List[eot.wowool.annotation.annotation.Annotation], object) eot.wowool.annotation.concept.Concept#

returns the next Concept

static prev(sentence: List[eot.wowool.annotation.annotation.Annotation], object) eot.wowool.annotation.concept.Concept#

returns the prev Concept

property begin_offset: int#
Returns

The begin offset of the annotation

Type

int

property end_offset: int#
Returns

The end offset of the annotation

Type

int

property index: int#
property is_concept: bool#
Returns

Whether the annotation is a Concept

Return type

bool

property is_sentence: bool#
Returns

Whether the annotation is a Sentence

Return type

bool

property is_token: bool#
Returns

Whether the annotation is a Token

Return type

bool

See also the corresponding JSON schema.