Skip to content

Better way to modify existing extractor. #98

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

Closed
racinmat opened this issue Oct 19, 2021 · 1 comment
Closed

Better way to modify existing extractor. #98

racinmat opened this issue Oct 19, 2021 · 1 comment

Comments

@racinmat
Copy link
Collaborator

racinmat commented Oct 19, 2021

Currently we have e.g. in mutagenesis example https://github.com/CTUAvastLab/JsonGrinder.jl/blob/master/examples/mutagenesis.jl
following, cumbersome way of modifying current extractor after suggestion:

extractor[:atoms].item[:bonds].item.dict[:charge] = JsonGrinder.ExtractCategorical(sch[:atoms].items[:bonds].items[:charge])

which is lengthy and we need to specify the path twice.
Instead it would be nice to e.g. use lenses, but that would require us to have unique code2lens, which is not now, because the logic is: takt value under that code and match/return everything that is equal as element under that code.
Which is troublesome.

printtree(sch, trav=true)
printtree(extractor, trav=true)
sch["BK"]
code2lens(sch, "BK")
sch_lens = only(code2lens(sch, "BK"))
code2lens(extractor, "BK")
ext_lens = first(code2lens(extractor, "BK"))

using Setfield
get(sch, sch_lens)
get(extractor, ext_lens)

also the schema lens to extractor lens is not working now, I would expect this to work:

Setfield.set(extractor, ext_lens, JsonGrinder.ExtractCategorical(get(sch, sch_lens)))

But maybe it may suffice to have yet another parameter to suggestextractor, which woud be similar as fsm field in reflectinmodel, where one would pass dict of path in schema => suggestion of extractor baed on shema.
But the path used by string code is unstable and code changes based on another fields. Maybe putting lens there would be worth it?

@simonmandlik
Copy link
Collaborator

IMO, adding this to suggestextractor makes things too complicated, when this is a simple one liner:

sch = schema(...)
e = suggestextractor(sch)

using Accessors

set(e, code2lens(e, "BK"), ...)

But some examples may be added to the docs: #137

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