Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce function to concatenate value to field #277

Open
TobiasNx opened this issue Jan 3, 2023 · 7 comments
Open

Introduce function to concatenate value to field #277

TobiasNx opened this issue Jan 3, 2023 · 7 comments

Comments

@TobiasNx
Copy link
Collaborator

TobiasNx commented Jan 3, 2023

Sometimes one has multiple fields that should be concatinated together, often it is the same element. Also sometimes one wants to add the value of an element to an existing field.
paste wont do the trick if one element exists multiple times, also it pasts even if the element does not exist and creating an empty array, copying the value in this array and then join_field is a workaround.

I suggest a concatenate function: concatenate("<sourceElement>", "<targetElememt>",[join_char: "[...]", direction: "[front/back]")

in:

honorificPrefix: Dr.
name: Maxi Muster

fix:
concatenate("honorificPrefix", "name", direction: "front")

out:

honorificPrefix: Dr.
name: Dr. Maxi Muster

If the target element does not exist, then the targetElement would be created.

@TobiasNx TobiasNx changed the title Introduce function to concatinate value to field Introduce function to concatenate value to field Jan 3, 2023
@blackwinter
Copy link
Member

Can you illustrate your edge cases with examples? The given example is equivalent to paste("name", "honorificPrefix", "name").

@TobiasNx
Copy link
Collaborator Author

TobiasNx commented Jan 3, 2023

Case 1:
in:

keyword: dog
keyword: animal
keyword: companion

fix
concatenate("keyword","keywords",join_char:"; ")

out:

keyword: dog
keyword: animal
keyword: companion
keywords: dog; animal; companion

Case 2:
in:
record 1:

pages: 56 S.
additionalMaterial: Illustration
size: 30 cm

record 2:

pages: 5 S.
size: 27 cm

fix:

copy_field("pages","extent")
concatenate("additionalMaterial","extent",join_char:" ; ")
concatenate("size","extent",join_char:" : ")

out:
record 1:

pages: 56 S.
additionalMaterial: Illustration
size: 30 cm
extent: 56 S. : Illustration ; 30 cm

record 2:

pages: 5 S.
size: 27 cm
extent: 5 S. : 27 cm

@blackwinter
Copy link
Member

blackwinter commented Jan 3, 2023

Thanks. Although I'm still not sure that they justify a new method.

Case 1:

copy_field("keyword", "keywords")
join_field("keywords", "; ")

Case 2:

copy_field("pages", "extent")
paste("extent", "extent", "additionalMaterial", join_char: " : ")
paste("extent", "extent", "size", join_char: " ; ")

The latter is certainly more complicated due to the optional clauses. But this could be an option ignore_missing: "true" or something like that (see also #226).

BTW: Your use of separators in the second example is not consistent. The desired output could only be achieved if additionalMaterial and size were concatenated first (with separator ;) and then appended to pages (with separator :).

paste('extent', 'additionalMaterial', 'size', join_char: ' ; ')
paste('extent', 'pages', 'extent', join_char: ' : ')

@TobiasNx
Copy link
Collaborator Author

TobiasNx commented Jan 5, 2023

another case would be simplified:

    set_array("subject[].$last.label")
    set_array("$i.@name")
    copy_field("$i.a","$i.@name.$append")
    copy_field("$i.b","$i.@name.$append")
    copy_field("$i.c","$i.@name.$append")
    copy_field("$i.d","$i.@name.$append")
    join_field("$i.@name")
    copy_field("$i.@name","subject[].$last.label.$append")
    copy_field("$i.x","subject[].$last.label.$append")
    copy_field("$i.y","subject[].$last.label.$append")
    copy_field("$i.z","subject[].$last.label.$append")
    copy_field("$i.v","subject[].$last.label.$append")
    join_field("subject[].$last.label"," / ")

@blackwinter
Copy link
Member

blackwinter commented Jan 5, 2023

What would the simplification with concatenate() look like? Isn't it already rather simple with paste() (save for ignore_missing: "true" if that's what's pivotal here)?

paste("$i.@name", "$i.a", "$i.b", "$i.c", "$i.d")
paste("subject[].$last.label", "$i.@name", "$i.x", "$i.y", "$i.z", "$i.v", join_char: " / ")

To be clear: It's not my intention to dismiss your use cases here. It's just that I'd rather extend an existing function instead of introducing a new one that does almost the same.

@blackwinter
Copy link
Member

save for ignore_missing: "true" if that's what's pivotal here

How did we even get to this point? Missing (null) values are already ignored. Your initial remark referred to #226, didn't it?

also it past[e]s even if the element does not exist

@blackwinter
Copy link
Member

So paste() needs to learn skip_incomplete: "true" for #226 and flatten: "true" (or recursive: "true"?) for arrays. The only thing remaining would be appending/prepending to an existing field which needs to be explicit with paste() (while also being more flexible).

Would this satisfy your requirements?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants