Text to URL

314 views
Skip to first unread message

okn...@gmail.com

unread,
Nov 28, 2020, 7:55:33 AM11/28/20
to OpenRefine
 Hi, 
 
 How do I converter a string of text that has URL links as text to URL? Like to below string of text

In OpenRefine
For questions related to Power BI Premium, see [Power BI Premium FAQ](https://docs.microsoft.com/en-us/power-bi/service-premium-faq).

Goal
For questions related to Power BI Premium, see [Power BI Premium FAQ](https://docs.microsoft.com/en-us/power-bi/service-premium-faq).

Happy late Thanksgiving and thanks for the help in advance 

okn...@gmail.com

unread,
Nov 30, 2020, 7:52:27 AM11/30/20
to OpenRefine
Can someone please help me, thanks.

Thad Guidry

unread,
Nov 30, 2020, 10:12:15 AM11/30/20
to openr...@googlegroups.com
URLs are text in fact.
Various clients however can treat them specially and recognize them and expose a link that you can click on.  One such kind of a client is a browser.
Browsers work with HTML.
So one way would be to convert the URL into a Hyperlink that a browser (or Excel, LibreOffice, etc.) could recognize if you exported in that format.
Just use regular Cell transforms to create and apply a format wrapped around your specific URL such as:


The basic steps are...You will first need to partition by some pattern such as
value.partition("https://",true)[1]
then apply any necessary string replacements or additions,
then concatenate everything back together.
'<a href="' + value + '</a>'

Then on export you can choose a format that recognizes HTML in their client programs, or simply use CSV and many programs will still recognize the HTML and allow a Hyperlink click in their program.

We do not currently have a quick GREL syntax that will convert any URLs found in a string and create Hyperlinks.
There are however some Python libraries that will do that and you could install one and then use Python in the Expression Editor to convert URLs in Strings to HTML Hyperlinks.

If you would like to have GREL add a new function that could create HTML Hyperlinks.
Unfortunately, we don't currently include all of Jsoup's commands such as allowing to set the HTML of an element or to set the attribute values and modify them.  But we could if requested as a future feature, but not sure how many users would really want to work with modifying HTML in that way. https://jsoup.org/apidocs/org/jsoup/nodes/Element.html

Hope this helps!
And I agree that perhaps a new GREL HTML helper function for extracting and setting <a href> tag's around URL's in Strings would probably be useful.



--
You received this message because you are subscribed to the Google Groups "OpenRefine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openrefine+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/openrefine/a10a3f0a-bee6-4a31-9972-e5fea8404302n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages