Reference
API reference for the functions exported by ParShift.
Parshift
Source code in parshift/oo_parshift.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
|
__init__
__init__(
annotation: pd.DataFrame | None = None,
stats: pd.DataFrame | List[pd.DataFrame] | None = None,
)
Parshift initialization
Source code in parshift/oo_parshift.py
19 20 21 22 23 24 25 26 27 |
|
get_propensities
get_propensities(filename: str | None = None) -> pd.DataFrame
Returns a data frame with the Participation Shift propensities.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str | None
|
Name of the file (csv) to save the propensities data frame. Default to |
None
|
Returns:
Type | Description |
---|---|
DataFrame
|
A Pandas |
Source code in parshift/oo_parshift.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
|
process
process(
filepath_or_buffer: FilePath | ReadCsvBuffer[bytes] | ReadCsvBuffer[str],
N: int = 1,
**kwargs: Any
)
Read a conversation file in CSV format, validate it, get Gibson's participation shift codes from turns in a conversation, determine the conditional probabilities for a sequence of participation shift codes and return a dict with parshift annotations and conditional probabilities.
The conversation file should have the following columns:
utterance_id
: ID of the message (int)speaker_id
: ID of the user sending the message (str)utterance
: The message itself (string)reply_to_id
ortarget_id
: The reply ID or the target ID (int)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath_or_buffer |
FilePath | ReadCsvBuffer[bytes] | ReadCsvBuffer[str]
|
Any valid string path to CSV file, as accepted by
Pandas |
required |
N |
int
|
Number of parts to split the conversation into. Default is 1 (all conversation).
|
1
|
**kwargs |
Any
|
Keyword parameters passed to Pandas
|
{}
|
- Parshift.annotation will be data frame equal as returned by
annotate()
. - Parshift.stats will be data frame equal as returned by
cond_probs()
.
Source code in parshift/oo_parshift.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
|
show_plot
show_plot(type: str = 'Pshift', filename: str | None = None)
Shows the frequency treemap plot returned by frequency_treemap()
Parameters:
Name | Type | Description | Default |
---|---|---|---|
type |
str
|
Column name to be used to plot the treemap, either |
'Pshift'
|
filename |
str | None
|
Name of the file to save the plot. Default to |
None
|
Source code in parshift/oo_parshift.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
|
show_stats
show_stats(filename: str | None = None)
Prints the stats returned by cond_probs()
Dataframe. If kwarg N (see process
) > 1, prints N data frames.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str | None
|
Name of the file (csv) to save the stats data frame. Default to |
None
|
Source code in parshift/oo_parshift.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
|
annotate
annotate(conv_df: pd.DataFrame) -> pd.DataFrame
Get Gibson's participation shift codes from turns in a conversation.
Sequences of messages from a speaker to the same addressee are considered to be in the same turn, and therefore will be assigned a single participation shift code.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
conv_df |
DataFrame
|
The conversation from where to obtain the participation shift codes. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
A data frame with the participation shift codes for each turn. |
Source code in parshift/annotation.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
|
cond_probs
cond_probs(pshift_codes: pd.DataFrame) -> pd.DataFrame
Determine the conditional probabilities for a sequence of participation shift codes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pshift_codes |
DataFrame
|
A sequence of participation shift code obtained with
|
required |
Returns:
Type | Description |
---|---|
DataFrame
|
A data frame containing the frequency, probability and conditional probabilities
(two) for each parshift code. This data frame is divided into two 'subgroups':
(1) those beginning with an undirected remark (A0-); and, (2) those beginning
with a directed one (AB-). The |
Source code in parshift/statistics.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
|
conv2turns
conv2turns(conv_df: pd.DataFrame) -> List[Dict[str, Any]]
Take a conversation data frame and group it into conversation turns.
A turn is a group of messages sent by the same user and addressed to the same target.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
conv_df |
DataFrame
|
The conversation from where to obtain the conversation turns. |
required |
Returns:
Type | Description |
---|---|
List[Dict[str, Any]]
|
A list of dictionaries, each representing a conversation turn. |
Source code in parshift/annotation.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
|
frequency_treemap
frequency_treemap(
cond_probs_df: pd.DataFrame,
ax: Optional[matplotlib.axes.Axes] = None,
type: str = "Pshift",
) -> matplotlib.axes.Axes
Get a matplotlib axes object displaying the conditional probabilities or frequencies.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cond_probs_df |
DataFrame
|
Dataframe with information about the participation shift
conditional probabilities. This data frame can be obtained with
|
required |
type |
str
|
Column name to be used to plot the treemap, either |
'Pshift'
|
ax |
Optional[Axes]
|
Matplotlib axes with the treemap plot. |
None
|
Returns:
Name | Type | Description |
---|---|---|
ax |
Axes
|
Matplotlib axes with the participation shifts probabilities or frequency. |
Source code in parshift/plotting.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
|
propensities
propensities(cond_probs_df: pd.DataFrame) -> pd.DataFrame
Determine the propensities from a conditional probabilities data frame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cond_probs_df |
DataFrame
|
A data frame with statistics obtained with
|
required |
Returns:
Type | Description |
---|---|
DataFrame
|
A data frame containing the propensities proposed by Gibson. |
Source code in parshift/statistics.py
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
|
pshift_class
pshift_class(pshift: str) -> str
Returns the participation shift class given a participation shift code.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pshift |
str
|
Participation shift code (e.g A0-XA). |
required |
Returns:
Type | Description |
---|---|
str
|
Participation shift classe in given the participation shift code (either "Turn Receiving", "Turn Claiming", "Turn Usurping" or "Turn Continuing"). |
Source code in parshift/annotation.py
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 |
|
read_ccsv
read_ccsv(
filepath_or_buffer: FilePath | ReadCsvBuffer[bytes] | ReadCsvBuffer[str],
**kwargs: Any
) -> pd.DataFrame
Read a conversation file in CSV format, validate it and return a data frame.
The conversation file should have the following columns:
utterance_id
: ID of the message (int)speaker_id
: ID of the user sending the message (str)utterance
: The message itself (string)reply_to_id
ortarget_id
: The reply ID or the target ID (int)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath_or_buffer |
FilePath | ReadCsvBuffer[bytes] | ReadCsvBuffer[str]
|
Any valid string path to CSV file, as accepted by
Pandas |
required |
**kwargs |
Any
|
Keyword parameters passed to Pandas
|
{}
|
Returns:
Type | Description |
---|---|
DataFrame
|
A Pandas |
Source code in parshift/annotation.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
|