Search code examples
regexopenrefine

OpenRefine custom text faceting


I have a column of names like:

  • Quaglia, Pietro Paolo
  • Bernard, of Clairvaux, Saint, or
  • .E., Calvin F.
  • Swingle, M Abate, Agostino, Assereto
  • Abati, Antonio
  • 10-NA)\u, Ferraro, Giuseppe, ed, Biblioteca comunale ariostea. Mss. (Esteri

I want to make a Custom text facet with openrefine that mark as "true" the names with one comma and "false" all the others, so that I can work with those last (".E., Calvin F." is not a problem, I'll work with that later).

I'm trying using "Custom text facet" and this expression:

if(value.match(/([^,]+),([^,]+)/), "true", "false")

But the result is all false. What's the wrong part?


Solution

  • The expression you are using:

    if(value.match(/([^,]+),([^,]+)/), "true", "false")
    

    will always evaluate to false because the output of the 'match' function is either an array, or null. When evaluated by 'if' neither an array nor 'null' evaluate to true.

    You can wrap the match function in a 'isNonBlank' or similar to get a boolean true/false, which would then cause the 'if' function to work as you want. However, once you have a boolean true/false result the 'if' becomes redundant as its only function is to turn the boolean true/false into string "true" or "false" - which won't make any difference to the values function of the custom text facet.

    So:

    isNonBlank(value.match(/([^,]+),([^,]+)/))
    

    should give you the desired result using match