Function of boundary edge length

I want to implement Nitsche’s boundary conditions as above (2.5) (see here).
With reference to the paper, I think the bilinear form can be implemented as follows:

# a term of the bilinear form a(u,v)
u = TrialFunction(V)
v = TestFunction(V)
n = FacetNormal(mesh)
term = f*inner(grad(u),n)*v*ds(mesh)

Here f should be a function of the edge (2D) or face (3D) diameter, on each boundary edge/face. Specifically, for a boundary edge E, f = gamma*h_E/(eps+gamma*h_e), for two numbers eps, gamma. I am having quite a hard time to implement f, is there any functionality I’m not aware of, that allows to realize it?