Skip to content

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

Description

@thadguidry

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Good First IssueIndicates issues suitable for newcomers to design or coding, providing a gentle introduction.Type: Feature RequestIdentifies requests for new features or enhancements. These involve proposing new improvements.grelThe default expression language, GREL, could be improved in many ways!

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions