Skip to content

Commit

Permalink
v0.3.3 (#18)
Browse files Browse the repository at this point in the history
* Centrality
* Run Black formatter
  • Loading branch information
mikulatomas authored Feb 23, 2022
1 parent e0e186b commit a1905bc
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 5 deletions.
4 changes: 2 additions & 2 deletions fcapsy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.3.2"
__version__ = "0.3.3"
__author__ = "Tomáš Mikula"
__email__ = "[email protected]"
__license__ = 'MIT license'
__license__ = "MIT license"
4 changes: 3 additions & 1 deletion fcapsy/basic_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ def basic_level_avg(
0.108
"""

return _basic_level(concept, cohesion, similarity, statistics.mean, statistics.mean, theta)
return _basic_level(
concept, cohesion, similarity, statistics.mean, statistics.mean, theta
)


def basic_level_min(
Expand Down
53 changes: 53 additions & 0 deletions fcapsy/centrality.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
__all__ = ["centrality"]


def centrality(item: str, concept: "concepts.lattices.Concept") -> float:
"""Calculates centrality of object/attribute in the given concept.
The object/attribute does not has to be from the extent/intent.
Args:
item (str): object or attribute name
concept (concepts.lattices.Concept)
Returns:
float: centrality
Example:
>>> from concepts import Context
>>> context = Context.fromstring('''
... |2 legs |nests |flies |raptor |
... sparrow | X | X | X | |
... lark | X | X | X | |
... penguin | X | | | |
... chicken | X | X | X | |
... vulture | X | | X | X |
... ''')
>>> birds = context.lattice.supremum
>>> birds.extent
('sparrow', 'lark', 'penguin', 'chicken', 'vulture')
>>> centrality("raptor", birds)
0.2
>>> centrality("flies", birds)
0.8
>>> centrality("2 legs", birds)
1.0
"""
context = concept.lattice._context

try:
instances_with_item = context.intension([item], raw=True)
Vector = type(concept._intent)
concept_core = concept._intent
except KeyError:
instances_with_item = context.extension([item], raw=True)
Vector = type(concept._extent)
concept_core = concept._extent

occurence_in_concept = Vector.fromint(instances_with_item & concept_core).count()

if not instances_with_item.count():
return 0.0

return (occurence_in_concept / instances_with_item.count()) * (
occurence_in_concept / concept._extent.count()
)
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
long_description=pathlib.Path("README.md").read_text(encoding="utf-8"),
long_description_content_type="text/markdown",
classifiers=[
'Development Status :: 3 - Alpha',
"Development Status :: 3 - Alpha",
"Intended Audience :: Science/Research",
'Intended Audience :: Developers',
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Programming Language :: Python :: 3",
Expand Down

0 comments on commit a1905bc

Please sign in to comment.