Skip to content

Commit

Permalink
combined docstrings and code
Browse files Browse the repository at this point in the history
  • Loading branch information
cecoeco committed Sep 28, 2024
1 parent 448a288 commit f27245d
Show file tree
Hide file tree
Showing 4 changed files with 255 additions and 325 deletions.
129 changes: 118 additions & 11 deletions src/checklist.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
include("checklist_docstrings.jl")

"""
$docstring_checklist_df
PRISMA.checklist_df()::DataFrame
returns a template PRISMA checklist as a `DataFrame`
## Returns
- `DataFrame`: the template dataframe
## Example
```jldoctest
julia> using PRISMA
julia> isa(checklist_df(), DataFrame)
true
```
"""
function checklist_df()::DataFrame
cols::Vector{String} = [
Expand Down Expand Up @@ -425,7 +439,47 @@ function complete_dataframe(paper::AbstractString)::DataFrame
end

"""
$docstring_checklist
PRISMA.checklist(paper::AbstractString)::Checklist
PRISMA.checklist(bytes::Vector{UInt8})::Checklist
Returns a completed PRISMA checklist as the type `Checklist`. The `Checklist`
type includes a completed checklist as a `DataFrame` and the metadata of the
paper as a `OrderedDict`. The `paper` argument can be a path to a pdf file or
an array of bytes. This function uses the C++ library `Poppler` via `Poppler_jll`
to parse the pdf and the natural language processing functionality in Julia via
[`Transformers.jl`](https://github.com/chengchingwen/Transformers.jl) to
find items from the checklist in the paper and populate the
`Comments or location in manuscript` and `Yes/No/NA` columns in the `DataFrame`
from `checklist_df()`.
The following metadata is parsed from the pdf file and stored in the `OrderedDict` as:
- `"title"`: the title of the paper
- `"subject"`: the subject of the paper
- `"author"`: the author of the paper
- `"creator"`: the creator of the paper
- `"producer"`: the producer of the paper
- `"creation date"`: the date the paper was created
- `"modification date"`: the date the paper was last modified
- `"pages"`: the number of pages in the paper
- `"paper size"`: the size of the paper
- `"paper rotation"`: the rotation of the paper
- `"file size"`: the size of the pdf file
- `"optimized"`: whether the pdf was optimized
- `"pdf version"`: the version of the pdf
All keys and values in the dictionary ar eof type `String`.
If the parsing fails the value will be an empty string.
## Arguments
- `paper::AbstractString`: a path to a pdf file as a string
- `bytes::Vector{UInt8}`: the pdf data as an array of bytes
## Returns
- `Checklist`: a completed checklist with the paper's metadata
"""
function checklist(paper::AbstractString)::Checklist
return Checklist(
Expand Down Expand Up @@ -477,22 +531,75 @@ function Base.show(io::IO, ::MIME"text/csv", cl::Checklist)::Nothing
end

"""
$docstring_checklist_read
checklist_read(fn::AbstractString)::DataFrame
reads the template data to a `DataFrame`
## Arguments
- `fn::AbstractString`: the name of the file to read
## Returns
- `DataFrame`: the template dataframe
## Example
```jldoctest
julia> using PRISMA
julia> checklist_template()
"checklist.csv"
julia> isa(checklist_read("checklist.csv"), DataFrame)
true
```
"""
function checklist_read(fn::AbstractString="checklist.csv")::DataFrame
return CSV.read(fn, DataFrame)
end

"""
$docstring_checklist_save
checklist_save(out::Any, cl::Checklist)
checklist_save(out::Any, df::DataFrame)
saves a `Checklist` as a CSV.
## Arguments
- `out::Any`: Accepts the same types as [`CSV.write`](https://csv.juliadata.org/stable/writing.html#CSV.write)
- `cl::Checklist`: the checklist to save
- `df::DataFrame`: the dataframe to save
"""
function checklist_save(fn::AbstractString, cl::Checklist)
return CSV.write(fn, cl.dataframe)
function checklist_save(out::Any, cl::Checklist)
return CSV.write(out, cl.dataframe)
end

function checklist_save(out::Any, df::DataFrame)
return CSV.write(out, df)
end

"""
$docstring_checklist_template
checklist_template(out::Any="checklist.csv")
saves a template checklist `DataFrame` as a CSV.
## Arguments
- `out::Any`: Accepts the same types as [`CSV.write`](https://csv.juliadata.org/stable/writing.html#CSV.write)
## Example
```jldoctest
julia> using PRISMA
julia> checklist_template()
"checklist.csv"
```
"""
function checklist_template(fn::AbstractString="checklist.csv")
return CSV.write(fn, checklist_df())
function checklist_template(out::Any="checklist.csv")
return CSV.write(out, checklist_df())
end
127 changes: 0 additions & 127 deletions src/checklist_docstrings.jl

This file was deleted.

Loading

0 comments on commit f27245d

Please sign in to comment.