Jump to content

Canonicalization: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Unicode: clean up, typo(s) fixed: For example → For example, using AWB
See also: annlink
 
(44 intermediate revisions by 39 users not shown)
Line 1: Line 1:
{{Short description|Process for converting data into a "standard", "normal", or canonical form}}
{{Distinguish|URL canonicalization|Canonization}}
{{Use American English|date=March 2021}}
{{Use dmy dates|date=March 2021}}
{{Distinguish|Canonical link element|Canonization}}


In [[computer science]], '''canonicalization''' (sometimes '''standardization''' or '''[[Normalization (statistics)|normalization]]''') is a process for converting [[data]] that has more than one possible representation into a "standard", "normal", or [[canonical form]]. This can be done to compare different representations for equivalence, to count the number of distinct data structures, to improve the efficiency of various [[algorithm]]s by eliminating repeated calculations, or to make it possible to impose a meaningful [[sorting]] order.
{{merge to|Canonical form|discuss=Talk:Canonical form#Proposed merge with Canonicalization|date=November 2015}}
In [[computer science]], '''canonicalization''' (sometimes '''standardization''' or '''normalization''') is a process for converting [[data]] that has more than one possible representation into a "standard", "normal", or [[canonical form]]. This can be done to compare different representations for equivalence, to count the number of distinct data structures, to improve the efficiency of various [[algorithm]]s by eliminating repeated calculations, or to make it possible to impose a meaningful [[sorting]] order.


==Usage cases==
==Usage cases==


===Web servers===
=== Filenames ===
Files in [[file system]]s may in most cases be accessed through multiple [[filename]]s. For instance in [[Unix]]-like systems, the string "<code>/./</code>" can be replaced by "<code>/</code>". In the [[C standard library]], the function <code>realpath()</code> performs this task. Other operations performed by this function to canonicalize filenames are the handling of <code>/..</code> components referring to parent directories, simplification of sequences of multiple slashes, removal of trailing slashes, and the resolution of [[symbolic link]]s.

Canonicalization of filenames is important for computer security. For example, a web server may have a restriction that only files under the cgi directory <code>C:\inetpub\wwwroot\cgi-bin</code> may be executed. This rule is enforced by checking that the path starts with <code>C:\inetpub\wwwroot\cgi-bin\</code> and only then executing it. While the file <code>C:\inetpub\wwwroot\cgi-bin\..\..\..\Windows\System32\cmd.exe</code> initially appears to be in the cgi directory, it exploits the <code>..</code> path specifier to traverse back up the directory hierarchy in an attempt to execute a file outside of <code>cgi-bin</code>. Permitting <code>cmd.exe</code> to execute would be an error caused by a failure to canonicalize the filename to the simplest representation, <code>C:\Windows\System32\cmd.exe</code>, and is called a [[directory traversal]] vulnerability. With the path canonicalized, it is clear the file should not be executed.
Canonicalization of filenames is important for computer security. For example, a web server may have a restriction that only files under the cgi directory <code>C:\inetpub\wwwroot\cgi-bin</code> may be executed. This rule is enforced by checking that the path starts with <code>C:\inetpub\wwwroot\cgi-bin\</code> and only then executing it. While the file <code>C:\inetpub\wwwroot\cgi-bin\..\..\..\Windows\System32\cmd.exe</code> initially appears to be in the cgi directory, it exploits the <code>..</code> path specifier to traverse back up the directory hierarchy in an attempt to execute a file outside of <code>cgi-bin</code>. Permitting <code>cmd.exe</code> to execute would be an error caused by a failure to canonicalize the filename to the simplest representation, <code>C:\Windows\System32\cmd.exe</code>, and is called a [[directory traversal]] vulnerability. With the path canonicalized, it is clear the file should not be executed.


Line 13: Line 17:
In [[Unicode]], many accented letters can be represented in more than one way. For example, ''é'' can be represented in Unicode as the Unicode character U+0065 (LATIN SMALL LETTER E) followed by the character U+0301 (COMBINING ACUTE ACCENT), but it can also be represented as the precomposed character U+00E9 (LATIN SMALL LETTER E WITH ACUTE). This makes string comparison more complicated, since every possible representation of a string containing such glyphs must be considered. To deal with this, Unicode provides the mechanism of [[canonical equivalence]]. In this context, canonicalization is [[Unicode normalization]].
In [[Unicode]], many accented letters can be represented in more than one way. For example, ''é'' can be represented in Unicode as the Unicode character U+0065 (LATIN SMALL LETTER E) followed by the character U+0301 (COMBINING ACUTE ACCENT), but it can also be represented as the precomposed character U+00E9 (LATIN SMALL LETTER E WITH ACUTE). This makes string comparison more complicated, since every possible representation of a string containing such glyphs must be considered. To deal with this, Unicode provides the mechanism of [[canonical equivalence]]. In this context, canonicalization is [[Unicode normalization]].


[[Variable-length encoding]]s in the Unicode standard, in particular [[UTF-8]], may cause an additional need for canonicalization in some situations. Namely, by the standard, in UTF-8 there is only one valid byte sequence for any Unicode character,<ref>http://www.ietf.org/rfc/rfc2279.txt</ref> but some byte sequences are invalid, i. e. cannot be obtained by encoding any string of Unicode characters into UTF-8. Some sloppy decoder implementations may accept invalid byte sequences as input and produce a valid Unicode character as output for such a sequence. If one uses such a decoder, some Unicode characters have effectively more than one corresponding byte sequence: the valid one and some invalid ones. This could lead to security issues similar to the one described in the previous section. Therefore, if one wants to apply some filter (e. g. a regular expression written in UTF-8) to UTF-8 strings that will later be passed to a decoder that allows invalid byte sequences, one should canonicalize the strings before passing them to the filter. In this context, canonicalization is the process of translating every string character to its single valid byte sequence. An alternative to canonicalization is to reject any strings containing invalid byte sequences..
[[Variable-width encoding]]s in the Unicode standard, in particular [[UTF-8]], may cause an additional need for canonicalization in some situations. Namely, by the standard, in UTF-8 there is only one valid byte sequence for any Unicode character,<ref>[http://www.ietf.org/rfc/rfc2279.txt RFC 2279: UTF-8, a transformation format of ISO 10646]</ref> but some byte sequences are invalid, i.e., they cannot be obtained by encoding any string of Unicode characters into UTF-8. Some sloppy decoder implementations may accept invalid byte sequences as input and produce a valid Unicode character as output for such a sequence. If one uses such a decoder, some Unicode characters effectively have more than one corresponding byte sequence: the valid one and some invalid ones. This could lead to security issues similar to the one described in the previous section. Therefore, if one wants to apply some filter (e.g., a regular expression written in UTF-8) to UTF-8 strings that will later be passed to a decoder that allows invalid byte sequences, one should canonicalize the strings before passing them to the filter. In this context, canonicalization is the process of translating every string character to its single valid byte sequence. An alternative to canonicalization is to reject any strings containing invalid byte sequences.

===URL===

A '''canonical URL''' is a [[URL]] for defining the [[single source of truth]] for [[duplicate content]].

==== Use by Google ====

A canonical URL is the URL of the page that Google thinks is most representative from a set of duplicate pages on your site. For example, if you have URLs for the same page, such as <code>https://example.com/?dress=1234</code> and <code>https://example.com/dresses/1234</code>, Google chooses one as canonical. Note that the pages do not need to be absolutely identical; minor changes in sorting or filtering of list pages do not make the page unique (for example, sorting by price or filtering by item color).

The canonical can be in a different domain than a duplicate.<ref>{{Cite web|url=https://support.google.com/webmasters/answer/139066?hl=en|title=Consolidate Duplicate URLs with Canonicals &#124; Google Search Central}}</ref>

==== Internet ====

With the help of canonical URLs, a search engine knows which link should be provided in a query result.

A [[canonical link element]] can get used to define a canonical URL.

==== Intranet ====

In [[intranets]], manual searching for information is predominant. In this case, canonical URLs can be defined in a non-machine-readable form, too. For example in a [[guideline]].

==== Misc ====

Canonical URLs are usually the URLs that get used for the [[share action]].

Since the Canonical URL gets used in the search result of search engines, they are in most cases a [[landing page]].


===Search engines and SEO===
===Search engines and SEO===
In web search and [[search engine optimization]] (SEO), [[URL canonicalization]] deals with web content that has more than one possible URL. Having multiple URLs for the same web content can cause problems for search engines - specifically in determining which URL should be shown in search results.<ref name=cutts>{{cite web|last=Cutts|first=Matt|title=SEO advice: url canonicalization|url=http://www.mattcutts.com//blog/seo-advice-url-canonicalization/|work=Matt Cutts: Gadgets, Google, and SEO|accessdate=3 September 2013|date=January 4, 2006}}</ref>
In web search and [[search engine optimization]] (SEO), [[URL canonicalization]] deals with web content that has more than one possible URL. Having multiple URLs for the same web content can cause problems for search engines - specifically in determining which URL should be shown in search results.<ref name=cutts>{{cite web|last=Cutts|first=Matt|title=SEO advice: url canonicalization|url=http://www.mattcutts.com//blog/seo-advice-url-canonicalization/|work=Matt Cutts: Gadgets, Google, and SEO|accessdate=3 September 2013|date=January 4, 2006}}</ref> Most search engines support the [[Canonical link element]] as a hint to which URL should be treated as the true version. As indicated by John Mueller of Google, having other directives in a page, like the [[Noindex|robots noindex]] element can give search engines conflicting signals about how to handle canonicalization <ref>{{Cite web|url=http://www.thegooglecache.com/canonicalized-url-is-noindex-nofollow.html|title=Canonicalized URL is noindex, nofollow|language=en-US|access-date=2020-04-20}}</ref>


Example:
Example:
* http://wikipedia.com
* <code>http://wikipedia.com{{cbignore}}</code>
* http://www.wikipedia.com
* <code>http://www.wikipedia.com{{cbignore}}</code>
* http://www.wikipedia.com/
* <code>http://www.wikipedia.com/{{cbignore}}</code>
* http://www.wikipedia.com/?source=asdf
* <code>http://www.wikipedia.com/?source=asdf{{cbignore}}</code>


All of these URLs point to the homepage of Wikipedia, but a search engine will only consider one of them to be the canonical form of the URL.
All of these URLs point to the homepage of Wikipedia, but a search engine will only consider one of them to be the canonical form of the URL.
Line 30: Line 60:


A simple example would be the following two snippets of XML:
A simple example would be the following two snippets of XML:
* <code><node1>Data</node1&nbsp;&nbsp;&nbsp;&nbsp;>&nbsp;<node2>Data</node2></code>
# <code><node1 x='1' a="1" a="2">Data</node1&nbsp;&nbsp;&nbsp;&nbsp;>&nbsp;<node2>Data</node2></code>
* <code><node1>Data</node1>&nbsp;<node2>Data</node2></code>
# <code><node1 a="2" x="1">Data</node1>&nbsp;<node2>Data</node2></code>
The first example contains extra spaces in the closing tag of the first node. The second example, which has been canonicalized, has had these spaces removed. Note that only the spaces within the tags are removed under W3C canonicalization, not those between tags.
The first example contains extra spaces in the closing tag of the first node. The second example, which has been canonicalized, has had these spaces removed. Note that only the spaces within the tags are removed under W3C canonicalization, not those between tags.


Line 52: Line 82:


=== Computational linguistics ===
=== Computational linguistics ===
In [[morphology (linguistics)|morphology]] and [[lexicography]], a [[Lemma (morphology)|lemma]] is the ''canonical form'' of a set of [[word]]s. In [[English language|English]], for example, ''run'', ''runs'', ''ran'' and ''running'' are forms of the same [[lexeme]], so we can elect one of them, ex. ''run'', to represent all the forms. Lexical databases as [http://www-igm.univ-mlv.fr/~unitex/index.php?page=7 Unitex] use this kind of representation.
In [[morphology (linguistics)|morphology]] and [[lexicography]], a [[Lemma (morphology)|lemma]] is the ''canonical form'' of a set of [[word]]s. In [[English language|English]], for example, ''run'', ''runs'', ''ran'', and ''running'' are forms of the same [[lexeme]], so we can select one of them; ex. ''run'', to represent all the forms. [[Lexical database]]s such as [http://www-igm.univ-mlv.fr/~unitex/index.php?page=7 Unitex] use this kind of representation.


[[Lemmatisation]] is the process to convert a word into its ''canonical form''.
[[Lemmatisation]] is the process of converting a word to its ''canonical form''.


== See also ==
== See also ==
* [[Canonical form]]
* {{annotated link|Canonical form}}
* [[Graph canonization]]
* {{annotated link|Graph canonization}}
* [[Lemmatisation]]
* {{annotated link|Lemmatisation}}
* [[Text normalization]]
* {{annotated link|Text normalization}}
* [[Type species]]
* {{annotated link|Type species}}


== References ==
== References ==

Latest revision as of 13:59, 14 November 2024

In computer science, canonicalization (sometimes standardization or normalization) is a process for converting data that has more than one possible representation into a "standard", "normal", or canonical form. This can be done to compare different representations for equivalence, to count the number of distinct data structures, to improve the efficiency of various algorithms by eliminating repeated calculations, or to make it possible to impose a meaningful sorting order.

Usage cases

[edit]

Filenames

[edit]

Files in file systems may in most cases be accessed through multiple filenames. For instance in Unix-like systems, the string "/./" can be replaced by "/". In the C standard library, the function realpath() performs this task. Other operations performed by this function to canonicalize filenames are the handling of /.. components referring to parent directories, simplification of sequences of multiple slashes, removal of trailing slashes, and the resolution of symbolic links.

Canonicalization of filenames is important for computer security. For example, a web server may have a restriction that only files under the cgi directory C:\inetpub\wwwroot\cgi-bin may be executed. This rule is enforced by checking that the path starts with C:\inetpub\wwwroot\cgi-bin\ and only then executing it. While the file C:\inetpub\wwwroot\cgi-bin\..\..\..\Windows\System32\cmd.exe initially appears to be in the cgi directory, it exploits the .. path specifier to traverse back up the directory hierarchy in an attempt to execute a file outside of cgi-bin. Permitting cmd.exe to execute would be an error caused by a failure to canonicalize the filename to the simplest representation, C:\Windows\System32\cmd.exe, and is called a directory traversal vulnerability. With the path canonicalized, it is clear the file should not be executed.

Unicode

[edit]

In Unicode, many accented letters can be represented in more than one way. For example, é can be represented in Unicode as the Unicode character U+0065 (LATIN SMALL LETTER E) followed by the character U+0301 (COMBINING ACUTE ACCENT), but it can also be represented as the precomposed character U+00E9 (LATIN SMALL LETTER E WITH ACUTE). This makes string comparison more complicated, since every possible representation of a string containing such glyphs must be considered. To deal with this, Unicode provides the mechanism of canonical equivalence. In this context, canonicalization is Unicode normalization.

Variable-width encodings in the Unicode standard, in particular UTF-8, may cause an additional need for canonicalization in some situations. Namely, by the standard, in UTF-8 there is only one valid byte sequence for any Unicode character,[1] but some byte sequences are invalid, i.e., they cannot be obtained by encoding any string of Unicode characters into UTF-8. Some sloppy decoder implementations may accept invalid byte sequences as input and produce a valid Unicode character as output for such a sequence. If one uses such a decoder, some Unicode characters effectively have more than one corresponding byte sequence: the valid one and some invalid ones. This could lead to security issues similar to the one described in the previous section. Therefore, if one wants to apply some filter (e.g., a regular expression written in UTF-8) to UTF-8 strings that will later be passed to a decoder that allows invalid byte sequences, one should canonicalize the strings before passing them to the filter. In this context, canonicalization is the process of translating every string character to its single valid byte sequence. An alternative to canonicalization is to reject any strings containing invalid byte sequences.

URL

[edit]

A canonical URL is a URL for defining the single source of truth for duplicate content.

Use by Google

[edit]

A canonical URL is the URL of the page that Google thinks is most representative from a set of duplicate pages on your site. For example, if you have URLs for the same page, such as https://example.com/?dress=1234 and https://example.com/dresses/1234, Google chooses one as canonical. Note that the pages do not need to be absolutely identical; minor changes in sorting or filtering of list pages do not make the page unique (for example, sorting by price or filtering by item color).

The canonical can be in a different domain than a duplicate.[2]

Internet

[edit]

With the help of canonical URLs, a search engine knows which link should be provided in a query result.

A canonical link element can get used to define a canonical URL.

Intranet

[edit]

In intranets, manual searching for information is predominant. In this case, canonical URLs can be defined in a non-machine-readable form, too. For example in a guideline.

Misc

[edit]

Canonical URLs are usually the URLs that get used for the share action.

Since the Canonical URL gets used in the search result of search engines, they are in most cases a landing page.

Search engines and SEO

[edit]

In web search and search engine optimization (SEO), URL canonicalization deals with web content that has more than one possible URL. Having multiple URLs for the same web content can cause problems for search engines - specifically in determining which URL should be shown in search results.[3] Most search engines support the Canonical link element as a hint to which URL should be treated as the true version. As indicated by John Mueller of Google, having other directives in a page, like the robots noindex element can give search engines conflicting signals about how to handle canonicalization [4]

Example:

All of these URLs point to the homepage of Wikipedia, but a search engine will only consider one of them to be the canonical form of the URL.

XML

[edit]

A Canonical XML document is by definition an XML document that is in XML Canonical form, defined by The Canonical XML specification. Briefly, canonicalization removes whitespace within tags, uses particular character encodings, sorts namespace references and eliminates redundant ones, removes XML and DOCTYPE declarations, and transforms relative URIs into absolute URIs.

A simple example would be the following two snippets of XML:

  1. <node1 x='1' a="1" a="2">Data</node1    > <node2>Data</node2>
  2. <node1 a="2" x="1">Data</node1> <node2>Data</node2>

The first example contains extra spaces in the closing tag of the first node. The second example, which has been canonicalized, has had these spaces removed. Note that only the spaces within the tags are removed under W3C canonicalization, not those between tags.

A full summary of canonicalization changes is listed below:

  • The document is encoded in UTF-8
  • Line breaks normalized to #xA on input, before parsing
  • Attribute values are normalized, as if by a validating processor
  • Character and parsed entity references are replaced
  • CDATA sections are replaced with their character content
  • The XML declaration and document type declaration are removed
  • Empty elements are converted to start-end tag pairs
  • Whitespace outside of the document element and within start and end tags is normalized
  • All whitespace in character content is retained (excluding characters removed during line feed normalization)
  • Attribute value delimiters are set to quotation marks (double quotes)
  • Special characters in attribute values and character content are replaced by character references
  • Superfluous namespace declarations are removed from each element
  • Default attributes are added to each element
  • Fixup of xml:base attributes is performed
  • Lexicographic order is imposed on the namespace declarations and attributes of each element

Computational linguistics

[edit]

In morphology and lexicography, a lemma is the canonical form of a set of words. In English, for example, run, runs, ran, and running are forms of the same lexeme, so we can select one of them; ex. run, to represent all the forms. Lexical databases such as Unitex use this kind of representation.

Lemmatisation is the process of converting a word to its canonical form.

See also

[edit]
  • Canonical form – Standard representation of a mathematical object
  • Graph canonization – Unsolved problem in computational complexity theory
  • Lemmatisation – Natural language processing canonicalisation
  • Text normalization – Process of transforming text into a single canonical form
  • Type species – Term used in biological nomenclature

References

[edit]
  1. ^ RFC 2279: UTF-8, a transformation format of ISO 10646
  2. ^ "Consolidate Duplicate URLs with Canonicals | Google Search Central".
  3. ^ Cutts, Matt (4 January 2006). "SEO advice: url canonicalization". Matt Cutts: Gadgets, Google, and SEO. Retrieved 3 September 2013.
  4. ^ "Canonicalized URL is noindex, nofollow". Retrieved 20 April 2020.
[edit]