url

The url library contains functions related to URL processing.

hostName

get the host for the URL

suffixHostName

get the suffix of the host for the URL

prefixHostName

get the prefix for the host of the URL

subHostName

get the sub host for the host of the URL

hostNameSize

get number of components in the host

path

get the URL path

suffixPath

get the suffix of the URL path

prefixPath

get the prefix of the URL path

subPath

get the sub path of the URL path

pathSize

get the number of components in the URL path

isValidUrl

check if the value is a valid URL

hostName

Get the host for the URL.

hostName(URL)

Where:

  • URL is the URL from which to extract the host.

Example
@library("url:", "url").
input("http://example.com/path").
result(X) :- input(Y), X = url:hostName(Y).
@output("result").
Expected results
result("example.com")

suffixHostName

Get the suffix of the host for the URL.

suffixHostName(URL, Pos)

Where:

  • URL is the URL from which to extract the suffix of the host.

  • Pos is an integer, the position of the element to retrieve from the suffix.

Example
@library("url:", "url").
input("http://sub.example.com/path", 2).
result(X) :- input(Y, Z), X = url:suffixHostName(Y, Z).
@output("result").
Expected results
result("com")

prefixHostName

Get the prefix for the host of the URL.

prefixHostName(URL, Elements)

Where:

  • URL is the URL from which to extract the prefix of the host.

  • Elements is an integer, the number of elements to retrieve from the prefix.

Example
@library("url:", "url").
input("http://sub.example.com/path", 1).
result(X) :- input(Y, Z), X = url:prefixHostName(Y, Z).
@output("result").
Expected results
result("sub")

subHostName

Get the sub host for the host of the URL.

subHostName(URL, StartPos, EndPos)

Where:

  • URL is the URL from which to extract the sub host.

  • StartPos is an integer, the starting position of the sub host name to extract.

  • EndPos is an integer, the ending position of the sub host name to extract.

Example
@library("url:", "url").
input("http://sub.example.com/path", 0, 2).
result(X) :- input(Y, Z, W), X = url:subHostName(Y, Z, W).
@output("result").
Expected results
result("sub.example")

hostNameSize

Get the number of components in the host.

hostNameSize(URL)

Where:

  • URL is the URL from which to count the number of components in the host.

Example
@library("url:", "url").
input("http://sub.example.com/path").
result(X) :- input(Y), X = url:hostNameSize(Y).
@output("result").
Expected results
result(3)

path

Get the URL path.

path(URL)

Where:

  • URL is the URL from which to extract the path.

Example
@library("url:", "url").
input("http://example.com/path/to/resource").
result(X) :- input(Y), X = url:path(Y).
@output("result").
Expected results
result("/path/to/resource")

suffixPath

Get the suffix of the URL path.

suffixPath(URL, Pos)

Where:

  • URL is the URL from which to extract the suffix of the path.

  • Pos is an integer, the position of the element to retrieve from the suffix.

Example
@library("url:", "url").
input("http://example.com/path/to/resource", 2).
result(X) :- input(Y, Z), X = url:suffixPath(Y, Z).
@output("result").
Expected results
result("resource")

prefixPath

Get the prefix of the URL path.

prefixPath(URL, Elements)

Where:

  • URL is the URL from which to extract the prefix of the path.

  • Elements is an integer, the number of elements to retrieve from the prefix.

Example
@library("url:", "url").
input("http://example.com/path/to/resource", 2).
result(X) :- input(Y, Z), X = url:prefixPath(Y, Z).
@output("result").
Expected results
result("path.to").

subPath

Get the sub path of the URL path.

subPath(URL, StartPos, EndPos)

Where:

  • URL is the URL from which to extract the sub path.

  • StartPos is an integer, the starting position of the sub path to extract.

  • EndPos is an integer, the ending position of the sub path to extract.

Example
@library("url:", "url").
input("http://example.com/path/to/resource", 1, 2).
result(X) :- input(Y, Z, W), X = url:subPath(Y, Z, W).
@output("result").
Expected results
result("/to")

pathSize

Get the number of components in the URL path.

pathSize(URL)

Where:

  • URL is the URL from which to count the number of components in the path.

Example
@library("url:", "url").
input("http://example.com/path/to/resource").
result(X) :- input(Y), X = url:pathSize(Y).
@output("result").
Expected results
result(3)

isValidUrl

Check if the value is a valid URL.

isValidUrl(Value)

Where:

  • Value is the string to be checked for URL validity.

Example
@library("url:", "url").
input("http://example.com").
result(X) :- input(Y), X = url:isValidUrl(Y).
@output("result").
Expected results
result("#T")