Metadata-Version: 2.4
Name: qe-refi-qda
Version: 0.1.2.9001
Summary: REFI-QDA projects (.qdpx from NVivo, ATLAS.ti, MAXQDA, QualCoder) as utterance × code tables
Author-email: Cody L Marquart <cody.marquart@wisc.edu>
License-Expression: MIT
Project-URL: Repository, https://gitlab.com/epistemic-analytics/qe-packages/refi-qda
Keywords: refi-qda,qdpx,nvivo,atlas.ti,maxqda,qualcoder,qualitative,ena
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Text Processing
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: pandas
Requires-Dist: pandas; extra == "pandas"
Provides-Extra: test
Requires-Dist: pytest; extra == "test"
Dynamic: license-file

# qe-refi-qda

Reads REFI-QDA projects (`.qdpx`, exported by NVivo, ATLAS.ti, MAXQDA,
QualCoder and others) into the table ENA works on: one row per utterance,
a 0/1 column per code. A port of the JavaScript package
[`@qe-libs/refi-qda`](../README.md): the same functions, the same output
byte for byte, tested on the same fixtures. Pure Python, no dependencies.

```bash
pip install qe-refi-qda --extra-index-url https://qe-libs.org/py/simple/
```

Then `import refi_qda`. Releases are on [qe-libs.org](https://qe-libs.org/py/)
(the PEP 503 index at `py/simple/`; dev builds of every push to `main` at
`py/dev/simple/`), published by cranqe.

## Use

```python
from refi_qda import to_csv

r = to_csv("project.qdpx", coder="any")
r.csv          # CSV text
r.fields       # column names
r.rows         # one list per row
r.report       # counts, coders, notes, skipped sources
r.coders       # the project's coders by name
```

`to_csv` and `read_project` take a path, bytes, a bytes-like object or an
open binary file.

`coder` chooses whose coding becomes the code columns, for projects coded
by more than one person (see `coders_of`):

| `coder` | Rows | A line is 1 for a code when… |
|---|---|---|
| `'any'` (default) | one per utterance | any coder coded it |
| `'all'` | one per utterance | every coder coded it |
| `'each'` | one per utterance per coder, with a `Coder` column | that row's coder coded it |
| `'columns'` | one per utterance; each code once per coder, `Code [Coder A]` | that column's coder coded it |
| a coder's name or GUID | one per utterance | that coder coded it |

`unit="sentence"` makes each sentence a row (a `Sentence` column follows
`Line`); `lines="all"` keeps lines without a `Speaker:` prefix, with the
previous speaker; `min_overlap=2` ignores spans that reach two characters or
fewer into a row. They are the JS library's `unit`, `lines` and `minOverlap`,
with the same output. `unit` may also be a callable
`(text, start) -> [(start, end, text)]` that splits a line's text itself.

For pandas:

```python
from refi_qda import read_project, to_table

df = to_table(read_project("project.qdpx"), coder="each").to_pandas()
```

| Function | Returns |
|---|---|
| `read_project(data)` | `Project`: `name`, `users` (GUID → name), `codes` (`Code(guid, name, parent, codable, description, parent_guid)`), `sources` (text, variables, coded spans), `skipped` |
| `coders_of(project)` | `[Coder(guid, name, spans)]`: who coded something, and how many coded spans |
| `to_table(project, coder=, unit=, lines=, min_overlap=)` | `Table(fields, rows, report)`, with `.to_pandas()`; `report["codebook"]` is the hierarchy as `[{name, parent}]` per code column |
| `to_csv(data, coder=, unit=, lines=, min_overlap=)` | `CSVResult`: `csv`, `fields`, `rows`, `report`, `coders`, `text_column` |
| `write_csv(fields, rows)` | CSV text |

The XML inside a `.qdpx` is parsed with the standard library, with any
document type declaration refused: a REFI-QDA project declares no DTD or
entities, and refusing them rules out entity-expansion bombs and external
entity references from an untrusted file.

Errors are `QdaError`s with a `.code`: `not-zip`, `no-project`, `bad-xml`,
`no-coder`, `misaligned`, `no-sources`. Their messages are written for the
person importing.

The table's columns, how lines become rows, the codebook hierarchy in
`report["codebook"]`, and how coded positions are checked and read are
described in the [main README](../README.md).

## Develop

```bash
cd python
pip install -e '.[test]'
pytest
```

The tests use `../tests/fixtures/`, shared with the JavaScript tests.

## Release

The Python package releases on its own tag, apart from the npm package:

```bash
# set version = "X.Y.Z" in python/pyproject.toml, commit, then
git tag python/vX.Y.Z && git push origin python/vX.Y.Z
```

CI checks the tag against `python/pyproject.toml`, then cranqe builds the
wheel and sdist and publishes them to qe-libs.org. A bare `vX.Y.Z` tag
releases only the npm package.
