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#
- 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 conceptend_offset (
int
) – End offset of the concepturi (
str
) – URI, or name, of the concept
- Returns
An initialized concept
- Return type
- 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
ofstr
- 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
ofstr
- 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
ofstr
- property annotations: List[eot.wowool.annotation.annotation.Annotation]#
- Returns
The tokens of the concept
- Return type
A
list
ofstr
- __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 conceptattributes
: 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
orstr
- 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
- 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
ofConcept
- __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
- Returns
A generator expression yielding concepts
- Return type
- 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#
See also the corresponding JSON schema.