Skip to content

Commit

Permalink
Merge pull request #16 from PharmCat/dev
Browse files Browse the repository at this point in the history
spss labels from question or description
  • Loading branch information
PharmCat committed Mar 24, 2023
2 parents 07a23d1 + ec1ab80 commit a9b9a30
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ODMXMLTools"
uuid = "2456a17b-6ca2-4f51-9342-f0287e829718"
authors = ["PharmCat <[email protected]>"]
version = "0.6.0"
version = "0.6.1"

[deps]

Expand Down
41 changes: 38 additions & 3 deletions src/spss.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,57 @@ function Base.show(io::IO, spssc::SPSSValueLabels)
print(io, ".")
end

function getTTcontent(node, lang::String)
tt = findelements(node, :TranslatedText)
li = findfirst(x-> attribute(x, :lang) == lang, tt)
if isnothing(li)
return content(first(tt))
else
return attribute(df[i], variable) => content(tt[li])
end
end
function getTTcontent(node, ::Nothing)
tt = findelement(node, :TranslatedText)
return content(tt)
end

"""
spss_form_variable_labels(mdb, form; variable = :OID, labels = :Name)
spss_form_variable_labels(mdb, form; variable = :OID, labels = :Name, source = :attr, lang = nothing)
SPSS command to set variable labels.
`variable` - varable names attribute, `OID` by default.
`labels` - labels names attribute, `Name` by default.
If `source` == `:Question` - try to get description from `TranslatedText` of `Question` element, if there is no `Question` element - get from attribute `labels`.
If `source` == `:Description` - try to get description from `TranslatedText` of `Description` element.
"""
function spss_form_variable_labels(mdb, form; variable = :OID, labels = :Name)
function spss_form_variable_labels(mdb, form; variable = :OID, labels = :Name, source = :attr, lang = nothing)
df = itemformdefcontent_(mdb, form; optional = true)
v = Vector{Pair}(undef, length(df))
for i = 1:size(df, 1)
v[i] = attribute(df[i], variable) => attribute(df[i], labels)
if source == :attr
v[i] = attribute(df[i], variable) => attribute(df[i], labels)
elseif source == :Question
q = findelement(df[i], :Question)
if isnothing(q)
v[i] = attribute(df[i], variable) => attribute(df[i], labels)
else
v[i] = attribute(df[i], variable) => getTTcontent(q, lang)
end
elseif source == :Description
q = findelement(df[i], :Description)
if isnothing(q)
v[i] = attribute(df[i], variable) => attribute(df[i], labels)
else
v[i] = attribute(df[i], variable) => getTTcontent(q, lang)
end
else
v[i] = attribute(df[i], variable) => attribute(df[i], labels)
end
end
SPSSVariableLabels(v)
end
Expand Down

2 comments on commit a9b9a30

@PharmCat
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/80329

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.6.1 -m "<description of version>" a9b9a30097362b5e6e82e5134763f48e3e130a68
git push origin v0.6.1

Please sign in to comment.