Reference
API reference for the functions exported by ParShift.
Parshift
Analysis of a conversation with Gibson's participation shifts.
The conversation is processed with process(),
which keeps the results in the annotation and stats attributes. These are
then used by the remaining methods to show, save and plot the results.
Attributes:
| Name | Type | Description |
|---|---|---|
annotation |
Participation shift codes of each turn, as returned by
|
|
stats |
Conditional probabilities, as returned by
|
Source code in parshift/oo_parshift.py
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 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 | |
__init__
__init__(
annotation: DataFrame | None = None,
stats: DataFrame | List[DataFrame] | None = None,
)
Create a Parshift object, optionally with existing results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
annotation
|
DataFrame | None
|
Participation shift codes of each turn, as returned by
|
None
|
stats
|
DataFrame | List[DataFrame] | None
|
Conditional probabilities, as returned by
|
None
|
Source code in parshift/oo_parshift.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
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
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 | |
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 the conversation, and determine their conditional probabilities.
The results are kept in the annotation and stats attributes; the
method returns nothing.
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_idortarget_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
|
{}
|
After processing:
Parshift.annotationis the data frame returned byannotate().Parshift.statsis the data frame returned bycond_probs()or, ifN > 1, a list with one such data frame for each of theNparts of the conversation (with approximately the same number of turns each).
Source code in parshift/oo_parshift.py
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 | |
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
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 | |
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
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 | |
annotate
annotate(conv_df: 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. In conversations with the reply_to_id column, the addressee of
a reply is the speaker of the replied utterance.
Only the 13 participation shifts defined by Gibson are assigned. For this purpose, the following turns are considered as addressed to the group, and a warning is issued:
- turns addressed to their own speaker (e.g., a speaker replying to themselves);
- in conversations with the
reply_to_idcolumn, turns replying to an utterance which is not in a previous turn (e.g., an utterance outside the data).
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
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 343 344 345 346 | |
cond_probs
cond_probs(pshift_codes: 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
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 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 | |
conv2turns
conv2turns(conv_df: 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
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 | |
frequency_treemap
frequency_treemap(
cond_probs_df: DataFrame, ax: Optional[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 where the treemap is drawn. If |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
ax |
Axes
|
Matplotlib axes with the participation shifts probabilities or frequency. |
Source code in parshift/plotting.py
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 90 91 92 93 | |
propensities
propensities(cond_probs_df: 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
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 | |
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., |
required |
Returns:
| Type | Description |
|---|---|
str
|
Participation shift class of the given participation shift code (either "Turn Receiving", "Turn Claiming", "Turn Usurping" or "Turn Continuing"). |
Source code in parshift/annotation.py
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 | |
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_idortarget_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
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 | |