cognipy.ontology¶
-
class
cognipy.ontology.
ABoxBatch
[source]¶ Bases:
object
A class used to create batch for A-Box manipulations on the ontology
-
delete
(onto)[source]¶ Deletes the current A-Box from the specific ontology
- Args:
onto(Ontogy): ontology to be modified
-
delete_instance
(inst)[source]¶ the instance to be deleted. Used only if delete is called
- Args:
inst(str): instance name
-
different_from
(inst, inst2)[source]¶ [inst] is not [inst2]. different-from relationship.
- Args:
inst,inst2(str): instance names
-
has_type
(inst, cls)[source]¶ [inst] is [cls]. has-type relationship.
- Args:
inst(str): instance name cls(str): concept name
-
insert
(onto)[source]¶ Inserts the current A-Box into the specific ontology
- Args:
onto(Ontogy): ontology to be modified
-
relates
(inst, prop, inst2)[source]¶ [inst] [prop] [inst2]. object relationship.
- Args:
inst,inst2(str): instance names prop(str): property name
-
-
cognipy.ontology.
CQL
(cql, ns='http://www.cognitum.eu/onto#')[source]¶ Converts CQL query into pure SPARQL by replacing CNL names into their IRI representations Args:
cql (str): cql string ns (str): namespace for CNL names into IRI expansion
-
class
cognipy.ontology.
Ontology
(source, arg, verbose=False, evaluator=None, graph_attribute_formatter=<function default_graph_attribute_formatter>, stop_on_error=True)[source]¶ Bases:
object
A class used to represent an ontology. This is the main entry point for the cognipy package. You can create many ontology objects and use them at the same time.
- Args:
- source (str):
‘cnl/file’ - local cnl file *.encnl ‘cnl/string’ - arg is a string ontology in a cnl format ‘rdf/uri’ - uri to OWL/RDF or RDF/XML file ‘rdf/string’ - arf is a string ontology in OWL/RDF or RDF/XML format
arg (str): path/string/uri verbose (bool): should the content of the ontology be displayed evaluator (function): a function that is used to evaluate string values within
the ontology that are embrased with backquotes i.e.:…. It enables encoding complex structures within the ontology. Default = None - no backqueted string evaluation is performed.
- graph_attribute_formatter (function)a function that is used to format
an attribute value when diagram is rendered
- stop_on_error(bool): if True (default) the method with throw an error if any
occured during the ontology loading process.
-
autocomplete
(str)[source]¶ Gives the autocompletion lists for a given string
- Args:
cnl (str): the partially defined cnl expression
- Returns:
List[str]: autocompletions
-
create_graph
(layout='hierarchical', show={'attributes', 'relations', 'subsumptions', 'types'}, include={}, exclude={}, constrains=[], format='svg', filename=None, fontname=None, fontsize=11)[source]¶ Creates the ontology diagram as an image
- Args:
layout(str): type of layout (one of: “hierarchical”(default), “force directed”) show(set(str)): one or more of strings {“subsumptions”,”types”,”relations”,”attributes”} include(set(str)): one or more names of entities that must be included (even if show argument says no) exclude(set(str)): one or more names of entities that must be excluded (even if show argument says yes) constrains(list(str)): one or more complex concept expressions that constrain the list of instances to be displayed
this allows to create graphs that are focusing on specific instance. Multiple constrains are joined using OR expression
format(str): format of the output image(one of: “svg”(default) ,”png”) filename(str): if None then output is returned, otherwize the output is written under the filename on the disk fontname(str): if None then default font is used, otherwize the fontname is the name of the typeface to be used fontsize(int): size of the font
-
delete_abox_cnl
(cnl)[source]¶ Deletes the specified knowledge from the A-Box ontology Only A-Box is accepted here. The exception will be thrown if T-Box is given
- Args:
cnl (str): the cnl string
-
delete_abox_instance
(inst)[source]¶ Deletes the specified instance from the A-Box of the ontology including all the connections it has to other instances and concepts. If the instance is involved in the T-Box definition the exception will be thrown.
- Args:
inst (str): the cnl name of the instance.
-
draw_graph
(layout='hierarchical', show={'attributes', 'relations', 'subsumptions', 'types'}, include={}, exclude={}, constrains=[], fontname=None, fontsize=11)[source]¶ Draws the ontology
- Args:
layout(str): type of layout (one of: “hierarchical”(default), “force directed”) show(set(str)): one or more of strings {“subsumptions”,”types”,”relations”,”attributes”} include(set(str)): one or more names of entities that must be included (even if show argument says no) exclude(set(str)): one or more names of entities that must be excluded (even if show argument says yes) constrains(list(str)): one or more complex concept expressions that constrain the list of instances to be displayed
this allows to create graphs that are focusing on specific instance. Multiple constrains are joined using OR expression
fontname(str): if None then default font is used, otherwize the fontname is the name of the typeface to be used fontsize(int): size of the font
-
highlight
(cnl)[source]¶ Gives the Markdown of the given cnl
- Args:
cnl (str): the cnl string
- Returns:
str: highlighted cnl string
-
insert_abox_cnl
(cnl)[source]¶ Inserts new knowledge into the ontology. Only A-Box is accepted here.
- Args:
cnl (str): the cnl string
-
instances_of
(cnl, direct=False)[source]¶ Get list of all the instances of the given concept specification
- Args:
cnl (str): the cnl expression that evaluates to the concept definition direct (bool): if True, only the direct instances of the given concept
specification will be returned
- Returns:
List of all the instances of the given concept expression
-
select_instances_of
(cnl)[source]¶ Get all the instances of the given concept specification
- Args:
cnl (str): the cnl expression that evaluates to the concept definition
- Returns:
Pandas DataFrame containing all the instances of the given concept expression together with all their attributes and relations
-
sparql_query
(query, asCNL=True, column_names=None)[source]¶ Executes the SPARQL query
- Args:
query: the SPARQL query. YOu can directly use prefixes like: [rdf:,rdfs,owl:] asCNL : should the result names be automatically converted back to their CNL representation (default)
of they should remain being rdf identifiers.
column_names : (default=None). List of column names for the returned dataframe. If None, the names of the variables are used.
- Returns:
Pandas DataFrame containing all the results of the query
-
sparql_query_for_instances
(cnl)[source]¶ Converts CNL concept definition into corresponding SPARQL query
- Args:
cnl (str): the cnl expression that evaluates to the concept definition
- Returns:
str: SPARQL query
-
sub_concepts_of
(cnl, direct=False)[source]¶ Get all the sub-concepts of the given concept specification
- Args:
cnl (str): the cnl expression that evaluates to the concept definition
- Returns:
Pandas DataFrame containing all the sub-concepts of the given concept expression
-
cognipy.ontology.
basic_backquote_string_evaluator
(val)[source]¶ The basic evaluator for backquoted strings
-
cognipy.ontology.
basic_graph_attribute_formatter
(val)[source]¶ The basic method of graph-attribute formatting, taking into account basic collection types