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

Add new GREL function to support Jsoup parent() function to complement our select() #4181

Closed
thadguidry opened this issue Sep 28, 2021 · 0 comments · Fixed by #4184
Closed
Labels
Good First Issue Indicates issues suitable for newcomers to design or coding, providing a gentle introduction. grel The default expression language, GREL, could be improved in many ways! Type: Feature Request Identifies requests for new features or enhancements. These involve proposing new improvements.
Milestone

Comments

@thadguidry
Copy link
Member

thadguidry commented Sep 28, 2021

There is no easy way to navigate up the parse tree provided by jsoup selector syntax. We currently can navigate down very easily with Jsoup's selector syntax value.parseHtml().select("div > p") and also value.parseHtml().select("div:has(@) ~ div") but
this does not directly allow DOM traversal itself. However, Jsoup conveniently provides DOM traversal for finding a https://jsoup.org/apidocs/org/jsoup/nodes/Element.html#parent()
which mimics the behavior from BeautifulSoup's https://www.crummy.com/software/BeautifulSoup/bs4/doc/#parent

Proposed solution

Add a new GREL function for the jsoup method parent() and for simplicity sake just call the GREL function parent()

Alternatives considered

A difficult path of custom installed Jython 2.7 with BeautifulSoup

Additional context

Existing code for select() functionality is here:
https://github.com/OpenRefine/OpenRefine/blob/master/main/src/com/google/refine/expr/functions/xml/SelectXml.java
and function registration to be added to is here:
https://github.com/OpenRefine/OpenRefine/blob/master/main/src/com/google/refine/grel/ControlFunctionRegistry.java#L249

@thadguidry thadguidry added Type: Feature Request Identifies requests for new features or enhancements. These involve proposing new improvements. grel The default expression language, GREL, could be improved in many ways! labels Sep 28, 2021
@wetneb wetneb added the Good First Issue Indicates issues suitable for newcomers to design or coding, providing a gentle introduction. label Sep 28, 2021
thadguidry added a commit to thadguidry/OpenRefine that referenced this issue Sep 28, 2021
wetneb added a commit that referenced this issue Jan 18, 2022
* Adds parent() GREL function for jsoup
fixes #4181

* Fix test for parent() by adding toString()

Co-authored-by: Antonin Delpeuch <antonin@delpeuch.eu>
@wetneb wetneb added this to the 3.6 milestone Jan 18, 2022
j-sal pushed a commit to j-sal/OpenRefine that referenced this issue Jan 18, 2022
* Adds parent() GREL function for jsoup
fixes OpenRefine#4181

* Fix test for parent() by adding toString()

Co-authored-by: Antonin Delpeuch <antonin@delpeuch.eu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good First Issue Indicates issues suitable for newcomers to design or coding, providing a gentle introduction. grel The default expression language, GREL, could be improved in many ways! Type: Feature Request Identifies requests for new features or enhancements. These involve proposing new improvements.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants