Is there a way to access information from other rows when using Jython?

Hi! I am trying to use Jython in a project to apply a transformation to a cell based on how many times the value in a neighboring column has already appeared in that record (simplified version - if column B contains [A,B,A,C,A], I want column A to have the values [1,1,2,1,3]). This is proving very difficult, because unlike GREL, which has the cross() method, I can't find any way of referencing other rows in the record while using Jython. Am I missing something, or is this a functionality that doesn't currently exist? Thanks!

AFAIK this is currently not possible as cross and other GREL specific functions are only available in GREL.

There is an open feature request on GitHub (Expose GREL functions in other expression languages · Issue #2251 · OpenRefine/OpenRefine · GitHub) addressing this issue.

Thanks so much for the response!

I can confirm that Jython doesn't have access to cross (or other projects), but I'd like to make sure I understand the example since one of the things that we're looking at for the next version is better support for column operations.

It sounds like you are perhaps using cross not for its join capabilities across projects but to access the rows within the same project, correct? And what you really want access to is all the cell values in a single column so that you can enumerate their occurrences?

Tom

Yes, correct! I will add that in this specific case, the issue would be solved (or at least obviated) if row.record.cells returned all cells in a column of a record and not just the non-blank ones, as I am trying to enumerate occurrences within a record and being thwarted by that behavior, but in other instances I frequently use cross to access other rows outside of a record in the same project.

You could also introduce a sentinel value for missing values (like "missing" or "NA") instead of having empty/null cells.

That way you could continue using row.record.cells but with all cells present.

Yeah, that's what I ended up doing. It is a bit clunky, but it is working so far.