pyvalues 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pyvalues-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 ValueEval
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,49 @@
1
+ Metadata-Version: 2.4
2
+ Name: pyvalues
3
+ Version: 0.1.0
4
+ Summary: Python library for processing, evaluating, and visualizing (Schwartz) human value scores
5
+ License: MIT License
6
+
7
+ Copyright (c) 2025 ValueEval
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in all
17
+ copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ SOFTWARE.
26
+ License-File: LICENSE
27
+ Keywords: ai,artificial intelligence,classification,human values,schwartz values,vallueeval
28
+ Author: Johannes Kiesel
29
+ Maintainer: Johannes Kiesel
30
+ Maintainer-email: Johannes.Kiesel@gesis.org
31
+ Requires-Python: >=3.11,<3.15
32
+ Classifier: License :: Other/Proprietary License
33
+ Classifier: Programming Language :: Python :: 3
34
+ Classifier: Programming Language :: Python :: 3.11
35
+ Classifier: Programming Language :: Python :: 3.12
36
+ Classifier: Programming Language :: Python :: 3.13
37
+ Classifier: Programming Language :: Python :: 3.14
38
+ Requires-Dist: matplotlib (>=3.10.8,<4.0.0)
39
+ Requires-Dist: numpy (>=2.4.1,<3.0.0)
40
+ Requires-Dist: pandas (>=2.3.3,<3.0.0)
41
+ Requires-Dist: pydantic (>=2.12.3,<3.0.0)
42
+ Project-URL: Issues, https://github.com/ValueEval/pyvalues/issues
43
+ Project-URL: Source, https://github.com/ValueEval/pyvalues
44
+ Description-Content-Type: text/markdown
45
+
46
+ # pyvalues
47
+
48
+ Python library for processing, evaluating, and visualizing (Schwartz) human value scores
49
+
@@ -0,0 +1,3 @@
1
+ # pyvalues
2
+
3
+ Python library for processing, evaluating, and visualizing (Schwartz) human value scores
@@ -0,0 +1,36 @@
1
+ [project]
2
+ name = "pyvalues"
3
+ version = "0.1.0"
4
+ description = "Python library for processing, evaluating, and visualizing (Schwartz) human value scores"
5
+ requires-python = ">=3.11,<3.15"
6
+ readme = "README.md"
7
+ dependencies = [
8
+ "pandas (>=2.3.3,<3.0.0)",
9
+ "pydantic (>=2.12.3,<3.0.0)",
10
+ "matplotlib (>=3.10.8,<4.0.0)",
11
+ "numpy (>=2.4.1,<3.0.0)",
12
+ ]
13
+ license = { file = "LICENSE" }
14
+ keywords = [ "ai", "artificial intelligence", "classification", "human values", "schwartz values", "vallueeval" ]
15
+ authors = [
16
+ {name = "Johannes Kiesel"},
17
+ ]
18
+ maintainers = [
19
+ {name = "Johannes Kiesel",email = "Johannes.Kiesel@gesis.org"}
20
+ ]
21
+
22
+ [project.urls]
23
+ "Source" = "https://github.com/ValueEval/pyvalues"
24
+ "Issues" = "https://github.com/ValueEval/pyvalues/issues"
25
+
26
+ [tool.poetry]
27
+ packages = [{include = "pyvalues", from = "src"}]
28
+
29
+ [tool.poetry.group.development]
30
+ optional = true
31
+ [tool.poetry.group.development.dependencies]
32
+ flake8 = "*"
33
+
34
+ [build-system]
35
+ requires = ["poetry-core>=2.0.0,<3.0.0"]
36
+ build-backend = "poetry.core.masonry.api"
@@ -0,0 +1,35 @@
1
+ from .values import (
2
+ RefinedValues,
3
+ RefinedCoarseValues,
4
+ OriginalValues,
5
+ RefinedValuesWithAttainment,
6
+ RefinedCoarseValuesWithAttainment,
7
+ OriginalValuesWithAttainment,
8
+ )
9
+ from .classifiers import (
10
+ RefinedValuesClassifier,
11
+ RefinedCoarseValuesClassifier,
12
+ OriginalValuesClassifier,
13
+ RefinedValuesWithAttainmentClassifier,
14
+ RefinedCoarseValuesWithAttainmentClassifier,
15
+ OriginalValuesWithAttainmentClassifier
16
+ )
17
+
18
+ __all__ = [
19
+ "RefinedValues",
20
+ "RefinedCoarseValues",
21
+ "OriginalValues",
22
+ "RefinedValuesWithAttainment",
23
+ "RefinedCoarseValuesWithAttainment",
24
+ "OriginalValuesWithAttainment",
25
+ "RefinedValuesClassifier",
26
+ "RefinedCoarseValuesClassifier",
27
+ "OriginalValuesClassifier",
28
+ "RefinedValuesWithAttainmentClassifier",
29
+ "RefinedCoarseValuesWithAttainmentClassifier",
30
+ "OriginalValuesWithAttainmentClassifier",
31
+ ]
32
+
33
+ from importlib import metadata
34
+
35
+ __version__ = metadata.version(__package__) # type: ignore
@@ -0,0 +1,109 @@
1
+ from abc import ABC, abstractmethod
2
+
3
+ from .values import (
4
+ RefinedValues,
5
+ RefinedCoarseValues,
6
+ OriginalValues,
7
+ RefinedValuesWithAttainment,
8
+ RefinedCoarseValuesWithAttainment,
9
+ OriginalValuesWithAttainment
10
+ )
11
+
12
+
13
+ class OriginalValuesClassifier(ABC):
14
+ """ Classifier for the ten values from Schwartz original system.
15
+ """
16
+
17
+ @abstractmethod
18
+ def classify_original_values(self, text: str, language: str = "EN") -> OriginalValues:
19
+ pass
20
+
21
+
22
+ class RefinedCoarseValuesClassifier(OriginalValuesClassifier):
23
+ """ Classifier for the the twelve values from Schwartz refined system (19 values)
24
+ when combining values with same name prefix.
25
+ """
26
+
27
+ def classify_original_values(self, text: str, language: str = "EN") -> OriginalValues:
28
+ return self.classify_refined_coarse_values(text=text, language=language).original_values()
29
+
30
+ @abstractmethod
31
+ def classify_refined_coarse_values(self, text: str, language: str = "EN") -> RefinedCoarseValues:
32
+ pass
33
+
34
+
35
+ class RefinedValuesClassifier(RefinedCoarseValuesClassifier):
36
+ """ Classifier for the 19 values from Schwartz refined system.
37
+ """
38
+
39
+ def classify_refined_coarse_values(self, text: str, language: str = "EN") -> RefinedCoarseValues:
40
+ return self.classify_refined_values(text=text, language=language).coarse_values()
41
+
42
+ @abstractmethod
43
+ def classify_refined_values(self, text: str, language: str = "EN") -> RefinedValues:
44
+ pass
45
+
46
+
47
+ class OriginalValuesWithAttainmentClassifier(OriginalValuesClassifier):
48
+ """ Classifier for the ten values from Schwartz original system with attainment.
49
+ """
50
+
51
+ def classify_original_values(self, text: str, language: str = "EN") -> OriginalValues:
52
+ return self.classify_original_values_with_attainment(text=text, language=language).without_attainment()
53
+
54
+ @abstractmethod
55
+ def classify_original_values_with_attainment(
56
+ self,
57
+ text: str,
58
+ language: str = "EN"
59
+ ) -> OriginalValuesWithAttainment:
60
+ pass
61
+
62
+
63
+ class RefinedCoarseValuesWithAttainmentClassifier(
64
+ OriginalValuesWithAttainmentClassifier, RefinedCoarseValuesClassifier):
65
+ """ Classifier for the the twelve values from Schwartz refined system (19 values)
66
+ when combining values with same name prefix and with attainment.
67
+ """
68
+
69
+ def classify_refined_coarse_values(
70
+ self, text: str, language: str = "EN"
71
+ ) -> RefinedCoarseValues:
72
+ return self.classify_refined_coarse_values_with_attainment(
73
+ text=text, language=language).without_attainment()
74
+
75
+ def classify_original_values_with_attainment(
76
+ self, text: str, language: str = "EN"
77
+ ) -> OriginalValuesWithAttainment:
78
+ return self.classify_refined_coarse_values_with_attainment(
79
+ text=text, language=language).original_values()
80
+
81
+ @abstractmethod
82
+ def classify_refined_coarse_values_with_attainment(
83
+ self, text: str, language: str = "EN"
84
+ ) -> RefinedCoarseValuesWithAttainment:
85
+ pass
86
+
87
+
88
+ class RefinedValuesWithAttainmentClassifier(
89
+ RefinedCoarseValuesWithAttainmentClassifier, RefinedValuesClassifier):
90
+ """ Classifier for the 19 values from Schwartz refined system with attainment.
91
+ """
92
+
93
+ def classify_refined_values(
94
+ self, text: str, language: str = "EN"
95
+ ) -> RefinedValues:
96
+ return self.classify_refined_values_with_attainment(
97
+ text=text, language=language).without_attainment()
98
+
99
+ def classify_refined_coarse_values_with_attainment(
100
+ self, text: str, language: str = "EN"
101
+ ) -> RefinedCoarseValuesWithAttainment:
102
+ return self.classify_refined_values_with_attainment(
103
+ text=text, language=language).coarse_values()
104
+
105
+ @abstractmethod
106
+ def classify_refined_values_with_attainment(
107
+ self, text: str, language: str = "EN"
108
+ ) -> RefinedValuesWithAttainment:
109
+ pass
@@ -0,0 +1,151 @@
1
+ from matplotlib.lines import Line2D
2
+ import matplotlib.pyplot as plt
3
+ import numpy as np
4
+
5
+ from matplotlib.patches import RegularPolygon
6
+ from matplotlib.path import Path
7
+ from matplotlib.projections import register_projection
8
+ from matplotlib.projections.polar import PolarAxes
9
+ from matplotlib.spines import Spine
10
+ from matplotlib.transforms import Affine2D
11
+
12
+
13
+ def plot_radar(
14
+ dim_names: list[str],
15
+ valuess: list[list[float]],
16
+ labels: list[str | None] = [None],
17
+ linecolors: list[str] = [
18
+ "#e41a1c",
19
+ "#377eb8",
20
+ "#4daf4a",
21
+ "#984ea3",
22
+ "#ff7f00",
23
+ "#ffff33",
24
+ "#a65628",
25
+ "#f781bf",
26
+ "#999999"
27
+ ],
28
+ fillcolors: list[str | None] = [None],
29
+ fillalphas: list[float] = [0.25]
30
+ ):
31
+ theta = radar_factory(len(dim_names))
32
+ fig, ax = plt.subplots(subplot_kw=dict(projection="radar"))
33
+ ax.set_ylim(0, 1)
34
+ ax.set_rgrids([0.25, 0.50, 0.75], fontsize="small") # type: ignore
35
+ ax.set_varlabels(dim_names) # type: ignore
36
+ has_label = False
37
+ for i in range(len(valuess)):
38
+ label = labels[i % len(labels)]
39
+ ax.plot(theta, list(valuess[i]),
40
+ color=linecolors[i % len(linecolors)],
41
+ label=label)
42
+ if fillcolors[i % len(fillcolors)] is not None:
43
+ ax.fill(theta, list(valuess[i]),
44
+ facecolor=fillcolors[i % len(fillcolors)],
45
+ alpha=fillalphas[i % len(fillalphas)],
46
+ label='_nolegend_')
47
+ if label is not None:
48
+ has_label = True
49
+ if has_label:
50
+ fig.legend(loc="upper right", labelspacing=0.1, fontsize='small')
51
+ return plt
52
+
53
+
54
+ def radar_factory(num_vars):
55
+ """
56
+ Create a radar chart with `num_vars` Axes.
57
+
58
+ This function creates a RadarAxes projection and registers it.
59
+
60
+ Based on
61
+ https://matplotlib.org/stable/gallery/specialty_plots/radar_chart.html
62
+
63
+ Parameters
64
+ ----------
65
+ num_vars : int
66
+ Number of variables for radar chart.
67
+ """
68
+ # calculate evenly-spaced axis angles
69
+ theta = np.linspace(2 * np.pi, 0, num_vars, endpoint=False)
70
+
71
+ class RadarTransform(PolarAxes.PolarTransform):
72
+
73
+ def transform_path_non_affine(self, path):
74
+ # Paths with non-unit interpolation steps correspond to gridlines,
75
+ # in which case we force interpolation (to defeat PolarTransform's
76
+ # autoconversion to circular arcs).
77
+ if path._interpolation_steps > 1:
78
+ path = path.interpolated(num_vars)
79
+ return Path(self.transform(path.vertices), path.codes)
80
+
81
+ class RadarAxes(PolarAxes):
82
+
83
+ name = 'radar'
84
+ PolarTransform = RadarTransform
85
+
86
+ def __init__(self, *args, **kwargs):
87
+ super().__init__(*args, **kwargs)
88
+ # rotate plot such that the first axis is at the top
89
+ self.set_theta_zero_location('N')
90
+
91
+ def fill(self, *args, closed=True, **kwargs):
92
+ """Override fill so that line is closed by default"""
93
+ return super().fill(closed=closed, *args, **kwargs)
94
+
95
+ def plot(self, *args, **kwargs) -> list[Line2D]:
96
+ """Override plot so that line is closed by default"""
97
+ lines = super().plot(*args, **kwargs)
98
+ for line in lines:
99
+ self._close_line(line)
100
+ return lines
101
+
102
+ def _close_line(self, line):
103
+ x, y = line.get_data()
104
+ # FIXME: markers at x[0], y[0] get doubled-up
105
+ if x[0] != x[-1]:
106
+ x = np.append(x, x[0])
107
+ y = np.append(y, y[0])
108
+ line.set_data(x, y)
109
+
110
+ def set_varlabels(self, labels):
111
+ self.set_thetagrids(np.degrees(theta), fmt="")
112
+ for i in range(len(labels)):
113
+ horizontal_alignment = None
114
+ if i == 0 or i == len(labels) / 2:
115
+ horizontal_alignment = "center"
116
+ elif i < len(labels) / 2:
117
+ horizontal_alignment = "left"
118
+ else:
119
+ horizontal_alignment = "right"
120
+
121
+ vertical_alignment = None
122
+ if i == len(labels) / 4 or i == (len(labels) * 3 / 4):
123
+ vertical_alignment = "center"
124
+ elif i < len(labels) / 4 or i > (len(labels) * 3 / 4):
125
+ vertical_alignment = "bottom"
126
+ else:
127
+ vertical_alignment = "top"
128
+
129
+ self.text(theta[i], 1.025, labels[i], fontsize="small",
130
+ horizontalalignment=horizontal_alignment,
131
+ verticalalignment=vertical_alignment)
132
+
133
+ def _gen_axes_patch(self):
134
+ # The Axes patch must be centered at (0.5, 0.5) and of radius 0.5
135
+ # in axes coordinates.
136
+ return RegularPolygon((0.5, 0.5), num_vars,
137
+ radius=.5, edgecolor="k")
138
+
139
+ def _gen_axes_spines(self):
140
+ # spine_type must be 'left'/'right'/'top'/'bottom'/'circle'.
141
+ spine = Spine(axes=self,
142
+ spine_type='circle',
143
+ path=Path.unit_regular_polygon(num_vars))
144
+ # unit_regular_polygon gives a polygon of radius 1 centered at
145
+ # (0, 0) but we want a polygon of radius 0.5 centered at (0.5,
146
+ # 0.5) in axes coordinates.
147
+ spine.set_transform(Affine2D().scale(.5).translate(.5, .5) + self.transAxes)
148
+ return {'polar': spine}
149
+
150
+ register_projection(RadarAxes)
151
+ return theta